diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 24ff8c79fa2486dc07311ecd2813e3ef8f214dea..c53970ccaaba334b865b2228fe442b3c642455ab 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2320,7 +2320,7 @@ private: void RetrySubscribeScreenUnlockedEvent(int32_t retryCount); void RemoveScreenUnlockInterceptor(); void RemoveUnauthorizedLaunchReasonMessage(const Want &want, AbilityRequest &abilityRequest, - const sptr &callerToken); + uint32_t callerTokenId); int VerifyAccountPermission(int32_t userId); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index c5e3ccdc9ba15788d51d76d8e7d446170798a0d8..a5c6c0f331b605302dd32d4bd3a245933579ac09 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1364,8 +1364,8 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(specifyTokenId)); abilityRequest.specifyTokenId = specifyTokenId; } - - RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerToken); + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerTokenId); abilityRequest.want.RemoveParam(PARAM_SPECIFIED_PROCESS_FLAG); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { abilityRequest.userId = oriValidUserId; @@ -2501,7 +2501,8 @@ int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionI StartAbilityUtils::skipErms = true; } Want newWant = abilityRequest.want; - RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, sessionInfo->callerToken); + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + RemoveUnauthorizedLaunchReasonMessage(sessionInfo->want, abilityRequest, callerTokenId); AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), true, sessionInfo->callerToken, std::make_shared(abilityInfo), false, appIndex); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : @@ -7888,7 +7889,7 @@ void AbilityManagerService::RemoveScreenUnlockInterceptor() } void AbilityManagerService::RemoveUnauthorizedLaunchReasonMessage(const Want &want, AbilityRequest &abilityRequest, - const sptr &callerToken) + uint32_t callerTokenId) { std::string value = want.GetStringParam(Want::PARM_LAUNCH_REASON_MESSAGE); TAG_LOGD(AAFwkTag::ABILITYMGR, "launchReasonMessage:%{public}s", value.c_str()); @@ -7898,28 +7899,13 @@ void AbilityManagerService::RemoveUnauthorizedLaunchReasonMessage(const Want &wa abilityRequest.want.RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); return; } - - if (callerToken == nullptr) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "callertoken is nullptr, remove launch reason message."); + if (!PermissionVerification::GetInstance()->VerifyPermissionByTokenId(callerTokenId, + PermissionConstants::PERMISSION_SET_LAUNCH_REASON_MESSAGE) || + (!PermissionVerification::GetInstance()->IsSystemAppCall() && + !PermissionVerification::GetInstance()->IsSACall())) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "verifyPermission failed, remove launch reason message."); (const_cast(want)).RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); abilityRequest.want.RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); - } else { - auto targetRecord = Token::GetAbilityRecordByToken(callerToken); - if (targetRecord == nullptr) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "targetRecord is nullptr."); - (const_cast(want)).RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); - abilityRequest.want.RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); - return; - } - auto tokenId = targetRecord->GetAbilityInfo().applicationInfo.accessTokenId; - if (!PermissionVerification::GetInstance()->VerifyPermissionByTokenId(tokenId, - PermissionConstants::PERMISSION_SET_LAUNCH_REASON_MESSAGE) || - (!PermissionVerification::GetInstance()->IsSystemAppCall() && - !PermissionVerification::GetInstance()->IsSACall())) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "verifyPermission failed, remove launch reason message."); - (const_cast(want)).RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); - abilityRequest.want.RemoveParam(Want::PARM_LAUNCH_REASON_MESSAGE); - } } } @@ -8188,8 +8174,8 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const TAG_LOGE(AAFwkTag::ABILITYMGR, "afterCheckExecuter_ null or doProcess error"); return result; } - - RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerToken); + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerTokenId); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { ReportEventToRSS(abilityRequest.abilityInfo, callerToken); abilityRequest.want.SetParam(ServerConstant::IS_CALL_BY_SCB, false); diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index cfcf6e7c6c498046b1c6fec7c9e55c76aaab6b3f..71773e07fae3c36ecd389644a2a789ca9ea0bbea 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -624,6 +624,7 @@ bool AppUtils::IsSystemReasonMessage(const std::string &reasonMessage) { const std::unordered_set systemReasonMessagesSet = { "ReasonMessage_SystemShare", + "ReasonMessage_DesktopShortcut", }; return systemReasonMessagesSet.find(reasonMessage) != systemReasonMessagesSet.end(); } diff --git a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp index 5ab40511bcc5f024e0a17176f70cb1aa58395a0b..a29a440af5b6431af82b3cc02f0bc434a14b01b8 100644 --- a/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp +++ b/test/unittest/ability_manager_service_twelfth_test/ability_manager_service_twelfth_test.cpp @@ -482,10 +482,11 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, GetUserScreenUnlockCallback_001, Test abilityMs_->RetrySubscribeScreenUnlockedEvent(retryCount); Want want; AbilityRequest abilityRequest; - abilityMs_->RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, nullptr); + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + abilityMs_->RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerTokenId); std::string testText = "AbilityManagerServiceTwelfthTest"; want.SetParam(Want::PARM_LAUNCH_REASON_MESSAGE, testText); - abilityMs_->RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, nullptr); + abilityMs_->RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerTokenId); auto ret = abilityMs_->GetUserScreenUnlockCallback(); if (ret) { ret();