mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
startup support feature module
Signed-off-by: zhangzezhong <zhangzezhong8@huawei-partners.com>
This commit is contained in:
@@ -489,12 +489,13 @@ int32_t JsAbilityStage::RunAutoStartupTask(const std::function<void()> &callback
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null hapModuleInfo");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (hapModuleInfo->moduleType != AppExecFwk::ModuleType::ENTRY) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "not entry module");
|
||||
if (hapModuleInfo->moduleType != AppExecFwk::ModuleType::ENTRY &&
|
||||
hapModuleInfo->moduleType != AppExecFwk::ModuleType::FEATURE) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "not entry module or feature module");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (hapModuleInfo->appStartup.empty()) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "entry module no app startup config");
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "module no app startup config");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (!shellContextRef_) {
|
||||
@@ -504,7 +505,7 @@ int32_t JsAbilityStage::RunAutoStartupTask(const std::function<void()> &callback
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
return RunAutoStartupTaskInner(callback, isAsyncCallback);
|
||||
return RunAutoStartupTaskInner(callback, isAsyncCallback, hapModuleInfo->name);
|
||||
}
|
||||
|
||||
int32_t JsAbilityStage::RegisterAppStartupTask(const std::shared_ptr<AppExecFwk::HapModuleInfo>& hapModuleInfo)
|
||||
@@ -519,18 +520,22 @@ int32_t JsAbilityStage::RegisterAppStartupTask(const std::shared_ptr<AppExecFwk:
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
result = startupManager->RunLoadModuleStartupConfigTask(needRunAutoStartupTask, hapModuleInfo);
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
if (!needRunAutoStartupTask) {
|
||||
return ERR_OK;
|
||||
}
|
||||
jsRuntime_.UpdateModuleNameAndAssetPath(hapModuleInfo->moduleName);
|
||||
|
||||
const std::string &configEntry = startupManager->GetPendingConfigEntry();
|
||||
if (!LoadJsStartupConfig(configEntry)) {
|
||||
if (!LoadJsStartupConfig(configEntry, hapModuleInfo->moduleName, hapModuleInfo->moduleType)) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "load js appStartup config failed.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
const std::vector<StartupTaskInfo> &startupTaskInfos = startupManager->GetStartupTaskInfos();
|
||||
const std::vector<StartupTaskInfo> startupTaskInfos = startupManager->GetStartupTaskInfos(hapModuleInfo->name);
|
||||
for (const auto& item : startupTaskInfos) {
|
||||
std::unique_ptr<NativeReference> startupJsRef = LoadJsOhmUrl(
|
||||
item.srcEntry, item.ohmUrl, item.moduleName, item.hapPath, item.esModule);
|
||||
@@ -543,12 +548,15 @@ int32_t JsAbilityStage::RegisterAppStartupTask(const std::shared_ptr<AppExecFwk:
|
||||
jsStartupTask->SetIsExcludeFromAutoStart(item.excludeFromAutoStart);
|
||||
jsStartupTask->SetCallCreateOnMainThread(item.callCreateOnMainThread);
|
||||
jsStartupTask->SetWaitOnMainThread(item.waitOnMainThread);
|
||||
jsStartupTask->SetModuleName(hapModuleInfo->moduleName);
|
||||
jsStartupTask->SetModuleType(hapModuleInfo->moduleType);
|
||||
startupManager->RegisterAppStartupTask(item.name, jsStartupTask);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t JsAbilityStage::RunAutoStartupTaskInner(const std::function<void()> &callback, bool &isAsyncCallback)
|
||||
int32_t JsAbilityStage::RunAutoStartupTaskInner(const std::function<void()> &callback, bool &isAsyncCallback,
|
||||
const std::string &moduleName)
|
||||
{
|
||||
std::shared_ptr<StartupManager> startupManager = DelayedSingleton<StartupManager>::GetInstance();
|
||||
if (startupManager == nullptr) {
|
||||
@@ -556,10 +564,15 @@ int32_t JsAbilityStage::RunAutoStartupTaskInner(const std::function<void()> &cal
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
std::shared_ptr<StartupTaskManager> startupTaskManager = nullptr;
|
||||
int32_t result = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager);
|
||||
int32_t result = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager, moduleName);
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
if (startupTaskManager == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null startupTaskManager");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
startupTaskManager->UpdateStartupTaskContextRef(shellContextRef_);
|
||||
result = startupTaskManager->Prepare();
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
@@ -634,7 +647,8 @@ std::unique_ptr<NativeReference> JsAbilityStage::LoadJsSrcEntry(const std::strin
|
||||
return jsCode;
|
||||
}
|
||||
|
||||
bool JsAbilityStage::LoadJsStartupConfig(const std::string &srcEntry)
|
||||
bool JsAbilityStage::LoadJsStartupConfig(const std::string &srcEntry, const std::string &moduleName,
|
||||
AppExecFwk::ModuleType moduleType)
|
||||
{
|
||||
std::unique_ptr<NativeReference> startupConfigEntry = LoadJsSrcEntry(srcEntry);
|
||||
if (startupConfigEntry == nullptr) {
|
||||
@@ -655,7 +669,7 @@ bool JsAbilityStage::LoadJsStartupConfig(const std::string &srcEntry)
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "null startupManager");
|
||||
return false;
|
||||
}
|
||||
startupManager->SetDefaultConfig(startupConfig);
|
||||
startupManager->SetModuleConfig(startupConfig, moduleName, moduleType == AppExecFwk::ModuleType::ENTRY);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1526,7 +1526,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
}
|
||||
#endif
|
||||
|
||||
application_->PreloadAppStartup(bundleInfo, entryHapModuleInfo, appLaunchData.GetPreloadModuleName());
|
||||
application_->PreloadAppStartup(bundleInfo, appLaunchData.GetPreloadModuleName());
|
||||
|
||||
if (isStageBased) {
|
||||
// Create runtime
|
||||
|
||||
@@ -869,8 +869,7 @@ void OHOSApplication::CleanEmptyAbilityStage()
|
||||
}
|
||||
}
|
||||
|
||||
void OHOSApplication::PreloadAppStartup(const BundleInfo &bundleInfo,
|
||||
const HapModuleInfo &entryHapModuleInfo, const std::string &preloadModuleName)
|
||||
void OHOSApplication::PreloadAppStartup(const BundleInfo &bundleInfo, const std::string &preloadModuleName)
|
||||
{
|
||||
if (!IsMainProcess(bundleInfo.applicationInfo.name, bundleInfo.applicationInfo.process)) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "not main process");
|
||||
@@ -883,7 +882,16 @@ void OHOSApplication::PreloadAppStartup(const BundleInfo &bundleInfo,
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "failed to get startupManager");
|
||||
return;
|
||||
}
|
||||
startupManager->PreloadAppHintStartup(bundleInfo, entryHapModuleInfo, preloadModuleName);
|
||||
|
||||
AppExecFwk::HapModuleInfo preloadHapModuleInfo;
|
||||
if (!bundleInfo.hapModuleInfos.empty()) {
|
||||
for (const auto& hapModuleInfo : bundleInfo.hapModuleInfos) {
|
||||
if (hapModuleInfo.name == preloadModuleName) {
|
||||
startupManager->PreloadAppHintStartup(bundleInfo, hapModuleInfo, preloadModuleName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OHOSApplication::IsUpdateColorNeeded(Configuration &config, AbilityRuntime::SetLevel level)
|
||||
|
||||
@@ -32,5 +32,25 @@ void AppStartupTask::SetIsExcludeFromAutoStart(bool excludeFromAutoStart)
|
||||
{
|
||||
isExcludeFromAutoStart_ = excludeFromAutoStart;
|
||||
}
|
||||
|
||||
void AppStartupTask::SetModuleName(const std::string &moduleName)
|
||||
{
|
||||
moduleName_ = moduleName;
|
||||
}
|
||||
|
||||
const std::string& AppStartupTask::GetModuleName() const
|
||||
{
|
||||
return moduleName_;
|
||||
}
|
||||
|
||||
void AppStartupTask::SetModuleType(AppExecFwk::ModuleType moduleType)
|
||||
{
|
||||
moduleType_ = moduleType;
|
||||
}
|
||||
|
||||
AppExecFwk::ModuleType AppStartupTask::GetModuleType() const
|
||||
{
|
||||
return moduleType_;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -171,6 +171,11 @@ void JsStartupTask::OnAsyncTaskCompleted(const std::shared_ptr<StartupTaskResult
|
||||
startupTaskResultCallback_->Call(result);
|
||||
}
|
||||
|
||||
void JsStartupTask::UpdateContextRef(std::shared_ptr<NativeReference> &contextJsRef)
|
||||
{
|
||||
contextJsRef_ = contextJsRef;
|
||||
}
|
||||
|
||||
int32_t JsStartupTask::RunTaskOnDependencyCompleted(const std::string &dependencyName,
|
||||
const std::shared_ptr<StartupTaskResult> &result)
|
||||
{
|
||||
|
||||
@@ -73,23 +73,25 @@ StartupManager::StartupManager()
|
||||
StartupManager::~StartupManager() = default;
|
||||
|
||||
int32_t StartupManager::PreloadAppHintStartup(const AppExecFwk::BundleInfo& bundleInfo,
|
||||
const AppExecFwk::HapModuleInfo& entryInfo, const std::string &preloadModuleName)
|
||||
const AppExecFwk::HapModuleInfo& preloadHapModuleInfo, const std::string &preloadModuleName)
|
||||
{
|
||||
moduleStartupConfigInfos_.clear();
|
||||
if (entryInfo.appStartup.empty()) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "entry module no app startup config");
|
||||
if (preloadHapModuleInfo.appStartup.empty()) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "module no app startup config");
|
||||
return ERR_OK;
|
||||
}
|
||||
bundleName_ = bundleInfo.name;
|
||||
moduleStartupConfigInfos_.emplace_back(entryInfo.name, entryInfo.appStartup, entryInfo.hapPath,
|
||||
entryInfo.moduleType, entryInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
moduleStartupConfigInfos_.emplace_back(preloadHapModuleInfo.name, preloadHapModuleInfo.appStartup,
|
||||
preloadHapModuleInfo.hapPath, preloadHapModuleInfo.moduleType,
|
||||
preloadHapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
isModuleStartupConfigInited_.emplace(preloadHapModuleInfo.name);
|
||||
|
||||
for (const auto& module : bundleInfo.hapModuleInfos) {
|
||||
if (module.appStartup.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (module.moduleType != AppExecFwk::ModuleType::SHARED) {
|
||||
// ENTRY has been added and FEATURE is not supported.
|
||||
// ENTRY or FEATURE has been added.
|
||||
continue;
|
||||
}
|
||||
moduleStartupConfigInfos_.emplace_back(module.name, module.appStartup, module.hapPath, module.moduleType,
|
||||
@@ -101,9 +103,8 @@ int32_t StartupManager::PreloadAppHintStartup(const AppExecFwk::BundleInfo& bund
|
||||
return ERR_STARTUP_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
if (entryInfo.name != preloadModuleName) {
|
||||
// not entry module, no need to load app startup config and preload so now.
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "not entry module: %{public}s", preloadModuleName.c_str());
|
||||
if (preloadHapModuleInfo.name != preloadModuleName) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "preload module name: %{public}s", preloadModuleName.c_str());
|
||||
return ERR_OK;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "appStartup modules: %{public}zu", moduleStartupConfigInfos_.size());
|
||||
@@ -118,7 +119,8 @@ int32_t StartupManager::PreloadAppHintStartup(const AppExecFwk::BundleInfo& bund
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager)
|
||||
int32_t StartupManager::BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager,
|
||||
const std::string &moduleName)
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<StartupTask>> autoStartupTasks;
|
||||
std::set<std::string> dependenciesSet;
|
||||
@@ -127,6 +129,10 @@ int32_t StartupManager::BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTa
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "startup task null");
|
||||
return ERR_STARTUP_INTERNAL_ERROR;
|
||||
}
|
||||
if (iter.second->GetModuleName() != moduleName &&
|
||||
iter.second->GetModuleType() != AppExecFwk::ModuleType::SHARED) {
|
||||
continue;
|
||||
}
|
||||
if (iter.second->GetIsExcludeFromAutoStart()) {
|
||||
continue;
|
||||
}
|
||||
@@ -148,7 +154,7 @@ int32_t StartupManager::BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTa
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "autoStartupTasksManager build, id: %{public}u, tasks num: %{public}zu",
|
||||
startupTaskManagerId, autoStartupTasks.size());
|
||||
startupTaskManager = std::make_shared<StartupTaskManager>(startupTaskManagerId, autoStartupTasks);
|
||||
startupTaskManager->SetConfig(defaultConfig_);
|
||||
startupTaskManager->SetConfig(moduleConfigs_[moduleName]);
|
||||
startupTaskManagerMap_.emplace(startupTaskManagerId, startupTaskManager);
|
||||
startupTaskManagerId++;
|
||||
return ERR_OK;
|
||||
@@ -189,6 +195,10 @@ int32_t StartupManager::BuildAppStartupTaskManager(const std::vector<std::string
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "%{public}s startup task null", iter.c_str());
|
||||
return ERR_STARTUP_INTERNAL_ERROR;
|
||||
}
|
||||
if (findResult->second->GetModuleType() == AppExecFwk::ModuleType::FEATURE) {
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "manual task of feature type is not supported");
|
||||
return ERR_STARTUP_DEPENDENCY_NOT_FOUND;
|
||||
}
|
||||
currentStartupTasks.emplace(iter, findResult->second);
|
||||
auto dependencies = findResult->second->GetDependencies();
|
||||
for (auto &dep : dependencies) {
|
||||
@@ -230,6 +240,15 @@ int32_t StartupManager::OnStartupTaskManagerComplete(uint32_t id)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void StartupManager::SetModuleConfig(const std::shared_ptr<StartupConfig> &config, const std::string &moduleName,
|
||||
bool isDefaultConfig = false)
|
||||
{
|
||||
moduleConfigs_[moduleName] = config;
|
||||
if (isDefaultConfig) {
|
||||
defaultConfig_ = config;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupManager::SetDefaultConfig(const std::shared_ptr<StartupConfig> &config)
|
||||
{
|
||||
defaultConfig_ = config;
|
||||
@@ -332,9 +351,19 @@ bool StartupManager::HasAppStartupConfig() const
|
||||
return !moduleStartupConfigInfos_.empty();
|
||||
}
|
||||
|
||||
const std::vector<StartupTaskInfo> &StartupManager::GetStartupTaskInfos() const
|
||||
const std::vector<StartupTaskInfo> StartupManager::GetStartupTaskInfos(const std::string &name)
|
||||
{
|
||||
return pendingStartupTaskInfos_;
|
||||
if (!isAppStartupTaskRegistered_) {
|
||||
isAppStartupTaskRegistered_ = true;
|
||||
return pendingStartupTaskInfos_;
|
||||
}
|
||||
std::vector<StartupTaskInfo> pendingStartupTaskInfos;
|
||||
for (const auto &iter : pendingStartupTaskInfos_) {
|
||||
if (iter.moduleName == name) {
|
||||
pendingStartupTaskInfos.emplace_back(iter);
|
||||
}
|
||||
}
|
||||
return pendingStartupTaskInfos;
|
||||
}
|
||||
|
||||
const std::string &StartupManager::GetPendingConfigEntry() const
|
||||
@@ -393,6 +422,11 @@ int32_t StartupManager::RegisterPreloadSoStartupTask(
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void StartupManager::ClearAppStartupTask()
|
||||
{
|
||||
appStartupTasks_.clear();
|
||||
}
|
||||
|
||||
int32_t StartupManager::RegisterAppStartupTask(
|
||||
const std::string &name, const std::shared_ptr<AppStartupTask> &startupTask)
|
||||
{
|
||||
@@ -401,7 +435,6 @@ int32_t StartupManager::RegisterAppStartupTask(
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "exist preload so startup task %{public}s", name.c_str());
|
||||
return ERR_STARTUP_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto result = appStartupTasks_.emplace(name, startupTask);
|
||||
if (!result.second) {
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "exist app startup task %{public}s", name.c_str());
|
||||
@@ -549,6 +582,48 @@ int32_t StartupManager::AddLoadAppStartupConfigTask(
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::RunLoadModuleStartupConfigTask(
|
||||
bool &needRunAutoStartupTask, const std::shared_ptr<AppExecFwk::HapModuleInfo>& hapModuleInfo)
|
||||
{
|
||||
if (isModuleStartupConfigInited_.count(hapModuleInfo->name) != 0) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "module startup config already loaded");
|
||||
return ERR_OK;
|
||||
}
|
||||
ModuleStartupConfigInfo configInfo(hapModuleInfo->name, hapModuleInfo->appStartup, hapModuleInfo->hapPath,
|
||||
hapModuleInfo->moduleType, hapModuleInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
if (hapModuleInfo->appStartup.empty()) {
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "module startup config is empty");
|
||||
return ERR_OK;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::STARTUP, "load module %{public}s, type: %{public}d", hapModuleInfo->name.c_str(),
|
||||
hapModuleInfo->moduleType);
|
||||
std::string configStr;
|
||||
int32_t result = GetStartupConfigString(configInfo, configStr);
|
||||
if (result != ERR_OK) {
|
||||
return result;
|
||||
}
|
||||
std::map<std::string, std::shared_ptr<AppStartupTask>> preloadSoStartupTasks;
|
||||
std::vector<StartupTaskInfo> pendingStartupTaskInfos;
|
||||
std::string pendingConfigEntry;
|
||||
bool success = AnalyzeStartupConfig(configInfo, configStr,
|
||||
preloadSoStartupTasks_, pendingStartupTaskInfos_, pendingConfigEntry);
|
||||
if (!success) {
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "failed to parse app startup module %{public}s, type: %{public}d",
|
||||
configInfo.name_.c_str(), configInfo.moduleType_);
|
||||
return ERR_STARTUP_CONFIG_PARSE_ERROR;
|
||||
}
|
||||
std::lock_guard guard(appStartupConfigInitializationMutex_);
|
||||
preloadSoStartupTasks_.insert(preloadSoStartupTasks.begin(), preloadSoStartupTasks.end());
|
||||
pendingStartupTaskInfos_.insert(pendingStartupTaskInfos_.end(), pendingStartupTaskInfos.begin(),
|
||||
pendingStartupTaskInfos.end());
|
||||
pendingConfigEntry_ = pendingConfigEntry;
|
||||
isModuleStartupConfigInited_.emplace(hapModuleInfo->name);
|
||||
if (!needRunAutoStartupTask && pendingConfigEntry.size() > 0) {
|
||||
needRunAutoStartupTask = true;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::RunLoadAppStartupConfigTask()
|
||||
{
|
||||
if (isAppStartupConfigInited_) {
|
||||
@@ -814,7 +889,7 @@ bool StartupManager::AnalyzeStartupConfig(const ModuleStartupConfigInfo& info, c
|
||||
return false;
|
||||
}
|
||||
|
||||
if (info.moduleType_ == AppExecFwk::ModuleType::ENTRY) {
|
||||
if (info.moduleType_ == AppExecFwk::ModuleType::ENTRY || info.moduleType_ == AppExecFwk::ModuleType::FEATURE) {
|
||||
if (!(startupConfigJson.contains(CONFIG_ENTRY) && startupConfigJson[CONFIG_ENTRY].is_string())) {
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "no config entry.");
|
||||
return false;
|
||||
@@ -958,7 +1033,7 @@ void StartupManager::SetOptionalParameters(const nlohmann::json& module, AppExec
|
||||
startupTaskInfo.ohmUrl = module.at(OHMURL).get<std::string>();
|
||||
}
|
||||
|
||||
if (moduleType != AppExecFwk::ModuleType::ENTRY) {
|
||||
if (moduleType != AppExecFwk::ModuleType::ENTRY && moduleType != AppExecFwk::ModuleType::FEATURE) {
|
||||
startupTaskInfo.excludeFromAutoStart = true;
|
||||
return;
|
||||
}
|
||||
@@ -982,7 +1057,7 @@ void StartupManager::SetOptionalParameters(const nlohmann::json &module, AppExec
|
||||
task->SetDependencies(dependencies);
|
||||
}
|
||||
|
||||
if (moduleType != AppExecFwk::ModuleType::ENTRY) {
|
||||
if (moduleType != AppExecFwk::ModuleType::ENTRY && moduleType != AppExecFwk::ModuleType::FEATURE) {
|
||||
task->SetIsExcludeFromAutoStart(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "startup_task_manager.h"
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "js_startup_task.h"
|
||||
#include "startup_manager.h"
|
||||
#include "startup_topologysort.h"
|
||||
|
||||
@@ -181,5 +182,25 @@ void StartupTaskManager::OnTimeout()
|
||||
CallListenerOnCompleted(ERR_STARTUP_TIMEOUT, StartupUtils::GetErrorMessage(ERR_STARTUP_TIMEOUT));
|
||||
DelayedSingleton<StartupManager>::GetInstance()->OnStartupTaskManagerComplete(startupTaskManagerId_);
|
||||
}
|
||||
|
||||
void StartupTaskManager::UpdateStartupTaskContextRef(std::shared_ptr<NativeReference> &contextJsRef)
|
||||
{
|
||||
for (auto& iter : tasks_) {
|
||||
if (iter.second == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (iter.second->GetType() != JsStartupTask::TASK_TYPE) {
|
||||
continue;
|
||||
}
|
||||
std::shared_ptr<JsStartupTask> jsStartupTask = std::static_pointer_cast<JsStartupTask>(iter.second);
|
||||
if (jsStartupTask == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::STARTUP, "null jsStartupTask: %{public}s", iter.first.c_str());
|
||||
continue;
|
||||
}
|
||||
if (jsStartupTask->GetModuleType() == AppExecFwk::ModuleType::SHARED) {
|
||||
jsStartupTask->UpdateContextRef(contextJsRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -77,7 +77,8 @@ private:
|
||||
|
||||
std::unique_ptr<NativeReference> LoadJsSrcEntry(const std::string &srcEntry);
|
||||
|
||||
bool LoadJsStartupConfig(const std::string &srcEntry);
|
||||
bool LoadJsStartupConfig(const std::string &srcEntry, const std::string &moduleName,
|
||||
AppExecFwk::ModuleType moduleType);
|
||||
|
||||
bool CallOnPrepareTerminate(napi_env env,
|
||||
AppExecFwk::AbilityTransactionCallbackInfo<AppExecFwk::OnPrepareTerminationResult> *callbackInfo) const;
|
||||
@@ -88,7 +89,8 @@ private:
|
||||
|
||||
int32_t RegisterAppStartupTask(const std::shared_ptr<AppExecFwk::HapModuleInfo>& hapModuleInfo);
|
||||
|
||||
static int32_t RunAutoStartupTaskInner(const std::function<void()> &callback, bool &isAsyncCallback);
|
||||
int32_t RunAutoStartupTaskInner(const std::function<void()> &callback, bool &isAsyncCallback,
|
||||
const std::string &moduleName);
|
||||
|
||||
void SetJsAbilityStage(const std::shared_ptr<Context> &context);
|
||||
|
||||
|
||||
@@ -230,8 +230,7 @@ public:
|
||||
bool GetDisplayConfig(uint64_t displayId, float &density, std::string &directionStr);
|
||||
#endif
|
||||
|
||||
void PreloadAppStartup(const BundleInfo &bundleInfo, const HapModuleInfo &entryHapModuleInfo,
|
||||
const std::string &preloadModuleName);
|
||||
void PreloadAppStartup(const BundleInfo &bundleInfo, const std::string &preloadModuleName);
|
||||
|
||||
private:
|
||||
void UpdateAppContextResMgr(const Configuration &config);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "bundle_info.h"
|
||||
#include "startup_task.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -32,8 +33,18 @@ public:
|
||||
|
||||
void SetIsExcludeFromAutoStart(bool excludeFromAutoStart);
|
||||
|
||||
void SetModuleName(const std::string &moduleName);
|
||||
|
||||
const std::string& GetModuleName() const;
|
||||
|
||||
void SetModuleType(AppExecFwk::ModuleType moduleType);
|
||||
|
||||
AppExecFwk::ModuleType GetModuleType() const;
|
||||
|
||||
protected:
|
||||
bool isExcludeFromAutoStart_ = false;
|
||||
std::string moduleName_;
|
||||
AppExecFwk::ModuleType moduleType_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
|
||||
void OnAsyncTaskCompleted(const std::shared_ptr<StartupTaskResult> &result);
|
||||
|
||||
void UpdateContextRef(std::shared_ptr<NativeReference> &contextJsRef);
|
||||
|
||||
private:
|
||||
JsRuntime &jsRuntime_;
|
||||
std::unique_ptr<NativeReference> startupJsRef_;
|
||||
|
||||
@@ -65,20 +65,29 @@ public:
|
||||
|
||||
int32_t LoadAppStartupTaskConfig(bool &needRunAutoStartupTask);
|
||||
|
||||
const std::vector<StartupTaskInfo> &GetStartupTaskInfos() const;
|
||||
const std::vector<StartupTaskInfo> GetStartupTaskInfos(const std::string &name);
|
||||
|
||||
const std::string &GetPendingConfigEntry() const;
|
||||
|
||||
void ClearAppStartupTask();
|
||||
|
||||
int32_t RegisterAppStartupTask(
|
||||
const std::string &name, const std::shared_ptr<AppStartupTask> &startupTask);
|
||||
|
||||
int32_t BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager);
|
||||
int32_t BuildAutoAppStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager,
|
||||
const std::string &moduleName);
|
||||
|
||||
int32_t BuildAppStartupTaskManager(const std::vector<std::string> &inputDependencies,
|
||||
std::shared_ptr<StartupTaskManager> &startupTaskManager);
|
||||
|
||||
int32_t OnStartupTaskManagerComplete(uint32_t id);
|
||||
|
||||
int32_t RunLoadModuleStartupConfigTask(
|
||||
bool &needRunAutoStartupTask, const std::shared_ptr<AppExecFwk::HapModuleInfo>& hapModuleInfo);
|
||||
|
||||
void SetModuleConfig(const std::shared_ptr<StartupConfig> &config, const std::string &moduleName,
|
||||
bool isDefaultConfig);
|
||||
|
||||
void SetDefaultConfig(const std::shared_ptr<StartupConfig> &config);
|
||||
|
||||
const std::shared_ptr<StartupConfig>& GetDefaultConfig() const;
|
||||
@@ -104,6 +113,8 @@ private:
|
||||
|
||||
std::mutex appStartupConfigInitializationMutex_;
|
||||
std::atomic<bool> isAppStartupConfigInited_ = false;
|
||||
std::atomic<bool> isAppStartupTaskRegistered_ = false;
|
||||
std::set<std::string> isModuleStartupConfigInited_;
|
||||
|
||||
std::mutex startupTaskManagerMutex_;
|
||||
uint32_t startupTaskManagerId = 0;
|
||||
@@ -120,6 +131,7 @@ private:
|
||||
bool autoPreloadSoStopped_ = false;
|
||||
|
||||
std::shared_ptr<StartupConfig> defaultConfig_;
|
||||
std::map<std::string, std::shared_ptr<StartupConfig>> moduleConfigs_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> mainHandler_;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> preloadHandler_;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "event_handler.h"
|
||||
#include "js_runtime.h"
|
||||
#include "startup_config.h"
|
||||
#include "startup_task.h"
|
||||
#include "startup_task_dispatcher.h"
|
||||
@@ -49,6 +50,8 @@ public:
|
||||
|
||||
void OnTimeout();
|
||||
|
||||
void UpdateStartupTaskContextRef(std::shared_ptr<NativeReference> &contextJsRef);
|
||||
|
||||
private:
|
||||
uint32_t startupTaskManagerId_ = 0;
|
||||
std::shared_ptr<StartupConfig> config_;
|
||||
|
||||
@@ -109,7 +109,7 @@ HWTEST_F(StartupManagerTest, BuildAutoAppStartupTaskManager_0100, Function | Med
|
||||
std::make_shared<StartupTaskManager>(startupTaskManagerId, autoStartupTasks);
|
||||
EXPECT_TRUE(startupTaskManager != nullptr);
|
||||
startupManager->appStartupTasks_.emplace(name, nullptr);
|
||||
int32_t ret = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager);
|
||||
int32_t ret = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager, "");
|
||||
EXPECT_EQ(ret, ERR_STARTUP_INTERNAL_ERROR);
|
||||
startupManager->appStartupTasks_.clear();
|
||||
startupManager->appStartupTasks_.emplace(name, startupTask);
|
||||
@@ -117,7 +117,7 @@ HWTEST_F(StartupManagerTest, BuildAutoAppStartupTaskManager_0100, Function | Med
|
||||
dependencies.emplace_back(name1);
|
||||
startupTask1->SetDependencies(dependencies);
|
||||
startupManager->appStartupTasks_.emplace(name1, startupTask1);
|
||||
ret = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager);
|
||||
ret = startupManager->BuildAutoAppStartupTaskManager(startupTaskManager, "");
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
GTEST_LOG_(INFO) << "StartupManagerTest BuildAutoAppStartupTaskManager_0100 end";
|
||||
}
|
||||
@@ -981,6 +981,44 @@ HWTEST_F(StartupManagerTest, AnalyzePreloadSoStartupTaskInner_0200, Function | M
|
||||
GTEST_LOG_(INFO) << "StartupManagerTest AnalyzePreloadSoStartupTaskInner_0200 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetModuleConfig_0100
|
||||
* @tc.type: FUNC
|
||||
* @tc.Function: GetModuleConfig
|
||||
*/
|
||||
HWTEST_F(StartupManagerTest, GetModuleConfig_0100, Function | MediumTest | Level1)
|
||||
{
|
||||
std::shared_ptr<StartupManager> startupManager = DelayedSingleton<StartupManager>::GetInstance();
|
||||
EXPECT_TRUE(startupManager != nullptr);
|
||||
std::string name = "test_name";
|
||||
std::shared_ptr<PreloadSoStartupTask> appStartupTask = std::make_shared<PreloadSoStartupTask>(name, "duri");
|
||||
startupManager->appStartupTasks_.emplace(name, appStartupTask);
|
||||
std::string moduleName = "application";
|
||||
startupManager->SetModuleConfig(nullptr, moduleName, false);
|
||||
EXPECT_EQ(startupManager->moduleConfigs_[moduleName], nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RunLoadModuleStartupConfigTask_0100
|
||||
* @tc.type: FUNC
|
||||
* @tc.Function: RunLoadModuleStartupConfigTask
|
||||
*/
|
||||
HWTEST_F(StartupManagerTest, RunLoadModuleStartupConfigTask_0100, Function | MediumTest | Level1)
|
||||
{
|
||||
std::shared_ptr<StartupManager> startupManager = DelayedSingleton<StartupManager>::GetInstance();
|
||||
EXPECT_TRUE(startupManager != nullptr);
|
||||
std::string name = "test_name";
|
||||
std::shared_ptr<PreloadSoStartupTask> appStartupTask = std::make_shared<PreloadSoStartupTask>(name, "duri");
|
||||
startupManager->appStartupTasks_.emplace(name, appStartupTask);
|
||||
std::string moduleName = "application";
|
||||
bool needRunAutoStartupTask = false;
|
||||
std::shared_ptr<AppExecFwk::HapModuleInfo> hapModuleInfo = std::make_shared<AppExecFwk::HapModuleInfo>();
|
||||
hapModuleInfo->name = moduleName;
|
||||
startupManager->isModuleStartupConfigInited_.emplace(moduleName);
|
||||
int32_t result = startupManager->RunLoadModuleStartupConfigTask(needRunAutoStartupTask, hapModuleInfo);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetStartupConfigString_0200
|
||||
* @tc.type: FUNC
|
||||
|
||||
Reference in New Issue
Block a user