fix StartSelfUIAbilityInCurrentProcess

Signed-off-by: zhengzhuolan <zhengzhuolan@huawei-partners.com>
This commit is contained in:
zhengzhuolan
2025-12-10 16:19:57 +08:00
parent 292ab4e520
commit d3d2b469c8
22 changed files with 207 additions and 69 deletions
@@ -63,6 +63,7 @@ public:
std::string processName;
uint64_t loadAbilityCallbackId = 0;
pid_t callingPid = -1;
pid_t selfPid = -1;
};
} // namespace AAFwk
} // namespace OHOS
@@ -147,7 +147,7 @@ private:
int32_t minWindowHeight_ = 0;
int32_t maxWindowWidth_ = 0;
int32_t maxWindowHeight_ = 0;
std::string currentProcessName_;
std::string currentProcessName_ = "";
};
} // namespace AAFwk
} // namespace OHOS
@@ -2747,7 +2747,7 @@ private:
AAFwk::EventInfo BuildEventInfo(const Want &want, int32_t userId);
AAFwk::EventInfo BuildEventInfoByAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
ErrCode IsUIAbilityAlreadyExist(const std::string &abilityName, const std::string &specifiedFlag,
ErrCode IsUIAbilityAlreadyExist(const Want &want, const std::string &specifiedFlag,
int32_t appIndex, const std::string &instanceKey, AppExecFwk::LaunchMode launchMode);
bool IsAppCloneOrMultiInstance(const Want &want, const std::shared_ptr<AbilityRecord> callerRecord,
+1 -1
View File
@@ -99,7 +99,7 @@ public:
* @return Returns ERR_OK on success, others on failure.
*/
int LoadAbility(bool isShellCall = false, bool isStartupHide = false, pid_t callingPid = -1,
uint64_t loadAbilityCallbackId = 0);
uint64_t loadAbilityCallbackId = 0, pid_t selfPid = -1);
/**
* foreground the ability.
@@ -108,6 +108,7 @@ struct ForegroundOptions {
std::string targetGrantBundleName;
pid_t callingPid = -1;
uint64_t loadAbilityCallbackId = 0;
pid_t selfPid = -1;
};
} // namespace AAFwk
} // namespace OHOS
@@ -537,7 +537,7 @@ public:
*/
int32_t NotifyStartupExceptionBySCB(int32_t requestId, const std::string &reason);
ErrCode IsUIAbilityAlreadyExist(const std::string &abilityName, const std::string &specifiedFlag,
ErrCode IsUIAbilityAlreadyExist(const Want &want, const std::string &specifiedFlag,
int32_t appIndex, const std::string &instanceKey, AppExecFwk::LaunchMode launchMode);
private:
@@ -2233,7 +2233,6 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St
abilityRequest.specifiedFlag = want.GetStringParam(KEY_SPECIFIED_FLAG);
abilityRequest.want.RemoveParam(KEY_SPECIFIED_FLAG);
abilityRequest.abilityInfo.isolationProcess = false;
abilityRequest.abilityInfo.process = currentProcessName;
}
abilityRequest.userId = validUserId;
@@ -15966,12 +15965,12 @@ int32_t AbilityManagerService::ProcessUdmfKey(
return ERR_OK;
}
ErrCode AbilityManagerService::IsUIAbilityAlreadyExist(const std::string &abilityName,const std::string &specifiedFlag,
ErrCode AbilityManagerService::IsUIAbilityAlreadyExist(const Want &want, const std::string &specifiedFlag,
int32_t appIndex, const std::string &instanceKey, AppExecFwk::LaunchMode launchMode)
{
auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid());
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
return uiAbilityManager->IsUIAbilityAlreadyExist(abilityName, specifiedFlag, appIndex, instanceKey, launchMode);
return uiAbilityManager->IsUIAbilityAlreadyExist(want, specifiedFlag, appIndex, instanceKey, launchMode);
}
bool AbilityManagerService::IsAppCloneOrMultiInstance(const Want &want, const std::shared_ptr<AbilityRecord> callerRecord,
@@ -16038,8 +16037,7 @@ ErrCode AbilityManagerService::StartSelfUIAbilityInCurrentProcess(const Want &wa
CHECK_TRUE_RETURN_RET(abilityInfo.type != AppExecFwk::AbilityType::PAGE,
TARGET_BUNDLE_NOT_EXIST, "not UIAbility");
auto ret = IsUIAbilityAlreadyExist(targetAbilityName,
specifiedFlag, appIndex, processInfo.instanceKey, abilityInfo.launchMode);
auto ret = IsUIAbilityAlreadyExist(want, specifiedFlag, appIndex, processInfo.instanceKey, abilityInfo.launchMode);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "UIAbility already exist");
return ret;
@@ -16050,6 +16048,10 @@ ErrCode AbilityManagerService::StartSelfUIAbilityInCurrentProcess(const Want &wa
auto useStartOptions = startOptions;
useStartOptions.SetCurrentProcessName(processInfo.processName_);
if (useStartOptions.processOptions == nullptr) {
useStartOptions.processOptions = std::make_shared<ProcessOptions>();
}
useStartOptions.processOptions->selfPid = callingPid;
auto useWant = want;
if (abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) {
useWant.SetParam(KEY_SPECIFIED_FLAG, specifiedFlag);
+4 -2
View File
@@ -274,7 +274,7 @@ void AbilityRecord::LoadUIAbility()
}
int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid,
uint64_t loadAbilityCallbackId)
uint64_t loadAbilityCallbackId, pid_t selfPid)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str());
@@ -315,6 +315,7 @@ int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t calli
loadParam.loadAbilityCallbackId = loadAbilityCallbackId;
loadParam.isPrelaunch = isPrelaunch_;
loadParam.isPreloadStart = isPreloadStart_;
loadParam.selfPid = selfPid;
auto userId = abilityInfo_.uid / BASE_USER_RANGE;
bool isMainUIAbility =
MainElementUtils::IsMainUIAbility(abilityInfo_.bundleName, abilityInfo_.name, userId);
@@ -449,7 +450,8 @@ void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, const ForegroundO
if (!isReady_) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "To load ability.");
lifeCycleStateInfo_.sceneFlagBak = options.sceneFlag;
LoadAbility(options.isShellCall, options.isStartupHide, options.callingPid, options.loadAbilityCallbackId);
LoadAbility(options.isShellCall, options.isStartupHide, options.callingPid,
options.loadAbilityCallbackId, options.selfPid);
return;
}
@@ -29,6 +29,7 @@ bool ProcessOptions::ReadFromParcel(Parcel &parcel)
isPreloadStart = parcel.ReadBool();
loadAbilityCallbackId = parcel.ReadUint64();
callingPid = parcel.ReadInt32();
selfPid = parcel.ReadInt32();
return true;
}
@@ -81,6 +82,10 @@ bool ProcessOptions::Marshalling(Parcel &parcel) const
TAG_LOGE(AAFwkTag::ABILITYMGR, "callingPid write failed");
return false;
}
if (!parcel.WriteInt32(selfPid)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "selfPid write failed");
return false;
}
return true;
}
@@ -271,6 +271,9 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp
options.callingPid = abilityRequest.processOptions->callingPid;
options.loadAbilityCallbackId = abilityRequest.processOptions->loadAbilityCallbackId;
}
if (sessionInfo->processOptions != nullptr) {
options.selfPid = sessionInfo->processOptions->selfPid;
}
uiAbilityRecord->ProcessForegroundAbility(callerTokenId, options);
if (uiAbilityRecord->GetSpecifiedFlag().empty() && !sessionInfo->specifiedFlag.empty()) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "update specified: %{public}d--%{public}s", sessionInfo->requestId,
@@ -382,10 +385,6 @@ UIAbilityRecordPtr UIAbilityLifecycleManager::GenerateAbilityRecord(AbilityReque
}
MoreAbilityNumbersSendEventInfo(
abilityRequest.userId, abilityInfo.bundleName, abilityInfo.name, abilityInfo.moduleName);
if (!abilityRequest.startOptions.GetCurrentProcessName().empty()) {
uiAbilityRecord->SetProcessName(abilityRequest.abilityInfo.process);
uiAbilityRecord->SetCallerSetProcess(true);
}
if (isLowMemKill) {
TAG_LOGI(AAFwkTag::ABILITYMGR, "killed by low-mem, created a new record, "
"replacing old record id=%{public}d, new record id=%{public}d",
@@ -4314,7 +4313,7 @@ int32_t UIAbilityLifecycleManager::NotifyStartupExceptionBySCB(int32_t requestId
return ERR_OK;
}
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const std::string &abilityName,
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const Want &want,
const std::string &specifiedFlag, int32_t appIndex,
const std::string &instanceKey, AppExecFwk::LaunchMode launchMode)
{
@@ -4323,18 +4322,22 @@ ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const std::string &ab
std::lock_guard<ffrt::mutex> guard(sessionLock_);
tempSessionAbilityMap = sessionAbilityMap_;
}
std::string moduleName = want.GetElement().GetModuleName();
std::string abilityName = want.GetElement().GetAbilityName();
for (auto it = tempSessionAbilityMap.begin(); it != tempSessionAbilityMap.end(); it++) {
if (it->second == nullptr) {
continue;
}
if (launchMode == AppExecFwk::LaunchMode::SPECIFIED && it->second->GetSpecifiedFlag() == specifiedFlag &&
it->second->GetAbilityInfo().name == abilityName && it->second->GetAppIndex() == appIndex &&
it->second->GetInstanceKey() == instanceKey) {
it->second->GetAbilityInfo().name == abilityName &&
(moduleName.empty() || it->second->GetAbilityInfo().moduleName == moduleName) &&
it->second->GetAppIndex() == appIndex && it->second->GetInstanceKey() == instanceKey) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "specifiedFlag is already exist");
return ERROR_UIABILITY_IS_ALREADY_EXIST;
}
if (launchMode != AppExecFwk::LaunchMode::SPECIFIED && it->second->GetAbilityInfo().name == abilityName &&
(moduleName.empty() || it->second->GetAbilityInfo().moduleName == moduleName) &&
it->second->GetInstanceKey() == instanceKey && it->second->GetAppIndex() == appIndex) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "UIAbility is already exist");
return ERROR_UIABILITY_IS_ALREADY_EXIST;
@@ -1901,6 +1901,11 @@ private:
void ReportUIExtensionProcColdStartToRss(const std::shared_ptr<AbilityInfo>& abilityInfo,
const std::shared_ptr<AAFwk::Want>& want);
void HandleExistingAppRecordAfterFound(std::shared_ptr<AppRunningRecord> appRecord,
std::shared_ptr<AbilityInfo> abilityInfo, const HapModuleInfo &hapModuleInfo,
std::shared_ptr<AAFwk::Want> want, bool isProcCache,
const std::shared_ptr<AbilityRuntime::LoadParam> &loadParam);
private:
/**
* ClearUpApplicationData, clear the application data.
+60 -39
View File
@@ -934,6 +934,24 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
TAG_LOGE(AAFwkTag::APPMGR, "null loadParam");
return;
}
BundleInfo bundleInfo;
bool isProcCache = false;
HapModuleInfo hapModuleInfo;
int32_t appIndex = 0;
if (loadParam->selfPid > 0) {
if (!GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex)) {
TAG_LOGE(AAFwkTag::APPMGR, "getBundleAndHapInfo fail");
return;
}
std::shared_ptr<AppRunningRecord> appRecord = GetAppRunningRecordByPid(loadParam->selfPid);
if (appRecord == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appRecord not found by pid %{public}d", loadParam->selfPid);
return;
}
isProcCache = DelayedSingleton<CacheProcessManager>::GetInstance()->ReuseCachedProcess(appRecord);
HandleExistingAppRecordAfterFound(appRecord, abilityInfo, hapModuleInfo, want, isProcCache, loadParam);
return;
}
LoadAbilityCallbackGuard guard(loadParam->loadAbilityCallbackId, loadParam->callingPid, weak_from_this());
if (!CheckLoadAbilityConditions(loadParam->token, abilityInfo, appInfo)) {
TAG_LOGE(AAFwkTag::APPMGR, "checkLoadAbilityConditions fail");
@@ -954,9 +972,6 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
return;
}
BundleInfo bundleInfo;
HapModuleInfo hapModuleInfo;
int32_t appIndex = 0;
std::string callerKey;
std::string processName;
std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want); // for isolation process
@@ -965,7 +980,6 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string customProcessFlag = loadParam->customProcessFlag;
bool isProcCache = false;
bool isExtensionSandBox = false;
if (want != nullptr) {
if (want->HasParameter(DLP_INDEX)) {
@@ -1073,41 +1087,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
return;
}
} else {
TAG_LOGI(AAFwkTag::APPMGR, "have apprecord");
if (!appRecord->IsKeepAliveDkv()) {
TAG_LOGD(AAFwkTag::APPMGR, "appRecord setKeepAlive");
appRecord->SetKeepAliveDkv(loadParam->isKeepAlive);
}
if (!appRecord->IsMainElementRunning()) {
TAG_LOGD(AAFwkTag::APPMGR, "appRecord SetMainElementRunning");
appRecord->SetMainElementRunning(loadParam->isMainElementRunning);
}
if (appRecord->GetProcessType() == ProcessType::EXTENSION &&
appRecord->GetExtensionType() != abilityInfo->extensionAbilityType) {
appRecord->SetProcessType(ProcessType::NORMAL);
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessTypeChanged(appRecord);
}
ReportEventToRSS(*abilityInfo, appRecord);
appRunningManager_->UpdateConfigurationDelayed(appRecord);
if (!isProcCache) {
SendPreloadAppStartupTypeEvent(appRecord, abilityInfo);
} else {
SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::WARM, AppStartReason::SUGGEST_CACHE);
}
if (appRecord->GetPreloadMode() == PreloadMode::PRE_LAUNCH) {
appRecord->SetPreloadMode(PreloadMode::PRELOAD_NONE);
}
if (appRecord->IsPreloaded()) {
appRecord->SetPreloadState(PreloadState::NONE);
appRecord->SetPreloadMode(PreloadMode::PRELOAD_NONE);
}
int32_t requestProcCode = (want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0);
if (requestProcCode != 0 && appRecord->GetRequestProcCode() == 0) {
appRecord->SetRequestProcCode(requestProcCode);
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessReused(appRecord);
}
StartAbility(loadParam->token, loadParam->preToken, abilityInfo, appRecord, hapModuleInfo, want,
loadParam->abilityRecordId);
HandleExistingAppRecordAfterFound(appRecord, abilityInfo, hapModuleInfo, want, isProcCache, loadParam);
if (AAFwk::UIExtensionUtils::IsUIExtension(abilityInfo->extensionAbilityType)) {
AddUIExtensionBindItem(want, appRecord, loadParam->token);
AddUIExtensionLauncherItem(want, appRecord, loadParam->token);
@@ -1191,6 +1171,47 @@ void AppMgrServiceInner::AfterLoadAbility(std::shared_ptr<AppRunningRecord> appR
appRecord->UpdateAbilityState(loadParam->token, AbilityState::ABILITY_STATE_CREATE);
}
void AppMgrServiceInner::HandleExistingAppRecordAfterFound(std::shared_ptr<AppRunningRecord> appRecord,
std::shared_ptr<AbilityInfo> abilityInfo, const HapModuleInfo &hapModuleInfo,
std::shared_ptr<AAFwk::Want> want, bool isProcCache, const std::shared_ptr<AbilityRuntime::LoadParam> &loadParam)
{
TAG_LOGI(AAFwkTag::APPMGR, "have apprecord");
if (!appRecord->IsKeepAliveDkv()) {
TAG_LOGD(AAFwkTag::APPMGR, "appRecord setKeepAlive");
appRecord->SetKeepAliveDkv(loadParam->isKeepAlive);
}
if (!appRecord->IsMainElementRunning()) {
TAG_LOGD(AAFwkTag::APPMGR, "appRecord SetMainElementRunning");
appRecord->SetMainElementRunning(loadParam->isMainElementRunning);
}
if (appRecord->GetProcessType() == ProcessType::EXTENSION &&
appRecord->GetExtensionType() != abilityInfo->extensionAbilityType) {
appRecord->SetProcessType(ProcessType::NORMAL);
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessTypeChanged(appRecord);
}
ReportEventToRSS(*abilityInfo, appRecord);
appRunningManager_->UpdateConfigurationDelayed(appRecord);
if (!isProcCache) {
SendPreloadAppStartupTypeEvent(appRecord, abilityInfo);
} else {
SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::WARM, AppStartReason::SUGGEST_CACHE);
}
if (appRecord->GetPreloadMode() == PreloadMode::PRE_LAUNCH) {
appRecord->SetPreloadMode(PreloadMode::PRELOAD_NONE);
}
if (appRecord->IsPreloaded()) {
appRecord->SetPreloadState(PreloadState::NONE);
appRecord->SetPreloadMode(PreloadMode::PRELOAD_NONE);
}
int32_t requestProcCode = (want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0);
if (requestProcCode != 0 && appRecord->GetRequestProcCode() == 0) {
appRecord->SetRequestProcCode(requestProcCode);
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessReused(appRecord);
}
StartAbility(loadParam->token, loadParam->preToken, abilityInfo, appRecord, hapModuleInfo, want,
loadParam->abilityRecordId);
}
void AppMgrServiceInner::AddUIExtensionLauncherItem(std::shared_ptr<AAFwk::Want> want,
std::shared_ptr<AppRunningRecord> appRecord, sptr<IRemoteObject> token)
{
@@ -394,7 +394,7 @@ public:
int32_t NotifyStartupExceptionBySCB(int32_t requestId, const std::string &reason);
ErrCode IsUIAbilityAlreadyExist(const std::string &abilityName, const std::string &specifiedFlag,
ErrCode IsUIAbilityAlreadyExist(const Want &want, const std::string &specifiedFlag,
int32_t appIndex, const std::string &instanceKey, AppExecFwk::LaunchMode launchMode);
private:
@@ -300,7 +300,8 @@ void AbilityRecord::LoadUIAbility()
g_addLifecycleEventTask(token_, methodName);
}
int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid, uint64_t callbackId)
int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid,
uint64_t callbackId, pid_t selfPid)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str());
@@ -754,7 +754,7 @@ int32_t UIAbilityLifecycleManager::NotifyStartupExceptionBySCB(int32_t requestId
return ERR_OK;
}
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const std::string &abilityName,
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const Want &want,
const std::string &specifiedFlag, int32_t appIndex,
const std::string &instanceKey, AppExecFwk::LaunchMode launchMode)
{
@@ -2086,11 +2086,11 @@ HWTEST_F(AbilityManagerServiceSixthTest, IsUIAbilityAlreadyExist_001, TestSize.L
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest IsUIAbilityAlreadyExist_001 start");
auto abilityMs = std::make_shared<AbilityManagerService>();
ASSERT_NE(abilityMs, nullptr);
std::string abilityName;
Want want;
std::string specifiedFlag;
int32_t appIndex = 0;
std::string instanceKey;
auto ret = abilityMs->IsUIAbilityAlreadyExist(abilityName, specifiedFlag, appIndex,
auto ret = abilityMs->IsUIAbilityAlreadyExist(want, specifiedFlag, appIndex,
instanceKey, AppExecFwk::LaunchMode::SPECIFIED);
EXPECT_EQ(ret, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceSixthTest IsUIAbilityAlreadyExist_001 end");
@@ -396,7 +396,7 @@ public:
int32_t NotifyStartupExceptionBySCB(int32_t requestId, const std::string &reason);
ErrCode IsUIAbilityAlreadyExist(const std::string &abilityName, const std::string &specifiedFlag,
ErrCode IsUIAbilityAlreadyExist(const Want &want, const std::string &specifiedFlag,
int32_t appIndex, const std::string &instanceKey, AppExecFwk::LaunchMode launchMode);
private:
@@ -304,7 +304,8 @@ void AbilityRecord::LoadUIAbility()
g_addLifecycleEventTask(token_, methodName);
}
int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid, uint64_t callbackId)
int AbilityRecord::LoadAbility(bool isShellCall, bool isStartupHide, pid_t callingPid,
uint64_t callbackId, pid_t selfPid)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::ABILITYMGR, "LoadLifecycle: abilityName:%{public}s", abilityInfo_.name.c_str());
@@ -763,7 +763,7 @@ int32_t UIAbilityLifecycleManager::NotifyStartupExceptionBySCB(int32_t requestId
return ERR_OK;
}
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const std::string &abilityName,
ErrCode UIAbilityLifecycleManager::IsUIAbilityAlreadyExist(const Want &want,
const std::string &specifiedFlag, int32_t appIndex,
const std::string &instanceKey, AppExecFwk::LaunchMode launchMode)
{
@@ -400,6 +400,95 @@ HWTEST_F(AppMgrServiceInnerTest, PreStartNWebSpawnProcess_001, TestSize.Level2)
EXPECT_NE(ret, ERR_OK);
}
/**
* @tc.name: HandleExistingAppRecordAfterFound_001
* @tc.desc: verify keepAlive/mainElement flags and preload reset without process cache
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, HandleExistingAppRecordAfterFound_001, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
ASSERT_NE(appMgrServiceInner, nullptr);
HapModuleInfo hapModuleInfo;
auto want = std::make_shared<AAFwk::Want>();
BundleInfo info;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, "");
appRecord->SetKeepAliveDkv(false);
appRecord->SetMainElementRunning(false);
appRecord->SetPreloadMode(PreloadMode::PRE_LAUNCH);
appRecord->SetPreloadState(PreloadState::PRELOADING);
AbilityRuntime::LoadParam loadParam;
loadParam.isKeepAlive = true;
loadParam.isMainElementRunning = true;
appMgrServiceInner->HandleExistingAppRecordAfterFound(appRecord, abilityInfo_, hapModuleInfo, want, false,
std::make_shared<AbilityRuntime::LoadParam>(loadParam));
EXPECT_TRUE(appRecord->IsKeepAliveDkv());
EXPECT_TRUE(appRecord->IsMainElementRunning());
EXPECT_EQ(appRecord->GetPreloadMode(), PreloadMode::PRELOAD_NONE);
}
/**
* @tc.name: HandleExistingAppRecordAfterFound_002
* @tc.desc: verify request proc code propagation from want to record
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, HandleExistingAppRecordAfterFound_002, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
ASSERT_NE(appMgrServiceInner, nullptr);
HapModuleInfo hapModuleInfo;
auto want = std::make_shared<AAFwk::Want>();
want->SetParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 5);
BundleInfo info;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, "");
EXPECT_EQ(appRecord->GetRequestProcCode(), 0);
AbilityRuntime::LoadParam loadParam;
appMgrServiceInner->HandleExistingAppRecordAfterFound(appRecord, abilityInfo_, hapModuleInfo, want, false,
std::make_shared<AbilityRuntime::LoadParam>(loadParam));
EXPECT_EQ(appRecord->GetRequestProcCode(), 5);
}
/**
* @tc.name: HandleExistingAppRecordAfterFound_003
* @tc.desc: when extension type mismatches in EXTENSION process, reset to NORMAL
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, HandleExistingAppRecordAfterFound_003, TestSize.Level1)
{
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
ASSERT_NE(appMgrServiceInner, nullptr);
HapModuleInfo hapModuleInfo;
auto want = std::make_shared<AAFwk::Want>();
BundleInfo info;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, "");
appRecord->SetProcessType(ProcessType::EXTENSION);
appRecord->extensionType_ = ExtensionAbilityType::SERVICE;
abilityInfo_->extensionAbilityType = ExtensionAbilityType::UI_SERVICE;
AbilityRuntime::LoadParam loadParam;
appMgrServiceInner->HandleExistingAppRecordAfterFound(appRecord, abilityInfo_, hapModuleInfo, want, false,
std::make_shared<AbilityRuntime::LoadParam>(loadParam));
EXPECT_EQ(appRecord->GetProcessType(), ProcessType::NORMAL);
}
/**
* @tc.name: PreStartNWebSpawnProcess_002
* @tc.desc: prestart nwebspawn process.
@@ -7149,7 +7149,9 @@ HWTEST_F(UIAbilityLifecycleManagerTest, IsUIAbilityAlreadyExist_0001, TestSize.L
record->SetInstanceKey(instanceKey);
mgr->sessionAbilityMap_[1] = record;
auto ret = mgr->IsUIAbilityAlreadyExist(abilityName, "", appIndex, instanceKey, AppExecFwk::LaunchMode::STANDARD);
Want want;
want.SetElementName("device", bundleName, abilityName, moduleName);
auto ret = mgr->IsUIAbilityAlreadyExist(want, "", appIndex, instanceKey, AppExecFwk::LaunchMode::STANDARD);
EXPECT_EQ(ret, ERROR_UIABILITY_IS_ALREADY_EXIST);
}
@@ -7182,7 +7184,9 @@ HWTEST_F(UIAbilityLifecycleManagerTest, IsUIAbilityAlreadyExist_0002, TestSize.L
record->SetSpecifiedFlag(specifiedFlag);
mgr->sessionAbilityMap_[10] = record;
auto ret = mgr->IsUIAbilityAlreadyExist(abilityName, specifiedFlag, appIndex, instanceKey,
Want want;
want.SetElementName("device", bundleName, abilityName, moduleName);
auto ret = mgr->IsUIAbilityAlreadyExist(want, specifiedFlag, appIndex, instanceKey,
AppExecFwk::LaunchMode::SPECIFIED);
EXPECT_EQ(ret, ERROR_UIABILITY_IS_ALREADY_EXIST);
}
@@ -7196,7 +7200,9 @@ HWTEST_F(UIAbilityLifecycleManagerTest, IsUIAbilityAlreadyExist_0003, TestSize.L
{
auto mgr = std::make_shared<UIAbilityLifecycleManager>();
ASSERT_NE(mgr, nullptr);
auto ret = mgr->IsUIAbilityAlreadyExist("NoExistAbility", "flag", 0, "key", AppExecFwk::LaunchMode::STANDARD);
Want want;
want.SetElementName("device", "com.example.test", "NoExistAbility", "entry");
auto ret = mgr->IsUIAbilityAlreadyExist(want, "flag", 0, "key", AppExecFwk::LaunchMode::STANDARD);
EXPECT_EQ(ret, ERR_OK);
AbilityRequest abilityRequest;
@@ -7208,7 +7214,7 @@ HWTEST_F(UIAbilityLifecycleManagerTest, IsUIAbilityAlreadyExist_0003, TestSize.L
record->SetAppIndex(0);
record->SetInstanceKey("key");
mgr->sessionAbilityMap_[5] = record;
ret = mgr->IsUIAbilityAlreadyExist("NoExistAbility", "flag", 0, "key", AppExecFwk::LaunchMode::STANDARD);
ret = mgr->IsUIAbilityAlreadyExist(want, "flag", 0, "key", AppExecFwk::LaunchMode::STANDARD);
EXPECT_EQ(ret, ERR_OK);
}
} // namespace AAFwk
+1
View File
@@ -58,6 +58,7 @@ struct LoadParam : public Parcelable {
uint64_t loadAbilityCallbackId = 0;
bool isPrelaunch = false;
bool isPreloadStart = false;
pid_t selfPid = -1;
};
} // namespace AbilityRuntime
} // namespace OHOS