diff --git a/frameworks/js/napi/wantagent/ability_want_agent/want_agent_module.cpp b/frameworks/js/napi/wantagent/ability_want_agent/want_agent_module.cpp index 9b9b9b6da3a194be72dd2578af7df3d106fedde6..c1fdbfd9ad2b9b4765c5b0a5f64374dfcca3a903 100644 --- a/frameworks/js/napi/wantagent/ability_want_agent/want_agent_module.cpp +++ b/frameworks/js/napi/wantagent/ability_want_agent/want_agent_module.cpp @@ -61,6 +61,7 @@ napi_value JsNapiWantAgentInit(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "trigger", moduleName, JsWantAgent::NapiTrigger); BindNativeFunction(env, exportObj, "getWant", moduleName, JsWantAgent::NapiGetWant); BindNativeFunction(env, exportObj, "getWantAgent", moduleName, JsWantAgent::NapiGetWantAgent); + BindNativeFunction(env, exportObj, "getWantAgentByUserId", moduleName, JsWantAgent::NapiGetWantAgentByUserId); BindNativeFunction(env, exportObj, "getOperationType", moduleName, JsWantAgent::NapiGetOperationType); BindNativeFunction(env, exportObj, "setWantAgentMultithreading", moduleName, JsWantAgent::NapiSetWantAgentMultithreading); diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index bec652481300d2a91885293a69fde96744f82b7b..96b1ea7ad936941342bef4a7f2b8256ad4119d96 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -303,6 +303,12 @@ napi_value JsWantAgent::NapiGetWantAgent(napi_env env, napi_callback_info info) return (me != nullptr) ? me->OnNapiGetWantAgent(env, info) : nullptr; }; +napi_value JsWantAgent::NapiGetWantAgentByUserId(napi_env env, napi_callback_info info) +{ + JsWantAgent* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnNapiGetWantAgentByUserId(env, info) : nullptr; +} + napi_value JsWantAgent::NapiGetOperationType(napi_env env, napi_callback_info info) { JsWantAgent* me = CheckParamsAndGetThis(env, info); @@ -1198,6 +1204,41 @@ napi_value JsWantAgent::OnNapiGetWantAgent(napi_env env, napi_callback_info info return result; } +napi_value JsWantAgent::OnNapiGetWantAgentByUserId(napi_env env, napi_callback_info info) +{ + size_t argc = ARGS_MAX_COUNT; + napi_value argv[ARGS_MAX_COUNT] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc > ARGC_THREE || argc < ARGC_ONE) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Not enough params"); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + std::shared_ptr spParas = std::make_shared(); + int32_t ret = GetWantAgentParam(env, info, *spParas); + if (ret != 0) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Failed to get wantAgent param"); + ThrowInvalidParamError(env, "Parameter error! Info must be a WantAgentInfo."); + return CreateJsUndefined(env); + } + int32_t userId = -1; + if (!ConvertFromJsValue(env, argv[INDEX_ONE], userId)) { + TAG_LOGE(AAFwkTag::APPKIT, "Parse userId failed"); + ThrowInvalidParamError(env, "Parse param userId failed, userId must be number."); + return CreateJsUndefined(env); + } + + NapiAsyncTask::CompleteCallback complete; + SetOnNapiGetWantAgentByUserIdCallback(spParas, userId, complete); + + napi_value lastParam = (argc >= ARGC_THREE) ? argv[INDEX_TWO] : nullptr; + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JsWantAgent::OnNapiGetWantAgentByUserId", + env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + return result; +} + void JsWantAgent::SetOnNapiGetWantAgentCallback(std::shared_ptr spParas, AbilityRuntime::NapiAsyncTask::CompleteCallback &complete) { @@ -1240,6 +1281,44 @@ void JsWantAgent::SetOnNapiGetWantAgentCallback(std::shared_ptr spParas, int32_t userId, + AbilityRuntime::NapiAsyncTask::CompleteCallback &complete) +{ + complete = [weak = weak_from_this(), parasobj = spParas, userId](napi_env env, + NapiAsyncTask &task, int32_t status) { + TAG_LOGD(AAFwkTag::WANTAGENT, "called"); + auto self = weak.lock(); + std::shared_ptr extraInfo = std::make_shared(parasobj->extraInfo); + WantAgentInfo wantAgentInfo(parasobj->requestCode, + static_cast(parasobj->operationType), + parasobj->wantAgentFlags, + parasobj->wants, + extraInfo); + + auto context = OHOS::AbilityRuntime::Context::GetApplicationContext(); + std::shared_ptr wantAgent = WantAgentHelper::GetWantAgent(wantAgentInfo, userId); + ErrCode result; + if (wantAgent == nullptr) { + result = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; + task.Reject(env, CreateJsError(env, result, AbilityRuntimeErrorUtil::GetErrMessage(result))); + return; + } + WantAgent *pWantAgent = new (std::nothrow) WantAgent(wantAgent->GetPendingWant()); + if (pWantAgent == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "null pWantAgent"); + result = ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; + task.Reject(env, CreateJsError(env, result, AbilityRuntimeErrorUtil::GetErrMessage(result))); + } else { + napi_value jsWantAgent = OHOS::AppExecFwk::WrapWantAgent(env, pWantAgent, nullptr); + if (jsWantAgent == nullptr) { + delete pWantAgent; + pWantAgent = nullptr; + } + task.ResolveWithNoError(env, jsWantAgent); + } + }; +} + napi_value JsWantAgent::OnNapiGetOperationType(napi_env env, napi_callback_info info) { TAG_LOGI(AAFwkTag::WANTAGENT, "called"); diff --git a/frameworks/js/napi/wantagent/napi_want_agent.h b/frameworks/js/napi/wantagent/napi_want_agent.h index 92ccb769a26d2bbf5044843f4b767cc0a34909e9..754035df98b99fe373caf81d7ecfd54e758a725d 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.h +++ b/frameworks/js/napi/wantagent/napi_want_agent.h @@ -92,6 +92,7 @@ public: static napi_value NapiGetWant(napi_env env, napi_callback_info info); static napi_value NapiTrigger(napi_env env, napi_callback_info info); static napi_value NapiGetWantAgent(napi_env env, napi_callback_info info); + static napi_value NapiGetWantAgentByUserId(napi_env env, napi_callback_info info); static napi_value NapiGetOperationType(napi_env env, napi_callback_info info); static napi_value NapiSetWantAgentMultithreading(napi_env env, napi_callback_info info); @@ -107,6 +108,7 @@ private: napi_value OnNapiGetWant(napi_env env, napi_callback_info info); napi_value OnNapiTrigger(napi_env env, napi_callback_info info); napi_value OnNapiGetWantAgent(napi_env env, napi_callback_info info); + napi_value OnNapiGetWantAgentByUserId(napi_env env, napi_callback_info info); napi_value OnNapiGetOperationType(napi_env env, napi_callback_info info); napi_value OnNapiSetWantAgentMultithreading(napi_env env, napi_callback_info info); int32_t UnWrapTriggerInfoParam(napi_env env, napi_callback_info info, @@ -123,6 +125,8 @@ private: AbilityRuntime::NapiAsyncTask::CompleteCallback &complete); void SetOnNapiGetWantAgentCallback(std::shared_ptr spParas, AbilityRuntime::NapiAsyncTask::CompleteCallback &complete); + void SetOnNapiGetWantAgentByUserIdCallback(std::shared_ptr spParas, int32_t userId, + AbilityRuntime::NapiAsyncTask::CompleteCallback &complete); int32_t GetTriggerWant(napi_env env, napi_value param, std::shared_ptr &want); int32_t GetTriggerPermission(napi_env env, napi_value param, std::string &permission); int32_t GetTriggerExtraInfo(napi_env env, napi_value param, std::shared_ptr &extraInfo); diff --git a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp index fbe194df57df074eed4208b73e262a9890a45850..ff41d86f1be4f370879635f0ccca9f934e2b6146 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp @@ -361,6 +361,7 @@ std::string WantAgentHelper::ToString(const std::shared_ptr &agent) jsonObject["requestCode"] = (*info.get()).requestCode; jsonObject["operationType"] = (*info.get()).type; jsonObject["flags"] = (*info.get()).flags; + jsonObject["userId"] = (*info.get()).userId; nlohmann::json wants = nlohmann::json::array(); for (auto &wantInfo : (*info.get()).allWants) { @@ -392,6 +393,10 @@ std::shared_ptr WantAgentHelper::FromString(const std::string &jsonSt if (jsonObject.contains("requestCode") && jsonObject["requestCode"].is_number_integer()) { requestCode = jsonObject.at("requestCode").get(); } + int userId = -1; + if (jsonObject.contains("userId") && jsonObject["userId"].is_number_integer()) { + userId = jsonObject.at("userId").get(); + } WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::UNKNOWN_TYPE; if (jsonObject.contains("operationType") && jsonObject["operationType"].is_number_integer()) { @@ -423,7 +428,7 @@ std::shared_ptr WantAgentHelper::FromString(const std::string &jsonSt } WantAgentInfo info(requestCode, operationType, flagsVec, wants, extraInfo); - return GetWantAgent(info, INVLID_WANT_AGENT_USER_ID, uid); + return GetWantAgent(info, userId, uid); } std::vector WantAgentHelper::ParseFlags(nlohmann::json jsonObject) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 24ff8c79fa2486dc07311ecd2813e3ef8f214dea..5932234a45116658f8a9af2ed203c9d5dce8ff50 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2279,6 +2279,7 @@ private: void PauseOldMissionListManager(int32_t userId); void PauseOldConnectManager(int32_t userId); bool IsSystemUI(const std::string &bundleName) const; + int32_t GetUidByCloneBundleInfo(std::string &bundleName, int32_t callerUid, int32_t appIndex, int32_t userId); bool VerificationAllToken(const sptr &token); std::shared_ptr GetCurrentDataAbilityManager(); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index c5e3ccdc9ba15788d51d76d8e7d446170798a0d8..a53da1ac6dc69a990d37cc7aeed5c2112b98c605 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5254,29 +5254,27 @@ int AbilityManagerService::UnRegisterMissionListener(const std::string &deviceId return dmsClient.UnRegisterMissionListener(Str8ToStr16(deviceId), listener->AsObject()); } +int32_t AbilityManagerService::GetUidByCloneBundleInfo( + std::string &bundleName, int32_t callerUid, int32_t appIndex, int32_t userId) +{ + auto bms = AbilityUtil::GetBundleManagerHelper(); + CHECK_POINTER_AND_RETURN(bms, -1); + AppExecFwk::BundleInfo bundleInfo; + MultiAppUtils::GetRunningMultiAppIndex(bundleName, callerUid, appIndex); + if (IN_PROCESS_CALL(bms->GetCloneBundleInfo( + bundleName, static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), + appIndex, bundleInfo, userId)) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed get bundle info for %{public}s", bundleName.c_str()); + return -1; + } + return bundleInfo.uid; +} + sptr AbilityManagerService::GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken, int32_t uid) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER_AND_RETURN(pendingWantManager, nullptr); - - auto bms = AbilityUtil::GetBundleManagerHelper(); - CHECK_POINTER_AND_RETURN(bms, nullptr); - - int32_t callerUid = IPCSkeleton::GetCallingUid(); - int32_t userId = wantSenderInfo.userId; - int32_t bundleMgrResult = 0; - - if (userId < 0) { - if (DelayedSingleton::GetInstance()-> - GetOsAccountLocalIdFromUid(callerUid, userId) != 0) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid failed uid=%{public}d", callerUid); - return nullptr; - } - } - TAG_LOGD(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid userId: %{public}d", userId); //sa caller and has uid,no need find from bms. bool isSpecifyUidBySa = (uid != -1) && (AAFwk::PermissionVerification::GetInstance()->IsSACall()); @@ -5286,31 +5284,53 @@ sptr AbilityManagerService::GetWantSender( if (!wantSenderInfo.allWants.empty()) { bundleName = wantSenderInfo.allWants.back().want.GetElement().GetBundleName(); } - if (!bundleName.empty()) { - if (!isSpecifyUidBySa) { - AppExecFwk::BundleInfo bundleInfo; - MultiAppUtils::GetRunningMultiAppIndex(bundleName, callerUid, appIndex); - bundleMgrResult = IN_PROCESS_CALL(bms->GetCloneBundleInfo(bundleName, - static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), - appIndex, bundleInfo, userId)); - if (bundleMgrResult == ERR_OK) { - appUid = bundleInfo.uid; - } + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerUserId = callerUid / BASE_USER_RANGE; + int32_t userId = -1; + std::shared_ptr pendingWantManager; + bool isSpecifyUserId = wantSenderInfo.userId >= 0; + bool isSystemApp = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); + if ((isSpecifyUidBySa || callerUserId == U0_USER_ID) && isSpecifyUserId) { + userId = wantSenderInfo.userId; + pendingWantManager = GetPendingWantManagerByUserId(userId); + if (uid >= 0) { + appUid = uid; } else { + appUid = GetUidByCloneBundleInfo(bundleName, callerUid, appIndex, userId); + } + } else if ((isSpecifyUidBySa || callerUserId == U0_USER_ID) && !isSpecifyUserId) { + if (uid >= 0) { + if (DelayedSingleton::GetInstance()-> + GetOsAccountLocalIdFromUid(callerUid, userId) != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid failed uid=%{public}d", callerUid); + return nullptr; + } appUid = uid; + } else { + userId = callerUserId; + appUid = GetUidByCloneBundleInfo(bundleName, callerUid, appIndex, userId); + } + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else if (!isSystemApp) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "called by normal app"); + userId = callerUserId; + appUid = callerUid; + } else if (isSystemApp) { + if (isSpecifyUserId) { + userId = wantSenderInfo.userId; + } else { + userId = callerUserId; } - TAG_LOGD(AAFwkTag::ABILITYMGR, - "bundleName: %{public}s, uid: %{public}d, userId: %{public}d, appIndex: %{public}d", bundleName.c_str(), - appUid, userId, appIndex); + appUid = GetUidByCloneBundleInfo(bundleName, callerUid, appIndex, userId); } - if (!CheckSenderWantInfo(callerUid, wantSenderInfo)) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + CHECK_POINTER_AND_RETURN(pendingWantManager, nullptr); + if (!CheckSenderWantInfo(appUid, wantSenderInfo)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "check bundleName failed"); return nullptr; } - bool isSystemApp = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); - - TAG_LOGI(AAFwkTag::ABILITYMGR, "bundleName: %{public}s, appIndex: %{public}d, isSystemApp: %{public}d, " + TAG_LOGD(AAFwkTag::ABILITYMGR, "bundleName: %{public}s, appIndex: %{public}d, isSystemApp: %{public}d, " "userId: %{public}d", wantSenderInfo.bundleName.c_str(), appIndex, isSystemApp, userId); return pendingWantManager->GetWantSender(callerUid, appUid, isSystemApp, wantSenderInfo, callerToken, appIndex); } @@ -5318,17 +5338,31 @@ sptr AbilityManagerService::GetWantSender( int AbilityManagerService::SendWantSender(sptr target, const SenderInfo &senderInfo) { TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER_AND_RETURN(pendingWantManager, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(target, ERR_INVALID_VALUE); + sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return ERR_INVALID_VALUE; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, ERR_INVALID_VALUE); + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } + CHECK_POINTER_AND_RETURN(pendingWantManager, ERR_INVALID_VALUE); return pendingWantManager->SendWantSender(target, senderInfo); } void AbilityManagerService::CancelWantSender(const sptr &sender) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER(pendingWantManager); CHECK_POINTER(sender); sptr obj = sender->AsObject(); @@ -5336,19 +5370,20 @@ void AbilityManagerService::CancelWantSender(const sptr &sender) TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); return; } - - auto bms = AbilityUtil::GetBundleManagerHelper(); - CHECK_POINTER(bms); - - int32_t callerUid = IPCSkeleton::GetCallingUid(); sptr record = iface_cast(obj); + CHECK_POINTER(record); - int userId = -1; - if (DelayedSingleton::GetInstance()-> - GetOsAccountLocalIdFromUid(callerUid, userId) != 0) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid failed uid=%{public}d", callerUid); - return; + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); } + CHECK_POINTER(pendingWantManager); TAG_LOGD(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid userId: %{public}d", userId); bool isSystemAppCall = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); @@ -5390,12 +5425,29 @@ void AbilityManagerService::CancelWantSenderByFlags(const sptr &sen int AbilityManagerService::GetPendingWantUid(const sptr &target) { TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s:begin", __func__); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER_AND_RETURN(pendingWantManager, -1); if (target == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%s, target null", __func__); return -1; } + sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return -1; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, -1); + + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } + CHECK_POINTER_AND_RETURN(pendingWantManager, -1); return pendingWantManager->GetPendingWantUid(target); } @@ -5415,21 +5467,56 @@ std::string AbilityManagerService::GetPendingWantBundleName(const sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return ""; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, ""); + + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } + CHECK_POINTER_AND_RETURN(pendingWantManager, ""); return pendingWantManager->GetPendingWantBundleName(target); } int AbilityManagerService::GetPendingWantCode(const sptr &target) { TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s:begin", __func__); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER_AND_RETURN(pendingWantManager, -1); if (target == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%s, target null", __func__); return -1; } + sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return -1; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, -1); + + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } + CHECK_POINTER_AND_RETURN(pendingWantManager, -1); return pendingWantManager->GetPendingWantCode(target); } @@ -5437,12 +5524,29 @@ int AbilityManagerService::GetPendingWantType(const sptr &target) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); XCOLLIE_TIMER_DEFAULT(__PRETTY_FUNCTION__); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER_AND_RETURN(pendingWantManager, -1); if (target == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%s, target null", __func__); return -1; } + sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return -1; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, -1); + + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } + CHECK_POINTER_AND_RETURN(pendingWantManager, -1); return pendingWantManager->GetPendingWantType(target); } @@ -5473,7 +5577,28 @@ int AbilityManagerService::GetPendingRequestWant(const sptr &target HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "Get pending request want."); XCOLLIE_TIMER_DEFAULT(__PRETTY_FUNCTION__); - auto pendingWantManager = GetCurrentPendingWantManager(); + if (target == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "%s, target null", __func__); + return -1; + } + sptr obj = target->AsObject(); + if (!obj || obj->IsProxyObject()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); + return -1; + } + sptr record = iface_cast(obj); + CHECK_POINTER_AND_RETURN(record, -1); + + int32_t userId = -1; + if (record->GetKey() != nullptr) { + userId = record->GetKey()->GetUserId(); + } + std::shared_ptr pendingWantManager; + if (userId > 0) { + pendingWantManager = GetPendingWantManagerByUserId(userId); + } else { + pendingWantManager = GetCurrentPendingWantManager(); + } CHECK_POINTER_AND_RETURN(pendingWantManager, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(target, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(want, ERR_INVALID_VALUE);