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

Signed-off-by: sodanotgreen <limengzheng@huawei.com>
This commit is contained in:
sodanotgreen 2024-07-22 13:40:28 +00:00 committed by Gitee
commit e45b56774f
1799 changed files with 54929 additions and 9145 deletions

View File

@ -93,6 +93,7 @@ declare_args() {
background_task_mgr_continuous_task_enable = true
resource_schedule_service_enable = true
ability_runtime_power = true
ability_runtime_feature_sandboxmanager = true
ability_runtime_relational = true
ability_runtime_ces = true
ability_runtime_resource = true
@ -106,6 +107,7 @@ declare_args() {
"com.ohos.textautofill/entry/TextAutoFillAbility"
cj_frontend = true
ability_runtime_app_no_response_dialog = false
include_app_domain_verify = true
if (!defined(global_parts_info) ||
defined(global_parts_info.account_os_account)) {
@ -170,6 +172,11 @@ declare_args() {
hichecker_enabled = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.bundlemanager_app_domain_verify)) {
include_app_domain_verify = false
}
if (!defined(global_parts_info) ||
defined(global_parts_info.ability_form_fwk)) {
form_fwk_enable = true

View File

@ -19,7 +19,8 @@
"SystemCapability.Ability.AbilityRuntime.Mission",
"SystemCapability.Ability.AbilityRuntime.QuickFix",
"SystemCapability.Ability.AbilityTools.AbilityAssistant",
"SystemCapability.Ability.AppStartup"
"SystemCapability.Ability.AppStartup",
"SystemCapability.Ability.AppExtension.PhotoEditorExtension"
],
"features": [
"ability_runtime_auto_fill_ability",
@ -41,6 +42,8 @@
"accessibility",
"access_token",
"ace_engine",
"app_domain_verify",
"app_file_service",
"appspawn",
"background_task_mgr",
"bundle_framework",
@ -84,6 +87,7 @@
"resource_management",
"resource_schedule_service",
"safwk",
"sandbox_manager",
"samgr",
"screenlock_mgr",
"storage_service",
@ -457,14 +461,6 @@
]
},
"name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:dialog_request_callback"
},
{
"header": {
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include",
"header_files": [
]
},
"name": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager:ability_manager_base"
}
],
"test": [
@ -475,6 +471,7 @@
"//foundation/ability/ability_runtime/tools/test:moduletest",
"//foundation/ability/ability_runtime/tools/test:systemtest",
"//foundation/ability/ability_runtime/tools/test:unittest",
"//foundation/ability/ability_runtime/cj_environment/test/unittest:unittest",
"//foundation/ability/ability_runtime/js_environment/test/unittest:unittest",
"//foundation/ability/ability_runtime/service_router_framework:test_target"
]

View File

@ -15,7 +15,6 @@
#include "cj_environment.h"
#include <regex>
#include <string>
#include "cj_hilog.h"
@ -177,7 +176,16 @@ bool CJEnvironment::LoadRuntimeApis()
#ifdef __OHOS__
Dl_namespace ns;
dlns_get(CJEnvironment::cjSDKNSName, &ns);
auto dso = DynamicLoadLibrary(&ns, RTLIB_NAME, 1);
std::string runtimeLibName = "libcangjie-runtime";
if (sanitizerKind_ == SanitizerKind::ASAN) {
runtimeLibName += "_asan";
} else if (sanitizerKind_ == SanitizerKind::TSAN) {
runtimeLibName += "_tsan";
} else if (sanitizerKind_ == SanitizerKind::HWASAN) {
runtimeLibName += "_hwasan";
}
runtimeLibName += ".so";
auto dso = DynamicLoadLibrary(&ns, runtimeLibName.c_str(), 1);
#else
auto dso = DynamicLoadLibrary(RTLIB_NAME, 1);
#endif
@ -467,10 +475,49 @@ bool CJEnvironment::StartDebugger()
return true;
}
bool IsCJAbility(const std::string& info)
CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance()
{
// in cj application, the srcEntry format should be packageName.AbilityClassName.
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
return std::regex_match(info, std::regex(pattern));
static CJEnvMethods gCJEnvMethods {
.initCJAppNS = [](const std::string& path) {
CJEnvironment::GetInstance()->InitCJAppNS(path);
},
.initCJSDKNS = [](const std::string& path) {
CJEnvironment::GetInstance()->InitCJSDKNS(path);
},
.initCJSysNS = [](const std::string& path) {
CJEnvironment::GetInstance()->InitCJSysNS(path);
},
.initCJChipSDKNS = [](const std::string& path) {
CJEnvironment::GetInstance()->InitCJChipSDKNS(path);
},
.startRuntime = [] {
return CJEnvironment::GetInstance()->StartRuntime();
},
.startUIScheduler = [] {
return CJEnvironment::GetInstance()->StartUIScheduler();
},
.loadCJModule = [](const char* dllName) {
return CJEnvironment::GetInstance()->LoadCJLibrary(dllName);
},
.loadLibrary = [](uint32_t kind, const char* dllName) {
return CJEnvironment::GetInstance()->LoadCJLibrary(static_cast<CJEnvironment::LibraryKind>(kind), dllName);
},
.getSymbol = [](void* handle, const char* dllName) {
return CJEnvironment::GetInstance()->GetSymbol(handle, dllName);
},
.loadCJLibrary = [](const char* dllName) {
return CJEnvironment::GetInstance()->LoadCJLibrary(dllName);
},
.startDebugger = []() {
return CJEnvironment::GetInstance()->StartDebugger();
},
.registerCJUncaughtExceptionHandler = [](const CJUncaughtExceptionInfo& handle) {
return CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(handle);
},
.setSanitizerKindRuntimeVersion = [](SanitizerKind kind) {
return CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(kind);
}
};
return &gCJEnvMethods;
}
}

View File

@ -16,6 +16,9 @@
#ifndef OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
#define OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
#include "cj_envsetup.h"
#include <string>
#include <functional>
#ifdef WINDOWS_PLATFORM
@ -27,17 +30,6 @@
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 {
@ -48,6 +40,11 @@ public:
{
return isRuntimeStarted_;
}
void SetSanitizerKindRuntimeVersion(SanitizerKind kind)
{
sanitizerKind_ = kind;
}
void InitCJAppNS(const std::string& path);
void InitCJSDKNS(const std::string& path);
void InitCJSysNS(const std::string& path);
@ -91,9 +88,9 @@ private:
bool isRuntimeStarted_{false};
bool isUISchedulerStarted_{false};
void* uiScheduler_ {nullptr};
SanitizerKind sanitizerKind_ {SanitizerKind::NONE};
};
CJ_EXPORT bool IsCJAbility(const std::string& info);
}
#endif //OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H

View File

@ -0,0 +1,63 @@
/*
* 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_ENVSETUP_H
#define OHOS_ABILITY_RUNTIME_CJ_ENVSETUP_H
#include <string>
namespace OHOS {
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;
};
enum SanitizerKind {
NONE,
ASAN,
TSAN,
HWASAN,
};
struct CJEnvMethods {
void (*initCJAppNS)(const std::string& path) = nullptr;
void (*initCJSDKNS)(const std::string& path) = nullptr;
void (*initCJSysNS)(const std::string& path) = nullptr;
void (*initCJChipSDKNS)(const std::string& path) = nullptr;
bool (*startRuntime)() = nullptr;
bool (*startUIScheduler)() = nullptr;
void* (*loadCJModule)(const char* dllName) = nullptr;
void* (*loadLibrary)(uint32_t kind, const char* dllName) = nullptr;
void* (*getSymbol)(void* handle, const char* symbol) = nullptr;
void* (*loadCJLibrary)(const char* dllName) = nullptr;
bool (*startDebugger)() = nullptr;
void (*registerCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) = nullptr;
void (*setSanitizerKindRuntimeVersion)(SanitizerKind kind) = nullptr;
};
class CJEnv {
public:
static CJEnvMethods* LoadInstance();
};
}
#endif // OHOS_ABILITY_RUNTIME_CJ_ENVSETUP_H

View File

@ -0,0 +1,21 @@
# 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/test.gni")
import("../../cj_environment.gni")
group("unittest") {
testonly = true
deps = [ "cj_environment_test:unittest" ]
}

View File

@ -0,0 +1,39 @@
# 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/test.gni")
module_output_path = "ability_runtime/cj_environment"
ohos_unittest("cj_environment_test") {
module_out_path = module_output_path
sources = [ "cj_environment_test.cpp" ]
sources += [ "cj_invoker.h" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_runtime:cj_environment",
"hilog:libhilog",
]
}
group("unittest") {
testonly = true
deps = []
deps += [ ":cj_environment_test" ]
}

View File

@ -0,0 +1,349 @@
/*
* 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 <gtest/gtest.h>
#include <gtest/hwext/gtest-multithread.h>
#include <string>
#define private public
#define protected public
#include "cj_environment.h"
#include "cj_invoker.h"
#undef private
#undef protected
using namespace testing;
using namespace testing::ext;
using namespace testing::mt;
namespace OHOS {
class CjEnvironmentTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
void CjEnvironmentTest::SetUpTestCase() {}
void CjEnvironmentTest::TearDownTestCase() {}
void CjEnvironmentTest::SetUp() {}
void CjEnvironmentTest::TearDown() {}
void RegisterCJUncaughtExceptionHandlerTest(const CJUncaughtExceptionInfo &handle) {}
/**
* @tc.name: CJEnvironment_GetInstance_0001
* @tc.desc: JsRuntime test for UpdatePkgContextInfoJson.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_GetInstance_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
CJEnvironment *ret = nullptr;
ret = cJEnvironment->GetInstance();
EXPECT_NE(ret, nullptr);
}
/**
* @tc.name: CJEnvironment_IsRuntimeStarted_0001
* @tc.desc: JsRuntime test for IsRuntimeStarted.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_IsRuntimeStarted_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
bool ret = cJEnvironment->IsRuntimeStarted();
EXPECT_EQ(ret, false);
}
/**
* @tc.name: CJEnvironment_SetSanitizerKindRuntimeVersion_0001
* @tc.desc: JsRuntime test for SetSanitizerKindRuntimeVersion.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_SetSanitizerKindRuntimeVersion_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
SanitizerKind kind = SanitizerKind::ASAN;
cJEnvironment->SetSanitizerKindRuntimeVersion(kind);
EXPECT_NE(cJEnvironment->sanitizerKind_, SanitizerKind::NONE);
}
/**
* @tc.name: CJEnvironment_InitCJAppNS_0001
* @tc.desc: JsRuntime test for InitCJAppNS.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_InitCJAppNS_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
std::string path = "ability_runtime/CjEnvironmentTest";
cJEnvironment->InitCJAppNS(path);
EXPECT_NE(cJEnvironment->cjAppNSName, nullptr);
}
/**
* @tc.name: CJEnvironment_InitCJSDKNS_0001
* @tc.desc: JsRuntime test for InitCJSDKNS.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_InitCJSDKNS_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
std::string path = "ability_runtime/CjEnvironmentTest";
cJEnvironment->InitCJSDKNS(path);
EXPECT_NE(cJEnvironment->cjAppNSName, nullptr);
}
/**
* @tc.name: CJEnvironment_InitCJSysNS_0001
* @tc.desc: JsRuntime test for InitCJSysNS.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_InitCJSysNS_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
std::string path = "ability_runtime/CjEnvironmentTest";
cJEnvironment->InitCJSysNS(path);
std::string getTempCjAppNSName = cJEnvironment->cjAppNSName;
EXPECT_NE(cJEnvironment->cjAppNSName, nullptr);
}
/**
* @tc.name: CJEnvironment_InitCJChipSDKNS_0001
* @tc.desc: JsRuntime test for InitCJChipSDKNS.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_InitCJChipSDKNS_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
std::string path = "ability_runtime/CjEnvironmentTest";
cJEnvironment->InitCJChipSDKNS(path);
EXPECT_NE(cJEnvironment->cjAppNSName, nullptr);
}
/**
* @tc.name: CJEnvironment_StartRuntime_0001
* @tc.desc: JsRuntime test for StartRuntime.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_StartRuntime_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
bool ret = cJEnvironment->StartRuntime();
EXPECT_EQ(ret, false);
cJEnvironment->isRuntimeStarted_ = true;
ret = cJEnvironment->StartRuntime();
EXPECT_EQ(ret, true);
}
/**
* @tc.name: CJEnvironment_StopRuntime_0001
* @tc.desc: JsRuntime test for StopRuntime.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_StopRuntime_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
cJEnvironment->StopRuntime();
EXPECT_EQ(cJEnvironment->isRuntimeStarted_, false);
cJEnvironment->isUISchedulerStarted_ = true;
EXPECT_EQ(cJEnvironment->isRuntimeStarted_, false);
}
/**
* @tc.name: CJEnvironment_RegisterCJUncaughtExceptionHandler_0001
* @tc.desc: JsRuntime test for RegisterCJUncaughtExceptionHandler.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_RegisterCJUncaughtExceptionHandler_0100, TestSize.Level1)
{
// using RegisterUncaughtExceptionType = void (*)(const CJUncaughtExceptionInfo& handle);
CJEnvironment cJEnvironment;
CJUncaughtExceptionInfo handle;
handle.hapPath = "/test1/";
handle.uncaughtTask = [](const char* summary, const CJErrorObject errorObj) {};
CJRuntimeAPI api {
.InitCJRuntime = nullptr,
.InitUIScheduler = nullptr,
.RunUIScheduler = nullptr,
.FiniCJRuntime = nullptr,
.InitCJLibrary = nullptr,
.RegisterEventHandlerCallbacks = nullptr,
.RegisterCJUncaughtExceptionHandler = RegisterCJUncaughtExceptionHandlerTest,
};
CJEnvironment::lazyApis_ = api;
cJEnvironment.RegisterCJUncaughtExceptionHandler(handle);
EXPECT_NE(cJEnvironment.lazyApis_.RegisterCJUncaughtExceptionHandler, nullptr);
}
/**
* @tc.name: CJEnvironment_IsUISchedulerStarted_0001
* @tc.desc: JsRuntime test for IsUISchedulerStarted.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, CJEnvironment_IsUISchedulerStarted_0100, TestSize.Level1)
{
auto cJEnvironment = std::make_shared<CJEnvironment>();
bool ret = cJEnvironment->IsUISchedulerStarted();
EXPECT_EQ(ret, false);
}
/**
* @tc.name: StartUIScheduler_0100
* @tc.desc: Test when isUISchedulerStarted_ is true.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, StartUIScheduler_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
cjEnv->isUISchedulerStarted_ = true;
auto res = cjEnv->StartUIScheduler();
EXPECT_EQ(res, true);
}
/**
* @tc.name: StopUIScheduler_0100
* @tc.desc: Test StopUIScheduler.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, StopUIScheduler_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
EXPECT_NE(cjEnv, nullptr);
cjEnv->StopUIScheduler();
}
/**
* @tc.name: LoadCJLibrary_0100
* @tc.desc: Test LoadCJLibrary.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, LoadCJLibrary_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
char dlNames[5] = "Name";
char* dlName = dlNames;
auto res = cjEnv->LoadCJLibrary(dlName);
EXPECT_EQ(res, nullptr);
}
/**
* @tc.name: LoadCJLibrary_0200
* @tc.desc: Test LoadCJLibrary.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, LoadCJLibrary_0200, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
CJEnvironment::LibraryKind kind = CJEnvironment::SYSTEM;
char dlNames[] = "Name";
char* dlName = dlNames;
auto res = cjEnv->LoadCJLibrary(kind, dlName);
EXPECT_EQ(res, nullptr);
}
/**
* @tc.name: UnLoadCJLibrary_0100
* @tc.desc: Test LoadCJLibrary.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, UnLoadCJLibrary_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
EXPECT_NE(cjEnv, nullptr);
cjEnv->UnLoadCJLibrary(nullptr);
}
/**
* @tc.name: GetUIScheduler_0100
* @tc.desc: Test GetUIScheduler.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, GetUIScheduler_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
cjEnv->isUISchedulerStarted_ = true;
auto res = cjEnv->GetUIScheduler();
EXPECT_EQ(res, nullptr);
}
/**
* @tc.name: GetSymbol_0100
* @tc.desc: Test GetSymbol.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, GetSymbol_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
EXPECT_NE(cjEnv, nullptr);
void* dso = nullptr;
char symbols[] = "symbol";
char* symbol = symbols;
auto res = cjEnv->GetSymbol(dso, symbol);
EXPECT_EQ(res, nullptr);
}
/**
* @tc.name: StartDebugger_0100
* @tc.desc: Test StartDebugger.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, StartDebugger_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
EXPECT_NE(cjEnv, nullptr);
auto res = cjEnv->StartDebugger();
EXPECT_EQ(res, false);
}
/**
* @tc.name: PostTask_0100
* @tc.desc: Test PostTask.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, PostTask_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
TaskFuncType task = nullptr;
auto res = cjEnv->PostTask(task);
EXPECT_EQ(res, false);
}
/**
* @tc.name: HasHigherPriorityTask_0100
* @tc.desc: Test HasHigherPriorityTask.
* @tc.type: FUNC
*/
HWTEST_F(CjEnvironmentTest, HasHigherPriorityTask_0100, TestSize.Level1)
{
auto cjEnv = std::make_shared<CJEnvironment>();
EXPECT_NE(cjEnv, nullptr);
auto res = cjEnv->HasHigherPriorityTask();
EXPECT_EQ(res, false);
}
} // namespace OHOS

View File

@ -18,5 +18,6 @@ group("cj_ability_packages") {
deps = [
"${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi",
"${ability_runtime_path}/frameworks/cj/ffi/app/errormanager:cj_errormanager_ffi",
"${ability_runtime_path}/frameworks/cj/ffi/ark_interop_helper:ark_interop_helper_ffi",
]
}

View File

@ -0,0 +1,54 @@
# 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")
ohos_shared_library("ark_interop_helper_ffi") {
defines = []
sources = [ "ark_interop_helper.cpp" ]
external_deps = [
"ets_runtime:libark_jsruntime",
"hilog:libhilog",
"napi:ace_napi",
"napi:ark_interop",
]
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
deps = []
if (build_ohos_sdk) {
defines += [ "PREVIEW" ]
} else {
deps += [
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_native",
]
external_deps += [ "ace_engine:ace_container_scope" ]
}
if (current_os == "mingw") {
defines += [ "__WINDOWS__" ]
}
innerapi_tags = [ "platformsdk" ]
part_name = "ability_runtime"
subsystem_name = "ability"
}

View File

@ -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 "ark_interop_helper.h"
#include "ark_native_engine.h"
#include "inner_api/cjffi/ark_interop/ark_interop_internal.h"
#include "inner_api/cjffi/ark_interop/ark_interop_log.h"
#ifndef PREVIEW
#include "core/common/container_scope.h"
#include "custom_scope.h"
#include "napi_base_context.h"
#include "ability.h"
#endif
using namespace panda::ecmascript;
extern "C" {
napi_value ArkTsValuetoNapiValue(napi_env env, ARKTS_Value arkValue)
{
LOGI("ArkTsValuetoNapiValue start");
if (env == nullptr) {
LOGE("FfiOHOSArkTsValuetoNapiValue Error: env is null!");
return nullptr;
}
Local<JSValueRef> js_value_ref = ARKTS_ToHandle<JSValueRef>(arkValue);
auto ark_native_obj = ArkNativeEngine::ArkValueToNapiValue(env, js_value_ref);
return ark_native_obj;
};
ARKTS_Value NapiValueToArkTsValue(napi_value value)
{
auto ref = BIT_CAST(value, Local<JSValueRef>);
return ARKTS_FromHandle(ref);
}
bool IsStageMode(napi_env env, napi_value context)
{
#ifndef PREVIEW
LOGI("IsStageMode start");
bool isStageMode = false;
napi_status status = OHOS::AbilityRuntime::IsStageContext(env, context, isStageMode);
if (status != napi_ok || !isStageMode) {
LOGI("IsStageMode false");
return false;
} else {
LOGI("IsStageMode true");
return true;
}
#else
return false;
#endif
}
void* GetContextStageMode(napi_env env, napi_value context)
{
#ifndef PREVIEW
LOGI("GetContextStageMode start");
if (!env || !context) {
LOGE("argument invalid");
return nullptr;
}
napi_valuetype type;
if (napi_typeof(env, context, &type) != napi_ok) {
LOGE("invalid napi value");
return nullptr;
}
if (type != napi_object) {
LOGE("not a object");
return nullptr;
}
void* data;
if (napi_unwrap(env, context, &data) != napi_ok) {
LOGE("no bind native object");
return nullptr;
}
if (!data) {
LOGE("native object is null");
return nullptr;
}
auto ability = OHOS::AbilityRuntime::GetStageModeContext(env, context);
if (ability == nullptr) {
LOGE("Failed to get native ability instance");
return nullptr;
}
LOGI("GetContextStageMode success");
return ability.get();
#else
return nullptr;
#endif
}
#ifndef PREVIEW
void CustomScope::Enter()
{
last_ = OHOS::Ace::ContainerScope::CurrentId();
OHOS::Ace::ContainerScope::UpdateCurrent(id_);
}
void CustomScope::Exit() const
{
OHOS::Ace::ContainerScope::UpdateCurrent(last_);
}
int32_t ARKTS_GetCurrentContainerId()
{
return OHOS::Ace::ContainerScope::CurrentId();
}
ContainerScope ARKTS_CreateContainerScope(int32_t id)
{
return new CustomScope(id);
}
void ARKTS_DestroyContainerScope(ContainerScope scope)
{
delete scope;
}
void ARKTS_EnterContainerScope(ContainerScope scope)
{
scope->Enter();
}
void ARKTS_ExitContainerScope(ContainerScope scope)
{
scope->Exit();
}
#else
int32_t ARKTS_GetCurrentContainerId() { return 0; }
ContainerScope ARKTS_CreateContainerScope(int32_t id) { return nullptr; }
void ARKTS_DestroyContainerScope(ContainerScope scope) {}
void ARKTS_EnterContainerScope(ContainerScope scope) {}
void ARKTS_ExitContainerScope(ContainerScope scope) {}
#endif
}

View File

@ -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.
*/
#ifndef NAPI_ARK_INTEROP_HELPER_H
#define NAPI_ARK_INTEROP_HELPER_H
#include "inner_api/cjffi/ark_interop/ark_interop_napi.h"
#include "napi/native_api.h"
#include <cstdint>
using ContainerScope = class CustomScope*;
extern "C" {
EXPORT napi_value ArkTsValuetoNapiValue(napi_env env, ARKTS_Value arkValue);
EXPORT ARKTS_Value NapiValueToArkTsValue(napi_value value);
EXPORT bool IsStageMode(napi_env env, napi_value context);
EXPORT void* GetContextStageMode(napi_env env, napi_value context);
EXPORT int32_t ARKTS_GetCurrentContainerId();
EXPORT ContainerScope ARKTS_CreateContainerScope(int32_t);
EXPORT void ARKTS_DestroyContainerScope(ContainerScope scope);
EXPORT void ARKTS_EnterContainerScope(ContainerScope scope);
EXPORT void ARKTS_ExitContainerScope(ContainerScope scope);
}
#endif // NAPI_ARK_INTEROP_HELPER_H

View File

@ -0,0 +1,33 @@
/*
* 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 NAPI_CUSTOM_SCOPE_H
#define NAPI_CUSTOM_SCOPE_H
#include <cstdint>
class CustomScope {
public:
explicit CustomScope(int32_t id): id_(id), last_(0) {}
void Enter();
void Exit() const;
private:
int32_t id_ = 0;
int32_t last_ = 0;
};
#endif // NAPI_CUSTOM_SCOPE_H

View File

@ -0,0 +1,31 @@
/*
* 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 ARK_INTEROP_HELPER_UTILS_H
#define ARK_INTEROP_HELPER_UTILS_H
#include <cstdint>
#include <memory>
#include <string>
#ifndef EXPORT
#ifdef __WINDOWS__
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __attribute__((visibility("default")))
#endif
#endif
#endif // ARK_INTEROP_HELPER_UTILS_H

View File

@ -21,7 +21,6 @@
#include "cj_utils_ffi.h"
#include "application_context.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace AbilityDelegatorCJ {

View File

@ -19,7 +19,6 @@
#include "application_context.h"
#include "cj_utils_ffi.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
namespace OHOS {
namespace ApplicationContextCJ {

View File

@ -18,7 +18,6 @@
#include "cj_utils_ffi.h"
#include "element_name.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
using OHOS::AppExecFwk::ElementName;

View File

@ -18,7 +18,6 @@
#include "securec.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
char* CreateCStringFromString(const std::string& source)
{

View File

@ -23,7 +23,6 @@
#include "want.h"
#include "want_params_wrapper.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
using OHOS::AAFwk::Want;
using OHOS::AppExecFwk::ElementName;

View File

@ -42,6 +42,7 @@ group("napi_packages") {
"${ability_runtime_napi_path}/app/error_manager:errormanager_napi",
"${ability_runtime_napi_path}/app/js_app_manager:appmanager",
"${ability_runtime_napi_path}/app/recovery:apprecovery_napi",
"${ability_runtime_napi_path}/app/sendable_context_manager:sendablecontextmanager_napi",
"${ability_runtime_napi_path}/app/test_runner:testrunner_napi",
"${ability_runtime_napi_path}/app_startup/async_task_callback:asynctaskcallback_napi",
"${ability_runtime_napi_path}/app_startup/async_task_excutor:asynctaskexcutor_napi",
@ -88,6 +89,9 @@ group("napi_packages") {
"${ability_runtime_napi_path}/share_extension_ability:shareextensionability_napi",
"${ability_runtime_napi_path}/ui_extension_ability:uiextensionability_napi",
"${ability_runtime_napi_path}/ui_extension_context:uiextensioncontext_napi",
"${ability_runtime_napi_path}/ui_service_extension_ability:uiserviceextensionability",
"${ability_runtime_napi_path}/ui_service_extension_ability:uiserviceextensionability_napi",
"${ability_runtime_napi_path}/ui_service_extension_context:uiserviceextensioncontext_napi",
"${ability_runtime_napi_path}/uri_permission:uripermissionmanager_napi",
"${ability_runtime_napi_path}/wantConstant:wantconstant",
"${ability_runtime_napi_path}/wantConstant:wantconstant_napi",

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_data_uri_utils_abc") {

View File

@ -18,6 +18,7 @@ ohos_shared_library("autostartupcallback") {
include_dirs = [
"./",
"${ability_runtime_napi_path}/inner/napi_common/",
"${ability_runtime_utils_path}/global/constant",
]
sources = [

View File

@ -16,7 +16,6 @@
#include "js_ability_auto_startup_callback.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_ability_auto_startup_manager_utils.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"

View File

@ -14,6 +14,8 @@
*/
#include "js_ability_auto_startup_manager_utils.h"
#include "global_constant.h"
#include "hilog_tag_wrapper.h"
#include "napi_common_util.h"
@ -68,7 +70,7 @@ bool IsNormalObject(napi_env env, napi_value value)
napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStartupInfo> &infoList)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
napi_value arrayObj = nullptr;
napi_create_array(env, &arrayObj);
for (size_t i = 0; i < infoList.size(); ++i) {
@ -89,7 +91,7 @@ napi_value CreateJsAutoStartupInfoArray(napi_env env, const std::vector<AutoStar
napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
napi_value object = AppExecFwk::CreateJSObject(env);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "object is nullptr.");
@ -127,7 +129,7 @@ napi_value CreateJsAutoStartupInfo(napi_env env, const AutoStartupInfo &info)
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Create js AutoStartupInfo failed.");
return nullptr;
}
if (info.appCloneIndex != -1) {
if (info.appCloneIndex >= 0 && info.appCloneIndex < GlobalConstant::MAX_APP_CLONE_INDEX) {
napi_value appCloneIndex = AppExecFwk::WrapInt32ToJS(env, info.appCloneIndex);
if (appCloneIndex == nullptr) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Convert ability type name failed.");

View File

@ -17,7 +17,6 @@
#define OHOS_ABILITY_RUNTIME_JS_ABILITY_AUTO_STARTUP_MANAGER_UTILS_H
#include "auto_startup_info.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "native_engine/native_engine.h"

View File

@ -19,7 +19,6 @@
#include "ability_manager_interface.h"
#include "auto_startup_info.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_ability_auto_startup_manager_utils.h"
#include "js_error_utils.h"
@ -41,7 +40,7 @@ constexpr const char *ON_OFF_TYPE_SYSTEM = "systemAutoStartup";
void JsAbilityAutoStartupManager::Finalizer(napi_env env, void *data, void *hint)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
std::unique_ptr<JsAbilityAutoStartupManager>(static_cast<JsAbilityAutoStartupManager *>(data));
}
@ -82,7 +81,7 @@ bool JsAbilityAutoStartupManager::CheckCallerIsSystemApp()
napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (info.argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowTooFewParametersError(env);
@ -130,7 +129,7 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnUnregisterAutoStartupCallback Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The argument is invalid.");
ThrowTooFewParametersError(env);
@ -175,7 +174,7 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnSetApplicationAutoStartup Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The argument is invalid.");
ThrowTooFewParametersError(env);
@ -225,7 +224,7 @@ napi_value JsAbilityAutoStartupManager::OnSetApplicationAutoStartup(napi_env env
napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "OnCancelApplicationAutoStartup Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "The param is invalid.");
ThrowTooFewParametersError(env);
@ -276,7 +275,7 @@ napi_value JsAbilityAutoStartupManager::OnCancelApplicationAutoStartup(napi_env
napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_env env, const NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (!CheckCallerIsSystemApp()) {
ThrowError(env, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP);
return CreateJsUndefined(env);
@ -316,7 +315,7 @@ napi_value JsAbilityAutoStartupManager::OnQueryAllAutoStartupApplications(napi_e
napi_value JsAbilityAutoStartupManagerInit(napi_env env, napi_value exportObj)
{
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called.");
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
if (env == nullptr || exportObj == nullptr) {
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Env or exportObj nullptr.");
return nullptr;

View File

@ -15,7 +15,6 @@
#include "ability_window_configuration.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "launch_param.h"
#include "mission_info.h"
#include "napi/native_api.h"

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_context_abc") {

View File

@ -112,6 +112,18 @@ class AbilityContext extends Context {
startAbilityForResultWithAccount(want, accountId, options, callback) {
return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, options, callback);
}
startUIServiceExtensionAbility(want, callback) {
return this.__context_impl__.startUIServiceExtensionAbility(want, callback);
}
connectUIServiceExtensionAbility(want, callback) {
return this.__context_impl__.connectUIServiceExtensionAbility(want, callback);
}
disconnectUIServiceExtensionAbility(proxy) {
return this.__context_impl__.disconnectUIServiceExtensionAbility(proxy);
}
startServiceExtensionAbility(want, callback) {
return this.__context_impl__.startServiceExtensionAbility(want, callback);

View File

@ -16,7 +16,6 @@
#include "js_ability_foreground_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
namespace OHOS {
@ -28,7 +27,7 @@ JSAbilityForegroundStateObserver::JSAbilityForegroundStateObserver(napi_env env)
void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (!valid_) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The app manager may has destroyed.");
return;
@ -50,7 +49,7 @@ void JSAbilityForegroundStateObserver::OnAbilityStateChanged(const AbilityStateD
void JSAbilityForegroundStateObserver::HandleOnAbilityStateChanged(const AbilityStateData &abilityStateData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
for (auto &item : jsObserverObjectSet_) {
if (item == nullptr) {
continue;

View File

@ -26,7 +26,6 @@
#include "errors.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -149,7 +148,7 @@ private:
napi_value OnOn(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params.");
ThrowTooFewParametersError(env);
@ -195,7 +194,7 @@ private:
napi_value OnOff(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
@ -233,7 +232,7 @@ private:
napi_value OnNotifyDebugAssertResult(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
@ -550,7 +549,7 @@ private:
napi_value OnGetForegroundUIAbilities(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
NapiAsyncTask::CompleteCallback complete = [](napi_env env, NapiAsyncTask &task, int32_t status) {
std::vector<AppExecFwk::AbilityStateData> list;
int32_t ret = AbilityManagerClient::GetInstance()->GetForegroundUIAbilities(list);
@ -571,7 +570,7 @@ private:
napi_value OnSetResidentProcessEnabled(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
@ -621,7 +620,7 @@ private:
napi_value OnIsEmbeddedOpenAllowed(napi_env env, NapiCallbackInfo& info)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (info.argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not enough params");
ThrowTooFewParametersError(env);

View File

@ -19,7 +19,6 @@
#include "ability_state.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi_common_want.h"
@ -119,7 +118,7 @@ napi_value AbilityStateInit(napi_env env)
napi_value UserStatusInit(napi_env env)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
@ -132,7 +131,7 @@ napi_value UserStatusInit(napi_env env)
napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
napi_value object = nullptr;
napi_create_object(env, &object);
if (object == nullptr) {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_action_extension_ability_abc") {

View File

@ -16,7 +16,6 @@
#include "ability_monitor.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "js_ability_delegator_utils.h"
#include "napi/native_common.h"

View File

@ -18,7 +18,6 @@
#include <mutex>
#include "ability_delegator_registry.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_ability_delegator_utils.h"
#include "js_context_utils.h"
#include "js_error_utils.h"

View File

@ -19,7 +19,6 @@
#include "ability_delegator.h"
#include "ability_delegator_registry.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_ability_delegator.h"
#include "js_ability_delegator_utils.h"
#include "js_runtime_utils.h"

View File

@ -17,7 +17,6 @@
#include <map>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_ability_monitor.h"
#include "napi/native_common.h"

View File

@ -18,7 +18,6 @@
#include <memory>
#include <string>
#include "hilog_wrapper.h"
#include "native_engine/native_reference.h"
namespace OHOS {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_lifecycle_callback_abc") {

View File

@ -83,6 +83,26 @@ class AbilityLifecycleCallback {
onAbilityWillBackground(ability) {
console.log('onAbilityWillBackground');
}
onAbilityWillContinue(ability) {
console.log('onAbilityWillContinue');
}
onWindowStageWillRestore(ability, windowStage) {
console.log('onWindowStageWillRestore');
}
onWindowStageRestore(ability, windowStage) {
console.log('onWindowStageRestore');
}
onAbilityWillSaveState(ability) {
console.log('onAbilityWillSaveState');
}
onAbilitySaveState(ability) {
console.log('onAbilitySaveState');
}
}
export default AbilityLifecycleCallback;

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_stage_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_ability_stage_context_abc") {

View File

@ -19,9 +19,9 @@
#include <mutex>
#include "ability_manager_interface.h"
#include "ability_manager_errors.h"
#include "app_mgr_interface.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi/native_api.h"
@ -179,32 +179,37 @@ private:
}
}
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, observer = observer_, observerId, errCode](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (observer == nullptr || appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr"));
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task.Resolve(env, CreateJsUndefined(env));
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed"));
}
};
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnUnregisterApplicationStateObserver",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, observer = observer_, observerId, errCode,
env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (observer == nullptr || appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr"));
delete task;
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task->Resolve(env, CreateJsUndefined(env));
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task->Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed"));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -218,32 +223,38 @@ private:
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task.Resolve(env, CreateJsAppStateDataArray(env, list));
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed"));
}
};
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnGetForegroundApplications",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
delete task;
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task->Resolve(env, CreateJsAppStateDataArray(env, list));
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task->Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed"));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -257,25 +268,30 @@ private:
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, errCode](napi_env env, NapiAsyncTask &task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetAllRunningProcesses(infos);
if (ret == 0) {
task.Resolve(env, CreateJsProcessRunningInfoArray(env, infos));
} else {
task.Reject(env, CreateJsError(env, ret, "Get mission infos failed."));
}
};
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnGetProcessRunningInfos",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetAllRunningProcesses(infos);
if (ret == 0) {
task->Resolve(env, CreateJsProcessRunningInfoArray(env, infos));
} else {
task->Reject(env, CreateJsError(env, ret, "Get mission infos failed."));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -289,29 +305,51 @@ private:
TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.Resolve(env, CreateJsValue(env, ret));
};
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnIsRunningInStabilityTest",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
delete task;
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task->Resolve(env, CreateJsValue(env, ret));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
static void OnKillProcessByBundleNameInner(std::string bundleName, bool clearPageStack,
sptr<OHOS::AAFwk::IAbilityManager> abilityManager, napi_env env, NapiAsyncTask *task)
{
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
if (ret == 0) {
task->Resolve(env, CreateJsValue(env, ret));
} else {
task->Reject(env, CreateJsError(env, ret, "kill process failed."));
}
}
napi_value OnKillProcessByBundleName(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
@ -340,29 +378,23 @@ private:
TAG_LOGI(AAFwkTag::APPMGR,
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
NapiAsyncTask::CompleteCallback complete =
[bundleName, clearPageStack, abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task,
int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
if (ret == 0) {
task.Resolve(env, CreateJsValue(env, ret));
} else {
task.Reject(env, CreateJsError(env, ret, "kill process failed."));
}
};
napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessByBundleName",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, errCode,
env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
} else {
OnKillProcessByBundleNameInner(bundleName, clearPageStack, abilityManager, env, task);
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -385,30 +417,35 @@ private:
}
}
NapiAsyncTask::CompleteCallback complete =
[bundleName, appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task,
int32_t status) {
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr"));
delete task;
return;
}
auto ret = appManager->ClearUpApplicationData(bundleName, 0);
if (ret == 0) {
task.Resolve(env, CreateJsValue(env, ret));
task->Resolve(env, CreateJsValue(env, ret));
} else {
task.Reject(env, CreateJsError(env, ret, "clear up application failed."));
task->Reject(env, CreateJsError(env, AAFwk::CLEAR_APPLICATION_DATA_FAIL,
"clear up application failed."));
}
delete task;
};
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnClearUpApplicationData",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -445,27 +482,32 @@ private:
TAG_LOGI(AAFwkTag::APPMGR,
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, bundleName, accountId, clearPageStack, errCode](
napi_env env, NapiAsyncTask &task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
if (ret == 0) {
task.Resolve(env, CreateJsUndefined(env));
} else {
TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, ret, "Kill processes failed."));
}
};
napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
return result;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack, errCode,
env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
if (ret == 0) {
task->Resolve(env, CreateJsUndefined(env));
} else {
TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task->Reject(env, CreateJsError(env, ret, "Kill processes failed."));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
TAG_LOGD(AAFwkTag::APPMGR, "end");
return result;
}
napi_value OnGetAppMemorySize(napi_env env, const size_t argc, napi_value* argv)
@ -477,26 +519,32 @@ private:
TAG_LOGE(AAFwkTag::APPMGR, "Insufficient params");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task.Resolve(env, CreateJsValue(env, memorySize));
};
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetAppMemorySize",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
delete task;
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task->Resolve(env, CreateJsValue(env, memorySize));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -509,26 +557,32 @@ private:
TAG_LOGE(AAFwkTag::APPMGR, "Not enough parameters");
errCode = ERR_NOT_OK;
}
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (errCode != 0) {
task.Reject(env, CreateJsError(env, errCode, "Invalidate params."));
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.Resolve(env, CreateJsValue(env, ret));
};
napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsRamConstrainedDevice",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() {
if (errCode != 0) {
task->Reject(env, CreateJsError(env, errCode, "Invalidate params."));
delete task;
return;
}
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr"));
delete task;
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task->Resolve(env, CreateJsValue(env, ret));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
} else {
napiAsyncTask.release();
}
return result;
}
};

View File

@ -18,7 +18,6 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iapplication_state_observer.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"

View File

@ -15,7 +15,6 @@
#include "js_app_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
#include "js_app_manager_utils.h"

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_application_context_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_application_state_change_callback_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_context_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_environment_callback_abc") {

View File

@ -22,7 +22,6 @@
#include "application_data_manager.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_error_observer.h"
#include "js_error_utils.h"
#include "js_runtime.h"
@ -541,7 +540,7 @@ private:
loopObserver_ = nullptr;
TAG_LOGI(AAFwkTag::JSNAPI, "Remove loopObserver success");
} else {
TAG_LOGI(AAFwkTag::JSNAPI, "Unregister loopObserver Called.");
TAG_LOGI(AAFwkTag::JSNAPI, "called");
}
return nullptr;
}

View File

@ -18,7 +18,6 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi/native_api.h"

View File

@ -48,7 +48,7 @@ void JSAbilityFirstFrameStateObserver::OnAbilityFirstFrameState(
void JSAbilityFirstFrameStateObserver::HandleOnAbilityFirstFrameState(
const AbilityFirstFrameStateData &AbilityFirstFrameStateData)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
napi_value obj = jsObserverObject_->GetNapiValue();
napi_value argv[] = { CreateJsAbilityFirstFrameStateData(env_, AbilityFirstFrameStateData) };
CallJsFunction(obj, "onAbilityFirstFrameDrawn", argv, ARGC_ONE);
@ -57,7 +57,7 @@ void JSAbilityFirstFrameStateObserver::HandleOnAbilityFirstFrameState(
void JSAbilityFirstFrameStateObserver::CallJsFunction(
const napi_value value, const char *methodName, const napi_value *argv, const size_t argc)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (value == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "value is nullptr.");
return;
@ -128,7 +128,7 @@ bool JSAbilityFirstFrameStateObserverManager::IsObserverObjectExist(const napi_v
void JSAbilityFirstFrameStateObserverManager::RemoveAllJsObserverObjects(
sptr<OHOS::AAFwk::IAbilityManager> &abilityManager)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (abilityManager == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManager is nullptr.");
return;
@ -144,7 +144,7 @@ void JSAbilityFirstFrameStateObserverManager::RemoveAllJsObserverObjects(
void JSAbilityFirstFrameStateObserverManager::RemoveJsObserverObject(
sptr<OHOS::AAFwk::IAbilityManager> &abilityManager, const napi_value &jsObserverObject)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
if (abilityManager == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityManager is nullptr.");
return;

View File

@ -27,7 +27,7 @@ JSAppForegroundStateObserver::JSAppForegroundStateObserver(napi_env env) : env_(
void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStateData)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (!valid_) {
TAG_LOGE(AAFwkTag::APPMGR, "The app manager may has destroyed.");
return;
@ -49,7 +49,7 @@ void JSAppForegroundStateObserver::OnAppStateChanged(const AppStateData &appStat
void JSAppForegroundStateObserver::HandleOnAppStateChanged(const AppStateData &appStateData)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
std::lock_guard<std::mutex> lock(jsObserverObjectSetLock_);
for (auto &item : jsObserverObjectSet_) {
napi_value obj = item->GetNapiValue();

View File

@ -26,7 +26,6 @@
#include "application_info.h"
#include "event_runner.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -343,7 +342,7 @@ private:
napi_value OnOnForeground(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_TWO) {
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params.");
ThrowTooFewParametersError(env);
@ -482,6 +481,23 @@ private:
return CreateJsUndefined(env);
}
#endif
static void OnOffOldInner(sptr<OHOS::AppExecFwk::IAppMgr> appManager, sptr<JSAppStateObserver> observer,
int64_t observerId, napi_env env, NapiAsyncTask *task)
{
if (observer == nullptr || appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task->ResolveWithNoError(env, CreateJsUndefined(env));
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize());
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task->Reject(env, CreateJsErrorByNativeErr(env, ret));
}
}
napi_value OnOffOld(napi_env env, size_t argc, napi_value* argv)
{
@ -511,29 +527,20 @@ private:
}
TAG_LOGD(AAFwkTag::APPMGR, "find observer exist observer:%{public}d", static_cast<int32_t>(observerId));
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, observer = observer_, observerId](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (observer == nullptr || appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t ret = appManager->UnregisterApplicationStateObserver(observer);
if (ret == 0 && observer->RemoveJsObserverObject(observerId)) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu",
observer->GetJsObserverMapSize());
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsErrorByNativeErr(env, ret));
}
};
napi_value lastParam = (argc > ARGC_TWO) ? argv[INDEX_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnUnregisterApplicationStateObserver",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, observer = observer_, observerId,
env, task = napiAsyncTask.get()]() {
OnOffOldInner(appManager, observer, observerId, env, task);
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -575,7 +582,7 @@ private:
napi_value OnOffForeground(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Not enough params when off.");
ThrowTooFewParametersError(env);
@ -611,54 +618,66 @@ private:
napi_value OnGetForegroundApplications(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task.ResolveWithNoError(env, CreateJsAppStateDataArray(env, list));
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
};
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnGetForegroundApplications",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
std::vector<AppExecFwk::AppStateData> list;
int32_t ret = appManager->GetForegroundApplications(list);
if (ret == 0) {
TAG_LOGD(AAFwkTag::APPMGR, "success.");
task->ResolveWithNoError(env, CreateJsAppStateDataArray(env, list));
} else {
TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret);
task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value OnGetRunningProcessInformation(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetAllRunningProcesses(infos);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
};
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnGetRunningProcessInformation",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetAllRunningProcesses(infos);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -729,52 +748,78 @@ private:
ThrowInvalidParamError(env, "Parse param bundleType failed, must not be less then zero.");
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, bundleType](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetRunningProcessesByBundleType(
static_cast<AppExecFwk::BundleType>(bundleType), infos);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
};
napi_value lastParam = (argc > ARGC_ONE) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnGetRunningProcessInformationByBundleType",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, bundleType, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
auto ret = appManager->GetRunningProcessesByBundleType(
static_cast<AppExecFwk::BundleType>(bundleType), infos);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret)));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value OnIsRunningInStabilityTest(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "called");
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnIsRunningInStabilityTest",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
bool ret = abilityManager->IsRunningInStabilityTest();
TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret);
task->ResolveWithNoError(env, CreateJsValue(env, ret));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
static void OnKillProcessesByBundleNameInner(std::string bundleName, bool clearPageStack,
sptr<OHOS::AAFwk::IAbilityManager> abilityManager, napi_env env, NapiAsyncTask *task)
{
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed."));
}
}
napi_value OnKillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "OnKillProcessesByBundleName called");
@ -803,25 +848,20 @@ private:
TAG_LOGI(AAFwkTag::APPMGR,
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
NapiAsyncTask::CompleteCallback complete =
[bundleName, clearPageStack, abilityManager = abilityManager_](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto ret = abilityManager->KillProcess(bundleName, clearPageStack);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed."));
}
};
napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessesByBundleName",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_,
env, task = napiAsyncTask.get()]() {
OnKillProcessesByBundleNameInner(bundleName, clearPageStack, abilityManager, env, task);
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -841,25 +881,30 @@ private:
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[bundleName, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
auto ret = appManager->ClearUpApplicationData(bundleName, 0);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
task->ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed."));
task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed."));
}
delete task;
};
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnClearUpApplicationData",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -885,24 +930,29 @@ private:
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[bundleName, appCloneIndex, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result);
auto asyncTask = [bundleName, appCloneIndex, appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
auto ret = appManager->ClearUpApplicationData(bundleName, appCloneIndex);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
task->ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed."));
task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed."));
}
delete task;
};
napi_value result = nullptr;
NapiAsyncTask::Schedule("JSAppManager::OnClearUpAppData",
env, CreateAsyncTaskWithLastParam(env, nullptr, nullptr, std::move(complete), &result));
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -929,22 +979,27 @@ private:
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[bundleName, versionCode, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr;
napi_value result = nullptr;
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, versionCode, appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
bool ret = appManager->IsSharedBundleRunning(bundleName, versionCode);
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
task->ResolveWithNoError(env, CreateJsValue(env, ret));
delete task;
};
napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsSharedBundleRunning",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -981,67 +1036,83 @@ private:
TAG_LOGI(AAFwkTag::APPMGR,
"kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]",
bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex);
NapiAsyncTask::CompleteCallback complete =
[appManager = appManager_, bundleName, accountId, clearPageStack](
napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr.");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed."));
}
};
napi_value lastParam = (argc == ARGC_THREE && !hasClearPageStack) ? argv[INDEX_TWO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack,
env, task = napiAsyncTask.get()]() {
if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr.");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task->Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed."));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value OnGetAppMemorySize(napi_env env, size_t argc, napi_value* argv)
{
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task.ResolveWithNoError(env, CreateJsValue(env, memorySize));
};
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetAppMemorySize",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
int32_t memorySize = abilityManager->GetAppMemorySize();
TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize);
task->ResolveWithNoError(env, CreateJsValue(env, memorySize));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value OnIsRamConstrainedDevice(napi_env env, size_t argc, napi_value* argv)
{
NapiAsyncTask::CompleteCallback complete =
[abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task.ResolveWithNoError(env, CreateJsValue(env, ret));
};
napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsRamConstrainedDevice",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() {
if (abilityManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
bool ret = abilityManager->IsRamConstrainedDevice();
TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret);
task->ResolveWithNoError(env, CreateJsValue(env, ret));
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
@ -1061,29 +1132,50 @@ private:
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[pid, appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr");
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
int32_t memSize = 0;
int32_t ret = appManager->GetProcessMemoryByPid(pid, memSize);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsValue(env, memSize));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret));
}
};
napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr;
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetProcessMemoryByPid",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [pid, appManager = appManager_, env, task = napiAsyncTask.get()]() {
if (appManager == nullptr) {
TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr");
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
delete task;
return;
}
int32_t memSize = 0;
int32_t ret = appManager->GetProcessMemoryByPid(pid, memSize);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsValue(env, memSize));
} else {
task->Reject(env, CreateJsErrorByNativeErr(env, ret));
}
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
static void OnGetRunningProcessInfoByBundleNameInner(std::string bundleName, int userId,
sptr<OHOS::AppExecFwk::IAppMgr> appManager, napi_env env, NapiAsyncTask *task)
{
if (appManager == nullptr) {
task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos);
if (ret == 0) {
task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task->Reject(env, CreateJsErrorByNativeErr(env, ret));
}
}
napi_value OnGetRunningProcessInfoByBundleName(napi_env env, size_t argc, napi_value* argv)
{
if (argc < ARGC_ONE) {
@ -1116,30 +1208,25 @@ private:
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[bundleName, userId, appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) {
if (appManager == nullptr) {
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
}
std::vector<AppExecFwk::RunningProcessInfo> infos;
int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos);
if (ret == 0) {
task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, ret));
}
};
napi_value lastParam = isPromiseType ? nullptr : argv[argc - 1];
napi_value result = nullptr;
NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetRunningProcessInfoByBundleName",
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
std::unique_ptr<NapiAsyncTask> napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result);
auto asyncTask = [bundleName, userId, appManager = appManager_, env, task = napiAsyncTask.get()]() {
OnGetRunningProcessInfoByBundleNameInner(bundleName, userId, appManager, env, task);
delete task;
};
if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) {
napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env,
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!"));
} else {
napiAsyncTask.release();
}
return result;
}
napi_value OnIsApplicationRunning(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Params not match.");
ThrowTooFewParametersError(env);
@ -1184,7 +1271,7 @@ private:
napi_value OnIsAppRunning(napi_env env, size_t argc, napi_value *argv)
{
TAG_LOGD(AAFwkTag::APPMGR, "Called.");
TAG_LOGD(AAFwkTag::APPMGR, "called");
if (argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::APPMGR, "Params not match.");
ThrowTooFewParametersError(env);

View File

@ -18,7 +18,6 @@
#include <cstdint>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "iapplication_state_observer.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"

View File

@ -15,7 +15,6 @@
#include "js_app_state_observer.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
#include "js_app_manager_utils.h"

View File

@ -17,7 +17,6 @@
#include "app_recovery.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"

View File

@ -0,0 +1,62 @@
# 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")
ohos_shared_library("sendablecontextmanager_napi") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"${ability_runtime_napi_path}/ability_auto_startup_callback",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
]
sources = [
"js_sendable_context_manager.cpp",
"native_module.cpp",
]
configs = [ "${ability_runtime_services_path}/common:common_config" ]
deps = [
"${ability_runtime_innerkits_path}/napi_base_context:napi_base_context",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_native_path}/appkit:appkit_native",
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"hilog:libhilog",
"napi:ace_napi",
]
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
part_name = "ability_runtime"
}

View File

@ -0,0 +1,433 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "js_sendable_context_manager.h"
#include "ability_context.h"
#include "ability_stage_context.h"
#include "application_context.h"
#include "context.h"
#include "js_ability_context.h"
#include "js_ability_stage_context.h"
#include "js_application_context_utils.h"
#include "js_context_utils.h"
#include "js_error_utils.h"
#include "js_runtime_utils.h"
#include "hilog_tag_wrapper.h"
#include "napi_base_context.h"
namespace OHOS {
namespace AbilityRuntime {
namespace {
constexpr size_t ARGC_ONE = 1;
} // namespace
class JsContext {
public:
explicit JsContext(std::weak_ptr<Context>&& context) : context_(std::move(context)) {}
virtual ~JsContext() = default;
static void Finalizer(napi_env env, void* data, void* hint);
std::weak_ptr<Context> context_;
};
void JsContext::Finalizer(napi_env env, void* data, void* hint)
{
TAG_LOGD(AAFwkTag::CONTEXT, "JsContext finalizer.");
if (data == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Input data invalid.");
return;
}
std::unique_ptr<JsContext>(static_cast<JsContext*>(data));
}
napi_value CreateSendableContextObject(napi_env env, std::shared_ptr<Context> context)
{
auto jsContext = std::make_unique<JsContext>(context);
napi_value objValue = nullptr;
auto status = napi_ok;
// Sendable context has no property for now.
status = napi_create_sendable_object_with_properties(env, 0, nullptr, &objValue);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Create sendable context failed with %{public}d.", status);
return nullptr;
}
status = napi_wrap_sendable(env, objValue, jsContext.release(), JsContext::Finalizer, nullptr);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Wrap sendable failed with %{public}d.", status);
return nullptr;
}
return objValue;
}
napi_value CreateJsBaseContextFromSendable(napi_env env, void* wrapped)
{
JsContext *sendableContext = static_cast<JsContext*>(wrapped);
if (sendableContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed.");
return nullptr;
}
auto weakContext = sendableContext->context_;
std::shared_ptr<Context> context = weakContext.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid.");
return nullptr;
}
auto contextPtr = Context::ConvertTo<Context>(context);
if (contextPtr == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to context failed.");
return nullptr;
}
// create normal context
auto value = CreateJsBaseContext(env, contextPtr);
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.Context", &value, 1);
if (systemModule == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Load context module failed.");
return nullptr;
}
return systemModule->GetNapiValue();
}
napi_value CreateJsApplicationContextFromSendable(napi_env env, void* wrapped)
{
JsContext *sendableContext = static_cast<JsContext*>(wrapped);
if (sendableContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed.");
return nullptr;
}
auto weakContext = sendableContext->context_;
std::shared_ptr<Context> context = weakContext.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid.");
return nullptr;
}
auto applicationContext = Context::ConvertTo<ApplicationContext>(context);
if (applicationContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to application context failed.");
return nullptr;
}
// create application context
auto value = JsApplicationContextUtils::CreateJsApplicationContext(env);
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.ApplicationContext", &value, 1);
if (systemModule == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Load application context module failed.");
return nullptr;
}
return systemModule->GetNapiValue();
}
napi_value CreateJsAbilityStageContextFromSendable(napi_env env, void* wrapped)
{
JsContext *sendableContext = static_cast<JsContext*>(wrapped);
if (sendableContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed.");
return nullptr;
}
auto weakContext = sendableContext->context_;
std::shared_ptr<Context> context = weakContext.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid.");
return nullptr;
}
auto abilitystageContext = Context::ConvertTo<AbilityStageContext>(context);
if (abilitystageContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to ability stage context failed.");
return nullptr;
}
// create normal abilitystage context
auto value = CreateJsAbilityStageContext(env, abilitystageContext);
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityStageContext", &value, 1);
if (systemModule == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Load ability stage context module failed.");
return nullptr;
}
return systemModule->GetNapiValue();
}
napi_value CreateJsUIAbilityContextFromSendable(napi_env env, void* wrapped)
{
JsContext *sendableContext = static_cast<JsContext*>(wrapped);
if (sendableContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed.");
return nullptr;
}
auto weakContext = sendableContext->context_;
std::shared_ptr<Context> context = weakContext.lock();
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid.");
return nullptr;
}
auto uiAbilityContext = Context::ConvertTo<AbilityContext>(context);
if (uiAbilityContext == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to UIAbility context failed.");
return nullptr;
}
// create normal uiability context
auto value = CreateJsAbilityContext(env, uiAbilityContext);
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityContext", &value, 1);
if (systemModule == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Load ability context module failed.");
return nullptr;
}
return systemModule->GetNapiValue();
}
class JsSendableContextManager {
public:
JsSendableContextManager() = default;
~JsSendableContextManager() = default;
static void Finalizer(napi_env env, void *data, void *hint)
{
TAG_LOGD(AAFwkTag::CONTEXT, "JsSendableContextManager finalizer.");
if (data == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Input data invalid.");
return;
}
std::unique_ptr<JsSendableContextManager>(static_cast<JsSendableContextManager*>(data));
}
static napi_value ConvertFromContext(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertFromContext);
}
static napi_value ConvertToContext(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToContext);
}
static napi_value ConvertToApplicationContext(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToApplicationContext);
}
static napi_value ConvertToAbilityStageContext(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToAbilityStageContext);
}
static napi_value ConvertToUIAbilityContext(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToUIAbilityContext);
}
private:
napi_value OnConvertFromContext(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Convert from context.");
if (info.argc != ARGC_ONE) {
TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid.");
ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid.");
return CreateJsUndefined(env);
}
// Get native context
bool stageMode = false;
napi_status status = IsStageContext(env, info.argv[0], stageMode);
if (status != napi_ok || !stageMode) {
TAG_LOGE(AAFwkTag::CONTEXT, "Context isn't stageMode, status is %{public}d.", status);
ThrowInvalidParamError(env, "Parse param context failed, must be a context of stageMode.");
return CreateJsUndefined(env);
}
auto context = GetStageModeContext(env, info.argv[0]);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Get context failed");
ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr.");
return CreateJsUndefined(env);
}
auto contextPtr = Context::ConvertTo<Context>(context);
if (contextPtr == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to context failed.");
ThrowInvalidParamError(env, "Parse param context failed, must be a context.");
return CreateJsUndefined(env);
}
// create sendable context
return CreateSendableContextObject(env, contextPtr);
}
napi_value OnConvertToContext(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Convert to context.");
if (info.argc != ARGC_ONE) {
TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid.");
ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid.");
return CreateJsUndefined(env);
}
// Get context
void *wrapped = nullptr;
auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status);
ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid.");
return CreateJsUndefined(env);
}
// Create normal context
auto object = CreateJsBaseContextFromSendable(env, wrapped);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed.");
ThrowInvalidParamError(env, "Parameter error: Create context failed.");
return CreateJsUndefined(env);
}
return object;
}
napi_value OnConvertToApplicationContext(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Convert to application context.");
if (info.argc != ARGC_ONE) {
TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid.");
ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid.");
return CreateJsUndefined(env);
}
// Get context
void *wrapped = nullptr;
auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status);
ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid.");
return CreateJsUndefined(env);
}
// Create normal context
auto object = CreateJsApplicationContextFromSendable(env, wrapped);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed.");
ThrowInvalidParamError(env, "Parameter error: Create application context failed.");
return CreateJsUndefined(env);
}
return object;
}
napi_value OnConvertToAbilityStageContext(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Convert to ability stage context.");
if (info.argc != ARGC_ONE) {
TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid.");
ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid.");
return CreateJsUndefined(env);
}
// Get context
void *wrapped = nullptr;
auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status);
ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid.");
return CreateJsUndefined(env);
}
// Create normal context
auto object = CreateJsAbilityStageContextFromSendable(env, wrapped);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed.");
ThrowInvalidParamError(env, "Parameter error: Create ability stage context failed.");
return CreateJsUndefined(env);
}
return object;
}
napi_value OnConvertToUIAbilityContext(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Convert to uiability context.");
if (info.argc != ARGC_ONE) {
TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid.");
ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid.");
return CreateJsUndefined(env);
}
// Get context
void *wrapped = nullptr;
auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status);
ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid.");
return CreateJsUndefined(env);
}
// Create uiability context
auto object = CreateJsUIAbilityContextFromSendable(env, wrapped);
if (object == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Create uiability context failed.");
ThrowInvalidParamError(env, "Parameter error: Create uiability context failed.");
return CreateJsUndefined(env);
}
return object;
}
};
napi_value CreateJsSendableContextManager(napi_env env, napi_value exportObj)
{
TAG_LOGD(AAFwkTag::CONTEXT, "Create sendable context manager.");
if (env == nullptr || exportObj == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "Invalid parameter.");
return nullptr;
}
napi_status status = napi_ok;
std::unique_ptr<JsSendableContextManager> sendableMgr = std::make_unique<JsSendableContextManager>();
status = napi_wrap(env, exportObj, sendableMgr.release(), JsSendableContextManager::Finalizer, nullptr, nullptr);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "napi wrap failed with %{public}d.", status);
return nullptr;
}
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("convertFromContext", JsSendableContextManager::ConvertFromContext),
DECLARE_NAPI_FUNCTION("convertToContext", JsSendableContextManager::ConvertToContext),
DECLARE_NAPI_FUNCTION("convertToApplicationContext", JsSendableContextManager::ConvertToApplicationContext),
DECLARE_NAPI_FUNCTION("convertToAbilityStageContext", JsSendableContextManager::ConvertToAbilityStageContext),
DECLARE_NAPI_FUNCTION("convertToUIAbilityContext", JsSendableContextManager::ConvertToUIAbilityContext),
};
status = napi_define_properties(env, exportObj, sizeof(properties) / sizeof(properties[0]), properties);
if (status != napi_ok) {
TAG_LOGE(AAFwkTag::CONTEXT, "napi define property failed with %{public}d.", status);
return nullptr;
}
return exportObj;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -0,0 +1,32 @@
/*
* 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_JS_SENDABLE_CONTEXT_MANAGER_H
#define OHOS_ABILITY_RUNTIME_JS_SENDABLE_CONTEXT_MANAGER_H
#include "native_engine/native_engine.h"
namespace OHOS {
namespace AbilityRuntime {
class Context;
napi_value CreateJsSendableContextManager(napi_env env, napi_value exportObj);
napi_value CreateSendableContextObject(napi_env env, std::shared_ptr<Context> context);
napi_value CreateJsBaseContextFromSendable(napi_env env, void* wrapped);
napi_value CreateJsApplicationContextFromSendable(napi_env env, void* wrapped);
napi_value CreateJsAbilityStageContextFromSendable(napi_env env, void* wrapped);
napi_value CreateJsUIAbilityContextFromSendable(napi_env env, void* wrapped);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_SENDABLE_CONTEXT_MANAGER_H

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "js_sendable_context_manager.h"
#include "native_engine/native_engine.h"
static napi_module _module = {
.nm_version = 0,
.nm_filename = "app/ability/libsendablecontextmanager_napi.so",
.nm_register_func = OHOS::AbilityRuntime::CreateJsSendableContextManager,
.nm_modname = "app.ability.sendableContextManager",
};
extern "C" __attribute__((constructor))
void NapiAppAbilitySendableContextManagerAutoRegister()
{
napi_module_register(&_module);
}

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_test_runner_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_async_task_callback_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_async_task_excutor_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_startup_config_entry_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_startup_listener_abc") {

View File

@ -17,7 +17,6 @@
#include "ability_runtime_error_util.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_startup_config.h"
#include "js_startup_task_result.h"
#include "napi/native_api.h"
@ -34,7 +33,7 @@ constexpr size_t ARGC_TWO = 2;
} // namespace
void JsStartupManager::Finalizer(napi_env env, void *data, void *hint)
{
TAG_LOGD(AAFwkTag::STARTUP, "Called.");
TAG_LOGD(AAFwkTag::STARTUP, "called");
std::unique_ptr<JsStartupManager>(static_cast<JsStartupManager *>(data));
}
@ -204,7 +203,7 @@ napi_value JsStartupManager::OnRemoveResult(napi_env env, NapiCallbackInfo &info
napi_value JsStartupManagerInit(napi_env env, napi_value exportObj)
{
TAG_LOGD(AAFwkTag::STARTUP, "Called.");
TAG_LOGD(AAFwkTag::STARTUP, "called");
if (env == nullptr || exportObj == nullptr) {
TAG_LOGE(AAFwkTag::STARTUP, "Env or exportObj nullptr.");
return nullptr;

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_startup_task_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_auto_fill_extension_ability_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_auto_fill_extension_context_abc") {

View File

@ -18,7 +18,6 @@
#include "ability_business_error.h"
#include "auto_fill_manager.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "ipc_skeleton.h"
#include "js_error_utils.h"
@ -32,7 +31,7 @@ constexpr size_t ARGC_ONE = 1;
void JsAutoFillManager::Finalizer(napi_env env, void *data, void *hint)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
std::unique_ptr<JsAutoFillManager>(static_cast<JsAutoFillManager *>(data));
}
@ -43,7 +42,7 @@ napi_value JsAutoFillManager::RequestAutoSave(napi_env env, napi_callback_info i
napi_value JsAutoFillManager::OnRequestAutoSave(napi_env env, NapiCallbackInfo &info)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
if (info.argc < ARGC_ONE) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "The param is invalid.");
ThrowTooFewParametersError(env);
@ -72,7 +71,7 @@ napi_value JsAutoFillManager::OnRequestAutoSave(napi_env env, NapiCallbackInfo &
return CreateJsUndefined(env);
}
auto autoSaveMangerFunc = std::bind(&JsAutoFillManager::OnRequestAutoSaveDone, this, std::placeholders::_1);
auto autoSaveMangerFunc = [this](const int32_t arg) { this->OnRequestAutoSaveDone(arg); };
saveCallback = std::make_shared<JsAutoSaveRequestCallback>(env, instanceId, autoSaveMangerFunc);
if (saveCallback == nullptr) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "saveCallback is nullptr.");
@ -107,7 +106,8 @@ void JsAutoFillManager::OnRequestAutoSaveInner(napi_env env, int32_t instanceId,
AutoFill::AutoFillRequest request;
uiContent->DumpViewData(request.viewData, request.autoFillType);
request.autoFillCommand = AutoFill::AutoFillCommand::SAVE;
auto ret = AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, saveRequestCallback);
AbilityRuntime::AutoFill::AutoFillResult result;
auto ret = AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, saveRequestCallback, result);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Request auto save error[%{public}d].", ret);
ThrowError(env, GetJsErrorCodeByNativeError(ret));
@ -140,7 +140,7 @@ void JsAutoFillManager::OnRequestAutoSaveDone(int32_t instanceId)
napi_value CreateJsAutoFillType(napi_env env)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
@ -191,7 +191,7 @@ napi_value CreateJsAutoFillType(napi_env env)
napi_value CreateJsPopupPlacement(napi_env env)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
@ -215,7 +215,7 @@ napi_value CreateJsPopupPlacement(napi_env env)
napi_value JsAutoFillManagerInit(napi_env env, napi_value exportObj)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
if (env == nullptr || exportObj == nullptr) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Env or exportObj nullptr.");
return nullptr;

View File

@ -16,7 +16,6 @@
#include "js_auto_save_request_callback.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_auto_fill_manager.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
@ -35,7 +34,7 @@ JsAutoSaveRequestCallback::~JsAutoSaveRequestCallback() {}
void JsAutoSaveRequestCallback::OnSaveRequestSuccess()
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
JSCallFunction(METHOD_ON_SAVE_REQUEST_SUCCESS);
if (autoFillManagerFunc_ != nullptr) {
autoFillManagerFunc_(instanceId_);
@ -44,7 +43,7 @@ void JsAutoSaveRequestCallback::OnSaveRequestSuccess()
void JsAutoSaveRequestCallback::OnSaveRequestFailed()
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
JSCallFunction(METHOD_ON_SAVE_REQUEST_FAILED);
if (autoFillManagerFunc_ != nullptr) {
autoFillManagerFunc_(instanceId_);
@ -53,7 +52,7 @@ void JsAutoSaveRequestCallback::OnSaveRequestFailed()
void JsAutoSaveRequestCallback::Register(napi_value value)
{
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called.");
TAG_LOGD(AAFwkTag::AUTOFILLMGR, "called");
if (IsJsCallbackEquals(callback_, value)) {
TAG_LOGE(AAFwkTag::AUTOFILLMGR, "The current callback already exists.");
return;

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_callee_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_caller_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
import("//build/templates/abc/ohos_abc.gni")

View File

@ -16,7 +16,6 @@
#include "request_info.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_runtime_utils.h"
namespace OHOS {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_embeddable_ui_ability_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_embeddable_ui_ability_context_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_embedded_ui_extension_ability_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_extension_ability_abc") {

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_extension_context_abc") {

View File

@ -23,7 +23,6 @@
#include "ability_process.h"
#include "element_name.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "js_runtime_utils.h"
#ifdef SUPPORT_SCREEN

View File

@ -18,7 +18,6 @@
#include <vector>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "securec.h"
namespace OHOS {

View File

@ -19,7 +19,6 @@
#include "data_ability_predicates.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_want.h"
#include "napi_data_ability_helper.h"
#include "values_bucket.h"
@ -62,28 +61,37 @@ napi_value UnwrapDataAbilityOperation(
return result;
}
napi_value BuildDataAbilityOperation(
std::shared_ptr<DataAbilityOperation> &dataAbilityOperation, napi_env env, napi_value param)
bool ParseUriAndType(napi_env env, napi_value &param, std::shared_ptr<Uri> &uri, int &type)
{
TAG_LOGI(AAFwkTag::FA, "start");
// get uri property
std::string uriStr("");
if (!UnwrapStringByPropertyName(env, param, "uri", uriStr)) {
TAG_LOGE(AAFwkTag::FA, "uri is not exist");
return nullptr;
TAG_LOGE(AAFwkTag::FA, "%{public}s, uri is not exist.", __func__);
return false;
}
TAG_LOGI(AAFwkTag::FA, "uri:%{public}s", uriStr.c_str());
std::shared_ptr<Uri> uri = std::make_shared<Uri>(uriStr);
TAG_LOGI(AAFwkTag::FA, "%{public}s, uri:%{public}s", __func__, uriStr.c_str());
uri = std::make_shared<Uri>(uriStr);
// get type property
int type = 0;
if (!UnwrapInt32ByPropertyName(env, param, "type", type)) {
TAG_LOGE(AAFwkTag::FA, "type:%{public}d is not exist", type);
return nullptr;
TAG_LOGE(AAFwkTag::FA, "%{public}s, type:%{public}d is not exist.", __func__, type);
return false;
}
TAG_LOGI(AAFwkTag::FA, "type:%{public}d", type);
return true;
}
napi_value BuildDataAbilityOperation(
std::shared_ptr<DataAbilityOperation> &dataAbilityOperation, napi_env env, napi_value param)
{
TAG_LOGI(AAFwkTag::FA, "%{public}s start.", __func__);
std::shared_ptr<Uri> uri = nullptr;
int type = 0;
if (!ParseUriAndType(env, param, uri, type)) {
return nullptr;
}
std::shared_ptr<DataAbilityOperationBuilder> builder = nullptr;
if (!GetDataAbilityOperationBuilder(builder, type, uri)) {
TAG_LOGE(AAFwkTag::FA, "GetDataAbilityOperationBuilder failed");

View File

@ -18,7 +18,6 @@
#include "distribute_constants.h"
#include "distribute_req_param.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_util.h"
#include "js_error_utils.h"

View File

@ -47,7 +47,6 @@ ohos_shared_library("napi_ability_common") {
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:want",
"access_token:libtokenid_sdk",
"bundle_framework:appexecfwk_base",
@ -62,7 +61,6 @@ ohos_shared_library("napi_ability_common") {
public_external_deps = [
"ability_base:configuration",
"bundle_framework:appexecfwk_core",
"window_manager:libwm_lite",
]
if (ability_runtime_graphics) {
@ -70,6 +68,11 @@ ohos_shared_library("napi_ability_common") {
"SUPPORT_GRAPHICS",
"SUPPORT_SCREEN",
]
public_external_deps += [
"form_fwk:fmskit_provider_client",
"form_fwk:form_manager",
"window_manager:libdm",
]
}
innerapi_tags = [ "platformsdk" ]

View File

@ -24,11 +24,16 @@
#include "napi_common_ability_wrap_utils.h"
#include "napi_common_util.h"
#include "napi_context.h"
#include "napi_remote_object.h"
using namespace OHOS::AbilityRuntime;
namespace OHOS {
namespace AppExecFwk {
static std::map<ConnectionKey, sptr<NAPIAbilityConnection>, key_compare> connects_;
static std::mutex g_connectionsLock_;
static int64_t serialNumber_ = 0;
JsNapiCommon::JsNapiCommon() : ability_(nullptr)
{}
@ -1413,10 +1418,14 @@ void JsNapiCommon::AddFreeInstallObserver(napi_env env, const AAFwk::Want &want,
{
// adapter free install async return install and start result
TAG_LOGD(AAFwkTag::JSNAPI, "AddFreeInstallObserver start.");
if (ability_ == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "the ability is nullptr");
return;
}
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
ret = ability_->AddFreeInstallObserver(freeInstallObserver_);
}
if (ret != ERR_OK) {
@ -1430,5 +1439,348 @@ void JsNapiCommon::AddFreeInstallObserver(napi_env env, const AAFwk::Want &want,
freeInstallObserver_->AddJsObserverObject(bundleName, abilityName, startTime, callback, result);
}
}
void ClearCallbackWork(uv_work_t* req, int)
{
std::unique_ptr<uv_work_t> work(req);
if (!req) {
TAG_LOGE(AAFwkTag::JSNAPI, "work null");
return;
}
std::unique_ptr<ConnectionCallback> callback(reinterpret_cast<ConnectionCallback*>(req->data));
if (!callback) {
TAG_LOGE(AAFwkTag::JSNAPI, "data null");
return;
}
callback->Reset();
}
void ConnectionCallback::Reset()
{
auto engine = reinterpret_cast<NativeEngine*>(env);
if (engine == nullptr) {
removeKey = nullptr;
return;
}
if (pthread_self() == engine->GetTid()) {
TAG_LOGD(AAFwkTag::JSNAPI, "in-js-thread");
if (connectCallbackRef) {
napi_delete_reference(env, connectCallbackRef);
connectCallbackRef = nullptr;
}
if (disconnectCallbackRef) {
napi_delete_reference(env, disconnectCallbackRef);
disconnectCallbackRef = nullptr;
}
if (failedCallbackRef) {
napi_delete_reference(env, failedCallbackRef);
failedCallbackRef = nullptr;
}
env = nullptr;
removeKey = nullptr;
return;
}
TAG_LOGI(AAFwkTag::JSNAPI, "not in-js-thread");
auto loop = engine->GetUVLoop();
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__);
env = nullptr;
removeKey = nullptr;
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr.");
return;
}
ConnectionCallback *data = new(std::nothrow) ConnectionCallback(std::move(*this));
work->data = data;
auto ret = uv_queue_work(loop, work, [](uv_work_t*) {}, ClearCallbackWork);
if (ret != 0) {
TAG_LOGE(AAFwkTag::JSNAPI, "uv_queue_work failed: %{public}d", ret);
data->env = nullptr;
data->removeKey = nullptr;
delete data;
delete work;
}
}
void NAPIAbilityConnection::AddConnectionCallback(std::shared_ptr<ConnectionCallback> callback)
{
std::lock_guard<std::mutex> guard(lock_);
callbacks_.emplace_back(callback);
}
int NAPIAbilityConnection::GetConnectionState() const
{
std::lock_guard<std::mutex> guard(lock_);
return connectionState_;
}
void NAPIAbilityConnection::SetConnectionState(int connectionState)
{
std::lock_guard<std::mutex> guard(lock_);
connectionState_ = connectionState;
}
size_t NAPIAbilityConnection::GetCallbackSize()
{
std::lock_guard<std::mutex> guard(lock_);
return callbacks_.size();
}
size_t NAPIAbilityConnection::RemoveAllCallbacks(ConnectRemoveKeyType key)
{
size_t result = 0;
std::lock_guard<std::mutex> guard(lock_);
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
auto callback = *it;
if (callback && callback->removeKey == key) {
it = callbacks_.erase(it);
result++;
} else {
++it;
}
}
TAG_LOGI(AAFwkTag::JSNAPI, "RemoveAllCallbacks removed size:%{public}zu, left size:%{public}zu", result,
callbacks_.size());
return result;
}
void UvWorkOnAbilityConnectDone(uv_work_t *work, int status)
{
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work");
std::unique_ptr<uv_work_t> managedWork(work);
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, work is null");
return;
}
// JS Thread
std::unique_ptr<ConnectAbilityCB> connectAbilityCB(static_cast<ConnectAbilityCB *>(work->data));
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, connectAbilityCB is null");
return;
}
CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo;
napi_handle_scope scope = nullptr;
napi_open_handle_scope(cbInfo.env, &scope);
if (scope == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed");
return;
}
napi_value globalValue;
napi_get_global(cbInfo.env, &globalValue);
napi_value func;
napi_get_named_property(cbInfo.env, globalValue, "requireNapi", &func);
napi_value rpcInfo;
napi_create_string_utf8(cbInfo.env, "rpc", NAPI_AUTO_LENGTH, &rpcInfo);
napi_value funcArgv[1] = { rpcInfo };
napi_value returnValue;
napi_call_function(cbInfo.env, globalValue, func, 1, funcArgv, &returnValue);
napi_value result[ARGS_TWO] = {nullptr};
result[PARAM0] =
WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
napi_value jsRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(
cbInfo.env, connectAbilityCB->abilityConnectionCB.connection);
result[PARAM1] = jsRemoteObject;
napi_value callback = nullptr;
napi_value undefined = nullptr;
napi_get_undefined(cbInfo.env, &undefined);
napi_value callResult = nullptr;
napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback);
napi_call_function(
cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
if (cbInfo.callback != nullptr) {
napi_delete_reference(cbInfo.env, cbInfo.callback);
}
napi_close_handle_scope(cbInfo.env, scope);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work end");
}
void NAPIAbilityConnection::HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(callback.env, &loop);
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == null.", __func__);
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, work == null.", __func__);
return;
}
ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB;
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == null.", __func__);
if (work != nullptr) {
delete work;
work = nullptr;
}
return;
}
connectAbilityCB->cbBase.cbInfo.env = callback.env;
connectAbilityCB->cbBase.cbInfo.callback = callback.connectCallbackRef;
callback.connectCallbackRef = nullptr;
connectAbilityCB->abilityConnectionCB.elementName = element_;
connectAbilityCB->abilityConnectionCB.resultCode = resultCode;
connectAbilityCB->abilityConnectionCB.connection = serviceRemoteObject_;
work->data = static_cast<void *>(connectAbilityCB);
int rev = uv_queue_work_with_qos(
loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityConnectDone, uv_qos_user_initiated);
if (rev != 0) {
if (connectAbilityCB != nullptr) {
delete connectAbilityCB;
connectAbilityCB = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
}
void NAPIAbilityConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d",
__func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode);
if (remoteObject == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, remoteObject == nullptr.", __func__);
return;
}
std::lock_guard<std::mutex> guard(lock_);
element_ = element;
serviceRemoteObject_ = remoteObject;
for (const auto &callback : callbacks_) {
HandleOnAbilityConnectDone(*callback, resultCode);
}
connectionState_ = CONNECTION_STATE_CONNECTED;
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__);
}
void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status)
{
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work");
std::unique_ptr<uv_work_t> managedWork(work);
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, work is null");
return;
}
// JS Thread
std::unique_ptr<ConnectAbilityCB> connectAbilityCB(static_cast<ConnectAbilityCB *>(work->data));
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, connectAbilityCB is null");
return;
}
CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo;
napi_handle_scope scope = nullptr;
napi_open_handle_scope(cbInfo.env, &scope);
if (scope == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed");
return;
}
napi_value result = WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
if (cbInfo.callback != nullptr) {
napi_value callback = nullptr;
napi_value callResult = nullptr;
napi_value undefined = nullptr;
napi_get_undefined(cbInfo.env, &undefined);
napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback);
napi_call_function(cbInfo.env, undefined, callback, ARGS_ONE, &result, &callResult);
napi_delete_reference(cbInfo.env, cbInfo.callback);
cbInfo.callback = nullptr;
}
napi_close_handle_scope(cbInfo.env, scope);
// release connect
std::lock_guard<std::mutex> lock(g_connectionsLock_);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size());
std::string deviceId = connectAbilityCB->abilityConnectionCB.elementName.GetDeviceID();
std::string bundleName = connectAbilityCB->abilityConnectionCB.elementName.GetBundleName();
std::string abilityName = connectAbilityCB->abilityConnectionCB.elementName.GetAbilityName();
auto item = std::find_if(connects_.begin(), connects_.end(),
[deviceId, bundleName, abilityName](const std::map<ConnectionKey,
sptr<NAPIAbilityConnection>>::value_type &obj) {
return (deviceId == obj.first.want.GetDeviceId()) &&
(bundleName == obj.first.want.GetBundle()) &&
(abilityName == obj.first.want.GetElement().GetAbilityName());
});
if (item != connects_.end()) {
// match deviceid & bundlename && abilityname
connects_.erase(item);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size());
}
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work end");
}
void NAPIAbilityConnection::HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(callback.env, &loop);
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__);
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr.");
return;
}
ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB;
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == nullptr.", __func__);
if (work != nullptr) {
delete work;
work = nullptr;
}
return;
}
connectAbilityCB->cbBase.cbInfo.env = callback.env;
connectAbilityCB->cbBase.cbInfo.callback = callback.disconnectCallbackRef;
callback.disconnectCallbackRef = nullptr;
connectAbilityCB->abilityConnectionCB.elementName = element_;
connectAbilityCB->abilityConnectionCB.resultCode = resultCode;
work->data = static_cast<void *>(connectAbilityCB);
int rev = uv_queue_work(
loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityDisconnectDone);
if (rev != 0) {
if (connectAbilityCB != nullptr) {
delete connectAbilityCB;
connectAbilityCB = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
}
void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d",
__func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode);
std::lock_guard<std::mutex> guard(lock_);
element_ = element;
for (const auto &callback : callbacks_) {
HandleOnAbilityDisconnectDone(*callback, resultCode);
}
connectionState_ = CONNECTION_STATE_DISCONNECTED;
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -15,6 +15,8 @@
#ifndef OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H
#define OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H
#include "ability_connect_callback_stub.h"
#include "ability_info.h"
#include "ability_manager_errors.h"
#include "application_info.h"
@ -143,6 +145,104 @@ public:
Ability *ability_;
sptr<AbilityRuntime::JsFreeInstallObserver> freeInstallObserver_ = nullptr;
};
enum {
CONNECTION_STATE_DISCONNECTED = -1,
CONNECTION_STATE_CONNECTED = 0,
CONNECTION_STATE_CONNECTING = 1
};
using ConnectRemoveKeyType = JsNapiCommon*;
struct ConnectionCallback {
ConnectionCallback(napi_env env, napi_value cbInfo, ConnectRemoveKeyType key)
{
this->env = env;
napi_value jsMethod = nullptr;
napi_get_named_property(env, cbInfo, "onConnect", &jsMethod);
napi_create_reference(env, jsMethod, 1, &connectCallbackRef);
napi_get_named_property(env, cbInfo, "onDisconnect", &jsMethod);
napi_create_reference(env, jsMethod, 1, &disconnectCallbackRef);
napi_get_named_property(env, cbInfo, "onFailed", &jsMethod);
napi_create_reference(env, jsMethod, 1, &failedCallbackRef);
removeKey = key;
}
ConnectionCallback(ConnectionCallback &) = delete;
ConnectionCallback(ConnectionCallback &&other)
: env(other.env), connectCallbackRef(other.connectCallbackRef),
disconnectCallbackRef(other.disconnectCallbackRef), failedCallbackRef(other.failedCallbackRef),
removeKey(other.removeKey)
{
other.env = nullptr;
other.connectCallbackRef = nullptr;
other.disconnectCallbackRef = nullptr;
other.failedCallbackRef = nullptr;
other.removeKey = nullptr;
}
const ConnectionCallback &operator=(ConnectionCallback &) = delete;
const ConnectionCallback &operator=(ConnectionCallback &&other)
{
Reset();
env = other.env;
connectCallbackRef = other.connectCallbackRef;
disconnectCallbackRef = other.disconnectCallbackRef;
failedCallbackRef = other.failedCallbackRef;
other.env = nullptr;
other.connectCallbackRef = nullptr;
other.disconnectCallbackRef = nullptr;
other.failedCallbackRef = nullptr;
other.removeKey = nullptr;
return *this;
}
~ConnectionCallback()
{
Reset();
}
void Reset();
napi_env env = nullptr;
napi_ref connectCallbackRef = nullptr;
napi_ref disconnectCallbackRef = nullptr;
napi_ref failedCallbackRef = nullptr;
ConnectRemoveKeyType removeKey = nullptr;
};
class NAPIAbilityConnection : public AAFwk::AbilityConnectionStub {
public:
void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void AddConnectionCallback(std::shared_ptr<ConnectionCallback> callback);
void HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode);
void HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode);
int GetConnectionState() const;
void SetConnectionState(int connectionState);
size_t GetCallbackSize();
size_t RemoveAllCallbacks(ConnectRemoveKeyType key);
private:
std::list<std::shared_ptr<ConnectionCallback>> callbacks_;
AppExecFwk::ElementName element_;
sptr<IRemoteObject> serviceRemoteObject_ = nullptr;
int connectionState_ = CONNECTION_STATE_DISCONNECTED;
mutable std::mutex lock_;
};
struct ConnectionKey {
Want want;
int64_t id;
};
struct key_compare {
bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const
{
if (key1.id < key2.id) {
return true;
}
return false;
}
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H

View File

@ -21,7 +21,6 @@
#include <uv.h>
#include "ability_util.h"
#include "ability_manager_client.h"
#include "hilog_tag_wrapper.h"
#include "js_napi_common_ability.h"
#include "js_runtime_utils.h"
@ -1016,349 +1015,6 @@ napi_value NAPI_StopAbilityCommon(napi_env env, napi_callback_info info, Ability
return ret;
}
void ClearCallbackWork(uv_work_t* req, int)
{
std::unique_ptr<uv_work_t> work(req);
if (!req) {
TAG_LOGE(AAFwkTag::JSNAPI, "work null");
return;
}
std::unique_ptr<ConnectionCallback> callback(reinterpret_cast<ConnectionCallback*>(req->data));
if (!callback) {
TAG_LOGE(AAFwkTag::JSNAPI, "data null");
return;
}
callback->Reset();
}
void ConnectionCallback::Reset()
{
auto engine = reinterpret_cast<NativeEngine*>(env);
if (engine == nullptr) {
removeKey = nullptr;
return;
}
if (pthread_self() == engine->GetTid()) {
TAG_LOGD(AAFwkTag::JSNAPI, "in-js-thread");
if (connectCallbackRef) {
napi_delete_reference(env, connectCallbackRef);
connectCallbackRef = nullptr;
}
if (disconnectCallbackRef) {
napi_delete_reference(env, disconnectCallbackRef);
disconnectCallbackRef = nullptr;
}
if (failedCallbackRef) {
napi_delete_reference(env, failedCallbackRef);
failedCallbackRef = nullptr;
}
env = nullptr;
removeKey = nullptr;
return;
}
TAG_LOGI(AAFwkTag::JSNAPI, "not in-js-thread");
auto loop = engine->GetUVLoop();
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__);
env = nullptr;
removeKey = nullptr;
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr.");
return;
}
ConnectionCallback *data = new(std::nothrow) ConnectionCallback(std::move(*this));
work->data = data;
auto ret = uv_queue_work(loop, work, [](uv_work_t*) {}, ClearCallbackWork);
if (ret != 0) {
TAG_LOGE(AAFwkTag::JSNAPI, "uv_queue_work failed: %{public}d", ret);
data->env = nullptr;
data->removeKey = nullptr;
delete data;
delete work;
}
}
void NAPIAbilityConnection::AddConnectionCallback(std::shared_ptr<ConnectionCallback> callback)
{
std::lock_guard<std::mutex> guard(lock_);
callbacks_.emplace_back(callback);
}
int NAPIAbilityConnection::GetConnectionState() const
{
std::lock_guard<std::mutex> guard(lock_);
return connectionState_;
}
void NAPIAbilityConnection::SetConnectionState(int connectionState)
{
std::lock_guard<std::mutex> guard(lock_);
connectionState_ = connectionState;
}
size_t NAPIAbilityConnection::GetCallbackSize()
{
std::lock_guard<std::mutex> guard(lock_);
return callbacks_.size();
}
size_t NAPIAbilityConnection::RemoveAllCallbacks(ConnectRemoveKeyType key)
{
size_t result = 0;
std::lock_guard<std::mutex> guard(lock_);
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
auto callback = *it;
if (callback && callback->removeKey == key) {
it = callbacks_.erase(it);
result++;
} else {
++it;
}
}
TAG_LOGI(AAFwkTag::JSNAPI, "RemoveAllCallbacks removed size:%{public}zu, left size:%{public}zu", result,
callbacks_.size());
return result;
}
void UvWorkOnAbilityConnectDone(uv_work_t *work, int status)
{
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work");
std::unique_ptr<uv_work_t> managedWork(work);
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, work is null");
return;
}
// JS Thread
std::unique_ptr<ConnectAbilityCB> connectAbilityCB(static_cast<ConnectAbilityCB *>(work->data));
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, connectAbilityCB is null");
return;
}
CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo;
napi_handle_scope scope = nullptr;
napi_open_handle_scope(cbInfo.env, &scope);
if (scope == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed");
return;
}
napi_value globalValue;
napi_get_global(cbInfo.env, &globalValue);
napi_value func;
napi_get_named_property(cbInfo.env, globalValue, "requireNapi", &func);
napi_value rpcInfo;
napi_create_string_utf8(cbInfo.env, "rpc", NAPI_AUTO_LENGTH, &rpcInfo);
napi_value funcArgv[1] = { rpcInfo };
napi_value returnValue;
napi_call_function(cbInfo.env, globalValue, func, 1, funcArgv, &returnValue);
napi_value result[ARGS_TWO] = {nullptr};
result[PARAM0] =
WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
napi_value jsRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(
cbInfo.env, connectAbilityCB->abilityConnectionCB.connection);
result[PARAM1] = jsRemoteObject;
napi_value callback = nullptr;
napi_value undefined = nullptr;
napi_get_undefined(cbInfo.env, &undefined);
napi_value callResult = nullptr;
napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback);
napi_call_function(
cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult);
if (cbInfo.callback != nullptr) {
napi_delete_reference(cbInfo.env, cbInfo.callback);
}
napi_close_handle_scope(cbInfo.env, scope);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work end");
}
void NAPIAbilityConnection::HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(callback.env, &loop);
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == null.", __func__);
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, work == null.", __func__);
return;
}
ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB;
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == null.", __func__);
if (work != nullptr) {
delete work;
work = nullptr;
}
return;
}
connectAbilityCB->cbBase.cbInfo.env = callback.env;
connectAbilityCB->cbBase.cbInfo.callback = callback.connectCallbackRef;
callback.connectCallbackRef = nullptr;
connectAbilityCB->abilityConnectionCB.elementName = element_;
connectAbilityCB->abilityConnectionCB.resultCode = resultCode;
connectAbilityCB->abilityConnectionCB.connection = serviceRemoteObject_;
work->data = static_cast<void *>(connectAbilityCB);
int rev = uv_queue_work_with_qos(
loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityConnectDone, uv_qos_user_initiated);
if (rev != 0) {
if (connectAbilityCB != nullptr) {
delete connectAbilityCB;
connectAbilityCB = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
}
void NAPIAbilityConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d",
__func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode);
if (remoteObject == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, remoteObject == nullptr.", __func__);
return;
}
std::lock_guard<std::mutex> guard(lock_);
element_ = element;
serviceRemoteObject_ = remoteObject;
for (const auto &callback : callbacks_) {
HandleOnAbilityConnectDone(*callback, resultCode);
}
connectionState_ = CONNECTION_STATE_CONNECTED;
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__);
}
void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status)
{
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work");
std::unique_ptr<uv_work_t> managedWork(work);
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, work is null");
return;
}
// JS Thread
std::unique_ptr<ConnectAbilityCB> connectAbilityCB(static_cast<ConnectAbilityCB *>(work->data));
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, connectAbilityCB is null");
return;
}
CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo;
napi_handle_scope scope = nullptr;
napi_open_handle_scope(cbInfo.env, &scope);
if (scope == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed");
return;
}
napi_value result = WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName);
if (cbInfo.callback != nullptr) {
napi_value callback = nullptr;
napi_value callResult = nullptr;
napi_value undefined = nullptr;
napi_get_undefined(cbInfo.env, &undefined);
napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback);
napi_call_function(cbInfo.env, undefined, callback, ARGS_ONE, &result, &callResult);
napi_delete_reference(cbInfo.env, cbInfo.callback);
cbInfo.callback = nullptr;
}
napi_close_handle_scope(cbInfo.env, scope);
// release connect
std::lock_guard<std::mutex> lock(g_connectionsLock_);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size());
std::string deviceId = connectAbilityCB->abilityConnectionCB.elementName.GetDeviceID();
std::string bundleName = connectAbilityCB->abilityConnectionCB.elementName.GetBundleName();
std::string abilityName = connectAbilityCB->abilityConnectionCB.elementName.GetAbilityName();
auto item = std::find_if(connects_.begin(), connects_.end(),
[deviceId, bundleName, abilityName](const std::map<ConnectionKey,
sptr<NAPIAbilityConnection>>::value_type &obj) {
return (deviceId == obj.first.want.GetDeviceId()) &&
(bundleName == obj.first.want.GetBundle()) &&
(abilityName == obj.first.want.GetElement().GetAbilityName());
});
if (item != connects_.end()) {
// match deviceid & bundlename && abilityname
connects_.erase(item);
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size());
}
TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work end");
}
void NAPIAbilityConnection::HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__);
uv_loop_s *loop = nullptr;
napi_get_uv_event_loop(callback.env, &loop);
if (loop == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__);
return;
}
uv_work_t *work = new(std::nothrow) uv_work_t;
if (work == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr.");
return;
}
ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB;
if (connectAbilityCB == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == nullptr.", __func__);
if (work != nullptr) {
delete work;
work = nullptr;
}
return;
}
connectAbilityCB->cbBase.cbInfo.env = callback.env;
connectAbilityCB->cbBase.cbInfo.callback = callback.disconnectCallbackRef;
callback.disconnectCallbackRef = nullptr;
connectAbilityCB->abilityConnectionCB.elementName = element_;
connectAbilityCB->abilityConnectionCB.resultCode = resultCode;
work->data = static_cast<void *>(connectAbilityCB);
int rev = uv_queue_work(
loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityDisconnectDone);
if (rev != 0) {
if (connectAbilityCB != nullptr) {
delete connectAbilityCB;
connectAbilityCB = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
}
}
void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d",
__func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode);
std::lock_guard<std::mutex> guard(lock_);
element_ = element;
for (const auto &callback : callbacks_) {
HandleOnAbilityDisconnectDone(*callback, resultCode);
}
connectionState_ = CONNECTION_STATE_DISCONNECTED;
TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__);
}
/**
* @brief AcquireDataAbilityHelper.
*

View File

@ -20,7 +20,6 @@
#include <mutex>
#include <list>
#include "ability_connect_callback_stub.h"
#include "ability_info.h"
#include "ability_manager_errors.h"
#include "application_info.h"
@ -167,90 +166,6 @@ napi_value NAPI_GetAbilityNameCommon(napi_env env, napi_callback_info info, Abil
*/
napi_value NAPI_StopAbilityCommon(napi_env env, napi_callback_info info, AbilityType abilityType);
enum {
CONNECTION_STATE_DISCONNECTED = -1,
CONNECTION_STATE_CONNECTED = 0,
CONNECTION_STATE_CONNECTING = 1
};
class JsNapiCommon;
using ConnectRemoveKeyType = JsNapiCommon*;
struct ConnectionCallback {
ConnectionCallback(napi_env env, napi_value cbInfo, ConnectRemoveKeyType key)
{
this->env = env;
napi_value jsMethod = nullptr;
napi_get_named_property(env, cbInfo, "onConnect", &jsMethod);
napi_create_reference(env, jsMethod, 1, &connectCallbackRef);
napi_get_named_property(env, cbInfo, "onDisconnect", &jsMethod);
napi_create_reference(env, jsMethod, 1, &disconnectCallbackRef);
napi_get_named_property(env, cbInfo, "onFailed", &jsMethod);
napi_create_reference(env, jsMethod, 1, &failedCallbackRef);
removeKey = key;
}
ConnectionCallback(ConnectionCallback &) = delete;
ConnectionCallback(ConnectionCallback &&other)
: env(other.env), connectCallbackRef(other.connectCallbackRef),
disconnectCallbackRef(other.disconnectCallbackRef), failedCallbackRef(other.failedCallbackRef),
removeKey(other.removeKey)
{
other.env = nullptr;
other.connectCallbackRef = nullptr;
other.disconnectCallbackRef = nullptr;
other.failedCallbackRef = nullptr;
other.removeKey = nullptr;
}
const ConnectionCallback &operator=(ConnectionCallback &) = delete;
const ConnectionCallback &operator=(ConnectionCallback &&other)
{
Reset();
env = other.env;
connectCallbackRef = other.connectCallbackRef;
disconnectCallbackRef = other.disconnectCallbackRef;
failedCallbackRef = other.failedCallbackRef;
other.env = nullptr;
other.connectCallbackRef = nullptr;
other.disconnectCallbackRef = nullptr;
other.failedCallbackRef = nullptr;
other.removeKey = nullptr;
return *this;
}
~ConnectionCallback()
{
Reset();
}
void Reset();
napi_env env = nullptr;
napi_ref connectCallbackRef = nullptr;
napi_ref disconnectCallbackRef = nullptr;
napi_ref failedCallbackRef = nullptr;
ConnectRemoveKeyType removeKey = nullptr;
};
class NAPIAbilityConnection : public AAFwk::AbilityConnectionStub {
public:
void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void AddConnectionCallback(std::shared_ptr<ConnectionCallback> callback);
void HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode);
void HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode);
int GetConnectionState() const;
void SetConnectionState(int connectionState);
size_t GetCallbackSize();
size_t RemoveAllCallbacks(ConnectRemoveKeyType key);
private:
std::list<std::shared_ptr<ConnectionCallback>> callbacks_;
AppExecFwk::ElementName element_;
sptr<IRemoteObject> serviceRemoteObject_ = nullptr;
int connectionState_ = CONNECTION_STATE_DISCONNECTED;
mutable std::mutex lock_;
};
/**
* @brief acquireDataAbilityHelper processing function.
*
@ -294,23 +209,6 @@ napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info in
*/
napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info info);
struct ConnectionKey {
Want want;
int64_t id;
};
struct key_compare {
bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const
{
if (key1.id < key2.id) {
return true;
}
return false;
}
};
static std::map<ConnectionKey, sptr<NAPIAbilityConnection>, key_compare> connects_;
static std::mutex g_connectionsLock_;
static int64_t serialNumber_ = 0;
enum ErrorCode {
NO_ERROR = 0,
INVALID_PARAMETER = -1,

View File

@ -25,7 +25,6 @@
#include "feature_ability_common.h"
#include "file_ex.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "js_napi_common_ability.h"
#include "permission_list_state.h"
#include "securec.h"

View File

@ -28,6 +28,7 @@ ohos_shared_library("napi_common") {
]
sources = [
"napi_common_child_process_param.cpp",
"napi_common_configuration.cpp",
"napi_common_execute_param.cpp",
"napi_common_execute_result.cpp",
@ -41,12 +42,12 @@ ohos_shared_library("napi_common") {
"${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}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/runtime:runtime",
]
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:session_info",
"ability_base:want",
"access_token:libtokenid_sdk",
@ -63,7 +64,7 @@ ohos_shared_library("napi_common") {
public_external_deps = [
"ability_base:configuration",
"bundle_framework:appexecfwk_core",
"window_manager:libwm_lite",
"input:libmmi-client",
]
if (ability_runtime_graphics) {
@ -71,6 +72,10 @@ ohos_shared_library("napi_common") {
"SUPPORT_GRAPHICS",
"SUPPORT_SCREEN",
]
public_external_deps += [
"form_fwk:form_manager",
"window_manager:libdm",
]
}
innerapi_tags = [ "platformsdk" ]

View File

@ -0,0 +1,133 @@
/*
* 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 "napi_common_child_process_param.h"
#include "hilog_tag_wrapper.h"
#include "napi_common_util.h"
namespace OHOS {
namespace AppExecFwk {
bool UnwrapChildProcessArgs(napi_env env, napi_value jsValue, AppExecFwk::ChildProcessArgs &args,
std::string &errorMsg)
{
if (!IsTypeForNapiValue(env, jsValue, napi_object)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parameter error. The type of args must be ProcessArgs.");
errorMsg = "Parameter error. The type of args must be ProcessArgs.";
return false;
}
if (IsExistsByPropertyName(env, jsValue, "entryParams") &&
!UnwrapStringByPropertyName(env, jsValue, "entryParams", args.entryParams)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parameter error. The type of args.entryParams must be string.");
errorMsg = "Parameter error. The type of args.entryParams must be string.";
return false;
}
if (IsExistsByPropertyName(env, jsValue, "fds")) {
napi_value jsFds = GetPropertyValueByPropertyName(env, jsValue, "fds", napi_object);
if (jsFds == nullptr) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "The type of args.fds must be Record<string, number>.");
errorMsg = "The type of args.fds must be Record<string, number>.";
return false;
}
if (!UnwrapChildProcessFds(env, jsFds, args.fds, errorMsg)) {
return false;
}
}
return true;
}
bool UnwrapChildProcessFds(napi_env env, napi_value param, std::map<std::string, int32_t> &map, std::string &errorMsg)
{
napi_value jsKeyList = nullptr;
uint32_t keyCount = 0;
NAPI_CALL_BASE(env, napi_get_property_names(env, param, &jsKeyList), false);
NAPI_CALL_BASE(env, napi_get_array_length(env, jsKeyList, &keyCount), false);
if (keyCount > CHILD_PROCESS_ARGS_FDS_MAX_COUNT) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "fds count must <= %{public}d.", CHILD_PROCESS_ARGS_FDS_MAX_COUNT);
errorMsg = "fds count must <= " + std::to_string(CHILD_PROCESS_ARGS_FDS_MAX_COUNT);
return false;
}
napi_value jsKey = nullptr;
for (uint32_t index = 0; index < keyCount; index++) {
NAPI_CALL_BASE(env, napi_get_element(env, jsKeyList, index, &jsKey), false);
std::string key;
if (!UnwrapStringFromJS2(env, jsKey, key)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "The type of args.fds must be Record<string, number>.");
errorMsg = "The type of args.fds must be Record<string, number>.";
return false;
}
if (!ChildProcessArgs::CheckFdKeyLength(key)) {
errorMsg = "fd key length must <= " + std::to_string(CHILD_PROCESS_ARGS_FD_KEY_MAX_LENGTH);
return false;
}
int32_t value;
if (!UnwrapInt32ByPropertyName(env, param, key.c_str(), value)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "The type of args.fds must be Record<string, number>.");
errorMsg = "The type of args.fds must be Record<string, number>.";
return false;
}
map.emplace(key, value);
}
return true;
}
bool UnwrapChildProcessOptions(napi_env env, napi_value jsValue, AppExecFwk::ChildProcessOptions &options,
std::string &errorMsg)
{
if (!IsTypeForNapiValue(env, jsValue, napi_object)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parameter error. The type of options must be ProcessOptions.");
errorMsg = "Parameter error. The type of options must be ProcessOptions.";
return false;
}
if (IsExistsByPropertyName(env, jsValue, "isolationMode") &&
!UnwrapBooleanByPropertyName(env, jsValue, "isolationMode", options.isolationMode)) {
TAG_LOGE(AAFwkTag::PROCESSMGR, "Parameter error. The type of options.isolationMode must be boolean.");
errorMsg = "Parameter error. The type of options.isolationMode must be boolean.";
return false;
}
return true;
}
napi_value WrapChildProcessArgs(napi_env env, AppExecFwk::ChildProcessArgs &args)
{
napi_value jsArgs = nullptr;
NAPI_CALL(env, napi_create_object(env, &jsArgs));
napi_value jsEntryParams = WrapStringToJS(env, args.entryParams);
SetPropertyValueByPropertyName(env, jsArgs, "entryParams", jsEntryParams);
napi_value jsFds = nullptr;
NAPI_CALL(env, napi_create_object(env, &jsFds));
if (!args.CheckFdsSize()) {
return jsArgs;
}
auto &fds = args.fds;
for (auto iter = fds.begin(); iter != fds.end(); iter++) {
std::string key = iter->first;
napi_value jsValue = WrapInt32ToJS(env, iter->second);
SetPropertyValueByPropertyName(env, jsFds, key.c_str(), jsValue);
}
SetPropertyValueByPropertyName(env, jsArgs, "fds", jsFds);
return jsArgs;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,36 @@
/*
* 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 perns and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_NAPI_COMMON_CHILD_PROCESS_PARAM
#define OHOS_ABILITY_RUNTIME_NAPI_COMMON_CHILD_PROCESS_PARAM
#include "child_process_args.h"
#include "child_process_options.h"
#include "napi/native_api.h"
namespace OHOS {
namespace AppExecFwk {
bool UnwrapChildProcessArgs(napi_env env, napi_value jsValue, AppExecFwk::ChildProcessArgs &args,
std::string &errorMsg);
bool UnwrapChildProcessFds(napi_env env, napi_value param, std::map<std::string, int32_t> &map, std::string &errorMsg);
bool UnwrapChildProcessOptions(napi_env env, napi_value jsValue, AppExecFwk::ChildProcessOptions &options,
std::string &errorMsg);
napi_value WrapChildProcessArgs(napi_env env, AppExecFwk::ChildProcessArgs &args);
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_NAPI_COMMON_CHILD_PROCESS_PARAM

View File

@ -17,7 +17,6 @@
#include "configuration_convertor.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_util.h"
namespace OHOS {

View File

@ -16,7 +16,6 @@
#include "napi_common_execute_param.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_util.h"
#include "napi_common_want.h"

View File

@ -16,7 +16,6 @@
#include "napi_common_execute_result.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "insight_intent_execute_result.h"
#include "napi_common_util.h"
#include "napi_common_want.h"

View File

@ -16,7 +16,6 @@
#include "napi_common_start_options.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_util.h"
#include "napi_common_want.h"
#include "int_wrapper.h"

View File

@ -17,7 +17,6 @@
#include <cstring>
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#include "napi_common_data.h"
#include "napi_common_error.h"
#include "securec.h"

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