app startup process quarantine

Signed-off-by: liuzongze <liuzongze@huawei.com>
Change-Id: I467bb8dc938bd098ac8d025428344c0e92567452
This commit is contained in:
liuzongze 2024-08-27 15:34:04 +08:00
parent 7fa45ddf39
commit c00bc5a381
6 changed files with 51 additions and 3 deletions

View File

@ -201,7 +201,7 @@ void UIAbility::OnStop()
(void)Rosen::WindowManager::GetInstance().UnregisterDisplayInfoChangedListener(token_, abilityDisplayListener_);
auto &&window = GetWindow();
if (window != nullptr) {
TAG_LOGD(AAFwkTag::UIABILITY, "UnregisterDisplayMoveListener");
TAG_LOGD(AAFwkTag::UIABILITY, "UnregisterDisplayMoveListener");
window->UnregisterDisplayMoveListener(abilityDisplayMoveListener_);
}
// Call JS Func(onWindowStageDestroy) and Release the scene.

View File

@ -635,6 +635,7 @@ 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 = CreateAutoStartupCallback(abilityStage, abilityRecord, callback);
if (autoStartupCallback != nullptr) {
abilityStage->RunAutoStartupTask(autoStartupCallback, isAsyncCallback, stageContext);
@ -669,7 +670,7 @@ const std::function<void()> OHOSApplication::CreateAutoStartupCallback(
const std::function<void(const std::shared_ptr<AbilityRuntime::Context>&)>& callback)
{
const std::shared_ptr<AbilityInfo> &abilityInfo = abilityRecord->GetAbilityInfo();
if (!IsBackupExtension(abilityInfo)) {
if (!IsMainProcess(abilityInfo->bundleName, abilityInfo->applicationInfo.process)) {
return nullptr;
}
std::string moduleName = abilityInfo->moduleName;
@ -1068,5 +1069,25 @@ bool OHOSApplication::IsBackupExtension(const std::shared_ptr<AbilityInfo> &abil
}
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

View File

@ -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

View File

@ -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

View File

@ -329,7 +329,7 @@ private:
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 IsBackupExtension(const std::shared_ptr<AbilityInfo> &abilityInfo);
bool IsMainProcess(const std::string &bundleName, const std::string &process);
private:
std::list<std::shared_ptr<AbilityLifecycleCallbacks>> abilityLifecycleCallbacks_;

View File

@ -472,6 +472,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config)
}
}
ProcessInfo processInfo(processName_, GetPriorityObject()->GetPid());
processInfo.SetProcessType(processType_);
launchData.SetProcessInfo(processInfo);
launchData.SetRecordId(appRecordId_);
launchData.SetUId(mainUid_);