From 34fa86335e3910b6df48fb11bdc9e60e33b24843 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Sat, 30 May 2026 17:00:51 +0800 Subject: [PATCH 1/2] Add index check error Co-Authored-By: Agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhen 🤖‍ AI[100%] 👌 AI Adopted[100%] 🧑 Human[0%] Co-authored-by: claude (glm-5.1) Change-Id: I0a8640bdf5e73812e3280b4ab676e319115038d8 --- .../include/utils/clone_for_account_util.h | 2 +- .../src/ability_manager_service.cpp | 30 ++++++++++++------- .../src/utils/clone_for_account_util.cpp | 7 +++-- .../clone_for_account_util_test.cpp | 28 +++++++---------- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/services/abilitymgr/include/utils/clone_for_account_util.h b/services/abilitymgr/include/utils/clone_for_account_util.h index dd1c3f6127..8d706c1c02 100644 --- a/services/abilitymgr/include/utils/clone_for_account_util.h +++ b/services/abilitymgr/include/utils/clone_for_account_util.h @@ -26,7 +26,7 @@ namespace OHOS { namespace AAFwk { class CloneForAccountUtil { public: - static void ProcessAppIndex(Want &want, int32_t userId); + static bool ProcessAppIndex(Want &want, int32_t userId); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f516a8d53e..1f23804076 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -697,7 +697,8 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re userId = GetValidUserId(userId); } #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), userId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), userId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); XCOLLIE_TIMER_LESS_IGNORE(__PRETTY_FUNCTION__, !want.GetDeviceId().empty()); @@ -1390,7 +1391,8 @@ int AbilityManagerService::StartAbilityInner(StartAbilityWrapParam ¶m) } int32_t oriValidUserId = GetValidUserId(param.userId); #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(param.want, oriValidUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(param.want, oriValidUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif std::string dialogSessionId = param.want.GetStringParam("dialogSessionId"); bool isSendDialogResult = false; @@ -1836,7 +1838,8 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt EventInfo eventInfo = BuildEventInfo(want, userId); int32_t oriValidUserId = GetValidUserId(userId); #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif if (want.GetBoolParam(AbilityConfig::DEBUG_APP, false)) { if (!system::GetBoolParameter(DEVELOPER_MODE_STATE, false)) { @@ -2217,7 +2220,8 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St EventInfo eventInfo = BuildEventInfo(want, userId); int32_t oriValidUserId = GetValidUserId(userId); #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif // prevent the app from dominating the screen if (callerToken == nullptr && !IsCallerSceneBoard() && !isCallByShortcut && @@ -2627,7 +2631,8 @@ int32_t AbilityManagerService::StartUIAbilitiesInSplitWindowModeHandleWant(const int32_t requestCode = DEFAULT_INVAL_VALUE; int32_t appIndex = 0; #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(secondaryWant), validUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(secondaryWant), validUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif AbilityUtil::RemoveShowModeKey(const_cast(secondaryWant)); auto result = CheckWantForSplitMode(secondaryWant, callerToken, validUserId, appIndex); @@ -2779,7 +2784,8 @@ int32_t AbilityManagerService::StartUIAbilitiesHandleWant(const Want &want, sptr uint32_t specifyTokenId = 0; int32_t requestCode = DEFAULT_INVAL_VALUE; #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), validUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), validUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif AbilityUtil::RemoveShowModeKey(const_cast(want)); @@ -3124,7 +3130,8 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, Ab #ifdef ENABLE_CLONE_FOR_ACCOUNT if (sessionInfo->want.GetBoolParam(ServerConstant::IS_CALL_BY_SCB, true)) { auto currentUserId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; - CloneForAccountUtil::ProcessAppIndex(sessionInfo->want, currentUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(sessionInfo->want, currentUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); } #endif sessionInfo->want.SetParam(AbilityRuntime::GlobalConstant::PAGE_CONFIG, params.pageConfig); @@ -9947,7 +9954,8 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const } int32_t oriValidUserId = GetValidUserId(accountId); #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif AbilityUtil::RemoveWantKey(const_cast(want)); int32_t appIndex = 0; @@ -10071,7 +10079,8 @@ int AbilityManagerService::StartAbilityForPrelaunch(const Want &want, const int3 } int32_t oriValidUserId = GetValidUserId(DEFAULT_INVAL_VALUE); #ifdef ENABLE_CLONE_FOR_ACCOUNT - CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), oriValidUserId), + RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, oriValidUserId, true, nullptr, @@ -11213,7 +11222,8 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptr(want), GetValidUserId(DEFAULT_INVAL_VALUE)); + CHECK_TRUE_RETURN_RET(!CloneForAccountUtil::ProcessAppIndex(const_cast(want), + GetValidUserId(DEFAULT_INVAL_VALUE)), RESOLVE_ABILITY_ERR, "CloneForAccountUtil::ProcessAppIndex failed"); #endif int32_t appIndex = 0; if (!StartAbilityUtils::GetAppIndex(want, nullptr, appIndex) || appIndex != 0) { diff --git a/services/abilitymgr/src/utils/clone_for_account_util.cpp b/services/abilitymgr/src/utils/clone_for_account_util.cpp index f9ece3c358..4f6ba90a7d 100644 --- a/services/abilitymgr/src/utils/clone_for_account_util.cpp +++ b/services/abilitymgr/src/utils/clone_for_account_util.cpp @@ -21,23 +21,24 @@ namespace OHOS { namespace AAFwk { -void CloneForAccountUtil::ProcessAppIndex(Want &want, int32_t userId) +bool CloneForAccountUtil::ProcessAppIndex(Want &want, int32_t userId) { want.RemoveParam(Want::PARAM_APP_CLONE_INDEX_KEY); auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); if (bundleMgrHelper == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleMgrHelper is nullptr"); - return; + return false; } AppExecFwk::AbilityInfo abilityInfo; if (!IN_PROCESS_CALL(bundleMgrHelper->QueryEnabledAbilityInfo(want, userId, abilityInfo))) { TAG_LOGE(AAFwkTag::ABILITYMGR, "QueryEnabledAbilityInfo failed"); - return; + return false; } want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, abilityInfo.appIndex); TAG_LOGI(AAFwkTag::ABILITYMGR, "CloneForAccount resolved appIndex: %{public}d", abilityInfo.appIndex); + return true; } } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp b/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp index 4ef8877620..339fd7eb3a 100644 --- a/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp +++ b/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp @@ -46,7 +46,7 @@ void CloneForAccountUtilTest::TearDown() {} /** * @tc.name: ProcessAppIndex_001 - * @tc.desc: Test ProcessAppIndex success with appIndex in want + * @tc.desc: Test ProcessAppIndex returns true on success with appIndex in want * @tc.type: FUNC */ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_001, TestSize.Level1) @@ -61,15 +61,14 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_001, TestSize.Level1) AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo; AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true; - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 1); } /** * @tc.name: ProcessAppIndex_002 - * @tc.desc: Test ProcessAppIndex with bundleMgrHelper null + * @tc.desc: Test ProcessAppIndex returns false when bundleMgrHelper is null * @tc.type: FUNC */ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_002, TestSize.Level1) @@ -80,14 +79,13 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_002, TestSize.Level1) want.SetElementName("com.test.bundle", "MainAbility"); want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1); - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); } /** * @tc.name: ProcessAppIndex_003 - * @tc.desc: Test ProcessAppIndex with QueryEnabledAbilityInfo failed + * @tc.desc: Test ProcessAppIndex returns false when QueryEnabledAbilityInfo fails * @tc.type: FUNC */ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_003, TestSize.Level1) @@ -98,14 +96,13 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_003, TestSize.Level1) want.SetElementName("com.test.bundle", "MainAbility"); want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1); - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); } /** * @tc.name: ProcessAppIndex_004 - * @tc.desc: Test ProcessAppIndex with no appIndex in want + * @tc.desc: Test ProcessAppIndex returns true with no appIndex in want * @tc.type: FUNC */ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_004, TestSize.Level1) @@ -119,8 +116,7 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_004, TestSize.Level1) AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo; AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true; - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 0); } @@ -142,15 +138,14 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_005, TestSize.Level1) AppExecFwk::BundleMgrHelper::abilityInfoResult = mockAbilityInfo; AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = true; - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_TRUE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); EXPECT_EQ(want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, -1), 2); } /** * @tc.name: ProcessAppIndex_006 - * @tc.desc: Test ProcessAppIndex removes appIndex before query, query fails + * @tc.desc: Test ProcessAppIndex returns false and removes appIndex when query fails * @tc.type: FUNC */ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_006, TestSize.Level1) @@ -161,8 +156,7 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_006, TestSize.Level1) want.SetElementName("com.test.bundle", "MainAbility"); want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 99); - CloneForAccountUtil::ProcessAppIndex(want, 100); - + EXPECT_FALSE(CloneForAccountUtil::ProcessAppIndex(want, 100)); EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); } From 7cb53ae15f678c21250e1106604cf554e601f330 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Mon, 1 Jun 2026 10:46:43 +0800 Subject: [PATCH 2/2] Add implicit handle Co-Authored-By: Agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhen 🤖‍ AI[100%] 👌 AI Adopted[100%] 🧑 Human[0%] Co-authored-by: claude (glm-5.1) Change-Id: Idfe08e7c2c3a4c437361aaf6fc6b60236b0dd615 --- .../src/utils/clone_for_account_util.cpp | 5 +++++ .../clone_for_account_util_test.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/services/abilitymgr/src/utils/clone_for_account_util.cpp b/services/abilitymgr/src/utils/clone_for_account_util.cpp index 4f6ba90a7d..288451aff4 100644 --- a/services/abilitymgr/src/utils/clone_for_account_util.cpp +++ b/services/abilitymgr/src/utils/clone_for_account_util.cpp @@ -25,6 +25,11 @@ bool CloneForAccountUtil::ProcessAppIndex(Want &want, int32_t userId) { want.RemoveParam(Want::PARAM_APP_CLONE_INDEX_KEY); + if (want.GetElement().GetAbilityName().empty()) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "implicit start, skip"); + return true; + } + auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); if (bundleMgrHelper == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleMgrHelper is nullptr"); diff --git a/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp b/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp index 339fd7eb3a..d3c9f7cd26 100644 --- a/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp +++ b/test/unittest/clone_for_account_util_test/clone_for_account_util_test.cpp @@ -160,5 +160,22 @@ HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_006, TestSize.Level1) EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); } +/** + * @tc.name: ProcessAppIndex_007 + * @tc.desc: Test ProcessAppIndex returns true on implicit start without query + * @tc.type: FUNC + */ +HWTEST_F(CloneForAccountUtilTest, ProcessAppIndex_007, TestSize.Level1) +{ + Want want; + want.SetAction("ohos.want.action.viewData"); + want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, 1); + + AppExecFwk::BundleMgrHelper::retQueryEnabledAbilityInfo = false; + + EXPECT_TRUE(CloneForAccountUtil::ProcessAppIndex(want, 100)); + EXPECT_FALSE(want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY)); +} + } // namespace AAFwk } // namespace OHOS