From 617548a03f2dab86ae1fc148a0b40df9a7bde4f6 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Fri, 1 Aug 2025 15:32:34 +0800 Subject: [PATCH 1/4] Code review1 Signed-off-by: wangzhen Change-Id: Idbbcf2235e60f9ce1a9ceb4ce3812c8f6f7667fa --- .../src/ability_manager_service.cpp | 5 +- services/abilitymgr/src/ability_record.cpp | 53 ++++++++----------- .../abilitymgr/src/sa_interceptor_manager.cpp | 1 + .../ui_ability_lifecycle_manager.cpp | 2 +- services/common/src/res_sched_util.cpp | 7 +++ 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 110082ba9ef..b69764e9456 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2943,10 +2943,7 @@ bool AbilityManagerService::IsCallerSceneBoard() auto connectManager = GetConnectManagerByUserId(userId); CHECK_POINTER_AND_RETURN(connectManager, false); auto sceneBoardTokenId = connectManager->GetSceneBoardTokenId(); - if (sceneBoardTokenId != 0 && IPCSkeleton::GetCallingTokenID() == sceneBoardTokenId) { - return true; - } - return false; + return sceneBoardTokenId != 0 && IPCSkeleton::GetCallingTokenID() == sceneBoardTokenId; } bool AbilityManagerService::IsBackgroundTaskUid(const int uid) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index eda793dbf60..e3e9261a60a 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -502,41 +502,32 @@ void AbilityRecord::ProcessForegroundAbility( GrantUriPermission(want_, abilityInfo_.applicationInfo.bundleName, false, tokenId); } #endif // SUPPORT_UPMS + if (!isReady_) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "To load ability."); + lifeCycleStateInfo_.sceneFlagBak = sceneFlag; + LoadAbility(isShellCall, isStartupHide); + return; + } - if (isReady_) { - PostForegroundTimeoutTask(); - if (IsAbilityState(AbilityState::FOREGROUND)) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Activate %{public}s", element.c_str()); - if (IsFrozenByPreload()) { - SetFrozenByPreload(false); - auto ret = - DelayedSingleton::GetInstance()->NotifyPreloadAbilityStateChanged(token_, false); - TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyPreloadAbilityStateChanged by start, ret: %{public}d", ret); - } - ForegroundAbility(sceneFlag); - } else { - // background to active state - TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str()); - lifeCycleStateInfo_.sceneFlagBak = sceneFlag; - std::string bundleName = GetAbilityInfo().bundleName; - int32_t uid = GetUid(); - auto pid = GetPid(); - if (pid > 0) { - auto callerPid = GetCallerRecord() ? GetCallerRecord()->GetPid() : -1; - TAG_LOGD(AAFwkTag::ABILITYMGR, - "ReportEventToRSS---%{public}d_%{public}s_%{public}d callerPid=%{public}d", - uid, bundleName.c_str(), pid, callerPid); - ResSchedUtil::GetInstance().ReportEventToRSS(uid, bundleName, "THAW_BY_FOREGROUND_ABILITY", pid, - callerPid); - } - SendAppStartupTypeEvent(AppExecFwk::AppStartType::HOT); - SetAbilityStateInner(AbilityState::FOREGROUNDING); - DelayedSingleton::GetInstance()->MoveToForeground(token_); + PostForegroundTimeoutTask(); + if (IsAbilityState(AbilityState::FOREGROUND)) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Activate %{public}s", element.c_str()); + if (IsFrozenByPreload()) { + SetFrozenByPreload(false); + auto ret = + DelayedSingleton::GetInstance()->NotifyPreloadAbilityStateChanged(token_, false); + TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyPreloadAbilityStateChanged by start, ret: %{public}d", ret); } + ForegroundAbility(sceneFlag); } else { - TAG_LOGD(AAFwkTag::ABILITYMGR, "To load ability."); + // background to active state + TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str()); lifeCycleStateInfo_.sceneFlagBak = sceneFlag; - LoadAbility(isShellCall, isStartupHide); + ResSchedUtil::GetInstance().ReportEventToRSS(GetUid(), GetAbilityInfo().bundleName, + "THAW_BY_FOREGROUND_ABILITY", GetPid(), GetCallerRecord() ? GetCallerRecord()->GetPid() : -1); + SendAppStartupTypeEvent(AppExecFwk::AppStartType::HOT); + SetAbilityStateInner(AbilityState::FOREGROUNDING); + DelayedSingleton::GetInstance()->MoveToForeground(token_); } } diff --git a/services/abilitymgr/src/sa_interceptor_manager.cpp b/services/abilitymgr/src/sa_interceptor_manager.cpp index ff45b1ae904..83f8f6931bd 100644 --- a/services/abilitymgr/src/sa_interceptor_manager.cpp +++ b/services/abilitymgr/src/sa_interceptor_manager.cpp @@ -85,6 +85,7 @@ int32_t SAInterceptorManager::ExecuteSAInterceptor(const std::string ¶ms, Ru HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto result = interceptor->OnCheckStarting(params, rule); if (result != ERR_OK || rule.type != RuleType::ALLOW) { + TAG_LOGW(AAFwkTag::SA_INTERCEPTOR, "OnCheckStarting error: %{public}d", result); return result; } } 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 2077539a409..a407df44103 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -2507,7 +2507,7 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedProcessRequest(const AbilityReq int32_t UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(AbilityRequest &abilityRequest) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); + TAG_LOGD(AAFwkTag::ABILITYMGR, "StartSpecifiedAbilityBySCB"); abilityRequest.isFromIcon = true; std::lock_guard guard(sessionLock_); // support specified process mode diff --git a/services/common/src/res_sched_util.cpp b/services/common/src/res_sched_util.cpp index 5b2df1149b7..547d898534a 100644 --- a/services/common/src/res_sched_util.cpp +++ b/services/common/src/res_sched_util.cpp @@ -147,6 +147,13 @@ void ResSchedUtil::ReportAbilityIntentExemptionInfoToRSS(int32_t callerUid, int3 void ResSchedUtil::ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, const int32_t pid, const int32_t callerPid) { + + TAG_LOGD(AAFwkTag::DEFAULT, "ReportEventToRSS---%{public}d_%{public}s_%{public}d callerPid=%{public}d", + uid, bundleName.c_str(), pid, callerPid); + if (pid < 0) { + TAG_LOGW(AAFwkTag::DEFAULT, "invalid pid: %{public}s_%{public}d", bundleName.c_str(), pid); + return; + } #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE uint32_t resType = ResourceSchedule::ResType::SYNC_RES_TYPE_THAW_ONE_APP; nlohmann::json payload; -- Gitee From cd4209c16fe368f3b3051abcaa4b8e501218faa9 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Fri, 1 Aug 2025 16:23:55 +0800 Subject: [PATCH 2/4] Code review2 Signed-off-by: wangzhen Change-Id: I3b2fda91b4aeea14ac0b471d33ec9f887f131f52 --- .../ui_ability_lifecycle_manager.h | 2 - .../ui_ability_lifecycle_manager.cpp | 43 ------------------- .../src/mock_ui_ability_lifecycle_manager.cpp | 9 ---- .../src/mock_ui_ability_lifecycle_manager.cpp | 9 ---- .../ui_ability_lifecycle_manager_test.cpp | 33 -------------- 5 files changed, 96 deletions(-) diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index c87a19c60f5..be1975cb71e 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -450,8 +450,6 @@ private: void HandleForegroundCollaborate(const AbilityRequest &abilityRequest, std::shared_ptr abilityRecord); - void NotifyStartSpecifiedAbility(AbilityRequest &request, const AAFwk::Want &want); - void NotifyRestartSpecifiedAbility(const AbilityRequest &request, const sptr &token); int32_t MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, const std::shared_ptr abilityRecord, std::shared_ptr callerAbility); int SendSessionInfoToSCB(std::shared_ptr &callerAbility, sptr &sessionInfo); 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 a407df44103..bc818202701 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -2340,11 +2340,9 @@ void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(SpecifiedRequest &spe CHECK_POINTER_LOG(abilityRecord, "OnAcceptWantResponse abilityRecord null"); UpdateAbilityRecordLaunchReason(abilityRequest, abilityRecord); MoveAbilityToFront(specifiedRequest, abilityRecord, callerAbility); - NotifyRestartSpecifiedAbility(abilityRequest, abilityRecord->GetToken()); return; } } - NotifyStartSpecifiedAbility(abilityRequest, want); StartAbilityBySpecifed(specifiedRequest, callerAbility); } @@ -2518,47 +2516,6 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(AbilityRequest &ab return ERR_OK; } -void UIAbilityLifecycleManager::NotifyRestartSpecifiedAbility(const AbilityRequest &request, - const sptr &token) -{ - if (request.abilityInfoCallback == nullptr) { - return; - } - sptr abilityInfoCallback - = iface_cast (request.abilityInfoCallback); - if (abilityInfoCallback != nullptr) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - abilityInfoCallback->NotifyRestartSpecifiedAbility(token); - } -} - -void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abilityRequest, const AAFwk::Want &want) -{ - if (abilityRequest.abilityInfoCallback == nullptr) { - return; - } - - sptr abilityInfoCallback - = iface_cast (abilityRequest.abilityInfoCallback); - if (abilityInfoCallback != nullptr) { - Want newWant = want; - int32_t type = static_cast(abilityRequest.abilityInfo.type); - newWant.SetParam("abilityType", type); - sptr extraParam = new (std::nothrow) Want(); - CHECK_POINTER(extraParam); - abilityInfoCallback->NotifyStartSpecifiedAbility(abilityRequest.callerToken, newWant, - abilityRequest.requestCode, extraParam); - int32_t procCode = extraParam->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0); - if (procCode != 0) { - abilityRequest.want.SetParam(Want::PARAM_RESV_REQUEST_PROC_CODE, procCode); - } - int32_t tokenCode = extraParam->GetIntParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, 0); - if (tokenCode != 0) { - abilityRequest.want.SetParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, tokenCode); - } - } -} - int32_t UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { diff --git a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp index d66f86a5a27..bb8f883cc7b 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp +++ b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp @@ -418,15 +418,6 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(AbilityRequest &ab return 0; } -void UIAbilityLifecycleManager::NotifyRestartSpecifiedAbility(const AbilityRequest &request, - const sptr &token) -{ -} - -void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abilityRequest, const AAFwk::Want &want) -{ -} - int UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, const std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp index 10a12975ccd..7362d702c45 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp @@ -427,15 +427,6 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(AbilityRequest &ab return 0; } -void UIAbilityLifecycleManager::NotifyRestartSpecifiedAbility(const AbilityRequest &request, - const sptr &token) -{ -} - -void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abilityRequest, const AAFwk::Want &want) -{ -} - int UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, const std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 0bee20422da..c88cbeb4de3 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -2605,39 +2605,6 @@ HWTEST_F(UIAbilityLifecycleManagerTest, IsStartSpecifiedProcessRequest_007, Test EXPECT_EQ(ret, true); } -/** - * @tc.name: UIAbilityLifecycleManager_NotifyRestartSpecifiedAbility_0100 - * @tc.desc: NotifyRestartSpecifiedAbility - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerTest, NotifyRestartSpecifiedAbility_001, TestSize.Level1) -{ - auto uiAbilityLifecycleManager = std::make_shared(); - EXPECT_NE(uiAbilityLifecycleManager, nullptr); - AbilityRequest request; - std::shared_ptr abilityRecord = InitAbilityRecord(); - sptr token = abilityRecord->GetToken(); - request.abilityInfoCallback = new MockAbilityInfoCallbackStub(); - uiAbilityLifecycleManager->NotifyRestartSpecifiedAbility(request, token); - uiAbilityLifecycleManager.reset(); -} - -/** - * @tc.name: UIAbilityLifecycleManager_NotifyStartSpecifiedAbility_0100 - * @tc.desc: NotifyStartSpecifiedAbility - * @tc.type: FUNC - */ -HWTEST_F(UIAbilityLifecycleManagerTest, NotifyStartSpecifiedAbility_001, TestSize.Level1) -{ - auto uiAbilityLifecycleManager = std::make_shared(); - EXPECT_NE(uiAbilityLifecycleManager, nullptr); - AbilityRequest request; - Want want; - request.abilityInfoCallback = new MockAbilityInfoCallbackStub(); - uiAbilityLifecycleManager->NotifyStartSpecifiedAbility(request, want); - uiAbilityLifecycleManager.reset(); -} - /** * @tc.name: UIAbilityLifecycleManager_MoveAbilityToFront_0100 * @tc.desc: MoveAbilityToFront -- Gitee From ea64b2346fc2e1466ea38ead77251a158499dfe1 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Fri, 1 Aug 2025 18:12:51 +0800 Subject: [PATCH 3/4] Remove pid check Signed-off-by: wangzhen Change-Id: I9cae88da75e73dc08ee81b00dc4d7b446f596e94 --- services/common/src/res_sched_util.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/services/common/src/res_sched_util.cpp b/services/common/src/res_sched_util.cpp index 547d898534a..ff7c9ab6bf1 100644 --- a/services/common/src/res_sched_util.cpp +++ b/services/common/src/res_sched_util.cpp @@ -147,13 +147,8 @@ void ResSchedUtil::ReportAbilityIntentExemptionInfoToRSS(int32_t callerUid, int3 void ResSchedUtil::ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, const int32_t pid, const int32_t callerPid) { - TAG_LOGD(AAFwkTag::DEFAULT, "ReportEventToRSS---%{public}d_%{public}s_%{public}d callerPid=%{public}d", uid, bundleName.c_str(), pid, callerPid); - if (pid < 0) { - TAG_LOGW(AAFwkTag::DEFAULT, "invalid pid: %{public}s_%{public}d", bundleName.c_str(), pid); - return; - } #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE uint32_t resType = ResourceSchedule::ResType::SYNC_RES_TYPE_THAW_ONE_APP; nlohmann::json payload; -- Gitee From 1a67afb09e08aa4d5fd02e0d98a4c4692bf444d5 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Tue, 12 Aug 2025 11:01:56 +0800 Subject: [PATCH 4/4] Code review Signed-off-by: wangzhen Change-Id: I597274e3a7ed57a0bf0afaffcd7846f13bef8a85 --- services/abilitymgr/src/ability_record.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index e3e9261a60a..590bb0a7f23 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -519,16 +519,16 @@ void AbilityRecord::ProcessForegroundAbility( TAG_LOGI(AAFwkTag::ABILITYMGR, "NotifyPreloadAbilityStateChanged by start, ret: %{public}d", ret); } ForegroundAbility(sceneFlag); - } else { - // background to active state - TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str()); - lifeCycleStateInfo_.sceneFlagBak = sceneFlag; - ResSchedUtil::GetInstance().ReportEventToRSS(GetUid(), GetAbilityInfo().bundleName, - "THAW_BY_FOREGROUND_ABILITY", GetPid(), GetCallerRecord() ? GetCallerRecord()->GetPid() : -1); - SendAppStartupTypeEvent(AppExecFwk::AppStartType::HOT); - SetAbilityStateInner(AbilityState::FOREGROUNDING); - DelayedSingleton::GetInstance()->MoveToForeground(token_); + return; } + // background to active state + TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str()); + lifeCycleStateInfo_.sceneFlagBak = sceneFlag; + ResSchedUtil::GetInstance().ReportEventToRSS(GetUid(), GetAbilityInfo().bundleName, + "THAW_BY_FOREGROUND_ABILITY", GetPid(), GetCallerRecord() ? GetCallerRecord()->GetPid() : -1); + SendAppStartupTypeEvent(AppExecFwk::AppStartType::HOT); + SetAbilityStateInner(AbilityState::FOREGROUNDING); + DelayedSingleton::GetInstance()->MoveToForeground(token_); } void AbilityRecord::PostForegroundTimeoutTask() -- Gitee