mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-12-02 20:47:11 +00:00
app startup process quarantine
Signed-off-by: liuzongze <liuzongze@huawei.com> Change-Id: I467bb8dc938bd098ac8d025428344c0e92567452
This commit is contained in:
parent
8e3b78aaf4
commit
d7b33a148b
@ -673,20 +673,14 @@ std::shared_ptr<AbilityRuntime::Context> OHOSApplication::AddAbilityStage(
|
||||
auto application = std::static_pointer_cast<OHOSApplication>(shared_from_this());
|
||||
std::weak_ptr<OHOSApplication> weak = application;
|
||||
abilityStage->Init(stageContext, weak);
|
||||
|
||||
auto autoStartupCallback = [weak, abilityStage, abilityRecord, moduleName, callback]() {
|
||||
auto ohosApplication = weak.lock();
|
||||
if (ohosApplication == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "ohosApplication is nullptr");
|
||||
return;
|
||||
|
||||
auto autoStartupCallback = CreateAutoStartupCallback(abilityStage, abilityRecord, callback);
|
||||
if (autoStartupCallback != nullptr) {
|
||||
abilityStage->RunAutoStartupTask(autoStartupCallback, isAsyncCallback, stageContext);
|
||||
if (isAsyncCallback) {
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "waiting for startup");
|
||||
return nullptr;
|
||||
}
|
||||
ohosApplication->AutoStartupDone(abilityRecord, abilityStage, moduleName);
|
||||
callback(abilityStage->GetContext());
|
||||
};
|
||||
abilityStage->RunAutoStartupTask(autoStartupCallback, isAsyncCallback, stageContext);
|
||||
if (isAsyncCallback) {
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "waiting for startup");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Want want;
|
||||
@ -708,6 +702,36 @@ std::shared_ptr<AbilityRuntime::Context> OHOSApplication::AddAbilityStage(
|
||||
return abilityStage->GetContext();
|
||||
}
|
||||
|
||||
const std::function<void()> OHOSApplication::CreateAutoStartupCallback(
|
||||
const std::shared_ptr<AbilityRuntime::AbilityStage> abilityStage,
|
||||
const std::shared_ptr<AbilityLocalRecord> abilityRecord,
|
||||
const std::function<void(const std::shared_ptr<AbilityRuntime::Context>&)>& callback)
|
||||
{
|
||||
const std::shared_ptr<AbilityInfo> &abilityInfo = abilityRecord->GetAbilityInfo();
|
||||
if (!IsMainProcess(abilityInfo->bundleName, abilityInfo->applicationInfo.process)) {
|
||||
return nullptr;
|
||||
}
|
||||
std::string moduleName = abilityInfo->moduleName;
|
||||
auto application = std::static_pointer_cast<OHOSApplication>(shared_from_this());
|
||||
std::weak_ptr<OHOSApplication> weak = application;
|
||||
|
||||
auto autoStartupCallback = [weak, abilityStage, abilityRecord, moduleName, callback]() {
|
||||
auto ohosApplication = weak.lock();
|
||||
if (ohosApplication == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null ohosApplication");
|
||||
return;
|
||||
}
|
||||
ohosApplication->AutoStartupDone(abilityRecord, abilityStage, moduleName);
|
||||
if (callback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null callback");
|
||||
return;
|
||||
}
|
||||
callback(abilityStage->GetContext());
|
||||
};
|
||||
|
||||
return autoStartupCallback;
|
||||
}
|
||||
|
||||
void OHOSApplication::AutoStartupDone(const std::shared_ptr<AbilityLocalRecord> &abilityRecord,
|
||||
const std::shared_ptr<AbilityRuntime::AbilityStage> &abilityStage, const std::string &moduleName)
|
||||
{
|
||||
@ -1036,5 +1060,25 @@ bool OHOSApplication::isUpdateLanguage(Configuration &config, const std::string
|
||||
AbilityRuntime::ApplicationConfigurationManager::GetInstance().SetLanguageSetLevel(currentSetLevel);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OHOSApplication::IsMainProcess(const std::string &bundleName, const std::string &process)
|
||||
{
|
||||
auto processInfo = GetProcessInfo();
|
||||
if (processInfo == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null processInfo");
|
||||
return false;
|
||||
}
|
||||
ProcessType processType = processInfo->GetProcessType();
|
||||
if (processType == ProcessType::NORMAL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string processName = processInfo->GetProcessName();
|
||||
if (processName == bundleName || processName == process) {
|
||||
return true;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "not main process");
|
||||
return false;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "parcel.h"
|
||||
#include "app_mgr_constants.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
@ -72,9 +73,24 @@ public:
|
||||
*/
|
||||
static ProcessInfo *Unmarshalling(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* @brief Set process type
|
||||
*
|
||||
* @param ProcessType process type.
|
||||
*/
|
||||
void SetProcessType(const ProcessType &processType);
|
||||
|
||||
/**
|
||||
* @brief Obtains type of the process.
|
||||
*
|
||||
* @return Returns process type.
|
||||
*/
|
||||
ProcessType GetProcessType() const;
|
||||
|
||||
private:
|
||||
std::string processName_;
|
||||
pid_t pid_ = 0;
|
||||
ProcessType processType_ = ProcessType::NORMAL;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -61,5 +61,15 @@ bool ProcessInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return (parcel.WriteString16(Str8ToStr16(processName_)) && parcel.WriteInt32(pid_));
|
||||
}
|
||||
|
||||
void ProcessInfo::SetProcessType(const ProcessType &processType)
|
||||
{
|
||||
processType_ = processType;
|
||||
}
|
||||
|
||||
ProcessType ProcessInfo::GetProcessType() const
|
||||
{
|
||||
return processType_;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -324,6 +324,11 @@ private:
|
||||
bool isUpdateFontSize(Configuration &config);
|
||||
bool isUpdateLanguage(Configuration &config, const std::string language,
|
||||
const std::string languageIsSetByApp, const std::string globalLanguageIsSetByApp);
|
||||
const std::function<void()> CreateAutoStartupCallback(
|
||||
const std::shared_ptr<AbilityRuntime::AbilityStage> abilityStage,
|
||||
const std::shared_ptr<AbilityLocalRecord> abilityRecord,
|
||||
const std::function<void(const std::shared_ptr<AbilityRuntime::Context>&)>& callback);
|
||||
bool IsMainProcess(const std::string &bundleName, const std::string &process);
|
||||
|
||||
private:
|
||||
std::list<std::shared_ptr<AbilityLifecycleCallbacks>> abilityLifecycleCallbacks_;
|
||||
|
@ -445,6 +445,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
|
||||
}
|
||||
}
|
||||
ProcessInfo processInfo(processName_, GetPriorityObject()->GetPid());
|
||||
processInfo.SetProcessType(processType_);
|
||||
launchData.SetProcessInfo(processInfo);
|
||||
launchData.SetRecordId(appRecordId_);
|
||||
launchData.SetUId(mainUid_);
|
||||
|
Loading…
Reference in New Issue
Block a user