mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
support wantAgent mutil userId
Signed-off-by: yuechunyang <yuechunyang1@h-partners.com>
This commit is contained in:
@@ -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<WantAgentWantsPa
|
||||
static_cast<WantAgentConstant::OperationType>(parasobj->operationType),
|
||||
parasobj->wantAgentFlags,
|
||||
parasobj->wants,
|
||||
extraInfo);
|
||||
extraInfo,
|
||||
parasobj->userId);
|
||||
|
||||
auto context = OHOS::AbilityRuntime::Context::GetApplicationContext();
|
||||
std::shared_ptr<WantAgent> wantAgent = nullptr;
|
||||
|
||||
@@ -76,6 +76,7 @@ struct WantAgentWantsParas {
|
||||
std::vector<std::shared_ptr<AAFwk::Want>> wants = {};
|
||||
int32_t operationType = -1;
|
||||
int32_t requestCode = -1;
|
||||
int32_t userId = -1;
|
||||
std::vector<WantAgentConstant::Flags> wantAgentFlags = {};
|
||||
AAFwk::WantParams extraInfo = {};
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
const std::shared_ptr<OHOS::AbilityRuntime::ApplicationContext> &context, int requestCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, unsigned int flags,
|
||||
const std::shared_ptr<AAFwk::WantParams> &options,
|
||||
std::shared_ptr<PendingWant> &pendingWant);
|
||||
std::shared_ptr<PendingWant> &pendingWant, int userId = -1);
|
||||
|
||||
/**
|
||||
* Like GetAbility(Context, int, Want, int)}, but allows an
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
*/
|
||||
WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType,
|
||||
const std::vector<WantAgentConstant::Flags> &flags, std::vector<std::shared_ptr<AAFwk::Want>> &Wants,
|
||||
const std::shared_ptr<AAFwk::WantParams> &extraInfo);
|
||||
const std::shared_ptr<AAFwk::WantParams> &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<AAFwk::WantParams> 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<WantAgentConstant::Flags> flags_ = std::vector<WantAgentConstant::Flags>();
|
||||
std::vector<std::shared_ptr<AAFwk::Want>> wants_ = std::vector<std::shared_ptr<AAFwk::Want>>();
|
||||
|
||||
@@ -57,13 +57,17 @@ ErrCode PendingWant::GetAbility(
|
||||
const std::shared_ptr<OHOS::AbilityRuntime::ApplicationContext> &context, int requestCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, unsigned int flags,
|
||||
const std::shared_ptr<AAFwk::WantParams> &options,
|
||||
std::shared_ptr<PendingWant> &pendingWant)
|
||||
std::shared_ptr<PendingWant> &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<int32_t>(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<IWantSender> target = nullptr;
|
||||
ErrCode result = WantAgentClient::GetInstance().GetWantSender(wantSenderInfo, nullptr, target);
|
||||
|
||||
@@ -112,11 +112,12 @@ ErrCode WantAgentHelper::GetWantAgent(
|
||||
std::shared_ptr<WantParams> extraInfo = paramsInfo.GetExtraInfo();
|
||||
std::shared_ptr<PendingWant> 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<WantAgent> &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<WantAgent> WantAgentHelper::FromString(const std::string &jsonSt
|
||||
requestCode = jsonObject.at("requestCode").get<int>();
|
||||
}
|
||||
|
||||
int userId = -1;
|
||||
if (jsonObject.contains("userId") && jsonObject["userId"].is_number_integer()) {
|
||||
userId = jsonObject.at("userId").get<int>();
|
||||
}
|
||||
|
||||
WantAgentConstant::OperationType operationType = WantAgentConstant::OperationType::UNKNOWN_TYPE;
|
||||
if (jsonObject.contains("operationType") && jsonObject["operationType"].is_number_integer()) {
|
||||
operationType = static_cast<WantAgentConstant::OperationType>(jsonObject.at("operationType").get<int>());
|
||||
@@ -530,7 +537,7 @@ std::shared_ptr<WantAgent> 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<WantAgentConstant::Flags> WantAgentHelper::ParseFlags(nlohmann::json jsonObject)
|
||||
|
||||
@@ -44,10 +44,11 @@ WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::Operation
|
||||
|
||||
WantAgentInfo::WantAgentInfo(int requestCode, const WantAgentConstant::OperationType &operationType,
|
||||
const std::vector<WantAgentConstant::Flags> &flags, std::vector<std::shared_ptr<Want>> &wants,
|
||||
const std::shared_ptr<WantParams> &extraInfo)
|
||||
const std::shared_ptr<WantParams> &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<WantParams> WantAgentInfo::GetExtraInfo() const
|
||||
{
|
||||
return extraInfo_;
|
||||
}
|
||||
|
||||
int WantAgentInfo::GetUserId() const
|
||||
{
|
||||
return userId_;
|
||||
}
|
||||
} // namespace OHOS::AbilityRuntime::WantAgent
|
||||
|
||||
@@ -2350,7 +2350,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<IWantSender> GetWantSenderByUserId(const WantSenderInfo &wantSenderInfo,
|
||||
const sptr<IRemoteObject> &callerToken, int32_t uid, int32_t callerUid, int32_t callerUserId);
|
||||
|
||||
bool VerificationAllToken(const sptr<IRemoteObject> &token);
|
||||
std::shared_ptr<DataAbilityManager> GetCurrentDataAbilityManager();
|
||||
|
||||
@@ -5844,12 +5844,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<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
|
||||
@@ -5860,27 +5860,78 @@ int32_t AbilityManagerService::GetUidByCloneBundleInfo(std::string &bundleName,
|
||||
return bundleInfo.uid;
|
||||
}
|
||||
|
||||
sptr<IWantSender> AbilityManagerService::GetWantSenderByUserId(const WantSenderInfo &wantSenderInfo,
|
||||
const sptr<IRemoteObject> &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<AppExecFwk::OsAccountManagerWrapper>::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> 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&>(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<IWantSender> AbilityManagerService::GetWantSender(
|
||||
const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &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<AppExecFwk::OsAccountManagerWrapper>::GetInstance()->
|
||||
GetOsAccountLocalIdFromUid(callerUid, userId) != 0) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "getOsAccountLocalIdFromUid failed uid=%{public}d", callerUid);
|
||||
return nullptr;
|
||||
}
|
||||
if (DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::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.
|
||||
@@ -5924,9 +5975,25 @@ sptr<IWantSender> AbilityManagerService::GetWantSender(
|
||||
int AbilityManagerService::SendWantSender(sptr<IWantSender> 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<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(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> pendingWantManager;
|
||||
if (userId >= 0) {
|
||||
pendingWantManager = GetPendingWantManagerByUserId(userId);
|
||||
} else {
|
||||
pendingWantManager = GetCurrentPendingWantManager();
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, ERR_INVALID_VALUE);
|
||||
return pendingWantManager->SendWantSender(target, senderInfo);
|
||||
}
|
||||
|
||||
@@ -5946,8 +6013,6 @@ int AbilityManagerService::SendLocalWantSender(const SenderInfo &senderInfo)
|
||||
void AbilityManagerService::CancelWantSender(const sptr<IWantSender> &sender)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
|
||||
auto pendingWantManager = GetCurrentPendingWantManager();
|
||||
CHECK_POINTER(pendingWantManager);
|
||||
CHECK_POINTER(sender);
|
||||
|
||||
sptr<IRemoteObject> obj = sender->AsObject();
|
||||
@@ -5955,19 +6020,20 @@ void AbilityManagerService::CancelWantSender(const sptr<IWantSender> &sender)
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return;
|
||||
}
|
||||
|
||||
auto bms = AbilityUtil::GetBundleManagerHelper();
|
||||
CHECK_POINTER(bms);
|
||||
|
||||
int32_t callerUid = IPCSkeleton::GetCallingUid();
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER(record);
|
||||
|
||||
int userId = -1;
|
||||
if (DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::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> 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();
|
||||
|
||||
@@ -5977,22 +6043,28 @@ void AbilityManagerService::CancelWantSender(const sptr<IWantSender> &sender)
|
||||
void AbilityManagerService::CancelWantSenderByFlags(const sptr<IWantSender> &sender, uint32_t flags)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
|
||||
auto pendingWantManager = GetCurrentPendingWantManager();
|
||||
CHECK_POINTER(pendingWantManager);
|
||||
CHECK_POINTER(sender);
|
||||
|
||||
sptr<IRemoteObject> 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<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER(record);
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> 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<uint32_t>(record->GetKey()->GetFlags()) & flags) == 0) {
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "flags=%{public}u not match wantAgent flags=%{public}d",
|
||||
@@ -6009,12 +6081,29 @@ void AbilityManagerService::CancelWantSenderByFlags(const sptr<IWantSender> &sen
|
||||
int AbilityManagerService::GetPendingWantUid(const sptr<IWantSender> &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<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return -1;
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER_AND_RETURN(record, -1);
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> pendingWantManager;
|
||||
if (userId >= 0) {
|
||||
pendingWantManager = GetPendingWantManagerByUserId(userId);
|
||||
} else {
|
||||
pendingWantManager = GetCurrentPendingWantManager();
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, -1);
|
||||
return pendingWantManager->GetPendingWantUid(target);
|
||||
}
|
||||
|
||||
@@ -6034,21 +6123,56 @@ std::string AbilityManagerService::GetPendingWantBundleName(const sptr<IWantSend
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
|
||||
XCOLLIE_TIMER_DEFAULT(__PRETTY_FUNCTION__);
|
||||
auto pendingWantManager = GetCurrentPendingWantManager();
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, "");
|
||||
CHECK_POINTER_AND_RETURN(target, "");
|
||||
|
||||
sptr<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return "";
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER_AND_RETURN(record, "");
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> pendingWantManager;
|
||||
if (userId >= 0) {
|
||||
pendingWantManager = GetPendingWantManagerByUserId(userId);
|
||||
} else {
|
||||
pendingWantManager = GetCurrentPendingWantManager();
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, "");
|
||||
return pendingWantManager->GetPendingWantBundleName(target);
|
||||
}
|
||||
|
||||
int AbilityManagerService::GetPendingWantCode(const sptr<IWantSender> &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<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return -1;
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER_AND_RETURN(record, -1);
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> pendingWantManager;
|
||||
if (userId >= 0) {
|
||||
pendingWantManager = GetPendingWantManagerByUserId(userId);
|
||||
} else {
|
||||
pendingWantManager = GetCurrentPendingWantManager();
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, -1);
|
||||
return pendingWantManager->GetPendingWantCode(target);
|
||||
}
|
||||
|
||||
@@ -6056,12 +6180,29 @@ int AbilityManagerService::GetPendingWantType(const sptr<IWantSender> &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<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return -1;
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER_AND_RETURN(record, -1);
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> pendingWantManager;
|
||||
if (userId >= 0) {
|
||||
pendingWantManager = GetPendingWantManagerByUserId(userId);
|
||||
} else {
|
||||
pendingWantManager = GetCurrentPendingWantManager();
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(pendingWantManager, -1);
|
||||
return pendingWantManager->GetPendingWantType(target);
|
||||
}
|
||||
|
||||
@@ -6092,10 +6233,27 @@ int AbilityManagerService::GetPendingRequestWant(const sptr<IWantSender> &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<IRemoteObject> obj = target->AsObject();
|
||||
if (!obj || obj->IsProxyObject()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "obj null or proxy obj");
|
||||
return -1;
|
||||
}
|
||||
sptr<PendingWantRecord> record = iface_cast<PendingWantRecord>(obj);
|
||||
CHECK_POINTER_AND_RETURN(record, -1);
|
||||
|
||||
int32_t userId = -1;
|
||||
if (record->GetKey() != nullptr) {
|
||||
userId = record->GetKey()->GetUserId();
|
||||
}
|
||||
std::shared_ptr<PendingWantManager> 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);
|
||||
}
|
||||
|
||||
+480
-4
@@ -70,6 +70,10 @@ public:
|
||||
|
||||
class MockPendingWantRecord : public PendingWantRecord {
|
||||
public:
|
||||
MockPendingWantRecord() : PendingWantRecord() {};
|
||||
MockPendingWantRecord(const std::shared_ptr<PendingWantManager> &pendingWantManager, int32_t uid,
|
||||
int32_t callerTokenId, const sptr<IRemoteObject> &callerToken, std::shared_ptr<PendingWantKey> key)
|
||||
: PendingWantRecord(pendingWantManager, uid, callerTokenId, callerToken, key) {};
|
||||
virtual ~MockPendingWantRecord() {};
|
||||
bool IsProxyObject() const override
|
||||
{
|
||||
@@ -81,8 +85,19 @@ public:
|
||||
proxyObject_ = proxyObject;
|
||||
}
|
||||
|
||||
std::shared_ptr<PendingWantKey> GetKey()
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
void SetKey(std::shared_ptr<PendingWantKey> key)
|
||||
{
|
||||
key_ = key;
|
||||
}
|
||||
|
||||
private:
|
||||
bool proxyObject_ = false;
|
||||
std::shared_ptr<PendingWantKey> 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<PendingWantManager>(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<AbilityManagerService>();
|
||||
EXPECT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(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<PendingWantManager>(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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(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<PendingWantManager>(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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
abilityMs->subManagersHelper_->currentPendingWantManager_ = std::make_shared<PendingWantManager>(nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_->currentPendingWantManager_, nullptr);
|
||||
|
||||
sptr<MockIWantSender> sender = new (std::nothrow) MockIWantSender();
|
||||
ASSERT_NE(sender, nullptr);
|
||||
abilityMs->CancelWantSender(sender);
|
||||
|
||||
sptr<MockPendingWantRecord> 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<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
|
||||
int32_t asObjectfunctionFrequency = 0;
|
||||
auto result = abilityMs->GetPendingWantUid(nullptr);
|
||||
EXPECT_EQ(result, -1);
|
||||
|
||||
sptr<MockIWantSender> 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<MockPendingWantRecord> 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<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
|
||||
int32_t asObjectfunctionFrequency = 0;
|
||||
auto bundleName = abilityMs->GetPendingWantBundleName(nullptr);
|
||||
EXPECT_TRUE(bundleName.empty());
|
||||
|
||||
sptr<MockIWantSender> sender = new (std::nothrow) MockIWantSender();
|
||||
EXPECT_NE(sender, nullptr);
|
||||
asObjectfunctionFrequency = 1;
|
||||
bundleName = abilityMs->GetPendingWantBundleName(sender);
|
||||
EXPECT_TRUE(bundleName.empty());
|
||||
|
||||
sptr<MockPendingWantRecord> 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<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
|
||||
int32_t asObjectfunctionFrequency = 0;
|
||||
auto result = abilityMs->GetPendingWantCode(nullptr);
|
||||
EXPECT_EQ(result, -1);
|
||||
|
||||
sptr<MockIWantSender> 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<MockPendingWantRecord> record = new (std::nothrow) MockPendingWantRecord();
|
||||
ASSERT_NE(record, nullptr);
|
||||
record->SetProxyObject(false);
|
||||
sender->SetIRemoteObjectFlags(record);
|
||||
abilityMs->GetPendingWantCode(sender);
|
||||
|
||||
std::shared_ptr<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
int32_t userId = 100;
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
|
||||
int32_t asObjectfunctionFrequency = 0;
|
||||
auto result = abilityMs->GetPendingWantType(nullptr);
|
||||
EXPECT_EQ(result, -1);
|
||||
|
||||
sptr<MockIWantSender> 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<MockPendingWantRecord> record = new (std::nothrow) MockPendingWantRecord();
|
||||
ASSERT_NE(record, nullptr);
|
||||
record->SetProxyObject(false);
|
||||
sender->SetIRemoteObjectFlags(record);
|
||||
abilityMs->GetPendingWantType(sender);
|
||||
|
||||
std::shared_ptr<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
int32_t userId = 100;
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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<AbilityManagerService>();
|
||||
ASSERT_NE(abilityMs, nullptr);
|
||||
abilityMs->subManagersHelper_ = std::make_shared<SubManagersHelper>(nullptr, nullptr);
|
||||
ASSERT_NE(abilityMs->subManagersHelper_, nullptr);
|
||||
|
||||
int32_t asObjectfunctionFrequency = 0;
|
||||
std::shared_ptr<Want> want;
|
||||
sptr<MockIWantSender> sender = new (std::nothrow) MockIWantSender();
|
||||
ASSERT_NE(sender, nullptr);
|
||||
auto result = abilityMs->GetPendingRequestWant(sender, want);
|
||||
EXPECT_EQ(result, ERR_INVALID_VALUE);
|
||||
|
||||
sptr<MockPendingWantRecord> record = new (std::nothrow) MockPendingWantRecord();
|
||||
ASSERT_NE(record, nullptr);
|
||||
record->SetProxyObject(false);
|
||||
sender->SetIRemoteObjectFlags(record);
|
||||
abilityMs->GetPendingRequestWant(sender, want);
|
||||
|
||||
std::shared_ptr<PendingWantKey> pendingKey = std::make_shared<PendingWantKey>();
|
||||
ASSERT_NE(pendingKey, nullptr);
|
||||
int32_t userId = 100;
|
||||
pendingKey->SetUserId(userId);
|
||||
sptr<MockPendingWantRecord> 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";
|
||||
|
||||
Reference in New Issue
Block a user