!11621 EmbeddUIExt & UIability 支持PC应用设置进程名

Merge pull request !11621 from chenzexin/1115
This commit is contained in:
openharmony_ci 2024-11-20 01:57:14 +00:00 committed by Gitee
commit afbe5ea39d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 56 additions and 18 deletions

View File

@ -273,6 +273,7 @@ struct AbilityRequest {
AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
AppExecFwk::ExtensionProcessMode extensionProcessMode = AppExecFwk::ExtensionProcessMode::UNDEFINED;
std::string customProcess;
sptr<SessionInfo> sessionInfo;
uint32_t specifyTokenId = 0;
@ -1011,6 +1012,8 @@ public:
void SetStartToBackground(const bool flag);
bool IsStartToForeground() const;
void SetStartToForeground(const bool flag);
bool IsCallerSetProcess() const;
void SetCallerSetProcess(const bool flag);
void SetSessionInfo(sptr<SessionInfo> sessionInfo);
void UpdateSessionInfo(sptr<IRemoteObject> sessionToken);
void SetMinimizeReason(bool fromUser);
@ -1304,6 +1307,7 @@ private:
bool isStartedByCall_ = false;
bool isStartToBackground_ = false;
bool isStartToForeground_ = false;
std::atomic_bool isCallerSetProcess_ = false;
int32_t appIndex_ = 0;
bool minimizeReason_ = false;

View File

@ -31,6 +31,7 @@ constexpr uint32_t PROCESS_MODE_RUN_WITH_MAIN_PROCESS =
constexpr uint32_t PROCESS_INNER_MODE_OFFSET = 16;
constexpr uint32_t PROCESS_MODE_HOST_SPECIFIED = 1 << (PROCESS_INNER_MODE_OFFSET + 0);
constexpr uint32_t PROCESS_MODE_HOST_INSTANCE = 1 << (PROCESS_INNER_MODE_OFFSET + 1);
constexpr uint32_t PROCESS_MODE_CUSTOM = 1 << (PROCESS_INNER_MODE_OFFSET + 2);
constexpr uint32_t PROCESS_MODE_SUPPORT_DEFAULT = PROCESS_MODE_BUNDLE | PROCESS_MODE_TYPE | PROCESS_MODE_INSTANCE;
constexpr uint32_t PRE_CHECK_FLAG_NONE = 0;
constexpr uint32_t PRE_CHECK_FLAG_CALLED_WITHIN_THE_BUNDLE = 1 << 0;

View File

@ -45,6 +45,7 @@ struct StartAbilityInfo {
AppExecFwk::AbilityInfo abilityInfo;
AppExecFwk::ExtensionProcessMode extensionProcessMode = AppExecFwk::ExtensionProcessMode::UNDEFINED;
int32_t status = ERR_OK;
std::string customProcess;
};
struct StartAbilityUtils {

View File

@ -1458,6 +1458,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr<AbilityRecord> &ab
loadParam.token = token;
loadParam.preToken = perToken;
loadParam.instanceKey = abilityRecord->GetInstanceKey();
loadParam.isCallerSetProcess = abilityRecord->IsCallerSetProcess();
DelayedSingleton<AppScheduler>::GetInstance()->LoadAbility(
loadParam, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), abilityRecord->GetWant());
}

View File

@ -6462,6 +6462,7 @@ int32_t AbilityManagerService::InitialAbilityRequest(AbilityRequest &request,
{
request.abilityInfo = abilityInfo.abilityInfo;
request.extensionProcessMode = abilityInfo.extensionProcessMode;
request.customProcess = abilityInfo.customProcess;
if (request.abilityInfo.applicationInfo.name.empty() || request.abilityInfo.applicationInfo.bundleName.empty()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "get app info failed");
return RESOLVE_APP_ERR;

View File

@ -347,6 +347,7 @@ int AbilityRecord::LoadAbility(bool isShellCall)
loadParam.token = token_;
loadParam.preToken = callerToken;
loadParam.instanceKey = instanceKey_;
loadParam.isCallerSetProcess = IsCallerSetProcess();
want_.RemoveParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED);
if (KeepAliveProcessManager::GetInstance().IsKeepAliveBundle(abilityInfo_.applicationInfo.bundleName, -1)) {
want_.SetParam(Want::PARAM_APP_KEEP_ALIVE_ENABLED, true);
@ -3076,6 +3077,16 @@ void AbilityRecord::SetStartToForeground(const bool flag)
isStartToForeground_ = flag;
}
bool AbilityRecord::IsCallerSetProcess() const
{
return isCallerSetProcess_.load();
}
void AbilityRecord::SetCallerSetProcess(const bool flag)
{
isCallerSetProcess_.store(flag);
}
void AbilityRecord::CallRequest()
{
CHECK_POINTER(scheduler_);

View File

@ -25,7 +25,8 @@ using namespace OHOS::AppExecFwk;
namespace {
const std::map<AppExecFwk::ExtensionAbilityType, ExtensionRecordConfig> EXTENSION_RECORD_CONFIG_MAP = {
{ AppExecFwk::ExtensionAbilityType::EMBEDDED_UI,
{ PROCESS_MODE_BUNDLE, PROCESS_MODE_SUPPORT_DEFAULT | PROCESS_MODE_HOST_SPECIFIED | PROCESS_MODE_HOST_INSTANCE,
{ PROCESS_MODE_BUNDLE, PROCESS_MODE_SUPPORT_DEFAULT | PROCESS_MODE_HOST_SPECIFIED |
PROCESS_MODE_HOST_INSTANCE | PROCESS_MODE_CUSTOM,
PRE_CHECK_FLAG_CALLED_WITHIN_THE_BUNDLE | PRE_CHECK_FLAG_MULTIPLE_PROCESSES }},
{ AppExecFwk::ExtensionAbilityType::STATUS_BAR_VIEW,
{ PROCESS_MODE_BUNDLE, PROCESS_MODE_SUPPORT_DEFAULT | PROCESS_MODE_RUN_WITH_MAIN_PROCESS,
@ -111,6 +112,12 @@ uint32_t ExtensionRecordFactory::GetExtensionProcessMode(
}
}
if (config.processModeSupport & PROCESS_MODE_CUSTOM) {
if (!abilityRequest.customProcess.empty()) {
return PROCESS_MODE_CUSTOM;
}
}
if (abilityRequest.extensionProcessMode == ExtensionProcessMode::UNDEFINED) {
return config.processModeDefault;
}

View File

@ -256,6 +256,11 @@ int32_t ExtensionRecordManager::UpdateProcessName(const AAFwk::AbilityRequest &a
abilityRecord->SetProcessName(process);
break;
}
case PROCESS_MODE_CUSTOM: {
std::string process = abilityRequest.abilityInfo.bundleName + abilityRequest.customProcess;
abilityRecord->SetProcessName(process);
break;
}
case PROCESS_MODE_HOST_SPECIFIED: {
std::string process = abilityRequest.want.GetStringParam(PROCESS_MODE_HOST_SPECIFIED_KEY);
if (!IsHostSpecifiedProcessValid(abilityRequest, record, process)) {

View File

@ -817,6 +817,7 @@ void UIAbilityLifecycleManager::UpdateProcessName(const AbilityRequest &abilityR
processName = GenerateProcessNameForNewProcessMode(abilityRequest.abilityInfo);
}
abilityRecord->SetProcessName(processName);
abilityRecord->SetCallerSetProcess(true);
}
void UIAbilityLifecycleManager::UpdateAbilityRecordLaunchReason(

View File

@ -278,6 +278,7 @@ std::shared_ptr<StartAbilityInfo> StartAbilityInfo::CreateStartExtensionInfo(con
return abilityInfo;
}
abilityInfo->extensionProcessMode = extensionInfo.extensionProcessMode;
abilityInfo->customProcess = extensionInfo.customProcess;
// For compatibility translates to AbilityInfo
AbilityRuntime::StartupUtil::InitAbilityInfoFromExtension(extensionInfo, abilityInfo->abilityInfo);

View File

@ -1461,7 +1461,7 @@ private:
*/
void MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, int32_t appIndex,
const std::string &specifiedProcessFlag, std::string &processName) const;
const std::string &specifiedProcessFlag, std::string &processName, bool isCallerSetProcess) const;
/**
* Build a process's name based on the info given

View File

@ -424,7 +424,7 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap
std::string processName;
auto abilityInfoPtr = std::make_shared<AbilityInfo>(abilityInfo);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName, false);
TAG_LOGD(AAFwkTag::APPMGR, "processName = %{public}s", processName.c_str());
auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY);
auto mainAppRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid,
@ -525,7 +525,7 @@ void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request)
std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want);
std::string processName;
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, request.appIndex, specifiedProcessFlag, processName);
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, request.appIndex, specifiedProcessFlag, processName, false);
TAG_LOGD(AAFwkTag::APPMGR, "HandlePreloadApplication processName = %{public}s", processName.c_str());
std::shared_ptr<AppRunningRecord> appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name,
@ -668,7 +668,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
// for isolation process
std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want);
std::string processName;
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag, processName);
MakeProcessName(abilityInfo, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag,
processName, loadParam->isCallerSetProcess);
TAG_LOGI(AAFwkTag::APPMGR, "%{public}s name:%{public}s-%{public}s processName = %{public}s",
__func__, abilityInfo->bundleName.c_str(), abilityInfo->name.c_str(), processName.c_str());
@ -899,17 +900,20 @@ void AppMgrServiceInner::MakeServiceExtProcessName(const std::shared_ptr<Ability
void AppMgrServiceInner::MakeProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
const std::shared_ptr<ApplicationInfo> &appInfo, const HapModuleInfo &hapModuleInfo, int32_t appIndex,
const std::string &specifiedProcessFlag, std::string &processName) const
const std::string &specifiedProcessFlag, std::string &processName, bool isCallerSetProcess) const
{
if (!abilityInfo || !appInfo) {
TAG_LOGE(AAFwkTag::APPMGR, "param error");
return;
}
if (!abilityInfo->process.empty()) {
if (!abilityInfo->process.empty() && (isCallerSetProcess || specifiedProcessFlag.empty())) {
TAG_LOGD(AAFwkTag::APPMGR, "Process not null");
processName = abilityInfo->process;
// extension's process is bundleName:extensionType, generated at installation time
MakeIsolateSandBoxProcessName(abilityInfo, hapModuleInfo, processName);
if (appIndex != 0) {
processName += ":" + std::to_string(appIndex);
}
return;
}
MakeProcessName(appInfo, hapModuleInfo, processName);
@ -4640,7 +4644,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap
std::string processName;
auto abilityInfoPtr = std::make_shared<AbilityInfo>(abilityInfo);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName, false);
std::vector<HapModuleInfo> hapModules;
hapModules.emplace_back(hapModuleInfo);
@ -6481,7 +6485,7 @@ int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &wan
std::string processName;
auto abilityInfoPtr = std::make_shared<AbilityInfo>(abilityInfo);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, 0, "", processName);
MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, 0, "", processName, false);
if (UserRecordManager::GetInstance().IsLogoutUser(GetUserIdByUid(appInfo->uid))) {
TAG_LOGE(AAFwkTag::APPMGR, "disable start process in logout user");
return ERR_INVALID_OPERATION;

View File

@ -816,20 +816,20 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_MakeProcessN
std::string specifiedProcessFlag = "akeProcessName";
std::string processName = "akeProcessName";
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo,
appIndex, specifiedProcessFlag, processName);
appIndex, specifiedProcessFlag, processName, false);
abilityInfo_->process = "akeProcessName";
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo,
appIndex, specifiedProcessFlag, processName);
appIndex, specifiedProcessFlag, processName, false);
abilityInfo_->process = "";
appIndex = 1;
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo,
appIndex, specifiedProcessFlag, processName);
appIndex, specifiedProcessFlag, processName, false);
abilityInfo_ = nullptr;
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo,
appIndex, specifiedProcessFlag, processName);
appIndex, specifiedProcessFlag, processName, false);
applicationInfo_ = nullptr;
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo,
appIndex, specifiedProcessFlag, processName);
appIndex, specifiedProcessFlag, processName, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerSecondTest_MakeProcessName_0100 end");
}

View File

@ -471,10 +471,10 @@ HWTEST_F(AppMgrServiceInnerTest, MakeProcessName_001, TestSize.Level0)
HapModuleInfo hapModuleInfo;
hapModuleInfo.moduleName = "module789";
std::string processName = "test_processName";
appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, "", processName);
appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, "", processName);
appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, "", processName);
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, "", processName);
appMgrServiceInner->MakeProcessName(nullptr, nullptr, hapModuleInfo, 1, "", processName, false);
appMgrServiceInner->MakeProcessName(nullptr, applicationInfo_, hapModuleInfo, 1, "", processName, false);
appMgrServiceInner->MakeProcessName(abilityInfo_, nullptr, hapModuleInfo, 1, "", processName, false);
appMgrServiceInner->MakeProcessName(abilityInfo_, applicationInfo_, hapModuleInfo, 1, "", processName, false);
EXPECT_NE(appMgrServiceInner, nullptr);
TAG_LOGI(AAFwkTag::TEST, "MakeProcessName_001 end");

View File

@ -44,6 +44,7 @@ struct LoadParam : public Parcelable {
sptr<IRemoteObject> preToken = nullptr;
std::string instanceKey = "";
bool isKeepAlive = false;
bool isCallerSetProcess = false;
};
} // namespace AbilityRuntime
} // namespace OHOS