Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into startAbilityByType

Signed-off-by: leyiZh <zhaoleyi@huawei.com>
This commit is contained in:
leyiZh
2024-05-25 07:31:18 +00:00
committed by Gitee
617 changed files with 18304 additions and 3600 deletions
+16
View File
@@ -18,10 +18,12 @@ ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi"
ability_base_path = "//foundation/ability/ability_base"
form_fwk_path = "//foundation/ability/form_fwk"
ability_runtime_innerkits_path = "${ability_runtime_path}/interfaces/inner_api"
ability_runtime_ndk_path = "${ability_runtime_path}/interfaces/kits/c"
ability_runtime_native_path = "${ability_runtime_path}/frameworks/native"
ability_runtime_services_path = "${ability_runtime_path}/services"
ability_runtime_abilitymgr_path = "${ability_runtime_services_path}/abilitymgr"
ability_runtime_test_path = "${ability_runtime_path}/test"
ability_runtime_utils_path = "${ability_runtime_path}/utils"
ace_engine_path = "//foundation/arkui/ace_engine"
arkui_path = "//foundation/arkui"
previewer_path = "//ide/tools/previewer"
@@ -73,6 +75,19 @@ srms_inner_api_path =
"${ability_runtime_path}/service_router_framework/interfaces/inner_api"
fuzz_test_output_path = "ability_runtime/ability_runtime"
accessibility_path = "//foundation/barrierfree/accessibility"
relational_store_base_path = "//foundation/distributeddatamgr/relational_store"
relational_store_napi_path = "${relational_store_base_path}/frameworks/js/napi"
common_tool_path = "//foundation/distributeddatamgr/kv_store/frameworks/common"
relational_store_common_path = "${relational_store_base_path}/frameworks/common"
ability_base_path = "//foundation/ability/ability_base"
ability_base_innerapi_path = "${ability_base_path}/interfaces/inner_api"
relational_store_innerapi_path =
"${relational_store_base_path}/interfaces/inner_api"
bgtaskmgr_root_path = "//foundation/resourceschedule/background_task_mgr"
bgtaskmgr_interfaces_path = "${bgtaskmgr_root_path}/interfaces"
bgtaskmgr_frameworks_path = "${bgtaskmgr_root_path}/frameworks"
os_account_path = "//base/account/os_account"
access_token_path = "//base/security/access_token"
declare_args() {
background_task_mgr_continuous_task_enable = true
@@ -92,6 +107,7 @@ declare_args() {
"com.ohos.textautofill/entry/TextAutoFillAbility"
ability_runtime_use_memmgr_plugin = false
ability_runtime_use_memmgr = false
cj_frontend = true
if (!defined(global_parts_info) ||
defined(global_parts_info.account_os_account)) {
+45 -8
View File
@@ -64,16 +64,21 @@
"hitrace",
"hiview",
"i18n",
"icu",
"image_framework",
"init",
"input",
"ipc",
"json",
"jsoncpp",
"kv_store",
"libuv",
"memmgr",
"memmgr_override",
"memory_utils",
"napi",
"netmanager_base",
"node",
"os_account",
"relational_store",
"resource_management",
@@ -83,16 +88,11 @@
"storage_service",
"toolchain",
"webview",
"window_manager"
"window_manager",
"zlib"
],
"third_party": [
"icu",
"json",
"jsoncpp",
"libjpeg-turbo",
"libuv",
"node",
"zlib"
"libjpeg-turbo"
]
},
"build": {
@@ -104,8 +104,10 @@
"//foundation/ability/ability_runtime/interfaces/inner_api:innerkits_target",
"//foundation/ability/ability_runtime/frameworks/native/ability/native:ability_thread",
"//foundation/ability/ability_runtime/frameworks/native/ability/native:extension_module",
"//foundation/ability/ability_runtime/frameworks/native/child_process:child_process",
"//foundation/ability/ability_runtime/frameworks/native/insight_intent:insight_intent_innerkits",
"//foundation/ability/ability_runtime/frameworks/js/napi:napi_packages",
"//foundation/ability/ability_runtime/cj_environment/frameworks/cj_environment:cj_environment",
"//foundation/ability/ability_runtime/js_environment/frameworks/js_environment:js_environment",
"//foundation/ability/ability_runtime/services/abilitymgr/etc:appfwk_etc",
"//foundation/ability/ability_runtime/service_router_framework:srms_target",
@@ -173,6 +175,15 @@
},
"name": "//foundation/ability/ability_runtime/js_environment/frameworks/js_environment:js_environment"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/cj_environment/interfaces/inner_api",
"header_files": [
"cj_environment.h"
]
},
"name": "//foundation/ability/ability_runtime/cj_environment/frameworks/cj_environment:cj_environment"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/runtime/include/",
@@ -302,6 +313,15 @@
},
"name": "//foundation/ability/ability_runtime/frameworks/native/appkit:app_context"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/c/ability/ability_runtime/child_process",
"header_files": [
"native_child_process.h"
]
},
"name": "//foundation/ability/ability_runtime/frameworks/native/child_process:child_process"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/uri_permission/include/",
@@ -418,6 +438,23 @@
]
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/auto_fill_manager:auto_fill_manager"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include",
"header_files": [
"start_options.h"
]
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager:ability_start_options"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/dialog_request_callback",
"header_files": [
]
},
"name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:dialog_request_callback"
}
],
"test": [
+34
View File
@@ -0,0 +1,34 @@
# 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("//build/ohos.gni")
cj_config = {
platform_name = ""
common_defines = []
}
if (current_os == "ohos") {
cj_config.platform_name = "ohos"
cj_config.common_defines = [
"__DSU__",
"__OHOS__",
"__LINUX__",
]
} else if (current_os == "linux") {
cj_config.platform_name = "linux"
cj_config.common_defines = [ "__LINUX__" ]
} else if (current_os == "mingw") {
cj_config.platform_name = "windows"
cj_config.common_defines = [ "__WINDOWS__" ]
}
@@ -0,0 +1,66 @@
# 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("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//foundation/ability/ability_runtime/cj_environment/cj_environment.gni")
config("cj_rt_public_config") {
include_dirs = [
"include",
"${ability_runtime_path}/cj_environment/interfaces/inner_api",
]
defines = cj_config.common_defines
}
ohos_shared_library("cj_environment") {
cflags_cc = [
"-std=c++17",
"-fvisibility=hidden",
"-fdata-sections",
"-ffunction-sections",
]
public_configs = [ ":cj_rt_public_config" ]
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
sources = [ "src/cj_environment.cpp" ]
defines = []
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
if (current_os == "ohos") {
sources += [ "src/dynamic_loader_ohos.cpp" ]
external_deps += [ "eventhandler:libeventhandler" ]
defines += [ "WITH_EVENT_HANDLER" ]
} else if (current_os == "linux") {
sources += [ "src/dynamic_loader_linux.cpp" ]
} else if (current_os == "mingw") {
sources += [ "src/dynamic_loader_win.cpp" ]
} else {
assert("unsupport platform: ${current_os}")
}
innerapi_tags = [ "platformsdk" ]
part_name = "ability_runtime"
subsystem_name = "ability"
}
@@ -0,0 +1,77 @@
/*
* 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_CJ_ENVIRONMENT_CJ_INTERFACE_H
#define OHOS_ABILITY_CJ_ENVIRONMENT_CJ_INTERFACE_H
#include <stdint.h>
using CJThreadHandle = void*;
namespace OHOS {
enum RTLogLevel {
RTLOG_VERBOSE,
RTLOG_DEBUGY,
RTLOG_INFO,
RTLOG_WARNING,
RTLOG_ERROR,
RTLOG_FATAL_WITHOUT_ABORT,
RTLOG_FATAL,
RTLOG_OFF
};
enum RTErrorCode { E_OK = 0, E_ARGS = -1, E_TIMEOUT = -2, E_STATE = -3, E_FAILED = -4 };
struct HeapParam {
size_t regionSize;
size_t heapSize;
double exemptionThreshold;
double heapUtilization;
double heapGrowth;
double allocationRate;
size_t allocationWaitTime;
};
struct GCParam {
size_t gcThreshold;
double garbageThreshold;
uint64_t gcInterval;
uint64_t backupGCInterval;
int32_t gcThreads;
};
struct LogParam {
enum RTLogLevel logLevel;
};
struct ConcurrencyParam {
size_t thStackSize;
size_t coStackSize;
uint32_t processorNum;
};
struct RuntimeParam {
struct HeapParam heapParam;
struct GCParam gcParam;
struct LogParam logParam;
struct ConcurrencyParam coParam;
};
#if defined(__OHOS__) && (__OHOS__ == 1)
using LogHandle = void (*)(const char*);
#endif
}
#endif // OHOS_ABILITY_CJ_ENVIRONMENT_CJ_INTERFACE_H
@@ -0,0 +1,42 @@
/*
* 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_CJ_INVOKER_H
#define OHOS_ABILITY_RUNTIME_CJ_INVOKER_H
#include "cj_interface.h"
#include <cstddef>
#include <cstdint>
#include <csignal>
namespace OHOS {
using PostTaskType = bool(*)(void*);
using HasHigherPriorityType = bool(*)();
struct CJUncaughtExceptionInfo;
struct CJRuntimeAPI {
int (*InitCJRuntime)(const struct RuntimeParam*);
void* (*InitUIScheduler)();
int (*RunUIScheduler)(unsigned long long);
int (*FiniCJRuntime)();
int (*InitCJLibrary)(const char*);
void (*RegisterEventHandlerCallbacks)(PostTaskType, HasHigherPriorityType);
void (*RegisterCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& handle);
};
}
#endif //OHOS_ABILITY_RUNTIME_CJ_INVOKER_H
@@ -0,0 +1,27 @@
/*
* 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_CJ_MACRO_H
#define OHOS_ABILITY_RUNTIME_CJ_MACRO_H
#ifndef CJ_EXPORT
#ifndef __WINDOWS__
#define CJ_EXPORT __attribute__((visibility("default")))
#else
#define CJ_EXPORT __declspec(dllexport)
#endif
#endif
#endif //OHOS_ABILITY_RUNTIME_CJ_MACRO_H
@@ -0,0 +1,469 @@
/*
* 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 "cj_environment.h"
#include <string>
#include "cj_hilog.h"
#include "cj_invoker.h"
#ifdef __OHOS__
#include <dlfcn.h>
#endif
#include "dynamic_loader.h"
#ifdef WITH_EVENT_HANDLER
#include "event_handler.h"
#endif
using namespace OHOS;
namespace {
const char DEBUGGER_LIBNAME[] = "libcj_debugger.z.so";
const char DEBUGGER_SYMBOL_NAME[] = "StartDebuggerServer";
const char INIT_CJRUNTIME_SYMBOL_NAME[] = "InitCJRuntime";
const char INIT_UISCHEDULER_SYMBOL_NAME[] = "InitUIScheduler";
const char RUN_UISCHEDULER_SYMBOL_NAME[] = "RunUIScheduler";
const char FINI_CJRUNTIME_SYMBOL_NAME[] = "FiniCJRuntime";
const char INIT_CJLIBRARY_SYMBOL_NAME[] = "InitCJLibrary";
const char REGISTER_EVENTHANDLER_CALLBACKS_NAME[] = "RegisterEventHandlerCallbacks";
using InitCJRuntimeType = int(*)(const struct RuntimeParam*);;
using InitUISchedulerType = void*(*)();
using RunUISchedulerType = int(*)(unsigned long long);
using FiniCJRuntimeType = int(*)();
using InitCJLibraryType = int(*)(const char*);
using RegisterEventHandlerType = void(*)(PostTaskType, HasHigherPriorityType);
#ifdef __OHOS__
const char REGISTER_UNCAUGHT_EXCEPTION_NAME[] = "RegisterUncaughtExceptionHandler";
using RegisterUncaughtExceptionType = void (*)(const CJUncaughtExceptionInfo& handle);
#endif
#ifdef WITH_EVENT_HANDLER
static std::shared_ptr<AppExecFwk::EventHandler> g_handler = nullptr;
#endif
bool LoadSymbolInitCJRuntime(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, INIT_CJRUNTIME_SYMBOL_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", INIT_CJRUNTIME_SYMBOL_NAME);
return false;
}
apis.InitCJRuntime = reinterpret_cast<InitCJRuntimeType>(symbol);
return true;
}
bool LoadSymbolInitUIScheduler(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, INIT_UISCHEDULER_SYMBOL_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", INIT_UISCHEDULER_SYMBOL_NAME);
return false;
}
apis.InitUIScheduler = reinterpret_cast<InitUISchedulerType>(symbol);
return true;
}
bool LoadSymbolRunUIScheduler(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, RUN_UISCHEDULER_SYMBOL_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", RUN_UISCHEDULER_SYMBOL_NAME);
return false;
}
apis.RunUIScheduler = reinterpret_cast<RunUISchedulerType>(symbol);
return true;
}
bool LoadSymbolFiniCJRuntime(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, FINI_CJRUNTIME_SYMBOL_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", FINI_CJRUNTIME_SYMBOL_NAME);
return false;
}
apis.FiniCJRuntime = reinterpret_cast<FiniCJRuntimeType>(symbol);
return true;
}
bool LoadSymbolInitCJLibrary(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, INIT_CJLIBRARY_SYMBOL_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", INIT_CJLIBRARY_SYMBOL_NAME);
return false;
}
apis.InitCJLibrary = reinterpret_cast<InitCJLibraryType>(symbol);
return true;
}
bool LoadSymbolRegisterEventHandlerCallbacks(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, REGISTER_EVENTHANDLER_CALLBACKS_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", REGISTER_EVENTHANDLER_CALLBACKS_NAME);
return false;
}
apis.RegisterEventHandlerCallbacks = reinterpret_cast<RegisterEventHandlerType>(symbol);
return true;
}
#ifdef __OHOS__
bool LoadSymbolRegisterCJUncaughtExceptionHandler(void* handle, CJRuntimeAPI& apis)
{
auto symbol = DynamicFindSymbol(handle, REGISTER_UNCAUGHT_EXCEPTION_NAME);
if (symbol == nullptr) {
LOGE("runtime api not found: %{public}s", REGISTER_UNCAUGHT_EXCEPTION_NAME);
return false;
}
apis.RegisterCJUncaughtExceptionHandler = reinterpret_cast<RegisterUncaughtExceptionType>(symbol);
return true;
}
#endif
bool PostTaskWrapper(void* func)
{
return CJEnvironment::GetInstance()->PostTask(reinterpret_cast<TaskFuncType>(func));
}
bool HasHigherPriorityTaskWrapper()
{
return CJEnvironment::GetInstance()->HasHigherPriorityTask();
}
} // namespace
const char *CJEnvironment::cjAppNSName = "cj_app";
const char *CJEnvironment::cjSDKNSName = "cj_sdk";
const char *CJEnvironment::cjSysNSName = "cj_system";
const char *CJEnvironment::cjChipSDKNSName = "cj_chipsdk";
CJRuntimeAPI CJEnvironment::lazyApis_ {};
CJEnvironment* CJEnvironment::GetInstance()
{
static CJEnvironment cjEnv;
#ifdef WITH_EVENT_HANDLER
if (g_handler == nullptr) {
g_handler = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
}
#endif
return &cjEnv;
}
bool CJEnvironment::LoadRuntimeApis()
{
static bool isRuntimeApiLoaded {false};
if (isRuntimeApiLoaded) {
return true;
}
#ifdef __WINDOWS__
#define RTLIB_NAME "libcangjie-runtime.dll"
#else
#define RTLIB_NAME "libcangjie-runtime.so"
#endif
#ifdef __OHOS__
Dl_namespace ns;
dlns_get(CJEnvironment::cjSDKNSName, &ns);
auto dso = DynamicLoadLibrary(&ns, RTLIB_NAME, 1);
#else
auto dso = DynamicLoadLibrary(RTLIB_NAME, 1);
#endif
if (!dso) {
LOGE("load library failed: %{public}s", RTLIB_NAME);
return false;
}
#undef RTLIB_NAME
if (!LoadSymbolInitCJRuntime(dso, lazyApis_) ||
!LoadSymbolInitUIScheduler(dso, lazyApis_) ||
!LoadSymbolRunUIScheduler(dso, lazyApis_) ||
!LoadSymbolFiniCJRuntime(dso, lazyApis_) ||
!LoadSymbolInitCJLibrary(dso, lazyApis_) ||
!LoadSymbolRegisterEventHandlerCallbacks(dso, lazyApis_)) {
LOGE("load symbol failed");
return false;
}
#ifdef __OHOS__
if (!LoadSymbolRegisterCJUncaughtExceptionHandler(dso, lazyApis_)) {
LOGE("load symbol RegisterCJUncaughtExceptionHandler failed");
return false;
}
#endif
isRuntimeApiLoaded = true;
return true;
}
void CJEnvironment::RegisterCJUncaughtExceptionHandler(const CJUncaughtExceptionInfo& handle)
{
lazyApis_.RegisterCJUncaughtExceptionHandler(handle);
}
bool CJEnvironment::PostTask(TaskFuncType task)
{
#ifdef WITH_EVENT_HANDLER
if (task == nullptr) {
LOGE("null task could not be posted");
return false;
}
bool postDone = g_handler->PostTask(task, "spawn-main-task-from-cj", 0, AppExecFwk::EventQueue::Priority::HIGH);
if (!postDone) {
LOGE("event handler support cj ui scheduler");
return false;
}
return true;
#endif
return true;
}
bool CJEnvironment::HasHigherPriorityTask()
{
#ifdef WITH_EVENT_HANDLER
return g_handler->HasPreferEvent(static_cast<int>(AppExecFwk::EventQueue::Priority::HIGH));
#endif
return false;
}
void CJEnvironment::InitCJChipSDKNS(const std::string& path)
{
#ifdef __OHOS__
LOGI("InitCJChipSDKNS: %{public}s", path.c_str());
Dl_namespace chip_ndk;
DynamicInitNamespace(&chip_ndk, nullptr, path.c_str(), CJEnvironment::cjChipSDKNSName);
Dl_namespace ndk;
Dl_namespace current;
dlns_get(nullptr, &current);
dlns_get("ndk", &ndk);
dlns_inherit(&chip_ndk, &ndk, "allow_all_shared_libs");
dlns_inherit(&chip_ndk, &current, "allow_all_shared_libs");
#endif
}
// Init app namespace
void CJEnvironment::InitCJAppNS(const std::string& path)
{
#ifdef __OHOS__
LOGI("InitCJAppNS: %{public}s", path.c_str());
Dl_namespace ndk;
Dl_namespace ns;
DynamicInitNamespace(&ns, nullptr, path.c_str(), CJEnvironment::cjAppNSName);
dlns_get("ndk", &ndk);
dlns_inherit(&ns, &ndk, "allow_all_shared_libs");
Dl_namespace current;
dlns_get(nullptr, &current);
dlns_inherit(&ndk, &current, "allow_all_shared_libs");
dlns_inherit(&current, &ndk, "allow_all_shared_libs");
#endif
}
// Init cj sdk namespace
void CJEnvironment::InitCJSDKNS(const std::string& path)
{
#ifdef __OHOS__
LOGI("InitCJSDKNS: %{public}s", path.c_str());
Dl_namespace cj_app;
Dl_namespace ns;
dlns_get(CJEnvironment::cjAppNSName, &cj_app);
DynamicInitNamespace(&ns, &cj_app, path.c_str(), CJEnvironment::cjSDKNSName);
#endif
}
// Init cj system namespace
void CJEnvironment::InitCJSysNS(const std::string& path)
{
#ifdef __OHOS__
LOGI("InitCJSysNS: %{public}s", path.c_str());
Dl_namespace cj_sdk;
Dl_namespace ndk;
Dl_namespace ns;
dlns_get(CJEnvironment::cjSDKNSName, &cj_sdk);
DynamicInitNamespace(&ns, &cj_sdk, path.c_str(), CJEnvironment::cjSysNSName);
dlns_get("ndk", &ndk);
dlns_inherit(&ns, &ndk, "allow_all_shared_libs");
#endif
}
bool CJEnvironment::StartRuntime()
{
if (isRuntimeStarted_) {
return true;
}
if (!LoadRuntimeApis()) {
LOGE("LoadRuntimeApis failed");
return false;
}
RuntimeParam rtParams {
.heapParam = {
.regionSize = 64,
.heapSize = 64 * 1024,
.exemptionThreshold= 0.8,
.heapUtilization = 0.8,
.heapGrowth = 0.15,
.allocationRate = 0,
.allocationWaitTime = 0,
},
.gcParam = {
.gcThreshold = 0,
.garbageThreshold = 0,
.gcInterval = 0,
.backupGCInterval = 0,
.gcThreads = 0,
},
.logParam = {
.logLevel = RTLOG_ERROR,
},
.coParam = {
.thStackSize = 2 * 1024,
.coStackSize = 2 * 1024,
.processorNum = 8,
}
};
auto status = lazyApis_.InitCJRuntime(&rtParams);
if (status != E_OK) {
LOGE("init cj runtime failed: %{public}d", status);
return false;
}
lazyApis_.RegisterEventHandlerCallbacks(PostTaskWrapper, HasHigherPriorityTaskWrapper);
isRuntimeStarted_ = true;
return true;
}
void CJEnvironment::StopRuntime()
{
if (!isRuntimeStarted_) {
return;
}
if (isUISchedulerStarted_) {
StopUIScheduler();
}
auto code = lazyApis_.FiniCJRuntime();
if (code == E_OK) {
isRuntimeStarted_ = false;
}
}
bool CJEnvironment::StartUIScheduler()
{
if (isUISchedulerStarted_) {
return true;
}
uiScheduler_ = lazyApis_.InitUIScheduler();
if (!uiScheduler_) {
LOGE("init cj ui scheduler failed");
return false;
}
isUISchedulerStarted_ = true;
return true;
}
void CJEnvironment::StopUIScheduler()
{
isUISchedulerStarted_ = false;
}
void* CJEnvironment::LoadCJLibrary(const char* dlName)
{
if (!StartRuntime()) {
LOGE("StartRuntime failed");
return nullptr;
}
auto handle = LoadCJLibrary(APP, dlName);
if (!handle) {
LOGE("load cj library failed: %{public}s", DynamicGetError());
return nullptr;
}
LOGI("LoadCJLibrary InitCJLibrary: %{public}s", dlName);
auto status = lazyApis_.InitCJLibrary(dlName);
if (status != E_OK) {
LOGE("InitCJLibrary failed: %{public}s", dlName);
UnLoadCJLibrary(handle);
return nullptr;
}
return handle;
}
void* CJEnvironment::LoadCJLibrary(OHOS::CJEnvironment::LibraryKind kind, const char* dlName)
{
#ifdef __OHOS__
Dl_namespace ns;
switch (kind) {
case APP:
dlns_get(CJEnvironment::cjAppNSName, &ns);
break;
case SYSTEM:
dlns_get(CJEnvironment::cjSysNSName, &ns);
break;
case SDK:
dlns_get(CJEnvironment::cjSDKNSName, &ns);
break;
}
auto handle = DynamicLoadLibrary(&ns, dlName, 1);
#else
auto handle = DynamicLoadLibrary(dlName, 1);
#endif
if (!handle) {
LOGE("load cj library failed: %{public}s", DynamicGetError());
return nullptr;
}
return handle;
}
void CJEnvironment::UnLoadCJLibrary(void* handle)
{
DynamicFreeLibrary(handle);
}
void* CJEnvironment::GetSymbol(void* dso, const char* symbol)
{
return DynamicFindSymbol(dso, symbol);
}
bool CJEnvironment::StartDebugger()
{
#ifdef __OHOS__
Dl_namespace ns;
dlns_get(CJEnvironment::cjSysNSName, &ns);
auto handle = DynamicLoadLibrary(&ns, DEBUGGER_LIBNAME, 0);
#else
auto handle = DynamicLoadLibrary(DEBUGGER_LIBNAME, 0);
#endif
if (!handle) {
LOGE("failed to load library: %{public}s", DEBUGGER_LIBNAME);
return false;
}
auto symbol = DynamicFindSymbol(handle, DEBUGGER_SYMBOL_NAME);
if (!symbol) {
LOGE("failed to find symbol: %{public}s", DEBUGGER_SYMBOL_NAME);
DynamicFreeLibrary(handle);
return false;
}
auto func = reinterpret_cast<bool (*)(int, const std::string&)>(symbol);
std::string name = "PandaDebugger";
func(0, name);
return true;
}
@@ -0,0 +1,41 @@
/*
* 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_CJ_HILOG_H
#define OHOS_ABILITY_RUNTIME_CJ_HILOG_H
#include "hilog/log.h"
#ifdef LOG_DOMAIN
#undef LOG_DOMAIN
#endif
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_DOMAIN 0xD003900
#define LOG_TAG "CJ-RUNTIME"
#define LOGI(...) \
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_INFO)) { \
HILOG_INFO(LOG_CORE, ##__VA_ARGS__); \
}
#define LOGE(...) \
if (HiLogIsLoggable(LOG_DOMAIN, LOG_TAG, LOG_ERROR)) { \
HILOG_ERROR(LOG_CORE, __VA_ARGS__); \
}
#endif //OHOS_ABILITY_RUNTIME_CJ_HILOG_H
@@ -0,0 +1,38 @@
/*
* 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 "dynamic_loader.h"
#include <dlfcn.h>
void* DynamicLoadLibrary(const char* dlPath, int mode)
{
return dlopen(dlPath, mode);
}
void* DynamicFindSymbol(void* so, const char* symbol)
{
return dlsym(so, symbol);
}
void DynamicFreeLibrary(void* so)
{
(void)dlclose(so);
}
const char* DynamicGetError()
{
return dlerror();
}
@@ -0,0 +1,117 @@
/*
* 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 "dynamic_loader.h"
#include "cj_hilog.h"
#include <dlfcn.h>
#include <cstdio>
#include <securec.h>
#include <unordered_set>
#include <string>
namespace {
constexpr auto ERROR_BUF_SIZE = 255;
static char g_dlError[ERROR_BUF_SIZE];
static std::unordered_set<std::string> HasInited;
}
enum ErrorCode {
OUT_OF_MEMORY = 12,
FILE_EXISTS = 17,
INVALID_ARGUMENT = 22,
};
static void ReadDlError()
{
char* errMsg = dlerror();
if (!errMsg) {
return;
}
auto ends = sprintf_s(g_dlError, sizeof(g_dlError), "%s", errMsg);
if (ends >= ERROR_BUF_SIZE) {
g_dlError[ERROR_BUF_SIZE - 1] = '\0';
} else {
g_dlError[ends] = '\0';
}
}
void DynamicInitNamespace(Dl_namespace* ns, void* parent, const char* entries, const char* name)
{
if (!ns || !entries || !name) {
LOGE("Invaild args for init namespace.");
return;
}
if (HasInited.count(std::string(name))) {
return;
}
dlns_init(ns, name);
auto status = dlns_create2(ns, entries, 0);
std::string errMsg;
if (status != 0) {
switch (status) {
case FILE_EXISTS:
errMsg = "dlns_create failed: File exists";
break;
case INVALID_ARGUMENT:
errMsg = "dlns_create failed: Invalid argument";
break;
case OUT_OF_MEMORY:
errMsg = "dlns_create failed: Out of memory";
break;
default:
errMsg = "dlns_create failed, status: " + std::to_string(status);
}
(void)sprintf_s(g_dlError, sizeof(g_dlError), errMsg.c_str());
return;
}
if (parent) {
dlns_inherit((Dl_namespace*)parent, ns, "allow_all_shared_libs");
}
if (strcmp(name, "cj_app") != 0) {
Dl_namespace current;
dlns_get(nullptr, &current);
dlns_inherit(ns, &current, "allow_all_shared_libs");
}
HasInited.insert(std::string(name));
}
void* DynamicLoadLibrary(Dl_namespace *ns, const char* dlPath, int mode)
{
if (ns == nullptr) {
dlns_get("cj_app", ns);
}
auto result = dlopen_ns(ns, dlPath, mode | RTLD_GLOBAL | RTLD_NOW);
if (!result) {
ReadDlError();
}
return result;
}
void* DynamicFindSymbol(void* so, const char* symbol)
{
return dlsym(so, symbol);
}
void DynamicFreeLibrary(void* so)
{
(void)dlclose(so);
}
const char* DynamicGetError()
{
return g_dlError;
}
@@ -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 "dynamic_loader.h"
#include <cstdio>
#include <libloaderapi.h>
#include <processenv.h>
constexpr auto ERROR_BUF_SIZE = 255;
static char g_dlError[ERROR_BUF_SIZE] {0};
void* DynamicLoadLibrary(const char* dlPath, int mode)
{
return LoadLibraryA(dlPath);
}
void* DynamicFindSymbol(void* so, const char* symbol)
{
return (void*)GetProcAddress((HMODULE)so, symbol);
}
void DynamicFreeLibrary(void* so)
{
(void)FreeLibrary((HMODULE)so);
}
const char* DynamicGetError()
{
return g_dlError;
}
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2022 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_CJ_ENVIRONMENT_H
#define OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
#include <functional>
#ifdef WINDOWS_PLATFORM
#define CJ_EXPORT __declspec(dllexport)
#else
#define CJ_EXPORT __attribute__((visibility("default")))
#endif
namespace OHOS {
struct CJRuntimeAPI;
struct CJErrorObject {
const char* name;
const char* message;
const char* stack;
};
struct CJUncaughtExceptionInfo {
const char* hapPath;
std::function<void(const char* summary, const CJErrorObject errorObj)> uncaughtTask;
};
using TaskFuncType = void(*)();
class CJ_EXPORT CJEnvironment final {
public:
static CJEnvironment* GetInstance();
bool IsRuntimeStarted()
{
return isRuntimeStarted_;
}
void InitCJAppNS(const std::string& path);
void InitCJSDKNS(const std::string& path);
void InitCJSysNS(const std::string& path);
void InitCJChipSDKNS(const std::string& path);
bool StartRuntime();
void StopRuntime();
void RegisterCJUncaughtExceptionHandler(const CJUncaughtExceptionInfo& handle);
bool IsUISchedulerStarted()
{
return isUISchedulerStarted_;
}
bool StartUIScheduler();
void StopUIScheduler();
enum LibraryKind {
SYSTEM,
SDK,
APP,
};
void* LoadCJLibrary(const char* dlName);
void* LoadCJLibrary(LibraryKind kind, const char* dlName);
void UnLoadCJLibrary(void* handle);
void* GetUIScheduler()
{
if (!isUISchedulerStarted_) {
return nullptr;
}
return uiScheduler_;
}
void* GetSymbol(void* dso, const char* symbol);
bool StartDebugger();
bool PostTask(TaskFuncType task);
bool HasHigherPriorityTask();
static const char *cjAppNSName;
static const char *cjSDKNSName;
static const char *cjSysNSName;
static const char *cjChipSDKNSName;
private:
bool LoadRuntimeApis();
static CJRuntimeAPI lazyApis_;
bool isRuntimeStarted_{false};
bool isUISchedulerStarted_{false};
void* uiScheduler_ {nullptr};
};
}
#endif //OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
@@ -0,0 +1,37 @@
/*
* 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_DYNAMIC_LOADER_H
#define OHOS_ABILITY_RUNTIME_DYNAMIC_LOADER_H
#ifdef __OHOS__
#include <dlfcn.h>
#endif
extern "C" {
#ifdef __OHOS__
void* DynamicLoadLibrary(Dl_namespace *ns, const char* dlPath, int mode);
#else
void* DynamicLoadLibrary(const char* dlPath, int mode);
#endif
void* DynamicFindSymbol(void* so, const char* symbol);
const char* DynamicGetError();
void DynamicFreeLibrary(void* so);
#ifdef __OHOS__
void DynamicInitNamespace(Dl_namespace* ns, void* parent, const char* entries, const char* name);
#endif
};
#endif //OHOS_ABILITY_RUNTIME_DYNAMIC_LOADER_H
@@ -27,6 +27,7 @@ ohos_shared_library("autostartupcallback") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -46,7 +46,7 @@ void JsAbilityAutoStartupCallBack::OnAutoStartupOff(const AutoStartupInfo &info)
void JsAbilityAutoStartupCallBack::Register(napi_value value)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
for (const auto &callback : callbacks_) {
if (IsJsCallbackEquals(callback, value)) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The current callback already exists.");
@@ -64,7 +64,7 @@ void JsAbilityAutoStartupCallBack::UnRegister(napi_value value)
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
napi_valuetype type = napi_undefined;
napi_typeof(env_, value, &type);
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
if (type == napi_undefined || type == napi_null) {
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "jsCallback is nullptr, delete all callback.");
callbacks_.clear();
@@ -105,7 +105,7 @@ void JsAbilityAutoStartupCallBack::JSCallFunction(const AutoStartupInfo &info, c
void JsAbilityAutoStartupCallBack::JSCallFunctionWorker(const AutoStartupInfo &info, const std::string &methodName)
{
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
for (auto callback : callbacks_) {
if (callback == nullptr) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "callback is nullptr.");
@@ -49,7 +49,7 @@ private:
napi_env env_;
std::vector<std::shared_ptr<NativeReference>> callbacks_;
std::mutex mutexlock;
std::mutex mutexlock_;
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -72,7 +72,7 @@ napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStar
}
if (napi_set_element(env, arrayObj, i, object) != napi_ok) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Inster object to array failed.");
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Insert object to array failed.");
return nullptr;
}
}
@@ -31,6 +31,7 @@ ohos_shared_library("autostartupmanager") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -35,6 +35,7 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
constexpr int32_t INDEX_ZERO = 0;
constexpr int32_t INDEX_ONE = 1;
constexpr int32_t INVALID_PARAM = static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
constexpr const char *ON_OFF_TYPE_SYSTEM = "systemAutoStartup";
} // namespace
@@ -91,7 +92,7 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
std::string type;
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, INVALID_PARAM, "Parameter error. Convert type fail.");
return CreateJsUndefined(env);
}
@@ -139,7 +140,7 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
std::string type;
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], type) || type != ON_OFF_TYPE_SYSTEM) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Failed to parse type.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, INVALID_PARAM, "Parameter error. Convert type fail.");
return CreateJsUndefined(env);
}
@@ -189,7 +190,7 @@ napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env
AutoStartupInfo autoStartupInfo;
if (!UnwrapAutoStartupInfo(env, info.argv[INDEX_ZERO], autoStartupInfo)) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, INVALID_PARAM, "Parameter error. Convert autoStartupInfo fail.");
return CreateJsUndefined(env);
}
@@ -239,7 +240,7 @@ napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env
AutoStartupInfo autoStartupInfo;
if (!UnwrapAutoStartupInfo(env, info.argv[INDEX_ZERO], autoStartupInfo)) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, INVALID_PARAM, "Parameter error. Convert autoStartupInfo fail.");
return CreateJsUndefined(env);
}
+4 -8
View File
@@ -18,9 +18,6 @@ ohos_shared_library("abilityconstant_napi") {
include_dirs = [
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_services_path}/common/include",
"${ability_base_kits_path}/uri/include",
"${ability_base_kits_path}/want/include",
"${ability_base_path}/interfaces/inner_api/base/include",
"//third_party/json/include",
]
@@ -29,12 +26,13 @@ ohos_shared_library("abilityconstant_napi") {
deps = []
external_deps = [
"ability_base:zuri",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
]
public_external_deps = [ "ability_base:want" ]
relative_install_dir = "module/application"
subsystem_name = "ability"
part_name = "ability_runtime"
@@ -44,9 +42,6 @@ ohos_shared_library("abilityconstant") {
include_dirs = [
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_services_path}/common/include",
"${ability_base_kits_path}/uri/include",
"${ability_base_kits_path}/want/include",
"${ability_base_path}/interfaces/inner_api/base/include",
"//third_party/json/include",
]
@@ -55,12 +50,13 @@ ohos_shared_library("abilityconstant") {
deps = []
external_deps = [
"ability_base:zuri",
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
]
public_external_deps = [ "ability_base:want" ]
defines = [ "ENABLE_ERRCODE" ]
relative_install_dir = "module/app/ability"
+3 -5
View File
@@ -29,14 +29,11 @@ template("abilitymanager") {
"js_ability_manager_utils.cpp",
]
include_dirs = [
"./",
"//third_party/icu/icu4c/source/common",
"${ipc_native_path}/src/napi/include",
]
include_dirs = [ "./" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -55,6 +52,7 @@ template("abilitymanager") {
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"icu:shared_icuuc",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
@@ -30,7 +30,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
if (!valid_) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The app manager may has destoryed.");
TAG_LOGE(AAFwkTag::ABILITYMGR, "The app manager may has destroyed.");
return;
}
wptr<JSAbilityForegroundStateObserver> jsObserver = this;
@@ -51,7 +51,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD
void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
for (auto &item : jsObserverObjectSet_) {
if (item == nullptr) {
continue;
@@ -112,7 +112,7 @@ void JSAbilityForegroundStateObserver::AddJsObserverObject(const napi_value &jsO
}
napi_ref ref = nullptr;
napi_create_reference(env_, jsObserverObject, 1, &ref);
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
jsObserverObjectSet_.emplace(std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref)));
}
@@ -124,7 +124,7 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value &
}
auto observer = GetObserverObject(jsObserverObject);
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
if (observer != nullptr) {
jsObserverObjectSet_.erase(observer);
}
@@ -132,7 +132,7 @@ void JSAbilityForegroundStateObserver::RemoveJsObserverObject(const napi_value &
void JSAbilityForegroundStateObserver::RemoveAllJsObserverObject()
{
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
if (!jsObserverObjectSet_.empty()) {
jsObserverObjectSet_.clear();
}
@@ -144,7 +144,7 @@ std::shared_ptr<NativeReference> JSAbilityForegroundStateObserver::GetObserverOb
TAG_LOGE(AAFwkTag::ABILITYMGR, "Observer is null.");
return nullptr;
}
std::lock_guard<std::mutex> lock(mutexlock);
std::lock_guard<std::mutex> lock(mutexlock_);
for (auto &observer : jsObserverObjectSet_) {
if (observer == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Invalid observer.");
@@ -47,7 +47,7 @@ public:
private:
napi_env env_;
volatile bool valid_ = true;
std::mutex mutexlock;
std::mutex mutexlock_;
std::set<std::shared_ptr<NativeReference>> jsObserverObjectSet_;
};
} // namespace AbilityRuntime
@@ -39,8 +39,8 @@ napi_value CreateJSToken(napi_env env, const sptr<IRemoteObject> target)
env, "TokenClass", NAPI_AUTO_LENGTH, constructorcb, nullptr, 0, nullptr, &tokenClass);
napi_value jsToken = nullptr;
napi_new_instance(env, tokenClass, 0, nullptr, &jsToken);
auto finalizecb = [](napi_env env, void *data, void *hint) {};
napi_wrap(env, jsToken, static_cast<void *>(target.GetRefPtr()), finalizecb, nullptr, nullptr);
auto finalizercb = [](napi_env env, void *data, void *hint) {};
napi_wrap(env, jsToken, static_cast<void *>(target.GetRefPtr()), finalizercb, nullptr, nullptr);
return jsToken;
}
@@ -27,7 +27,6 @@ template("delegator") {
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_delegator/",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/tools/aa/include",
"${ipc_native_path}/src/napi/include",
]
sources = [
@@ -46,7 +46,7 @@ public:
~JSAbilityDelegator() = default;
/**
* Destory object.
* Destroy object.
*
* @param env Indicates the native engine.
* @param data Indicates the object to be destroyed.
@@ -32,6 +32,7 @@ ohos_shared_library("appmanager_napi") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -94,7 +94,7 @@ public:
static napi_value KillProcessesByBundleName(napi_env env, napi_callback_info info)
{
TAG_LOGD(AAFwkTag::APPMGR, "KillProcessesByBundleName start.");
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnkillProcessByBundleName);
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessByBundleName);
}
static napi_value ClearUpApplicationData(napi_env env, napi_callback_info info)
@@ -130,7 +130,7 @@ private:
}
static int64_t serialNumber = 0;
std::vector<std::string> bundleNameList;
// unwarp observer
// unwrap observer
if (observer_ == nullptr) {
observer_ = new JSAppStateObserver(env);
}
@@ -310,9 +310,9 @@ private:
return result;
}
napi_value OnkillProcessByBundleName(napi_env env, size_t argc, napi_value* argv)
napi_value OnKillProcessByBundleName(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessByBundleName called");
TAG_LOGD(AAFwkTag::APPMGR, "called");
int32_t errCode = 0;
std::string bundleName;
@@ -350,7 +350,7 @@ private:
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnkillProcessByBundleName",
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessByBundleName",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -47,8 +47,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData)
{
TAG_LOGI(AAFwkTag::APPMGR,
"HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
TAG_LOGI(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d.",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
@@ -29,7 +29,7 @@ using OHOS::AppExecFwk::ProcessData;
class JSAppStateObserver : public ApplicationStateObserverStub {
public:
explicit JSAppStateObserver(napi_env engine);
~JSAppStateObserver();
virtual ~JSAppStateObserver();
void OnForegroundApplicationChanged(const AppStateData &appStateData) override;
void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override;
void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override;
@@ -189,6 +189,10 @@ class ApplicationContext {
return this.__context_impl__.setSupportedProcessCache(isSupport);
}
getCurrentAppCloneIndex(){
return this.__context_impl__.getCurrentAppCloneIndex()
}
set area(mode) {
return this.__context_impl__.switchArea(mode);
}
@@ -34,6 +34,7 @@ template("errormanager") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_native_path}/appkit:appkit_native",
@@ -211,7 +211,7 @@ private:
if (type == ON_OFF_TYPE_SYNC_LOOP) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
ThrowInvalidCallerError(env);
return CreateJsUndefined(env);
}
return OnSetLoopWatch(env, argc, argv);
@@ -219,7 +219,7 @@ private:
if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
ThrowInvalidCallerError(env);
return CreateJsUndefined(env);
}
if (argc != ARGC_TWO) {
@@ -327,7 +327,7 @@ private:
if (type == ON_OFF_TYPE_SYNC_LOOP) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
TAG_LOGE(AAFwkTag::JSNAPI, "LoopObserver can only be set from main thread.");
ThrowInvaildCallerError(env);
ThrowInvalidCallerError(env);
return CreateJsUndefined(env);
}
return OnRemoveLoopWatch(env, argc, argv);
@@ -335,7 +335,7 @@ private:
if (type == ON_OFF_TYPE_UNHANDLED_REJECTION) {
if (!AppExecFwk::EventRunner::IsAppMainThread()) {
TAG_LOGE(AAFwkTag::JSNAPI, "UnhandledRejectionObserver can only be unset from main thread.");
ThrowInvaildCallerError(env);
ThrowInvalidCallerError(env);
return CreateJsUndefined(env);
}
if (argc != ARGC_TWO && argc != ARGC_ONE) {
@@ -418,7 +418,7 @@ private:
return res;
}
}
TAG_LOGE(AAFwkTag::JSNAPI, "Remove UnhandledRjectionObserver failed");
TAG_LOGE(AAFwkTag::JSNAPI, "Remove UnhandledRejectionObserver failed");
ThrowError(env, AbilityErrorCode::ERROR_CODE_OBSERVER_NOT_FOUND);
return res;
}
@@ -479,15 +479,15 @@ private:
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([number](napi_env env, NapiAsyncTask &task, int32_t status) {
if (loopObserver_ == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: loopObserver_ is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "loopObserver_ is null.");
return;
}
if (loopObserver_->env == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: env is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "env is null.");
return;
}
if (loopObserver_->observerObject == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "CallbackTimeout: observerObject is null.");
TAG_LOGE(AAFwkTag::JSNAPI, "observerObject is null.");
return;
}
napi_value jsValue[] = { CreateJsValue(loopObserver_->env, number) };
@@ -37,6 +37,7 @@ ohos_shared_library("appmanager") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -29,7 +29,7 @@ void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStat
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destoryed.");
TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destroyed.");
return;
}
wptr<JSAppForegroundStateObserver> self = this;
@@ -110,6 +110,11 @@ public:
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnIsRunningInStabilityTest);
}
static napi_value GetRunningMultiAppInfo(napi_env env, napi_callback_info info)
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnGetRunningMultiAppInfo);
}
static napi_value KillProcessWithAccount(napi_env env, napi_callback_info info)
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessWithAccount);
@@ -117,7 +122,7 @@ public:
static napi_value KillProcessesByBundleName(napi_env env, napi_callback_info info)
{
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnkillProcessesByBundleName);
GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnKillProcessesByBundleName);
}
static napi_value ClearUpApplicationData(napi_env env, napi_callback_info info)
@@ -178,8 +183,8 @@ public:
}
napi_ref ref = nullptr;
napi_create_reference(env, para, 1, &ref);
NativeReference* nativeReferece = reinterpret_cast<NativeReference *>(ref);
auto object = nativeReferece->GetNapiValue();
NativeReference* nativeReference = reinterpret_cast<NativeReference *>(ref);
auto object = nativeReference->GetNapiValue();
napi_value method = nullptr;
napi_get_named_property(env, object, methodName.c_str(), &method);
if (method == nullptr) {
@@ -478,7 +483,7 @@ private:
int64_t observerId = -1;
napi_get_value_int64(env, argv[INDEX_ONE], &observerId);
if (observer_ == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "observer_ is nullptr, please register first");
TAG_LOGE(AAFwkTag::APPMGR, "observer is nullptr, please register first");
ThrowInvalidParamError(env, "observer is nullptr, please register first");
return CreateJsUndefined(env);
}
@@ -640,6 +645,52 @@ private:
return result;
}
napi_value OnGetRunningMultiAppInfo(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!CheckCallerIsSystemApp()) {
TAG_LOGE(AAFwkTag::APPMGR, "Current app is not system app");
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
}
// only support 1 params
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments");
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
std::string bundleName;
if (!ConvertFromJsValue(env, argv[0], bundleName)) {
TAG_LOGE(AAFwkTag::APPMGR, "get bundleName failed!");
ThrowInvalidParamError(env, "Parse param bundleName failed, must be a string");
return CreateJsUndefined(env);
}
auto info = std::make_shared<RunningMultiAppInfo>();
auto innerErrorCode = std::make_shared<int32_t>(ERR_OK);
NapiAsyncTask::ExecuteCallback execute =
[appManager = appManager_, bundleName, innerErrorCode, info]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
*innerErrorCode = static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER);
return;
}
*innerErrorCode = appManager->GetRunningMultiAppInfoByBundleName(bundleName, *info);
};
NapiAsyncTask::CompleteCallback complete =
[innerErrorCode, info](napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode == ERR_OK) {
task.ResolveWithNoError(env, CreateJsRunningMultiAppInfo(env, *info));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
}
};
napi_value lastParam = nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetRunningMultiAppInfo",
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
return result;
}
napi_value OnGetRunningProcessInformationByBundleType(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
@@ -694,7 +745,7 @@ private:
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
@@ -705,9 +756,9 @@ private:
return result;
}
napi_value OnkillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv)
napi_value OnKillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "OnkillProcessesByBundleName called");
TAG_LOGD(AAFwkTag::APPMGR, "OnKillProcessesByBundleName called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Params not match");
ThrowTooFewParametersError(env);
@@ -739,7 +790,7 @@ private:
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnkillProcessesByBundleName",
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessesByBundleName",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -1176,20 +1227,15 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj)
JsAppManager::KillProcessesByBundleName);
BindNativeFunction(env, exportObj, "clearUpApplicationData", moduleName,
JsAppManager::ClearUpApplicationData);
BindNativeFunction(env, exportObj, "getAppMemorySize", moduleName,
JsAppManager::GetAppMemorySize);
BindNativeFunction(env, exportObj, "isRamConstrainedDevice", moduleName,
JsAppManager::IsRamConstrainedDevice);
BindNativeFunction(env, exportObj, "isSharedBundleRunning", moduleName,
JsAppManager::IsSharedBundleRunning);
BindNativeFunction(env, exportObj, "getProcessMemoryByPid", moduleName,
JsAppManager::GetProcessMemoryByPid);
BindNativeFunction(env, exportObj, "getAppMemorySize", moduleName, JsAppManager::GetAppMemorySize);
BindNativeFunction(env, exportObj, "isRamConstrainedDevice", moduleName, JsAppManager::IsRamConstrainedDevice);
BindNativeFunction(env, exportObj, "isSharedBundleRunning", moduleName, JsAppManager::IsSharedBundleRunning);
BindNativeFunction(env, exportObj, "getProcessMemoryByPid", moduleName, JsAppManager::GetProcessMemoryByPid);
BindNativeFunction(env, exportObj, "getRunningProcessInfoByBundleName", moduleName,
JsAppManager::GetRunningProcessInfoByBundleName);
BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName,
JsAppManager::IsApplicationRunning);
BindNativeFunction(env, exportObj, "preloadApplication", moduleName,
JsAppManager::PreloadApplication);
BindNativeFunction(env, exportObj, "getRunningMultiAppInfo", moduleName, JsAppManager::GetRunningMultiAppInfo);
BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName, JsAppManager::IsApplicationRunning);
BindNativeFunction(env, exportObj, "preloadApplication", moduleName, JsAppManager::PreloadApplication);
BindNativeFunction(env, exportObj, "getRunningProcessInformationByBundleType", moduleName,
JsAppManager::GetRunningProcessInformationByBundleType);
TAG_LOGD(AAFwkTag::APPMGR, "end");
@@ -150,6 +150,47 @@ napi_value CreateJsRunningProcessInfo(napi_env env, const RunningProcessInfo &in
return object;
}
napi_value CreateJsRunningMultiAppInfo(napi_env env, const RunningMultiAppInfo &info)
{
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "bundleName", CreateJsValue(env, info.bundleName));
napi_set_named_property(env, object, "mode", CreateJsValue(env, info.mode));
napi_set_named_property(env, object, "runningAppClones", CreateJsRunningAppCloneArray(env, info.runningAppClones));
return object;
}
napi_value CreateJsRunningAppCloneArray(napi_env env, const std::vector<RunningAppClone>& data)
{
napi_value arrayValue = nullptr;
napi_create_array_with_length(env, data.size(), &arrayValue);
uint32_t index = 0;
for (const auto &item : data) {
napi_set_element(env, arrayValue, index++, CreateJsRunningAppClone(env, item));
}
return arrayValue;
}
napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info)
{
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "objValue nullptr.");
return nullptr;
}
napi_set_named_property(env, object, "appCloneIndex", CreateJsValue(env, info.appCloneIndex));
napi_set_named_property(env, object, "uid", CreateJsValue(env, info.uid));
napi_set_named_property(env, object, "pids", CreateNativeArray(env, info.pids));
return object;
}
napi_value ApplicationStateInit(napi_env env)
{
TAG_LOGD(AAFwkTag::APPMGR, "ApplicationStateInit enter");
@@ -19,6 +19,7 @@
#include "application_state_observer_stub.h"
#include "native_engine/native_engine.h"
#include "running_process_info.h"
#include "running_multi_info.h"
#ifdef SUPPORT_GRAPHICS
#include "ability_first_frame_state_data.h"
#endif
@@ -29,6 +30,8 @@ using OHOS::AppExecFwk::AppStateData;
using OHOS::AppExecFwk::AbilityStateData;
using OHOS::AppExecFwk::ProcessData;
using OHOS::AppExecFwk::RunningProcessInfo;
using OHOS::AppExecFwk::RunningMultiAppInfo;
using OHOS::AppExecFwk::RunningAppClone;
#ifdef SUPPORT_GRAPHICS
using OHOS::AppExecFwk::AbilityFirstFrameStateData;
#endif
@@ -63,6 +66,9 @@ bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv,
std::string &errorMsg);
JsAppProcessState ConvertToJsAppProcessState(
const AppExecFwk::AppProcessState &appProcessState, const bool &isFocused);
napi_value CreateJsRunningMultiAppInfo(napi_env env, const RunningMultiAppInfo &info);
napi_value CreateJsRunningAppCloneArray(napi_env env, const std::vector<RunningAppClone>& data);
napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_APP_MANAGER_UTILS_H
@@ -29,10 +29,10 @@ JSAppStateObserver::~JSAppStateObserver() = default;
void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData)
{
TAG_LOGD(AAFwkTag::APPMGR, "onForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
TAG_LOGD(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@@ -53,8 +53,7 @@ void JSAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appS
void JSAppStateObserver::HandleOnForegroundApplicationChanged(const AppStateData &appStateData)
{
TAG_LOGD(AAFwkTag::APPMGR,
"HandleOnForegroundApplicationChanged bundleName:%{public}s, uid:%{public}d, state:%{public}d",
TAG_LOGD(AAFwkTag::APPMGR, "bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
auto tmpMap = jsObserverObjectMap_;
for (auto &item : tmpMap) {
@@ -102,7 +101,7 @@ void JSAppStateObserver::OnExtensionStateChanged(const AbilityStateData &ability
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@@ -170,7 +169,7 @@ void JSAppStateObserver::OnProcessStateChanged(const ProcessData &processData)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@@ -204,7 +203,7 @@ void JSAppStateObserver::OnProcessDied(const ProcessData &processData)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@@ -239,7 +238,7 @@ void JSAppStateObserver::OnAppStarted(const AppStateData &appStateData)
TAG_LOGD(AAFwkTag::APPMGR, "onAppStarted bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
@@ -279,7 +278,7 @@ void JSAppStateObserver::OnAppStopped(const AppStateData &appStateData)
TAG_LOGD(AAFwkTag::APPMGR, "OnAppStopped bundleName:%{public}s, uid:%{public}d, state:%{public}d",
appStateData.bundleName.c_str(), appStateData.uid, appStateData.state);
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destoryed");
TAG_LOGE(AAFwkTag::APPMGR, "the app manager may has destroyed");
return;
}
wptr<JSAppStateObserver> jsObserver = this;
+1
View File
@@ -32,6 +32,7 @@ ohos_shared_library("apprecovery_napi") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -16,13 +16,13 @@
class AsyncTaskCallback {
private __impl__: AsyncTaskCallback;
constructor(object) {
"use sendable"
'use sendable';
this.__impl__ = object;
}
onAsyncTaskCompleted(startupName) {
onAsyncTaskCompleted(startupName, startupResult) {
console.log('AsyncTaskCallback onAsyncTaskCompleted called, startupName: ' + startupName);
this.__impl__.onAsyncTaskCompleted(startupName);
this.__impl__.onAsyncTaskCompleted(startupName, startupResult);
}
}
@@ -13,26 +13,34 @@
* limitations under the License.
*/
function concurrentFunc(startup, asyncCallback, context, startupName) {
"use concurrent";
async function concurrentFunc(startup, asyncCallback, context, startupName) {
'use concurrent';
console.log('concurrentFunc start.');
let taskPool = requireNapi('taskpool');
startup.init(context);
taskPool.Task.sendData(asyncCallback, startupName);
let startupResult;
await startup.init(context).then((result: Object) => {
startupResult = result
let taskPool = requireNapi('taskpool');
taskPool.Task.sendData(asyncCallback, startupName, startupResult);
});
console.log('concurrentFunc end.');
}
function receiveResult(asyncCallback, startupName) {
function receiveResult(asyncCallback, startupName, startupResult) {
console.log('receiveResult called.');
asyncCallback.onAsyncTaskCompleted(startupName);
asyncCallback.onAsyncTaskCompleted(startupName, startupResult);
console.log('receiveResult end.');
}
function pushTask(startup, asyncCallback, context, startupName) {
console.log('pushTask start.');
let taskPool = requireNapi('taskpool');
let task = new taskPool.Task(concurrentFunc, startup, asyncCallback, context, startupName);
task.onReceiveData(receiveResult);
taskPool.execute(task);
try {
let task = new taskPool.Task(concurrentFunc, startup, asyncCallback, context, startupName);
task.onReceiveData(receiveResult);
taskPool.execute(task);
} catch (error) {
console.log('new taskPool failed message:' + error);
}
console.log('pushTask end.');
}
@@ -14,8 +14,8 @@
*/
class StartupTask {
constructor () {
"use sendable"
constructor() {
'use sendable';
}
onDependenceCompleted(dependence, result) {
@@ -13,7 +13,6 @@
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//foundation/arkui/ace_engine/ace_config.gni")
ohos_shared_library("autofillmanager_napi") {
sources = [
@@ -53,13 +53,15 @@ napi_value JsAutoFillManager::OnRequestAutoSave(napi_env env, NapiCallbackInfo &
napi_value instanceIdValue = nullptr;
if (napi_get_named_property(env, info.argv[INDEX_ZERO], "instanceId_", &instanceIdValue) != napi_ok) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Get function by name failed.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM),
"Parameter error. Get instance id failed.");
return CreateJsUndefined(env);
}
int32_t instanceId = -1;
if (!ConvertFromJsValue(env, instanceIdValue, instanceId)) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Failed to parse type.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM),
"Parameter error. Parse instance id failed.");
return CreateJsUndefined(env);
}
@@ -81,7 +83,8 @@ napi_value JsAutoFillManager::OnRequestAutoSave(napi_env env, NapiCallbackInfo &
if (info.argc != ARGC_ONE) {
if (!CheckTypeForNapiValue(env, info.argv[INDEX_ONE], napi_object)) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Second input parameter error.");
ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM);
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM),
"Parameter error. The second parameter is not of type callback.");
return CreateJsUndefined(env);
}
saveCallback->Register(info.argv[INDEX_ONE]);
+3 -4
View File
@@ -51,10 +51,9 @@ class BusinessError extends Error {
class ThrowInvalidParamError extends Error {
constructor(msg) {
let code = ERROR_CODE_INVALID_PARAM;
let oriMsg = ERROR_MSG_INVALID_PARAM;
super(code);
this.msg = oriMsg + msg;
let message = ERROR_MSG_INVALID_PARAM + msg;
super(message);
this.code = ERROR_CODE_INVALID_PARAM;
}
}
+3 -4
View File
@@ -48,10 +48,9 @@ class BusinessError extends Error {
class ThrowInvalidParamError extends Error {
constructor(msg) {
let code = ERROR_CODE_INVALID_PARAM;
let oriMsg = ERROR_MSG_INVALID_PARAM;
super(code);
this.msg = oriMsg + msg;
let message = ERROR_MSG_INVALID_PARAM + msg;
super(message);
this.code = ERROR_CODE_INVALID_PARAM;
}
}
+2 -2
View File
@@ -13,7 +13,6 @@
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//foundation/distributeddatamgr/relational_store/relational_store.gni")
ohos_shared_library("featureability") {
include_dirs = [ "./" ]
@@ -28,6 +27,7 @@ ohos_shared_library("featureability") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
@@ -37,7 +37,6 @@ ohos_shared_library("featureability") {
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:data_ability_helper",
"${ability_runtime_native_path}/appkit:appkit_native",
"//third_party/libuv:uv",
]
external_deps = [
@@ -50,6 +49,7 @@ ohos_shared_library("featureability") {
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"libuv:uv",
"napi:ace_napi",
]
@@ -48,14 +48,6 @@ CallbackInfo g_aceCallbackInfo;
const int PARA_SIZE_IS_ONE = 1;
const int PARA_SIZE_IS_TWO = 2;
/**
* @brief FeatureAbility NAPI module registration.
*
* @param env The environment that the Node-API call is invoked under.
* @param exports An empty object via the exports parameter as a convenience.
*
* @return The return value from Init is treated as the exports object for the module.
*/
napi_value FeatureAbilityInit(napi_env env, napi_value exports)
{
TAG_LOGD(AAFwkTag::FA, "called");
@@ -441,14 +433,6 @@ napi_value JsFeatureAbility::OnGetWindow(napi_env env, napi_callback_info info)
}
#endif
/**
* @brief FeatureAbility NAPI method : setResult.
*
* @param env The environment that the Node-API call is invoked under.
* @param info The callback info passed into the callback function.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value NAPI_SetResult(napi_env env, napi_callback_info info)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
@@ -471,14 +455,6 @@ napi_value NAPI_SetResult(napi_env env, napi_callback_info info)
return ret;
}
/**
* @brief SetResult processing function.
*
* @param env The environment that the Node-API call is invoked under.
* @param asyncCallbackInfo Process data asynchronously.
*
* @return Return JS data successfully, otherwise return nullptr.
*/
napi_value SetResultWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
@@ -633,16 +609,6 @@ napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo)
}
EXTERN_C_START
/**
* @brief The interface of onAbilityResult provided for ACE to call back to JS.
*
* @param requestCode Indicates the request code returned after the ability is started.
* @param resultCode Indicates the result code returned after the ability is started.
* @param resultData Indicates the data returned after the ability is started.
* @param cb The environment and call back info that the Node-API call is invoked under.
*
* @return The return value from NAPI C++ to JS for the module.
*/
void CallOnAbilityResult(int requestCode, int resultCode, const Want &resultData, CallbackInfo callbackInfo)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
@@ -758,15 +724,6 @@ bool InnerUnwrapWant(napi_env env, napi_value args, Want &want)
return UnwrapWant(env, jsWant, want);
}
/**
* @brief Parse the parameters.
*
* @param param Indicates the parameters saved the parse result.
* @param env The environment that the Node-API call is invoked under.
* @param args Indicates the arguments passed into the callback.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value UnwrapForResultParam(CallAbilityParam &param, napi_env env, napi_value args)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
@@ -804,15 +761,6 @@ napi_value UnwrapForResultParam(CallAbilityParam &param, napi_env env, napi_valu
return result;
}
/**
* @brief Parse the abilityResult parameters.
*
* @param param Indicates the want parameters saved the parse result.
* @param env The environment that the Node-API call is invoked under.
* @param args Indicates the arguments passed into the callback.
*
* @return The return value from NAPI C++ to JS for the module.
*/
napi_value UnwrapAbilityResult(CallAbilityParam &param, napi_env env, napi_value args)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s,called", __func__);
@@ -23,14 +23,6 @@
namespace OHOS {
namespace AppExecFwk {
/**
* @brief FeatureAbilityConstantInit NAPI module registration.
*
* @param env The environment that the Node-API call is invoked under.
* @param exports An empty object via the exports parameter as a convenience.
*
* @return The return value from Init is treated as the exports object for the module.
*/
napi_value FAConstantInit(napi_env env, napi_value exports)
{
const int Window_Configuration_Zero = 100;
@@ -263,7 +263,7 @@ void AnalysisValuesBucket(NativeRdb::ValuesBucket &valuesBucket, const napi_env
uint32_t arrLen = 0;
napi_status status = napi_get_array_length(env, keys, &arrLen);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::FA, "ValuesBucket errr");
TAG_LOGE(AAFwkTag::FA, "ValuesBucket error");
return;
}
TAG_LOGI(AAFwkTag::FA, "ValuesBucket num:%{public}d ", arrLen);
@@ -419,7 +419,7 @@ void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data)
void InsertPromiseCompleteCB(napi_env env, napi_status status, void *data)
{
TAG_LOGI(AAFwkTag::FA, "NAPI_Insert, main event thread complete.");
TAG_LOGI(AAFwkTag::FA, "NAPI_Insert, main event thread complete.");
DAHelperInsertCB *insertCB = static_cast<DAHelperInsertCB *>(data);
napi_value result = nullptr;
napi_create_int32(env, insertCB->result, &result);
@@ -103,7 +103,7 @@ napi_value BuildDataAbilityOperation(
UnwrapDataAbilityPredicates(*predicates, env, jsPredicates);
builder->WithPredicates(predicates);
// get expectedcount property
// get expectedCount property
int expectedCount = 0;
UnwrapInt32ByPropertyName(env, param, "expectedCount", expectedCount);
TAG_LOGI(AAFwkTag::FA, "%{public}s, expectedCount:%{public}d", __func__, expectedCount);
@@ -32,6 +32,7 @@ ohos_shared_library("napi_ability_common") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -15,6 +15,7 @@
#ifndef OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H
#define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_COMMON_H
#include "ability.h"
#include "ability_info.h"
#include "application_info.h"
@@ -15,6 +15,7 @@
#ifndef OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_COMMON_H
#define OHOS_ABILITY_RUNTIME_JS_FEATURE_ABILITY_COMMON_H
#include "ability.h"
#include "ability_info.h"
#include "abs_shared_result_set.h"
@@ -127,7 +127,7 @@ public:
napi_value CreateAbilityInfos(napi_env env, const std::vector<AbilityInfo> &abilityInfos);
napi_value CreateAppVersionInfo(napi_env env, const std::shared_ptr<JsApplicationInfo> &appInfo);
napi_value CreateWant(napi_env env, const std::shared_ptr<JsWant> &want);
bool UnwarpVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options);
bool UnwrapVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options);
bool GetStringsValue(napi_env env, napi_value object, std::vector<std::string> &strList);
bool GetPermissionOptions(napi_env env, napi_value object, JsPermissionOptions &options);
void AddFreeInstallObserver(napi_env env, const AAFwk::Want &want, napi_value callback, napi_value* result);
@@ -2991,20 +2991,20 @@ napi_value GetAbilityNameWrap(napi_env env, napi_callback_info info, AbilityName
napi_value NAPI_GetAbilityNameCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
AbilityNameCB *ablityNameCB = CreateAbilityNameCBInfo(env);
if (ablityNameCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ablityNameCB == nullptr", __func__);
AbilityNameCB *abilityNameCB = CreateAbilityNameCBInfo(env);
if (abilityNameCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s abilityNameCB == nullptr", __func__);
return WrapVoidToJS(env);
}
ablityNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR;
ablityNameCB->cbBase.abilityType = abilityType;
napi_value ret = GetAbilityNameWrap(env, info, ablityNameCB);
abilityNameCB->cbBase.errCode = NAPI_ERR_NO_ERROR;
abilityNameCB->cbBase.abilityType = abilityType;
napi_value ret = GetAbilityNameWrap(env, info, abilityNameCB);
if (ret == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullptr", __func__);
if (ablityNameCB != nullptr) {
delete ablityNameCB;
ablityNameCB = nullptr;
if (abilityNameCB != nullptr) {
delete abilityNameCB;
abilityNameCB = nullptr;
}
ret = WrapVoidToJS(env);
}
@@ -3131,7 +3131,7 @@ bool UnwrapParamForWant(napi_env env, napi_value args, AbilityType, CallAbilityP
if (jsSettingObj != nullptr) {
param.setting = AbilityStartSetting::GetEmptySetting();
if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, unwrap abilityStartSetting falied.", __func__);
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, unwrap abilityStartSetting failed.", __func__);
}
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s abilityStartSetting", __func__);
}
@@ -3743,7 +3743,7 @@ void StartBackgroundRunningExecuteCB(napi_env env, void *data)
}
const std::shared_ptr<AbilityInfo> info = asyncCallbackInfo->ability->GetAbilityInfo();
if (info == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "abilityinfo is null");
TAG_LOGE(AAFwkTag::JSNAPI, "ability info is null");
asyncCallbackInfo->errCode = NAPI_ERR_ACE_ABILITY;
return;
}
@@ -3900,7 +3900,7 @@ napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info in
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullpter", __func__);
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullptr", __func__);
return WrapVoidToJS(env);
}
@@ -4018,14 +4018,14 @@ napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info i
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
AsyncCallbackInfo *asyncCallbackInfo = CreateAsyncCallbackInfo(env);
if (asyncCallbackInfo == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullpter", __func__);
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s asyncCallbackInfo == nullptr", __func__);
return WrapVoidToJS(env);
}
asyncCallbackInfo->errCode = NAPI_ERR_NO_ERROR;
napi_value ret = CancelBackgroundRunningWrap(env, info, asyncCallbackInfo);
if (ret == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullpter", __func__);
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s ret == nullptr", __func__);
if (asyncCallbackInfo != nullptr) {
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
@@ -4119,7 +4119,7 @@ napi_value JsNapiCommon::JsConnectAbility(napi_env env, napi_callback_info info,
connectionCallback->Reset();
RemoveConnectionLocked(want);
}
// free failedcallback here, avoid possible multi-threading problems when disconnect success
// free failed callback here, avoid possible multi-threading problems when disconnect success
napi_delete_reference(env, connectionCallback->failedCallbackRef);
connectionCallback->failedCallbackRef = nullptr;
return CreateJsValue(env, id);
@@ -4454,7 +4454,7 @@ napi_value JsNapiCommon::JsGetCacheDir(napi_env env, napi_callback_info info, co
auto context = obj->ability_->GetAbilityContext();
if (context == nullptr) {
*value = static_cast<int32_t>(NAPI_ERR_ABILITY_CALL_INVALID);
TAG_LOGE(AAFwkTag::JSNAPI, "JsGetCacheDir task execute error, the abilitycontext is nullptr");
TAG_LOGE(AAFwkTag::JSNAPI, "JsGetCacheDir task execute error, the ability context is nullptr");
return;
}
dir->name = context->GetCacheDir();
@@ -4706,7 +4706,7 @@ napi_value JsNapiCommon::JsGetOrCreateDistributedDir(
auto context = obj->ability_->GetAbilityContext();
if (context == nullptr) {
*value = static_cast<int32_t>(NAPI_ERR_ACE_ABILITY);
TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the abilitycontext is nullptr");
TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the ability context is nullptr");
return;
}
dir->name = context->GetDistributedFilesDir();
@@ -5041,7 +5041,7 @@ napi_value JsNapiCommon::CreateAppVersionInfo(napi_env env, const std::shared_pt
return objContext;
}
bool JsNapiCommon::UnwarpVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options)
bool JsNapiCommon::UnwrapVerifyPermissionParams(napi_env env, napi_callback_info info, JsPermissionOptions &options)
{
bool flagCall = true;
size_t argc = ARGS_MAX_COUNT;
@@ -2879,12 +2879,12 @@ static napi_value ConstructNapiJSContext(napi_env env)
TAG_LOGE(AAFwkTag::JSNAPI, "CreateObject failed");
return nullptr;
}
auto jsCalss = std::make_unique<NapiJsContext>();
if (!jsCalss->DataInit(env)) {
auto jsClass = std::make_unique<NapiJsContext>();
if (!jsClass->DataInit(env)) {
TAG_LOGE(AAFwkTag::JSNAPI, "NapiJsContext init failed");
return nullptr;
}
napi_wrap(env, objContext, jsCalss.release(), NapiJsContext::Finalizer, nullptr, nullptr);
napi_wrap(env, objContext, jsClass.release(), NapiJsContext::Finalizer, nullptr, nullptr);
napi_set_named_property(env, objContext, "stageMode", CreateJsValue(env, false));
if (!BindNapiJSContextFunction(env, objContext)) {
TAG_LOGE(AAFwkTag::JSNAPI, "bind func failed");
@@ -3318,7 +3318,7 @@ napi_value NapiJsContext::OnVerifyPermission(napi_env env, napi_callback_info in
return CreateJsNull(env);
}
JsPermissionOptions options;
bool flagCall = UnwarpVerifyPermissionParams(env, info, options);
bool flagCall = UnwrapVerifyPermissionParams(env, info, options);
auto execute = [obj = this, permission, options, value = errorVal] () {
if (obj->ability_ == nullptr) {
*value = static_cast<int32_t>(NAPI_ERR_ACE_ABILITY);
@@ -3599,7 +3599,7 @@ napi_value NapiJsContext::OnGetOrCreateLocalDir(napi_env env, napi_callback_info
auto context = obj->ability_->GetAbilityContext();
if (context == nullptr || dir == nullptr) {
*value = static_cast<int32_t>(NAPI_ERR_ABILITY_CALL_INVALID);
TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the abilitycontext is nullptr");
TAG_LOGE(AAFwkTag::JSNAPI, "task execute error, the ability context is nullptr");
return;
}
dir->name = context->GetBaseDir();
@@ -42,9 +42,9 @@ ohos_shared_library("napi_common") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:process_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"//third_party/libuv:uv",
]
external_deps = [
@@ -57,6 +57,7 @@ ohos_shared_library("napi_common") {
"hilog:libhilog",
"ipc:ipc_core",
"ipc:ipc_napi",
"libuv:uv",
"napi:ace_napi",
]
@@ -36,7 +36,7 @@ bool UnwrapExecuteResult(napi_env env, napi_value param, InsightIntentExecuteRes
}
int32_t code = 0;
if (!UnwrapInt32ByPropertyName(env, param, "code", code)) {
TAG_LOGE(AAFwkTag::JSNAPI, "Intent result must contian a code.");
TAG_LOGE(AAFwkTag::JSNAPI, "Intent result must contain a code.");
return false;
}
executeResult.code = code;
@@ -46,6 +46,9 @@ bool UnwrapOpenLinkOptions(napi_env env, napi_value param, AAFwk::OpenLinkOption
openLinkOptions.SetAppLinkingOnly(appLinkingOnly);
want.SetParam(APP_LINKING_ONLY, appLinkingOnly);
}
if (!want.HasParameter(APP_LINKING_ONLY)) {
want.SetParam(APP_LINKING_ONLY, false);
}
return true;
}
@@ -25,6 +25,7 @@ ohos_shared_library("insightintentdriver_napi") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:ability_business_error",
@@ -105,8 +105,8 @@ private:
auto requestInfo = new RequestInfo(callerToken, left, top, width, height);
auto jsRequestInfo = RequestInfo::WrapRequestInfo(env, requestInfo);
if (jsRequestInfo == nullptr) {
TAG_LOGE(AAFwkTag::DIALOG, "Can not wrap requestinfo from target request.");
ThrowInvalidParamError(env, "Parameter error: Can not wrap requestinfo from target request.");
TAG_LOGE(AAFwkTag::DIALOG, "Can not wrap request info from target request.");
ThrowInvalidParamError(env, "Parameter error: Can not wrap request info from target request.");
return CreateJsUndefined(env);
}
@@ -27,11 +27,10 @@ ohos_shared_library("dialogsession_napi") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/appkit:app_context",
"//third_party/json:nlohmann_json_static",
"//third_party/jsoncpp:jsoncpp",
]
external_deps = [
@@ -45,6 +44,8 @@ ohos_shared_library("dialogsession_napi") {
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"json:nlohmann_json_static",
"jsoncpp:jsoncpp",
"napi:ace_napi",
"samgr:samgr_proxy",
]
@@ -66,6 +66,8 @@ napi_value WrapDialogAbilityInfo(napi_env env, const AAFwk::DialogAbilityInfo &d
SetPropertyValueByPropertyName(env, jsObject, "abilityIconId", jsValue);
jsValue = WrapInt32ToJS(env, dialogAbilityInfo.abilityLabelId);
SetPropertyValueByPropertyName(env, jsObject, "abilityLabelId", jsValue);
jsValue = WrapBoolToJS(env, dialogAbilityInfo.visible);
SetPropertyValueByPropertyName(env, jsObject, "visible", jsValue);
return jsObject;
}
@@ -28,6 +28,7 @@ ohos_shared_library("missionmanager") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -46,9 +47,9 @@ ohos_shared_library("missionmanager") {
]
if (ability_runtime_graphics) {
include_dirs += [ "//third_party/icu/icu4c/source/common" ]
external_deps += [
"graphic_2d:color_manager",
"icu:shared_icuuc",
"image_framework:image",
]
defines = [ "SUPPORT_GRAPHICS" ]
@@ -265,7 +265,7 @@ private:
napi_value lastParam = (argc <= ARG_COUNT_TWO) ? nullptr : argv[INDEX_TWO];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnUnregisterMissionListener",
NapiAsyncTask::Schedule("MissionManager::OnUnregisterMissionListener",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -350,7 +350,7 @@ private:
napi_value lastParam = (argc <= 2) ? nullptr : argv[2];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfos",
NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfos",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -390,7 +390,7 @@ private:
napi_value lastParam = (argc <= 2) ? nullptr : argv[2];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfo",
NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfo",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -423,7 +423,7 @@ private:
};
std::shared_ptr<MissionSnapshotWrap> snapshotWrap = std::make_shared<MissionSnapshotWrap>();
auto excute = [deviceId, missionId, isLowResolution, snapshotWrap]() {
auto execute = [deviceId, missionId, isLowResolution, snapshotWrap]() {
snapshotWrap->result = AbilityManagerClient::GetInstance()->GetMissionSnapshot(
deviceId, missionId, snapshotWrap->missionSnapshot, isLowResolution);
};
@@ -452,8 +452,8 @@ private:
};
napi_value lastParam = (argc > ARG_COUNT_TWO) ? argv[ARG_COUNT_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnGetMissionSnapShot",
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(excute), std::move(complete), &result));
NapiAsyncTask::Schedule("MissionManager::OnGetMissionSnapShot",
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
return result;
}
@@ -508,7 +508,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnLockMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnLockMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -541,7 +541,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnUnlockMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnUnlockMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -574,7 +574,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnClearMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnClearMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -595,7 +595,7 @@ private:
napi_value lastParam = (argc > 0) ? argv[0] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -636,7 +636,7 @@ private:
napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -694,7 +694,7 @@ private:
napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionsToForeground", env,
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionsToForeground", env,
CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -748,7 +748,7 @@ private:
napi_value lastParam = (argc <= 1) ? nullptr : argv[1];
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionsToBackground",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionsToBackground",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
+6 -5
View File
@@ -28,6 +28,7 @@ ohos_shared_library("missionmanager_napi") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -45,9 +46,9 @@ ohos_shared_library("missionmanager_napi") {
]
if (ability_runtime_graphics) {
include_dirs += [ "//third_party/icu/icu4c/source/common" ]
external_deps += [
"graphic_2d:color_manager",
"icu:shared_icuuc",
"image_framework:image",
]
defines = [ "SUPPORT_GRAPHICS" ]
@@ -60,10 +61,7 @@ ohos_shared_library("missionmanager_napi") {
}
ohos_shared_library("distributedmissionmanager") {
include_dirs = [
"//third_party/libuv/include",
"//third_party/node/src",
]
include_dirs = []
configs = [ "${ability_runtime_services_path}/common:common_config" ]
@@ -81,6 +79,7 @@ ohos_shared_library("distributedmissionmanager") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -96,7 +95,9 @@ ohos_shared_library("distributedmissionmanager") {
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"libuv:uv",
"napi:ace_napi",
"node:node_header_notice",
"samgr:samgr_proxy",
]
@@ -2066,6 +2066,7 @@ void UvWorkOnContinueDone(uv_work_t *work, int status)
result = WrapInt32(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->resultCode, "code");
}
if (continueAbilityCB->cbBase.deferred == nullptr) {
std::lock_guard<std::mutex> autoLock(registrationLock_);
napi_value callback = nullptr;
napi_value undefined = nullptr;
napi_get_undefined(continueAbilityCB->cbBase.cbInfo.env, &undefined);
@@ -2075,6 +2076,7 @@ void UvWorkOnContinueDone(uv_work_t *work, int status)
napi_call_function(continueAbilityCB->cbBase.cbInfo.env, undefined, callback, 1, &result, &callResult);
if (continueAbilityCB->cbBase.cbInfo.callback != nullptr) {
napi_delete_reference(continueAbilityCB->cbBase.cbInfo.env, continueAbilityCB->cbBase.cbInfo.callback);
continueAbilityCB->cbBase.cbInfo.callback = nullptr;
}
} else {
napi_value result[2] = { nullptr };
@@ -182,7 +182,7 @@ private:
napi_value lastParam = (argc <= 1) ? nullptr : argv[1];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnUnregisterMissionListener",
NapiAsyncTask::Schedule("MissionManager::OnUnregisterMissionListener",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -222,7 +222,7 @@ private:
napi_value lastParam = (argc <= 2) ? nullptr : argv[2];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfos",
NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfos",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -262,7 +262,7 @@ private:
napi_value lastParam = (argc <= 2) ? nullptr : argv[2];
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::OnGetMissionInfo",
NapiAsyncTask::Schedule("MissionManager::OnGetMissionInfo",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -323,7 +323,7 @@ private:
};
napi_value lastParam = (argc > ARG_COUNT_TWO) ? argv[ARG_COUNT_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("MissioManager::GetMissionSnapShot",
NapiAsyncTask::Schedule("MissionManager::GetMissionSnapShot",
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(excute), std::move(complete), &result));
return result;
}
@@ -379,7 +379,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnLockMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnLockMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -412,7 +412,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnUnlockMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnUnlockMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -445,7 +445,7 @@ private:
napi_value lastParam = (argc > 1) ? argv[1] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnClearMission",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnClearMission",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -466,7 +466,7 @@ private:
napi_value lastParam = (argc > 0) ? argv[0] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
@@ -507,7 +507,7 @@ private:
napi_value lastParam = (argc > unwrapArgc) ? argv[unwrapArgc] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("MissioManager::OnMoveMissionToFront",
NapiAsyncTask::ScheduleHighQos("MissionManager::OnMoveMissionToFront",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
}
+4 -6
View File
@@ -13,15 +13,11 @@
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//foundation/distributeddatamgr/relational_store/relational_store.gni")
ohos_shared_library("particleability") {
include_dirs = [
"//third_party/node/src",
"${ability_runtime_napi_path}/featureAbility",
"${ability_runtime_services_path}/common/include",
"//third_party/jsoncpp",
"//third_party/jsoncpp/include/json",
]
sources = [
@@ -35,6 +31,7 @@ ohos_shared_library("particleability") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -44,8 +41,6 @@ ohos_shared_library("particleability") {
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:data_ability_helper",
"${ability_runtime_native_path}/appkit:appkit_native",
"//third_party/jsoncpp:jsoncpp",
"//third_party/libuv:uv",
]
external_deps = [
@@ -58,7 +53,10 @@ ohos_shared_library("particleability") {
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"jsoncpp:jsoncpp",
"libuv:uv",
"napi:ace_napi",
"node:node_header_notice",
]
if (ability_runtime_relational) {
@@ -175,7 +175,7 @@ private:
napi_value CreateJsUriPermMgr(napi_env env, napi_value exportObj)
{
TAG_LOGI(AAFwkTag::URIPERMMGR, "CreateJsUriPermMgr is called");
TAG_LOGD(AAFwkTag::URIPERMMGR, "CreateJsUriPermMgr is called");
if (env == nullptr || exportObj == nullptr) {
TAG_LOGI(AAFwkTag::URIPERMMGR, "Invalid input parameters");
return nullptr;
+3 -3
View File
@@ -16,9 +16,7 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_shared_library("wantagent") {
include_dirs = [
"//third_party/node/src",
"${ability_runtime_services_path}/common/include",
"//third_party/libuv/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
"${ability_runtime_services_path}/abilitymgr/include",
"./",
@@ -30,7 +28,7 @@ ohos_shared_library("wantagent") {
]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits",
@@ -46,7 +44,9 @@ ohos_shared_library("wantagent") {
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"ipc:ipc_core",
"libuv:uv",
"napi:ace_napi",
"node:node_header_notice",
]
relative_install_dir = "module"
@@ -16,9 +16,7 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_shared_library("wantagent_napi") {
include_dirs = [
"//third_party/node/src",
"${ability_runtime_services_path}/common/include",
"//third_party/libuv/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
"${ability_runtime_services_path}/abilitymgr/include",
"./",
@@ -31,7 +29,7 @@ ohos_shared_library("wantagent_napi") {
]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits",
@@ -47,7 +45,9 @@ ohos_shared_library("wantagent_napi") {
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"ipc:ipc_core",
"libuv:uv",
"napi:ace_napi",
"node:node_header_notice",
]
relative_install_dir = "module/app/ability"
+5 -2
View File
@@ -24,7 +24,6 @@ config("ability_context_public_config") {
"${user_file_service_innerkits_path}/file_access/*",
]
include_dirs = [
"${ability_base_kits_path}/extractortool/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime/context",
@@ -61,6 +60,7 @@ ohos_shared_library("ability_context_native") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
@@ -83,7 +83,10 @@ ohos_shared_library("ability_context_native") {
"ipc:ipc_core",
"napi:ace_napi",
]
public_external_deps = [
"ability_base:extractortool",
"background_task_mgr:bgtaskmgr_innerkits",
]
if (ability_runtime_graphics) {
external_deps += [
"ace_engine:ace_uicontent",
@@ -255,8 +255,7 @@ void ConnectionManager::DisconnectNonexistentService(
for (auto &&abilityConnection : abilityConnections) {
ConnectionInfo connectionInfo = abilityConnection.first;
if (connectionInfo.abilityConnection == connection &&
connectionInfo.connectReceiver.GetBundleName() == element.GetBundleName() &&
connectionInfo.connectReceiver.GetAbilityName() == element.GetAbilityName()) {
connectionInfo.connectReceiver.GetBundleName() == element.GetBundleName()) {
HILOG_DEBUG("find connection.");
exit = true;
break;
+64 -47
View File
@@ -13,7 +13,6 @@
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
import("//foundation/distributeddatamgr/relational_store/relational_store.gni")
config("ability_config") {
visibility = [ ":*" ]
@@ -38,9 +37,7 @@ config("ability_config") {
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${form_fwk_path}/interfaces/kits/native/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"//third_party/node/src",
"${ability_runtime_innerkits_path}/ability_manager/include/continuation",
"${ability_runtime_path}/interfaces/kits/native/appkit/app/task",
"${ability_runtime_napi_path}/inner/napi_common",
@@ -89,12 +86,9 @@ config("ability_public_config") {
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/recovery/",
"${accessibility_path}/interfaces/innerkits/common/include/",
"//third_party/libuv/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_innerkits_path}/ability_manager/include/continuation",
"${ability_runtime_services_path}/common/include",
"//third_party/jsoncpp/include",
"//third_party/json/include",
]
@@ -121,19 +115,10 @@ config("abilitykit_utils_public_config") {
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
"//third_party/jsoncpp/include",
"//third_party/json/include",
]
if (ability_runtime_graphics) {
include_dirs += [
"${form_fwk_path}/interfaces/inner_api/include",
"${graphic_path}/utils/color_manager/export",
"${multimedia_path}/interfaces/innerkits/include",
"${windowmanager_path}/interfaces/innerkits/wm",
"${windowmanager_path}/interfaces/innerkits/dm",
"${windowmanager_path}/utils/include",
]
defines = [ "SUPPORT_GRAPHICS" ]
}
}
@@ -162,7 +147,6 @@ ohos_shared_library("abilitykit_utils") {
"ability_base:configuration",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
@@ -172,15 +156,25 @@ ohos_shared_library("abilitykit_utils") {
"resource_management:global_resmgr",
]
public_external_deps = [ "bundle_framework:appexecfwk_core" ]
public_external_deps = [
"bundle_framework:appexecfwk_core",
"jsoncpp:jsoncpp",
"window_manager:libwm",
]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [
"ability_base:session_info",
"window_manager:libdm",
"icu:shared_icuuc",
"window_manager:libwm",
]
public_external_deps += [
"form_fwk:form_manager",
"graphic_2d:color_manager",
"image_framework:image_native",
"window_manager:libdm",
"window_manager:libwmutil",
]
}
innerapi_tags = [ "platformsdk" ]
@@ -189,13 +183,7 @@ ohos_shared_library("abilitykit_utils") {
}
ohos_shared_library("abilitykit_native") {
include_dirs = [
"${ability_base_kits_path}/extractortool/include",
"${ability_runtime_path}/utils/global/time/include",
"${relational_store_napi_path}/rdb/include",
"${relational_store_napi_path}/common/include",
"${relational_store_napi_path}/dataability/include",
]
include_dirs = [ "${ability_runtime_path}/utils/global/time/include" ]
sources = [
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_info.cpp",
@@ -241,6 +229,7 @@ ohos_shared_library("abilitykit_native") {
":continuation_ipc",
":extension_blocklist_config",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
@@ -262,6 +251,7 @@ ohos_shared_library("abilitykit_native") {
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:extractortool",
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
@@ -279,12 +269,18 @@ ohos_shared_library("abilitykit_native") {
"ipc:ipc_napi",
"ipc:rpc",
"napi:ace_napi",
"node:node_header_notice",
"relational_store:native_rdb",
"resource_management:global_resmgr",
"samgr:samgr_proxy",
]
public_external_deps = [ "bundle_framework:appexecfwk_core" ]
public_external_deps = [
"accessibility:accessibility_common",
"bundle_framework:appexecfwk_core",
"jsoncpp:jsoncpp",
"libuv:uv",
]
defines = []
@@ -310,11 +306,11 @@ ohos_shared_library("abilitykit_native") {
"${ability_runtime_native_path}/ability/native/ability_window.cpp",
"${ability_runtime_native_path}/ability/native/page_ability_impl.cpp",
]
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [
"ability_base:session_info",
"form_fwk:form_manager",
"icu:shared_icuuc",
"image_framework:image",
"image_framework:image",
"image_framework:image_native",
@@ -342,17 +338,12 @@ config("extensionkit_public_config") {
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
"//third_party/jsoncpp/include",
"//third_party/json/include",
]
if (ability_runtime_graphics) {
include_dirs += [
"${form_fwk_path}/interfaces/inner_api/include",
"${graphic_path}/utils/color_manager/export",
"${multimedia_path}/interfaces/innerkits/include",
"${windowmanager_path}/interfaces/innerkits/wm",
"${windowmanager_path}/interfaces/innerkits/dm",
"${windowmanager_path}/utils/include",
]
defines = [ "SUPPORT_GRAPHICS" ]
@@ -383,6 +374,7 @@ ohos_shared_library("extensionkit_native") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -400,10 +392,19 @@ ohos_shared_library("extensionkit_native") {
public_deps = [ ":abilitykit_utils" ]
public_external_deps = [ "bundle_framework:appexecfwk_core" ]
public_external_deps = [
"bundle_framework:appexecfwk_core",
"jsoncpp:jsoncpp",
]
if (ability_runtime_graphics) {
external_deps += [ "ability_base:session_info" ]
public_external_deps += [
"form_fwk:form_manager",
"graphic_2d:color_manager",
"image_framework:image_native",
"window_manager:libdm",
]
}
innerapi_tags = [ "platformsdk" ]
@@ -427,6 +428,7 @@ ohos_shared_library("insight_intent_executor") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:ability_business_error",
@@ -462,19 +464,11 @@ config("uiability_config") {
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_services_path}/abilitymgr/include",
"${arkui_path}/napi",
"${arkui_path}/napi/interfaces/kits",
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
"//third_party/libuv/include",
"//third_party/node/src",
]
if (ability_runtime_graphics) {
include_dirs += [
"${form_fwk_path}/interfaces/inner_api/include",
"${graphic_path}/utils/color_manager/export",
"${multimedia_path}/interfaces/innerkits/include",
"${windowmanager_path}/interfaces/innerkits/dm",
"${windowmanager_path}/interfaces/innerkits/wm",
"${windowmanager_path}/utils/include",
]
@@ -509,6 +503,7 @@ ohos_shared_library("uiabilitykit_native") {
":continuation_ipc",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/ability_manager:process_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -534,21 +529,29 @@ ohos_shared_library("uiabilitykit_native") {
"hitrace:hitrace_meter",
"ipc:ipc_core",
"ipc:ipc_napi",
"napi:ace_napi",
"resource_management:global_resmgr",
]
public_external_deps = [ "bundle_framework:appexecfwk_core" ]
public_external_deps = [
"bundle_framework:appexecfwk_core",
"libuv:uv",
"napi:ace_napi",
"node:node_header_notice",
]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [
"ability_base:session_info",
"window_manager:libdm",
"icu:shared_icuuc",
"window_manager:libwm",
"window_manager:libwsutils",
"window_manager:windowstage_kit",
]
public_external_deps += [
"form_fwk:form_manager",
"graphic_2d:color_manager",
"image_framework:image_native",
"window_manager:libdm",
]
}
innerapi_tags = [ "platformsdk" ]
@@ -574,6 +577,7 @@ ohos_shared_library("ability_thread") {
":extensionkit_native",
":uiabilitykit_native",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_native_path}/appkit:app_context",
@@ -705,6 +709,7 @@ ohos_shared_library("service_extension") {
deps = [
":abilitykit_native",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -734,6 +739,7 @@ ohos_shared_library("service_extension") {
external_deps += [
"image_framework:image",
"window_manager:libdm",
"window_manager:libwm",
]
}
@@ -769,6 +775,7 @@ ohos_shared_library("continuation_ipc") {
deps = [
":abilitykit_utils",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
]
external_deps = [
@@ -778,8 +785,13 @@ ohos_shared_library("continuation_ipc") {
"eventhandler:libeventhandler",
"hilog:libhilog",
"ipc:ipc_core",
"node:node_header_notice",
"resource_management:global_resmgr",
]
public_external_deps = [
"accessibility:accessibility_common",
"libuv:uv",
]
defines = []
@@ -977,6 +989,7 @@ ohos_shared_library("ui_extension") {
deps = [
":abilitykit_native",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -1066,6 +1079,7 @@ ohos_shared_library("share_extension") {
":abilitykit_native",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -1116,6 +1130,7 @@ ohos_shared_library("action_extension") {
":abilitykit_native",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -1317,6 +1332,7 @@ ohos_shared_library("embedded_ui_extension") {
":abilitykit_native",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
@@ -1410,6 +1426,7 @@ ohos_shared_library("auto_fill_extension") {
":insight_intent_executor",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
+1 -9
View File
@@ -72,7 +72,6 @@ const int Ability::DEFAULT_DMS_SESSION_ID(0);
const std::string LAUNCHER_BUNDLE_NAME = "com.ohos.launcher";
const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility";
const std::string SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen";
const std::string DLP_INDEX = "ohos.dlp.params.index";
const std::string DLP_PARAMS_SECURITY_FLAG = "ohos.dlp.params.securityFlag";
const std::string COMPONENT_STARTUP_NEW_RULES = "component.startup.newRules";
@@ -165,8 +164,6 @@ void Ability::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
return;
}
appIndex_ = want.GetIntParam(DLP_INDEX, 0);
(const_cast<Want &>(want)).RemoveParam(DLP_INDEX);
securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false);
(const_cast<Want &>(want)).RemoveParam(DLP_PARAMS_SECURITY_FLAG);
SetWant(want);
@@ -340,11 +337,6 @@ bool Ability::IsRestoredInContinuation() const
return false;
}
if (abilityContext_->GetContentStorage() == nullptr) {
TAG_LOGD(AAFwkTag::ABILITY, "not Restored In Continuation");
return false;
}
TAG_LOGD(AAFwkTag::ABILITY, "Is Restored In Continuation");
return true;
}
@@ -1657,7 +1649,7 @@ std::string Ability::GetContentInfo()
if (scene_ == nullptr) {
return "";
}
return scene_->GetContentInfo();
return scene_->GetContentInfo(Rosen::BackupAndRestoreType::CONTINUATION);
}
void Ability::OnWindowFocusChanged(bool hasFocus)
@@ -78,6 +78,10 @@ constexpr const char* ERROR_MSG_TARGET_BUNDLE_NOT_EXIST = "The target bundle doe
constexpr const char* ERROR_MSG_SET_SUPPORTED_PROCESS_CACHE_AGAIN = "Can not set process cache state more than once.";
constexpr const char* ERROR_MSG_NO_RESIDENT_PERMISSION =
"The caller application can only set the resident status of the configured process.";
constexpr const char* ERROR_MSG_MULTI_APP_NOT_SUPPORTED = "App clone or multi-instance is not supported.";
constexpr const char* ERROR_MSG_APP_CLONE_INDEX_INVALID =
"The target app clone with the specified index does not exist.";
constexpr const char* ERROR_MSG_NOT_APP_CLONE = "The target app is not Clone.";
// follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework
constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220;
@@ -131,6 +135,9 @@ static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
{ AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST },
{ AbilityErrorCode::ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN, ERROR_MSG_SET_SUPPORTED_PROCESS_CACHE_AGAIN },
{ AbilityErrorCode::ERROR_CODE_NO_RESIDENT_PERMISSION, ERROR_MSG_NO_RESIDENT_PERMISSION },
{ AbilityErrorCode::ERROR_CODE_MULTI_APP_NOT_SUPPORTED, ERROR_MSG_MULTI_APP_NOT_SUPPORTED },
{ AbilityErrorCode::ERROR_APP_CLONE_INDEX_INVALID, ERROR_MSG_APP_CLONE_INDEX_INVALID },
{ AbilityErrorCode::ERROR_NOT_APP_CLONE, ERROR_MSG_NOT_APP_CLONE },
};
static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP {
@@ -187,6 +194,8 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
{ERR_TARGET_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST},
{ERR_SET_SUPPORTED_PROCESS_CACHE_AGAIN, AbilityErrorCode::ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN},
{ERR_NO_RESIDENT_PERMISSION, AbilityErrorCode::ERROR_CODE_NO_RESIDENT_PERMISSION},
{ERR_MULTI_APP_NOT_SUPPORTED, AbilityErrorCode::ERROR_CODE_MULTI_APP_NOT_SUPPORTED},
{ERR_APP_CLONE_INDEX_INVALID, AbilityErrorCode::ERROR_APP_CLONE_INDEX_INVALID},
};
}
@@ -609,7 +609,7 @@ void JsAbility::RestorePageStack(const Want &want)
auto env = jsRuntime_.GetNapiEnv();
if (abilityContext_->GetContentStorage()) {
scene_->GetMainWindow()->NapiSetUIContent(pageStack, env,
abilityContext_->GetContentStorage()->GetNapiValue(), true);
abilityContext_->GetContentStorage()->GetNapiValue(), Rosen::BackupAndRestoreType::CONTINUATION);
} else {
TAG_LOGE(AAFwkTag::ABILITY, "restore: content storage is nullptr");
}
@@ -1174,7 +1174,7 @@ napi_value JsAbilityContext::OnConnectAbility(napi_env env, NapiCallbackInfo& in
// unwrap want
AAFwk::Want want;
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
TAG_LOGI(AAFwkTag::CONTEXT, "ConnectAbility, callee:%{public}s.%{public}s",
TAG_LOGD(AAFwkTag::CONTEXT, "ConnectAbility, callee:%{public}s.%{public}s",
want.GetBundle().c_str(),
want.GetElement().GetAbilityName().c_str());
@@ -1224,8 +1224,7 @@ napi_value JsAbilityContext::OnConnectAbilityWithAccount(napi_env env, NapiCallb
AAFwk::Want want;
OHOS::AppExecFwk::UnwrapWant(env, info.argv[INDEX_ZERO], want);
TAG_LOGI(AAFwkTag::CONTEXT, "ConnectAbilityWithAccount, bundlename:%{public}s abilityname:%{public}s",
want.GetBundle().c_str(),
want.GetElement().GetAbilityName().c_str());
want.GetBundle().c_str(), want.GetElement().GetAbilityName().c_str());
int32_t accountId = 0;
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(env, info.argv[INDEX_ONE], accountId)) {
@@ -1685,7 +1684,7 @@ void JSAbilityConnection::SetConnectionId(int64_t id)
void JSAbilityConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
const sptr<IRemoteObject> &remoteObject, int resultCode)
{
TAG_LOGI(AAFwkTag::CONTEXT, "OnAbilityConnectDone, resultCode:%{public}d", resultCode);
TAG_LOGD(AAFwkTag::CONTEXT, "OnAbilityConnectDone, resultCode:%{public}d", resultCode);
wptr<JSAbilityConnection> connection = this;
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([connection, element, remoteObject, resultCode](napi_env env, NapiAsyncTask &task, int32_t status) {
@@ -1706,7 +1705,7 @@ void JSAbilityConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &el
void JSAbilityConnection::HandleOnAbilityConnectDone(const AppExecFwk::ElementName &element,
const sptr<IRemoteObject> &remoteObject, int resultCode)
{
TAG_LOGI(AAFwkTag::CONTEXT, "HandleOnAbilityConnectDone, resultCode:%{public}d", resultCode);
TAG_LOGD(AAFwkTag::CONTEXT, "HandleOnAbilityConnectDone, resultCode:%{public}d", resultCode);
if (jsConnectionObject_ == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "jsConnectionObject_ nullptr");
return;
@@ -1732,7 +1731,7 @@ void JSAbilityConnection::HandleOnAbilityConnectDone(const AppExecFwk::ElementNa
void JSAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
TAG_LOGI(AAFwkTag::CONTEXT, "OnAbilityDisconnectDone, resultCode:%{public}d", resultCode);
TAG_LOGD(AAFwkTag::CONTEXT, "OnAbilityDisconnectDone, resultCode:%{public}d", resultCode);
wptr<JSAbilityConnection> connection = this;
std::unique_ptr<NapiAsyncTask::CompleteCallback> complete = std::make_unique<NapiAsyncTask::CompleteCallback>
([connection, element, resultCode](napi_env env, NapiAsyncTask &task, int32_t status) {
@@ -706,7 +706,7 @@ void JsUIAbility::RestorePageStack(const Want &want)
auto env = jsRuntime_.GetNapiEnv();
if (abilityContext_->GetContentStorage()) {
scene_->GetMainWindow()->NapiSetUIContent(pageStack, env,
abilityContext_->GetContentStorage()->GetNapiValue(), true);
abilityContext_->GetContentStorage()->GetNapiValue(), Rosen::BackupAndRestoreType::CONTINUATION);
} else {
TAG_LOGE(AAFwkTag::UIABILITY, "Content storage is nullptr.");
}
@@ -728,7 +728,8 @@ void JsUIAbility::AbilityContinuationOrRecover(const Want &want)
auto env = jsRuntime_.GetNapiEnv();
auto mainWindow = scene_->GetMainWindow();
if (mainWindow != nullptr) {
mainWindow->NapiSetUIContent(pageStack, env, abilityContext_->GetContentStorage()->GetNapiValue(), true);
mainWindow->NapiSetUIContent(pageStack, env, abilityContext_->GetContentStorage()->GetNapiValue(),
Rosen::BackupAndRestoreType::CONTINUATION);
} else {
TAG_LOGE(AAFwkTag::UIABILITY, "MainWindow is nullptr.");
}
@@ -793,9 +794,10 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want)
auto option = GetWindowOption(want);
Rosen::WMError ret = Rosen::WMError::WM_OK;
auto sessionToken = GetSessionToken();
auto identityToken = GetIdentityToken();
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken != nullptr) {
abilityContext_->SetWeakSessionToken(sessionToken);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken, identityToken);
} else {
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
}
@@ -29,6 +29,7 @@
#include "bundle_info.h"
#include "bundle_mgr_interface.h"
#include "child_process.h"
#include "native_child_ipc_process.h"
#include "child_process_manager_error_utils.h"
#include "child_process_start_info.h"
#include "constants.h"
@@ -115,6 +116,37 @@ ChildProcessManagerErrorCode ChildProcessManager::StartChildProcessByAppSpawnFor
return ChildProcessManagerErrorCode::ERR_OK;
}
ChildProcessManagerErrorCode ChildProcessManager::StartNativeChildProcessByAppSpawnFork(
const std::string &libName, const sptr<IRemoteObject> &callbackStub)
{
TAG_LOGI(AAFwkTag::PROCESSMGR, "called, libName:%{private}s", libName.c_str());
ChildProcessManagerErrorCode errorCode = PreCheckNativeProcess();
if (errorCode != ChildProcessManagerErrorCode::ERR_OK) {
return errorCode;
}
sptr<AppExecFwk::IAppMgr> appMgr = GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "GetAppMgr for native child process failed.");
return ChildProcessManagerErrorCode::ERR_GET_APP_MGR_FAILED;
}
auto ret = appMgr->StartNativeChildProcess(libName, childProcessCount_, callbackStub);
TAG_LOGD(AAFwkTag::PROCESSMGR, "AppMgr StartNativeChildProcess ret:%{public}d", ret);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "AppMgr StartNativeChildProcess failed, ret:%{public}d", ret);
if (ret == ERR_OVERFLOW) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Max native child processes readched");
return ChildProcessManagerErrorCode::ERR_MAX_NATIVE_CHILD_PROCESSES;
}
return ChildProcessManagerErrorCode::ERR_GET_APP_MGR_START_PROCESS_FAILED;
}
++childProcessCount_;
return ChildProcessManagerErrorCode::ERR_OK;
}
void ChildProcessManager::RegisterSignal()
{
if (!signalRegistered_) {
@@ -144,6 +176,21 @@ ChildProcessManagerErrorCode ChildProcessManager::PreCheck()
return ChildProcessManagerErrorCode::ERR_OK;
}
ChildProcessManagerErrorCode ChildProcessManager::PreCheckNativeProcess()
{
ChildProcessManagerErrorCode errCode = PreCheck();
if (errCode != ChildProcessManagerErrorCode::ERR_OK) {
return errCode;
}
if (!AAFwk::AppUtils::GetInstance().IsSupportNativeChildProcess()) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Unsupport native child process");
return ChildProcessManagerErrorCode::ERR_UNSUPPORT_NATIVE_CHILD_PROCESS;
}
return ChildProcessManagerErrorCode::ERR_OK;
}
bool ChildProcessManager::IsChildProcess()
{
return isChildProcessBySelfFork_ || hasChildProcessRecord();
@@ -207,6 +254,28 @@ bool ChildProcessManager::LoadJsFile(const std::string &srcEntry, const AppExecF
return true;
}
bool ChildProcessManager::LoadNativeLib(const std::string &libPath, const sptr<IRemoteObject> &mainProcessCb)
{
auto childProcess = NativeChildIpcProcess::Create();
if (childProcess == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Failed create NativeChildIpcProcess");
return false;
}
std::shared_ptr<ChildProcessStartInfo> processStartInfo = std::make_shared<ChildProcessStartInfo>();
processStartInfo->name = std::filesystem::path(libPath).stem();
processStartInfo->srcEntry = libPath;
processStartInfo->ipcObj = mainProcessCb;
if (!childProcess->Init(processStartInfo)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "NativeChildIpcProcess init failed.");
return false;
}
childProcess->OnStart();
TAG_LOGD(AAFwkTag::PROCESSMGR, "LoadNativeLib end.");
return true;
}
std::unique_ptr<AbilityRuntime::Runtime> ChildProcessManager::CreateRuntime(const AppExecFwk::BundleInfo &bundleInfo,
const AppExecFwk::HapModuleInfo &hapModuleInfo, const bool fromAppSpawn, const bool jitEnabled)
{
@@ -0,0 +1,146 @@
/*
* 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_child_ipc_process.h"
#include <dlfcn.h>
#include <thread>
#include <chrono>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "child_process_manager_error_utils.h"
namespace OHOS {
namespace AbilityRuntime {
std::shared_ptr<ChildProcess> NativeChildIpcProcess::Create()
{
return std::make_shared<NativeChildIpcProcess>();
}
NativeChildIpcProcess::~NativeChildIpcProcess()
{
UnloadNativeLib();
}
bool NativeChildIpcProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
{
TAG_LOGD(AAFwkTag::PROCESSMGR, "NativeChildIpcProcess init");
if (info == nullptr || info->ipcObj == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "info or ipc callback is null");
return false;
}
if (!ChildProcess::Init(info)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Base class init failed.");
return false;
}
auto iNotify = iface_cast<OHOS::AppExecFwk::INativeChildNotify>(info->ipcObj);
if (iNotify == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Faild cvt interface to INativeChildNotify");
return false;
}
if (!LoadNativeLib(info)) {
iNotify->OnError(static_cast<int32_t>(ChildProcessManagerErrorCode::ERR_LIB_LOADING_FAILED));
return false;
}
mainProcessCb_ = iNotify;
return true;
}
void NativeChildIpcProcess::OnStart()
{
if (funcNativeLibOnConnect_ == nullptr || funcNativeLibMainProc_ == nullptr || mainProcessCb_ == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "No init");
return;
}
ChildProcess::OnStart();
OHIPCRemoteStub *ipcStub = funcNativeLibOnConnect_();
if (ipcStub == nullptr || ipcStub->remote == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Native lib OnConnect function return null stub");
mainProcessCb_->OnError(static_cast<int32_t>(ChildProcessManagerErrorCode::ERR_CONNECTION_FAILED));
return;
}
std::thread cbThread([this, childIpcStub = std::move(ipcStub->remote)] () -> void {
// Wait MainProc run first
std::this_thread::sleep_for(std::chrono::milliseconds(1));
TAG_LOGI(AAFwkTag::PROCESSMGR, "Notify native child process started");
mainProcessCb_->OnNativeChildStarted(childIpcStub);
});
TAG_LOGI(AAFwkTag::PROCESSMGR, "Enter native lib MainProc");
funcNativeLibMainProc_();
TAG_LOGI(AAFwkTag::PROCESSMGR, "Native lib MainProc returned");
if (cbThread.joinable()) {
cbThread.join();
}
}
bool NativeChildIpcProcess::LoadNativeLib(const std::shared_ptr<ChildProcessStartInfo> &info)
{
if (nativeLibHandle_ != nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Native lib already loaded");
return false;
}
void *libHandle = dlopen(info->srcEntry.c_str(), RTLD_LAZY);
if (libHandle == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Load lib file %{private}s failed, err %{public}s",
info->srcEntry.c_str(), dlerror());
return false;
}
do {
NativeChildProcess_OnConnect funcOnConnect =
reinterpret_cast<NativeChildProcess_OnConnect>(dlsym(libHandle, "NativeChildProcess_OnConnect"));
if (funcOnConnect == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Get OnConnect function address failed, err %{public}s", dlerror());
break;
}
NativeChildProcess_MainProc funcMainProc =
reinterpret_cast<NativeChildProcess_MainProc>(dlsym(libHandle, "NativeChildProcess_MainProc"));
if (funcMainProc == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Get MainProc function address failed, err %{public}s", dlerror());
break;
}
funcNativeLibOnConnect_ = funcOnConnect;
funcNativeLibMainProc_ = funcMainProc;
nativeLibHandle_ = libHandle;
return true;
} while (false);
dlclose(libHandle);
return false;
}
void NativeChildIpcProcess::UnloadNativeLib()
{
if (nativeLibHandle_ != nullptr) {
dlclose(nativeLibHandle_);
nativeLibHandle_ = nullptr;
funcNativeLibOnConnect_ = nullptr;
funcNativeLibMainProc_ = nullptr;
}
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -41,6 +41,7 @@ void ConfigurationUtils::UpdateGlobalConfig(const Configuration &configuration,
std::string colormode;
std::string hasPointerDevice;
GetGlobalConfig(configuration, language, colormode, hasPointerDevice);
std::string colorModeIsSetByApp = configuration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP);
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
if (resConfig == nullptr) {
TAG_LOGE(AAFwkTag::ABILITY, "Create resource config failed.");
@@ -75,6 +76,11 @@ void ConfigurationUtils::UpdateGlobalConfig(const Configuration &configuration,
TAG_LOGD(AAFwkTag::ABILITY, "Update config, hasPointerDevice: %{public}d", resConfig->GetInputDevice());
}
if (!colorModeIsSetByApp.empty()) {
TAG_LOGD(AAFwkTag::ABILITY, "set app true");
resConfig->SetAppColorMode(true);
}
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "resourceManager->UpdateResConfig");
Global::Resource::RState ret = resourceManager->UpdateResConfig(*resConfig);
if (ret != Global::Resource::RState::SUCCESS) {
@@ -351,8 +351,7 @@ bool DataAbilityOperation::Marshalling(Parcel &out) const
}
int referenceSize = (int)dataAbilityPredicatesBackReferences_.size();
if (dataAbilityPredicatesBackReferences_.empty()) {
TAG_LOGD(
AAFwkTag::DATA_ABILITY, "DataAbilityOperation::Marshalling dataAbilityPredicatesBackReferences_ is empty");
TAG_LOGD(AAFwkTag::DATA_ABILITY, "DataAbilityOperation::Marshalling dataAbilityPredicatesBackReferences_:null");
if (!out.WriteInt32(referenceSize)) {
TAG_LOGE(AAFwkTag::DATA_ABILITY, "DataAbilityOperation::Marshalling WriteInt32(VALUE_OBJECT) error");
return false;
@@ -219,7 +219,13 @@ void JsServiceExtension::ListenWMS()
return;
}
auto listener = sptr<SystemAbilityStatusChangeListener>::MakeSptr(displayListener_);
auto context = GetContext();
if (context == nullptr || context->GetToken()) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Param invalid.");
return;
}
auto listener = sptr<SystemAbilityStatusChangeListener>::MakeSptr(displayListener_, context->GetToken());
if (listener == nullptr) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Failed to create status change listener.");
return;
@@ -237,7 +243,8 @@ void JsServiceExtension::SystemAbilityStatusChangeListener::OnAddSystemAbility(i
{
TAG_LOGD(AAFwkTag::SERVICE_EXT, "systemAbilityId: %{public}d add", systemAbilityId);
if (systemAbilityId == WINDOW_MANAGER_SERVICE_ID) {
Rosen::DisplayManager::GetInstance().RegisterDisplayListener(tmpDisplayListener_);
TAG_LOGI(AAFwkTag::SERVICE_EXT, "RegisterDisplayInfoChangedListener");
Rosen::WindowManager::GetInstance().RegisterDisplayInfoChangedListener(token_, tmpDisplayListener_);
}
}
@@ -315,7 +322,14 @@ void JsServiceExtension::OnStop()
ConnectionManager::GetInstance().ReportConnectionLeakEvent(getpid(), gettid());
TAG_LOGD(AAFwkTag::SERVICE_EXT, "The service extension connection is not disconnected.");
}
Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(displayListener_);
TAG_LOGI(AAFwkTag::SERVICE_EXT, "UnregisterDisplayInfoChangedListener");
auto context = GetContext();
if (context == nullptr || context->GetToken()) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Param invalid.");
return;
}
Rosen::WindowManager::GetInstance()
.UnregisterDisplayInfoChangedListener(context->GetToken(), displayListener_);
TAG_LOGD(AAFwkTag::SERVICE_EXT, "ok");
}
@@ -451,8 +465,7 @@ bool JsServiceExtension::HandleInsightIntent(const AAFwk::Want &want)
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return false;
}
TAG_LOGD(AAFwkTag::SERVICE_EXT,
"Insight intent bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s"
TAG_LOGD(AAFwkTag::SERVICE_EXT, "Insight bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s"
"insightIntentName: %{public}s, executeMode: %{public}d, intentId: %{public}" PRIu64 "",
executeParam->bundleName_.c_str(), executeParam->moduleName_.c_str(), executeParam->abilityName_.c_str(),
executeParam->insightIntentName_.c_str(), executeParam->executeMode_, executeParam->insightIntentId_);
@@ -799,6 +812,43 @@ void JsServiceExtension::OnDestroy(Rosen::DisplayId displayId)
TAG_LOGD(AAFwkTag::SERVICE_EXT, "exit.");
}
void JsServiceExtension::OnDisplayInfoChange(const sptr<IRemoteObject>& token, Rosen::DisplayId displayId,
float density, Rosen::DisplayOrientation orientation)
{
TAG_LOGI(AAFwkTag::SERVICE_EXT, "displayId: %{public}" PRIu64, displayId);
auto context = GetContext();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Context is invalid.");
return;
}
auto contextConfig = context->GetConfiguration();
if (contextConfig == nullptr) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Configuration is invalid.");
return;
}
TAG_LOGD(AAFwkTag::SERVICE_EXT, "Config dump: %{public}s", contextConfig->GetName().c_str());
bool configChanged = false;
auto configUtils = std::make_shared<ConfigurationUtils>();
configUtils->UpdateDisplayConfig(displayId, contextConfig, context->GetResourceManager(), configChanged);
TAG_LOGD(AAFwkTag::SERVICE_EXT, "Config dump after update: %{public}s", contextConfig->GetName().c_str());
if (configChanged) {
auto jsServiceExtension = std::static_pointer_cast<JsServiceExtension>(shared_from_this());
auto task = [jsServiceExtension]() {
if (jsServiceExtension) {
jsServiceExtension->ConfigurationUpdated();
}
};
if (handler_ != nullptr) {
handler_->PostTask(task, "JsServiceExtension:OnChange");
}
}
TAG_LOGD(AAFwkTag::SERVICE_EXT, "finished.");
}
void JsServiceExtension::OnChange(Rosen::DisplayId displayId)
{
TAG_LOGD(AAFwkTag::SERVICE_EXT, "displayId: %{public}" PRIu64"", displayId);
@@ -210,7 +210,7 @@ private:
napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info, bool isStartRecent = false)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::SERVICE_EXT, "StartAbility");
TAG_LOGD(AAFwkTag::SERVICE_EXT, "StartAbility");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Start ability failed, not enough params.");
ThrowTooFewParametersError(env);
@@ -782,7 +782,7 @@ private:
napi_value OnDisconnectAbility(napi_env env, NapiCallbackInfo& info)
{
TAG_LOGI(AAFwkTag::SERVICE_EXT, "DisconnectAbility start");
TAG_LOGD(AAFwkTag::SERVICE_EXT, "DisconnectAbility start");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Disconnect ability error, not enough params.");
ThrowTooFewParametersError(env);
@@ -1077,7 +1077,7 @@ private:
return;
}
if (*retCode == 0) {
TAG_LOGI(AAFwkTag::SERVICE_EXT, "StartAbility is success");
TAG_LOGD(AAFwkTag::SERVICE_EXT, "StartAbility is success");
task.Resolve(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, *retCode));
@@ -1277,7 +1277,7 @@ void JSServiceExtensionConnection::OnAbilityDisconnectDone(const AppExecFwk::Ele
void JSServiceExtensionConnection::HandleOnAbilityDisconnectDone(const AppExecFwk::ElementName &element,
int resultCode)
{
TAG_LOGI(AAFwkTag::SERVICE_EXT, "HandleOnAbilityDisconnectDone, resultCode:%{public}d", resultCode);
TAG_LOGD(AAFwkTag::SERVICE_EXT, "HandleOnAbilityDisconnectDone, resultCode:%{public}d", resultCode);
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(env_, element);
napi_value argv[] = {napiElementName};
if (jsConnectionObject_ == nullptr) {
+63 -14
View File
@@ -36,7 +36,6 @@ constexpr int32_t DEFAULT_DMS_SESSION_ID = 0;
constexpr char LAUNCHER_BUNDLE_NAME[] = "com.ohos.launcher";
constexpr char LAUNCHER_ABILITY_NAME[] = "com.ohos.launcher.MainAbility";
constexpr char SHOW_ON_LOCK_SCREEN[] = "ShowOnLockScreen";
constexpr char DLP_INDEX[] = "ohos.dlp.params.index";
constexpr char DLP_PARAMS_SECURITY_FLAG[] = "ohos.dlp.params.securityFlag";
constexpr char COMPONENT_STARTUP_NEW_RULES[] = "component.startup.newRules";
constexpr int32_t ERR_INVALID_VALUE = -1;
@@ -94,7 +93,8 @@ void UIAbility::Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
TAG_LOGE(AAFwkTag::UIABILITY, "abilityDisplayListener_ is nullptr.");
return;
}
Rosen::DisplayManager::GetInstance().RegisterDisplayListener(abilityDisplayListener_);
TAG_LOGI(AAFwkTag::UIABILITY, "RegisterDisplayInfoChangedListener.");
Rosen::WindowManager::GetInstance().RegisterDisplayInfoChangedListener(token_, abilityDisplayListener_);
#endif
lifecycle_ = std::make_shared<AppExecFwk::LifeCycle>();
abilityLifecycleExecutor_ = std::make_shared<AppExecFwk::AbilityLifecycleExecutor>();
@@ -152,8 +152,6 @@ void UIAbility::OnStart(const AAFwk::Want &want, sptr<AAFwk::SessionInfo> sessio
return;
}
appIndex_ = want.GetIntParam(DLP_INDEX, 0);
(const_cast<AAFwk::Want &>(want)).RemoveParam(DLP_INDEX);
securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false);
(const_cast<AAFwk::Want &>(want)).RemoveParam(DLP_PARAMS_SECURITY_FLAG);
SetWant(want);
@@ -161,6 +159,7 @@ void UIAbility::OnStart(const AAFwk::Want &want, sptr<AAFwk::SessionInfo> sessio
#ifdef SUPPORT_GRAPHICS
if (sessionInfo != nullptr) {
SetSessionToken(sessionInfo->sessionToken);
SetIdentityToken(sessionInfo->identityToken);
}
OnStartForSupportGraphics(want);
#endif
@@ -187,7 +186,8 @@ void UIAbility::OnStop()
if (abilityRecovery_ != nullptr) {
abilityRecovery_->ScheduleSaveAbilityState(AppExecFwk::StateReason::LIFECYCLE);
}
(void)Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(abilityDisplayListener_);
TAG_LOGI(AAFwkTag::UIABILITY, "UnregisterDisplayInfoChangedListener.");
(void)Rosen::WindowManager::GetInstance().UnregisterDisplayInfoChangedListener(token_, abilityDisplayListener_);
auto &&window = GetWindow();
if (window != nullptr) {
TAG_LOGD(AAFwkTag::UIABILITY, "Call UnregisterDisplayMoveListener.");
@@ -242,10 +242,6 @@ bool UIAbility::IsRestoredInContinuation() const
return false;
}
if (abilityContext_->GetContentStorage() == nullptr) {
TAG_LOGD(AAFwkTag::UIABILITY, "Get content failed.");
return false;
}
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
return true;
}
@@ -295,6 +291,7 @@ void UIAbility::OnConfigurationUpdatedNotify(const AppExecFwk::Configuration &co
std::string colormode;
std::string hasPointerDevice;
InitConfigurationProperties(configuration, language, colormode, hasPointerDevice);
std::string colorModeIsSetByApp = configuration.GetItem(AAFwk::GlobalConfigurationKey::COLORMODE_IS_SET_BY_APP);
// Notify ResourceManager
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
if (resConfig == nullptr) {
@@ -320,6 +317,10 @@ void UIAbility::OnConfigurationUpdatedNotify(const AppExecFwk::Configuration &co
if (!hasPointerDevice.empty()) {
resConfig->SetInputDevice(AppExecFwk::ConvertHasPointerDevice(hasPointerDevice));
}
if (!colorModeIsSetByApp.empty()) {
TAG_LOGD(AAFwkTag::UIABILITY, "set app true");
resConfig->SetAppColorMode(true);
}
resourceManager->UpdateResConfig(*resConfig);
TAG_LOGD(AAFwkTag::UIABILITY, "Current colorMode: %{public}d, hasPointerDevice: %{public}d.",
resConfig->GetColorMode(), resConfig->GetInputDevice());
@@ -800,6 +801,49 @@ void UIAbility::OnDestroy(Rosen::DisplayId displayId)
TAG_LOGD(AAFwkTag::UIABILITY, "Called.");
}
void UIAbility::OnDisplayInfoChange(const sptr<IRemoteObject>& token, Rosen::DisplayId displayId, float density,
Rosen::DisplayOrientation orientation)
{
TAG_LOGI(AAFwkTag::UIABILITY, "Begin displayId: %{public}" PRIu64, displayId);
// Get display
auto display = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId);
if (!display) {
TAG_LOGE(AAFwkTag::UIABILITY, "Get display by displayId %{public}" PRIu64 " failed.", displayId);
return;
}
// Notify ResourceManager
int32_t width = display->GetWidth();
int32_t height = display->GetHeight();
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
if (resConfig != nullptr) {
auto resourceManager = GetResourceManager();
if (resourceManager != nullptr) {
resourceManager->GetResConfig(*resConfig);
resConfig->SetScreenDensity(density);
resConfig->SetDirection(AppExecFwk::ConvertDirection(height, width));
resourceManager->UpdateResConfig(*resConfig);
TAG_LOGD(AAFwkTag::UIABILITY, "Notify ResourceManager, Density: %{public}f, Direction: %{public}d",
resConfig->GetScreenDensity(), resConfig->GetDirection());
}
}
// Notify ability
Configuration newConfig;
newConfig.AddItem(
displayId, AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION, AppExecFwk::GetDirectionStr(height, width));
newConfig.AddItem(
displayId, AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI, AppExecFwk::GetDensityStr(density));
if (application_ == nullptr) {
TAG_LOGE(AAFwkTag::UIABILITY, "application_ is nullptr.");
return;
}
OnChangeForUpdateConfiguration(newConfig);
TAG_LOGD(AAFwkTag::UIABILITY, "End.");
}
void UIAbility::OnChange(Rosen::DisplayId displayId)
{
TAG_LOGD(AAFwkTag::UIABILITY, "Begin displayId: %{public}" PRIu64 "", displayId);
@@ -1023,11 +1067,6 @@ void UIAbility::OnChangeForUpdateConfiguration(const AppExecFwk::Configuration &
ability->OnConfigurationUpdated(configuration);
};
handler_->PostTask(task);
auto diffConfiguration = std::make_shared<AppExecFwk::Configuration>(newConfig);
TAG_LOGD(AAFwkTag::UIABILITY, "Update display config %{public}s for all windows.",
diffConfiguration->GetName().c_str());
Rosen::Window::UpdateConfigurationForAll(diffConfiguration);
}
}
@@ -1095,6 +1134,16 @@ void UIAbility::EraseUIExtension(int32_t sessionId)
}
abilityContextImpl->EraseUIExtension(sessionId);
}
void UIAbility::SetIdentityToken(const std::string &identityToken)
{
identityToken_ = identityToken;
}
std::string UIAbility::GetIdentityToken() const
{
return identityToken_;
}
#endif
} // namespace AbilityRuntime
} // namespace OHOS
@@ -368,7 +368,7 @@ void UIAbilityImpl::UpdateSilentForeground(const AAFwk::LifeCycleStateInfo &targ
}
if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL &&
sessionInfo && sessionInfo->processOptions &&
AAFwk::ProcessOptions::IsNewProcessMode(sessionInfo->processOptions->processMode) &&
AAFwk::ProcessOptions::IsValidProcessMode(sessionInfo->processOptions->processMode) &&
sessionInfo->processOptions->startupVisibility == AAFwk::StartupVisibility::STARTUP_HIDE) {
TAG_LOGI(AAFwkTag::UIABILITY, "Set IsSilentForeground to true.");
ability_->SetIsSilentForeground(true);
@@ -782,7 +782,7 @@ void JsUIExtension::DestroyWindow(const sptr<AAFwk::SessionInfo> &sessionInfo)
CallObjectMethod("onSessionDestroy", argv, ARGC_ONE);
}
}
auto& uiWindow = uiWindowMap_[componentId];
auto uiWindow = uiWindowMap_[componentId];
if (uiWindow) {
uiWindow->Destroy();
}
@@ -564,26 +564,8 @@ napi_value JsUIExtensionContentSession::OnTerminateSelfWithResult(napi_env env,
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[uiWindow = uiWindow_, sessionInfo = sessionInfo_, want, resultCode](napi_env env,
NapiAsyncTask& task, int32_t status) {
if (uiWindow == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr.");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto ret = uiWindow->TransferAbilityResult(resultCode, want);
if (ret != Rosen::WMError::WM_OK) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto errorCode = AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo);
if (errorCode == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, errorCode));
}
};
NapiAsyncTask::CompleteCallback complete;
SetCallbackForTerminateWithResult(resultCode, want, complete);
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
@@ -633,7 +615,7 @@ napi_value JsUIExtensionContentSession::OnSetReceiveDataCallback(napi_env env, N
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_function)) {
TAG_LOGE(AAFwkTag::UI_EXT, "invalid param");
ThrowInvalidParamError(env, "Parameter error: Callback must be a function.");
@@ -681,7 +663,7 @@ napi_value JsUIExtensionContentSession::OnSetReceiveDataForResultCallback(napi_e
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!CheckTypeForNapiValue(env, info.argv[INDEX_ZERO], napi_function)) {
TAG_LOGE(AAFwkTag::UI_EXT, "invalid param");
ThrowInvalidParamError(env, "Parameter error: Callback must be a function.");
@@ -733,7 +715,7 @@ napi_value JsUIExtensionContentSession::OnLoadContent(napi_env env, NapiCallback
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], contextPath)) {
TAG_LOGE(AAFwkTag::UI_EXT, "invalid param");
ThrowInvalidParamError(env, "Parameter error: Path must be a string.");
@@ -761,7 +743,8 @@ napi_value JsUIExtensionContentSession::OnLoadContent(napi_env env, NapiCallback
isFirstTriggerBindModal_ = false;
}
sptr<IRemoteObject> parentToken = sessionInfo_->parentToken;
Rosen::WMError ret = uiWindow_->NapiSetUIContent(contextPath, env, storage, false, parentToken);
Rosen::WMError ret = uiWindow_->NapiSetUIContent(contextPath, env, storage,
Rosen::BackupAndRestoreType::NONE, parentToken);
if (ret == Rosen::WMError::WM_OK) {
TAG_LOGD(AAFwkTag::UI_EXT, "NapiSetUIContent success");
} else {
@@ -781,7 +764,7 @@ napi_value JsUIExtensionContentSession::OnSetWindowBackgroundColor(napi_env env,
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], color)) {
TAG_LOGE(AAFwkTag::UI_EXT, "invalid param");
ThrowInvalidParamError(env, "Parameter error: Parse color failed! Color must be a string.");
@@ -812,7 +795,7 @@ napi_value JsUIExtensionContentSession::OnSetWindowPrivacyMode(napi_env env, Nap
ThrowTooFewParametersError(env);
return CreateJsUndefined(env);
}
if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], isPrivacyMode)) {
TAG_LOGE(AAFwkTag::UI_EXT, "invalid param");
ThrowInvalidParamError(env, "Parameter error: Failed to parse isPrivacyMode! IsPrivacyMode must be a boolean.");
@@ -849,7 +832,7 @@ napi_value JsUIExtensionContentSession::OnSetWindowPrivacyMode(napi_env env, Nap
napi_value JsUIExtensionContentSession::OnStartAbilityByType(napi_env env, NapiCallbackInfo& info)
{
TAG_LOGI(AAFwkTag::UI_EXT, "called");
std::string type;
AAFwk::WantParams wantParam;
@@ -1084,5 +1067,38 @@ void JsUIExtensionContentSession::AddFreeInstallObserver(napi_env env,
bundleName, abilityName, startTime, callback, result, isAbilityResult);
}
}
void JsUIExtensionContentSession::SetCallbackForTerminateWithResult(int32_t resultCode, AAFwk::Want& want,
NapiAsyncTask::CompleteCallback& complete)
{
complete =
[weak = context_, uiWindow = uiWindow_, sessionInfo = sessionInfo_, want, resultCode](napi_env env,
NapiAsyncTask& task, int32_t status) {
auto extensionContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIExtensionContext>(weak.lock());
if (!extensionContext) {
TAG_LOGE(AAFwkTag::UI_EXT, "extensionContext is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
return;
}
auto token = extensionContext->GetToken();
AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want);
if (uiWindow == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr.");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto ret = uiWindow->TransferAbilityResult(resultCode, want);
if (ret != Rosen::WMError::WM_OK) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto errorCode = AAFwk::AbilityManagerClient::GetInstance()->TerminateUIExtensionAbility(sessionInfo);
if (errorCode == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, errorCode));
}
};
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -428,33 +428,8 @@ napi_value JsUIExtensionContext::OnTerminateSelfWithResult(napi_env env, NapiCal
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[weak = context_, want, resultCode](napi_env env, NapiAsyncTask& task, int32_t status) {
auto context = weak.lock();
if (!context) {
TAG_LOGW(AAFwkTag::UI_EXT, "context is released");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
sptr<Rosen::Window> uiWindow = context->GetWindow();
if (uiWindow == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
auto ret = uiWindow->TransferAbilityResult(resultCode, want);
if (ret != Rosen::WMError::WM_OK) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
auto errorCode = context->TerminateSelf();
if (errorCode == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, errorCode));
}
};
NapiAsyncTask::CompleteCallback complete;
SetCallbackForTerminateWithResult(resultCode, want, complete);
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JsUIExtensionContext::OnTerminateSelfWithResult",
@@ -666,6 +641,45 @@ napi_value JsUIExtensionContext::OnOpenAtomicService(napi_env env, NapiCallbackI
return OpenAtomicServiceInner(env, info, want, startOptions, unwrapArgc);
}
void JsUIExtensionContext::SetCallbackForTerminateWithResult(int32_t resultCode, AAFwk::Want& want,
NapiAsyncTask::CompleteCallback& complete)
{
complete =
[weak = context_, want, resultCode](napi_env env, NapiAsyncTask& task, int32_t status) {
auto context = weak.lock();
if (!context) {
TAG_LOGE(AAFwkTag::UI_EXT, "context is released");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
return;
}
auto extensionContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIExtensionContext>(context);
if (!extensionContext) {
TAG_LOGE(AAFwkTag::UI_EXT, "extensionContext is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
auto token = extensionContext->GetToken();
AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want);
sptr<Rosen::Window> uiWindow = context->GetWindow();
if (!uiWindow) {
TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
auto ret = uiWindow->TransferAbilityResult(resultCode, want);
if (ret != Rosen::WMError::WM_OK) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
auto errorCode = context->TerminateSelf();
if (errorCode == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, errorCode));
}
};
}
napi_value JsUIExtensionContext::OpenAtomicServiceInner(napi_env env, NapiCallbackInfo& info, Want &want,
const AAFwk::StartOptions &options, size_t unwrapArgc)
{
+44 -19
View File
@@ -48,29 +48,21 @@ config("appkit_config") {
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/dfr",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"//third_party/json/include",
]
}
config("appkit_public_config") {
visibility = [ ":*" ]
include_dirs = [
"${ability_base_kits_path}/configuration/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_delegator",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/dfr",
"${global_path}/resource_management/interfaces/inner_api/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
]
if (ability_runtime_graphics) {
include_dirs += [
"${global_path}/i18n/frameworks/intl/include",
"//third_party/icu/icu4c/source/common",
]
defines = [
"SUPPORT_GRAPHICS",
"SUPPORT_APP_PREFERRED_LANGUAGE",
@@ -97,6 +89,7 @@ ohos_shared_library("appkit_native") {
"${ability_runtime_path}/utils/global/time/include",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_napi_path}/inner/napi_common",
"${ability_runtime_utils_path}/global/constant",
]
if (ability_runtime_graphics) {
@@ -125,6 +118,7 @@ ohos_shared_library("appkit_native") {
"${ability_runtime_native_path}/appkit/app/assert_fault_callback.cpp",
"${ability_runtime_native_path}/appkit/app/assert_fault_task_thread.cpp",
"${ability_runtime_native_path}/appkit/app/child_main_thread.cpp",
"${ability_runtime_native_path}/appkit/app/dump_ffrt_helper.cpp",
"${ability_runtime_native_path}/appkit/app/dump_ipc_helper.cpp",
"${ability_runtime_native_path}/appkit/app/extension_plugin_info.cpp",
"${ability_runtime_native_path}/appkit/app/idle_time.cpp",
@@ -155,6 +149,7 @@ ohos_shared_library("appkit_native") {
":appkit_delegator",
"${ability_runtime_abilitymgr_path}/:abilityms",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/child_process_manager:child_process_manager",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
@@ -173,7 +168,6 @@ ohos_shared_library("appkit_native") {
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:extractresourcemanager",
"ability_base:string_utils",
"ability_base:want",
@@ -193,18 +187,30 @@ ohos_shared_library("appkit_native") {
"i18n:preferred_language",
"init:libbegetutil",
"ipc:ipc_core",
"json:nlohmann_json_static",
"napi:ace_napi",
"resource_management:global_resmgr",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
public_external_deps = [ "ability_base:configuration" ]
if (cj_frontend) {
sources += [
"${ability_runtime_native_path}/appkit/ability_runtime/app/cj_ability_stage.cpp",
"${ability_runtime_native_path}/appkit/ability_runtime/app/cj_ability_stage_object.cpp",
]
include_dirs +=
[ "${ability_runtime_path}/cj_environment/interfaces/inner_api" ]
}
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [
"ace_engine:ace_forward_compatibility",
"graphic_2d:librender_service_client",
"i18n:intl_util",
"icu:shared_icuuc",
"window_manager:libwm",
]
}
@@ -238,7 +244,6 @@ ohos_shared_library("appkit_native") {
# build so
ohos_shared_library("app_context") {
include_dirs = [
"${ability_base_kits_path}/extractortool/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
@@ -263,6 +268,7 @@ ohos_shared_library("app_context") {
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -270,7 +276,7 @@ ohos_shared_library("app_context") {
]
external_deps = [
"ability_base:configuration",
"ability_base:extractortool",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
@@ -280,14 +286,18 @@ ohos_shared_library("app_context") {
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
"json:nlohmann_json_static",
"napi:ace_napi",
"resource_management:global_resmgr",
"samgr:samgr_proxy",
]
public_external_deps = [ "ability_base:configuration" ]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [ "i18n:intl_util" ]
external_deps += [
"i18n:intl_util",
"icu:shared_icuuc",
]
}
innerapi_tags = [ "platformsdk" ]
@@ -318,6 +328,7 @@ ohos_shared_library("app_context_utils") {
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -337,14 +348,17 @@ ohos_shared_library("app_context_utils") {
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"json:nlohmann_json_static",
"napi:ace_napi",
"resource_management:global_resmgr",
"resource_management:resmgr_napi_core",
]
public_external_deps = [ "ability_base:configuration" ]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [ "i18n:intl_util" ]
external_deps += [
"i18n:intl_util",
"icu:shared_icuuc",
]
}
innerapi_tags = [ "platformsdk" ]
@@ -388,6 +402,7 @@ ohos_shared_library("appkit_delegator") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:delegator_mgmt",
@@ -401,11 +416,19 @@ ohos_shared_library("appkit_delegator") {
"eventhandler:libeventhandler",
"hilog:libhilog",
"ipc:ipc_core",
"json:nlohmann_json_static",
"napi:ace_napi",
]
public_external_deps = [ "ability_base:configuration" ]
if (cj_frontend) {
sources += [
"${ability_runtime_native_path}/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp",
"${ability_runtime_native_path}/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp",
]
}
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [ "icu:shared_icuuc" ]
}
innerapi_tags = [ "platformsdk" ]
@@ -425,6 +448,7 @@ ohos_shared_library("appkit_manager_helper") {
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
"${ability_runtime_services_path}/common/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_utils_path}/global/constant",
]
configs = [ ":appkit_config" ]
@@ -447,11 +471,12 @@ ohos_shared_library("appkit_manager_helper") {
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"json:nlohmann_json_static",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [ "icu:shared_icuuc" ]
}
innerapi_tags = [ "platformsdk" ]
@@ -16,6 +16,7 @@
#include "bundle_mgr_helper.h"
#include "bundle_mgr_service_death_recipient.h"
#include "global_constant.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
@@ -81,7 +82,7 @@ ErrCode BundleMgrHelper::InstallSandboxApp(const std::string &bundleName, int32_
ErrCode BundleMgrHelper::UninstallSandboxApp(const std::string &bundleName, int32_t appIndex, int32_t userId)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
if (bundleName.empty() || appIndex <= Constants::INITIAL_APP_INDEX) {
if (bundleName.empty() || appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "The params are invalid.");
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
}
@@ -112,7 +113,7 @@ ErrCode BundleMgrHelper::GetSandboxBundleInfo(
const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
if (bundleName.empty() || appIndex <= Constants::INITIAL_APP_INDEX) {
if (bundleName.empty() || appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "The params are invalid.");
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
}
@@ -130,7 +131,7 @@ ErrCode BundleMgrHelper::GetSandboxAbilityInfo(const Want &want, int32_t appInde
AbilityInfo &abilityInfo)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
if (appIndex <= Constants::INITIAL_APP_INDEX || appIndex > Constants::MAX_APP_INDEX) {
if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "The params are invalid.");
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
}
@@ -151,7 +152,7 @@ ErrCode BundleMgrHelper::GetSandboxExtAbilityInfos(const Want &want, int32_t app
int32_t userId, std::vector<ExtensionAbilityInfo> &extensionInfos)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
if (appIndex <= Constants::INITIAL_APP_INDEX || appIndex > Constants::MAX_APP_INDEX) {
if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "The params are invalid.");
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
}
@@ -169,7 +170,7 @@ ErrCode BundleMgrHelper::GetSandboxHapModuleInfo(const AbilityInfo &abilityInfo,
HapModuleInfo &hapModuleInfo)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
if (appIndex <= Constants::INITIAL_APP_INDEX || appIndex > Constants::MAX_APP_INDEX) {
if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "The params are invalid.");
return ERR_APPEXECFWK_SANDBOX_INSTALL_PARAM_ERROR;
}
@@ -797,5 +798,31 @@ ErrCode BundleMgrHelper::GetLaunchWantForBundle(const std::string &bundleName, W
return bundleMgr->GetLaunchWantForBundle(bundleName, want, userId);
}
ErrCode BundleMgrHelper::QueryCloneAbilityInfo(const ElementName &element, int32_t flags, int32_t appCloneIndex,
AbilityInfo &abilityInfo, int32_t userId)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
auto bundleMgr = Connect();
if (bundleMgr == nullptr) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect.");
return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
}
return bundleMgr->QueryCloneAbilityInfo(element, flags, appCloneIndex, abilityInfo, userId);
}
ErrCode BundleMgrHelper::GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex,
BundleInfo &bundleInfo, int32_t userId)
{
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
auto bundleMgr = Connect();
if (bundleMgr == nullptr) {
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect.");
return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
}
return bundleMgr->GetCloneBundleInfo(bundleName, flags, appCloneIndex, bundleInfo, userId);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -0,0 +1,126 @@
/*
* 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 "runner_runtime/cj_test_runner.h"
#include <regex>
#include "ability_delegator_registry.h"
#include "hilog_wrapper.h"
#include "runner_runtime/cj_test_runner_object.h"
namespace OHOS {
namespace RunnerRuntime {
std::unique_ptr<TestRunner> CJTestRunner::Create(const std::unique_ptr<Runtime> &runtime,
const std::shared_ptr<AbilityDelegatorArgs> &args, const AppExecFwk::BundleInfo &bundleInfo)
{
HILOG_INFO("CJTestRunner::Create start.");
if (!runtime) {
HILOG_ERROR("Invalid runtime");
return nullptr;
}
auto cjRuntime = static_cast<CJRuntime*>(runtime.get());
if (cjRuntime->IsAppLibLoaded()) {
HILOG_ERROR("CJTestRunner: AppLib Not Loaded");
return nullptr;
}
if (!args) {
HILOG_ERROR("Invalid ability delegator args");
return nullptr;
}
auto pTestRunner = new (std::nothrow) CJTestRunner(*cjRuntime, args, bundleInfo);
if (!pTestRunner) {
HILOG_ERROR("Failed to create test runner");
return nullptr;
}
return std::unique_ptr<CJTestRunner>(pTestRunner);
}
CJTestRunner::CJTestRunner(CJRuntime &cjRuntime, const std::shared_ptr<AbilityDelegatorArgs> &args,
const AppExecFwk::BundleInfo &bundleInfo) : cjRuntime_(cjRuntime)
{
std::string moduleName = args->GetTestRunnerClassName();
cjTestRunnerObj_ = CJTestRunnerObject::LoadModule(moduleName);
}
CJTestRunner::~CJTestRunner() = default;
bool CJTestRunner::Initialize()
{
if (!cjRuntime_.IsAppLibLoaded()) {
HILOG_ERROR("CJTestRunner: AppLib Not Loaded");
return false;
}
if (!cjTestRunnerObj_) {
HILOG_ERROR("CJTestRunnerObj does not exist, Initialize failed.");
return false;
}
return true;
}
void CJTestRunner::Prepare()
{
HILOG_INFO("Enter");
TestRunner::Prepare();
if (!cjTestRunnerObj_) {
HILOG_ERROR("CJTestRunnerObj does not exist, Prepare failed.");
return;
}
cjTestRunnerObj_->OnPrepare();
HILOG_INFO("End");
}
void CJTestRunner::Run()
{
HILOG_INFO("Enter");
TestRunner::Run();
if (!cjTestRunnerObj_) {
HILOG_ERROR("CJTestRunnerObj does not exist, OnRun failed.");
return;
}
cjTestRunnerObj_->OnRun();
HILOG_INFO("End");
}
void CJTestRunner::ReportFinished(const std::string &msg)
{
HILOG_INFO("Enter");
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (!delegator) {
HILOG_ERROR("delegator is null.");
return;
}
delegator->FinishUserTest(msg, -1);
}
void CJTestRunner::ReportStatus(const std::string &msg)
{
HILOG_INFO("Enter");
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
if (!delegator) {
HILOG_ERROR("delegator is null.");
return;
}
delegator->Print(msg);
}
} // namespace RunnerRuntime
} // namespace OHOS
@@ -0,0 +1,88 @@
/*
* 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 "runner_runtime/cj_test_runner_object.h"
#include <string>
#include "hilog_wrapper.h"
namespace {
// g_cjTestRunnerFuncs is used to save cj functions.
// It is assigned by the global variable REGISTER_ABILITY on the cj side which invokes RegisterCJTestRunnerFuncs.
// And it is never released.
CJTestRunnerFuncs* g_cjTestRunnerFuncs = nullptr;
} // namespace
void RegisterCJTestRunnerFuncs(void (*registerFunc)(CJTestRunnerFuncs*))
{
HILOG_INFO("RegisterCJTestRunnerFuncs start.");
if (g_cjTestRunnerFuncs != nullptr) {
HILOG_ERROR("Repeated registration for cj functions of CJTestRunner.");
return;
}
if (registerFunc == nullptr) {
HILOG_ERROR("RegisterCJTestRunnerFuncs failed, registerFunc is nullptr.");
return;
}
g_cjTestRunnerFuncs = new CJTestRunnerFuncs();
registerFunc(g_cjTestRunnerFuncs);
HILOG_INFO("RegisterCJTestRunnerFuncs end.");
}
namespace OHOS {
namespace RunnerRuntime {
std::shared_ptr<CJTestRunnerObject> CJTestRunnerObject::LoadModule(const std::string& name)
{
if (g_cjTestRunnerFuncs == nullptr) {
HILOG_ERROR("cj functions for CJTestRunner are not registered");
return nullptr;
}
auto id = g_cjTestRunnerFuncs->cjTestRunnerCreate(name.c_str());
if (id == 0) {
HILOG_ERROR(
"Failed to invoke CJTestRunnerObject::LoadModule. Ability: %{public}s is not registered.", name.c_str());
return nullptr;
}
return std::make_shared<CJTestRunnerObject>(id);
}
CJTestRunnerObject::~CJTestRunnerObject()
{
g_cjTestRunnerFuncs->cjTestRunnerRelease(id_);
id_ = 0;
}
void CJTestRunnerObject::OnRun() const
{
if (g_cjTestRunnerFuncs == nullptr) {
HILOG_ERROR("cj functions for CJTestRunner are not registered");
return;
}
g_cjTestRunnerFuncs->cjTestRunnerOnRun(id_);
}
void CJTestRunnerObject::OnPrepare() const
{
if (g_cjTestRunnerFuncs == nullptr) {
HILOG_ERROR("cj functions for CJTestRunner are not registered");
return;
}
g_cjTestRunnerFuncs->cjTestRunnerOnPrepare(id_);
}
} // namespace RunnerRuntime
} // namespace OHOS
@@ -17,6 +17,7 @@
#include "bundle_mgr_helper.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "runner_runtime/cj_test_runner.h"
#include "runner_runtime/js_test_runner.h"
#include "runtime.h"
#include "sys_mgr_client.h"
@@ -58,6 +59,8 @@ std::unique_ptr<TestRunner> TestRunner::Create(const std::unique_ptr<AbilityRunt
switch (runtime->GetLanguage()) {
case AbilityRuntime::Runtime::Language::JS:
return RunnerRuntime::JsTestRunner::Create(runtime, args, bundleInfo, isFaJsModel);
case AbilityRuntime::Runtime::Language::CJ:
return RunnerRuntime::CJTestRunner::Create(runtime, args, bundleInfo);
default:
return std::make_unique<TestRunner>();
}
@@ -19,6 +19,7 @@
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "cj_ability_stage.h"
#include "js_ability_stage.h"
#include "runtime.h"
@@ -35,7 +36,8 @@ std::shared_ptr<AbilityStage> AbilityStage::Create(
switch (runtime->GetLanguage()) {
case Runtime::Language::JS:
return JsAbilityStage::Create(runtime, hapModuleInfo);
case Runtime::Language::CJ:
return CJAbilityStage::Create(runtime, hapModuleInfo);
default:
return std::make_shared<AbilityStage>();
}
@@ -115,7 +117,8 @@ void AbilityStage::OnMemoryLevel(int level)
TAG_LOGD(AAFwkTag::APPKIT, "%{public}s called.", __func__);
}
int32_t AbilityStage::RunAutoStartupTask(const std::function<void()> &callback, bool &isAsyncCallback)
int32_t AbilityStage::RunAutoStartupTask(const std::function<void()> &callback, bool &isAsyncCallback,
const std::shared_ptr<Context> &stageContext)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
isAsyncCallback = false;

Some files were not shown because too many files have changed in this diff Show More