From e1cf1c19386c70666119c70d09c40ea0a9de26f3 Mon Sep 17 00:00:00 2001 From: hanchen45 Date: Thu, 31 Jul 2025 11:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E7=82=B9ClearProtec?= =?UTF-8?q?tedWantParam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchen45 --- .../include/ability_manager_errors.h | 5 +++++ .../abilitymgr/src/ability_manager_service.cpp | 3 +-- .../src/utils/update_caller_info_util.cpp | 10 ++++++++++ .../update_caller_info_util_test.cpp | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 870dfefc01a..addc64f8eb4 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -978,6 +978,11 @@ enum { */ ERR_PROCESS_START_INVALID_PID = 2097386, + /** + * Result (2097387) for not expected caller native name. + */ + ERR_NOT_EXPECTED_NATIVE_CALLER_NAME = 2097387, + /** * Native error(3000000) for target bundle not exist. */ diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f8612a2753b..250c17db81a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2636,12 +2636,11 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, bo HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); XCOLLIE_TIMER_LESS(__PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::ABILITYMGR, "call, sceneFlag:%{public}u", sceneFlag); - EventInfo eventInfo = BuildEventInfo(sessionInfo->want, -1); if (sessionInfo == nullptr || sessionInfo->sessionToken == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo null"); - eventHelper_.SendStartAbilityErrorEvent(eventInfo, ERR_INVALID_VALUE, "sessionInfo null", true); return ERR_INVALID_VALUE; } + EventInfo eventInfo = BuildEventInfo(sessionInfo->want, -1); #ifdef MEMMGR_OVERRIDE_ENABLE WantParams wantParams = (sessionInfo->want).GetParams(); std::string bundleName = (sessionInfo->want).GetElement().GetBundleName(); diff --git a/services/abilitymgr/src/utils/update_caller_info_util.cpp b/services/abilitymgr/src/utils/update_caller_info_util.cpp index 5105b90792c..f503f4e82d8 100644 --- a/services/abilitymgr/src/utils/update_caller_info_util.cpp +++ b/services/abilitymgr/src/utils/update_caller_info_util.cpp @@ -15,6 +15,7 @@ #include "utils/update_caller_info_util.h" +#include "ability_event_util.h" #include "ability_util.h" #include "ability_record.h" #include "accesstoken_kit.h" @@ -335,6 +336,15 @@ void UpdateCallerInfoUtil::UpdateCallerAppCloneIndex(Want& want, int32_t appInde void UpdateCallerInfoUtil::ClearProtectedWantParam(Want &want) { + if (want.HasParameter(Want::PARAM_RESV_CALLER_NATIVE_NAME)) { + EventInfo eventInfo; + eventInfo.bundleName = want.GetElement().GetBundleName(); + eventInfo.moduleName = want.GetElement().GetModuleName(); + eventInfo.abilityName = want.GetElement().GetAbilityName(); + AbilityEventUtil eventUtil; + eventUtil.SendStartAbilityErrorEvent(eventInfo, AAFwk::ERR_NOT_EXPECTED_NATIVE_CALLER_NAME, + std::string("no expected caller native name: ") + want.GetStringParam(Want::PARAM_RESV_CALLER_NATIVE_NAME)); + } want.RemoveParam(Want::PARAM_RESV_CALLER_NATIVE_NAME); want.RemoveParam(COMPONENT_STARTUP_NEW_RULES); if (!PermissionVerification::GetInstance()->IsSystemAppCall()) { diff --git a/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp b/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp index 153dd98d132..3c4f2557b75 100644 --- a/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp +++ b/test/unittest/update_caller_info_util_test/update_caller_info_util_test.cpp @@ -160,6 +160,21 @@ HWTEST_F(UpdateCallerInfoUtilTest, ClearProtectedWantParam_002, TestSize.Level1) EXPECT_EQ(want.GetStringParam(Want::PARAM_ABILITY_UNIFIED_DATA_KEY), ""); } +/** + * @tc.name: UpdateCallerInfoUtilTest_ClearProtectedWantParam_003 + * @tc.desc: The caller is system app, do not remove udKey. + * @tc.type: FUNC + */ +HWTEST_F(UpdateCallerInfoUtilTest, ClearProtectedWantParam_003, TestSize.Level1) +{ + std::shared_ptr updateCallerUtil = std::make_shared(); + Want want; + std::string key = "test"; + want.SetParam(Want::PARAM_RESV_CALLER_NATIVE_NAME, key); + updateCallerUtil->ClearProtectedWantParam(want); + EXPECT_EQ(want.GetStringParam(Want::PARAM_RESV_CALLER_NATIVE_NAME), ""); +} + /** * @tc.name: UpdateCallerInfoUtilTest_UpdateAsCallerInfoFromCallerRecord_0002 * @tc.desc: Test the state of QueryAllAutoStartupApplications -- Gitee