Signed-off-by: wendel <yuwenze1@huawei.com>
This commit is contained in:
wendel
2025-11-15 20:05:45 +08:00
parent 8c42a4c9bf
commit 47e76117fc
28 changed files with 215 additions and 131 deletions
@@ -434,7 +434,8 @@ public:
* @param element The element name to search for
* @return Vector of matching ability records
*/
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element,
int32_t appIndex);
/**
* @brief Get ability record by token
@@ -852,7 +853,8 @@ private:
* @param element The element name
* @return Vector of matching ability records
*/
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element,
int32_t appIndex);
/**
* @brief Handle foreground collaboration
@@ -54,7 +54,7 @@ struct StartAbilityUtils {
AppExecFwk::ApplicationInfo &appInfo);
static bool GetCallerAbilityInfo(const sptr<IRemoteObject> &callerToken,
AppExecFwk::AbilityInfo &abilityInfo);
static int32_t CheckAppProvisionMode(const Want& want, int32_t userId);
static int32_t CheckAppProvisionMode(const Want& want, int32_t userId, sptr<IRemoteObject> callerToken);
static int32_t CheckAppProvisionMode(const std::string& bundleName, int32_t userId);
static std::vector<int32_t> GetCloneAppIndexes(const std::string &bundleName, int32_t userId);
@@ -18,7 +18,10 @@
#include <cstdint>
#include "refbase.h"
namespace OHOS {
class IRemoteObject;
namespace AAFwk {
class Want;
class StartOptions;
@@ -32,10 +35,12 @@ public:
StartOptionsUtils() = default;
~StartOptionsUtils() = default;
static int32_t CheckProcessOptions(const Want &want, const StartOptions &options, int32_t userId);
static int32_t CheckProcessOptions(const Want &want, const StartOptions &options, sptr<IRemoteObject> callerToken,
int32_t userId);
private:
static int32_t CheckProcessOptionsInner(const Want &want, const StartOptions &options, int32_t userId);
static int32_t CheckProcessOptionsInner(const Want &want, const StartOptions &options,
sptr<IRemoteObject> callerToken, int32_t userId);
static int32_t CheckStartSelfUIAbilityStartOptions(const Want &want, const StartOptions &options);
};
@@ -620,7 +620,7 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re
if (userId == DEFAULT_INVAL_VALUE) {
userId = GetValidUserId(userId);
}
if ((err = StartAbilityUtils::CheckAppProvisionMode(want, userId)) != ERR_OK) {
if ((err = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr)) != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "checkAppProvisionMode returns errcode=%{public}d", err);
return err;
}
@@ -1647,7 +1647,7 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt
if (userId == DEFAULT_INVAL_VALUE) {
userId = GetValidUserId(userId);
}
if ((err = StartAbilityUtils::CheckAppProvisionMode(want, userId)) != ERR_OK) {
if ((err = StartAbilityUtils::CheckAppProvisionMode(want, userId, callerToken)) != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "checkAppProvisionMode returns errcode=%{public}d", err);
AbilityEventUtil::SendStartAbilityErrorEvent(eventInfo, err, "checkAppProvisionMode failed");
return err;
@@ -1904,7 +1904,7 @@ int AbilityManagerService::StartUIAbilityForOptionWrap(const Want &want, const S
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
int32_t ret = ERR_OK;
if ((ret = StartOptionsUtils::CheckProcessOptions(want, options, userId)) != ERR_OK) {
if ((ret = StartOptionsUtils::CheckProcessOptions(want, options, callerToken, userId)) != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "check process oprions failed: %{public}d", ret);
return ret;
}
@@ -2202,7 +2202,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St
abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) {
auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid());
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
auto abilityRecords = uiAbilityManager->GetAbilityRecordsByName(want.GetElement());
auto abilityRecords = uiAbilityManager->GetAbilityRecordsByName(want.GetElement(), appIndex);
if (!abilityRecords.empty() && abilityRecords[0] &&
!startOptions.processOptions->isRestartKeepAlive &&
!ProcessOptions::IsAttachToStatusBarItemMode(startOptions.processOptions->processMode) &&
@@ -7756,11 +7756,10 @@ int AbilityManagerService::GenerateAbilityRequest(const Want &want, int requestC
(const_cast<Want &>(want)).SetParam(DLP_PARAMS_SECURITY_FLAG, abilityRecord->GetSecurityFlag());
}
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex);
if (abilityRecord != nullptr &&
abilityRecord->GetApplicationInfo().bundleName == want.GetElement().GetBundleName() &&
abilityRecord->GetAppIndex() == appIndex) {
(!want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY) ||
want.GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, 0) == abilityRecord->GetAppIndex())) {
(const_cast<Want &>(want)).SetParam(DEBUG_APP, abilityRecord->IsDebugApp());
}
@@ -7776,7 +7775,7 @@ int AbilityManagerService::GenerateAbilityRequest(const Want &want, int requestC
auto abilityInfo = StartAbilityUtils::startAbilityInfo;
if (abilityInfo == nullptr || abilityInfo->GetAppBundleName() != want.GetElement().GetBundleName()) {
int32_t appIndex = 0;
if (!AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex)) {
if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) {
return ERR_APP_CLONE_INDEX_INVALID;
}
Want localWant = want;
@@ -7883,7 +7882,7 @@ int AbilityManagerService::GenerateExtensionAbilityRequest(
auto abilityInfo = StartAbilityUtils::startAbilityInfo;
if (abilityInfo == nullptr || abilityInfo->GetAppBundleName() != want.GetElement().GetBundleName()) {
int32_t appIndex = 0;
if (!AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex)) {
if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) {
return ERR_APP_CLONE_INDEX_INVALID;
}
abilityInfo = StartAbilityInfo::CreateStartExtensionInfo(want, userId, appIndex);
@@ -83,22 +83,6 @@ auto g_deleteLifecycleEventTask = [](const sptr<Token> &token) {
CHECK_POINTER_LOG(token, "token is nullptr.");
FreezeUtil::GetInstance().DeleteLifecycleEvent(token->AsObject());
};
bool CompareTwoRequest(const AbilityRequest &left, const AbilityRequest &right)
{
int32_t leftIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(left.want, leftIndex);
int32_t rightIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(right.want, rightIndex);
auto LeftInstanceKey = left.want.GetStringParam(Want::APP_INSTANCE_KEY);
auto RightInstanceKey = right.want.GetStringParam(Want::APP_INSTANCE_KEY);
return leftIndex == rightIndex && LeftInstanceKey == RightInstanceKey &&
left.abilityInfo.name == right.abilityInfo.name &&
left.abilityInfo.bundleName == right.abilityInfo.bundleName &&
left.abilityInfo.moduleName == right.abilityInfo.moduleName;
}
}
UIAbilityLifecycleManager::UIAbilityLifecycleManager(int32_t userId): userId_(userId) {}
@@ -419,7 +403,11 @@ std::shared_ptr<AbilityRecord> UIAbilityLifecycleManager::FindRecordFromTmpMap(
const AbilityRequest &abilityRequest)
{
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(abilityRequest.want, appIndex);
if (abilityRequest.want.HasParameter(ServerConstant::DLP_INDEX)) {
appIndex = abilityRequest.want.GetIntParam(ServerConstant::DLP_INDEX, 0);
} else {
appIndex = abilityRequest.abilityInfo.appIndex;
}
auto instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY);
for (const auto &[requestId, abilityRecord] : tmpAbilityMap_) {
if (abilityRecord) {
@@ -2867,7 +2855,7 @@ int UIAbilityLifecycleManager::ReleaseCallLocked(
std::lock_guard<ffrt::mutex> guard(sessionLock_);
auto abilityRecords = GetAbilityRecordsByNameInner(element);
auto abilityRecords = GetAbilityRecordsByNameInner(element, -1);
auto isExist = [connect] (const std::shared_ptr<AbilityRecord> &abilityRecord) {
if (abilityRecord == nullptr) {
return false;
@@ -2897,7 +2885,7 @@ void UIAbilityLifecycleManager::OnCallConnectDied(const std::shared_ptr<CallReco
std::lock_guard<ffrt::mutex> guard(sessionLock_);
AppExecFwk::ElementName element = callRecord->GetTargetServiceName();
auto abilityRecords = GetAbilityRecordsByNameInner(element);
auto abilityRecords = GetAbilityRecordsByNameInner(element, -1);
auto isExist = [callRecord] (const std::shared_ptr<AbilityRecord> &abilityRecord) {
if (abilityRecord == nullptr) {
return false;
@@ -2915,14 +2903,14 @@ void UIAbilityLifecycleManager::OnCallConnectDied(const std::shared_ptr<CallReco
}
std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilityRecordsByName(
const AppExecFwk::ElementName &element)
const AppExecFwk::ElementName &element, int32_t appIndex)
{
std::lock_guard<ffrt::mutex> guard(sessionLock_);
return GetAbilityRecordsByNameInner(element);
return GetAbilityRecordsByNameInner(element, appIndex);
}
std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilityRecordsByNameInner(
const AppExecFwk::ElementName &element)
const AppExecFwk::ElementName &element, int32_t appIndex)
{
std::vector<std::shared_ptr<AbilityRecord>> records;
for (const auto& [first, second] : sessionAbilityMap_) {
@@ -2931,8 +2919,10 @@ std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilit
abilityInfo.name, abilityInfo.moduleName);
AppExecFwk::ElementName localElementNoModuleName(abilityInfo.deviceId,
abilityInfo.bundleName, abilityInfo.name);
if (localElement == element || localElementNoModuleName == element) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "find element %{public}s", localElement.GetURI().c_str());
if ((localElement == element || localElementNoModuleName == element) &&
(appIndex == -1 || abilityInfo.appIndex == appIndex)) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "find element %{public}s, appIndex:%{public}d",
localElement.GetURI().c_str(), appIndex);
records.push_back(second);
}
}
@@ -3935,7 +3925,11 @@ void UIAbilityLifecycleManager::EnableListForSCBRecovery()
std::shared_ptr<AbilityRecord> UIAbilityLifecycleManager::FindRecordFromSessionMap(const AbilityRequest &abilityRequest)
{
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(abilityRequest.want, appIndex);
if (abilityRequest.want.HasParameter(ServerConstant::DLP_INDEX)) {
appIndex = abilityRequest.want.GetIntParam(ServerConstant::DLP_INDEX, 0);
} else {
appIndex = abilityRequest.abilityInfo.appIndex;
}
auto instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY);
for (const auto &[sessionId, abilityRecord] : sessionAbilityMap_) {
if (abilityRecord) {
@@ -41,8 +41,9 @@ thread_local bool StartAbilityUtils::ermsSupportBackToCallerFlag = false;
bool StartAbilityUtils::GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken, int32_t &appIndex)
{
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (abilityRecord && abilityRecord->GetAppIndex() > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX &&
abilityRecord->GetApplicationInfo().bundleName == want.GetElement().GetBundleName()) {
if (abilityRecord && abilityRecord->GetApplicationInfo().bundleName == want.GetElement().GetBundleName() &&
(abilityRecord->GetAppIndex() > AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX ||
!want.HasParameter(Want::PARAM_APP_CLONE_INDEX_KEY))) {
appIndex = abilityRecord->GetAppIndex();
return true;
}
@@ -114,12 +115,12 @@ int32_t StartAbilityUtils::CheckAppProvisionMode(const std::string& bundleName,
return ERR_OK;
}
int32_t StartAbilityUtils::CheckAppProvisionMode(const Want& want, int32_t userId)
int32_t StartAbilityUtils::CheckAppProvisionMode(const Want& want, int32_t userId, sptr<IRemoteObject> callerToken)
{
auto abilityInfo = StartAbilityUtils::startAbilityInfo;
if (!abilityInfo || abilityInfo->GetAppBundleName() != want.GetElement().GetBundleName()) {
int32_t appIndex = 0;
if (!AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex)) {
if (!GetAppIndex(want, callerToken, appIndex)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid app clone index");
return ERR_APP_CLONE_INDEX_INVALID;
}
@@ -26,11 +26,12 @@
#include "hilog_tag_wrapper.h"
#include "hitrace_meter.h"
#include "ipc_skeleton.h"
#include "iremote_object.h"
#include "permission_verification.h"
#include "process_options.h"
#include "scene_board_judgement.h"
#include "start_ability_utils.h"
#include "start_options.h"
#include "startup_util.h"
#include "want.h"
namespace OHOS {
@@ -39,7 +40,8 @@ namespace {
constexpr const char* ACTION_CHOOSE = "ohos.want.action.select";
constexpr const char* FOUNDATION_PROCESS_NAME = "foundation";
}
int32_t StartOptionsUtils::CheckProcessOptions(const Want &want, const StartOptions &options, int32_t userId)
int32_t StartOptionsUtils::CheckProcessOptions(const Want &want, const StartOptions &options,
sptr<IRemoteObject> callerToken, int32_t userId)
{
if (HiddenStartUtils::IsHiddenStart(options)) {
return HiddenStartUtils::CheckHiddenStartSupported(options);
@@ -48,10 +50,11 @@ int32_t StartOptionsUtils::CheckProcessOptions(const Want &want, const StartOpti
options.processOptions != nullptr && options.processOptions->isStartFromNDK) {
return CheckStartSelfUIAbilityStartOptions(want, options);
}
return CheckProcessOptionsInner(want, options, userId);
return CheckProcessOptionsInner(want, options, callerToken, userId);
}
int32_t StartOptionsUtils::CheckProcessOptionsInner(const Want &want, const StartOptions &options, int32_t userId)
int32_t StartOptionsUtils::CheckProcessOptionsInner(const Want &want, const StartOptions &options,
sptr<IRemoteObject> callerToken, int32_t userId)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
if (options.processOptions == nullptr ||
@@ -76,7 +79,7 @@ int32_t StartOptionsUtils::CheckProcessOptionsInner(const Want &want, const Star
}
int32_t appIndex = 0;
appIndex = !AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex) ? 0 : appIndex;
appIndex = !StartAbilityUtils::GetAppIndex(want, callerToken, appIndex) ? 0 : appIndex;
CHECK_TRUE_RETURN_RET(!DelayedSingleton<AbilityManagerService>::GetInstance()->CheckCallingTokenId(
element.GetBundleName(), userId, appIndex), ERR_NOT_SELF_APPLICATION, "not self application");
@@ -91,7 +94,7 @@ int32_t StartOptionsUtils::CheckProcessOptionsInner(const Want &want, const Star
!uiAbilityManager->IsCallerInStatusBar(processInfo.instanceKey)), ERR_START_OPTIONS_CHECK_FAILED,
"not in status bar");
auto abilityRecords = uiAbilityManager->GetAbilityRecordsByName(element);
auto abilityRecords = uiAbilityManager->GetAbilityRecordsByName(element, appIndex);
CHECK_TRUE_RETURN_RET(!abilityRecords.empty() && abilityRecords[0] &&
abilityRecords[0]->GetAbilityInfo().launchMode != AppExecFwk::LaunchMode::STANDARD &&
abilityRecords[0]->GetAbilityInfo().launchMode != AppExecFwk::LaunchMode::SPECIFIED,
@@ -2167,8 +2167,7 @@ private:
void OnProcessDied(std::shared_ptr<AppRunningRecord> appRecord);
bool IsBlockedByDisposeRules(const std::string &bundleName, int32_t userId,
int32_t appIndex);
int32_t PreCheckStartProcess(const std::string &bundleName, int32_t uid,
std::shared_ptr<AAFwk::Want> &want);
int32_t PreCheckStartProcess(const std::string &bundleName, int32_t uid, int32_t appIndex);
void InsertUninstallOrUpgradeUidSet(int32_t uid);
void RemoveUninstallOrUpgradeUidSet(int32_t uid);
bool IsUninstallingOrUpgrading(int32_t uid);
+38 -14
View File
@@ -284,6 +284,7 @@ constexpr const char* KEY_IS_WATERMARK_ENABLED = "com.ohos.param.isWatermarkEnab
constexpr const char* KILL_SUB_PROCESS_REASON_PREFIX = "Kill SubProcess Reason:";
constexpr const char* PROC_SELF_TASK_PATH = "/proc/self/task/";
constexpr const char* DLP_INDEX = "ohos.dlp.params.index";
constexpr int32_t ROOT_UID = 0;
constexpr int32_t FOUNDATION_UID = 5523;
@@ -472,7 +473,11 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap
auto appInfo = std::make_shared<ApplicationInfo>(abilityInfo.applicationInfo);
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex);
if (want.HasParameter(DLP_INDEX)) {
appIndex = want.GetIntParam(DLP_INDEX, 0);
} else {
appIndex = abilityInfo.appIndex;
}
if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) {
return;
}
@@ -963,7 +968,11 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
bool isProcCache = false;
bool isExtensionSandBox = false;
if (want != nullptr) {
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, appIndex);
if (want->HasParameter(DLP_INDEX)) {
appIndex = want->GetIntParam(DLP_INDEX, 0);
} else {
appIndex = abilityInfo->appIndex;
}
callerKey = want->GetStringParam(Want::PARAMS_REAL_CALLER_KEY);
want->RemoveParam(Want::PARAMS_REAL_CALLER_KEY);
}
@@ -1341,7 +1350,11 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
uint64_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo);
int32_t bundleIndex = 0;
if (want != nullptr) {
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, bundleIndex);
if (want->HasParameter(DLP_INDEX)) {
bundleIndex = want->GetIntParam(DLP_INDEX, 0);
} else {
bundleIndex = abilityInfo->appIndex;
}
} else {
TAG_LOGE(AAFwkTag::APPMGR, "startFlags is default");
}
@@ -3277,7 +3290,11 @@ std::shared_ptr<AppRunningRecord> AppMgrServiceInner::CreateAppRunningRecord(
appRecord->SetErrorInfoEnhance(want->GetBoolParam(ERROR_INFO_ENHANCE, false));
appRecord->SetMultiThread(want->GetBoolParam(MULTI_THREAD, false));
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, appIndex);
if (want->HasParameter(DLP_INDEX)) {
appIndex = want->GetIntParam(DLP_INDEX, 0);
} else {
appIndex = abilityInfo->appIndex;
}
appRecord->SetAppIndex(appIndex);
#ifdef WITH_DLP
appRecord->SetSecurityFlag(want->GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false));
@@ -4488,7 +4505,7 @@ int32_t AppMgrServiceInner::StartProcess(const std::string &appName, const std::
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null");
return ERR_INVALID_VALUE;
}
auto ret = PreCheckStartProcess(bundleName, uid, want);
auto ret = PreCheckStartProcess(bundleName, uid, bundleIndex);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "precheck failed");
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
@@ -5647,7 +5664,11 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptr<IR
appRecord->SetUserTestInfo(testRecord);
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex);
if (want.HasParameter(DLP_INDEX)) {
appIndex = want.GetIntParam(DLP_INDEX, 0);
} else {
appIndex = appInfo->appIndex;
}
uint64_t startFlags = AppspawnUtil::BuildStartFlags(want, info.applicationInfo);
StartProcess(appInfo->name, processName, startFlags, appRecord, appInfo->uid, info, appInfo->bundleName,
appIndex, appExistFlag);
@@ -5752,7 +5773,11 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap
auto appInfo = std::make_shared<ApplicationInfo>(abilityInfo.applicationInfo);
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex);
if (want.HasParameter(DLP_INDEX)) {
appIndex = want.GetIntParam(DLP_INDEX, 0);
} else {
appIndex = abilityInfo.appIndex;
}
if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) {
return;
}
@@ -10501,7 +10526,11 @@ bool AppMgrServiceInner::IsSpecifiedModuleLoaded(const AAFwk::Want &want, const
}
auto appInfo = std::make_shared<ApplicationInfo>(abilityInfo.applicationInfo);
int32_t appIndex = 0;
(void)AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex);
if (want.HasParameter(DLP_INDEX)) {
appIndex = want.GetIntParam(DLP_INDEX, 0);
} else {
appIndex = abilityInfo.appIndex;
}
BundleInfo bundleInfo;
HapModuleInfo hapModuleInfo;
if (!GetBundleAndHapInfo(abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) {
@@ -10905,8 +10934,7 @@ bool AppMgrServiceInner::IsBlockedByDisposeRules(const std::string &bundleName,
return false;
}
int32_t AppMgrServiceInner:: PreCheckStartProcess(const std::string &bundleName, int32_t uid,
std::shared_ptr<AAFwk::Want> &want)
int32_t AppMgrServiceInner::PreCheckStartProcess(const std::string &bundleName, int32_t uid, int32_t appIndex)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGD(AAFwkTag::APPMGR,
@@ -10915,10 +10943,6 @@ int32_t AppMgrServiceInner:: PreCheckStartProcess(const std::string &bundleName,
return ERR_OK;
}
int32_t userId = uid / BASE_USER_RANGE;
int32_t appIndex = 0;
if (want != nullptr) {
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, appIndex);
}
if (IsBlockedByDisposeRules(bundleName, userId, appIndex)) {
return AAFwk::ERR_UNINSTALLING_OR_UPGRADING_APP;
}
@@ -73,7 +73,7 @@ void StartAbilityUtilsFuzztest1(bool boolParam, std::string &stringParam, int32_
AppExecFwk::AbilityInfo abilityInfo;
StartAbilityUtils::GetCallerAbilityInfo(nullptr, abilityInfo);
StartAbilityUtils::GetCallerAbilityInfo(callerToken, abilityInfo);
StartAbilityUtils::CheckAppProvisionMode(want, int32Param);
StartAbilityUtils::CheckAppProvisionMode(want, int32Param, callerToken);
std::shared_ptr<StartAbilityInfoWrap> startAbilityInfoWrap =
std::make_shared<StartAbilityInfoWrap>(want, int32Param, int32Param, callerToken, boolParam);
StartAbilityInfo::CreateStartAbilityInfo(want, int32Param, int32Param, nullptr);
@@ -39,7 +39,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
AbilityFuzzUtil::GetRandomStartOptions(fdp, startOptions);
int32_t userId = fdp.ConsumeIntegral<int32_t>();
StartOptionsUtils::CheckProcessOptions(want, startOptions, userId);
StartOptionsUtils::CheckProcessOptions(want, startOptions, nullptr, userId);
return true;
}
} // namespace OHOS
@@ -41,7 +41,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
startOptions.processOptions = std::make_shared<AAFwk::ProcessOptions>();
startOptions.processOptions->isStartFromNDK = true;
int32_t userId = fdp.ConsumeIntegral<int32_t>();
int32_t ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, userId);
int32_t ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, nullptr, userId);
return true;
}
} // namespace OHOS
@@ -126,7 +126,7 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size)
sptr<SessionInfo> sessionInfo;
uIAbilityLifecycleManager->ChangeUIAbilityVisibilityBySCB(sessionInfo, boolParam);
AppExecFwk::ElementName element;
uIAbilityLifecycleManager->GetAbilityRecordsByName(element);
uIAbilityLifecycleManager->GetAbilityRecordsByName(element, int32Param);
uIAbilityLifecycleManager->GetAbilityRecordByToken(token);
#ifdef SUPPORT_GRAPHICS
@@ -256,12 +256,6 @@ public:
*/
void CallRequestDone(const std::shared_ptr<AbilityRecord> &abilityRecord, const sptr<IRemoteObject> &callStub);
/**
* release the connection of this call.
*
* @param connect caller callback ipc.
* @param element target ability name.
*/
int ReleaseCallLocked(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element);
/**
@@ -367,7 +361,8 @@ public:
int ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element,
int32_t appIndex);
std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const;
@@ -449,7 +444,8 @@ private:
int NotifySCBPendingActivation(sptr<SessionInfo> &sessionInfo, const AbilityRequest &abilityRequest);
bool IsHookModule(const AbilityRequest &abilityRequest) const;
int ResolveAbility(const std::shared_ptr<AbilityRecord> &targetAbility, const AbilityRequest &abilityRequest) const;
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element,
int32_t appIndex);
void HandleForegroundCollaborate(const AbilityRequest &abilityRequest,
std::shared_ptr<AbilityRecord> abilityRecord);
@@ -258,12 +258,6 @@ public:
*/
void CallRequestDone(const std::shared_ptr<AbilityRecord> &abilityRecord, const sptr<IRemoteObject> &callStub);
/**
* release the connection of this call.
*
* @param connect caller callback ipc.
* @param element target ability name.
*/
int ReleaseCallLocked(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element);
/**
@@ -369,7 +363,8 @@ public:
int ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element,
int32_t appIndex);
std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const;
@@ -452,7 +447,8 @@ private:
const AbilityRequest &abilityRequest, std::string &errMsg);
bool IsHookModule(const AbilityRequest &abilityRequest) const;
int ResolveAbility(const std::shared_ptr<AbilityRecord> &targetAbility, const AbilityRequest &abilityRequest) const;
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element,
int32_t appIndex);
void HandleForegroundCollaborate(const AbilityRequest &abilityRequest,
std::shared_ptr<AbilityRecord> abilityRecord);
@@ -458,13 +458,13 @@ void UIAbilityLifecycleManager::OnCallConnectDied(const std::shared_ptr<CallReco
}
std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilityRecordsByName(
const AppExecFwk::ElementName &element)
const AppExecFwk::ElementName &element, int32_t appIndex)
{
return {};
}
std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilityRecordsByNameInner(
const AppExecFwk::ElementName &element)
const AppExecFwk::ElementName &element, int32_t appIndex)
{
return {};
}
@@ -2614,8 +2614,8 @@ HWTEST_F(AppMgrServiceInnerSecondTest, PreCheckStartProcess_001, TestSize.Level1
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
std::string bundleName = "test.bundle.name";
int32_t uid = UID_ONE;
std::shared_ptr<AAFwk::Want> want = nullptr;
auto ret = appMgrServiceInner->PreCheckStartProcess(bundleName, uid, want);
int32_t appIndex = 0;
auto ret = appMgrServiceInner->PreCheckStartProcess(bundleName, uid, appIndex);
EXPECT_EQ(ret, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "PreCheckStartProcess_001 end");
}
@@ -2631,11 +2631,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, PreCheckStartProcess_002, TestSize.Level1
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
std::string bundleName = "test.bundle.name";
int32_t uid = UID_ONE;
std::shared_ptr<AAFwk::Want> want = nullptr;
appMgrServiceInner->InsertUninstallOrUpgradeUidSet(UID_ONE);
bool flag = appMgrServiceInner->IsUninstallingOrUpgrading(UID_ONE);
EXPECT_EQ(flag, true);
auto ret = appMgrServiceInner->PreCheckStartProcess(bundleName, uid, want);
int32_t appIndex = 0;
auto ret = appMgrServiceInner->PreCheckStartProcess(bundleName, uid, appIndex);
EXPECT_EQ(ret, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "PreCheckStartProcess_002 end");
}
@@ -1057,7 +1057,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr
* @tc.steps: step1. Initialize AppRunningManager instance
* @tc.expected: expect first Foreground
*/
AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
AppRunningRecord foregroundingRecord(appInfo_, 0, PROCESS_NAME);
foregroundingRecord.SetAppIndex(1);
foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
@@ -153,7 +153,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_004, TestSize.Level1)
Want want;
int32_t userId = 1001;
StartAbilityUtils::startAbilityInfo = std::make_shared<StartAbilityInfo>();
int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, ERR_NOT_IN_APP_PROVISION_MODE);
}
@@ -170,7 +170,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_005, TestSize.Level1)
StartAbilityUtils::startAbilityInfo->abilityInfo.bundleName = "bundleName";
StartAbilityUtils::startAbilityInfo->abilityInfo.name = "name";
StartAbilityUtils::startAbilityInfo->status = 1;
int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
int32_t ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, StartAbilityUtils::startAbilityInfo->status);
}
@@ -189,7 +189,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_006, TestSize.Level1)
AppExecFwk::ApplicationInfo applicationInfo;
applicationInfo.bundleName = bundleName;
StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo = applicationInfo;
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, ERR_NOT_IN_APP_PROVISION_MODE);
}
@@ -208,7 +208,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_007, TestSize.Level1)
AppExecFwk::ApplicationInfo applicationInfo;
applicationInfo.bundleName = bundleName;
StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo = applicationInfo;
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, ERR_APP_CLONE_INDEX_INVALID);
}
@@ -228,7 +228,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_008, TestSize.Level1)
applicationInfo.bundleName = bundleName;
applicationInfo.appProvisionType = AppExecFwk::Constants::APP_PROVISION_TYPE_DEBUG;
StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo = applicationInfo;
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, ERR_OK);
}
@@ -241,7 +241,8 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_009, TestSize.Level1)
{
std::string bundleName = "testName";
Want want;
want.SetParam("ohos.dlp.params.index", 0);
int32_t dlpIndex = 1001;
want.SetParam("ohos.dlp.params.index", dlpIndex);
want.SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, 0);
want.SetParam(AAFwk::Want::DESTINATION_PLUGIN_ABILITY, true);
int32_t userId = 0;
@@ -249,7 +250,7 @@ HWTEST_F(StartAbilityUtilsTest, CheckAppProvisionMode_009, TestSize.Level1)
AppExecFwk::ApplicationInfo applicationInfo;
applicationInfo.bundleName = bundleName;
StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo = applicationInfo;
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId);
auto ret = StartAbilityUtils::CheckAppProvisionMode(want, userId, nullptr);
EXPECT_EQ(ret, RESOLVE_ABILITY_ERR);
}
@@ -44,6 +44,7 @@ ohos_unittest("start_options_utils_test") {
"mock/src/mock_hidden_start_utils.cpp",
"mock/src/mock_permission_verification.cpp",
"mock/src/mock_scene_board_judgement.cpp",
"mock/src/mock_start_ability_utils.cpp",
"mock/src/mock_ui_ability_lifecycle_manager.cpp",
"start_options_utils_test.cpp",
]
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H
#define OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H
#include "iremote_object.h"
#include "refbase.h"
#include "want.h"
namespace OHOS {
namespace AAFwk {
struct StartAbilityUtils {
static bool GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken, int32_t &appIndex);
};
}
}
#endif // OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H
@@ -34,7 +34,8 @@ public:
virtual ~UIAbilityLifecycleManager() = default;
bool IsCallerInStatusBar(const std::string &instanceKey);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element,
int32_t appIndex);
};
} // namespace AAFwk
} // namespace OHOS
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "start_ability_utils.h"
namespace OHOS {
namespace AAFwk {
bool StartAbilityUtils::GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken, int32_t &appIndex)
{
appIndex = 0;
return true;
}
}
}
@@ -27,7 +27,7 @@ bool UIAbilityLifecycleManager::IsCallerInStatusBar(const std::string &instanceK
}
std::vector<std::shared_ptr<AbilityRecord>> UIAbilityLifecycleManager::GetAbilityRecordsByName(
const AppExecFwk::ElementName &element)
const AppExecFwk::ElementName &element, int32_t appIndex)
{
return MyFlag::GetInstance().abilityRecords_;
}
@@ -63,7 +63,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptions_001, TestSize.Level1)
Want want;
StartOptions startOptions;
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, -1);
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, nullptr, -1);
EXPECT_EQ(ret, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptions_001 end");
@@ -86,7 +86,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptions_002, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->isStartFromNDK = true;
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, -1);
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, nullptr, -1);
EXPECT_EQ(ret, StartOptionsUtils::CheckStartSelfUIAbilityStartOptions(want, startOptions));
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptions_002 end");
@@ -107,7 +107,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptions_003, TestSize.Level1)
Want want;
StartOptions startOptions;
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, -1);
auto ret = StartOptionsUtils::CheckProcessOptions(want, startOptions, nullptr, -1);
EXPECT_EQ(ret, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptions_003 end");
@@ -280,7 +280,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_001, TestSize.Level1)
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_001 start");
Want want;
StartOptions startOptions;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_001 end");
}
@@ -300,7 +300,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_002, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::UNSPECIFIED;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_002 end");
}
@@ -322,7 +322,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_003, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_CAPABILITY_NOT_SUPPORT);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_003 end");
}
@@ -345,7 +345,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_004, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_CAPABILITY_NOT_SUPPORT);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_004 end");
@@ -369,7 +369,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_005, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_NOT_ALLOW_IMPLICIT_START);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_005 end");
@@ -395,7 +395,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_006, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->isRestartKeepAlive = true;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_006 end");
@@ -422,7 +422,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_007, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_NOT_SELF_APPLICATION);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_007 end");
@@ -450,7 +450,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_008, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::NEW_PROCESS_ATTACH_TO_PARENT;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_008 end");
@@ -479,7 +479,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_009, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_START_OPTIONS_CHECK_FAILED);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_009 end");
@@ -511,7 +511,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_010, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_ABILITY_ALREADY_RUNNING);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_010 end");
@@ -541,7 +541,7 @@ HWTEST_F(StartOptionsUtilsTest, CheckProcessOptionsInner_011, TestSize.Level1)
StartOptions startOptions;
startOptions.processOptions = std::make_shared<ProcessOptions>();
startOptions.processOptions->processMode = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, -1);
auto retCode = StartOptionsUtils::CheckProcessOptionsInner(want, startOptions, nullptr, -1);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "StartOptionsUtilsTest CheckProcessOptionsInner_011 end");
@@ -3646,7 +3646,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByName_001, TestSize.Le
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element, appIndex);
EXPECT_EQ(ret.empty(), true);
}
@@ -3666,7 +3667,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByName_002, TestSize.Le
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element("100", "com.example.unittest", "MainAbility");
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element, appIndex);
EXPECT_EQ(ret.empty(), false);
}
@@ -3687,7 +3689,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByName_003, TestSize.Le
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element("100", "com.example.unittest", "MainAbility", "entry");
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByName(element, appIndex);
EXPECT_EQ(ret.empty(), false);
}
@@ -3707,7 +3710,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByNameInner_001, TestSi
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element, appIndex);
EXPECT_EQ(ret.empty(), true);
}
@@ -3727,7 +3731,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByNameInner_002, TestSi
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element("100", "com.example.unittest", "MainAbility");
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element, appIndex);
EXPECT_EQ(ret.empty(), false);
}
@@ -3748,7 +3753,8 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetAbilityRecordsByNameInner_003, TestSi
auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord);
AppExecFwk::ElementName element("100", "com.example.unittest", "MainAbility", "entry");
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element);
int32_t appIndex = 0;
auto ret = uiAbilityLifecycleManager->GetAbilityRecordsByNameInner(element, appIndex);
EXPECT_EQ(ret.empty(), false);
}
@@ -215,8 +215,8 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, FindRecordFromTmpMap_001, TestSize.
abilityRequest.abilityInfo.name = "Name";
abilityRequest.abilityInfo.bundleName = "BundleName";
abilityRequest.abilityInfo.moduleName = "ModuleName";
abilityRequest.abilityInfo.appIndex = 5;
abilityRequest.want.SetParam(Want::APP_INSTANCE_KEY, std::string("InstanceKey"));
abilityRequest.want.SetParam(ServerConstant::DLP_INDEX, 5);
auto callerAbilityRecord = std::make_shared<AbilityRecord>(
abilityRequest.want, abilityRequest.abilityInfo, abilityRequest.appInfo, abilityRequest.requestCode);
+8 -9
View File
@@ -30,18 +30,16 @@ constexpr int32_t VALID_REQUEST_CODE_LENGTH = 49;
}
bool StartupUtil::GetAppIndex(const AAFwk::Want &want, int32_t &appIndex)
{
appIndex = want.GetIntParam(ServerConstant::DLP_INDEX, 0);
if (appIndex > GlobalConstant::MAX_APP_CLONE_INDEX) {
return true;
if (want.HasParameter(ServerConstant::DLP_INDEX)) {
appIndex = want.GetIntParam(ServerConstant::DLP_INDEX, 0);
return appIndex > GlobalConstant::MAX_APP_CLONE_INDEX;
}
if (appIndex == 0) {
if (want.HasParameter(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY)) {
appIndex = want.GetIntParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, 0);
if (appIndex < 0 || appIndex > GlobalConstant::MAX_APP_CLONE_INDEX) {
return false;
}
return true;
return (appIndex >= 0 && appIndex <= GlobalConstant::MAX_APP_CLONE_INDEX);
}
return false;
appIndex = 0;
return true;
}
int32_t StartupUtil::BuildAbilityInfoFlag()
@@ -100,6 +98,7 @@ void StartupUtil::InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo
abilityInfo.extensionTypeName = extensionInfo.extensionTypeName;
abilityInfo.isolationProcess = extensionInfo.isolationProcess;
abilityInfo.uid = extensionInfo.uid;
abilityInfo.appIndex = extensionInfo.appIndex;
if (!extensionInfo.hapPath.empty()) {
abilityInfo.hapPath = extensionInfo.hapPath;
}