From a5ebb78d7bffb4732f65b45358ae867d9c46b1e7 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Sat, 16 Nov 2024 15:09:18 +0800 Subject: [PATCH 1/2] Optimise lifecycle detecting Signed-off-by: wangzhen Change-Id: I6a1ac02096d446c6eef59c5b48357568cacdf2fd --- .../native/ability/native/ability_impl.cpp | 10 +- .../native/ability_runtime/cj_ui_ability.cpp | 6 +- .../native/ability_runtime/js_ability.cpp | 6 +- .../native/ability_runtime/js_ui_ability.cpp | 9 +- .../ability/native/fa_ability_thread.cpp | 11 +-- .../ability/native/new_ability_impl.cpp | 3 +- .../native/ability/native/ui_ability_impl.cpp | 20 ++-- .../ability/native/ui_ability_thread.cpp | 13 +-- .../ability_runtime/app/js_ability_stage.cpp | 4 + frameworks/native/appkit/app/main_thread.cpp | 6 +- .../native/appkit/dfr/appfreeze_inner.cpp | 3 +- .../ability_manager/include/ability_state.h | 5 - interfaces/inner_api/app_manager/BUILD.gn | 3 - .../include/appmgr/ams_mgr_interface.h | 3 - .../include/appmgr/ams_mgr_proxy.h | 2 - .../app_manager/include/appmgr/ams_mgr_stub.h | 1 - .../appmgr/app_exception_callback_proxy.h | 43 --------- .../appmgr/app_exception_callback_stub.h | 39 -------- .../include/appmgr/app_exception_manager.h | 43 --------- .../include/appmgr/iapp_exception_callback.h | 49 ---------- .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 22 ----- .../app_manager/src/appmgr/ams_mgr_stub.cpp | 7 -- .../appmgr/app_exception_callback_proxy.cpp | 85 ----------------- .../appmgr/app_exception_callback_stub.cpp | 55 ----------- .../src/appmgr/app_exception_manager.cpp | 78 ---------------- .../src/appmgr/app_scheduler_proxy.cpp | 21 ++++- services/abilitymgr/abilitymgr.gni | 1 - services/abilitymgr/include/ability_record.h | 11 --- .../include/app_exception_handler.h | 38 -------- .../abilitymgr/src/ability_manager_proxy.cpp | 12 +-- .../src/ability_manager_service.cpp | 11 +-- services/abilitymgr/src/ability_record.cpp | 21 ++--- .../src/ability_scheduler_proxy.cpp | 7 ++ .../abilitymgr/src/app_exception_handler.cpp | 88 ------------------ .../src/mission/mission_list_manager.cpp | 22 ++--- .../ui_ability_lifecycle_manager.cpp | 22 ++--- services/appmgr/include/ams_mgr_scheduler.h | 2 - services/appmgr/include/app_running_record.h | 5 +- services/appmgr/src/ams_mgr_scheduler.cpp | 21 ----- services/appmgr/src/app_lifecycle_deal.cpp | 3 +- services/appmgr/src/app_mgr_event.cpp | 12 +-- services/appmgr/src/app_mgr_service_inner.cpp | 67 +++++++------- services/appmgr/src/app_running_manager.cpp | 38 ++++---- services/appmgr/src/app_running_record.cpp | 39 ++++++-- .../appmgr/src/app_state_observer_manager.cpp | 4 +- services/appmgr/src/cache_process_manager.cpp | 4 +- .../freezeutil_fuzzer/freezeutil_fuzzer.cpp | 7 +- .../freeze_util_test/freeze_util_test.cpp | 45 +++++---- utils/global/freeze/BUILD.gn | 5 +- utils/global/freeze/include/error_msg_util.h | 58 ++++++++++++ utils/global/freeze/include/freeze_util.h | 24 ++--- utils/global/freeze/src/error_msg_util.cpp | 87 ++++++++++++++++++ utils/global/freeze/src/freeze_util.cpp | 92 ++++++++++--------- 53 files changed, 419 insertions(+), 874 deletions(-) delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_proxy.h delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_stub.h delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/app_exception_manager.h delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/iapp_exception_callback.h delete mode 100644 interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_proxy.cpp delete mode 100644 interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_stub.cpp delete mode 100644 interfaces/inner_api/app_manager/src/appmgr/app_exception_manager.cpp delete mode 100644 services/abilitymgr/include/app_exception_handler.h delete mode 100644 services/abilitymgr/src/app_exception_handler.cpp create mode 100644 utils/global/freeze/include/error_msg_util.h create mode 100644 utils/global/freeze/src/error_msg_util.cpp diff --git a/frameworks/native/ability/native/ability_impl.cpp b/frameworks/native/ability/native/ability_impl.cpp index 1a1a486278..ee05e8b0c6 100644 --- a/frameworks/native/ability/native/ability_impl.cpp +++ b/frameworks/native/ability/native/ability_impl.cpp @@ -617,9 +617,8 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground() TAG_LOGE(AAFwkTag::ABILITY, "null stage mode ability/abilityImpl"); return; } - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle"; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); bool needNotifyAMS = false; { @@ -639,7 +638,7 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground() auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData); if (ret == ERR_OK) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } @@ -653,16 +652,15 @@ void AbilityImpl::WindowLifeCycleImpl::AfterBackground() TAG_LOGW(AAFwkTag::ABILITY, "not stage"); return; } - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND }; std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle"; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); TAG_LOGI(AAFwkTag::ABILITY, "window after background"); PacMap restoreData; auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData); if (ret == ERR_OK) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } diff --git a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp index 95c516376e..83f0c1b0bc 100644 --- a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp @@ -181,16 +181,14 @@ void CJUIAbility::OnStart(const Want &want, sptr sessionInfo void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " begin"; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void CJUIAbility::AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " end."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } int32_t CJUIAbility::OnShare(WantParams &wantParams) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 02d5e62415..228b89b8fb 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -271,16 +271,14 @@ void JsAbility::OnStart(const Want &want, sptr sessionInfo) void JsAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " begin"; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void JsAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " end"; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } int32_t JsAbility::OnShare(WantParams &wantParam) diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index 8b321c6848..b58fa7f6a1 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -362,16 +362,14 @@ void JsUIAbility::OnStart(const Want &want, sptr sessionInfo void JsUIAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " begin."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void JsUIAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, state }; auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " end."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } int32_t JsUIAbility::OnShare(WantParams &wantParam) @@ -878,8 +876,7 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want) } if (ret != Rosen::WMError::WM_OK) { TAG_LOGE(AAFwkTag::UIABILITY, "init window scene failed"); - FreezeUtil::LifecycleFlow flow = { AbilityContext::token_, FreezeUtil::TimeoutState::FOREGROUND }; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, + FreezeUtil::GetInstance().AppendLifecycleEvent(AbilityContext::token_, std::string("ERROR JsUIAbility::DoOnForegroundForSceneIsNull: ") + std::to_string(static_cast(ret))); return; } diff --git a/frameworks/native/ability/native/fa_ability_thread.cpp b/frameworks/native/ability/native/fa_ability_thread.cpp index a0b140c610..9f3a257856 100644 --- a/frameworks/native/ability/native/fa_ability_thread.cpp +++ b/frameworks/native/ability/native/fa_ability_thread.cpp @@ -315,15 +315,14 @@ void FAAbilityThread::AttachInner(const std::shared_ptrInit(application, abilityRecord, currentAbility_, abilityHandler_, token_); // 4. ability attach : ipc TAG_LOGD(AAFwkTag::FA, "attach ability"); - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::LOAD }; std::string entry = "AbilityThread::Attach; the load lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_); if (err != ERR_OK) { TAG_LOGE(AAFwkTag::FA, "err = %{public}d", err); return; } - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } @@ -496,14 +495,12 @@ void FAAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) return; } if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) { - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND }; std::string entry = "AbilityThread::" + methodName + "; the background lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } } diff --git a/frameworks/native/ability/native/new_ability_impl.cpp b/frameworks/native/ability/native/new_ability_impl.cpp index f19b446c1d..ed3cc993d6 100644 --- a/frameworks/native/ability/native/new_ability_impl.cpp +++ b/frameworks/native/ability/native/new_ability_impl.cpp @@ -77,8 +77,7 @@ void NewAbilityImpl::AbilityTransactionCallback(const AbilityLifeCycleState &sta TAG_LOGI(AAFwkTag::ABILITY, "notify ams"); auto ret = AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData()); if (ret == ERR_OK && state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } diff --git a/frameworks/native/ability/native/ui_ability_impl.cpp b/frameworks/native/ability/native/ui_ability_impl.cpp index 2d11d39623..38453a4111 100644 --- a/frameworks/native/ability/native/ui_ability_impl.cpp +++ b/frameworks/native/ability/native/ui_ability_impl.cpp @@ -217,15 +217,14 @@ void UIAbilityImpl::HandleShareData(int32_t uniqueId) void UIAbilityImpl::AbilityTransactionCallback(const AAFwk::AbilityLifeCycleState &state) { TAG_LOGD(AAFwkTag::UIABILITY, "called"); - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { lifecycleState_ = AAFwk::ABILITY_STATE_FOREGROUND_NEW; std::string entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData()); if (ret == ERR_OK && state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } @@ -419,9 +418,8 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground() TAG_LOGE(AAFwkTag::UIABILITY, "null owner"); return; } - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); bool needNotifyAMS = false; { @@ -438,13 +436,13 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground() if (needNotifyAMS) { TAG_LOGI(AAFwkTag::UIABILITY, "notify ability manager service"); entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); owner->lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND_NEW; AppExecFwk::PacMap restoreData; auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone( token_, AAFwk::AbilityLifeCycleState::ABILITY_STATE_FOREGROUND_NEW, restoreData); if (ret == ERR_OK) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } @@ -454,15 +452,14 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterBackground() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::UIABILITY, "Lifecycle:call"); - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND }; std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); AppExecFwk::PacMap restoreData; auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone( token_, AAFwk::AbilityLifeCycleState::ABILITY_STATE_BACKGROUND_NEW, restoreData); if (ret == ERR_OK) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } } @@ -490,9 +487,8 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterUnfocused() void UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed(int32_t type) { TAG_LOGE(AAFwkTag::UIABILITY, "scb call, ForegroundFailed"); - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "ERROR UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed; GoForeground failed."; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AppendLifecycleEvent(token_, entry); AppExecFwk::PacMap restoreData; switch (type) { case static_cast(OHOS::Rosen::WMError::WM_ERROR_INVALID_OPERATION): { diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index ae045b8522..6d419a6dca 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -167,17 +167,16 @@ void UIAbilityThread::AttachInner(const std::shared_ptrAttachAbilityThread(this, token_); if (err != ERR_OK) { entry = std::string("AbilityThread::Attach failed ipc error: ") + std::to_string(err); - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); TAG_LOGE(AAFwkTag::UIABILITY, "err: %{public}d", err); return; } - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(0); } @@ -250,14 +249,12 @@ void UIAbilityThread::HandleAbilityTransaction( void UIAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) const { if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) { - FreezeUtil::LifecycleFlow flow = { token_, FreezeUtil::TimeoutState::BACKGROUND }; std::string entry = "AbilityThread::" + methodName + "; the background lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } } diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp index 7a8cf09e5e..a9768d4282 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp @@ -16,6 +16,7 @@ #include "js_ability_stage.h" #include "ability_delegator_registry.h" +#include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "js_ability_stage_context.h" #include "js_context_utils.h" @@ -72,6 +73,7 @@ std::shared_ptr JsAbilityStage::Create( TAG_LOGW(AAFwkTag::APPKIT, "runtime is nullptr"); return nullptr; } + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::Create"); auto& jsRuntime = static_cast(*runtime); std::string srcPath(hapModuleInfo.name); std::string moduleName(hapModuleInfo.moduleName); @@ -169,8 +171,10 @@ void JsAbilityStage::OnCreate(const AAFwk::Want &want) const TAG_LOGE(AAFwkTag::APPKIT, "Failed to get 'onCreate' from AbilityStage object"); return; } + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::OnCreate begin"); HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); napi_call_function(env, obj, methodOnCreate, 0, nullptr, nullptr); + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "JsAbilityStage::OnCreate end"); auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); if (delegator) { diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 88d855cf1b..c5dd41ff4d 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -734,9 +734,8 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptrSetBgWorkingThreadStatus(IsBgWorkingThread(info)); tmpWatchdog = nullptr; } - FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD }; std::string entry = "MainThread::ScheduleLaunchAbility; the load lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token, entry); wptr weak = this; auto task = [weak, abilityRecord]() { @@ -2159,9 +2158,8 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & auto abilityToken = abilityRecord->GetToken(); CHECK_POINTER_LOG(abilityToken, "abilityRecord->GetToken failed"); - FreezeUtil::LifecycleFlow flow = { abilityToken, FreezeUtil::TimeoutState::LOAD }; std::string entry = "MainThread::HandleLaunchAbility; the load lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(abilityToken, entry); abilityRecordMgr_->SetToken(abilityToken); abilityRecordMgr_->AddAbilityRecord(abilityToken, abilityRecord); diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index b94f940621..65f9761058 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -188,9 +188,8 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) FaultData faultData; faultData.errorObject.message = it->errorObject.message + "\n"; if (it->state != 0) { - FreezeUtil::LifecycleFlow flow = { it->token, static_cast(it->state) }; faultData.errorObject.message += "client:\n" + - FreezeUtil::GetInstance().GetLifecycleEvent(flow) + "\nclient app:\n" + + FreezeUtil::GetInstance().GetLifecycleEvent(it->token) + "\nclient app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(0) + "\n"; } faultData.errorObject.stack = stack; diff --git a/interfaces/inner_api/ability_manager/include/ability_state.h b/interfaces/inner_api/ability_manager/include/ability_state.h index 91e2d28e8b..b37b6cf158 100644 --- a/interfaces/inner_api/ability_manager/include/ability_state.h +++ b/interfaces/inner_api/ability_manager/include/ability_state.h @@ -67,11 +67,6 @@ enum UserStatus { ASSERT_CONTINUE, ASSERT_RETRY, }; - -enum class FreezeStrategy : uint8_t { - PRINT_FREEZE_LOG, - NOTIFY_FREEZE_MGR, -}; } // namespace AAFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_ABILITY_STATE_H diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 210326f3fd..bb1a578108 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -61,9 +61,6 @@ ohos_shared_library("app_manager") { "src/appmgr/app_debug_info.cpp", "src/appmgr/app_debug_listener_proxy.cpp", "src/appmgr/app_debug_listener_stub.cpp", - "src/appmgr/app_exception_callback_proxy.cpp", - "src/appmgr/app_exception_callback_stub.cpp", - "src/appmgr/app_exception_manager.cpp", "src/appmgr/app_foreground_state_observer_proxy.cpp", "src/appmgr/app_foreground_state_observer_stub.cpp", "src/appmgr/app_jsheap_mem_info.cpp", diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index b0adff0e71..0e2bacdedd 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -454,8 +454,6 @@ public: return false; } - virtual void SetAppExceptionCallback(sptr callback) {} - enum class Message { LOAD_ABILITY = 0, TERMINATE_ABILITY, @@ -509,7 +507,6 @@ public: IS_PROCESS_ATTACHED, IS_CALLER_KILLING, ENABLE_START_PROCESS_FLAG_BY_USER_ID, - SET_APP_EXCEPTION_CALLBACK, SET_KEEP_ALIVE_DKV, // Add enumeration values above END diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 1b25574e3a..9b3c90d4c2 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -402,8 +402,6 @@ public: virtual bool IsCallerKilling(const std::string& callerKey) override; - virtual void SetAppExceptionCallback(sptr callback) override; - private: bool WriteInterfaceToken(MessageParcel &data); int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index 7531a90964..15eda6a711 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -103,7 +103,6 @@ private: int32_t HandleIsProcessContainsOnlyUIAbility(MessageParcel &data, MessageParcel &reply); int32_t HandleIsProcessAttached(MessageParcel &data, MessageParcel &reply); int32_t HandleIsCallerKilling(MessageParcel &data, MessageParcel &reply); - int32_t HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(AmsMgrStub); }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_proxy.h deleted file mode 100644 index 16b571960b..0000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_proxy.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H -#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H - -#include "iapp_exception_callback.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace AppExecFwk { -class AppExceptionCallbackProxy : public IRemoteProxy { -public: - explicit AppExceptionCallbackProxy(const sptr &impl); - virtual ~AppExceptionCallbackProxy() = default; - - /** - * Notify abilityManager lifecycle exception. - * - * @param type lifecycle failed type - * @param token associated ability - */ - virtual void OnLifecycleException(LifecycleException type, sptr token); -private: - bool WriteInterfaceToken(MessageParcel &data); - static inline BrokerDelegator delegator_; - int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_PROXY_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_stub.h deleted file mode 100644 index 686fe9a38e..0000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/app_exception_callback_stub.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H -#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H - -#include "iapp_exception_callback.h" -#include "iremote_stub.h" -#include "nocopyable.h" - -namespace OHOS { -namespace AppExecFwk { -class AppExceptionCallbackStub : public IRemoteStub { -public: - AppExceptionCallbackStub() = default; - virtual ~AppExceptionCallbackStub() = default; - - virtual int32_t OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; -private: - int32_t HandleLifecycleException(MessageParcel &data, MessageParcel &reply); - - DISALLOW_COPY_AND_MOVE(AppExceptionCallbackStub); -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_CALLBACK_STUB_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_exception_manager.h b/interfaces/inner_api/app_manager/include/appmgr/app_exception_manager.h deleted file mode 100644 index 126eecdb60..0000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/app_exception_manager.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H -#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H - -#include "iapp_exception_callback.h" - -namespace OHOS { -namespace AppExecFwk { -class AppExceptionManager { -public: - static AppExceptionManager &GetInstance(); - AppExceptionManager(AppExceptionManager &) = delete; - void operator=(AppExceptionManager &) = delete; - - void LaunchAbilityFailed(sptr token, const std::string &msg); - void ForegroundAppFailed(sptr token, const std::string &msg); - void ForegroundAppWait(sptr token, const std::string &msg); - - void NotifyLifecycleException(LifecycleException type, sptr token); - void SetExceptionCallback(sptr exceptionCallback); - sptr GetExceptionCallback() const; -private: - AppExceptionManager() = default; - mutable std::mutex exceptionCallbackMutex_; - sptr exceptionCallback_; -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_MANAGER_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/iapp_exception_callback.h b/interfaces/inner_api/app_manager/include/appmgr/iapp_exception_callback.h deleted file mode 100644 index 40e2355f6e..0000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/iapp_exception_callback.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H -#define OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H - -#include "iremote_broker.h" -#include "iremote_object.h" - -namespace OHOS { -namespace AppExecFwk { -enum class LifecycleException { - LAUNCH_ABILITY_FAIL, - FOREGROUND_APP_FAIL, - FOREGROUND_APP_WAIT, - END -}; - -class IAppExceptionCallback : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppExceptionCallback"); - - /** - * Notify abilityManager lifecycle exception. - * - * @param type lifecycle failed type - * @param token associated ability - */ - virtual void OnLifecycleException(LifecycleException type, sptr token) {} - - enum class Message { - LIFECYCLE_EXCEPTION_MSG_ID = 0, - }; -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_I_APP_EXCEPTION_CALLBACK_H diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index a485eb4a60..a53f738896 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -1365,27 +1365,5 @@ bool AmsMgrProxy::IsCallerKilling(const std::string& callerKey) } return reply.ReadBool(); } - -void AmsMgrProxy::SetAppExceptionCallback(sptr callback) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); - return; - } - if (!data.WriteRemoteObject(callback.GetRefPtr())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callback"); - return; - } - - auto ret = SendTransactCmd(static_cast(IAmsMgr::Message::SET_APP_EXCEPTION_CALLBACK), - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret); - return; - } -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 354e16c250..626661dd8a 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -874,12 +874,5 @@ int32_t AmsMgrStub::HandleIsCallerKilling(MessageParcel &data, MessageParcel &re } return NO_ERROR; } - -int32_t AmsMgrStub::HandleSetAppExceptionCallback(MessageParcel &data, MessageParcel &reply) -{ - sptr callback = data.ReadRemoteObject(); - SetAppExceptionCallback(callback); - return NO_ERROR; -} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_proxy.cpp deleted file mode 100644 index e23d723ae1..0000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_proxy.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app_exception_callback_proxy.h" - -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AppExecFwk { -AppExceptionCallbackProxy::AppExceptionCallbackProxy(const sptr &impl) - : IRemoteProxy(impl) {} - -bool AppExceptionCallbackProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(AppExceptionCallbackProxy::GetDescriptor())) { - TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed"); - return false; - } - return true; -} - -int32_t AppExceptionCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr."); - return ERR_NULL_OBJECT; - } - - auto ret = remote->SendRequest(code, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret); - return ret; - } - return ret; -} - -void AppExceptionCallbackProxy::OnLifecycleException(LifecycleException type, sptr token) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - return; - } - - int32_t exceptionType = static_cast(type); - if (!data.WriteInt32(exceptionType)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write exceptionType"); - return; - } - - if (token) { - if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token"); - return; - } - } else { - if (!data.WriteBool(false)) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag"); - return; - } - } - - int32_t ret = SendTransactCmd( - static_cast(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID), data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_stub.cpp deleted file mode 100644 index 10e7b8dc77..0000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/app_exception_callback_stub.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app_exception_callback_stub.h" - -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AppExecFwk { -int32_t AppExceptionCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - std::u16string descriptor = AppExceptionCallbackStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote"); - return ERR_INVALID_STATE; - } - - switch (code) { - case static_cast(IAppExceptionCallback::Message::LIFECYCLE_EXCEPTION_MSG_ID): - return HandleLifecycleException(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t AppExceptionCallbackStub::HandleLifecycleException(MessageParcel &data, MessageParcel &reply) -{ - auto type = data.ReadInt32(); - if (type < 0 || type > static_cast(LifecycleException::END)) { - return ERR_INVALID_STATE; - } - auto lifecycleExceptType = static_cast(type); - sptr token; - if (data.ReadBool()) { - token = data.ReadRemoteObject(); - } - OnLifecycleException(lifecycleExceptType, token); - return ERR_OK; -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_exception_manager.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_exception_manager.cpp deleted file mode 100644 index 164b960207..0000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/app_exception_manager.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app_exception_manager.h" - -#include "freeze_util.h" -#include "hilog_tag_wrapper.h" - -namespace OHOS { -using AbilityRuntime::FreezeUtil; -namespace AppExecFwk { -AppExceptionManager &AppExceptionManager::GetInstance() -{ - static AppExceptionManager appExceptionMgr; - return appExceptionMgr; -} - -void AppExceptionManager::LaunchAbilityFailed(sptr token, const std::string &msg) -{ - FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::LOAD}; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("LaunchAbilityFailed: " + msg)); - NotifyLifecycleException(LifecycleException::LAUNCH_ABILITY_FAIL, token); -} - -void AppExceptionManager::ForegroundAppFailed(sptr token, const std::string &msg) -{ - FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND}; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppFailed: " + msg)); - NotifyLifecycleException(LifecycleException::FOREGROUND_APP_FAIL, token); -} - -void AppExceptionManager::ForegroundAppWait(sptr token, const std::string &msg) -{ - FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND}; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("ForegroundAppWait: " + msg)); - NotifyLifecycleException(LifecycleException::FOREGROUND_APP_WAIT, token); -} - -void AppExceptionManager::NotifyLifecycleException(LifecycleException type, sptr token) -{ - auto callback = GetExceptionCallback(); - if (callback != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "notify app exception"); - callback->OnLifecycleException(type, token); - } -} - -void AppExceptionManager::SetExceptionCallback(sptr exceptionCallback) -{ - if (exceptionCallback == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "callback null"); - } - std::lock_guard lock(exceptionCallbackMutex_); - if (exceptionCallback_ != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "inner callback not null"); - } - exceptionCallback_ = exceptionCallback; -} - -sptr AppExceptionManager::GetExceptionCallback() const -{ - std::lock_guard lock(exceptionCallbackMutex_); - return exceptionCallback_; -} -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index dd12d8867e..f351f78ba4 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -15,7 +15,7 @@ #include "app_scheduler_proxy.h" -#include "app_exception_manager.h" +#include "error_msg_util.h" #include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" @@ -46,6 +46,9 @@ bool AppSchedulerProxy::ScheduleForegroundApplication() if (!WriteInterfaceToken(data)) { return false; } + auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast(this), + "ScheduleForegroundRunning"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "AppScheduler::ScheduleForegroundApplication"); int32_t ret = SendTransactCmd(static_cast(IAppScheduler::Message::SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION), data, @@ -53,6 +56,8 @@ bool AppSchedulerProxy::ScheduleForegroundApplication() option); if (ret != NO_ERROR) { TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, + std::string("ScheduleForegroundApplication ipc error ") + std::to_string(ret)); return false; } return true; @@ -193,7 +198,6 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt return; } data.WriteParcelable(&info); - AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD}; if (token) { if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) { TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token"); @@ -208,7 +212,7 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt if (!data.WriteParcelable(want.get())) { TAG_LOGE(AAFwkTag::APPMGR, "write want fail."); - AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, "ERROR AppLifeCycleDeal::LaunchAbility; write want fail"); return; } @@ -220,8 +224,8 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt static_cast(IAppScheduler::Message::SCHEDULE_LAUNCH_ABILITY_TRANSACTION), data, reply, option); if (ret != NO_ERROR) { TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - AppExceptionManager::GetInstance().LaunchAbilityFailed(token, std::string("SendRequest failed") + - std::to_string(ret)); + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, + "ERROR AppLifeCycleDeal::LaunchAbility; ipc fail " + std::to_string(ret)); } } @@ -258,13 +262,18 @@ void AppSchedulerProxy::ScheduleLaunchApplication(const AppLaunchData &launchDat return; } + auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast(this), + "LaunchApplication"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "AppScheduler::ScheduleLaunchApplication"); if (!data.WriteParcelable(&launchData)) { TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable launchData failed"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write launchData fail"); return; } if (!data.WriteParcelable(&config)) { TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable config failed"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write config fail"); return ; } @@ -272,6 +281,8 @@ void AppSchedulerProxy::ScheduleLaunchApplication(const AppLaunchData &launchDat static_cast(IAppScheduler::Message::SCHEDULE_LAUNCH_APPLICATION_TRANSACTION), data, reply, option); if (ret != NO_ERROR) { TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, + std::string("ScheduleLaunchApplication ipc error ") + std::to_string(ret)); } } diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 7e7214fb8c..e557099e77 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -27,7 +27,6 @@ abilityms_files = [ "src/ability_manager_xcollie.cpp", "src/ability_scheduler_proxy.cpp", "src/ability_token_stub.cpp", - "src/app_exception_handler.cpp", "src/app_scheduler.cpp", "src/app_exit_reason_helper.cpp", "src/assert_fault_callback_death_mgr.cpp", diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index c33e4cf67a..290fb38e27 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1121,16 +1121,6 @@ public: return securityFlag_; } - FreezeStrategy GetFreezeStrategy() const - { - return freezeStrategy_; - } - - void SetFreezeStrategy(FreezeStrategy value) - { - freezeStrategy_ = value; - } - protected: void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false); @@ -1357,7 +1347,6 @@ private: LaunchDebugInfo launchDebugInfo_; std::string instanceKey_ = ""; bool securityFlag_ = false; - std::atomic freezeStrategy_{FreezeStrategy::NOTIFY_FREEZE_MGR}; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/app_exception_handler.h b/services/abilitymgr/include/app_exception_handler.h deleted file mode 100644 index a94f98e376..0000000000 --- a/services/abilitymgr/include/app_exception_handler.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H -#define OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H - -#include - -#include "iremote_object.h" - -namespace OHOS { -namespace AAFwk { -class AppExceptionHandler { -public: - static AppExceptionHandler &GetInstance(); - AppExceptionHandler(AppExceptionHandler &) = delete; - void operator=(AppExceptionHandler &) = delete; - - void RegisterAppExceptionCallback(); - void AbilityForegroundFailed(sptr token, const std::string &msg); -private: - AppExceptionHandler() = default; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_APP_EXCEPTION_HANDLER_H diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index df81ca58bb..096503a013 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1336,7 +1336,6 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr &sche MessageParcel data; MessageParcel reply; MessageOption option; - AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD}; if (scheduler == nullptr) { return ERR_INVALID_VALUE; } @@ -1351,8 +1350,8 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr &sche error = SendRequest(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD, data, reply, option); if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); - AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, - std::string("ERROR AttachAbilityThread failed IPC error") + std::to_string(error)); + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, + std::string("ERROR AttachAbilityThread failed IPC error ") + std::to_string(error)); return error; } return reply.ReadInt32(); @@ -1365,7 +1364,6 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, MessageParcel reply; MessageOption option; - AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::FOREGROUND}; if (!WriteInterfaceToken(data)) { return INNER_ERR; } @@ -1375,7 +1373,7 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, } if (!data.WriteParcelable(&saveData)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write fail"); - AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, "write saveData failed"); return INNER_ERR; } @@ -1383,8 +1381,8 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, error = SendRequest(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE, data, reply, option); if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); - AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, - std::string("ERROR AbilityTransitionDone failed IPC error") + std::to_string(error)); + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, + std::string("ERROR AbilityTransitionDone failed IPC error ") + std::to_string(error)); return error; } return reply.ReadInt32(); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b7a9c242f7..8d3bf6f050 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -20,7 +20,6 @@ #include "ability_manager_radar.h" #include "accesstoken_kit.h" #include "ability_manager_xcollie.h" -#include "app_exception_handler.h" #include "app_utils.h" #include "app_exit_reason_data_manager.h" #include "application_util.h" @@ -5391,9 +5390,8 @@ int AbilityManagerService::AttachAbilityThread( } return dataAbilityManager->AttachAbilityThread(scheduler, token); } else { - FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD }; std::string entry = "AbilityManagerService::AttachAbilityThread; the end of load lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token, entry); int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId(); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { auto uiAbilityManager = GetUIAbilityManagerByUserId(ownerMissionUserId); @@ -5995,14 +5993,12 @@ int AbilityManagerService::AbilityTransitionDone(const sptr &toke } if (targetState == AbilityState::BACKGROUND) { - FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::BACKGROUND }; std::string entry = "AbilityManagerService::AbilityTransitionDone; the end of background lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token, entry); } else if (targetState != AbilityState::INITIAL) { - FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::FOREGROUND }; std::string entry = "AbilityManagerService::AbilityTransitionDone; the end of foreground lifecycle." " the end of foreground lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token, entry); } int32_t ownerMissionUserId = abilityRecord->GetOwnerMissionUserId(); @@ -7258,7 +7254,6 @@ void AbilityManagerService::ConnectServices() TAG_LOGE(AAFwkTag::ABILITYMGR, "failed init appScheduler"); usleep(REPOLL_TIME_MICRO_SECONDS); } - AppExceptionHandler::GetInstance().RegisterAppExceptionCallback(); TAG_LOGI(AAFwkTag::ABILITYMGR, "waiting bundleMgr service run completed"); while (AbilityUtil::GetBundleManagerHelper() == nullptr) { diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 4293b134b0..e0688b075f 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -20,7 +20,6 @@ #include "ability_manager_service.h" #include "ability_resident_process_rdb.h" #include "ability_scheduler_stub.h" -#include "app_exception_handler.h" #include "app_exit_reason_data_manager.h" #include "app_utils.h" #include "array_wrapper.h" @@ -28,6 +27,7 @@ #include "configuration_convertor.h" #include "connection_state_manager.h" #include "common_event_manager.h" +#include "error_msg_util.h" #include "freeze_util.h" #include "global_constant.h" #include "hitrace_meter.h" @@ -108,11 +108,10 @@ const int MAX_URI_COUNT = 500; const int RESTART_SCENEBOARD_DELAY = 500; constexpr int32_t DMS_UID = 5522; -auto g_addLifecycleEventTask = [](sptr token, FreezeUtil::TimeoutState state, std::string &methodName) { +auto g_addLifecycleEventTask = [](sptr token, std::string &methodName) { CHECK_POINTER_LOG(token, "token is nullptr"); - FreezeUtil::LifecycleFlow flow = { token->AsObject(), state }; std::string entry = std::string("AbilityRecord::") + methodName + "; the " + methodName + " lifecycle starts."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(token->AsObject(), entry); }; Token::Token(std::weak_ptr abilityRecord) : abilityRecord_(abilityRecord) @@ -308,7 +307,7 @@ void AbilityRecord::LoadUIAbility() SendEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, loadTimeout / HALF_TIMEOUT); SendEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, loadTimeout); std::string methodName = "LoadAbility"; - g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::LOAD, methodName); + g_addLifecycleEventTask(token_, methodName); } int AbilityRecord::LoadAbility(bool isShellCall) @@ -409,9 +408,9 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag) lifeCycleStateInfo_.sceneFlag = sceneFlag; Want want = GetWant(); UpdateDmsCallerInfo(want); - if (!lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo()) && token_) { - AppExceptionHandler::GetInstance().AbilityForegroundFailed(token_->AsObject(), "ForegroundNew"); - } + AbilityRuntime::ErrorMsgGuard errorMsgGuard(token_ ? token_->AsObject() : nullptr, + reinterpret_cast(GetScheduler().GetRefPtr()), "ScheduleAbilityTransaction"); + lifecycleDeal_->ForegroundNew(want, lifeCycleStateInfo_, GetSessionInfo()); lifeCycleStateInfo_.sceneFlag = 0; lifeCycleStateInfo_.sceneFlagBak = 0; { @@ -500,7 +499,7 @@ void AbilityRecord::PostForegroundTimeoutTask() SendEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, foregroundTimeout / HALF_TIMEOUT); SendEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, foregroundTimeout); std::string methodName = "ProcessForegroundAbility"; - g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::FOREGROUND, methodName); + g_addLifecycleEventTask(token_, methodName); ResSchedUtil::GetInstance().ReportLoadingEventToRss(LoadingStage::FOREGROUND_BEGIN, GetPid(), GetUid(), foregroundTimeout, GetAbilityRecordId()); } @@ -511,7 +510,6 @@ void AbilityRecord::RemoveForegroundTimeoutTask() CHECK_POINTER(handler); handler->RemoveEvent(AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG, GetAbilityRecordId()); handler->RemoveEvent(AbilityManagerService::FOREGROUND_TIMEOUT_MSG, GetAbilityRecordId()); - SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR); } void AbilityRecord::RemoveLoadTimeoutTask() @@ -520,7 +518,6 @@ void AbilityRecord::RemoveLoadTimeoutTask() CHECK_POINTER(handler); handler->RemoveEvent(AbilityManagerService::LOAD_HALF_TIMEOUT_MSG, GetAbilityRecordId()); handler->RemoveEvent(AbilityManagerService::LOAD_TIMEOUT_MSG, GetAbilityRecordId()); - SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR); } void AbilityRecord::PostUIExtensionAbilityTimeoutTask(uint32_t messageId) @@ -1270,7 +1267,7 @@ void AbilityRecord::BackgroundAbility(const Closure &task) if (abilityInfo_.type == AppExecFwk::AbilityType::PAGE) { std::string methodName = "BackgroundAbility"; - g_addLifecycleEventTask(token_, FreezeUtil::TimeoutState::BACKGROUND, methodName); + g_addLifecycleEventTask(token_, methodName); } } } else { diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index d10f2da969..d3d02ce1e3 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -19,6 +19,7 @@ #include "data_ability_operation.h" #include "data_ability_predicates.h" #include "data_ability_result.h" +#include "error_msg_util.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" #include "ishared_result_set.h" @@ -52,14 +53,18 @@ bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L if (!WriteInterfaceToken(data)) { return false; } + auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast(this), + "ScheduleAbilityTransaction"); if (!data.WriteParcelable(&want)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed"); return false; } data.WriteParcelable(&stateInfo); if (sessionInfo) { if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed"); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write sessionInfo failed"); return false; } } else { @@ -70,6 +75,8 @@ bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const L int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_TRANSACTION, data, reply, option); if (err != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err); + AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, + std::string("ScheduleAbilityTransaction ipc error " + std::to_string(err))); return false; } int64_t cost = std::chrono::duration_cast( diff --git a/services/abilitymgr/src/app_exception_handler.cpp b/services/abilitymgr/src/app_exception_handler.cpp deleted file mode 100644 index af0976f87b..0000000000 --- a/services/abilitymgr/src/app_exception_handler.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "app_exception_handler.h" - -#include "ability_record.h" -#include "app_exception_callback_stub.h" -#include "app_mgr_util.h" -#include "freeze_util.h" -#include "hilog_tag_wrapper.h" - -namespace OHOS { -using AppExecFwk::LifecycleException; -using AbilityRuntime::FreezeUtil; -namespace AAFwk { -namespace { -class AppExceptionCallback : public AppExecFwk::AppExceptionCallbackStub { - /** - * Notify abilityManager lifecycle exception. - * - * @param type lifecycle failed type - * @param token associated ability - */ - void OnLifecycleException(LifecycleException type, sptr token) override - { - auto abilityRecord = Token::GetAbilityRecordByToken(token); - if (abilityRecord == nullptr) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null"); - return; - } - - TAG_LOGI(AAFwkTag::ABILITYMGR, "lifecycle exception: %{public}s, %{public}d", - abilityRecord->GetURI().c_str(), type); - abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR); - } -}; -} - -AppExceptionHandler &AppExceptionHandler::GetInstance() -{ - static AppExceptionHandler appExceptionHandler; - return appExceptionHandler; -} - -void AppExceptionHandler::RegisterAppExceptionCallback() -{ - auto appMgr = AppMgrUtil::GetAppMgr(); - if (appMgr == nullptr) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed"); - return; - } - - auto service = appMgr->GetAmsMgr(); - if (service == nullptr) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "GetAmsMgr failed"); - return; - } - auto callback = sptr(new AppExceptionCallback()); - service->SetAppExceptionCallback(callback->AsObject()); -} - -void AppExceptionHandler::AbilityForegroundFailed(sptr token, const std::string &msg) -{ - auto abilityRecord = Token::GetAbilityRecordByToken(token); - if (abilityRecord == nullptr) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "abilityRecord null"); - return; - } - FreezeUtil::LifecycleFlow flow{token, FreezeUtil::TimeoutState::FOREGROUND}; - FreezeUtil::GetInstance().AppendLifecycleEvent(flow, std::string("AbilityForegroundFailed: " + msg)); - - TAG_LOGI(AAFwkTag::ABILITYMGR, "AbilityForegroundFailed: %{public}s", abilityRecord->GetURI().c_str()); - abilityRecord->SetFreezeStrategy(FreezeStrategy::NOTIFY_FREEZE_MGR); -} -} // namespace AAFwk -} // namespace OHOS diff --git a/services/abilitymgr/src/mission/mission_list_manager.cpp b/services/abilitymgr/src/mission/mission_list_manager.cpp index 85de58bfdf..511362a6a7 100644 --- a/services/abilitymgr/src/mission/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission/mission_list_manager.cpp @@ -89,10 +89,9 @@ FreezeUtil::TimeoutState MsgId2State(uint32_t msgId) return FreezeUtil::TimeoutState::UNKNOWN; } -auto g_deleteLifecycleEventTask = [](const sptr &token, FreezeUtil::TimeoutState state) { +auto g_deleteLifecycleEventTask = [](const sptr &token) { CHECK_POINTER_LOG(token, "token is nullptr."); - FreezeUtil::LifecycleFlow flow = { token->AsObject(), state }; - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token->AsObject()); }; } // namespace @@ -1015,8 +1014,7 @@ int MissionListManager::AttachAbilityThread(const sptr &sched CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); abilityRecord->RemoveLoadTimeoutTask(); abilityRecord->SetLoading(false); - FreezeUtil::LifecycleFlow flow = { token, FreezeUtil::TimeoutState::LOAD }; - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token); abilityRecord->SetScheduler(scheduler); @@ -1256,7 +1254,7 @@ int MissionListManager::DispatchForeground(const std::shared_ptr auto eventHandler = AbilityManagerService::GetPubInstance()->GetEventHandler(); CHECK_POINTER_AND_RETURN_LOG(eventHandler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); abilityRecord->RemoveForegroundTimeoutTask(); - g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND); + g_deleteLifecycleEventTask(abilityRecord->GetToken()); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid()); auto self(weak_from_this()); auto taskHandler = AbilityManagerService::GetPubInstance()->GetTaskHandler(); @@ -1394,7 +1392,7 @@ int MissionListManager::DispatchBackground(const std::shared_ptr // remove background timeout task. handler->CancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); - g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::BACKGROUND); + g_deleteLifecycleEventTask(abilityRecord->GetToken()); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid()); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); }; @@ -2249,20 +2247,16 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr &a flow.token = ability->GetToken()->AsObject(); flow.state = state; } - info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow) + info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) + "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); if (!isHalf) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(ability->GetPid()); } } else { info.msg = msgContent; } - if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) { - AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow); - } else { - TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str()); - } + AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow); } bool MissionListManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 49777c7c2e..dbcd88cbde 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -68,10 +68,9 @@ FreezeUtil::TimeoutState MsgId2State(uint32_t msgId) return FreezeUtil::TimeoutState::UNKNOWN; } -auto g_deleteLifecycleEventTask = [](const sptr &token, FreezeUtil::TimeoutState state) { +auto g_deleteLifecycleEventTask = [](const sptr &token) { CHECK_POINTER_LOG(token, "token is nullptr."); - FreezeUtil::LifecycleFlow flow = { token->AsObject(), state }; - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token->AsObject()); }; } @@ -294,8 +293,7 @@ int UIAbilityLifecycleManager::AttachAbilityThread(const sptr CHECK_POINTER_AND_RETURN_LOG(handler, ERR_INVALID_VALUE, "Fail to get AbilityEventHandler."); abilityRecord->RemoveLoadTimeoutTask(); abilityRecord->SetLoading(false); - FreezeUtil::LifecycleFlow flow = {token, FreezeUtil::TimeoutState::LOAD}; - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token); abilityRecord->SetScheduler(scheduler); if (DoProcessAttachment(abilityRecord) != ERR_OK) { @@ -551,7 +549,7 @@ int UIAbilityLifecycleManager::DispatchForeground(const std::shared_ptrRemoveForegroundTimeoutTask(); - g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::FOREGROUND); + g_deleteLifecycleEventTask(abilityRecord->GetToken()); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid()); auto self(weak_from_this()); if (success) { @@ -602,7 +600,7 @@ int UIAbilityLifecycleManager::DispatchBackground(const std::shared_ptrCancelTask("background_" + std::to_string(abilityRecord->GetAbilityRecordId())); - g_deleteLifecycleEventTask(abilityRecord->GetToken(), FreezeUtil::TimeoutState::BACKGROUND); + g_deleteLifecycleEventTask(abilityRecord->GetToken()); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(abilityRecord->GetPid()); auto self(shared_from_this()); auto task = [self, abilityRecord]() { self->CompleteBackground(abilityRecord); }; @@ -1211,20 +1209,16 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr a flow.token = ability->GetToken()->AsObject(); flow.state = state; } - info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow) + info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) + "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); if (!isHalf) { - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(processInfo.pid_); } } else { info.msg = msgContent; } - if (ability->GetFreezeStrategy() == FreezeStrategy::NOTIFY_FREEZE_MGR) { - AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow); - } else { - TAG_LOGW(AAFwkTag::ABILITYMGR, "%{public}s", info.msg.c_str()); - } + AppExecFwk::AppfreezeManager::GetInstance()->LifecycleTimeoutHandle(info, flow); } bool UIAbilityLifecycleManager::GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 2e9a39ef1d..f9f50a4e50 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -429,8 +429,6 @@ public: virtual bool IsCallerKilling(const std::string& callerKey) override; - virtual void SetAppExceptionCallback(sptr callback) override; - private: /** * @brief Judge whether the application service is ready. diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index ebc270a0cf..263c0897e9 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -938,6 +938,7 @@ public: bool GetIsGPU(); void SetGPUPid(pid_t gpuPid); pid_t GetGPUPid(); + pid_t GetPid(); inline void SetStrictMode(bool strictMode) { @@ -1021,9 +1022,9 @@ public: void AddAppLifecycleEvent(const std::string &msg); void SetNWebPreload(const bool isAllowedNWebPreload); - + void SetIsUnSetPermission(bool isUnSetPermission); - + bool IsUnSetPermission(); private: /** diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index f3858935a3..a95c7789bf 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -22,7 +22,6 @@ #include "accesstoken_kit.h" #include "app_death_recipient.h" -#include "app_exception_manager.h" #include "app_mgr_constants.h" #include "app_utils.h" #include "hilog_tag_wrapper.h" @@ -760,25 +759,5 @@ bool AmsMgrScheduler::IsCallerKilling(const std::string& callerKey) } return amsMgrServiceInner_->IsCallerKilling(callerKey); } - -void AmsMgrScheduler::SetAppExceptionCallback(sptr callback) -{ - if (!IsReady()) { - TAG_LOGE(AAFwkTag::APPMGR, "AmsMgrService is not ready."); - return; - } - pid_t callingPid = IPCSkeleton::GetCallingPid(); - pid_t procPid = getprocpid(); - if (callingPid != procPid) { - TAG_LOGE(AAFwkTag::APPMGR, "not allow other process to call"); - return; - } - - if (callback == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "callback null"); - } - auto exceptionCallback = iface_cast(callback); - return AppExceptionManager::GetInstance().SetExceptionCallback(exceptionCallback); -} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index ce3195eec1..621379d666 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -75,9 +75,8 @@ void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr return; } if (abilityInfo->type == AbilityType::PAGE) { - FreezeUtil::LifecycleFlow flow = {ability->GetToken(), FreezeUtil::TimeoutState::LOAD}; std::string entry = "AppLifeCycleDeal::LaunchAbility; the LoadAbility lifecycle."; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + FreezeUtil::GetInstance().AddLifecycleEvent(ability->GetToken(), entry); } TAG_LOGD(AAFwkTag::APPMGR, "Launch"); appThread->ScheduleLaunchAbility(*abilityInfo, ability->GetToken(), diff --git a/services/appmgr/src/app_mgr_event.cpp b/services/appmgr/src/app_mgr_event.cpp index 09a77df5f8..ef58671217 100644 --- a/services/appmgr/src/app_mgr_event.cpp +++ b/services/appmgr/src/app_mgr_event.cpp @@ -33,8 +33,8 @@ int32_t AppMgrEventUtil::GetCallerPid(const std::shared_ptr &c TAG_LOGW(AAFwkTag::APPMGR, "null priorityObject"); return IPCSkeleton::GetCallingPid(); } - - return callerAppRecord->GetPriorityObject()->GetPid(); + + return callerAppRecord->GetPid(); } void AppMgrEventUtil::UpdateStartupType(const std::shared_ptr &abilityInfo, int32_t &abilityType, @@ -125,7 +125,7 @@ bool AppMgrEventUtil::SendProcessStartEvent(const std::shared_ptrGetPriorityObject()) { TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject"); } else { - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); } AAFwk::EventReport::SendProcessStartEvent(AAFwk::EventName::PROCESS_START, eventInfo); return true; @@ -165,7 +165,7 @@ bool AppMgrEventUtil::SendProcessStartFailedEvent(std::shared_ptrGetPriorityObject()) { TAG_LOGE(AAFwkTag::APPMGR, "null priorityObject"); } else { - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); } AAFwk::EventReport::SendProcessStartFailedEvent(AAFwk::EventName::PROCESS_START_FAILED, eventInfo); return true; @@ -213,7 +213,7 @@ bool AppMgrEventUtil::SendChildProcessStartFailedEvent(std::shared_ptrGetUid(); - eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1; + eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPid() : -1; eventInfo.callerBundleName = hostRecord->GetBundleName(); eventInfo.callerProcessName = hostRecord->GetProcessName(); eventInfo.bundleName = hostRecord->GetBundleName(); @@ -245,7 +245,7 @@ bool AppMgrEventUtil::SendRenderProcessStartFailedEvent(std::shared_ptrGetUid(); - eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1; + eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPid() : -1; eventInfo.callerBundleName = hostRecord->GetBundleName(); eventInfo.callerProcessName = hostRecord->GetProcessName(); eventInfo.bundleName = hostRecord->GetBundleName(); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index baf120f45c..87413193d5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -599,14 +599,14 @@ int32_t AppMgrServiceInner::ProcessKia(bool isKia, std::shared_ptr(WindowManager::GetInstance().SetProcessWatermark( - appRecord->GetPriorityObject()->GetPid(), watermarkBusinessName, isWatermarkEnabled)); + appRecord->GetPid(), watermarkBusinessName, isWatermarkEnabled)); if (resultCode != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "setting watermark fails with result code:%{public}d", resultCode); return resultCode; } TAG_LOGI(AAFwkTag::APPMGR, "setting watermark succeeds, start setting snapshot skip"); resultCode = static_cast(WindowManager::GetInstance().SkipSnapshotForAppProcess( - appRecord->GetPriorityObject()->GetPid(), isWatermarkEnabled)); + appRecord->GetPid(), isWatermarkEnabled)); if (resultCode != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "setting snapshot skip fails with result code:%{public}d", resultCode); return resultCode; @@ -629,10 +629,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s return; } if (abilityInfo->type == AbilityType::PAGE) { - AbilityRuntime::FreezeUtil::LifecycleFlow flow = {loadParam->token, - AbilityRuntime::FreezeUtil::TimeoutState::LOAD}; std::string entry = "AppMgrServiceInner::LoadAbility; the load lifecycle."; - AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); + AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(loadParam->token, entry); } if (!appRunningManager_) { @@ -800,7 +798,7 @@ void AppMgrServiceInner::AddUIExtensionLauncherItem(std::shared_ptr auto hostPid = want->GetIntParam(UIEXTENSION_ROOT_HOST_PID, -1); pid_t providerPid = -1; if (appRecord->GetPriorityObject() != nullptr) { - providerPid = appRecord->GetPriorityObject()->GetPid(); + providerPid = appRecord->GetPid(); } if (uiExtensionAbilityId == -1 || hostPid == -1 || providerPid == -1) { TAG_LOGE(AAFwkTag::APPMGR, "invalid want params"); @@ -1143,7 +1141,7 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptrGetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); eventInfo.processName = appRecord->GetProcessName(); AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_ATTACH, HiSysEventType::BEHAVIOR, eventInfo); } @@ -1341,7 +1339,7 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId) return; } // Prevent forged requests from changing the app's state. - appRecord->AddAppLifecycleEvent("ServiceInner::ForeForegrounded"); + appRecord->AddAppLifecycleEvent("ServiceInner::AppBackgrounded"); if (appRecord->GetApplicationScheduleState() != ApplicationScheduleState::SCHEDULE_BACKGROUNDING) { TAG_LOGE(AAFwkTag::APPMGR, "app is not scheduling to background"); return; @@ -1387,7 +1385,7 @@ AAFwk::EventInfo AppMgrServiceInner::BuildEventInfo(std::shared_ptr(applicationInfo->bundleType); } if (appRecord->GetPriorityObject() != nullptr) { - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); } eventInfo.processName = appRecord->GetProcessName(); eventInfo.processType = static_cast(appRecord->GetProcessType()); @@ -1430,7 +1428,7 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId) eventInfo.versionCode = applicationInfo->versionCode; } ClearAppRunningDataForKeepAlive(appRecord); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); eventInfo.processName = appRecord->GetProcessName(); AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_TERMINATE, HiSysEventType::BEHAVIOR, eventInfo); @@ -1636,7 +1634,7 @@ void AppMgrServiceInner::SendProcessExitEventTask( TAG_LOGE(AAFwkTag::APPMGR, "priority object null"); return; } - auto pid = appRecord->GetPriorityObject()->GetPid(); + auto pid = appRecord->GetPid(); auto exitResult = !ProcessExist(pid); constexpr int32_t EXIT_SUCESS = 0; constexpr int32_t EXIT_FAILED = -1; @@ -2386,7 +2384,7 @@ void AppMgrServiceInner::GetRunningProcess(const std::shared_ptrGetProcessName(); - info.pid_ = appRecord->GetPriorityObject()->GetPid(); + info.pid_ = appRecord->GetPid(); info.uid_ = appRecord->GetUid(); info.state_ = static_cast(appRecord->GetState()); info.isContinuousTask = appRecord->IsContinuousTask(); @@ -2447,7 +2445,7 @@ void AppMgrServiceInner::GetChildrenProcesses(const std::shared_ptrGetPriorityObject()->GetPid(), childProcessRecord->GetPid()); + appRecord->GetPid(), childProcessRecord->GetPid()); continue; } info.emplace_back(childProcessInfo); @@ -2506,7 +2504,7 @@ int32_t AppMgrServiceInner::KillProcessByPidInner(const pid_t pid, const std::st killedProcessMap_.emplace(killTime, appRecord->GetProcessName()); } DelayedSingleton::GetInstance()->OnProcessKilled(appRecord); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); eventInfo.processName = appRecord->GetProcessName(); bool foreground = appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND || appRecord->GetState() == ApplicationState::APP_STATE_FOCUS; @@ -2679,8 +2677,9 @@ void AppMgrServiceInner::UpdateAbilityState(const sptr &token, co return; } - AbilityRuntime::FreezeUtil::LifecycleFlow flow{token, AbilityRuntime::FreezeUtil::TimeoutState::FOREGROUND}; - AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow, "ServiceInner::UpdateAbilityState"); + if (state == AbilityState::ABILITY_STATE_BACKGROUND) { + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, "ServiceInner::UpdateAbilityState"); + } auto appRecord = GetAppRunningRecordByAbilityToken(token); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "app unexist"); @@ -2861,7 +2860,7 @@ void AppMgrServiceInner::KillProcessByAbilityToken(const sptr &to return; } - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (pid > 0) { std::list pids; pids.push_back(pid); @@ -2925,7 +2924,7 @@ void AppMgrServiceInner::AttachPidToParent(const sptr &token, con TAG_LOGE(AAFwkTag::APPMGR, "abilityRecord null"); return; } - auto pid = appRecord->GetPriorityObject()->GetPid(); + auto pid = appRecord->GetPid(); if (pid <= 0) { TAG_LOGE(AAFwkTag::APPMGR, "invalid pid"); return; @@ -3091,7 +3090,7 @@ void AppMgrServiceInner::OnAppStarted(const std::shared_ptr &a } TAG_LOGD(AAFwkTag::APPMGR, "OnAppStarted begin, bundleName is %{public}s, pid:%{public}d", - appRecord->GetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid()); + appRecord->GetBundleName().c_str(), appRecord->GetPid()); DelayedSingleton::GetInstance()->OnAppStarted(appRecord); } @@ -3111,7 +3110,7 @@ void AppMgrServiceInner::OnAppStopped(const std::shared_ptr &a } TAG_LOGD(AAFwkTag::APPMGR, "OnAppStopped begin, bundleName is %{public}s, pid:%{public}d", - appRecord->GetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid()); + appRecord->GetBundleName().c_str(), appRecord->GetPid()); DelayedSingleton::GetInstance()->OnAppStopped(appRecord); } @@ -3128,7 +3127,7 @@ AppProcessData AppMgrServiceInner::WrapAppProcessData(const std::shared_ptrGetProcessName(); - processData.pid = appRecord->GetPriorityObject()->GetPid(); + processData.pid = appRecord->GetPid(); processData.appState = state; processData.isFocused = appRecord->GetFocusFlag(); processData.appIndex = appRecord->GetAppIndex(); @@ -3799,7 +3798,7 @@ void AppMgrServiceInner::SendAppStartupTypeEvent(const std::shared_ptrGetPriorityObject() == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "priorityObject null"); } else { - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); } eventInfo.startType = static_cast(startType); AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_STARTUP_TYPE, HiSysEventType::BEHAVIOR, eventInfo); @@ -3976,7 +3975,7 @@ void AppMgrServiceInner::TerminateApplication(const std::shared_ptrRemoveAppDeathRecipient(); appRecord->SetProcessChangeReason(ProcessChangeReason::REASON_APP_TERMINATED_TIMEOUT); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_TERMINATED, false, false); - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); int32_t uid = appRecord->GetUid(); if (pid > 0) { auto timeoutTask = [appRecord, pid, uid, innerService = shared_from_this()]() { @@ -4180,7 +4179,7 @@ void AppMgrServiceInner::StartEmptyResidentProcess( } appRecord->AddModules(appInfo, hapModuleInfos); TAG_LOGI(AAFwkTag::APPMGR, "StartEmptyResidentProcess of pid : [%{public}d], ", - appRecord->GetPriorityObject()->GetPid()); + appRecord->GetPid()); } bool AppMgrServiceInner::CheckRemoteClient() @@ -4507,7 +4506,7 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptrSetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->AddModules(appInfo, info.hapModuleInfos); - TAG_LOGI(AAFwkTag::APPMGR, "startEmptyProcess pid: [%{public}d]", appRecord->GetPriorityObject()->GetPid()); + TAG_LOGI(AAFwkTag::APPMGR, "startEmptyProcess pid: [%{public}d]", appRecord->GetPid()); return ERR_OK; } @@ -4947,7 +4946,7 @@ void AppMgrServiceInner::KillApplicationByRecord(const std::shared_ptrGetPriorityObject()->GetPid(); + auto pid = appRecord->GetPid(); appRecord->SetTerminating(); if (!appRunningManager_) { TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); @@ -4993,7 +4992,7 @@ void AppMgrServiceInner::SendHiSysEvent(int32_t innerEventId, std::shared_ptrGetPriorityObject()->GetPid(); + int32_t pid = appRecord->GetPid(); int32_t uid = appRecord->GetUid(); std::string packageName = appRecord->GetBundleName(); std::string processName = appRecord->GetProcessName(); @@ -7462,7 +7461,7 @@ void AppMgrServiceInner::KillAttachedChildProcess(const std::shared_ptrGetParentAppRecord(); if (parentAppRecord) { - parentAppRecord->RemoveChildAppRecord(appRecord->GetPriorityObject()->GetPid()); + parentAppRecord->RemoveChildAppRecord(appRecord->GetPid()); } std::vector pids; std::queue> queue; @@ -7604,7 +7603,7 @@ void AppMgrServiceInner::SendAppLaunchEvent(const std::shared_ptrversionCode; } if (appRecord->GetPriorityObject() != nullptr) { - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.pid = appRecord->GetPid(); } eventInfo.processName = appRecord->GetProcessName(); int32_t callerPid = appRecord->GetCallerPid() == -1 ? @@ -8092,7 +8091,7 @@ void AppMgrServiceInner::OnAppCacheStateChanged(const std::shared_ptrGetBundleName().c_str(), appRecord->GetPriorityObject()->GetPid()); + appRecord->GetBundleName().c_str(), appRecord->GetPid()); DelayedSingleton::GetInstance()->OnAppCacheStateChanged(appRecord, state); } @@ -8214,7 +8213,7 @@ void AppMgrServiceInner::KillProcessDependedOnWeb() } std::string bundleName = appRecord->GetBundleName(); - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (appRecord->IsKeepAliveApp()) { ExitResidentProcessManager::GetInstance().RecordExitResidentBundleDependedOnWeb(bundleName, appRecord->GetUid()); @@ -8326,7 +8325,7 @@ void AppMgrServiceInner::CheckCleanAbilityByUserRequest(const std::shared_ptrGetPriorityObject()) { - pid = appRecord->GetPriorityObject()->GetPid(); + pid = appRecord->GetPid(); } TAG_LOGI(AAFwkTag::APPMGR, "clean ability set up bg, force kill, pid:%{public}d", pid); KillProcessByPid(pid, KILL_REASON_USER_REQUEST); @@ -8356,7 +8355,7 @@ void AppMgrServiceInner::GetPidsByAccessTokenId(const uint32_t accessTokenId, st continue; } if (accessTokenId == applicationInfo->accessTokenId) { - pid_t curPid = appRecord->GetPriorityObject()->GetPid(); + pid_t curPid = appRecord->GetPid(); if (appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND) { foregroundPid = curPid; continue; @@ -8469,7 +8468,7 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund osAccountMgr->GetOsAccountLocalIdFromUid(appRecord->GetUid(), procUserId) == 0 && procUserId == callderUserId && cachePrcoMgr->IsAppSupportProcessCache(appRecord) && appRecord->GetPriorityObject() != nullptr) { - pidList.push_back(appRecord->GetPriorityObject()->GetPid()); + pidList.push_back(appRecord->GetPid()); } } return ERR_OK; diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 9c4ab7df7b..0a9865c99c 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -248,7 +248,7 @@ std::shared_ptr AppRunningManager::GetAppRunningRecordByPid(co { std::lock_guard guard(runningRecordMapMutex_); auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) { - return pair.second->GetPriorityObject()->GetPid() == pid; + return pair.second->GetPid() == pid; }); return ((iter == appRunningRecordMap_.end()) ? nullptr : iter->second); } @@ -277,7 +277,7 @@ bool AppRunningManager::ProcessExitByBundleName( // Before using this method, consider whether you need. if (appRecord && (!appRecord->IsKeepAliveApp() || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficient())) { - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); auto appInfoList = appRecord->GetAppInfoList(); auto isExist = [&bundleName](const std::shared_ptr &appInfo) { return appInfo->bundleName == bundleName; @@ -306,7 +306,7 @@ bool AppRunningManager::GetPidsByUserId(int32_t userId, std::list &pids) int32_t id = -1; if ((DelayedSingleton::GetInstance()-> GetOsAccountLocalIdFromUid(appRecord->GetUid(), id) == 0) && (id == userId)) { - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (pid > 0) { pids.push_back(pid); appRecord->ScheduleProcessSecurityExit(); @@ -352,7 +352,7 @@ bool AppRunningManager::ProcessExitByBundleNameAndUid( return appInfo->bundleName == bundleName && appInfo->uid == uid; }; auto iter = std::find_if(appInfoList.begin(), appInfoList.end(), isExist); - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (iter == appInfoList.end() || pid <= 0) { continue; } @@ -392,7 +392,7 @@ bool AppRunningManager::ProcessExitByBundleNameAndAppIndex(const std::string &bu } if (appInfo->bundleName == bundleName && appRecord->GetAppIndex() == appIndex) { - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (pid <= 0) { continue; } @@ -432,7 +432,7 @@ bool AppRunningManager::ProcessExitByTokenIdAndInstance(uint32_t accessTokenId, if (appRecord->GetPriorityObject() == nullptr) { continue; } - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (pid <= 0) { continue; } @@ -462,7 +462,7 @@ bool AppRunningManager::GetPidsByBundleNameUserIdAndAppIndex(const std::string & appInfo->appIndex == appIndex; }; auto iter = std::find_if(appInfoList.begin(), appInfoList.end(), isExist); - pid_t pid = appRecord->GetPriorityObject()->GetPid(); + pid_t pid = appRecord->GetPid(); if (iter == appInfoList.end() || pid <= 0) { continue; } @@ -522,7 +522,7 @@ std::shared_ptr AppRunningManager::OnRemoteDied(const wptrGetPriorityObject() != nullptr) { - RemoveUIExtensionLauncherItem(appRecord->GetPriorityObject()->GetPid()); + RemoveUIExtensionLauncherItem(appRecord->GetPid()); } return appRecord; @@ -551,8 +551,8 @@ void AppRunningManager::RemoveAppRunningRecordById(const int32_t recordId) } if (appRecord != nullptr && appRecord->GetPriorityObject() != nullptr) { - RemoveUIExtensionLauncherItem(appRecord->GetPriorityObject()->GetPid()); - AbilityRuntime::FreezeUtil::GetInstance().DeleteAppLifecycleEvent(appRecord->GetPriorityObject()->GetPid()); + RemoveUIExtensionLauncherItem(appRecord->GetPid()); + AbilityRuntime::FreezeUtil::GetInstance().DeleteAppLifecycleEvent(appRecord->GetPid()); } } @@ -780,7 +780,7 @@ void AppRunningManager::NotifyAppPreCache(const std::shared_ptrGetPriorityObject() == nullptr) { return; } - int32_t pid = appRecord->GetPriorityObject()->GetPid(); + int32_t pid = appRecord->GetPid(); int32_t userId = appRecord->GetUid() / BASE_USER_RANGE; auto notifyAppPreCache = [pid, userId, inner = appMgrServiceInner]() { if (inner == nullptr) { @@ -819,7 +819,7 @@ int32_t AppRunningManager::AssignRunningProcessInfoByAppRecord( } info.processName_ = appRecord->GetProcessName(); - info.pid_ = appRecord->GetPriorityObject()->GetPid(); + info.pid_ = appRecord->GetPid(); info.uid_ = appRecord->GetUid(); info.bundleNames.emplace_back(appRecord->GetBundleName()); info.state_ = static_cast(appRecord->GetState()); @@ -875,7 +875,7 @@ void AppRunningManager::GetForegroundApplications(std::vector &lis AppStateData appData; appData.bundleName = appRecord->GetBundleName(); appData.uid = appRecord->GetUid(); - appData.pid = appRecord->GetPriorityObject()->GetPid(); + appData.pid = appRecord->GetPid(); appData.state = static_cast(ApplicationState::APP_STATE_FOREGROUND); auto appInfo = appRecord->GetApplicationInfo(); appData.accessTokenId = appInfo ? appInfo->accessTokenId : 0; @@ -1129,7 +1129,7 @@ bool AppRunningManager::GetAppRunningStateByBundleName(const std::string &bundle TAG_LOGD(AAFwkTag::APPMGR, "Process of [%{public}s] is running, processName: %{public}s.", bundleName.c_str(), appRecord->GetProcessName().c_str()); if (IPCSkeleton::GetCallingUid() == QUICKFIX_UID && appRecord->GetPriorityObject() != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "pid: %{public}d", appRecord->GetPriorityObject()->GetPid()); + TAG_LOGI(AAFwkTag::APPMGR, "pid: %{public}d", appRecord->GetPid()); } return true; } @@ -1573,7 +1573,7 @@ int AppRunningManager::DumpIpcAllStart(std::string& result) for (const auto &item : GetAppRunningRecordMap()) { const auto &appRecord = item.second; TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStart::pid:%{public}d", - appRecord->GetPriorityObject()->GetPid()); + appRecord->GetPid()); std::string currentResult; errCode = appRecord->DumpIpcStart(currentResult); result += currentResult + "\n"; @@ -1591,7 +1591,7 @@ int AppRunningManager::DumpIpcAllStop(std::string& result) for (const auto &item : GetAppRunningRecordMap()) { const auto &appRecord = item.second; TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStop::pid:%{public}d", - appRecord->GetPriorityObject()->GetPid()); + appRecord->GetPid()); std::string currentResult; errCode = appRecord->DumpIpcStop(currentResult); result += currentResult + "\n"; @@ -1609,7 +1609,7 @@ int AppRunningManager::DumpIpcAllStat(std::string& result) for (const auto &item : GetAppRunningRecordMap()) { const auto &appRecord = item.second; TAG_LOGD(AAFwkTag::APPMGR, "AppRunningManager::DumpIpcAllStat::pid:%{public}d", - appRecord->GetPriorityObject()->GetPid()); + appRecord->GetPid()); std::string currentResult; errCode = appRecord->DumpIpcStat(currentResult); result += currentResult + "\n"; @@ -1723,7 +1723,7 @@ bool AppRunningManager::HandleUserRequestClean(const sptr &abilit appRecord->SetUserRequestCleaning(); if (appRecord->GetPriorityObject()) { - pid = appRecord->GetPriorityObject()->GetPid(); + pid = appRecord->GetPid(); } uid = appRecord->GetUid(); return true; @@ -1803,7 +1803,7 @@ bool AppRunningManager::CheckAppRunningRecordIsLast(const std::shared_ptrGetAppIndex(); auto appRecordId = appRecord->GetRecordId(); auto userId = appRecord->GetUserId(); - + for (const auto &item : appRunningRecordMap_) { const auto &itemAppRecord = item.second; if (itemAppRecord != nullptr && diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 34cea4f2eb..128986e02b 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -14,9 +14,9 @@ */ #include "ability_window_configuration.h" -#include "app_exception_manager.h" #include "app_running_record.h" #include "app_mgr_service_inner.h" +#include "error_msg_util.h" #include "event_report.h" #include "exit_resident_process_manager.h" #include "freeze_util.h" @@ -469,8 +469,10 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) TAG_LOGE(AAFwkTag::APPMGR, "null appLifeCycleDeal_"); return; } - if (!appLifeCycleDeal_->GetApplicationClient()) { + auto scheduler = appLifeCycleDeal_->GetApplicationClient(); + if (!scheduler) { TAG_LOGE(AAFwkTag::APPMGR, "null appThread"); + AddAppLifecycleEvent("AppRunningRecord::LaunchApplication null scheduler"); return; } AppLaunchData launchData; @@ -481,7 +483,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) launchData.SetApplicationInfo(*(moduleRecords->second)); } } - ProcessInfo processInfo(processName_, GetPriorityObject()->GetPid()); + ProcessInfo processInfo(processName_, GetPid()); processInfo.SetProcessType(processType_); launchData.SetProcessInfo(processInfo); launchData.SetRecordId(appRecordId_); @@ -501,6 +503,8 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) TAG_LOGD(AAFwkTag::APPMGR, "%{public}s called,app is %{public}s.", __func__, GetName().c_str()); AddAppLifecycleEvent("AppRunningRecord::LaunchApplication"); + AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast(scheduler.GetRefPtr()), + "ScheduleForegroundRunning"); appLifeCycleDeal_->LaunchApplication(launchData, config); } @@ -667,6 +671,13 @@ bool AppRunningRecord::ScheduleForegroundRunning() SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING); if (appLifeCycleDeal_) { AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning"); + auto scheduler = appLifeCycleDeal_->GetApplicationClient(); + if (!scheduler) { + AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning null scheduler"); + return false; + } + AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast(scheduler.GetRefPtr()), + "LaunchApplication"); return appLifeCycleDeal_->ScheduleForegroundRunning(); } return false; @@ -845,7 +856,7 @@ void AppRunningRecord::StateChangedNotifyObserver(const std::shared_ptrapplicationInfo.bundleName; abilityStateData.moduleName = abilityInfo->moduleName; abilityStateData.abilityName = ability->GetName(); - abilityStateData.pid = GetPriorityObject()->GetPid(); + abilityStateData.pid = GetPid(); abilityStateData.abilityState = state; abilityStateData.uid = abilityInfo->applicationInfo.uid; abilityStateData.token = ability->GetToken(); @@ -1020,10 +1031,9 @@ void AppRunningRecord::AbilityForeground(const std::shared_ptrGetToken(), "schedule failed"); + AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(ability->GetToken(), + "ScheduleForegroundRunning fail"); } - } else { - AppExceptionManager::GetInstance().ForegroundAppWait(ability->GetToken(), "pendingState not ready"); } foregroundingAbilityTokens_.insert(ability->GetToken()); TAG_LOGD(AAFwkTag::APPMGR, "foregroundingAbility size: %{public}d", @@ -1325,7 +1335,7 @@ void AppRunningRecord::SendAppStartupTypeEvent(const std::shared_ptrGetPid(); + eventInfo.pid = GetPid(); } eventInfo.startType = static_cast(startType); AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_STARTUP_TYPE, HiSysEventType::BEHAVIOR, eventInfo); @@ -2005,7 +2015,7 @@ void AppRunningRecord::ChangeWindowVisibility(const sptrpid_ != GetPriorityObject()->GetPid()) { + if (info->pid_ != GetPid()) { return; } } @@ -2039,7 +2049,7 @@ void AppRunningRecord::OnWindowVisibilityChanged( TAG_LOGE(AAFwkTag::APPMGR, "null info"); continue; } - if (info->pid_ != GetPriorityObject()->GetPid()) { + if (info->pid_ != GetPid()) { continue; } std::lock_guard windowIdsLock(windowIdsLock_); @@ -2487,6 +2497,15 @@ pid_t AppRunningRecord::GetGPUPid() return gpuPid_; } +pid_t AppRunningRecord::GetPid() +{ + auto prioObj = GetPriorityObject(); + if (prioObj) { + return prioObj->GetPid(); + } + return 0; +} + void AppRunningRecord::SetAttachedToStatusBar(bool isAttached) { isAttachedToStatusBar = isAttached; diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index 59cda00804..3061eae887 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -815,7 +815,7 @@ ProcessData AppStateObserverManager::WrapProcessData(const std::shared_ptrGetBundleName(); - processData.pid = appRecord->GetPriorityObject()->GetPid(); + processData.pid = appRecord->GetPid(); processData.uid = appRecord->GetUid(); auto applicationInfo = appRecord->GetApplicationInfo(); if (applicationInfo) { @@ -1024,7 +1024,7 @@ AppStateData AppStateObserverManager::WrapAppStateData(const std::shared_ptrGetPriorityObject()->GetPid(); + appStateData.pid = appRecord->GetPid(); appStateData.bundleName = appRecord->GetBundleName(); appStateData.state = static_cast(state); appStateData.uid = appRecord->GetUid(); diff --git a/services/appmgr/src/cache_process_manager.cpp b/services/appmgr/src/cache_process_manager.cpp index ccfc77618e..b63b324f5a 100644 --- a/services/appmgr/src/cache_process_manager.cpp +++ b/services/appmgr/src/cache_process_manager.cpp @@ -144,7 +144,7 @@ bool CacheProcessManager::CheckAndCacheProcess(const std::shared_ptrGetPriorityObject()) { - taskName += std::to_string(appRecord->GetPriorityObject()->GetPid()); + taskName += std::to_string(appRecord->GetPid()); } auto res = appRecord->CancelTask(taskName); if (res) { @@ -306,7 +306,7 @@ void CacheProcessManager::CheckAndSetProcessCacheEnable(const std::shared_ptrGetPriorityObject()->GetPid()); + AAFwk::ResSchedUtil::GetInstance().CheckShouldForceKillProcess(appRecord->GetPid()); if (forceKillProcess) { appRecord->SetProcessCacheBlocked(true); return; diff --git a/test/fuzztest/freezeutil_fuzzer/freezeutil_fuzzer.cpp b/test/fuzztest/freezeutil_fuzzer/freezeutil_fuzzer.cpp index f3e3cbfa88..4c47943484 100644 --- a/test/fuzztest/freezeutil_fuzzer/freezeutil_fuzzer.cpp +++ b/test/fuzztest/freezeutil_fuzzer/freezeutil_fuzzer.cpp @@ -50,7 +50,6 @@ sptr GetFuzzAbilityToken() bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { - FreezeUtil::LifecycleFlow flow; std::string JsonStr(data, size); FreezeUtil::GetInstance(); sptr token = GetFuzzAbilityToken(); @@ -58,11 +57,9 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::cout << "Get ability token failed." << std::endl; return false; }; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, JsonStr); - FreezeUtil::GetInstance().GetLifecycleEvent(flow); - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); + FreezeUtil::GetInstance().AddLifecycleEvent(token, JsonStr); + FreezeUtil::GetInstance().GetLifecycleEvent(token); FreezeUtil::GetInstance().DeleteLifecycleEvent(token); - FreezeUtil::GetInstance().DeleteLifecycleEventInner(flow); return true; } } diff --git a/test/unittest/freeze_util_test/freeze_util_test.cpp b/test/unittest/freeze_util_test/freeze_util_test.cpp index cd145c6a5b..a05be92a29 100644 --- a/test/unittest/freeze_util_test/freeze_util_test.cpp +++ b/test/unittest/freeze_util_test/freeze_util_test.cpp @@ -51,15 +51,14 @@ void FreezeUtilTest::TearDown() */ HWTEST_F(FreezeUtilTest, FreezeUtilTest_001, TestSize.Level1) { - FreezeUtil::LifecycleFlow flow; - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), ""); - flow.state = FreezeUtil::TimeoutState::FOREGROUND; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, "firstEntry"); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), + sptr token(new IPCObjectStub(u"testStub")); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), ""); + FreezeUtil::GetInstance().AddLifecycleEvent(token, "firstEntry"); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), TimeUtil::DefaultCurrentTimeStr() + "; " + "firstEntry"); - FreezeUtil::GetInstance().AddLifecycleEvent(flow, "secondEntry"); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), TimeUtil::DefaultCurrentTimeStr() + "; " + + FreezeUtil::GetInstance().AddLifecycleEvent(token, "secondEntry"); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), TimeUtil::DefaultCurrentTimeStr() + "; " + "firstEntry\n" + TimeUtil::DefaultCurrentTimeStr() + "; " + "secondEntry"); TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_001 is end"); } @@ -71,13 +70,12 @@ HWTEST_F(FreezeUtilTest, FreezeUtilTest_001, TestSize.Level1) */ HWTEST_F(FreezeUtilTest, FreezeUtilTest_002, TestSize.Level1) { - FreezeUtil::LifecycleFlow flow; - flow.state = FreezeUtil::TimeoutState::LOAD; - FreezeUtil::GetInstance().AddLifecycleEvent(flow, "testDeleteEntry"); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), + sptr token(new IPCObjectStub(u"testStub")); + FreezeUtil::GetInstance().AddLifecycleEvent(token, "testDeleteEntry"); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteEntry"); - FreezeUtil::GetInstance().DeleteLifecycleEvent(flow); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(flow), ""); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token), ""); TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_002 is end"); } @@ -88,20 +86,21 @@ HWTEST_F(FreezeUtilTest, FreezeUtilTest_002, TestSize.Level1) */ HWTEST_F(FreezeUtilTest, FreezeUtilTest_003, TestSize.Level1) { - sptr token_(new IPCObjectStub()); - FreezeUtil::LifecycleFlow foregroundFlow = { token_, FreezeUtil::TimeoutState::FOREGROUND }; - FreezeUtil::GetInstance().AddLifecycleEvent(foregroundFlow, "testDeleteLifecyleEventForground"); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(foregroundFlow), + sptr token1(new IPCObjectStub()); + FreezeUtil::GetInstance().AddLifecycleEvent(token1, "testDeleteLifecyleEventForground"); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token1), TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteLifecyleEventForground"); - FreezeUtil::LifecycleFlow backgroundFlow = { token_, FreezeUtil::TimeoutState::BACKGROUND }; - FreezeUtil::GetInstance().AddLifecycleEvent(backgroundFlow, "testDeleteLifecyleEventBackground"); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(backgroundFlow), + sptr token2(new IPCObjectStub()); + FreezeUtil::GetInstance().AddLifecycleEvent(token2, "testDeleteLifecyleEventBackground"); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token2), TimeUtil::DefaultCurrentTimeStr() + "; " + "testDeleteLifecyleEventBackground"); - FreezeUtil::GetInstance().DeleteLifecycleEvent(token_); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(foregroundFlow), ""); - EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(backgroundFlow), ""); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token1); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token1), ""); + FreezeUtil::GetInstance().DeleteLifecycleEvent(token2); + EXPECT_EQ(FreezeUtil::GetInstance().GetLifecycleEvent(token2), ""); + TAG_LOGI(AAFwkTag::TEST, "FreezeUtilTest_003 is end"); } } diff --git a/utils/global/freeze/BUILD.gn b/utils/global/freeze/BUILD.gn index 6c80a3b651..8b5e161a24 100644 --- a/utils/global/freeze/BUILD.gn +++ b/utils/global/freeze/BUILD.gn @@ -26,7 +26,10 @@ ohos_shared_library("freeze_util") { "${ability_runtime_services_path}/common/include", ] - sources = [ "src/freeze_util.cpp" ] + sources = [ + "src/error_msg_util.cpp", + "src/freeze_util.cpp", + ] public_configs = [ ":freeze_util_config" ] diff --git a/utils/global/freeze/include/error_msg_util.h b/utils/global/freeze/include/error_msg_util.h new file mode 100644 index 0000000000..d275ad9894 --- /dev/null +++ b/utils/global/freeze/include/error_msg_util.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H +#define OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H + +#include +#include +#include + +#include "iremote_object.h" + +namespace OHOS::AbilityRuntime { +class ErrorMsgGuard { +public: + ErrorMsgGuard(sptr token, uintptr_t scheduler, const std::string &name); // for ability + ErrorMsgGuard(pid_t pid, uintptr_t scheduler, const std::string &name); // for app + ~ErrorMsgGuard(); + + ErrorMsgGuard(const ErrorMsgGuard &) = delete; + void operator=(const ErrorMsgGuard &) = delete; +private: + sptr token_; // token, determines ability or app + pid_t pid_ = 0; + std::string errorKey_; +}; + +class ErrorMgsUtil { +public: + ErrorMgsUtil& operator=(const ErrorMgsUtil&) = delete; + ErrorMgsUtil(const ErrorMgsUtil&) = delete; + virtual ~ErrorMgsUtil() = default; + static ErrorMgsUtil& GetInstance(); + static std::string BuildErrorKey(uintptr_t scheduler, const std::string &name); + + void AddErrorMsg(const std::string &key, const std::string &errorMsg); + bool UpdateErrorMsg(const std::string &key, const std::string &errorMsg); + std::string DeleteErrorMsg(const std::string &key); +private: + ErrorMgsUtil() = default; + + std::mutex errorMsgMapMutex_; + std::unordered_map errorMsgMap_; +}; +} // namespace OHOS::AbilityRuntime +#endif // OHOS_ABILITY_RUNTIME_ERROR_MSG_UTIL_H \ No newline at end of file diff --git a/utils/global/freeze/include/freeze_util.h b/utils/global/freeze/include/freeze_util.h index 36673ce006..743c7c81cd 100644 --- a/utils/global/freeze/include/freeze_util.h +++ b/utils/global/freeze/include/freeze_util.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H #define OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H +#include #include #include @@ -34,11 +35,6 @@ public: struct LifecycleFlow { sptr token; TimeoutState state = TimeoutState::UNKNOWN; - - bool operator==(const LifecycleFlow &other) const - { - return token == other.token && state == other.state; - } }; FreezeUtil& operator=(const FreezeUtil&) = delete; @@ -46,10 +42,9 @@ public: virtual ~FreezeUtil() = default; static FreezeUtil& GetInstance(); - void AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry); - bool AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry); - std::string GetLifecycleEvent(const LifecycleFlow &flow); - void DeleteLifecycleEvent(const LifecycleFlow &flow); + void AddLifecycleEvent(sptr token, const std::string &entry); + bool AppendLifecycleEvent(sptr token, const std::string &entry); + std::string GetLifecycleEvent(sptr token); void DeleteLifecycleEvent(sptr token); void AddAppLifecycleEvent(pid_t pid, const std::string &entry); @@ -57,19 +52,18 @@ public: std::string GetAppLifecycleEvent(pid_t pid); private: FreezeUtil() = default; - void DeleteLifecycleEventInner(const LifecycleFlow &flow); - class LifecycleFlowObjHash { + class RemoteObjHash { public: - size_t operator() (const LifecycleFlow &flow) const + size_t operator() (const sptr &obj) const { - return reinterpret_cast(flow.token.GetRefPtr()) + std::hash()(static_cast(flow.state)); + return std::hash()(obj.GetRefPtr()); } }; std::mutex mutex_; - std::unordered_map lifecycleFlow_; - std::unordered_map appLifeCycleFlow_; + std::unordered_map, std::list, RemoteObjHash> lifecycleFlow_; + std::unordered_map> appLifeCycleFlow_; }; } // namespace OHOS::AbilityRuntime #endif // OHOS_ABILITY_RUNTIME_FREEZE_UTIL_H \ No newline at end of file diff --git a/utils/global/freeze/src/error_msg_util.cpp b/utils/global/freeze/src/error_msg_util.cpp new file mode 100644 index 0000000000..645388a59b --- /dev/null +++ b/utils/global/freeze/src/error_msg_util.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "error_msg_util.h" + +#include "freeze_util.h" + +namespace OHOS::AbilityRuntime { +ErrorMsgGuard::ErrorMsgGuard(sptr token, uintptr_t scheduler, const std::string &name) + : token_(token), errorKey_(ErrorMgsUtil::BuildErrorKey(scheduler, name)) +{ + if (token != nullptr) { + ErrorMgsUtil::GetInstance().AddErrorMsg(errorKey_, ""); + } +} + +ErrorMsgGuard::ErrorMsgGuard(pid_t pid, uintptr_t scheduler, const std::string &name) + : pid_(pid), errorKey_(ErrorMgsUtil::BuildErrorKey(scheduler, name)) +{ + ErrorMgsUtil::GetInstance().AddErrorMsg(errorKey_, ""); +} + +ErrorMsgGuard::~ErrorMsgGuard() +{ + auto errorMsg = ErrorMgsUtil::GetInstance().DeleteErrorMsg(errorKey_); + if (errorMsg.empty()) { + return; + } + if (token_) { + FreezeUtil::GetInstance().AppendLifecycleEvent(token_, errorMsg); + } else { + FreezeUtil::GetInstance().AddAppLifecycleEvent(pid_, errorMsg); + } +} + +ErrorMgsUtil &ErrorMgsUtil::GetInstance() +{ + static ErrorMgsUtil instance; + return instance; +} + +std::string ErrorMgsUtil::BuildErrorKey(uintptr_t scheduler, const std::string &name) +{ + return std::to_string(scheduler) + "#" + name; +} + +void ErrorMgsUtil::AddErrorMsg(const std::string &key, const std::string &errorMsg) +{ + std::lock_guard lock(errorMsgMapMutex_); + errorMsgMap_[key] = errorMsg; +} + +bool ErrorMgsUtil::UpdateErrorMsg(const std::string &key, const std::string &errorMsg) +{ + std::lock_guard lock(errorMsgMapMutex_); + auto it = errorMsgMap_.find(key); + if (it == errorMsgMap_.end()) { + return false; + } + it->second = errorMsg; + return true; +} + +std::string ErrorMgsUtil::DeleteErrorMsg(const std::string &key) +{ + std::lock_guard lock(errorMsgMapMutex_); + auto it = errorMsgMap_.find(key); + if (it == errorMsgMap_.end()) { + return ""; + } + auto result = std::move(it->second); + errorMsgMap_.erase(it); + return result; +} +} // namespace OHOS::AbilityRuntime \ No newline at end of file diff --git a/utils/global/freeze/src/freeze_util.cpp b/utils/global/freeze/src/freeze_util.cpp index aad8cf8c0f..37be9a7e5b 100644 --- a/utils/global/freeze/src/freeze_util.cpp +++ b/utils/global/freeze/src/freeze_util.cpp @@ -19,82 +19,90 @@ #include "time_util.h" namespace OHOS::AbilityRuntime { +namespace { +constexpr int32_t MAX_ENTRY_COUNT = 10; +std::string ConcatStr(const std::list &strList, const std::string &split) +{ + if (strList.empty()) { + return ""; + } + if (strList.size() == 1) { + return strList.front(); + } + + int32_t reserveSize = 0; + for (const auto &item : strList) { + reserveSize += split.size() + item.size(); + } + reserveSize -= split.size(); + std::string result; + if (reserveSize > 0) { + result.reserve(reserveSize); + } + result.append(strList.front()); + auto iter = strList.begin(); + for (++iter; iter != strList.end(); ++iter) { + result.append(split).append(*iter); + } + return result; +} +} + FreezeUtil& FreezeUtil::GetInstance() { static FreezeUtil instance; return instance; } -void FreezeUtil::AddLifecycleEvent(const LifecycleFlow &flow, const std::string &entry) +void FreezeUtil::AddLifecycleEvent(sptr token, const std::string &entry) { auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry; std::lock_guard lock(mutex_); - auto iter = lifecycleFlow_.find(flow); - if (iter != lifecycleFlow_.end()) { - iter->second += "\n" + newEntry; - } else { - lifecycleFlow_.emplace(flow, newEntry); + auto &entryList = lifecycleFlow_[token]; + entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry); + if (entryList.size() > MAX_ENTRY_COUNT) { + entryList.pop_front(); } } -bool FreezeUtil::AppendLifecycleEvent(const LifecycleFlow &flow, const std::string &entry) +bool FreezeUtil::AppendLifecycleEvent(sptr token, const std::string &entry) { std::lock_guard lock(mutex_); - auto iter = lifecycleFlow_.find(flow); + auto iter = lifecycleFlow_.find(token); if (iter == lifecycleFlow_.end()) { return false; } - auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry; - iter->second += "\n" + newEntry; + auto &entryList = iter->second; + entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry); + if (entryList.size() > MAX_ENTRY_COUNT) { + entryList.pop_front(); + } return true; } -std::string FreezeUtil::GetLifecycleEvent(const LifecycleFlow &flow) +std::string FreezeUtil::GetLifecycleEvent(sptr token) { std::lock_guard lock(mutex_); - auto search = lifecycleFlow_.find(flow); + auto search = lifecycleFlow_.find(token); if (search != lifecycleFlow_.end()) { - return search->second; + return ConcatStr(search->second, "\n"); } return ""; } -void FreezeUtil::DeleteLifecycleEvent(const LifecycleFlow &flow) -{ - std::lock_guard lock(mutex_); - DeleteLifecycleEventInner(flow); -} - void FreezeUtil::DeleteLifecycleEvent(sptr token) { std::lock_guard lock(mutex_); - if (lifecycleFlow_.empty()) { - return; - } - LifecycleFlow foregroundFlow = { token, TimeoutState::FOREGROUND }; - DeleteLifecycleEventInner(foregroundFlow); - - LifecycleFlow backgroundFlow = { token, TimeoutState::BACKGROUND }; - DeleteLifecycleEventInner(backgroundFlow); -} - -void FreezeUtil::DeleteLifecycleEventInner(const LifecycleFlow &flow) -{ - if (lifecycleFlow_.count(flow)) { - lifecycleFlow_.erase(flow); - } - TAG_LOGD(AAFwkTag::DEFAULT, "lifecycleFlow size: %{public}zu", lifecycleFlow_.size()); + lifecycleFlow_.erase(token); } void FreezeUtil::AddAppLifecycleEvent(pid_t pid, const std::string &entry) { std::lock_guard lock(mutex_); - auto newEntry = TimeUtil::DefaultCurrentTimeStr() + "; " + entry; - auto iter = appLifeCycleFlow_.find(pid); - if (iter != appLifeCycleFlow_.end()) { - iter->second += "\n" + newEntry; - } else { - appLifeCycleFlow_.emplace(pid, newEntry); + auto &entryList = appLifeCycleFlow_[pid]; + entryList.emplace_back(TimeUtil::DefaultCurrentTimeStr() + "; " + entry); + if (entryList.size() > MAX_ENTRY_COUNT) { + entryList.pop_front(); } } @@ -109,7 +117,7 @@ std::string FreezeUtil::GetAppLifecycleEvent(pid_t pid) std::lock_guard lock(mutex_); auto search = appLifeCycleFlow_.find(pid); if (search != appLifeCycleFlow_.end()) { - return search->second; + return ConcatStr(search->second, "\n"); } return ""; } From 1590c200ff9ddb6c1426b6547eb992c022260249 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Mon, 18 Nov 2024 12:30:09 +0800 Subject: [PATCH 2/2] lfiecycle msg modification Signed-off-by: wangzhen Change-Id: Ica6f817fa1449eac3c8b1adfa8cb0284112546b0 --- frameworks/native/ability/native/ability_impl.cpp | 4 ++-- .../ability/native/ability_runtime/cj_ui_ability.cpp | 4 ++-- .../ability/native/ability_runtime/js_ability.cpp | 4 ++-- .../ability/native/ability_runtime/js_ui_ability.cpp | 6 +++--- frameworks/native/ability/native/fa_ability_thread.cpp | 6 +++--- frameworks/native/ability/native/ui_ability_impl.cpp | 10 +++++----- frameworks/native/ability/native/ui_ability_thread.cpp | 8 ++++---- frameworks/native/appkit/app/main_thread.cpp | 10 +++++----- frameworks/native/appkit/dfr/appfreeze_inner.cpp | 4 ++-- .../app_manager/src/appmgr/app_scheduler_proxy.cpp | 4 ++-- services/abilitymgr/src/ability_manager_proxy.cpp | 6 +++--- .../abilitymgr/src/mission/mission_list_manager.cpp | 5 +++-- .../src/scene_board/ui_ability_lifecycle_manager.cpp | 5 +++-- services/appmgr/src/app_lifecycle_deal.cpp | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- services/appmgr/src/app_running_record.cpp | 8 ++++---- utils/global/freeze/src/freeze_util.cpp | 2 +- 17 files changed, 46 insertions(+), 44 deletions(-) diff --git a/frameworks/native/ability/native/ability_impl.cpp b/frameworks/native/ability/native/ability_impl.cpp index ee05e8b0c6..3ed794adbd 100644 --- a/frameworks/native/ability/native/ability_impl.cpp +++ b/frameworks/native/ability/native/ability_impl.cpp @@ -617,7 +617,7 @@ void AbilityImpl::WindowLifeCycleImpl::AfterForeground() TAG_LOGE(AAFwkTag::ABILITY, "null stage mode ability/abilityImpl"); return; } - std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle"; + std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterForeground"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); bool needNotifyAMS = false; @@ -652,7 +652,7 @@ void AbilityImpl::WindowLifeCycleImpl::AfterBackground() TAG_LOGW(AAFwkTag::ABILITY, "not stage"); return; } - std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle"; + std::string entry = "AbilityImpl::WindowLifeCycleImpl::AfterBackground"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); TAG_LOGI(AAFwkTag::ABILITY, "window after background"); diff --git a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp index 83f0c1b0bc..9d2a35f6fd 100644 --- a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp @@ -181,13 +181,13 @@ void CJUIAbility::OnStart(const Want &want, sptr sessionInfo void CJUIAbility::AddLifecycleEventBeforeCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " begin"; + auto entry = std::string("CJUIAbility::") + methodName + " begin"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void CJUIAbility::AddLifecycleEventAfterCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("CJUIAbility::") + methodName + "; the " + methodName + " end."; + auto entry = std::string("CJUIAbility::") + methodName + " end"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 228b89b8fb..9873b036dd 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -271,13 +271,13 @@ void JsAbility::OnStart(const Want &want, sptr sessionInfo) void JsAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " begin"; + auto entry = std::string("JsAbility::") + methodName + " begin"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void JsAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("JsAbility::") + methodName + "; the " + methodName + " end"; + auto entry = std::string("JsAbility::") + methodName + " end"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index b58fa7f6a1..9a5f4e1a20 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -362,13 +362,13 @@ void JsUIAbility::OnStart(const Want &want, sptr sessionInfo void JsUIAbility::AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " begin."; + auto entry = std::string("JsUIAbility::") + methodName + " begin"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } void JsUIAbility::AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const { - auto entry = std::string("JsUIAbility::") + methodName + "; the " + methodName + " end."; + auto entry = std::string("JsUIAbility::") + methodName + " end"; FreezeUtil::GetInstance().AddLifecycleEvent(AbilityContext::token_, entry); } @@ -877,7 +877,7 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want) if (ret != Rosen::WMError::WM_OK) { TAG_LOGE(AAFwkTag::UIABILITY, "init window scene failed"); FreezeUtil::GetInstance().AppendLifecycleEvent(AbilityContext::token_, - std::string("ERROR JsUIAbility::DoOnForegroundForSceneIsNull: ") + std::to_string(static_cast(ret))); + std::string("JsUIAbility::DoOnForegroundForSceneIsNull; error ") + std::to_string(static_cast(ret))); return; } diff --git a/frameworks/native/ability/native/fa_ability_thread.cpp b/frameworks/native/ability/native/fa_ability_thread.cpp index 9f3a257856..0bab4595fe 100644 --- a/frameworks/native/ability/native/fa_ability_thread.cpp +++ b/frameworks/native/ability/native/fa_ability_thread.cpp @@ -315,7 +315,7 @@ void FAAbilityThread::AttachInner(const std::shared_ptrInit(application, abilityRecord, currentAbility_, abilityHandler_, token_); // 4. ability attach : ipc TAG_LOGD(AAFwkTag::FA, "attach ability"); - std::string entry = "AbilityThread::Attach; the load lifecycle."; + std::string entry = "AbilityThread::Attach"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); ErrCode err = AbilityManagerClient::GetInstance()->AttachAbilityThread(this, token_); if (err != ERR_OK) { @@ -495,11 +495,11 @@ void FAAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) return; } if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle."; + std::string entry = "AbilityThread::" + methodName; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) { - std::string entry = "AbilityThread::" + methodName + "; the background lifecycle."; + std::string entry = "AbilityThread::" + methodName; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } } diff --git a/frameworks/native/ability/native/ui_ability_impl.cpp b/frameworks/native/ability/native/ui_ability_impl.cpp index 38453a4111..cc6c528ea3 100644 --- a/frameworks/native/ability/native/ui_ability_impl.cpp +++ b/frameworks/native/ability/native/ui_ability_impl.cpp @@ -219,7 +219,7 @@ void UIAbilityImpl::AbilityTransactionCallback(const AAFwk::AbilityLifeCycleStat TAG_LOGD(AAFwkTag::UIABILITY, "called"); if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { lifecycleState_ = AAFwk::ABILITY_STATE_FOREGROUND_NEW; - std::string entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start."; + std::string entry = "AbilityManagerClient::AbilityTransitionDone"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } auto ret = AAFwk::AbilityManagerClient::GetInstance()->AbilityTransitionDone(token_, state, GetRestoreData()); @@ -418,7 +418,7 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground() TAG_LOGE(AAFwkTag::UIABILITY, "null owner"); return; } - std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterForeground; the foreground lifecycle."; + std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterForeground"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); bool needNotifyAMS = false; @@ -435,7 +435,7 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterForeground() if (needNotifyAMS) { TAG_LOGI(AAFwkTag::UIABILITY, "notify ability manager service"); - entry = "AbilityManagerClient::AbilityTransitionDone; the transaction start."; + entry = "AbilityManagerClient::AbilityTransitionDone"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); owner->lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND_NEW; AppExecFwk::PacMap restoreData; @@ -452,7 +452,7 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterBackground() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::UIABILITY, "Lifecycle:call"); - std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterBackground; the background lifecycle."; + std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::AfterBackground"; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); AppExecFwk::PacMap restoreData; @@ -487,7 +487,7 @@ void UIAbilityImpl::WindowLifeCycleImpl::AfterUnfocused() void UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed(int32_t type) { TAG_LOGE(AAFwkTag::UIABILITY, "scb call, ForegroundFailed"); - std::string entry = "ERROR UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed; GoForeground failed."; + std::string entry = "UIAbilityImpl::WindowLifeCycleImpl::ForegroundFailed; GoForeground failed"; FreezeUtil::GetInstance().AppendLifecycleEvent(token_, entry); AppExecFwk::PacMap restoreData; switch (type) { diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index 6d419a6dca..8d55440949 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -167,11 +167,11 @@ void UIAbilityThread::AttachInner(const std::shared_ptrAttachAbilityThread(this, token_); if (err != ERR_OK) { - entry = std::string("AbilityThread::Attach failed ipc error: ") + std::to_string(err); + entry = std::string("AbilityThread::Attach; error ") + std::to_string(err); FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); TAG_LOGE(AAFwkTag::UIABILITY, "err: %{public}d", err); return; @@ -249,11 +249,11 @@ void UIAbilityThread::HandleAbilityTransaction( void UIAbilityThread::AddLifecycleEvent(uint32_t state, std::string &methodName) const { if (state == AAFwk::ABILITY_STATE_FOREGROUND_NEW) { - std::string entry = "AbilityThread::" + methodName + "; the foreground lifecycle."; + std::string entry = "AbilityThread::" + methodName; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } if (state == AAFwk::ABILITY_STATE_BACKGROUND_NEW) { - std::string entry = "AbilityThread::" + methodName + "; the background lifecycle."; + std::string entry = "AbilityThread::" + methodName; FreezeUtil::GetInstance().AddLifecycleEvent(token_, entry); } } diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index c5dd41ff4d..2bca286ae5 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -734,7 +734,7 @@ void MainThread::ScheduleLaunchAbility(const AbilityInfo &info, const sptrSetBgWorkingThreadStatus(IsBgWorkingThread(info)); tmpWatchdog = nullptr; } - std::string entry = "MainThread::ScheduleLaunchAbility; the load lifecycle."; + std::string entry = "MainThread::ScheduleLaunchAbility"; FreezeUtil::GetInstance().AddLifecycleEvent(token, entry); wptr weak = this; @@ -1296,7 +1296,7 @@ CJUncaughtExceptionInfo MainThread::CreateCjExceptionInfo(const std::string &bun void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, const Configuration &config) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication:begin"); + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication begin"); if (!CheckForHandleLaunchApplication(appLaunchData)) { TAG_LOGE(AAFwkTag::APPKIT, "CheckForHandleLaunchApplication failed"); return; @@ -1747,7 +1747,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con TAG_LOGE(AAFwkTag::APPKIT, "applicationImpl_->PerformAppReady failed"); return; } - FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication:end"); + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleLaunchApplication end"); // L1 needs to add corresponding interface ApplicationEnvImpl *pAppEvnIml = ApplicationEnvImpl::GetInstance(); @@ -2158,7 +2158,7 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & auto abilityToken = abilityRecord->GetToken(); CHECK_POINTER_LOG(abilityToken, "abilityRecord->GetToken failed"); - std::string entry = "MainThread::HandleLaunchAbility; the load lifecycle."; + std::string entry = "MainThread::HandleLaunchAbility"; FreezeUtil::GetInstance().AddLifecycleEvent(abilityToken, entry); abilityRecordMgr_->SetToken(abilityToken); @@ -2330,7 +2330,7 @@ void MainThread::HandleForegroundApplication() } if (!applicationImpl_->PerformForeground()) { - FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleForegroundApplication fail"); + FreezeUtil::GetInstance().AddAppLifecycleEvent(0, "HandleForegroundApplication; fail"); TAG_LOGE(AAFwkTag::APPKIT, "applicationImpl_->PerformForeground() failed"); } diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 65f9761058..164135d980 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -188,8 +188,8 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) FaultData faultData; faultData.errorObject.message = it->errorObject.message + "\n"; if (it->state != 0) { - faultData.errorObject.message += "client:\n" + - FreezeUtil::GetInstance().GetLifecycleEvent(it->token) + "\nclient app:\n" + + faultData.errorObject.message += "client actions for ability:\n" + + FreezeUtil::GetInstance().GetLifecycleEvent(it->token) + "\nclient actions for app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(0) + "\n"; } faultData.errorObject.stack = stack; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index f351f78ba4..3cd5a68e6c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -213,7 +213,7 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt if (!data.WriteParcelable(want.get())) { TAG_LOGE(AAFwkTag::APPMGR, "write want fail."); AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, - "ERROR AppLifeCycleDeal::LaunchAbility; write want fail"); + "AppLifeCycleDeal::LaunchAbility; write want fail"); return; } if (!data.WriteInt32(abilityRecordId)) { @@ -225,7 +225,7 @@ void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const spt if (ret != NO_ERROR) { TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, - "ERROR AppLifeCycleDeal::LaunchAbility; ipc fail " + std::to_string(ret)); + "AppLifeCycleDeal::LaunchAbility; ipc error " + std::to_string(ret)); } } diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 096503a013..2954aec704 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1351,7 +1351,7 @@ int AbilityManagerProxy::AttachAbilityThread(const sptr &sche if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, - std::string("ERROR AttachAbilityThread failed IPC error ") + std::to_string(error)); + std::string("AttachAbilityThread; ipc error ") + std::to_string(error)); return error; } return reply.ReadInt32(); @@ -1374,7 +1374,7 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, if (!data.WriteParcelable(&saveData)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write fail"); AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, - "write saveData failed"); + "AbilityTransitionDone; write saveData failed"); return INNER_ERR; } @@ -1382,7 +1382,7 @@ int AbilityManagerProxy::AbilityTransitionDone(const sptr &token, if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token, - std::string("ERROR AbilityTransitionDone failed IPC error ") + std::to_string(error)); + std::string("AbilityTransitionDone; ipc error ") + std::to_string(error)); return error; } return reply.ReadInt32(); diff --git a/services/abilitymgr/src/mission/mission_list_manager.cpp b/services/abilitymgr/src/mission/mission_list_manager.cpp index 511362a6a7..88f1952f59 100644 --- a/services/abilitymgr/src/mission/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission/mission_list_manager.cpp @@ -2247,8 +2247,9 @@ void MissionListManager::PrintTimeOutLog(const std::shared_ptr &a flow.token = ability->GetToken()->AsObject(); flow.state = state; } - info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) - + "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); + info.msg = msgContent + "\nserver actions for ability:\n" + + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) + + "\nserver actions for app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); if (!isHalf) { FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(ability->GetPid()); diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index dbcd88cbde..ac21589c1a 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1209,8 +1209,9 @@ void UIAbilityLifecycleManager::PrintTimeOutLog(std::shared_ptr a flow.token = ability->GetToken()->AsObject(); flow.state = state; } - info.msg = msgContent + "\nserver:\n" + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) - + "\nserver app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); + info.msg = msgContent + "\nserver actions for ability:\n" + + FreezeUtil::GetInstance().GetLifecycleEvent(flow.token) + + "\nserver actions for app:\n" + FreezeUtil::GetInstance().GetAppLifecycleEvent(processInfo.pid_); if (!isHalf) { FreezeUtil::GetInstance().DeleteLifecycleEvent(flow.token); FreezeUtil::GetInstance().DeleteAppLifecycleEvent(processInfo.pid_); diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 621379d666..1840ee6d89 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -75,7 +75,7 @@ void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr return; } if (abilityInfo->type == AbilityType::PAGE) { - std::string entry = "AppLifeCycleDeal::LaunchAbility; the LoadAbility lifecycle."; + std::string entry = "AppLifeCycleDeal::LaunchAbility"; FreezeUtil::GetInstance().AddLifecycleEvent(ability->GetToken(), entry); } TAG_LOGD(AAFwkTag::APPMGR, "Launch"); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 87413193d5..a3fcdd4a21 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -629,7 +629,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s return; } if (abilityInfo->type == AbilityType::PAGE) { - std::string entry = "AppMgrServiceInner::LoadAbility; the load lifecycle."; + std::string entry = "AppMgrServiceInner::LoadAbility"; AbilityRuntime::FreezeUtil::GetInstance().AddLifecycleEvent(loadParam->token, entry); } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 128986e02b..5f4952d081 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -472,7 +472,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) auto scheduler = appLifeCycleDeal_->GetApplicationClient(); if (!scheduler) { TAG_LOGE(AAFwkTag::APPMGR, "null appThread"); - AddAppLifecycleEvent("AppRunningRecord::LaunchApplication null scheduler"); + AddAppLifecycleEvent("AppRunningRecord::LaunchApplication; null scheduler"); return; } AppLaunchData launchData; @@ -504,7 +504,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) TAG_LOGD(AAFwkTag::APPMGR, "%{public}s called,app is %{public}s.", __func__, GetName().c_str()); AddAppLifecycleEvent("AppRunningRecord::LaunchApplication"); AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast(scheduler.GetRefPtr()), - "ScheduleForegroundRunning"); + "LaunchApplication"); appLifeCycleDeal_->LaunchApplication(launchData, config); } @@ -673,11 +673,11 @@ bool AppRunningRecord::ScheduleForegroundRunning() AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning"); auto scheduler = appLifeCycleDeal_->GetApplicationClient(); if (!scheduler) { - AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning null scheduler"); + AddAppLifecycleEvent("AppRunningRecord::ScheduleForegroundRunning; null scheduler"); return false; } AbilityRuntime::ErrorMsgGuard errorMsgGuard(GetPid(), reinterpret_cast(scheduler.GetRefPtr()), - "LaunchApplication"); + "ScheduleForegroundRunning"); return appLifeCycleDeal_->ScheduleForegroundRunning(); } return false; diff --git a/utils/global/freeze/src/freeze_util.cpp b/utils/global/freeze/src/freeze_util.cpp index 37be9a7e5b..6b68ec1e08 100644 --- a/utils/global/freeze/src/freeze_util.cpp +++ b/utils/global/freeze/src/freeze_util.cpp @@ -20,7 +20,7 @@ namespace OHOS::AbilityRuntime { namespace { -constexpr int32_t MAX_ENTRY_COUNT = 10; +constexpr int32_t MAX_ENTRY_COUNT = 20; std::string ConcatStr(const std::list &strList, const std::string &split) { if (strList.empty()) {