From 4c03f6814cebd1962d7da8a07794a2101b228ed3 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Sat, 6 Sep 2025 17:26:17 +0800 Subject: [PATCH] support wantAgent multiuser Signed-off-by: zhangzezhong --- .../js/napi/wantagent/napi_want_agent.cpp | 13 +- .../js/napi/wantagent/napi_want_agent.h | 1 + .../wantagent/include/pending_want.h | 2 +- .../wantagent/include/want_agent_info.h | 10 +- .../inner_api/wantagent/src/pending_want.cpp | 14 +- .../wantagent/src/want_agent_helper.cpp | 11 +- .../wantagent/src/want_agent_info.cpp | 8 +- .../include/ability_manager_service.h | 5 +- .../src/ability_manager_service.cpp | 242 +++++++-- .../ability_manager_service_eleven_test.cpp | 484 +++++++++++++++++- 10 files changed, 734 insertions(+), 56 deletions(-) diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index 445affef69f..0bedfb765ef 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -970,6 +970,16 @@ int32_t JsWantAgent::GetWantAgentParam(napi_env env, napi_callback_info info, Wa return PARAMETER_ERROR; } + bool hasUserId = false; + napi_has_named_property(env, argv[0], "userId", &hasUserId); + if (hasUserId) { + napi_value jsUserId = nullptr; + napi_get_named_property(env, argv[0], "userId", &jsUserId); + if (!ConvertFromJsValue(env, jsUserId, paras.userId)) { + TAG_LOGE(AAFwkTag::WANTAGENT, "Convert userId failed"); + return PARAMETER_ERROR; + } + } bool hasActionFlags = false; napi_has_named_property(env, argv[0], "actionFlags", &hasActionFlags); if (hasActionFlags) { @@ -1341,7 +1351,8 @@ void JsWantAgent::SetOnNapiGetWantAgentCallback(std::shared_ptr(parasobj->operationType), parasobj->wantAgentFlags, parasobj->wants, - extraInfo); + extraInfo, + parasobj->userId); auto context = OHOS::AbilityRuntime::Context::GetApplicationContext(); std::shared_ptr wantAgent = nullptr; diff --git a/frameworks/js/napi/wantagent/napi_want_agent.h b/frameworks/js/napi/wantagent/napi_want_agent.h index 626083f2c63..31c02dbd58c 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.h +++ b/frameworks/js/napi/wantagent/napi_want_agent.h @@ -76,6 +76,7 @@ struct WantAgentWantsParas { std::vector> wants = {}; int32_t operationType = -1; int32_t requestCode = -1; + int32_t userId = -1; std::vector wantAgentFlags = {}; AAFwk::WantParams extraInfo = {}; }; diff --git a/interfaces/inner_api/wantagent/include/pending_want.h b/interfaces/inner_api/wantagent/include/pending_want.h index 00ab6d4fe03..4cdebd5a0c5 100644 --- a/interfaces/inner_api/wantagent/include/pending_want.h +++ b/interfaces/inner_api/wantagent/include/pending_want.h @@ -74,7 +74,7 @@ public: const std::shared_ptr &context, int requestCode, const std::shared_ptr &want, unsigned int flags, const std::shared_ptr &options, - std::shared_ptr &pendingWant); + std::shared_ptr &pendingWant, int userId = -1); /** * Like GetAbility(Context, int, Want, int)}, but allows an diff --git a/interfaces/inner_api/wantagent/include/want_agent_info.h b/interfaces/inner_api/wantagent/include/want_agent_info.h index 326c73e7b68..03a718bc381 100644 --- a/interfaces/inner_api/wantagent/include/want_agent_info.h +++ b/interfaces/inner_api/wantagent/include/want_agent_info.h @@ -69,7 +69,7 @@ public: */ WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, const std::vector &flags, std::vector> &Wants, - const std::shared_ptr &extraInfo); + const std::shared_ptr &extraInfo, int userId = -1); /** * A constructor used to create an WantAgentInfo instance by copying parameters from an existing one. @@ -113,8 +113,16 @@ public: */ std::shared_ptr GetExtraInfo() const; + /** + * Obtains the userId of the WantAgent object. + * + * @return Returns the userId of the WantAgent object. + */ + int GetUserId() const; + private: int requestCode_ = 0; + int userId_ = -1; WantAgentConstant::OperationType operationType_ = WantAgentConstant::OperationType::UNKNOWN_TYPE; std::vector flags_ = std::vector(); std::vector> wants_ = std::vector>(); diff --git a/interfaces/inner_api/wantagent/src/pending_want.cpp b/interfaces/inner_api/wantagent/src/pending_want.cpp index cccc8d57cd9..a2670d6c823 100644 --- a/interfaces/inner_api/wantagent/src/pending_want.cpp +++ b/interfaces/inner_api/wantagent/src/pending_want.cpp @@ -57,13 +57,17 @@ ErrCode PendingWant::GetAbility( const std::shared_ptr &context, int requestCode, const std::shared_ptr &want, unsigned int flags, const std::shared_ptr &options, - std::shared_ptr &pendingWant) + std::shared_ptr &pendingWant, int userId) { if (context == nullptr) { TAG_LOGE(AAFwkTag::WANTAGENT, "invalid input param"); return ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; } + if (want == nullptr) { + TAG_LOGE(AAFwkTag::WANTAGENT, "input param want is nullptr"); + return ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; + } WantsInfo wantsInfo; wantsInfo.want = *want; wantsInfo.resolvedTypes = want != nullptr ? want->GetType() : ""; @@ -74,9 +78,13 @@ ErrCode PendingWant::GetAbility( WantSenderInfo wantSenderInfo; wantSenderInfo.type = static_cast(WantAgentConstant::OperationType::START_ABILITY); wantSenderInfo.allWants.push_back(wantsInfo); - wantSenderInfo.bundleName = context->GetBundleName(); + if (userId >= 0) { + wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); + } else { + wantSenderInfo.bundleName = context->GetBundleName(); + } wantSenderInfo.flags = flags; - wantSenderInfo.userId = -1; // -1 : invalid user id + wantSenderInfo.userId = userId; wantSenderInfo.requestCode = requestCode; sptr target = nullptr; ErrCode result = WantAgentClient::GetInstance().GetWantSender(wantSenderInfo, nullptr, target); diff --git a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp index 5f7d6248e40..06c7b6bda77 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_helper.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_helper.cpp @@ -112,11 +112,12 @@ ErrCode WantAgentHelper::GetWantAgent( std::shared_ptr extraInfo = paramsInfo.GetExtraInfo(); std::shared_ptr pendingWant = nullptr; int requestCode = paramsInfo.GetRequestCode(); + int userId = paramsInfo.GetUserId(); WantAgentConstant::OperationType operationType = paramsInfo.GetOperationType(); ErrCode result; switch (operationType) { case WantAgentConstant::OperationType::START_ABILITY: - result = PendingWant::GetAbility(context, requestCode, wants[0], flags, extraInfo, pendingWant); + result = PendingWant::GetAbility(context, requestCode, wants[0], flags, extraInfo, pendingWant, userId); break; case WantAgentConstant::OperationType::START_ABILITIES: result = PendingWant::GetAbilities(context, requestCode, wants, flags, extraInfo, pendingWant); @@ -468,6 +469,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) { @@ -500,6 +502,11 @@ std::shared_ptr WantAgentHelper::FromString(const std::string &jsonSt 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()) { operationType = static_cast(jsonObject.at("operationType").get()); @@ -530,7 +537,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/interfaces/inner_api/wantagent/src/want_agent_info.cpp b/interfaces/inner_api/wantagent/src/want_agent_info.cpp index f2f62d14247..001b42fc72b 100644 --- a/interfaces/inner_api/wantagent/src/want_agent_info.cpp +++ b/interfaces/inner_api/wantagent/src/want_agent_info.cpp @@ -44,10 +44,11 @@ WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::Operation WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType, const std::vector &flags, std::vector> &wants, - const std::shared_ptr &extraInfo) + const std::shared_ptr &extraInfo, int userId) { requestCode_ = requestCode; operationType_ = operationType; + userId_ = userId; if (!flags.empty()) { flags_.insert(flags_.end(), flags.begin(), flags.end()); } @@ -105,4 +106,9 @@ std::shared_ptr WantAgentInfo::GetExtraInfo() const { return extraInfo_; } + +int WantAgentInfo::GetUserId() const +{ + return userId_; +} } // namespace OHOS::AbilityRuntime::WantAgent diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index a5050ce4158..91979f5f49a 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2346,7 +2346,10 @@ 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 userId) const; + int32_t GetUidByCloneBundleInfo(std::string &bundleName, int32_t callerUid, int32_t userId, + int32_t &appIndex) const; + sptr GetWantSenderByUserId(const WantSenderInfo &wantSenderInfo, + const sptr &callerToken, int32_t uid, int32_t callerUid, int32_t callerUserId); 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 9fe1a9780bf..03f95380b4a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5836,12 +5836,12 @@ 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 userId) const +int32_t AbilityManagerService::GetUidByCloneBundleInfo( + std::string &bundleName, int32_t callerUid, int32_t userId, int32_t &appIndex) const { auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, -1); AppExecFwk::BundleInfo bundleInfo; - int32_t appIndex = 0; MultiAppUtils::GetRunningMultiAppIndex(bundleName, callerUid, appIndex); if (IN_PROCESS_CALL(bms->GetCloneBundleInfo( bundleName, static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), @@ -5852,27 +5852,78 @@ int32_t AbilityManagerService::GetUidByCloneBundleInfo(std::string &bundleName, return bundleInfo.uid; } +sptr AbilityManagerService::GetWantSenderByUserId(const WantSenderInfo &wantSenderInfo, + const sptr &callerToken, int32_t uid, int32_t callerUid, int32_t callerUserId) +{ + bool isSpecifyUserId = wantSenderInfo.userId >= 0; + std::string bundleName = ""; + if (!wantSenderInfo.allWants.empty()) { + bundleName = wantSenderInfo.allWants.back().want.GetElement().GetBundleName(); + } + bool isSACall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + bool isSystemApp = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); + + int32_t userId = -1; + int32_t appUid = -1; + int32_t appIndex = 0; + if (isSACall || callerUserId == U0_USER_ID) { + if (isSpecifyUserId) { + userId = wantSenderInfo.userId; + appUid = (uid >= 0) ? uid : GetUidByCloneBundleInfo(bundleName, callerUid, appIndex, userId); + } else 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); + } + } else if (isSystemApp) { + userId = isSpecifyUserId ? wantSenderInfo.userId : callerUserId; + appUid = GetUidByCloneBundleInfo(bundleName, callerUid, appIndex, userId); + } else { + userId = callerUserId; + appUid = callerUid; + } + std::shared_ptr pendingWantManager = GetPendingWantManagerByUserId(userId); + CHECK_POINTER_AND_RETURN(pendingWantManager, nullptr); + if (!CheckSenderWantInfo(appUid, wantSenderInfo)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "check bundleName failed for appUid: %{public}d", appUid); + return nullptr; + } + const_cast(wantSenderInfo).userId = userId; + TAG_LOGI(AAFwkTag::ABILITYMGR, "bundleName: %{public}s, appIndex: %{public}d, isSystemApp: %{public}d, " + "isSACall: %{public}d, userId: %{public}d, appUid: %{public}d", bundleName.c_str(), appIndex, isSystemApp, + isSACall, userId, appUid); + + return pendingWantManager->GetWantSender(callerUid, appUid, isSystemApp, wantSenderInfo, callerToken, appIndex); +} + sptr AbilityManagerService::GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken, int32_t uid) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); + int32_t userId = wantSenderInfo.userId; + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerUserId = callerUid / BASE_USER_RANGE; + if (userId >= 0 || callerUserId == U0_USER_ID) { + return GetWantSenderByUserId(wantSenderInfo, callerToken, uid, callerUid, callerUserId); + } 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; - } + 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. @@ -5916,9 +5967,25 @@ sptr AbilityManagerService::GetWantSender( int AbilityManagerService::SendWantSender(sptr target, 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); } @@ -5938,8 +6005,6 @@ int AbilityManagerService::SendLocalWantSender(const SenderInfo &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(); @@ -5947,19 +6012,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(); @@ -5969,22 +6035,28 @@ void AbilityManagerService::CancelWantSender(const sptr &sender) void AbilityManagerService::CancelWantSenderByFlags(const sptr &sender, uint32_t flags) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); - auto pendingWantManager = GetCurrentPendingWantManager(); - CHECK_POINTER(pendingWantManager); CHECK_POINTER(sender); - sptr obj = sender->AsObject(); if (!obj || obj->IsProxyObject()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj"); return; } - - auto bms = AbilityUtil::GetBundleManagerHelper(); - CHECK_POINTER(bms); - sptr record = iface_cast(obj); CHECK_POINTER(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(); + } + + auto bms = AbilityUtil::GetBundleManagerHelper(); + CHECK_POINTER(bms); if (flags != 0 && record->GetKey() != nullptr && (static_cast(record->GetKey()->GetFlags()) & flags) == 0) { TAG_LOGI(AAFwkTag::ABILITYMGR, "flags=%{public}u not match wantAgent flags=%{public}d", @@ -6001,12 +6073,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); } @@ -6026,21 +6115,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); } @@ -6048,12 +6172,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); } @@ -6084,10 +6225,27 @@ 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(); - CHECK_POINTER_AND_RETURN(pendingWantManager, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(target, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(want, ERR_INVALID_VALUE); + 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_CALLER_IS_SYSTEM_APP; return pendingWantManager->GetPendingRequestWant(target, want); } diff --git a/test/unittest/ability_manager_service_eleven_test/ability_manager_service_eleven_test.cpp b/test/unittest/ability_manager_service_eleven_test/ability_manager_service_eleven_test.cpp index 3176db75deb..ed145fd8088 100644 --- a/test/unittest/ability_manager_service_eleven_test/ability_manager_service_eleven_test.cpp +++ b/test/unittest/ability_manager_service_eleven_test/ability_manager_service_eleven_test.cpp @@ -70,6 +70,10 @@ public: class MockPendingWantRecord : public PendingWantRecord { public: + MockPendingWantRecord() : PendingWantRecord() {}; + MockPendingWantRecord(const std::shared_ptr &pendingWantManager, int32_t uid, + int32_t callerTokenId, const sptr &callerToken, std::shared_ptr key) + : PendingWantRecord(pendingWantManager, uid, callerTokenId, callerToken, key) {}; virtual ~MockPendingWantRecord() {}; bool IsProxyObject() const override { @@ -81,8 +85,19 @@ public: proxyObject_ = proxyObject; } + std::shared_ptr GetKey() + { + return key_; + } + + void SetKey(std::shared_ptr key) + { + key_ = key; + } + private: bool proxyObject_ = false; + std::shared_ptr key_; }; class MockIWantSender : public IWantSender { @@ -255,8 +270,15 @@ HWTEST_F(AbilityManagerServiceElevenTest, GetWantSender_0002, TestSize.Level1) EXPECT_EQ(result, nullptr); MyFlag::flag_ = 1; - wantSenderInfo.userId = 1; - uid = 1; + wantSenderInfo.userId = 100; + bundleName = "com.ohos.settings"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + wantsInfo.want = want; + wantSenderInfo.allWants.clear(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + abilityMs->subManagersHelper_->pendingWantManagers_.emplace( + wantSenderInfo.userId, std::make_shared(nullptr)); EXPECT_EQ(wantSenderInfo.allWants.size(), 1); result = abilityMs->GetWantSender(wantSenderInfo, nullptr, uid); EXPECT_NE(result, nullptr); @@ -264,6 +286,191 @@ HWTEST_F(AbilityManagerServiceElevenTest, GetWantSender_0002, TestSize.Level1) GTEST_LOG_(INFO) << "GetWantSender_0002 end"; } +/* + * Feature: GetWantSender_0003 + * Function: GetWantSender + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetWantSender + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetWantSender_0003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetWantSender_0003 start"; + auto abilityMs = std::make_shared(); + EXPECT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + EXPECT_NE(abilityMs->subManagersHelper_, nullptr); + + MyFlag::flag_ = 1; + WantSenderInfo wantSenderInfo; + wantSenderInfo.userId = 100; + AAFwk::Want want; + AAFwk::Operation operation; + std::string bundleName = "com.ohos.settings"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + WantsInfo wantsInfo; + wantsInfo.want = want; + wantsInfo.resolvedTypes = want.GetType(); + wantSenderInfo.allWants.clear(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + abilityMs->subManagersHelper_->pendingWantManagers_.emplace( + wantSenderInfo.userId, std::make_shared(nullptr)); + EXPECT_EQ(wantSenderInfo.allWants.size(), 1); + auto result = abilityMs->GetWantSender(wantSenderInfo, nullptr, -1); + EXPECT_NE(result, nullptr); + GTEST_LOG_(INFO) << "GetWantSender_0003 end"; +} + +/* + * Feature: GetWantSenderByUserId_0001 + * Function: GetWantSenderByUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetWantSenderByUserId + * EnvConditions: NA + * CaseDescription: Test GetWantSenderByUserId when isSACall is true and userId is specified + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetWantSenderByUserId_0001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0001 start"; + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + // Mock SACall permission + MyFlag::flag_ = 1; + WantSenderInfo wantSenderInfo; + wantSenderInfo.userId = 100; + AAFwk::Want want; + AAFwk::Operation operation; + std::string bundleName = "com.ohos.settings"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + WantsInfo wantsInfo; + wantsInfo.want = want; + wantsInfo.resolvedTypes = want.GetType(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + + int32_t callerUid = 20010080; + int32_t callerUserId = 0; + abilityMs->GetWantSenderByUserId(wantSenderInfo, nullptr, -1, callerUid, callerUserId); + // Mock pending want manager + abilityMs->subManagersHelper_->pendingWantManagers_.emplace( + wantSenderInfo.userId, std::make_shared(nullptr)); + auto result = abilityMs->GetWantSenderByUserId(wantSenderInfo, nullptr, callerUid, callerUid, callerUserId); + EXPECT_NE(result, nullptr); + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0001 end"; +} + +/* + * Feature: GetWantSenderByUserId_0002 + * Function: GetWantSenderByUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetWantSenderByUserId + * EnvConditions: NA + * CaseDescription: Test GetWantSenderByUserId when isSACall is true and userId is not specified + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetWantSenderByUserId_0002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0002 start"; + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + MyFlag::flag_ = 1; + + WantSenderInfo wantSenderInfo; + wantSenderInfo.userId = -1; + AAFwk::Want want; + AAFwk::Operation operation; + std::string bundleName = "com.ohos.settings"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + WantsInfo wantsInfo; + wantsInfo.want = want; + wantsInfo.resolvedTypes = want.GetType(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + int32_t callerUid = 20010080; + int32_t callerUserId = 0; + abilityMs->subManagersHelper_->pendingWantManagers_.clear(); + auto result = abilityMs->GetWantSenderByUserId(wantSenderInfo, nullptr, callerUid, callerUid, callerUserId); + EXPECT_EQ(result, nullptr); + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0002 end"; +} + +/* + * Feature: GetWantSenderByUserId_0003 + * Function: GetWantSenderByUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetWantSenderByUserId + * EnvConditions: NA + * CaseDescription: Test GetWantSenderByUserId when isSACall is true and userId is not specified + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetWantSenderByUserId_0003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0003 start"; + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + MyFlag::flag_ = 1; + WantSenderInfo wantSenderInfo; + wantSenderInfo.userId = -1; + AAFwk::Want want; + AAFwk::Operation operation; + std::string bundleName = "com.ohos.settings"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + WantsInfo wantsInfo; + wantsInfo.want = want; + wantsInfo.resolvedTypes = want.GetType(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + int32_t uid = -1; + int32_t callerUid = 20010080; + int32_t callerUserId = 0; + abilityMs->subManagersHelper_->pendingWantManagers_.clear(); + auto result = abilityMs->GetWantSenderByUserId(wantSenderInfo, nullptr, uid, callerUid, callerUserId); + EXPECT_EQ(result, nullptr); + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0003 end"; +} + +/* + * Feature: GetWantSenderByUserId_0003 + * Function: GetWantSenderByUserId + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetWantSenderByUserId + * EnvConditions: NA + * CaseDescription: Test GetWantSenderByUserId when isSystemApp is true and userId is specified + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetWantSenderByUserId_0004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0004 start"; + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + MyFlag::flag_ = 0; + WantSenderInfo wantSenderInfo; + wantSenderInfo.userId = 100; + AAFwk::Want want; + AAFwk::Operation operation; + std::string bundleName = "com.ohos.testexample"; + operation.SetBundleName(bundleName); + want.SetOperation(operation); + WantsInfo wantsInfo; + wantsInfo.want = want; + wantsInfo.resolvedTypes = want.GetType(); + wantSenderInfo.allWants.emplace_back(wantsInfo); + int32_t uid = -1; + int32_t callerUid = 20010080; + int32_t callerUserId = 100; + AppExecFwk::MockAppMgrService::retCode_ = 400; + abilityMs->subManagersHelper_->pendingWantManagers_.clear(); + auto result = abilityMs->GetWantSenderByUserId(wantSenderInfo, nullptr, uid, callerUid, callerUserId); + EXPECT_EQ(result, nullptr); + GTEST_LOG_(INFO) << "GetWantSenderByUserId_0004 end"; +} + /* * Feature: CancelWantSender_0003 * Function: CancelWantSender @@ -305,6 +512,52 @@ HWTEST_F(AbilityManagerServiceElevenTest, CancelWantSender_0003, TestSize.Level1 GTEST_LOG_(INFO) << "CancelWantSender_0003 end"; } +/* + * Feature: CancelWantSender_0004 + * Function: CancelWantSender + * SubFunction: NA + * FunctionPoints: AbilityManagerService CancelWantSender + */ +HWTEST_F(AbilityManagerServiceElevenTest, CancelWantSender_0004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CancelWantSender_0004 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + abilityMs->subManagersHelper_->currentPendingWantManager_ = std::make_shared(nullptr); + ASSERT_NE(abilityMs->subManagersHelper_->currentPendingWantManager_, nullptr); + + sptr sender = new (std::nothrow) MockIWantSender(); + ASSERT_NE(sender, nullptr); + abilityMs->CancelWantSender(sender); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(true); + sender->SetIRemoteObjectFlags(record); + abilityMs->CancelWantSender(sender); + + record->SetProxyObject(false); + abilityMs->CancelWantSender(sender); + int32_t asObjectfunctionFrequency = 4; + EXPECT_EQ(sender->GetasObjectfunctionFrequency(), asObjectfunctionFrequency); + + int32_t userId = 100; + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + abilityMs->CancelWantSender(sender); + asObjectfunctionFrequency = 5; + EXPECT_EQ(sender->GetasObjectfunctionFrequency(), asObjectfunctionFrequency); + + GTEST_LOG_(INFO) << "CancelWantSender_0004 end"; +} + /* * Feature: CancelWantSenderByFlags_0004 * Function: CancelWantSenderByFlags @@ -378,6 +631,228 @@ HWTEST_F(AbilityManagerServiceElevenTest, GetPendingWantUid_0005, TestSize.Level GTEST_LOG_(INFO) << "GetPendingWantUid_0005 end"; } +/* + * Feature: GetPendingWantUid_0006 + * Function: GetPendingWantUid + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetPendingWantUid + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetPendingWantUid_0006, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPendingWantUid_0006 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + int32_t asObjectfunctionFrequency = 0; + auto result = abilityMs->GetPendingWantUid(nullptr); + EXPECT_EQ(result, -1); + + sptr sender = new (std::nothrow) MockIWantSender(); + ASSERT_NE(sender, nullptr); + asObjectfunctionFrequency = 1; + result = abilityMs->GetPendingWantUid(sender); + EXPECT_EQ(result, -1); + EXPECT_EQ(sender->GetasObjectfunctionFrequency(), asObjectfunctionFrequency); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(false); + sender->SetIRemoteObjectFlags(record); + abilityMs->GetPendingWantUid(sender); + + int32_t userId = 100; + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + result = abilityMs->GetPendingWantUid(sender); + EXPECT_EQ(result, -1); + + GTEST_LOG_(INFO) << "GetPendingWantUid_0006 end"; +} + +/* + * Feature: GetPendingWantBundleName_0001 + * Function: GetPendingWantBundleName + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetPendingWantBundleName + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetPendingWantBundleName_0001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPendingWantBundleName_0001 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + int32_t asObjectfunctionFrequency = 0; + auto bundleName = abilityMs->GetPendingWantBundleName(nullptr); + EXPECT_TRUE(bundleName.empty()); + + sptr sender = new (std::nothrow) MockIWantSender(); + EXPECT_NE(sender, nullptr); + asObjectfunctionFrequency = 1; + bundleName = abilityMs->GetPendingWantBundleName(sender); + EXPECT_TRUE(bundleName.empty()); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(false); + sender->SetIRemoteObjectFlags(record); + bundleName = abilityMs->GetPendingWantBundleName(sender); + EXPECT_TRUE(bundleName.empty()); + + int32_t userId = 100; + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + bundleName = abilityMs->GetPendingWantBundleName(sender); + EXPECT_TRUE(bundleName.empty()); + + GTEST_LOG_(INFO) << "GetPendingWantBundleName_0001 end"; +} + +/* + * Feature: GetPendingWantCode_0001 + * Function: GetPendingWantCode + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetPendingWantCode + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetPendingWantCode_0001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPendingWantCode_0001 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + int32_t asObjectfunctionFrequency = 0; + auto result = abilityMs->GetPendingWantCode(nullptr); + EXPECT_EQ(result, -1); + + sptr sender = new (std::nothrow) MockIWantSender(); + ASSERT_NE(sender, nullptr); + asObjectfunctionFrequency = 1; + result = abilityMs->GetPendingWantCode(sender); + EXPECT_EQ(result, -1); + EXPECT_EQ(sender->GetasObjectfunctionFrequency(), asObjectfunctionFrequency); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(false); + sender->SetIRemoteObjectFlags(record); + abilityMs->GetPendingWantCode(sender); + + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + int32_t userId = 100; + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + result = abilityMs->GetPendingWantCode(sender); + EXPECT_EQ(result, -1); + + GTEST_LOG_(INFO) << "GetPendingWantCode_0001 end"; +} + +/* + * Feature: GetPendingWantType_0001 + * Function: GetPendingWantType + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetPendingWantType + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetPendingWantType_0001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPendingWantType_0001 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + int32_t asObjectfunctionFrequency = 0; + auto result = abilityMs->GetPendingWantType(nullptr); + EXPECT_EQ(result, -1); + + sptr sender = new (std::nothrow) MockIWantSender(); + ASSERT_NE(sender, nullptr); + asObjectfunctionFrequency = 1; + result = abilityMs->GetPendingWantType(sender); + EXPECT_EQ(result, -1); + EXPECT_EQ(sender->GetasObjectfunctionFrequency(), asObjectfunctionFrequency); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(false); + sender->SetIRemoteObjectFlags(record); + abilityMs->GetPendingWantType(sender); + + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + int32_t userId = 100; + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + result = abilityMs->GetPendingWantType(sender); + EXPECT_EQ(result, -1); + + GTEST_LOG_(INFO) << "GetPendingWantType_0001 end"; +} + +/* + * Feature: GetPendingRequestWant_0001 + * Function: GetPendingRequestWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetPendingRequestWant + */ +HWTEST_F(AbilityManagerServiceElevenTest, GetPendingRequestWant_0001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPendingRequestWant_0001 start"; + + auto abilityMs = std::make_shared(); + ASSERT_NE(abilityMs, nullptr); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + ASSERT_NE(abilityMs->subManagersHelper_, nullptr); + + int32_t asObjectfunctionFrequency = 0; + std::shared_ptr want; + sptr sender = new (std::nothrow) MockIWantSender(); + ASSERT_NE(sender, nullptr); + auto result = abilityMs->GetPendingRequestWant(sender, want); + EXPECT_EQ(result, ERR_INVALID_VALUE); + + sptr record = new (std::nothrow) MockPendingWantRecord(); + ASSERT_NE(record, nullptr); + record->SetProxyObject(false); + sender->SetIRemoteObjectFlags(record); + abilityMs->GetPendingRequestWant(sender, want); + + std::shared_ptr pendingKey = std::make_shared(); + ASSERT_NE(pendingKey, nullptr); + int32_t userId = 100; + pendingKey->SetUserId(userId); + sptr recordWithKey = + new (std::nothrow) MockPendingWantRecord(nullptr, 0, 0, nullptr, pendingKey); + sender->SetIRemoteObjectFlags(recordWithKey); + abilityMs->GetPendingRequestWant(sender, want); + result = abilityMs->GetPendingRequestWant(nullptr, want); + EXPECT_EQ(result, ERR_INVALID_VALUE); + + GTEST_LOG_(INFO) << "GetPendingRequestWant_0001 end"; +} + /* * Feature: GetPendingWantUserId_0006 * Function: GetPendingWantUserId @@ -950,11 +1425,12 @@ HWTEST_F(AbilityManagerServiceElevenTest, GetUidByCloneBundleInfo_001, TestSize. int uid = -1; int userId = 100; AppExecFwk::MockAppMgrService::retCode_ = uid; - abilityMs->GetUidByCloneBundleInfo(bundleName, uid, userId); + int appIndex = 0; + abilityMs->GetUidByCloneBundleInfo(bundleName, uid, userId, appIndex); bundleName = "com.applicaion.test"; userId = 101; - auto result = abilityMs->GetUidByCloneBundleInfo(bundleName, uid, userId); + auto result = abilityMs->GetUidByCloneBundleInfo(bundleName, uid, userId, appIndex); EXPECT_EQ(result, uid); GTEST_LOG_(INFO) << "GetUidByCloneBundleInfo_001 end"; -- Gitee