mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
Description: 支持启动框架2
IssueNo: #I9BEJF Sig: SIG_ApplicationFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: yangzk <yangzhongkai@huawei.com> Change-Id: I5f467c895391232b28160ec27bb67c32c3896522
This commit is contained in:
@@ -43,7 +43,9 @@ group("napi_packages") {
|
||||
"${ability_runtime_napi_path}/app/js_app_manager:appmanager",
|
||||
"${ability_runtime_napi_path}/app/recovery:apprecovery_napi",
|
||||
"${ability_runtime_napi_path}/app/test_runner:testrunner_napi",
|
||||
"${ability_runtime_napi_path}/app_startup/startup_task_executor:startuptaskexecutor_napi",
|
||||
"${ability_runtime_napi_path}/app_startup/startup_config_entry:startupconfigentry_napi",
|
||||
"${ability_runtime_napi_path}/app_startup/startup_listener:startuplistener_napi",
|
||||
"${ability_runtime_napi_path}/app_startup/startup_task:startuptask_napi",
|
||||
"${ability_runtime_napi_path}/application_context_constant:contextconstant_napi",
|
||||
"${ability_runtime_napi_path}/auto_fill_extension_ability:autofillextensionability_napi",
|
||||
"${ability_runtime_napi_path}/auto_fill_extension_context:autofillextensioncontext_napi",
|
||||
|
||||
+19
-18
@@ -14,47 +14,48 @@
|
||||
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_startup_task_executor_abc") {
|
||||
src_js = rebase_path("startup_task_executor.js")
|
||||
dst_file = rebase_path(target_out_dir + "/startup_task_executor.abc")
|
||||
in_puts = [ "startup_task_executor.js" ]
|
||||
out_puts = [ target_out_dir + "/startup_task_executor.abc" ]
|
||||
es2abc_gen_abc("gen_startup_config_entry_abc") {
|
||||
src_js = rebase_path("startup_config_entry.js")
|
||||
dst_file = rebase_path(target_out_dir + "/startup_config_entry.abc")
|
||||
in_puts = [ "startup_config_entry.js" ]
|
||||
out_puts = [ target_out_dir + "/startup_config_entry.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("startup_task_executor_js") {
|
||||
input = "startup_task_executor.js"
|
||||
output = target_out_dir + "/startup_task_executor.o"
|
||||
gen_js_obj("startup_config_entry_js") {
|
||||
input = "startup_config_entry.js"
|
||||
output = target_out_dir + "/startup_config_entry.o"
|
||||
}
|
||||
|
||||
gen_js_obj("startup_task_executor_abc") {
|
||||
input = get_label_info(":gen_startup_task_executor_abc", "target_out_dir") +
|
||||
"/startup_task_executor.abc"
|
||||
output = target_out_dir + "/startup_task_executor_abc.o"
|
||||
dep = ":gen_startup_task_executor_abc"
|
||||
gen_js_obj("startup_config_entry_abc") {
|
||||
input = get_label_info(":gen_startup_config_entry_abc", "target_out_dir") +
|
||||
"/startup_config_entry.abc"
|
||||
output = target_out_dir + "/startup_config_entry_abc.o"
|
||||
dep = ":gen_startup_config_entry_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("startuptaskexecutor_napi") {
|
||||
ohos_shared_library("startupconfigentry_napi") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [ "startup_task_executor_module.cpp" ]
|
||||
sources = [ "startup_config_entry_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":startup_task_executor_abc",
|
||||
":startup_task_executor_js",
|
||||
":startup_config_entry_abc",
|
||||
":startup_config_entry_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
relative_install_dir = "module/app/appstartup"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
+6
-5
@@ -13,9 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "startup_task_executor.h"
|
||||
class StartupConfigEntry {
|
||||
onConfig() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
export default StartupConfigEntry;
|
||||
+13
-14
@@ -15,42 +15,41 @@
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_startup_task_executor_js_start[];
|
||||
extern const char _binary_startup_task_executor_js_end[];
|
||||
extern const char _binary_startup_task_executor_abc_start[];
|
||||
extern const char _binary_startup_task_executor_abc_end[];
|
||||
extern const char _binary_startup_config_entry_js_start[];
|
||||
extern const char _binary_startup_config_entry_js_end[];
|
||||
extern const char _binary_startup_config_entry_abc_start[];
|
||||
extern const char _binary_startup_config_entry_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "application/libstartuptaskexecutor_napi.so/startup_task_executor.js",
|
||||
.nm_modname = "application.StartupTaskExecutor",
|
||||
.nm_filename = "app/appstartup/libstartupconfigentry_napi.so/startup_config_entry.js",
|
||||
.nm_modname = "app.appstartup.StartupConfigEntry",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_StartupTaskExecutor_AutoRegister()
|
||||
void NAPI_app_appstartup_StartupConfigEntry_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StartupTaskExecutor_GetJSCode(const char **buf, int *bufLen)
|
||||
void NAPI_app_appstartup_StartupConfigEntry_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_task_executor_js_start;
|
||||
*buf = _binary_startup_config_entry_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_startup_task_executor_js_end - _binary_startup_task_executor_js_start;
|
||||
*bufLen = _binary_startup_config_entry_js_end - _binary_startup_config_entry_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// startup_task_executor JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_StartupTaskExecutor_GetABCCode(const char **buf, int *buflen)
|
||||
void NAPI_app_appstartup_StartupConfigEntry_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_task_executor_abc_start;
|
||||
*buf = _binary_startup_config_entry_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_startup_task_executor_abc_end - _binary_startup_task_executor_abc_start;
|
||||
*buflen = _binary_startup_config_entry_abc_end - _binary_startup_config_entry_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_startup_listener_abc") {
|
||||
src_js = rebase_path("startup_listener.js")
|
||||
dst_file = rebase_path(target_out_dir + "/startup_listener.abc")
|
||||
in_puts = [ "startup_listener.js" ]
|
||||
out_puts = [ target_out_dir + "/startup_listener.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("startup_listener_js") {
|
||||
input = "startup_listener.js"
|
||||
output = target_out_dir + "/startup_listener.o"
|
||||
}
|
||||
|
||||
gen_js_obj("startup_listener_abc") {
|
||||
input = get_label_info(":gen_startup_listener_abc", "target_out_dir") +
|
||||
"/startup_listener.abc"
|
||||
output = target_out_dir + "/startup_listener_abc.o"
|
||||
dep = ":gen_startup_listener_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("startuplistener_napi") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [ "startup_listener_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":startup_listener_abc",
|
||||
":startup_listener_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/app/appstartup"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
+3
-5
@@ -13,11 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
class StartupTaskExecutor {
|
||||
runOnMainThread(message) {
|
||||
console.log('StartupTaskExecutor, message ' + message);
|
||||
class StartupListener {
|
||||
onCompleted(error) {
|
||||
}
|
||||
}
|
||||
|
||||
export default StartupTaskExecutor;
|
||||
export default StartupListener;
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_startup_listener_js_start[];
|
||||
extern const char _binary_startup_listener_js_end[];
|
||||
extern const char _binary_startup_listener_abc_start[];
|
||||
extern const char _binary_startup_listener_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "app/appstartup/libstartuplistener_napi.so/startup_listener.js",
|
||||
.nm_modname = "app.appstartup.StartupListener",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_app_appstartup_StartupListener_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_app_appstartup_StartupListener_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_listener_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_startup_listener_js_end - _binary_startup_listener_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_app_appstartup_StartupListener_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_listener_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_startup_listener_abc_end - _binary_startup_listener_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
es2abc_gen_abc("gen_startup_task_abc") {
|
||||
src_js = rebase_path("startup_task.js")
|
||||
dst_file = rebase_path(target_out_dir + "/startup_task.abc")
|
||||
in_puts = [ "startup_task.js" ]
|
||||
out_puts = [ target_out_dir + "/startup_task.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("startup_task_js") {
|
||||
input = "startup_task.js"
|
||||
output = target_out_dir + "/startup_task.o"
|
||||
}
|
||||
|
||||
gen_js_obj("startup_task_abc") {
|
||||
input = get_label_info(":gen_startup_task_abc", "target_out_dir") +
|
||||
"/startup_task.abc"
|
||||
output = target_out_dir + "/startup_task_abc.o"
|
||||
dep = ":gen_startup_task_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("startuptask_napi") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sources = [ "startup_task_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":startup_task_abc",
|
||||
":startup_task_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/app/appstartup"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
+9
-10
@@ -13,15 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_STARTUP_TASK_EXECUTOR_H
|
||||
#define OHOS_ABILITY_RUNTIME_STARTUP_TASK_EXECUTOR_H
|
||||
class StartupTask {
|
||||
onDependenceCompleted(dependence, result) {
|
||||
console.log('onDependenceCompleted');
|
||||
}
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
isManualDispatch() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class StartupTaskExecutor {
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_STARTUP_TASK_EXECUTOR_H
|
||||
export default StartupTask;
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_startup_task_js_start[];
|
||||
extern const char _binary_startup_task_js_end[];
|
||||
extern const char _binary_startup_task_abc_start[];
|
||||
extern const char _binary_startup_task_abc_end[];
|
||||
|
||||
static napi_module _module = {
|
||||
.nm_version = 0,
|
||||
.nm_filename = "app/appstartup/libstartuptask_napi.so/startup_task.js",
|
||||
.nm_modname = "app.appstartup.StartupTask",
|
||||
};
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_app_appstartup_StartupTask_AutoRegister()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_app_appstartup_StartupTask_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_task_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_startup_task_js_end - _binary_startup_task_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_app_appstartup_StartupTask_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_startup_task_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_startup_task_abc_end - _binary_startup_task_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@ config("appkit_public_config") {
|
||||
ohos_shared_library("appkit_native") {
|
||||
include_dirs = [
|
||||
"native",
|
||||
"${ability_runtime_path}/interfaces/inner_api/error_utils/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
@@ -141,14 +142,14 @@ ohos_shared_library("appkit_native") {
|
||||
"${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/js_startup_task.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/js_startup_task_executor.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/js_startup_task_main_thread_executor.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/js_startup_task_result.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_config.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_listener.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_manager.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_task.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_task_dispatcher.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_task_executor.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_task_manager.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app_startup/startup_task_result.cpp",
|
||||
"${ability_runtime_native_path}/appkit/dfr/appfreeze_inner.cpp",
|
||||
"${ability_runtime_native_path}/appkit/dfr/appfreeze_state.cpp",
|
||||
"${ability_runtime_native_path}/appkit/dfr/watchdog.cpp",
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
#include "js_startup_task.h"
|
||||
|
||||
#include "ability_runtime_error_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_startup_task_main_thread_executor.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@@ -29,15 +29,28 @@ JsStartupTask::~JsStartupTask() = default;
|
||||
int32_t JsStartupTask::Init()
|
||||
{
|
||||
// init dependencies_, isManualDispatch_, callCreateOnMainThread_, waitOnMainThread_, isAutoStartup_
|
||||
HILOG_DEBUG("%{public}s, dump: %{public}d%{public}d%{public}d%{public}d, dep: %{public}s", name_.c_str(),
|
||||
isManualDispatch_, callCreateOnMainThread_, waitOnMainThread_, isAutoStartup_, DumpDependencies().c_str());
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t JsStartupTask::RunTaskInit()
|
||||
int32_t JsStartupTask::RunTaskInit(std::unique_ptr<StartupTaskResultCallback> callback)
|
||||
{
|
||||
HILOG_DEBUG("run startup task: %{public}s", name_.c_str());
|
||||
executor_ = std::make_shared<JsStartupTaskMainThreadExecutor>();
|
||||
executor_->Run(jsRuntime_);
|
||||
return ERR_OK;
|
||||
if (state_ != State::CREATED) {
|
||||
HILOG_ERROR("%{public}s, state is wrong %{public}d", name_.c_str(), static_cast<int32_t>(state_));
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR;
|
||||
}
|
||||
state_ = State::INITIALIZING;
|
||||
callback->Push([weak = weak_from_this()](const std::shared_ptr<StartupTaskResult> &result) {
|
||||
auto startupTask = weak.lock();
|
||||
if (startupTask == nullptr) {
|
||||
HILOG_ERROR("startupTask is nullptr.");
|
||||
return;
|
||||
}
|
||||
startupTask->SaveResult(result);
|
||||
});
|
||||
HILOG_DEBUG("%{public}s, RunOnMainThread", name_.c_str());
|
||||
return JsStartupTaskExecutor::RunOnMainThread(jsRuntime_, startupJsRef_, contextJsRef_, std::move(callback));
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -15,10 +15,161 @@
|
||||
|
||||
#include "js_startup_task_executor.h"
|
||||
|
||||
#include "ability_runtime_error_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_startup_task_result.h"
|
||||
|
||||
#define TMP_NAPI_ANONYMOUS_FUNC "_"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
JsStartupTaskExecutor::JsStartupTaskExecutor() = default;
|
||||
int32_t JsStartupTaskExecutor::RunOnMainThread(JsRuntime &jsRuntime,
|
||||
const std::shared_ptr<NativeReference> &startup, const std::shared_ptr<NativeReference> &context,
|
||||
std::unique_ptr<StartupTaskResultCallback> callback)
|
||||
{
|
||||
HandleScope handleScope(jsRuntime);
|
||||
auto env = jsRuntime.GetNapiEnv();
|
||||
|
||||
JsStartupTaskExecutor::~JsStartupTaskExecutor() = default;
|
||||
napi_value returnVal = nullptr;
|
||||
int32_t resultCode = CallStartupInit(env, startup, context, callback, returnVal);
|
||||
if (resultCode != ERR_OK) {
|
||||
return resultCode;
|
||||
}
|
||||
return HandleReturnVal(env, returnVal, callback);
|
||||
}
|
||||
|
||||
int32_t JsStartupTaskExecutor::RunOnTaskPool(JsRuntime &jsRuntime,
|
||||
const std::shared_ptr<NativeReference> &startup, const std::shared_ptr<NativeReference> &context,
|
||||
std::unique_ptr<StartupTaskResultCallback> callback)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t JsStartupTaskExecutor::CallStartupInit(napi_env env, const std::shared_ptr<NativeReference> &startup,
|
||||
const std::shared_ptr<NativeReference> &context, std::unique_ptr<StartupTaskResultCallback> &callback,
|
||||
napi_value &returnVal)
|
||||
{
|
||||
if (startup == nullptr || context == nullptr) {
|
||||
ReplyFailed(std::move(callback), ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR,
|
||||
"startup task is null or context is null.");
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR;
|
||||
}
|
||||
napi_value startupValue = startup->GetNapiValue();
|
||||
if (!CheckTypeForNapiValue(env, startupValue, napi_object)) {
|
||||
ReplyFailed(std::move(callback), ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR,
|
||||
"startup task is not napi object.");
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR;
|
||||
}
|
||||
napi_value startupInit = nullptr;
|
||||
napi_get_named_property(env, startupValue, "init", &startupInit);
|
||||
if (startupInit == nullptr) {
|
||||
ReplyFailed(std::move(callback), ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP,
|
||||
"failed to get property init from startup task.");
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP;
|
||||
}
|
||||
bool isCallable = false;
|
||||
napi_is_callable(env, startupInit, &isCallable);
|
||||
if (!isCallable) {
|
||||
ReplyFailed(std::move(callback), ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP,
|
||||
"startup task init is not callable.");
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP;
|
||||
}
|
||||
napi_value argv[1] = { context->GetNapiValue() };
|
||||
napi_call_function(env, startupValue, startupInit, 1, argv, &returnVal);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t JsStartupTaskExecutor::HandleReturnVal(napi_env env, napi_value returnVal,
|
||||
std::unique_ptr<StartupTaskResultCallback> &callback)
|
||||
{
|
||||
bool isPromise = false;
|
||||
napi_is_promise(env, returnVal, &isPromise);
|
||||
if (!isPromise) {
|
||||
ReplyFailed(std::move(callback), ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP,
|
||||
"the return value of startup task init is not promise.");
|
||||
return ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP;
|
||||
}
|
||||
|
||||
auto *callbackPtr = callback.release();
|
||||
napi_value promiseThen = nullptr;
|
||||
napi_get_named_property(env, returnVal, "then", &promiseThen);
|
||||
napi_value promiseResolveCallback = nullptr;
|
||||
napi_create_function(env, TMP_NAPI_ANONYMOUS_FUNC, strlen(TMP_NAPI_ANONYMOUS_FUNC),
|
||||
ResolveResultCallback, callbackPtr, &promiseResolveCallback);
|
||||
napi_value argvThen[1] = { promiseResolveCallback };
|
||||
napi_call_function(env, returnVal, promiseThen, 1, argvThen, nullptr);
|
||||
|
||||
napi_value promiseCatch = nullptr;
|
||||
napi_get_named_property(env, returnVal, "catch", &promiseCatch);
|
||||
napi_value promiseRejectCallback = nullptr;
|
||||
napi_create_function(env, TMP_NAPI_ANONYMOUS_FUNC, strlen(TMP_NAPI_ANONYMOUS_FUNC),
|
||||
RejectResultCallback, callbackPtr, &promiseRejectCallback);
|
||||
napi_value argvCatch[1] = { promiseRejectCallback };
|
||||
napi_call_function(env, returnVal, promiseCatch, 1, argvCatch, nullptr);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
napi_value JsStartupTaskExecutor::ResolveResultCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("enter");
|
||||
size_t argc = 1;
|
||||
napi_value argv[1] = { nullptr };
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, argv, nullptr, &data);
|
||||
auto *callback = static_cast<StartupTaskResultCallback *>(data);
|
||||
napi_value resultJs = argv[0];
|
||||
napi_ref resultRef = nullptr;
|
||||
napi_create_reference(env, resultJs, 1, &resultRef);
|
||||
std::shared_ptr<NativeReference> result(reinterpret_cast<NativeReference*>(resultRef));
|
||||
ReplySucceeded(callback, result);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value JsStartupTaskExecutor::RejectResultCallback(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("enter");
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data);
|
||||
auto *callback = static_cast<StartupTaskResultCallback *>(data);
|
||||
ReplyFailed(callback, ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP,
|
||||
"the promise of startup task init is reject.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void JsStartupTaskExecutor::ReplyFailed(StartupTaskResultCallback *callback,
|
||||
int32_t resultCode, const std::string &resultMessage)
|
||||
{
|
||||
HILOG_DEBUG("enter");
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<StartupTaskResult> result = std::make_shared<JsStartupTaskResult>(resultCode, resultMessage);
|
||||
callback->Call(result);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
void JsStartupTaskExecutor::ReplyFailed(std::unique_ptr<StartupTaskResultCallback> callback,
|
||||
int32_t resultCode, const std::string &resultMessage)
|
||||
{
|
||||
HILOG_ERROR("Failed to execute: %{public}s", resultMessage.c_str());
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<StartupTaskResult> result = std::make_shared<JsStartupTaskResult>(resultCode, resultMessage);
|
||||
callback->Call(result);
|
||||
}
|
||||
|
||||
void JsStartupTaskExecutor::ReplySucceeded(StartupTaskResultCallback *callback,
|
||||
const std::shared_ptr<NativeReference> &resultRef)
|
||||
{
|
||||
HILOG_DEBUG("enter");
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<StartupTaskResult> result = std::make_shared<JsStartupTaskResult>(resultRef);
|
||||
callback->Call(result);
|
||||
delete callback;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
JsStartupTaskResult::JsStartupTaskResult() : StartupTaskResult()
|
||||
{}
|
||||
|
||||
JsStartupTaskResult::~JsStartupTaskResult() = default;
|
||||
|
||||
JsStartupTaskResult::JsStartupTaskResult(int32_t resultCode, const std::string &resultMessage)
|
||||
: StartupTaskResult(resultCode, resultMessage)
|
||||
{}
|
||||
|
||||
JsStartupTaskResult::JsStartupTaskResult(const std::shared_ptr<NativeReference> &result)
|
||||
: StartupTaskResult(), jsStartupResultRef_(result)
|
||||
{}
|
||||
|
||||
StartupTaskResult::ResultType JsStartupTaskResult::GetResultType() const
|
||||
{
|
||||
return ResultType::JS;
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> JsStartupTaskResult::GetJsStartupResultRef() const
|
||||
{
|
||||
return jsStartupResultRef_;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -17,5 +17,31 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
StartupConfig::StartupConfig() = default;
|
||||
|
||||
StartupConfig::~StartupConfig() = default;
|
||||
|
||||
StartupConfig::StartupConfig(int32_t awaitTimeoutMs) : awaitTimeoutMs_(awaitTimeoutMs)
|
||||
{}
|
||||
|
||||
StartupConfig::StartupConfig(const std::shared_ptr<StartupListener> &listener) : listener_(listener)
|
||||
{}
|
||||
|
||||
StartupConfig::StartupConfig(int32_t awaitTimeoutMs, const std::shared_ptr<StartupListener> &listener)
|
||||
: awaitTimeoutMs_(awaitTimeoutMs), listener_(listener)
|
||||
{}
|
||||
|
||||
int32_t StartupConfig::GetAwaitTimeoutMs() const
|
||||
{
|
||||
return awaitTimeoutMs_;
|
||||
}
|
||||
|
||||
int32_t StartupConfig::ListenerOnCompleted(const StartupTaskResult &result)
|
||||
{
|
||||
if (listener_ != nullptr) {
|
||||
listener_->OnCompleted(result);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -17,5 +17,17 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
StartupListener::StartupListener(const OnCompletedCallback &callback) : onCompletedCallback_(callback)
|
||||
{}
|
||||
|
||||
StartupListener::~StartupListener() = default;
|
||||
|
||||
void StartupListener::OnCompleted(const StartupTaskResult &result)
|
||||
{
|
||||
if (onCompletedCallback_ != nullptr) {
|
||||
onCompletedCallback_(result);
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -37,6 +37,74 @@ int32_t StartupManager::RegisterStartupTask(const std::string &name, const std::
|
||||
|
||||
int32_t StartupManager::BuildAutoStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager)
|
||||
{
|
||||
startupTaskManager = std::make_shared<StartupTaskManager>(startupTaskManagerId);
|
||||
for (auto &iter : startupTasks_) {
|
||||
if (!iter.second->GetIsAutoStartup()) {
|
||||
continue;
|
||||
}
|
||||
startupTaskManager->AddTask(iter.second);
|
||||
// find dep and add
|
||||
}
|
||||
startupTaskManagerMap_.emplace(startupTaskManagerId, startupTaskManager);
|
||||
startupTaskManagerId++;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::shared_ptr<StartupConfig> StartupManager::GetDefaultConfig() const
|
||||
{
|
||||
return defaultConfig_;
|
||||
}
|
||||
|
||||
int32_t StartupManager::RemoveAllResult()
|
||||
{
|
||||
HILOG_DEBUG("called.");
|
||||
for (auto &iter : startupTasks_) {
|
||||
if (iter.second != nullptr) {
|
||||
iter.second->RemoveResult();
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::RemoveResult(const std::string &name)
|
||||
{
|
||||
HILOG_DEBUG("called, name: %{public}s", name.c_str());
|
||||
auto findResult = startupTasks_.find(name);
|
||||
if (findResult == startupTasks_.end() || findResult->second == nullptr) {
|
||||
HILOG_ERROR("name: %{public}s, not found", name.c_str());
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
findResult->second->RemoveResult();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::GetResult(const std::string &name, std::shared_ptr<StartupTaskResult> &result)
|
||||
{
|
||||
HILOG_DEBUG("called, name: %{public}s", name.c_str());
|
||||
auto findResult = startupTasks_.find(name);
|
||||
if (findResult == startupTasks_.end() || findResult->second == nullptr) {
|
||||
HILOG_ERROR("name: %{public}s, not found", name.c_str());
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
StartupTask::State state = findResult->second->GetState();
|
||||
if (state != StartupTask::State::INITIALIZED) {
|
||||
HILOG_ERROR("name: %{public}s, not initialized", name.c_str());
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
result = findResult->second->GetResult();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupManager::IsInitialized(const std::string &name, bool &isInitialized)
|
||||
{
|
||||
HILOG_DEBUG("called, name: %{public}s", name.c_str());
|
||||
auto findResult = startupTasks_.find(name);
|
||||
if (findResult == startupTasks_.end() || findResult->second == nullptr) {
|
||||
HILOG_ERROR("name: %{public}s, not found", name.c_str());
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
StartupTask::State state = findResult->second->GetState();
|
||||
isInitialized = state == StartupTask::State::INITIALIZED;
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
#include "startup_task.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
StartupTask::StartupTask(const std::string &name) : name_(name)
|
||||
{}
|
||||
{
|
||||
state_ = State::CREATED;
|
||||
}
|
||||
|
||||
StartupTask::~StartupTask() = default;
|
||||
|
||||
@@ -76,7 +79,56 @@ void StartupTask::SetWaitOnMainThread(bool waitOnMainThread)
|
||||
|
||||
void StartupTask::SetIsAutoStartup(bool isAutoStartup)
|
||||
{
|
||||
isAutoStartup = isAutoStartup_;
|
||||
isAutoStartup_ = isAutoStartup;
|
||||
}
|
||||
|
||||
void StartupTask::SaveResult(const std::shared_ptr<StartupTaskResult> &result)
|
||||
{
|
||||
if (result == nullptr) {
|
||||
HILOG_ERROR("startup task: %{public}s, result is null", name_.c_str());
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("startup task: %{public}s, result code: %{public}d", name_.c_str(), result->GetResultCode());
|
||||
result_ = result;
|
||||
if (result->GetResultCode() == ERR_OK) {
|
||||
state_ = State::INITIALIZED;
|
||||
} else {
|
||||
state_ = State::CREATED;
|
||||
}
|
||||
}
|
||||
|
||||
void StartupTask::RemoveResult()
|
||||
{
|
||||
result_ = nullptr;
|
||||
state_ = State::CREATED;
|
||||
}
|
||||
|
||||
std::shared_ptr<StartupTaskResult> StartupTask::GetResult() const
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
StartupTask::State StartupTask::GetState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
std::string StartupTask::DumpDependencies() const
|
||||
{
|
||||
if (dependencies_.empty()) {
|
||||
return "";
|
||||
}
|
||||
bool isFirst = true;
|
||||
std::string dumpResult;
|
||||
for (auto &iter : dependencies_) {
|
||||
if (isFirst) {
|
||||
dumpResult = iter;
|
||||
isFirst = false;
|
||||
} else {
|
||||
dumpResult += ", " + iter;
|
||||
}
|
||||
}
|
||||
return dumpResult;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
StartupTaskManager::StartupTaskManager() = default;
|
||||
StartupTaskManager::StartupTaskManager(uint32_t startupTaskManagerId) : startupTaskManagerId_(startupTaskManagerId)
|
||||
{}
|
||||
|
||||
StartupTaskManager::~StartupTaskManager() = default;
|
||||
|
||||
@@ -40,19 +41,29 @@ int32_t StartupTaskManager::AddTask(const std::shared_ptr<StartupTask> &task)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupTaskManager::SetConfig(const std::shared_ptr<StartupConfig> &config)
|
||||
{
|
||||
config_ = config;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupTaskManager::Prepare()
|
||||
{
|
||||
HILOG_DEBUG("id: %{public}u, task number: %{public}zu", startupTaskManagerId_, tasks_.size());
|
||||
// sort
|
||||
dispatcher_ = std::make_shared<StartupTaskDispatcher>();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t StartupTaskManager::Run()
|
||||
{
|
||||
HILOG_DEBUG("id: %{public}u, task number: %{public}zu", startupTaskManagerId_, tasks_.size());
|
||||
for (auto &iter : tasks_) {
|
||||
if (iter.second == nullptr) {
|
||||
continue;
|
||||
}
|
||||
iter.second->RunTaskInit();
|
||||
std::unique_ptr<StartupTaskResultCallback> callback = std::make_unique<StartupTaskResultCallback>();
|
||||
iter.second->RunTaskInit(std::move(callback));
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
+19
-5
@@ -13,17 +13,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "js_startup_task_main_thread_executor.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
JsStartupTaskMainThreadExecutor::JsStartupTaskMainThreadExecutor() = default;
|
||||
StartupTaskResult::StartupTaskResult() = default;
|
||||
|
||||
JsStartupTaskMainThreadExecutor::~JsStartupTaskMainThreadExecutor() = default;
|
||||
StartupTaskResult::~StartupTaskResult() = default;
|
||||
|
||||
int32_t JsStartupTaskMainThreadExecutor::Run(JsRuntime &jsRuntime)
|
||||
StartupTaskResult::StartupTaskResult(int32_t resultCode, const std::string &resultMessage)
|
||||
: resultCode_(resultCode), resultMessage_(resultMessage)
|
||||
{}
|
||||
|
||||
int32_t StartupTaskResult::GetResultCode() const
|
||||
{
|
||||
return ERR_OK;
|
||||
return resultCode_;
|
||||
}
|
||||
|
||||
std::string StartupTaskResult::GetResultMessage() const
|
||||
{
|
||||
return resultMessage_;
|
||||
}
|
||||
|
||||
StartupTaskResult::ResultType StartupTaskResult::GetResultType() const
|
||||
{
|
||||
return ResultType::INVALID;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -26,8 +26,10 @@
|
||||
*MainThread*;
|
||||
*MixStackDumper*;
|
||||
*OHOSApplication*;
|
||||
*StartupManager*;
|
||||
*StartupTaskResult*;
|
||||
*Watchdog*;
|
||||
};
|
||||
local:
|
||||
*;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -74,6 +74,8 @@ enum {
|
||||
|
||||
ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP = 16400001,
|
||||
|
||||
ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP = 16500001,
|
||||
|
||||
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_BUNDLENAME = 18500001,
|
||||
ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_HQF = 18500002,
|
||||
ERR_ABILITY_RUNTIME_EXTERNAL_DEPLOY_HQF_FAILED = 18500003,
|
||||
@@ -125,4 +127,4 @@ public:
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H
|
||||
#endif // OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H
|
||||
|
||||
@@ -149,6 +149,8 @@ const std::map<int32_t, std::string> ERROR_MSG_MAP = {
|
||||
"Restart too frequently. Try again at least 10s later." },
|
||||
{ ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP,
|
||||
"The input bundleName and moduleName is not system HSP" },
|
||||
{ ERR_ABILITY_RUNTIME_EXTERNAL_STARTUP_FAILED_TO_EXECUTE_STARTUP,
|
||||
"Failed to execute startup task." },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -194,4 +196,4 @@ std::string AbilityRuntimeErrorUtil::GetErrMessage(int32_t errCode)
|
||||
return errMsg;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "ability_manager_errors.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_startup_task_executor.h"
|
||||
#include "js_startup_task_result.h"
|
||||
#include "startup_task.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -32,13 +33,12 @@ public:
|
||||
|
||||
int32_t Init();
|
||||
|
||||
int32_t RunTaskInit() override;
|
||||
int32_t RunTaskInit(std::unique_ptr<StartupTaskResultCallback> callback) override;
|
||||
|
||||
private:
|
||||
JsRuntime &jsRuntime_;
|
||||
std::shared_ptr<NativeReference> startupJsRef_;
|
||||
std::shared_ptr<NativeReference> contextJsRef_;
|
||||
std::shared_ptr<JsStartupTaskExecutor> executor_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -18,17 +18,40 @@
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "js_runtime.h"
|
||||
#include "startup_task_executor.h"
|
||||
#include "js_startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsStartupTaskExecutor : public StartupTaskExecutor {
|
||||
class JsStartupTaskExecutor {
|
||||
public:
|
||||
JsStartupTaskExecutor();
|
||||
static int32_t RunOnMainThread(JsRuntime &jsRuntime,
|
||||
const std::shared_ptr<NativeReference> &startup, const std::shared_ptr<NativeReference> &context,
|
||||
std::unique_ptr<StartupTaskResultCallback> callback);
|
||||
|
||||
virtual ~JsStartupTaskExecutor();
|
||||
static int32_t RunOnTaskPool(JsRuntime &jsRuntime,
|
||||
const std::shared_ptr<NativeReference> &startup, const std::shared_ptr<NativeReference> &context,
|
||||
std::unique_ptr<StartupTaskResultCallback> callback);
|
||||
|
||||
virtual int32_t Run(JsRuntime &jsRuntime) = 0;
|
||||
private:
|
||||
static int32_t CallStartupInit(napi_env env, const std::shared_ptr<NativeReference> &startup,
|
||||
const std::shared_ptr<NativeReference> &context, std::unique_ptr<StartupTaskResultCallback> &callback,
|
||||
napi_value &returnVal);
|
||||
|
||||
static int32_t HandleReturnVal(napi_env env, napi_value returnVal,
|
||||
std::unique_ptr<StartupTaskResultCallback> &callback);
|
||||
|
||||
static napi_value ResolveResultCallback(napi_env env, napi_callback_info info);
|
||||
|
||||
static napi_value RejectResultCallback(napi_env env, napi_callback_info info);
|
||||
|
||||
static void ReplyFailed(StartupTaskResultCallback *callback,
|
||||
int32_t resultCode, const std::string &resultMessage = "");
|
||||
|
||||
static void ReplyFailed(std::unique_ptr<StartupTaskResultCallback> callback,
|
||||
int32_t resultCode, const std::string &resultMessage = "");
|
||||
|
||||
static void ReplySucceeded(StartupTaskResultCallback *callback,
|
||||
const std::shared_ptr<NativeReference> &resultRef);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
+19
-9
@@ -13,22 +13,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_MAIN_THREAD_EXECUTOR_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_MAIN_THREAD_EXECUTOR_H
|
||||
#ifndef OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_RESULT_H
|
||||
#define OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_RESULT_H
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "js_startup_task_executor.h"
|
||||
#include "js_runtime.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsStartupTaskMainThreadExecutor : public JsStartupTaskExecutor {
|
||||
class JsStartupTaskResult : public StartupTaskResult {
|
||||
public:
|
||||
JsStartupTaskMainThreadExecutor();
|
||||
JsStartupTaskResult();
|
||||
|
||||
~JsStartupTaskMainThreadExecutor() override;
|
||||
~JsStartupTaskResult() override;
|
||||
|
||||
int32_t Run(JsRuntime &jsRuntime) override;
|
||||
JsStartupTaskResult(int32_t resultCode, const std::string &resultMessage);
|
||||
|
||||
explicit JsStartupTaskResult(const std::shared_ptr<NativeReference> &result);
|
||||
|
||||
ResultType GetResultType() const override;
|
||||
|
||||
std::shared_ptr<NativeReference> GetJsStartupResultRef() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<NativeReference> jsStartupResultRef_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_MAIN_THREAD_EXECUTOR_H
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_JS_STARTUP_TASK_RESULT_H
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "startup_listener.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@@ -33,6 +34,10 @@ public:
|
||||
|
||||
explicit StartupConfig(int32_t awaitTimeoutMs, const std::shared_ptr<StartupListener> &listener);
|
||||
|
||||
int32_t GetAwaitTimeoutMs() const;
|
||||
|
||||
int32_t ListenerOnCompleted(const StartupTaskResult &result);
|
||||
|
||||
private:
|
||||
int32_t awaitTimeoutMs_ = 10000; // 10s
|
||||
std::shared_ptr<StartupListener> listener_;
|
||||
|
||||
@@ -16,11 +16,25 @@
|
||||
#ifndef OHOS_ABILITY_RUNTIME_STARTUP_LISTENER_H
|
||||
#define OHOS_ABILITY_RUNTIME_STARTUP_LISTENER_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using OnCompletedCallback = std::function<void(const StartupTaskResult &)>;
|
||||
|
||||
class StartupListener {
|
||||
public:
|
||||
explicit StartupListener(const OnCompletedCallback &callback);
|
||||
|
||||
~StartupListener();
|
||||
|
||||
void OnCompleted(const StartupTaskResult &result);
|
||||
|
||||
private:
|
||||
OnCompletedCallback onCompletedCallback_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -34,7 +34,20 @@ public:
|
||||
|
||||
int32_t BuildAutoStartupTaskManager(std::shared_ptr<StartupTaskManager> &startupTaskManager);
|
||||
|
||||
std::shared_ptr<StartupConfig> GetDefaultConfig() const;
|
||||
|
||||
int32_t RemoveAllResult();
|
||||
|
||||
int32_t RemoveResult(const std::string &name);
|
||||
|
||||
int32_t GetResult(const std::string &name, std::shared_ptr<StartupTaskResult> &result);
|
||||
|
||||
int32_t IsInitialized(const std::string &name, bool &isInitialized);
|
||||
|
||||
private:
|
||||
uint32_t startupTaskManagerId = 0;
|
||||
std::map<uint32_t, std::shared_ptr<StartupTaskManager>> startupTaskManagerMap_;
|
||||
// read only after initialization
|
||||
std::map<std::string, std::shared_ptr<StartupTask>> startupTasks_;
|
||||
std::shared_ptr<StartupConfig> defaultConfig_;
|
||||
};
|
||||
|
||||
@@ -18,13 +18,22 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class StartupTask {
|
||||
class StartupTask : public std::enable_shared_from_this<StartupTask> {
|
||||
public:
|
||||
enum class State {
|
||||
INVALID,
|
||||
CREATED,
|
||||
INITIALIZING,
|
||||
INITIALIZED,
|
||||
};
|
||||
|
||||
explicit StartupTask(const std::string &name);
|
||||
|
||||
virtual ~StartupTask();
|
||||
@@ -51,7 +60,15 @@ public:
|
||||
|
||||
void SetIsAutoStartup(bool isAutoStartup);
|
||||
|
||||
virtual int32_t RunTaskInit() = 0;
|
||||
void SaveResult(const std::shared_ptr<StartupTaskResult> &result);
|
||||
|
||||
void RemoveResult();
|
||||
|
||||
std::shared_ptr<StartupTaskResult> GetResult() const;
|
||||
|
||||
virtual int32_t RunTaskInit(std::unique_ptr<StartupTaskResultCallback> callback) = 0;
|
||||
|
||||
State GetState() const;
|
||||
|
||||
protected:
|
||||
std::string name_;
|
||||
@@ -60,6 +77,10 @@ protected:
|
||||
bool callCreateOnMainThread_ = true;
|
||||
bool waitOnMainThread_ = true;
|
||||
bool isAutoStartup_ = true;
|
||||
std::shared_ptr<StartupTaskResult> result_;
|
||||
State state_ = State::INVALID;
|
||||
|
||||
std::string DumpDependencies() const;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define OHOS_ABILITY_RUNTIME_STARTUP_TASK_DISPATCHER_H
|
||||
|
||||
#include "ability_manager_errors.h"
|
||||
#include "startup_task_result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
@@ -27,17 +27,20 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class StartupTaskManager {
|
||||
public:
|
||||
StartupTaskManager();
|
||||
explicit StartupTaskManager(uint32_t startupTaskManagerId);
|
||||
|
||||
~StartupTaskManager();
|
||||
|
||||
int32_t AddTask(const std::shared_ptr<StartupTask> &task);
|
||||
|
||||
int32_t SetConfig(const std::shared_ptr<StartupConfig> &config);
|
||||
|
||||
int32_t Prepare();
|
||||
|
||||
int32_t Run();
|
||||
|
||||
private:
|
||||
uint32_t startupTaskManagerId_ = 0;
|
||||
std::shared_ptr<StartupConfig> config_;
|
||||
std::shared_ptr<StartupTaskDispatcher> dispatcher_;
|
||||
std::map<std::string, std::shared_ptr<StartupTask>> tasks_;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ABILITY_RUNTIME_STARTUP_TASK_RESULT_H
|
||||
#define OHOS_ABILITY_RUNTIME_STARTUP_TASK_RESULT_H
|
||||
|
||||
#include <string>
|
||||
#include "ability_manager_errors.h"
|
||||
#include "ability_transaction_callback_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class StartupTaskResult {
|
||||
public:
|
||||
enum class ResultType {
|
||||
INVALID,
|
||||
JS
|
||||
};
|
||||
|
||||
StartupTaskResult();
|
||||
|
||||
StartupTaskResult(int32_t resultCode, const std::string &resultMessage);
|
||||
|
||||
virtual ~StartupTaskResult();
|
||||
|
||||
int32_t GetResultCode() const;
|
||||
|
||||
std::string GetResultMessage() const;
|
||||
|
||||
virtual ResultType GetResultType() const;
|
||||
|
||||
private:
|
||||
int32_t resultCode_ = ERR_OK;
|
||||
std::string resultMessage_;
|
||||
};
|
||||
using StartupTaskResultCallback = AppExecFwk::AbilityTransactionCallbackInfo<const std::shared_ptr<StartupTaskResult>>;
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_STARTUP_TASK_RESULT_H
|
||||
|
||||
Reference in New Issue
Block a user