mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
Merge branch 'master' of gitee.com:openharmony/ability_ability_runtime into master
Signed-off-by: 孙旭辉 <sunxuhui7@huawei.com>
This commit is contained in:
@@ -457,14 +457,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": [
|
||||
|
||||
@@ -177,7 +177,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
|
||||
@@ -473,4 +482,47 @@ bool IsCJAbility(const std::string& info)
|
||||
std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$";
|
||||
return std::regex_match(info, std::regex(pattern));
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance()
|
||||
{
|
||||
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);
|
||||
},
|
||||
.getSymbol = [](void* handle, const char* dllName) {
|
||||
return CJEnvironment::GetInstance()->GetSymbol(handle, dllName);
|
||||
}
|
||||
};
|
||||
return &gCJEnvMethods;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#ifdef WINDOWS_PLATFORM
|
||||
@@ -48,6 +49,16 @@ public:
|
||||
{
|
||||
return isRuntimeStarted_;
|
||||
}
|
||||
enum SanitizerKind {
|
||||
NONE,
|
||||
ASAN,
|
||||
TSAN,
|
||||
HWASAN,
|
||||
};
|
||||
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,6 +102,7 @@ private:
|
||||
bool isRuntimeStarted_{false};
|
||||
bool isUISchedulerStarted_{false};
|
||||
void* uiScheduler_ {nullptr};
|
||||
SanitizerKind sanitizerKind_ {SanitizerKind::NONE};
|
||||
};
|
||||
|
||||
CJ_EXPORT bool IsCJAbility(const std::string& info);
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
@@ -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,34 @@ 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, 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, CreateJsError(env, ERROR_CODE_ONE, "send event failed"));
|
||||
} else {
|
||||
napiAsyncTask.release();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -445,27 +481,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 +518,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 +556,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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -482,6 +482,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 +528,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;
|
||||
}
|
||||
|
||||
@@ -611,54 +619,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 +749,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 +849,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 +882,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 +931,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 +980,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 +1037,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 +1133,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,24 +1209,19 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//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_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"
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* 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 "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;
|
||||
}
|
||||
|
||||
// create normal context
|
||||
return CreateJsBaseContext(env, context);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// create application context
|
||||
return JsApplicationContextUtils::CreateJsApplicationContext(env);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// create normal abilitystage context
|
||||
return CreateJsAbilityStageContext(env, context);
|
||||
}
|
||||
|
||||
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 = AbilityRuntime::Context::ConvertTo<AbilityContext>(context);
|
||||
if (uiAbilityContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Convert to UIAbility context failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// create normal uiability context
|
||||
return CreateJsAbilityContext(env, uiAbilityContext);
|
||||
}
|
||||
|
||||
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::ABILITYMGR, "get context failed");
|
||||
ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr.");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
// create sendable context
|
||||
return CreateSendableContextObject(env, context);
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -107,7 +107,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));
|
||||
|
||||
@@ -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,13 @@ 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",
|
||||
"window_manager:libdm_lite",
|
||||
"window_manager:libwm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
|
||||
@@ -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)
|
||||
{}
|
||||
|
||||
@@ -1430,5 +1435,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
|
||||
@@ -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
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <uv.h>
|
||||
|
||||
#include "ability_util.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_napi_common_ability.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_ability_execute_utils.h"
|
||||
@@ -1016,349 +1016,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.
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -46,7 +46,6 @@ ohos_shared_library("napi_common") {
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:configuration",
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"access_token:libtokenid_sdk",
|
||||
@@ -63,7 +62,6 @@ ohos_shared_library("napi_common") {
|
||||
public_external_deps = [
|
||||
"ability_base:configuration",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"window_manager:libwm_lite",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
@@ -71,6 +69,12 @@ ohos_shared_library("napi_common") {
|
||||
"SUPPORT_GRAPHICS",
|
||||
"SUPPORT_SCREEN",
|
||||
]
|
||||
public_external_deps += [
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
"window_manager:libwm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
|
||||
@@ -840,7 +840,6 @@ void OffExecuteCB(napi_env env, OnCB *onCB)
|
||||
onCB->onRegistration->DelOnCallbackCBRef(env, onCB->onCallbackCB.napiCallback);
|
||||
if (!onCB->onRegistration->GetOnCallbackCBRef().empty()) {
|
||||
TAG_LOGI(AAFwkTag::MISSION, "There are still other remaining callback");
|
||||
return;
|
||||
}
|
||||
DmsSaClient::GetInstance().DelListener(onCB->type, onCB->onRegistration);
|
||||
if (onCB->result == NO_ERROR) {
|
||||
|
||||
@@ -18,6 +18,6 @@ let UIExtensionAbility = requireNapi('app.ability.UIExtensionAbility');
|
||||
export default class PhotoEditorExtensionAbility extends UIExtensionAbility {
|
||||
|
||||
onStartContentEditing(uri, want, session) {
|
||||
console.log("onStartContentEditing: " + uri);
|
||||
console.log('onStartContentEditing: ' + uri);
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,12 @@ export class PhotoEditorExtensionContext extends UIExtensionContext {
|
||||
}
|
||||
|
||||
saveEditedContentWithUri(uri, asyncCallback) {
|
||||
console.log("saveEditedContent with uri: " + uri);
|
||||
console.log('saveEditedContent with uri: ' + uri);
|
||||
return this.__context_impl__.saveEditedContentWithUri(uri, asyncCallback);
|
||||
}
|
||||
|
||||
saveEditedContentWithImage(image, option, asyncCallback) {
|
||||
console.log("saveEditedContent with image pixmap.");
|
||||
console.log('saveEditedContent with image pixmap.');
|
||||
return this.__context_impl__.saveEditedContentWithImage(image, option, asyncCallback);
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,11 @@ class ServiceExtensionContext extends ExtensionContext {
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
preStartMission(bundleName, moduleName, abilityName, startTime) {
|
||||
console.log('preStartMission');
|
||||
return this.__context_impl__.preStartMission(bundleName, moduleName, abilityName, startTime);
|
||||
}
|
||||
}
|
||||
|
||||
export default ServiceExtensionContext;
|
||||
|
||||
@@ -114,6 +114,11 @@ napi_value WantConstantInit(napi_env env, napi_value exports)
|
||||
SetNamedProperty(env, params, "ohos.extra.param.key.supportContinueSourceExit", "SUPPORT_CONTINUE_SOURCE_EXIT_KEY");
|
||||
SetNamedProperty(env, params, "ohos.extra.param.key.showMode", "SHOW_MODE_KEY");
|
||||
SetNamedProperty(env, params, "ohos.extra.param.key.appCloneIndex", "APP_CLONE_INDEX_KEY");
|
||||
SetNamedProperty(env, params, "ohos.param.atomicservice.pagePath", "PAGE_PATH");
|
||||
SetNamedProperty(env, params, "ohos.param.atomicservice.routerName", "ROUTER_NAME");
|
||||
SetNamedProperty(env, params, "ohos.param.atomicservice.pageSourceFile", "PAGE_SOURCE_FILE");
|
||||
SetNamedProperty(env, params, "ohos.param.atomicservice.buildFunction", "BUILD_FUNCTION");
|
||||
SetNamedProperty(env, params, "ohos.param.atomicservice.subpackageName", "SUB_PACKAGE_NAME");
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("Action", action),
|
||||
DECLARE_NAPI_PROPERTY("Entity", entity),
|
||||
|
||||
@@ -74,7 +74,7 @@ void TriggerCompleteCallBack::SetCallbackInfo(napi_env env, NativeReference* ref
|
||||
triggerCompleteInfo_.nativeRef.reset(ref);
|
||||
}
|
||||
|
||||
void TriggerCompleteCallBack::SetWantAgentInstance(WantAgent* wantAgent)
|
||||
void TriggerCompleteCallBack::SetWantAgentInstance(std::shared_ptr<WantAgent> wantAgent)
|
||||
{
|
||||
triggerCompleteInfo_.wantAgent = wantAgent;
|
||||
}
|
||||
@@ -221,7 +221,9 @@ void TriggerCompleteCallBack::OnSendFinished(
|
||||
dataWorker->resultExtras = resultExtras;
|
||||
dataWorker->env = triggerCompleteInfo_.env;
|
||||
dataWorker->nativeRef = std::move(triggerCompleteInfo_.nativeRef);
|
||||
dataWorker->wantAgent = triggerCompleteInfo_.wantAgent;
|
||||
if (triggerCompleteInfo_.wantAgent != nullptr) {
|
||||
dataWorker->wantAgent = new WantAgent(triggerCompleteInfo_.wantAgent->GetPendingWant());
|
||||
}
|
||||
work->data = static_cast<void *>(dataWorker);
|
||||
int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, OnSendFinishedUvAfterWorkCallback);
|
||||
if (ret != 0) {
|
||||
@@ -761,7 +763,7 @@ int32_t JsWantAgent::UnWrapTriggerInfoParam(napi_env env, napi_callback_info inf
|
||||
napi_ref ref = nullptr;
|
||||
napi_create_reference(env, argv[ARGC_TWO], 1, &ref);
|
||||
triggerObj->SetCallbackInfo(env, reinterpret_cast<NativeReference*>(ref));
|
||||
triggerObj->SetWantAgentInstance(pWantAgent);
|
||||
triggerObj->SetWantAgentInstance(std::make_shared<WantAgent>(pWantAgent->GetPendingWant()));
|
||||
|
||||
return BUSINESS_ERROR_CODE_OK;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ const uint8_t NUMBER_OF_PARAMETERS_NINE = 9;
|
||||
class TriggerCompleteCallBack;
|
||||
|
||||
struct CallbackInfo {
|
||||
WantAgent* wantAgent = nullptr;
|
||||
std::shared_ptr<WantAgent> wantAgent;
|
||||
napi_env env = nullptr;
|
||||
std::unique_ptr<NativeReference> nativeRef = nullptr;
|
||||
};
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData,
|
||||
const AAFwk::WantParams &resultExtras) override;
|
||||
void SetCallbackInfo(napi_env env, NativeReference* ref);
|
||||
void SetWantAgentInstance(WantAgent* wantAgent);
|
||||
void SetWantAgentInstance(std::shared_ptr<WantAgent> wantAgent);
|
||||
|
||||
private:
|
||||
CallbackInfo triggerCompleteInfo_;
|
||||
|
||||
@@ -301,7 +301,7 @@ ErrCode AbilityContextImpl::StopServiceExtensionAbility(const AAFwk::Want& want,
|
||||
ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want& want, int resultCode)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::CONTEXT, "TerminateAbilityWithResult");
|
||||
isTerminating_ = true;
|
||||
isTerminating_.store(true);
|
||||
#ifdef SUPPORT_SCREEN
|
||||
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
|
||||
auto sessionToken = GetSessionToken();
|
||||
@@ -539,7 +539,7 @@ ErrCode AbilityContextImpl::MoveUIAbilityToBackground()
|
||||
ErrCode AbilityContextImpl::TerminateSelf()
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::CONTEXT, "TerminateSelf");
|
||||
isTerminating_ = true;
|
||||
isTerminating_.store(true);
|
||||
auto sessionToken = GetSessionToken();
|
||||
if (sessionToken == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::CONTEXT, "sessionToken is null");
|
||||
@@ -576,7 +576,7 @@ ErrCode AbilityContextImpl::CloseAbility()
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "CloseAbility");
|
||||
isTerminating_ = true;
|
||||
isTerminating_.store(true);
|
||||
AAFwk::Want resultWant;
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->CloseAbility(token_, -1, &resultWant);
|
||||
if (err != ERR_OK) {
|
||||
|
||||
@@ -250,19 +250,19 @@ bool ConnectionManager::DisconnectNonexistentService(
|
||||
std::lock_guard<std::recursive_mutex> lock(connectionsLock_);
|
||||
abilityConnections = abilityConnections_;
|
||||
}
|
||||
HILOG_DEBUG("abilityConnectionsSize: %{public}zu", abilityConnections.size());
|
||||
TAG_LOGD(AAFwkTag::CONNECTION, "abilityConnectionsSize: %{public}zu", abilityConnections.size());
|
||||
|
||||
for (auto &&abilityConnection : abilityConnections) {
|
||||
ConnectionInfo connectionInfo = abilityConnection.first;
|
||||
if (connectionInfo.abilityConnection == connection &&
|
||||
connectionInfo.connectReceiver.GetBundleName() == element.GetBundleName()) {
|
||||
HILOG_DEBUG("find connection.");
|
||||
TAG_LOGD(AAFwkTag::CONNECTION, "find connection.");
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exit) {
|
||||
HILOG_ERROR("this service need disconnect");
|
||||
TAG_LOGE(AAFwkTag::CONNECTION, "this service need disconnect");
|
||||
AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connection);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ DialogUIExtensionCallback::DialogUIExtensionCallback(const std::weak_ptr<AppExec
|
||||
{}
|
||||
void DialogUIExtensionCallback::OnRelease()
|
||||
{
|
||||
HILOG_DEBUG("Called");
|
||||
TAG_LOGD(AAFwkTag::DIALOG, "Called");
|
||||
auto abilityCallback = abilityCallback_.lock();
|
||||
if (abilityCallback == nullptr) {
|
||||
HILOG_ERROR("abilityCallback is nullptr");
|
||||
TAG_LOGE(AAFwkTag::DIALOG, "abilityCallback is nullptr");
|
||||
return;
|
||||
}
|
||||
#ifdef SUPPORT_SCREEN
|
||||
|
||||
@@ -36,8 +36,6 @@ config("ability_config") {
|
||||
"${ability_runtime_innerkits_path}/uri/include",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include/continuation",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app/task",
|
||||
"${ability_runtime_napi_path}/inner/napi_common",
|
||||
@@ -63,7 +61,6 @@ config("ability_config") {
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
include_dirs += [ "${form_fwk_path}/interfaces/inner_api/include" ]
|
||||
defines += [
|
||||
"SUPPORT_GRAPHICS",
|
||||
"SUPPORT_SCREEN",
|
||||
@@ -95,13 +92,7 @@ config("ability_public_config") {
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
include_dirs += [
|
||||
"${form_fwk_path}/interfaces/kits/native/include",
|
||||
"${form_fwk_path}/interfaces/inner_api/include",
|
||||
"${windowmanager_path}/interfaces/innerkits/dm",
|
||||
"${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi",
|
||||
"${windowmanager_path}/utils/include",
|
||||
]
|
||||
include_dirs += [ "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi" ]
|
||||
defines = [ "SUPPORT_GRAPHICS" ]
|
||||
}
|
||||
}
|
||||
@@ -214,6 +205,7 @@ ohos_shared_library("abilitykit_native") {
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_helper_impl.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_impl.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/data_uri_utils.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp",
|
||||
@@ -279,10 +271,12 @@ ohos_shared_library("abilitykit_native") {
|
||||
"json:nlohmann_json_static",
|
||||
"napi:ace_napi",
|
||||
"node:node_header_notice",
|
||||
"relational_store:native_rdb",
|
||||
"resource_management:global_resmgr",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
if (!(host_os == "linux" && host_cpu == "arm64")) {
|
||||
external_deps += [ "relational_store:native_rdb" ]
|
||||
}
|
||||
|
||||
public_external_deps = [
|
||||
"accessibility:accessibility_common",
|
||||
@@ -330,17 +324,20 @@ ohos_shared_library("abilitykit_native") {
|
||||
|
||||
external_deps += [
|
||||
"ability_base:session_info",
|
||||
"form_fwk:form_manager",
|
||||
"icu:shared_icuuc",
|
||||
"image_framework:image",
|
||||
"image_framework:image",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:windowstage_kit",
|
||||
]
|
||||
|
||||
public_external_deps += [
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
@@ -406,6 +403,7 @@ ohos_shared_library("extensionkit_native") {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"json:nlohmann_json_static",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
@@ -728,6 +726,15 @@ ohos_shared_library("form_extension_module") {
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
public_external_deps = [
|
||||
"form_fwk:fmskit_provider_client",
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
relative_install_dir = "extensionability"
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
@@ -837,6 +844,14 @@ ohos_shared_library("continuation_ipc") {
|
||||
"libuv:uv",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
public_external_deps += [
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
defines = []
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
@@ -874,10 +889,21 @@ ohos_shared_library("data_ability_helper") {
|
||||
"hitrace:hitrace_meter",
|
||||
"json:nlohmann_json_static",
|
||||
"relational_store:native_dataability",
|
||||
"relational_store:native_rdb",
|
||||
"relational_store:rdb_data_ability_adapter",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
if (!(host_os == "linux" && host_cpu == "arm64")) {
|
||||
external_deps += [ "relational_store:native_rdb" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
public_external_deps = [
|
||||
"form_fwk:fmskit_provider_client",
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "ability"
|
||||
@@ -909,9 +935,12 @@ ohos_shared_library("service_extension_module") {
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [
|
||||
"image_framework:image",
|
||||
external_deps += [ "image_framework:image" ]
|
||||
public_external_deps = [
|
||||
"form_fwk:fmskit_provider_client",
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libdm_lite",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1022,7 +1051,6 @@ config("ui_extension_public_config") {
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
|
||||
"${windowmanager_path}/interfaces/kits/napi/embeddable_window_stage",
|
||||
"${windowmanager_path}/interfaces/kits/napi/extension_window",
|
||||
"${windowmanager_path}/wm/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1076,6 +1104,8 @@ ohos_shared_library("ui_extension") {
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
|
||||
public_external_deps = [ "window_manager:scene_session_manager" ]
|
||||
}
|
||||
|
||||
subsystem_name = "ability"
|
||||
@@ -1092,6 +1122,7 @@ ohos_shared_library("ui_extension_module") {
|
||||
deps = [
|
||||
":ui_extension",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@@ -1103,6 +1134,9 @@ ohos_shared_library("ui_extension_module") {
|
||||
"napi:ace_napi",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "form_fwk:form_manager" ]
|
||||
}
|
||||
|
||||
relative_install_dir = "extensionability/"
|
||||
subsystem_name = "ability"
|
||||
@@ -1234,7 +1268,10 @@ ohos_shared_library("share_extension_module") {
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
external_deps += [
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
relative_install_dir = "extensionability/"
|
||||
@@ -1290,7 +1327,10 @@ ohos_shared_library("action_extension_module") {
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "window_manager:libwm" ]
|
||||
external_deps += [
|
||||
"form_fwk:form_manager",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
}
|
||||
|
||||
relative_install_dir = "extensionability/"
|
||||
@@ -1524,6 +1564,7 @@ ohos_shared_library("auto_fill_extension_module") {
|
||||
deps = [
|
||||
":auto_fill_extension",
|
||||
"${ability_runtime_innerkits_path}/runtime:runtime",
|
||||
"${ability_runtime_native_path}/appkit:appkit_native",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@@ -1535,6 +1576,9 @@ ohos_shared_library("auto_fill_extension_module") {
|
||||
"napi:ace_napi",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
if (ability_runtime_graphics) {
|
||||
external_deps += [ "form_fwk:form_manager" ]
|
||||
}
|
||||
|
||||
relative_install_dir = "extensionability/"
|
||||
subsystem_name = "ability"
|
||||
|
||||
@@ -85,6 +85,7 @@ constexpr const char* ERROR_MSG_NOT_APP_CLONE = "The target app is not Clone.";
|
||||
constexpr const char* ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED =
|
||||
"The extension can not start the specified third party application.";
|
||||
constexpr const char* ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED = "The extension can not start the service.";
|
||||
constexpr const char* ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST = "The target free install task does not exist.";
|
||||
|
||||
// follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework
|
||||
constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220;
|
||||
@@ -144,7 +145,8 @@ static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
|
||||
{ AbilityErrorCode::ERROR_CODE_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED,
|
||||
ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED },
|
||||
{ AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED, ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED},
|
||||
{ AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST}
|
||||
{ AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST},
|
||||
{ AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST, ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST }
|
||||
};
|
||||
|
||||
static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP {
|
||||
@@ -207,6 +209,7 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
|
||||
AbilityErrorCode::ERROR_CODE_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED},
|
||||
{EXTENSION_BLOCKED_BY_SERVICE_LIST, AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED},
|
||||
{ERR_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID},
|
||||
{ERR_FREE_INSTALL_TASK_NOT_EXIST, AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -547,7 +547,7 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called .");
|
||||
if (executeParam == nullptr) {
|
||||
HILOG_WARN("Intention execute param invalid.");
|
||||
TAG_LOGW(AAFwkTag::UIABILITY, "Intention execute param invalid.");
|
||||
RequestFocus(want);
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
@@ -580,7 +580,7 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called.");
|
||||
if (executeParam == nullptr) {
|
||||
HILOG_WARN("Intention execute param invalid.");
|
||||
TAG_LOGW(AAFwkTag::UIABILITY, "Intention execute param invalid.");
|
||||
OnForeground(want);
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
|
||||
@@ -532,7 +532,7 @@ napi_value JsAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
StartAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, TRACE_ATOMIC_SERVICE, TRACE_ATOMIC_SERVICE_ID);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::CONTEXT, "OnOpenLink");
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "OnOpenLink");
|
||||
|
||||
std::string linkValue("");
|
||||
AAFwk::OpenLinkOptions openLinkOptions;
|
||||
@@ -547,7 +547,6 @@ napi_value JsAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info)
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::CONTEXT, "open link:%{public}s.", linkValue.c_str());
|
||||
want.SetUri(linkValue);
|
||||
int requestCode = -1;
|
||||
if (CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) {
|
||||
@@ -2047,39 +2046,38 @@ napi_value JsAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo
|
||||
napi_value JsAbilityContext::OnRequestModalUIExtension(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::CONTEXT, "called");
|
||||
|
||||
if (info.argc < ARGC_ONE) {
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
AAFwk::Want want;
|
||||
if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "Failed to parse want!");
|
||||
ThrowInvalidParamError(env, "Parse param want failed, want must be Want.");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
TAG_LOGW(AAFwkTag::CONTEXT, "context is released");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
|
||||
return;
|
||||
}
|
||||
auto errcode = context->RequestModalUIExtension(want);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
}
|
||||
};
|
||||
|
||||
auto innerErrCode = std::make_shared<ErrCode>(ERR_OK);
|
||||
NapiAsyncTask::ExecuteCallback execute = [abilityContext = context_, want, innerErrCode]() {
|
||||
auto context = abilityContext.lock();
|
||||
if (!context) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "context is released");
|
||||
*innerErrCode = static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return;
|
||||
}
|
||||
*innerErrCode = AAFwk::AbilityManagerClient::GetInstance()->RequestModalUIExtension(want);
|
||||
};
|
||||
NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (*innerErrCode == ERR_OK) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "OnRequestModalUIExtension is failed %{public}d", *innerErrCode);
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
|
||||
}
|
||||
};
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnRequestModalUIExtension",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -520,15 +520,21 @@ void JsUIAbility::OnSceneRestored()
|
||||
}
|
||||
UpdateJsWindowStage(jsAppWindowStage->GetNapiValue());
|
||||
napi_value argv[] = {jsAppWindowStage->GetNapiValue()};
|
||||
jsWindowStageObj_ = std::shared_ptr<NativeReference>(jsAppWindowStage.release());
|
||||
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnWindowStageWillRestore(jsAbilityObj_, jsWindowStageObj_);
|
||||
}
|
||||
CallObjectMethod("onWindowStageRestore", argv, ArraySize(argv));
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnWindowStageRestore(jsAbilityObj_, jsWindowStageObj_);
|
||||
}
|
||||
|
||||
auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (delegator) {
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformScenceRestored.");
|
||||
delegator->PostPerformScenceRestored(CreateADelegatorAbilityProperty());
|
||||
}
|
||||
|
||||
jsWindowStageObj_ = std::shared_ptr<NativeReference>(jsAppWindowStage.release());
|
||||
}
|
||||
|
||||
void JsUIAbility::OnSceneWillDestroy()
|
||||
@@ -1074,6 +1080,12 @@ int32_t JsUIAbility::OnContinue(WantParams &wantParams)
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "Failed to get Ability object.");
|
||||
return AppExecFwk::ContinuationManagerStage::OnContinueResult::REJECT;
|
||||
}
|
||||
|
||||
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnAbilityWillContinue(jsAbilityObj_);
|
||||
}
|
||||
|
||||
napi_value jsWantParams = OHOS::AppExecFwk::WrapWantParams(env, wantParams);
|
||||
napi_value result = CallObjectMethod("onContinue", &jsWantParams, 1, true);
|
||||
int32_t onContinueRes = 0;
|
||||
@@ -1089,7 +1101,6 @@ int32_t JsUIAbility::OnContinue(WantParams &wantParams)
|
||||
}
|
||||
}
|
||||
OHOS::AppExecFwk::UnwrapWantParams(env, jsWantParams, wantParams);
|
||||
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnAbilityContinue(jsAbilityObj_);
|
||||
}
|
||||
@@ -1111,6 +1122,11 @@ int32_t JsUIAbility::OnSaveState(int32_t reason, WantParams &wantParams)
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto applicationContext = AbilityRuntime::Context::GetApplicationContext();
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnAbilityWillSaveState(jsAbilityObj_);
|
||||
}
|
||||
|
||||
napi_value methodOnSaveState = nullptr;
|
||||
napi_get_named_property(env, obj, "onSaveState", &methodOnSaveState);
|
||||
if (methodOnSaveState == nullptr) {
|
||||
@@ -1130,6 +1146,11 @@ int32_t JsUIAbility::OnSaveState(int32_t reason, WantParams &wantParams)
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "AppRecovery no result return from onSaveState.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (applicationContext != nullptr) {
|
||||
applicationContext->DispatchOnAbilitySaveState(jsAbilityObj_);
|
||||
}
|
||||
|
||||
return numberResult;
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -493,6 +493,7 @@ bool JsAutoFillExtension::HandleAutoFillCreate(const AAFwk::Want &want, const sp
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
|
||||
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);
|
||||
option->SetParentId(sessionInfo->hostWindowId);
|
||||
option->SetUIExtensionUsage(static_cast<uint32_t>(sessionInfo->uiExtensionUsage));
|
||||
auto uiWindow = Rosen::Window::Create(option, GetContext(), sessionInfo->sessionToken);
|
||||
if (uiWindow == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "Create ui window error.");
|
||||
|
||||
+3
-7
@@ -23,10 +23,7 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
DialogRequestCallbackStub::DialogRequestCallbackStub()
|
||||
{
|
||||
vecMemberFunc_.resize(IDialogRequestCallback::CODE_MAX);
|
||||
vecMemberFunc_[CODE_SEND_RESULT] = &DialogRequestCallbackStub::SendResultInner;
|
||||
}
|
||||
{}
|
||||
|
||||
int DialogRequestCallbackStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
@@ -38,9 +35,8 @@ int DialogRequestCallbackStub::OnRemoteRequest(
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (code < IDialogRequestCallback::CODE_MAX) {
|
||||
auto memberFunc = vecMemberFunc_[code];
|
||||
return (this->*memberFunc)(data, reply);
|
||||
if (code == CODE_SEND_RESULT) {
|
||||
return SendResultInner(data, reply);
|
||||
}
|
||||
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace {
|
||||
constexpr static char FORM_EXTENSION[] = "FormExtension";
|
||||
constexpr static char UI_EXTENSION[] = "UIExtensionAbility";
|
||||
constexpr static char CUSTOM_EXTENSION[] = "ExtensionAbility";
|
||||
constexpr static char MEDIA_CONTROL_EXTENSION[] = "MediaControlExtensionAbility";
|
||||
constexpr static char USER_AUTH_EXTENSION[] = "UserAuthExtensionAbility";
|
||||
constexpr static char ACTION_EXTENSION[] = "ActionExtensionAbility";
|
||||
constexpr static char SHARE_EXTENSION[] = "ShareExtensionAbility";
|
||||
@@ -151,11 +150,6 @@ void ExtensionAbilityThread::CreateExtensionAbilityName(
|
||||
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::INPUTMETHOD) {
|
||||
abilityName = INPUTMETHOD_EXTENSION;
|
||||
}
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL) {
|
||||
abilityName = MEDIA_CONTROL_EXTENSION;
|
||||
}
|
||||
#endif // SUPPORT_GRAPHICS
|
||||
if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION) {
|
||||
abilityName = APP_ACCOUNT_AUTHORIZATION_EXTENSION;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,20 @@
|
||||
#include "ability_local_record.h"
|
||||
#include "ability_transaction_callback_info.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_object_proxy.h"
|
||||
#include "extension_context.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "ui_extension_utils.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
ExtensionImpl::~ExtensionImpl()
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::EXT, "~ExtensionImpl");
|
||||
}
|
||||
|
||||
void ExtensionImpl::Init(const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
std::shared_ptr<Extension> &extension,
|
||||
@@ -48,12 +55,33 @@ void ExtensionImpl::Init(const std::shared_ptr<AppExecFwk::OHOSApplication> &app
|
||||
extension_->SetExtensionWindowLifeCycleListener(
|
||||
sptr<ExtensionWindowLifeCycleImpl>(new ExtensionWindowLifeCycleImpl(token_, shared_from_this())));
|
||||
}
|
||||
if (record->GetAbilityInfo()->name == "com.ohos.callui.ServiceAbility") {
|
||||
PrintTokenInfo();
|
||||
}
|
||||
}
|
||||
extension_->Init(record, application, handler, token);
|
||||
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
|
||||
skipCommandExtensionWithIntent_ = false;
|
||||
}
|
||||
|
||||
void ExtensionImpl::PrintTokenInfo() const
|
||||
{
|
||||
if (token_ == nullptr) {
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null");
|
||||
return;
|
||||
}
|
||||
if (!token_->IsProxyObject()) {
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy");
|
||||
return;
|
||||
}
|
||||
IPCObjectProxy *tokenProxyObject = reinterpret_cast<IPCObjectProxy *>(token_.GetRefPtr());
|
||||
if (tokenProxyObject != nullptr) {
|
||||
std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor());
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s",
|
||||
tokenProxyObject->GetHandle(), remoteDescriptor.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle switching of Extension.
|
||||
*
|
||||
@@ -442,9 +470,9 @@ void ExtensionImpl::SendResult(int requestCode, int resultCode, const Want &resu
|
||||
|
||||
void ExtensionImpl::SetLaunchParam(const AAFwk::LaunchParam &launchParam)
|
||||
{
|
||||
HILOG_DEBUG("Called.");
|
||||
TAG_LOGD(AAFwkTag::EXT, "Called.");
|
||||
if (extension_ == nullptr) {
|
||||
HILOG_ERROR("Extension is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::EXT, "Extension is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,10 @@
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
FreeInstallObserverStub::FreeInstallObserverStub()
|
||||
{
|
||||
memberFuncMap_[IFreeInstallObserver::ON_INSTALL_FINISHED] =
|
||||
&FreeInstallObserverStub::OnInstallFinishedInner;
|
||||
}
|
||||
{}
|
||||
|
||||
FreeInstallObserverStub::~FreeInstallObserverStub()
|
||||
{
|
||||
memberFuncMap_.clear();
|
||||
}
|
||||
{}
|
||||
|
||||
int FreeInstallObserverStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
@@ -54,12 +49,8 @@ int FreeInstallObserverStub::OnRemoteRequest(
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
auto memberFunc = itFunc->second;
|
||||
if (memberFunc != nullptr) {
|
||||
return (this->*memberFunc)(data, reply);
|
||||
}
|
||||
if (code == IFreeInstallObserver::ON_INSTALL_FINISHED) {
|
||||
return OnInstallFinishedInner(data, reply);
|
||||
}
|
||||
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
|
||||
@@ -45,12 +45,14 @@ namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t INDEX_TWO = 2;
|
||||
constexpr int32_t INDEX_THREE = 3;
|
||||
constexpr int32_t ERROR_CODE_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE_TWO = 2;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr size_t ARGC_FOUR = 4;
|
||||
|
||||
class StartAbilityByCallParameters {
|
||||
public:
|
||||
@@ -170,6 +172,11 @@ public:
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnRequestModalUIExtension);
|
||||
}
|
||||
|
||||
static napi_value PreStartMission(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnPreStartMission);
|
||||
}
|
||||
|
||||
private:
|
||||
std::weak_ptr<ServiceExtensionContext> context_;
|
||||
sptr<JsFreeInstallObserver> freeInstallObserver_ = nullptr;
|
||||
@@ -301,7 +308,7 @@ private:
|
||||
napi_value OnOpenLink(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::SERVICE_EXT, "OnOpenLink");
|
||||
TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnOpenLink");
|
||||
|
||||
std::string linkValue("");
|
||||
AAFwk::OpenLinkOptions openLinkOptions;
|
||||
@@ -315,7 +322,6 @@ private:
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::SERVICE_EXT, "open link:%{public}s.", linkValue.c_str());
|
||||
want.SetUri(linkValue);
|
||||
auto innerErrorCode = std::make_shared<int>(ERR_OK);
|
||||
|
||||
@@ -690,12 +696,12 @@ private:
|
||||
NapiAsyncTask::CompleteCallback complete = [connection, connectId, innerErrorCode](napi_env env,
|
||||
NapiAsyncTask& task, int32_t status) {
|
||||
if (*innerErrorCode == 0) {
|
||||
HILOG_INFO("Connect ability success.");
|
||||
TAG_LOGI(AAFwkTag::SERVICE_EXT, "Connect ability success.");
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_ERROR("Connect ability failed.");
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "Connect ability failed.");
|
||||
int32_t errcode = static_cast<int32_t>(AbilityRuntime::GetJsErrorCodeByNativeError(*innerErrorCode));
|
||||
if (errcode) {
|
||||
connection->CallJsFailed(errcode);
|
||||
@@ -1017,27 +1023,100 @@ private:
|
||||
ThrowInvalidParamError(env, "Parse param want failed, must be a Want.");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
|
||||
auto innerErrCode = std::make_shared<ErrCode>(ERR_OK);
|
||||
NapiAsyncTask::ExecuteCallback execute = [serviceContext = context_, want, innerErrCode]() {
|
||||
auto context = serviceContext.lock();
|
||||
if (!context) {
|
||||
TAG_LOGW(AAFwkTag::SERVICE_EXT, "context is released");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "context is released");
|
||||
*innerErrCode = static_cast<int>(AbilityErrorCode::ERROR_CODE_INNER);
|
||||
return;
|
||||
}
|
||||
auto errcode = context->RequestModalUIExtension(want);
|
||||
if (errcode == 0) {
|
||||
*innerErrCode = AAFwk::AbilityManagerClient::GetInstance()->RequestModalUIExtension(want);
|
||||
};
|
||||
NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
if (*innerErrCode == ERR_OK) {
|
||||
task.Resolve(env, CreateJsUndefined(env));
|
||||
} else {
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "OnRequestModalUIExtension is failed %{public}d", *innerErrCode);
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
|
||||
}
|
||||
};
|
||||
|
||||
napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr;
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JSServiceExtensionContext::OnRequestModalUIExtension",
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result));
|
||||
env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ParsePreStartMissionArgs(const napi_env &env, const NapiCallbackInfo &info, std::string& bundleName,
|
||||
std::string& moduleName, std::string& abilityName, std::string& startTime)
|
||||
{
|
||||
if (info.argc < ARGC_FOUR) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "wrong arguments num");
|
||||
ThrowTooFewParametersError(env);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string args[ARGC_FOUR];
|
||||
for (size_t i = 0; i < ARGC_FOUR; i++) {
|
||||
if (!CheckTypeForNapiValue(env, info.argv[i], napi_string)) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "param must be string");
|
||||
return false;
|
||||
}
|
||||
if (!ConvertFromJsValue(env, info.argv[i], args[i])) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "parameter invalid");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bundleName = args[INDEX_ZERO];
|
||||
moduleName = args[INDEX_ONE];
|
||||
abilityName = args[INDEX_TWO];
|
||||
startTime = args[INDEX_THREE];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
napi_value OnPreStartMission(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::SERVICE_EXT, "called");
|
||||
if (info.argc < ARGC_FOUR) {
|
||||
ThrowTooFewParametersError(env);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
std::string bundleName;
|
||||
std::string moduleName;
|
||||
std::string abilityName;
|
||||
std::string startTime;
|
||||
if (!ParsePreStartMissionArgs(env, info, bundleName, moduleName, abilityName, startTime)) {
|
||||
TAG_LOGE(AAFwkTag::SERVICE_EXT, "parse preStartMission arguments failed");
|
||||
ThrowInvalidParamError(env, "Parse params failed, params must be strings.");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = context_, bundleName, moduleName, abilityName, startTime](
|
||||
napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
TAG_LOGW(AAFwkTag::SERVICE_EXT, "context is released");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
|
||||
return;
|
||||
}
|
||||
auto errcode = context->PreStartMission(bundleName, moduleName, abilityName, startTime);
|
||||
if (errcode == 0) {
|
||||
task.ResolveWithNoError(env, CreateJsUndefined(env));
|
||||
return;
|
||||
}
|
||||
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
|
||||
};
|
||||
|
||||
napi_value result = nullptr;
|
||||
NapiAsyncTask::ScheduleHighQos("JSServiceExtensionContext::OnPreStartMission",
|
||||
env, CreateAsyncTaskWithLastParam(env, nullptr, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1152,6 +1231,8 @@ napi_value CreateJsServiceExtensionContext(napi_env env, std::shared_ptr<Service
|
||||
JsServiceExtensionContext::StartRecentAbility);
|
||||
BindNativeFunction(env, object, "requestModalUIExtension", moduleName,
|
||||
JsServiceExtensionContext::RequestModalUIExtension);
|
||||
BindNativeFunction(env, object, "preStartMission", moduleName,
|
||||
JsServiceExtensionContext::PreStartMission);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "photo_editor_extension_context.h"
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include "media_errors.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
@@ -114,8 +115,14 @@ PhotoEditorErrorCode PhotoEditorExtensionContext::CopyImageToPanel(const std::st
|
||||
TAG_LOGD(AAFwkTag::UI_EXT, "ImageUri: %{public}s, panelPhysicalPath: %{public}s.", imageUri.c_str(),
|
||||
panelPhysicalPath.c_str());
|
||||
|
||||
char imagePath[PATH_MAX] = {0};
|
||||
if (realpath(imageUri.c_str(), imagePath) == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "Realpath error, errno is %{public}d.", errno);
|
||||
return PhotoEditorErrorCode::ERROR_CODE_IMAGE_INPUT_ERROR;
|
||||
}
|
||||
|
||||
std::ifstream sourceFile;
|
||||
sourceFile.open(imageUri, std::ios::binary);
|
||||
sourceFile.open(imagePath, std::ios::binary);
|
||||
if (!sourceFile.is_open()) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "Can not open source file.");
|
||||
sourceFile.close();
|
||||
@@ -143,8 +150,7 @@ PhotoEditorErrorCode PhotoEditorExtensionContext::CopyImageToPanel(const std::st
|
||||
while (sourceFile.read(buffer, sizeof(buffer))) {
|
||||
panelFile.write(buffer, sizeof(buffer));
|
||||
}
|
||||
size_t remainingBytes = sourceFile.gcount();
|
||||
panelFile.write(buffer, remainingBytes);
|
||||
panelFile.write(buffer, sourceFile.gcount());
|
||||
sourceFile.close();
|
||||
panelFile.close();
|
||||
|
||||
|
||||
+17
@@ -66,6 +66,11 @@ napi_value JsEmbeddableUIAbilityContext::StartAbility(napi_env env, napi_callbac
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbility);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OpenLink(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnOpenLink);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityForResult(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityForResult);
|
||||
@@ -187,6 +192,17 @@ napi_value JsEmbeddableUIAbilityContext::OnStartAbility(napi_env env, NapiCallba
|
||||
return jsAbilityContext_->OnStartAbility(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::EMBEDDED_FULL_SCREEN_MODE) {
|
||||
TAG_LOGI(AAFwkTag::UI_EXT, "Start openlink in embedded screen mode.");
|
||||
CHECK_POINTER_RETURN(env, jsUIExtensionContext_);
|
||||
return jsUIExtensionContext_->OnOpenLink(env, info);
|
||||
}
|
||||
CHECK_POINTER_RETURN(env, jsAbilityContext_);
|
||||
return jsAbilityContext_->OnOpenLink(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::EMBEDDED_FULL_SCREEN_MODE) {
|
||||
@@ -524,6 +540,7 @@ napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi
|
||||
|
||||
const char* moduleName = "JsEmbeddableUIAbilityContext";
|
||||
BindNativeFunction(env, objValue, "startAbility", moduleName, StartAbility);
|
||||
BindNativeFunction(env, objValue, "openLink", moduleName, OpenLink);
|
||||
BindNativeFunction(env, objValue, "startAbilityForResult", moduleName, StartAbilityForResult);
|
||||
BindNativeFunction(env, objValue, "connectServiceExtensionAbility", moduleName, ConnectAbility);
|
||||
BindNativeFunction(env, objValue, "disconnectServiceExtensionAbility", moduleName, DisconnectAbility);
|
||||
|
||||
@@ -708,6 +708,7 @@ sptr<Rosen::Window> JsUIExtension::CreateUIWindow(const std::shared_ptr<UIExtens
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
|
||||
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);
|
||||
option->SetParentId(sessionInfo->hostWindowId);
|
||||
option->SetUIExtensionUsage(static_cast<uint32_t>(sessionInfo->uiExtensionUsage));
|
||||
return Rosen::Window::Create(option, GetContext(), sessionInfo->sessionToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -503,6 +503,7 @@ bool JsUIExtensionBase::HandleSessionCreate(const AAFwk::Want &want, const sptr<
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION);
|
||||
option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION);
|
||||
option->SetParentId(sessionInfo->hostWindowId);
|
||||
option->SetUIExtensionUsage(static_cast<uint32_t>(sessionInfo->uiExtensionUsage));
|
||||
auto uiWindow = Rosen::Window::Create(option, context_, sessionInfo->sessionToken);
|
||||
if (uiWindow == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "create ui window error.");
|
||||
|
||||
+4
-4
@@ -1080,11 +1080,11 @@ void JsUIExtensionContentSession::SetCallbackForTerminateWithResult(int32_t resu
|
||||
auto extensionContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIExtensionContext>(weak.lock());
|
||||
if (!extensionContext) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "extensionContext is nullptr");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT));
|
||||
return;
|
||||
} else {
|
||||
auto token = extensionContext->GetToken();
|
||||
AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want);
|
||||
}
|
||||
auto token = extensionContext->GetToken();
|
||||
AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want);
|
||||
|
||||
if (uiWindow == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr.");
|
||||
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
|
||||
|
||||
@@ -289,7 +289,7 @@ static bool ParseOpenLinkParams(const napi_env &env, const NapiCallbackInfo &inf
|
||||
napi_value JsUIExtensionContext::OnOpenLink(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
TAG_LOGI(AAFwkTag::UI_EXT, "OnOpenLink");
|
||||
TAG_LOGD(AAFwkTag::UI_EXT, "OnOpenLink");
|
||||
|
||||
std::string linkValue("");
|
||||
AAFwk::OpenLinkOptions openLinkOptions;
|
||||
@@ -304,7 +304,6 @@ napi_value JsUIExtensionContext::OnOpenLink(napi_env env, NapiCallbackInfo& info
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
TAG_LOGI(AAFwkTag::UI_EXT, "open link:%{public}s.", linkValue.c_str());
|
||||
want.SetUri(linkValue);
|
||||
int requestCode = -1;
|
||||
if (CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) {
|
||||
|
||||
@@ -120,6 +120,7 @@ ohos_shared_library("appkit_native") {
|
||||
"${ability_runtime_native_path}/appkit/app/child_main_thread.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/dump_ffrt_helper.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/dump_ipc_helper.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/dump_runtime_helper.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/extension_plugin_info.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/idle_time.cpp",
|
||||
"${ability_runtime_native_path}/appkit/app/main_thread.cpp",
|
||||
@@ -175,6 +176,7 @@ ohos_shared_library("appkit_native") {
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ets_runtime:libark_jsruntime",
|
||||
"eventhandler:libeventhandler",
|
||||
"faultloggerd:libbacktrace_local",
|
||||
"faultloggerd:libdfx_procinfo",
|
||||
|
||||
@@ -668,7 +668,7 @@ void BundleMgrHelper::UpgradeAtomicService(const Want &want, int32_t userId)
|
||||
}
|
||||
|
||||
bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault,
|
||||
std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos)
|
||||
std::vector<AbilityInfo> &abilityInfos, std::vector<ExtensionAbilityInfo> &extensionInfos, bool &findDefaultApp)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
|
||||
auto bundleMgr = Connect();
|
||||
@@ -680,7 +680,6 @@ bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_
|
||||
AAFwk::Want newWant = want;
|
||||
newWant.RemoveAllFd();
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
bool findDefaultApp = false;
|
||||
bool ret = bundleMgr->ImplicitQueryInfos(newWant, flags, userId, withDefault, abilityInfos,
|
||||
extensionInfos, findDefaultApp);
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "findDefaultApp is %{public}d.", findDefaultApp);
|
||||
@@ -714,19 +713,6 @@ bool BundleMgrHelper::QueryDataGroupInfos(
|
||||
return bundleMgr->QueryDataGroupInfos(bundleName, userId, infos);
|
||||
}
|
||||
|
||||
bool BundleMgrHelper::GetBundleGidsByUid(const std::string &bundleName, const int32_t &uid, std::vector<int32_t> &gids)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
|
||||
auto bundleMgr = Connect();
|
||||
if (bundleMgr == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
return bundleMgr->GetBundleGidsByUid(bundleName, uid, gids);
|
||||
}
|
||||
|
||||
bool BundleMgrHelper::RegisterBundleEventCallback(const sptr<IBundleEventCallback> &bundleEventCallback)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called.");
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <regex>
|
||||
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "runner_runtime/cj_test_runner_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -27,26 +27,26 @@ namespace RunnerRuntime {
|
||||
std::unique_ptr<TestRunner> CJTestRunner::Create(const std::unique_ptr<Runtime> &runtime,
|
||||
const std::shared_ptr<AbilityDelegatorArgs> &args, const AppExecFwk::BundleInfo &bundleInfo)
|
||||
{
|
||||
HILOG_INFO("CJTestRunner::Create start.");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "CJTestRunner::Create start.");
|
||||
if (!runtime) {
|
||||
HILOG_ERROR("Invalid runtime");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "Invalid runtime");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto cjRuntime = static_cast<CJRuntime*>(runtime.get());
|
||||
if (!cjRuntime->IsAppLibLoaded()) {
|
||||
HILOG_ERROR("CJTestRunner: AppLib Not Loaded");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunner: AppLib Not Loaded");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!args) {
|
||||
HILOG_ERROR("Invalid ability delegator args");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "Invalid ability delegator args");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pTestRunner = new (std::nothrow) CJTestRunner(*cjRuntime, args, bundleInfo);
|
||||
if (!pTestRunner) {
|
||||
HILOG_ERROR("Failed to create test runner");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "Failed to create test runner");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ CJTestRunner::~CJTestRunner() = default;
|
||||
bool CJTestRunner::Initialize()
|
||||
{
|
||||
if (!cjRuntime_.IsAppLibLoaded()) {
|
||||
HILOG_ERROR("CJTestRunner: AppLib Not Loaded");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunner: AppLib Not Loaded");
|
||||
return false;
|
||||
}
|
||||
if (!cjTestRunnerObj_) {
|
||||
HILOG_ERROR("CJTestRunnerObj does not exist, Initialize failed.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, Initialize failed.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -77,34 +77,34 @@ bool CJTestRunner::Initialize()
|
||||
|
||||
void CJTestRunner::Prepare()
|
||||
{
|
||||
HILOG_INFO("Enter");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "Enter");
|
||||
TestRunner::Prepare();
|
||||
if (!cjTestRunnerObj_) {
|
||||
HILOG_ERROR("CJTestRunnerObj does not exist, Prepare failed.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, Prepare failed.");
|
||||
return;
|
||||
}
|
||||
cjTestRunnerObj_->OnPrepare();
|
||||
HILOG_INFO("End");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "End");
|
||||
}
|
||||
|
||||
void CJTestRunner::Run()
|
||||
{
|
||||
HILOG_INFO("Enter");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "Enter");
|
||||
TestRunner::Run();
|
||||
if (!cjTestRunnerObj_) {
|
||||
HILOG_ERROR("CJTestRunnerObj does not exist, OnRun failed.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, OnRun failed.");
|
||||
return;
|
||||
}
|
||||
cjTestRunnerObj_->OnRun();
|
||||
HILOG_INFO("End");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "End");
|
||||
}
|
||||
|
||||
void CJTestRunner::ReportFinished(const std::string &msg)
|
||||
{
|
||||
HILOG_INFO("Enter");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "Enter");
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
HILOG_ERROR("delegator is null.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "delegator is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ void CJTestRunner::ReportFinished(const std::string &msg)
|
||||
|
||||
void CJTestRunner::ReportStatus(const std::string &msg)
|
||||
{
|
||||
HILOG_INFO("Enter");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "Enter");
|
||||
auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator();
|
||||
if (!delegator) {
|
||||
HILOG_ERROR("delegator is null.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "delegator is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace {
|
||||
// g_cjTestRunnerFuncs is used to save cj functions.
|
||||
@@ -28,20 +28,20 @@ CJTestRunnerFuncs* g_cjTestRunnerFuncs = nullptr;
|
||||
|
||||
void RegisterCJTestRunnerFuncs(void (*registerFunc)(CJTestRunnerFuncs*))
|
||||
{
|
||||
HILOG_INFO("RegisterCJTestRunnerFuncs start.");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs start.");
|
||||
if (g_cjTestRunnerFuncs != nullptr) {
|
||||
HILOG_ERROR("Repeated registration for cj functions of CJTestRunner.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "Repeated registration for cj functions of CJTestRunner.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (registerFunc == nullptr) {
|
||||
HILOG_ERROR("RegisterCJTestRunnerFuncs failed, registerFunc is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs failed, registerFunc is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
g_cjTestRunnerFuncs = new CJTestRunnerFuncs();
|
||||
registerFunc(g_cjTestRunnerFuncs);
|
||||
HILOG_INFO("RegisterCJTestRunnerFuncs end.");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs end.");
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
@@ -49,12 +49,12 @@ namespace RunnerRuntime {
|
||||
std::shared_ptr<CJTestRunnerObject> CJTestRunnerObject::LoadModule(const std::string& name)
|
||||
{
|
||||
if (g_cjTestRunnerFuncs == nullptr) {
|
||||
HILOG_ERROR("cj functions for CJTestRunner are not registered");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered");
|
||||
return nullptr;
|
||||
}
|
||||
auto id = g_cjTestRunnerFuncs->cjTestRunnerCreate(name.c_str());
|
||||
if (id == 0) {
|
||||
HILOG_ERROR(
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR,
|
||||
"Failed to invoke CJTestRunnerObject::LoadModule. Ability: %{public}s is not registered.", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ CJTestRunnerObject::~CJTestRunnerObject()
|
||||
void CJTestRunnerObject::OnRun() const
|
||||
{
|
||||
if (g_cjTestRunnerFuncs == nullptr) {
|
||||
HILOG_ERROR("cj functions for CJTestRunner are not registered");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjTestRunnerFuncs->cjTestRunnerOnRun(id_);
|
||||
@@ -79,7 +79,7 @@ void CJTestRunnerObject::OnRun() const
|
||||
void CJTestRunnerObject::OnPrepare() const
|
||||
{
|
||||
if (g_cjTestRunnerFuncs == nullptr) {
|
||||
HILOG_ERROR("cj functions for CJTestRunner are not registered");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjTestRunnerFuncs->cjTestRunnerOnPrepare(id_);
|
||||
|
||||
@@ -80,34 +80,45 @@ std::shared_ptr<CJAbilityStage> CJAbilityStage::Create(
|
||||
const std::unique_ptr<Runtime>& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo)
|
||||
{
|
||||
if (!runtime) {
|
||||
HILOG_ERROR("Runtime does not exist.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Runtime does not exist.");
|
||||
return nullptr;
|
||||
}
|
||||
auto& cjRuntime = static_cast<CJRuntime&>(*runtime);
|
||||
// Load cj app library.
|
||||
if (!cjRuntime.IsAppLibLoaded()) {
|
||||
HILOG_ERROR("Failed to create CJAbilityStage, applib not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage, applib not loaded.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto cjAbilityStageObject = CJAbilityStageObject::LoadModule(hapModuleInfo.moduleName);
|
||||
if (cjAbilityStageObject == nullptr) {
|
||||
cjRuntime.UnLoadCJAppLibrary();
|
||||
HILOG_ERROR("Failed to create CJAbilityStage.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_shared<CJAbilityStage>(cjAbilityStageObject);
|
||||
}
|
||||
|
||||
void CJAbilityStage::Init(const std::shared_ptr<Context> &context,
|
||||
const std::weak_ptr<AppExecFwk::OHOSApplication> application)
|
||||
{
|
||||
AbilityStage::Init(context, application);
|
||||
if (!cjAbilityStageObject_) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->Init(this);
|
||||
}
|
||||
|
||||
void CJAbilityStage::OnCreate(const AAFwk::Want& want) const
|
||||
{
|
||||
AbilityStage::OnCreate(want);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("CJAbilityStage::OnCreate");
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "CJAbilityStage::OnCreate");
|
||||
cjAbilityStageObject_->OnCreate();
|
||||
}
|
||||
|
||||
@@ -115,7 +126,7 @@ std::string CJAbilityStage::OnAcceptWant(const AAFwk::Want& want)
|
||||
{
|
||||
AbilityStage::OnAcceptWant(want);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return "";
|
||||
}
|
||||
return cjAbilityStageObject_->OnAcceptWant(want);
|
||||
@@ -126,12 +137,12 @@ void CJAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration& con
|
||||
AbilityStage::OnConfigurationUpdated(configuration);
|
||||
auto fullConfig = GetContext()->GetConfiguration();
|
||||
if (!fullConfig) {
|
||||
HILOG_ERROR("configuration is nullptr.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "configuration is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->OnConfigurationUpdated(fullConfig);
|
||||
@@ -141,7 +152,7 @@ void CJAbilityStage::OnMemoryLevel(int level)
|
||||
{
|
||||
AbilityStage::OnMemoryLevel(level);
|
||||
if (!cjAbilityStageObject_) {
|
||||
HILOG_ERROR("CJAbilityStage is not loaded.");
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded.");
|
||||
return;
|
||||
}
|
||||
cjAbilityStageObject_->OnMemoryLevel(level);
|
||||
|
||||
@@ -67,6 +67,15 @@ CJAbilityStageObject::~CJAbilityStageObject()
|
||||
id_ = 0;
|
||||
}
|
||||
|
||||
void CJAbilityStageObject::Init(AbilityStageHandle abilityStage) const
|
||||
{
|
||||
if (g_cjAbilityStageFuncs == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "cj functions for CJAbilityStage are not registered");
|
||||
return;
|
||||
}
|
||||
g_cjAbilityStageFuncs->AbilityStageInit(id_, abilityStage);
|
||||
}
|
||||
|
||||
void CJAbilityStageObject::OnCreate() const
|
||||
{
|
||||
if (g_cjAbilityStageFuncs == nullptr) {
|
||||
|
||||
@@ -48,9 +48,9 @@ constexpr const char* EXCLUDE_FROM_AUTO_START = "excludeFromAutoStart";
|
||||
constexpr const char* RUN_ON_THREAD = "runOnThread";
|
||||
constexpr const char* WAIT_ON_MAIN_THREAD = "waitOnMainThread";
|
||||
constexpr const char* CONFIG_ENTRY = "configEntry";
|
||||
constexpr const char *MAIN_THREAD = "mainThread";
|
||||
constexpr const char *TASKPOOL = "taskPool";
|
||||
|
||||
constexpr const char *TASKPOOL_LOWER = "taskpool";
|
||||
|
||||
napi_value AttachAbilityStageContext(napi_env env, void *value, void *)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "AttachAbilityStageContext");
|
||||
@@ -63,7 +63,7 @@ napi_value AttachAbilityStageContext(napi_env env, void *value, void *)
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "invalid context.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value object = CreateJsAbilityStageContext(env, ptr, nullptr, nullptr);
|
||||
napi_value object = CreateJsAbilityStageContext(env, ptr);
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityStageContext", &object, 1);
|
||||
if (systemModule == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "invalid systemModule.");
|
||||
@@ -169,7 +169,7 @@ void JsAbilityStage::Init(const std::shared_ptr<Context> &context,
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "stage is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetJsAbilityStage(context);
|
||||
}
|
||||
|
||||
@@ -415,12 +415,12 @@ int32_t JsAbilityStage::RegisterStartupTaskFromProfile(std::vector<JsStartupTask
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appStartup config not exist.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
||||
if (!AnalyzeProfileInfoAndRegisterStartupTask(profileInfo)) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appStartup config not exist.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -432,19 +432,19 @@ bool JsAbilityStage::GetProfileInfoFromResourceManager(std::vector<std::string>
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "context is nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
auto resMgr = context->GetResourceManager();
|
||||
if (!resMgr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "resMgr is nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
auto hapModuleInfo = context->GetHapModuleInfo();
|
||||
if (!hapModuleInfo) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "hapModuleInfo is nullptr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
jsRuntime_.UpdateModuleNameAndAssetPath(hapModuleInfo->moduleName);
|
||||
bool isCompressed = !hapModuleInfo->hapPath.empty();
|
||||
std::string appStartup = hapModuleInfo->appStartup;
|
||||
@@ -452,7 +452,7 @@ bool JsAbilityStage::GetProfileInfoFromResourceManager(std::vector<std::string>
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appStartup invalid.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
GetResFromResMgr(appStartup, resMgr, isCompressed, profileInfo);
|
||||
if (profileInfo.empty()) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appStartup config not exist.");
|
||||
@@ -482,17 +482,17 @@ std::unique_ptr<NativeReference> JsAbilityStage::LoadJsSrcEntry(const std::strin
|
||||
bool esmodule = hapModuleInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE;
|
||||
std::string moduleName(hapModuleInfo->moduleName);
|
||||
std::string srcPath(moduleName + "/" + srcEntry);
|
||||
|
||||
|
||||
auto pos = srcPath.rfind('.');
|
||||
if (pos == std::string::npos) {
|
||||
return nullptr;
|
||||
}
|
||||
srcPath.erase(pos);
|
||||
srcPath.append(".abc");
|
||||
|
||||
|
||||
std::unique_ptr<NativeReference> jsCode(
|
||||
jsRuntime_.LoadModule(moduleName, srcPath, hapModuleInfo->hapPath, esmodule));
|
||||
|
||||
|
||||
return jsCode;
|
||||
}
|
||||
|
||||
@@ -544,15 +544,13 @@ void JsAbilityStage::SetOptionalParameters(
|
||||
|
||||
if (module.contains(RUN_ON_THREAD) && module[RUN_ON_THREAD].is_string()) {
|
||||
std::string profileName = module.at(RUN_ON_THREAD).get<std::string>();
|
||||
if (profileName == MAIN_THREAD) {
|
||||
jsStartupTask.SetCallCreateOnMainThread(true);
|
||||
} else if (profileName == TASKPOOL) {
|
||||
if (profileName == TASKPOOL || profileName == TASKPOOL_LOWER) {
|
||||
jsStartupTask.SetCallCreateOnMainThread(false);
|
||||
} else {
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "RunOnThread configuration is invalid.");
|
||||
jsStartupTask.SetCallCreateOnMainThread(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (module.contains(WAIT_ON_MAIN_THREAD) && module[WAIT_ON_MAIN_THREAD].is_boolean()) {
|
||||
jsStartupTask.SetWaitOnMainThread(module.at(WAIT_ON_MAIN_THREAD).get<bool>());
|
||||
} else {
|
||||
@@ -598,7 +596,7 @@ bool JsAbilityStage::AnalyzeProfileInfoAndRegisterStartupTask(const std::vector<
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Invalid module data.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<NativeReference> startupJsRef = LoadJsSrcEntry(module.at(SRC_ENTRY).get<std::string>());
|
||||
if (startupJsRef == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "load js appStartup tasks failed.");
|
||||
@@ -730,7 +728,7 @@ bool JsAbilityStage::GetResFromResMgr(
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "res name is empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
size_t pos = resName.rfind(PROFILE_FILE_PREFIX);
|
||||
if ((pos == std::string::npos) || (pos == resName.length() - strlen(PROFILE_FILE_PREFIX))) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "res name %{public}s is invalid.", resName.c_str());
|
||||
@@ -781,10 +779,10 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr<Context> &context)
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "context is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto env = jsRuntime_.GetNapiEnv();
|
||||
|
||||
|
||||
napi_value obj = nullptr;
|
||||
if (jsAbilityStageObj_) {
|
||||
obj = jsAbilityStageObj_->GetNapiValue();
|
||||
@@ -793,8 +791,8 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr<Context> &context)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value contextObj = CreateJsAbilityStageContext(env, context, nullptr, nullptr);
|
||||
|
||||
napi_value contextObj = CreateJsAbilityStageContext(env, context);
|
||||
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityStageContext", &contextObj, 1);
|
||||
if (shellContextRef_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Failed to get LoadSystemModuleByEngine");
|
||||
@@ -809,7 +807,7 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr<Context> &context)
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachAbilityStageContext, workContext, nullptr);
|
||||
context->Bind(jsRuntime_, shellContextRef_.get());
|
||||
|
||||
|
||||
if (obj != nullptr) {
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ void JsAbilityStageContext::ConfigurationUpdated(napi_env env, std::shared_ptr<N
|
||||
napi_call_function(env, object, method, 1, argv, nullptr);
|
||||
}
|
||||
|
||||
napi_value CreateJsAbilityStageContext(napi_env env,
|
||||
std::shared_ptr<AbilityRuntime::Context> context, DetachCallback detach, NapiAttachCallback attach)
|
||||
napi_value CreateJsAbilityStageContext(napi_env env, std::shared_ptr<AbilityRuntime::Context> context)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called.");
|
||||
napi_value objValue = CreateJsBaseContext(env, context);
|
||||
|
||||
@@ -149,6 +149,33 @@ void JsAbilityLifecycleCallback::OnAbilityContinue(const std::shared_ptr<NativeR
|
||||
CallJsMethod("onAbilityContinue", ability);
|
||||
}
|
||||
|
||||
void JsAbilityLifecycleCallback::OnAbilityWillContinue(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
CallJsMethod("onAbilityWillContinue", ability);
|
||||
}
|
||||
|
||||
void JsAbilityLifecycleCallback::OnWindowStageWillRestore(const std::shared_ptr<NativeReference> &ability,
|
||||
const std::shared_ptr<NativeReference> &windowStage)
|
||||
{
|
||||
CallWindowStageJsMethod("onWindowStageWillRestore", ability, windowStage);
|
||||
}
|
||||
|
||||
void JsAbilityLifecycleCallback::OnWindowStageRestore(const std::shared_ptr<NativeReference> &ability,
|
||||
const std::shared_ptr<NativeReference> &windowStage)
|
||||
{
|
||||
CallWindowStageJsMethod("onWindowStageRestore", ability, windowStage);
|
||||
}
|
||||
|
||||
void JsAbilityLifecycleCallback::OnAbilityWillSaveState(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
CallJsMethod("onAbilityWillSaveState", ability);
|
||||
}
|
||||
|
||||
void JsAbilityLifecycleCallback::OnAbilitySaveState(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
CallJsMethod("onAbilitySaveState", ability);
|
||||
}
|
||||
|
||||
int32_t JsAbilityLifecycleCallback::Register(napi_value jsCallback, bool isSync)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "enter");
|
||||
|
||||
@@ -235,6 +235,88 @@ void ApplicationContext::DispatchOnAbilityContinue(const std::shared_ptr<NativeR
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchOnAbilityWillContinue(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillContinue.");
|
||||
if (ability == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAbilityWillContinue(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchOnWindowStageWillRestore(const std::shared_ptr<NativeReference> &ability,
|
||||
const std::shared_ptr<NativeReference> &windowStage)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageWillRestore.");
|
||||
if (ability == nullptr || windowStage == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability or windowStage is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnWindowStageWillRestore(ability, windowStage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchOnWindowStageRestore(const std::shared_ptr<NativeReference> &ability,
|
||||
const std::shared_ptr<NativeReference> &windowStage)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageRestore.");
|
||||
if (ability == nullptr || windowStage == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability or windowStage is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnWindowStageRestore(ability, windowStage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchOnAbilityWillSaveState(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillSaveState.");
|
||||
if (ability == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAbilityWillSaveState(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchOnAbilitySaveState(const std::shared_ptr<NativeReference> &ability)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilitySaveState.");
|
||||
if (ability == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock(callbackLock_);
|
||||
for (auto callback : callbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAbilitySaveState(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationContext::DispatchConfigurationUpdated(const AppExecFwk::Configuration &config)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(envCallbacksLock_);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_object_proxy.h"
|
||||
#include "ipc_singleton.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#ifdef SUPPORT_SCREEN
|
||||
@@ -1014,6 +1015,9 @@ void ContextImpl::SetToken(const sptr<IRemoteObject> &token)
|
||||
return;
|
||||
}
|
||||
token_ = token;
|
||||
if (GetBundleName() == "com.ohos.callui") {
|
||||
PrintTokenInfo();
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> ContextImpl::GetToken()
|
||||
@@ -1262,5 +1266,23 @@ int32_t ContextImpl::SetSupportedProcessCacheSelf(bool isSupport)
|
||||
}
|
||||
return appMgrClient->SetSupportedProcessCacheSelf(isSupport);
|
||||
}
|
||||
|
||||
void ContextImpl::PrintTokenInfo() const
|
||||
{
|
||||
if (token_ == nullptr) {
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null");
|
||||
return;
|
||||
}
|
||||
if (!token_->IsProxyObject()) {
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy");
|
||||
return;
|
||||
}
|
||||
IPCObjectProxy *tokenProxyObject = reinterpret_cast<IPCObjectProxy *>(token_.GetRefPtr());
|
||||
if (tokenProxyObject != nullptr) {
|
||||
std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor());
|
||||
TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s",
|
||||
tokenProxyObject->GetHandle(), remoteDescriptor.c_str());
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -435,7 +435,7 @@ napi_value JsApplicationContextUtils::OnGetCloudFileDir(napi_env env, NapiCallba
|
||||
{
|
||||
auto applicationContext = applicationContext_.lock();
|
||||
if (!applicationContext) {
|
||||
HILOG_WARN("applicationContext is already released");
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "applicationContext is already released");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = applicationContext->GetCloudFileDir();
|
||||
@@ -715,7 +715,7 @@ napi_value JsApplicationContextUtils::PreloadUIExtensionAbility(napi_env env, na
|
||||
|
||||
napi_value JsApplicationContextUtils::OnPreloadUIExtensionAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called");
|
||||
if (info.argc < ARGC_ONE) {
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "Params error!");
|
||||
ThrowTooFewParametersError(env);
|
||||
@@ -1426,6 +1426,7 @@ napi_value JsApplicationContextUtils::OnGetApplicationContext(napi_env env, Napi
|
||||
[](napi_env, void *data, void *) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called");
|
||||
delete static_cast<std::weak_ptr<ApplicationContext> *>(data);
|
||||
data = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ napi_value JsBaseContext::OnGetCloudFileDir(napi_env env, NapiCallbackInfo& info
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
TAG_LOGW(AAFwkTag::APPKIT, "context is already released");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetCloudFileDir();
|
||||
@@ -637,6 +637,7 @@ napi_value JsBaseContext::CreateJSApplicationContext(napi_env env,
|
||||
[](napi_env, void *data, void *) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called");
|
||||
delete static_cast<std::weak_ptr<ApplicationContext> *>(data);
|
||||
data = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
napi_ref ref = nullptr;
|
||||
@@ -722,6 +723,7 @@ napi_value AttachApplicationContext(napi_env env, void* value, void* hint)
|
||||
[](napi_env, void *data, void *) {
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called");
|
||||
delete static_cast<std::weak_ptr<ApplicationContext> *>(data);
|
||||
data = nullptr;
|
||||
},
|
||||
nullptr, nullptr);
|
||||
return contextObj;
|
||||
|
||||
@@ -132,6 +132,9 @@ ErrCode ServiceExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "accountId: %{public}d, ability: %{public}s, caller: %{public}s",
|
||||
accountId, want.GetElement().GetURI().c_str(), callerName.c_str());
|
||||
(const_cast<Want &>(want)).SetParam(START_ABILITY_TYPE, true);
|
||||
if (callerName == "com.ohos.callui.ServiceAbility") {
|
||||
PrintTokenInfo();
|
||||
}
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(
|
||||
want, token_, ILLEGAL_REQUEST_CODE, accountId);
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err);
|
||||
@@ -232,5 +235,18 @@ AppExecFwk::AbilityType ServiceExtensionContext::GetAbilityInfoType() const
|
||||
|
||||
return info->type;
|
||||
}
|
||||
|
||||
ErrCode ServiceExtensionContext::PreStartMission(const std::string& bundleName, const std::string& moduleName,
|
||||
const std::string& abilityName, const std::string& startTime)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "Called.");
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->PreStartMission(
|
||||
bundleName, moduleName, abilityName, startTime);
|
||||
if (err != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "ServiceExtensionContext::PreStartMission is failed %{public}d", err);
|
||||
}
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "End.");
|
||||
return err;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "dump_runtime_helper.h"
|
||||
|
||||
#include "app_mgr_client.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "singleton.h"
|
||||
#include "dfx_jsnapi.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
DumpRuntimeHelper::DumpRuntimeHelper(const std::shared_ptr<OHOSApplication> &application)
|
||||
: application_(application)
|
||||
{}
|
||||
|
||||
void DumpRuntimeHelper::SetAppFreezeFilterCallback()
|
||||
{
|
||||
if (application_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback OHOSApplication is nullptr");
|
||||
return;
|
||||
}
|
||||
auto& runtime = application_->GetRuntime();
|
||||
if (runtime == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback GetRuntime is nullptr");
|
||||
return;
|
||||
}
|
||||
auto appfreezeFilterCallback = [] (const int32_t pid) -> bool {
|
||||
auto client = DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance();
|
||||
if (client == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback client is nullptr");
|
||||
return false;
|
||||
}
|
||||
return client->SetAppFreezeFilter(pid);
|
||||
};
|
||||
auto vm = (static_cast<AbilityRuntime::JsRuntime&>(*runtime)).GetEcmaVm();
|
||||
panda::DFXJSNApi::SetAppFreezeFilterCallback(vm, appfreezeFilterCallback);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "ability_thread.h"
|
||||
#include "ability_util.h"
|
||||
#include "app_loader.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "app_recovery.h"
|
||||
#include "app_utils.h"
|
||||
#include "appfreeze_inner.h"
|
||||
@@ -49,6 +48,7 @@
|
||||
#include "context_impl.h"
|
||||
#include "dump_ffrt_helper.h"
|
||||
#include "dump_ipc_helper.h"
|
||||
#include "dump_runtime_helper.h"
|
||||
#include "exit_reason.h"
|
||||
#include "extension_ability_info.h"
|
||||
#include "extension_module_loader.h"
|
||||
@@ -58,6 +58,7 @@
|
||||
#include "file_path_utils.h"
|
||||
#include "freeze_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "resource_config_helper.h"
|
||||
#ifdef SUPPORT_SCREEN
|
||||
#include "locale_config.h"
|
||||
@@ -1485,6 +1486,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
#ifdef CJ_FRONTEND
|
||||
if (isCJApp) {
|
||||
AbilityRuntime::CJRuntime::SetAppLibPath(appLibPaths);
|
||||
if (appInfo.asanEnabled) {
|
||||
AbilityRuntime::CJRuntime::SetAsanVersion();
|
||||
} else if (appInfo.tsanEnabled) {
|
||||
AbilityRuntime::CJRuntime::SetTsanVersion();
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, isSystemApp);
|
||||
@@ -1623,7 +1629,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
TAG_LOGI(AAFwkTag::APPKIT, "hisysevent write result=%{public}d, send event [FRAMEWORK,PROCESS_KILL],"
|
||||
" pid=%{public}d, processName=%{public}s, msg=%{public}s", result, pid, processName.c_str(),
|
||||
KILL_REASON);
|
||||
|
||||
|
||||
if (ApplicationDataManager::GetInstance().NotifyUnhandledException(summary) &&
|
||||
ApplicationDataManager::GetInstance().NotifyExceptionObject(appExecErrorObj)) {
|
||||
return;
|
||||
@@ -1683,6 +1689,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
|
||||
|
||||
IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc();
|
||||
jsEngine.NotifyIdleStatusControl(cb);
|
||||
|
||||
auto helper = std::make_shared<DumpRuntimeHelper>(application_);
|
||||
helper->SetAppFreezeFilterCallback();
|
||||
}
|
||||
#ifdef CJ_FRONTEND
|
||||
}
|
||||
@@ -2534,7 +2543,7 @@ void MainThread::HandleDumpHeap(bool isPrivate)
|
||||
};
|
||||
|
||||
ffrt::submit(taskFork, {}, {}, ffrt::task_attr().qos(ffrt::qos_user_initiated));
|
||||
runtime->DumpCpuProfile(isPrivate);
|
||||
runtime->DumpCpuProfile();
|
||||
}
|
||||
|
||||
void MainThread::DestroyHeapProfiler()
|
||||
|
||||
@@ -170,6 +170,7 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread)
|
||||
faultData.notifyApp = false;
|
||||
faultData.waitSaveState = false;
|
||||
faultData.forceExit = false;
|
||||
faultData.eventId = it->eventId;
|
||||
bool isExit = IsExitApp(it->errorObject.name);
|
||||
if (isExit) {
|
||||
faultData.forceExit = true;
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ napi_value CreateJsInsightIntentContext(napi_env env, const std::shared_ptr<Insi
|
||||
return contextObj;
|
||||
}
|
||||
|
||||
bool CheckStartAbilityParam(napi_env env, NapiCallbackInfo& info, AAFwk::Want want)
|
||||
bool CheckStartAbilityParam(napi_env env, NapiCallbackInfo& info, AAFwk::Want& want)
|
||||
{
|
||||
if (info.argc == 0) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "not enough args");
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include "cj_environment.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hdc_register.h"
|
||||
#include "connect_server_manager.h"
|
||||
|
||||
@@ -51,7 +51,7 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths)
|
||||
std::string appPath = "";
|
||||
for (const auto& kv : appLibPaths) {
|
||||
for (const auto& libPath : kv.second) {
|
||||
HILOG_INFO("SetCJAppLibPath: %{public}s.", libPath.c_str());
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "SetCJAppLibPath: %{public}s.", libPath.c_str());
|
||||
CJRuntime::appLibPaths_.emplace_back(libPath);
|
||||
appPath += appPath.empty() ? libPath : ":" + libPath;
|
||||
}
|
||||
@@ -65,19 +65,19 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths)
|
||||
bool CJRuntime::Initialize(const Options& options)
|
||||
{
|
||||
if (options.lang != GetLanguage()) {
|
||||
HILOG_ERROR("CJRuntime Initialize fail, language mismatch");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJRuntime Initialize fail, language mismatch");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::CJEnvironment::GetInstance()->StartRuntime()) {
|
||||
HILOG_ERROR("start cj runtime failed");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "start cj runtime failed");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::CJEnvironment::GetInstance()->StartUIScheduler()) {
|
||||
HILOG_ERROR("start cj ui context failed");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "start cj ui context failed");
|
||||
return false;
|
||||
}
|
||||
if (!LoadCJAppLibrary(CJRuntime::appLibPaths_)) {
|
||||
HILOG_ERROR("CJRuntime::Initialize fail, load app library fail.");
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "CJRuntime::Initialize fail, load app library fail.");
|
||||
return false;
|
||||
}
|
||||
bundleName_ = options.bundleName;
|
||||
@@ -87,7 +87,7 @@ bool CJRuntime::Initialize(const Options& options)
|
||||
|
||||
void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo)
|
||||
{
|
||||
HILOG_INFO("RegisterUncaughtExceptionHandler not support yet");
|
||||
OHOS::CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(uncaughtExceptionInfo);
|
||||
}
|
||||
|
||||
bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
@@ -102,7 +102,7 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
handle = OHOS::CJEnvironment::GetInstance()->LoadCJLibrary(itor.path().c_str());
|
||||
if (handle == nullptr) {
|
||||
char* errMsg = dlerror();
|
||||
HILOG_ERROR(
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR,
|
||||
"Failed to load %{public}s : reason: %{public}s.", itor.path().c_str(), errMsg ? errMsg : "null");
|
||||
return false;
|
||||
}
|
||||
@@ -112,10 +112,25 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CJRuntime::SetAsanVersion()
|
||||
{
|
||||
CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::ASAN);
|
||||
}
|
||||
|
||||
void CJRuntime::SetTsanVersion()
|
||||
{
|
||||
CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::TSAN);
|
||||
}
|
||||
|
||||
void CJRuntime::SetHWAsanVersion()
|
||||
{
|
||||
CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::HWASAN);
|
||||
}
|
||||
|
||||
void CJRuntime::StartDebugMode(const DebugOption dOption)
|
||||
{
|
||||
if (debugModel_) {
|
||||
HILOG_INFO("Already in debug mode");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "Already in debug mode");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,12 +139,13 @@ void CJRuntime::StartDebugMode(const DebugOption dOption)
|
||||
const std::string bundleName = bundleName_;
|
||||
std::string inputProcessName = bundleName_ != dOption.processName ? dOption.processName : "";
|
||||
|
||||
HILOG_INFO("StartDebugMode %{public}s", bundleName_.c_str());
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "StartDebugMode %{public}s", bundleName_.c_str());
|
||||
|
||||
HdcRegister::Get().StartHdcRegister(bundleName_, inputProcessName, isDebugApp,
|
||||
[bundleName, isStartWithDebug, isDebugApp](int socketFd, std::string option) {
|
||||
HILOG_INFO("HdcRegister callback is call, socket fd is %{public}d, option is %{public}s.",
|
||||
socketFd, option.c_str());
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR,
|
||||
"HdcRegister callback is call, socket fd is %{public}d, option is %{public}s.",
|
||||
socketFd, option.c_str());
|
||||
if (option.find(DEBUGGER) == std::string::npos) {
|
||||
if (!isDebugApp) {
|
||||
ConnectServerManager::Get().StopConnectServer(false);
|
||||
@@ -137,7 +153,7 @@ void CJRuntime::StartDebugMode(const DebugOption dOption)
|
||||
ConnectServerManager::Get().SendDebuggerInfo(isStartWithDebug, isDebugApp);
|
||||
ConnectServerManager::Get().StartConnectServer(bundleName, socketFd, false);
|
||||
} else {
|
||||
HILOG_ERROR("debugger service unexpected option: %{public}s", option.c_str());
|
||||
TAG_LOGE(AAFwkTag::DELEGATOR, "debugger service unexpected option: %{public}s", option.c_str());
|
||||
}
|
||||
});
|
||||
if (isDebugApp) {
|
||||
@@ -155,5 +171,5 @@ bool CJRuntime::StartDebugger()
|
||||
|
||||
void CJRuntime::UnLoadCJAppLibrary()
|
||||
{
|
||||
HILOG_INFO("UnLoadCJAppLibrary not support yet");
|
||||
TAG_LOGI(AAFwkTag::DELEGATOR, "UnLoadCJAppLibrary not support yet");
|
||||
}
|
||||
|
||||
@@ -173,17 +173,13 @@ void ConnectServerManager::SendDebuggerInfo(bool needBreakPoint, bool isDebugApp
|
||||
|
||||
panda::EcmaVM* vm = reinterpret_cast<panda::EcmaVM*>(g_debuggerInfo[tid].first);
|
||||
std::lock_guard<std::mutex> lock(g_debuggerMutex);
|
||||
const auto &debuggerPoskTask = g_debuggerInfo[tid].second;
|
||||
if (!debuggerPoskTask) {
|
||||
const auto &debuggerPostTask = g_debuggerInfo[tid].second;
|
||||
if (!debuggerPostTask) {
|
||||
continue;
|
||||
}
|
||||
ConnectServerManager::Get().SendInstanceMessage(tid, instanceId, instanceName);
|
||||
auto storeDebugInfoTask = [needBreakPoint, isDebugApp, instanceId, vm, debuggerPoskTask, instanceName]() {
|
||||
panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, isDebugApp ? needBreakPoint : false};
|
||||
panda::JSNApi::StoreDebugInfo(getproctid(), vm, debugOption, debuggerPoskTask, isDebugApp);
|
||||
};
|
||||
|
||||
debuggerPoskTask(storeDebugInfoTask);
|
||||
panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, isDebugApp ? needBreakPoint : false};
|
||||
panda::JSNApi::StoreDebugInfo(tid, vm, debugOption, debuggerPostTask, isDebugApp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,33 +200,15 @@ void ConnectServerManager::SetConnectedCallback()
|
||||
});
|
||||
}
|
||||
|
||||
bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, const std::string& instanceName)
|
||||
void ConnectServerManager::SetSwitchCallback(int32_t instanceId)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage Add instance to connect server");
|
||||
LoadConnectServerDebuggerSo();
|
||||
|
||||
auto setSwitchCallBack = reinterpret_cast<SetSwitchCallBack>(
|
||||
dlsym(handlerConnectServerSo_, "SetSwitchCallBack"));
|
||||
dlsym(handlerConnectServerSo_, "SetSwitchCallBack"));
|
||||
if (setSwitchCallBack == nullptr) {
|
||||
TAG_LOGI(
|
||||
AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'setSwitchCallBack'");
|
||||
return false;
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance failed to find symbol 'setSwitchCallBack'");
|
||||
return;
|
||||
}
|
||||
|
||||
auto storeMessage = reinterpret_cast<StoreMessage>(dlsym(handlerConnectServerSo_, "StoreMessage"));
|
||||
if (storeMessage == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'StoreMessage'");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto setProfilerCallback = reinterpret_cast<SetProfilerCallback>(
|
||||
dlsym(handlerConnectServerSo_, "SetProfilerCallback"));
|
||||
if (setProfilerCallback == nullptr) {
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME,
|
||||
"ConnectServerManager::SendInstanceMessage failed to find symbol 'setProfilerCallback'");
|
||||
return false;
|
||||
}
|
||||
|
||||
setSwitchCallBack(
|
||||
[this](bool status) {
|
||||
if (setStatus_ != nullptr) {
|
||||
@@ -246,7 +224,18 @@ bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId,
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::createLayoutInfo_ is nullptr");
|
||||
}
|
||||
}, instanceId);
|
||||
|
||||
}
|
||||
|
||||
void ConnectServerManager::SetProfilerCallBack()
|
||||
{
|
||||
LoadConnectServerDebuggerSo();
|
||||
auto setProfilerCallback = reinterpret_cast<SetProfilerCallback>(
|
||||
dlsym(handlerConnectServerSo_, "SetProfilerCallback"));
|
||||
if (setProfilerCallback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME,
|
||||
"ConnectServerManager::AddInstance failed to find symbol 'setProfilerCallback'");
|
||||
return;
|
||||
}
|
||||
setProfilerCallback([this](bool status) {
|
||||
if (setArkUIStateProfilerStatus_ != nullptr) {
|
||||
setArkUIStateProfilerStatus_(status);
|
||||
@@ -254,14 +243,25 @@ bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId,
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setArkUIStateProfilerStatus_ is nullptr");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, const std::string& instanceName)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage Add instance to connect server");
|
||||
ConnectServerManager::Get().SetSwitchCallback(instanceId);
|
||||
ConnectServerManager::Get().SetProfilerCallBack();
|
||||
std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid);
|
||||
LoadConnectServerDebuggerSo();
|
||||
auto storeMessage = reinterpret_cast<StoreMessage>(dlsym(handlerConnectServerSo_, "StoreMessage"));
|
||||
if (storeMessage == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'StoreMessage'");
|
||||
return false;
|
||||
}
|
||||
storeMessage(instanceId, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConnectServerManager::AddInstance(int32_t tid, int32_t instanceId, const std::string& instanceName)
|
||||
{
|
||||
{
|
||||
@@ -280,46 +280,10 @@ bool ConnectServerManager::AddInstance(int32_t tid, int32_t instanceId, const st
|
||||
}
|
||||
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance Add instance to connect server");
|
||||
|
||||
ConnectServerManager::Get().SetSwitchCallback(instanceId);
|
||||
ConnectServerManager::Get().SetProfilerCallBack();
|
||||
LoadConnectServerDebuggerSo();
|
||||
|
||||
auto setSwitchCallBack = reinterpret_cast<SetSwitchCallBack>(
|
||||
dlsym(handlerConnectServerSo_, "SetSwitchCallBack"));
|
||||
if (setSwitchCallBack == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance failed to find symbol 'setSwitchCallBack'");
|
||||
return false;
|
||||
}
|
||||
setSwitchCallBack(
|
||||
[this](bool status) {
|
||||
if (setStatus_ != nullptr) {
|
||||
setStatus_(status);
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setStatus_ is nullptr");
|
||||
}
|
||||
},
|
||||
[this](int32_t containerId) {
|
||||
if (createLayoutInfo_ != nullptr) {
|
||||
createLayoutInfo_(containerId);
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::createLayoutInfo_ is nullptr");
|
||||
}
|
||||
}, instanceId);
|
||||
|
||||
auto setProfilerCallback = reinterpret_cast<SetProfilerCallback>(
|
||||
dlsym(handlerConnectServerSo_, "SetProfilerCallback"));
|
||||
if (setProfilerCallback == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME,
|
||||
"ConnectServerManager::AddInstance failed to find symbol 'setProfilerCallback'");
|
||||
return false;
|
||||
}
|
||||
|
||||
setProfilerCallback([this](bool status) {
|
||||
if (setArkUIStateProfilerStatus_ != nullptr) {
|
||||
setArkUIStateProfilerStatus_(status);
|
||||
} else {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setArkUIStateProfilerStatus_ is nullptr");
|
||||
}
|
||||
});
|
||||
|
||||
// Get the message including information of new instance, which will be send to IDE.
|
||||
std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid);
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
void SendDebuggerInfo(bool needBreakPoint, bool isDebugApp);
|
||||
void LoadConnectServerDebuggerSo();
|
||||
DebuggerPostTask GetDebuggerPostTask(int32_t tid);
|
||||
void SetSwitchCallback(int32_t instanceId);
|
||||
void SetProfilerCallBack();
|
||||
|
||||
private:
|
||||
ConnectServerManager() = default;
|
||||
|
||||
@@ -118,6 +118,13 @@ napi_value CreateJsConfiguration(napi_env env, const AppExecFwk::Configuration&
|
||||
std::string fontWeightScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE);
|
||||
napi_set_named_property(env, object, "fontWeightScale",
|
||||
CreateJsValue(env, fontWeightScale == "" ? 1.0 : std::stod(fontWeightScale)));
|
||||
|
||||
napi_set_named_property(env, object, "mcc", CreateJsValue(env,
|
||||
configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC)));
|
||||
|
||||
napi_set_named_property(env, object, "mnc", CreateJsValue(env,
|
||||
configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC)));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,9 +283,7 @@ void JsRuntime::StartDebugMode(const DebugOption dOption)
|
||||
if (isDebugApp) {
|
||||
weak->StopDebugger(option);
|
||||
}
|
||||
int32_t tid = weak->ParseHdcRegisterOption(option);
|
||||
const auto &debuggerPostTask = ConnectServerManager::Get().GetDebuggerPostTask(tid);
|
||||
weak->StartDebugger(option, socketFd, isDebugApp, debuggerPostTask);
|
||||
weak->StartDebugger(option, socketFd, isDebugApp);
|
||||
}
|
||||
});
|
||||
if (isDebugApp) {
|
||||
@@ -416,9 +414,7 @@ void JsRuntime::StartProfiler(const DebugOption dOption)
|
||||
if (isDebugApp) {
|
||||
weak->StopDebugger(option);
|
||||
}
|
||||
int32_t tid = weak->ParseHdcRegisterOption(option);
|
||||
const auto &debuggerPostTask = ConnectServerManager::Get().GetDebuggerPostTask(tid);
|
||||
weak->StartDebugger(option, socketFd, isDebugApp, debuggerPostTask);
|
||||
weak->StartDebugger(option, socketFd, isDebugApp);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1202,11 +1198,11 @@ void JsRuntime::RemoveTask(const std::string& name)
|
||||
jsEnv_->RemoveTask(name);
|
||||
}
|
||||
|
||||
void JsRuntime::DumpCpuProfile(bool isPrivate)
|
||||
void JsRuntime::DumpCpuProfile()
|
||||
{
|
||||
auto nativeEngine = GetNativeEnginePointer();
|
||||
CHECK_POINTER(nativeEngine);
|
||||
nativeEngine->DumpCpuProfile(true, DumpFormat::JSON, isPrivate, false);
|
||||
nativeEngine->DumpCpuProfile();
|
||||
}
|
||||
|
||||
void JsRuntime::DumpHeapSnapshot(bool isPrivate)
|
||||
@@ -1220,7 +1216,13 @@ void JsRuntime::DumpHeapSnapshot(uint32_t tid, bool isFullGC)
|
||||
{
|
||||
auto vm = GetEcmaVm();
|
||||
CHECK_POINTER(vm);
|
||||
DFXJSNApi::DumpHeapSnapshot(vm, 0, true, false, false, isFullGC, tid);
|
||||
panda::ecmascript::DumpSnapShotOption dumpOption;
|
||||
dumpOption.dumpFormat = panda::ecmascript::DumpFormat::JSON;
|
||||
dumpOption.isVmMode = true;
|
||||
dumpOption.isPrivate = false;
|
||||
dumpOption.captureNumericValue = false;
|
||||
dumpOption.isFullGC = isFullGC;
|
||||
DFXJSNApi::DumpHeapSnapshot(vm, dumpOption, tid);
|
||||
}
|
||||
|
||||
void JsRuntime::ForceFullGC(uint32_t tid)
|
||||
|
||||
@@ -452,5 +452,23 @@ std::unique_ptr<NapiAsyncTask> CreateAsyncTaskWithLastParam(napi_env env, napi_v
|
||||
return CreateAsyncTaskWithLastParam(env, lastParam, std::unique_ptr<NapiAsyncTask::ExecuteCallback>(),
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>(), result);
|
||||
}
|
||||
|
||||
std::unique_ptr<NapiAsyncTask> CreateEmptyAsyncTask(napi_env env, napi_value lastParam, napi_value* result)
|
||||
{
|
||||
napi_valuetype type = napi_undefined;
|
||||
napi_typeof(env, lastParam, &type);
|
||||
if (lastParam == nullptr || type != napi_function) {
|
||||
napi_deferred nativeDeferred = nullptr;
|
||||
napi_create_promise(env, &nativeDeferred, result);
|
||||
return std::make_unique<NapiAsyncTask>(nativeDeferred, std::unique_ptr<NapiAsyncTask::ExecuteCallback>(),
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>());
|
||||
} else {
|
||||
napi_get_undefined(env, result);
|
||||
napi_ref callbackRef = nullptr;
|
||||
napi_create_reference(env, lastParam, 1, &callbackRef);
|
||||
return std::make_unique<NapiAsyncTask>(callbackRef, std::unique_ptr<NapiAsyncTask::ExecuteCallback>(),
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>());
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "bundle_info.h"
|
||||
#include "bundle_mgr_helper.h"
|
||||
#include "bundle_mgr_proxy.h"
|
||||
#include "connect_server_manager.h"
|
||||
#include "commonlibrary/c_utils/base/include/refbase.h"
|
||||
#include "console.h"
|
||||
#ifdef SUPPORT_SCREEN
|
||||
#include "core/common/container_scope.h"
|
||||
#include "declarative_module_preloader.h"
|
||||
@@ -32,18 +34,16 @@
|
||||
|
||||
#include "extractor.h"
|
||||
#include "file_mapper.h"
|
||||
#include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_base/include/bundle_info.h"
|
||||
#include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h"
|
||||
#include "foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/iservice_registry.h"
|
||||
#include "foundation/communication/ipc/interfaces/innerkits/ipc_core/include/iremote_object.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "native_engine/impl/ark/ark_native_engine.h"
|
||||
#include "commonlibrary/ets_utils/js_sys_module/console/console.h"
|
||||
#include "refbase.h"
|
||||
#include "singleton.h"
|
||||
#include "syscap_ts.h"
|
||||
#include "system_ability_definition.h"
|
||||
#ifdef SUPPORT_SCREEN
|
||||
using OHOS::Ace::ContainerScope;
|
||||
#endif
|
||||
@@ -100,7 +100,7 @@ void InitWorkerFunc(NativeEngine* nativeEngine)
|
||||
}
|
||||
|
||||
if (g_debugMode) {
|
||||
auto instanceId = getproctid();
|
||||
auto instanceId = arkNativeEngine->GetThreadIdOrTaskId();
|
||||
std::string instanceName = "workerThread_" + std::to_string(instanceId);
|
||||
bool needBreakPoint = ConnectServerManager::Get().AddInstance(instanceId, instanceId, instanceName);
|
||||
if (g_nativeStart) {
|
||||
@@ -128,9 +128,9 @@ void OffWorkerFunc(NativeEngine* nativeEngine)
|
||||
}
|
||||
|
||||
if (g_debugMode) {
|
||||
auto instanceId = getproctid();
|
||||
ConnectServerManager::Get().RemoveInstance(instanceId);
|
||||
auto arkNativeEngine = static_cast<ArkNativeEngine*>(nativeEngine);
|
||||
auto instanceId = arkNativeEngine->GetThreadIdOrTaskId();
|
||||
ConnectServerManager::Get().RemoveInstance(instanceId);
|
||||
auto vm = const_cast<EcmaVM*>(arkNativeEngine->GetEcmaVm());
|
||||
panda::JSNApi::StopDebugger(vm);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ ohos_shared_library("ability_simulator_inner") {
|
||||
"${windowmanager_path}/interfaces/innerkits/wm",
|
||||
"${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi",
|
||||
"include/bundle_parser",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -113,6 +112,7 @@ ohos_shared_library("ability_simulator_inner") {
|
||||
"ets_utils:console",
|
||||
"ets_utils:timer",
|
||||
"hilog:libhilog",
|
||||
"json:nlohmann_json_static",
|
||||
"jsoncpp:jsoncpp_static",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@@ -227,7 +227,7 @@ napi_value JsApplicationContextUtils::OnGetCloudFileDir(napi_env env, NapiCallba
|
||||
{
|
||||
auto context = context_.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is already released");
|
||||
TAG_LOGW(AAFwkTag::ABILITY_SIM, "context is already released");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
std::string path = context->GetCloudFileDir();
|
||||
|
||||
@@ -319,6 +319,24 @@ std::unique_ptr<NapiAsyncTask> CreateAsyncTaskWithLastParam(napi_env env, napi_v
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>(), result);
|
||||
}
|
||||
|
||||
std::unique_ptr<NapiAsyncTask> CreateEmptyAsyncTask(napi_env env, napi_value lastParam, napi_value* result)
|
||||
{
|
||||
napi_valuetype type = napi_undefined;
|
||||
napi_typeof(env, lastParam, &type);
|
||||
if (lastParam == nullptr || type != napi_function) {
|
||||
napi_deferred nativeDeferred = nullptr;
|
||||
napi_create_promise(env, &nativeDeferred, result);
|
||||
return std::make_unique<NapiAsyncTask>(nativeDeferred, std::unique_ptr<NapiAsyncTask::ExecuteCallback>(),
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>());
|
||||
} else {
|
||||
napi_get_undefined(env, result);
|
||||
napi_ref callbackRef = nullptr;
|
||||
napi_create_reference(env, lastParam, 1, &callbackRef);
|
||||
return std::make_unique<NapiAsyncTask>(callbackRef, std::unique_ptr<NapiAsyncTask::ExecuteCallback>(),
|
||||
std::unique_ptr<NapiAsyncTask::CompleteCallback>());
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<NativeReference> JsRuntime::LoadSystemModuleByEngine(napi_env env,
|
||||
const std::string &moduleName, napi_value const *argv, size_t argc)
|
||||
{
|
||||
|
||||
@@ -27,8 +27,11 @@ config("ability_manager_public_config") {
|
||||
"include/",
|
||||
"include/status_bar_delegate",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed",
|
||||
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
|
||||
@@ -57,112 +60,6 @@ config("ability_manager_public_config") {
|
||||
}
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_manager_base") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include",
|
||||
"${ability_runtime_innerkits_path}/ability_manager/include/status_bar_delegate",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/native",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
if (ability_command_for_test) {
|
||||
defines += [ "ABILITY_COMMAND_FOR_TEST" ]
|
||||
}
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
defines += [
|
||||
"SUPPORT_GRAPHICS",
|
||||
"SUPPORT_SCREEN",
|
||||
]
|
||||
}
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_operation.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_operation_builder.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_result.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/dialog_session_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/extension_running_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/mission_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/open_link/open_link_options.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/remote_on_listener_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/sender_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_ability_connect_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_host_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/want_sender_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/wants_info.cpp",
|
||||
"src/status_bar_delegate/status_bar_delegate_proxy.cpp",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
sources += [
|
||||
"src/ability_first_frame_state_data.cpp",
|
||||
"src/ability_first_frame_state_observer_proxy.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
":ability_start_options",
|
||||
":ability_start_setting",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:libappexecfwk_common",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
public_external_deps = [
|
||||
"ability_base:configuration",
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"relational_store:native_dataability",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
|
||||
innerapi_tags = [
|
||||
"platformsdk",
|
||||
"sasdk",
|
||||
]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_manager") {
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/data_ability_operation.cpp",
|
||||
@@ -175,12 +72,14 @@ ohos_shared_library("ability_manager") {
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/dialog_session_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/extension_running_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp",
|
||||
@@ -188,6 +87,7 @@ ohos_shared_library("ability_manager") {
|
||||
"${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/mission_listener_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/open_link/open_link_options.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/remote_on_listener_proxy.cpp",
|
||||
@@ -196,6 +96,7 @@ ohos_shared_library("ability_manager") {
|
||||
"${ability_runtime_services_path}/abilitymgr/src/system_ability_token_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_ability_connect_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_host_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/ui_extension_session_info.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/user_callback_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/want_receiver_stub.cpp",
|
||||
@@ -203,6 +104,7 @@ ohos_shared_library("ability_manager") {
|
||||
"${ability_runtime_services_path}/abilitymgr/src/want_sender_proxy.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/want_sender_stub.cpp",
|
||||
"${ability_runtime_services_path}/abilitymgr/src/wants_info.cpp",
|
||||
"src/status_bar_delegate/status_bar_delegate_proxy.cpp",
|
||||
"src/status_bar_delegate/status_bar_delegate_stub.cpp",
|
||||
"src/window_manager_service_handler_proxy.cpp",
|
||||
"src/window_manager_service_handler_stub.cpp",
|
||||
@@ -211,6 +113,7 @@ ohos_shared_library("ability_manager") {
|
||||
if (ability_runtime_graphics) {
|
||||
sources += [
|
||||
"src/ability_first_frame_state_data.cpp",
|
||||
"src/ability_first_frame_state_observer_proxy.cpp",
|
||||
"src/ability_first_frame_state_observer_stub.cpp",
|
||||
]
|
||||
}
|
||||
@@ -233,7 +136,6 @@ ohos_shared_library("ability_manager") {
|
||||
external_deps = [
|
||||
"ability_base:base",
|
||||
"ability_base:session_info",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:libappexecfwk_common",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
@@ -243,9 +145,11 @@ ohos_shared_library("ability_manager") {
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"relational_store:native_dataability",
|
||||
"relational_store:native_rdb",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
if (host_cpu != "arm64") {
|
||||
external_deps += [ "relational_store:native_rdb" ]
|
||||
}
|
||||
|
||||
public_external_deps = [
|
||||
"ability_base:configuration",
|
||||
@@ -264,7 +168,6 @@ ohos_shared_library("ability_manager") {
|
||||
deps += []
|
||||
external_deps += [
|
||||
"ability_base:session_info",
|
||||
"graphic_2d:color_manager",
|
||||
"image_framework:image_native",
|
||||
"window_manager:libwsutils",
|
||||
"window_manager:session_manager_lite",
|
||||
@@ -385,6 +288,7 @@ ohos_shared_library("ability_start_setting") {
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"jsoncpp:jsoncpp",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
if (ability_runtime_graphics) {
|
||||
public_external_deps += [ "graphic_2d:color_manager" ]
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "parcel.h"
|
||||
#include "app_mgr_constants.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
||||
@@ -1009,7 +1009,8 @@ public:
|
||||
* @param handler Indidate handler of WindowManagerService.
|
||||
* @return ErrCode Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode RegisterWindowManagerServiceHandler(sptr<IWindowManagerServiceHandler> handler);
|
||||
ErrCode RegisterWindowManagerServiceHandler(sptr<IWindowManagerServiceHandler> handler,
|
||||
bool animationEnabled = true);
|
||||
|
||||
/**
|
||||
* WindowManager notification AbilityManager after the first frame is drawn.
|
||||
@@ -1408,6 +1409,17 @@ public:
|
||||
ErrCode GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token, UIExtensionHostInfo &hostInfo,
|
||||
int32_t userId = DEFAULT_INVAL_VALUE);
|
||||
|
||||
/**
|
||||
* @brief Get ui extension session info
|
||||
*
|
||||
* @param token The ability token.
|
||||
* @param uiExtensionSessionInfo The ui extension session info.
|
||||
* @param userId The user id.
|
||||
* @return int32_t Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode GetUIExtensionSessionInfo(const sptr<IRemoteObject> token, UIExtensionSessionInfo &uiExtensionSessionInfo,
|
||||
int32_t userId = DEFAULT_INVAL_VALUE);
|
||||
|
||||
/**
|
||||
* @brief Restart app self.
|
||||
* @param want The ability type must be UIAbility.
|
||||
@@ -1498,6 +1510,18 @@ public:
|
||||
*/
|
||||
void NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid);
|
||||
|
||||
/**
|
||||
* Open atomic service window prior to finishing free install.
|
||||
*
|
||||
* @param bundleName, the bundle name of the atomic service.
|
||||
* @param moduleName, the module name of the atomic service.
|
||||
* @param abilityName, the ability name of the atomic service.
|
||||
* @param startTime, the starting time of the free install task.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName,
|
||||
const std::string& abilityName, const std::string& startTime);
|
||||
|
||||
private:
|
||||
AbilityManagerClient();
|
||||
DISALLOW_COPY_AND_MOVE(AbilityManagerClient);
|
||||
@@ -1517,6 +1541,7 @@ private:
|
||||
|
||||
static std::once_flag singletonFlag_;
|
||||
std::recursive_mutex mutex_;
|
||||
std::mutex topAbilityMutex_;
|
||||
static std::shared_ptr<AbilityManagerClient> instance_;
|
||||
sptr<IAbilityManager> proxy_;
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_;
|
||||
|
||||
@@ -549,6 +549,16 @@ enum {
|
||||
* Native error(2097258) for target bundle not exist.
|
||||
*/
|
||||
ERR_BUNDLE_NOT_EXIST,
|
||||
|
||||
/*
|
||||
* Result (2097260) for target free install task does not exist.
|
||||
*/
|
||||
ERR_FREE_INSTALL_TASK_NOT_EXIST = 2097260,
|
||||
|
||||
/**
|
||||
* Native error(3000000) for target bundle not exist.
|
||||
*/
|
||||
ERR_CODE_NOT_EXIST = 3000000,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "system_memory_attr.h"
|
||||
#include "ui_extension_ability_connect_info.h"
|
||||
#include "ui_extension_host_info.h"
|
||||
#include "ui_extension_session_info.h"
|
||||
#include "ui_extension_window_command.h"
|
||||
#include "uri.h"
|
||||
#include "want.h"
|
||||
@@ -76,6 +77,7 @@ using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam;
|
||||
using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult;
|
||||
using UIExtensionAbilityConnectInfo = AbilityRuntime::UIExtensionAbilityConnectInfo;
|
||||
using UIExtensionHostInfo = AbilityRuntime::UIExtensionHostInfo;
|
||||
using UIExtensionSessionInfo = AbilityRuntime::UIExtensionSessionInfo;
|
||||
#ifdef SUPPORT_SCREEN
|
||||
using IAbilityFirstFrameStateObserver = AppExecFwk::IAbilityFirstFrameStateObserver;
|
||||
#endif
|
||||
@@ -723,7 +725,23 @@ public:
|
||||
* @param uid uid of bundle.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int UninstallApp(const std::string &bundleName, int32_t uid) = 0;
|
||||
virtual int UninstallApp(const std::string &bundleName, int32_t uid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall app
|
||||
*
|
||||
* @param bundleName bundle name of uninstalling app.
|
||||
* @param uid uid of bundle.
|
||||
* @param appIndex the app index of app clone.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade app, record exit reason and kill application
|
||||
@@ -731,9 +749,11 @@ public:
|
||||
* @param bundleName bundle name of upgrading app.
|
||||
* @param uid uid of bundle.
|
||||
* @param exitMsg the exit reason message.
|
||||
* @param appIndex the app index of app clone.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg)
|
||||
virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg,
|
||||
int32_t appIndex = 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -884,7 +904,11 @@ public:
|
||||
* @param handler Indidate handler of WindowManagerService.
|
||||
* @return ErrCode Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) = 0;
|
||||
virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
|
||||
bool animationEnabled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* WindowManager notification AbilityManager after the first frame is drawn.
|
||||
@@ -1493,6 +1517,20 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get ui extension session info
|
||||
*
|
||||
* @param token The ability token.
|
||||
* @param uiExtensionSessionInfo The ui extension session info.
|
||||
* @param userId The user id.
|
||||
* @return int32_t Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t GetUIExtensionSessionInfo(const sptr<IRemoteObject> token,
|
||||
UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId = DEFAULT_INVAL_VALUE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Restart app self.
|
||||
* @param want The ability type must be UIAbility.
|
||||
@@ -1610,6 +1648,21 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open atomic service window prior to finishing free install.
|
||||
*
|
||||
* @param bundleName, the bundle name of the atomic service.
|
||||
* @param moduleName, the module name of the atomic service.
|
||||
* @param abilityName, the ability name of the atomic service.
|
||||
* @param startTime, the starting time of the free install task.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName,
|
||||
const std::string& abilityName, const std::string& startTime)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -395,8 +395,14 @@ enum class AbilityManagerInterfaceCode {
|
||||
// ipc id for preload UIExtension ability by want
|
||||
PRELOAD_UIEXTENSION_ABILITY = 1062,
|
||||
|
||||
// ipc id for start UIExtension ability non—modal
|
||||
START_UI_EXTENSION_ABILITY_NON_MODAL = 1063,
|
||||
// ipc id for start UIExtension ability embedded
|
||||
START_UI_EXTENSION_ABILITY_EMBEDDED = 1063,
|
||||
|
||||
// ipc id for start UIExtension ability constrained embedded
|
||||
START_UI_EXTENSION_CONSTRAINED_EMBEDDED = 1064,
|
||||
|
||||
// get ui extension session info
|
||||
GET_UI_EXTENSION_SESSION_INFO = 1065,
|
||||
|
||||
// ipc id for continue ability(1101)
|
||||
START_CONTINUATION = 1101,
|
||||
@@ -444,6 +450,9 @@ enum class AbilityManagerInterfaceCode {
|
||||
// ipc for notify frozen process by RSS
|
||||
NOTIFY_FROZEN_PROCESS_BY_RSS = 1130,
|
||||
|
||||
// ipc id for pre-start mission
|
||||
PRE_START_MISSION = 1135,
|
||||
|
||||
// ipc id 2001-3000 for tools
|
||||
// ipc id for dumping state (2001)
|
||||
DUMP_STATE = 2001,
|
||||
|
||||
@@ -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 OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H
|
||||
#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H
|
||||
|
||||
#include "parcel.h"
|
||||
#include "session_info_constants.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class UIExtensionSessionInfo : public Parcelable {
|
||||
public:
|
||||
UIExtensionSessionInfo() = default;
|
||||
virtual ~UIExtensionSessionInfo() = default;
|
||||
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static UIExtensionSessionInfo *Unmarshalling(Parcel &parcel);
|
||||
|
||||
int32_t persistentId = 0;
|
||||
uint32_t hostWindowId = 0;
|
||||
AAFwk::UIExtensionUsage uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H
|
||||
@@ -122,7 +122,6 @@ ohos_shared_library("app_manager") {
|
||||
deps = [ "${ability_runtime_path}/utils/global/freeze:freeze_util" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
"c_utils:utils",
|
||||
"faultloggerd:libdfx_dumpcatcher",
|
||||
"faultloggerd:libfaultloggerd",
|
||||
@@ -141,6 +140,7 @@ ohos_shared_library("app_manager") {
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"image_framework:image_native",
|
||||
"relational_store:native_rdb",
|
||||
"skia:skia_canvaskit",
|
||||
]
|
||||
|
||||
if (background_task_mgr_continuous_task_enable) {
|
||||
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
|
||||
virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) = 0;
|
||||
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token) = 0;
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false) = 0;
|
||||
|
||||
virtual void GetRunningProcessInfoByToken(
|
||||
const sptr<IRemoteObject> &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0;
|
||||
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
|
||||
virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override;
|
||||
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token) override;
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false) override;
|
||||
|
||||
void GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) override;
|
||||
|
||||
|
||||
@@ -292,8 +292,9 @@ public:
|
||||
* Prepare terminate.
|
||||
*
|
||||
* @param token Ability identify.
|
||||
* @param clearMissionFlag Clear mission flag.
|
||||
*/
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token);
|
||||
virtual void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false);
|
||||
|
||||
/**
|
||||
* Get running process information by ability token.
|
||||
@@ -516,6 +517,14 @@ public:
|
||||
*/
|
||||
int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData);
|
||||
|
||||
/**
|
||||
* Set Appfreeze Detect Filter
|
||||
*
|
||||
* @param pid the process pid.
|
||||
* @return Returns true on success, others on failure.
|
||||
*/
|
||||
bool SetAppFreezeFilter(int32_t pid);
|
||||
|
||||
/**
|
||||
* Set AbilityForegroundingFlag of an app-record to true.
|
||||
*
|
||||
@@ -755,6 +764,10 @@ public:
|
||||
* @return Returns RESULT_OK on success, others on failure.
|
||||
*/
|
||||
virtual AppMgrResultCode AttachedToStatusBar(const sptr<IRemoteObject> &token);
|
||||
|
||||
int32_t NotifyProcessDependedOnWeb();
|
||||
|
||||
void KillProcessDependedOnWeb();
|
||||
private:
|
||||
void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr);
|
||||
/**
|
||||
|
||||
@@ -431,6 +431,14 @@ public:
|
||||
*/
|
||||
virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) = 0;
|
||||
|
||||
/**
|
||||
* Set Appfreeze Detect Filter
|
||||
*
|
||||
* @param pid the process pid.
|
||||
* @return Returns true on success, others on failure.
|
||||
*/
|
||||
virtual bool SetAppFreezeFilter(int32_t pid) = 0;
|
||||
|
||||
#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
|
||||
/**
|
||||
* @brief Set whether the process is continuousTask.
|
||||
@@ -719,6 +727,30 @@ public:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify that the process depends on web by itself.
|
||||
*/
|
||||
virtual int32_t NotifyProcessDependedOnWeb()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill process depended on web by sa.
|
||||
*/
|
||||
virtual void KillProcessDependedOnWeb()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart resident process depended on web.
|
||||
*/
|
||||
virtual void RestartResidentProcessDependedOnWeb()
|
||||
{
|
||||
return;
|
||||
}
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -106,6 +106,11 @@ enum class AppMgrInterfaceCode {
|
||||
GET_RUNNING_PROCESS_INFO_BY_PID = 80,
|
||||
IS_APP_RUNNING = 81,
|
||||
CHECK_CALLING_IS_USER_TEST_MODE = 82,
|
||||
SET_APPFREEZE_FILTER = 83,
|
||||
// ipc for process depended on arkweb
|
||||
NOTIFY_PROCESS_DEPENDED_ON_WEB = 84,
|
||||
KILL_PROCESS_DEPENDED_ON_WEB = 85,
|
||||
RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB = 86,
|
||||
};
|
||||
} // AppExecFwk
|
||||
} // OHOS
|
||||
|
||||
@@ -358,6 +358,14 @@ public:
|
||||
*/
|
||||
virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override;
|
||||
|
||||
/**
|
||||
* Set Appfreeze Detect Filter
|
||||
*
|
||||
* @param pid the process pid.
|
||||
* @return Returns true on success, others on failure.
|
||||
*/
|
||||
virtual bool SetAppFreezeFilter(int32_t pid) override;
|
||||
|
||||
#ifdef ABILITY_COMMAND_FOR_TEST
|
||||
/**
|
||||
* Block app service.
|
||||
@@ -629,6 +637,11 @@ public:
|
||||
*/
|
||||
int32_t CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) override;
|
||||
|
||||
virtual int32_t NotifyProcessDependedOnWeb() override;
|
||||
|
||||
virtual void KillProcessDependedOnWeb() override;
|
||||
|
||||
virtual void RestartResidentProcessDependedOnWeb() override;
|
||||
private:
|
||||
bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply);
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
|
||||
@@ -110,6 +110,7 @@ private:
|
||||
int32_t HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleNotifyFault(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSetAppFreezeFilter(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetRunningProcessInfoByPid(MessageParcel &data, MessageParcel &reply);
|
||||
@@ -142,6 +143,9 @@ private:
|
||||
int32_t HandleStartNativeChildProcess(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSaveBrowserChannel(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleCheckCallingIsUserTestMode(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply);
|
||||
using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, AppMgrFunc> memberFuncMap_;
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ struct FaultData : public Parcelable {
|
||||
bool notifyApp = false;
|
||||
bool forceExit = false;
|
||||
uint32_t state = 0;
|
||||
int32_t eventId = -1;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
};
|
||||
|
||||
@@ -84,6 +85,7 @@ struct AppFaultDataBySA : public Parcelable {
|
||||
bool notifyApp = false;
|
||||
bool forceExit = false;
|
||||
uint32_t state = 0;
|
||||
int32_t eventId = -1;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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_PARCEL_UTIL_H
|
||||
#define OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
#define PARCEL_UTIL_WRITE_NORET(parcel, type, value) \
|
||||
do { \
|
||||
if (!(parcel).Write##type(value)) { \
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define PARCEL_UTIL_WRITE_RET_INT(parcel, type, value) \
|
||||
do { \
|
||||
if (!(parcel).Write##type(value)) { \
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \
|
||||
return IPC_PROXY_ERR; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define PARCEL_UTIL_SENDREQ_NORET(code, data, reply, option) \
|
||||
do { \
|
||||
int32_t ret = SendRequest(code, data, reply, option); \
|
||||
if (ret != NO_ERROR) { \
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define PARCEL_UTIL_SENDREQ_RET_INT(code, data, reply, option) \
|
||||
do { \
|
||||
int32_t ret = SendRequest(code, data, reply, option); \
|
||||
if (ret != NO_ERROR) { \
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H
|
||||
@@ -501,7 +501,7 @@ void AmsMgrProxy::AbilityAttachTimeOut(const sptr<IRemoteObject> &token)
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "end");
|
||||
}
|
||||
|
||||
void AmsMgrProxy::PrepareTerminate(const sptr<IRemoteObject> &token)
|
||||
void AmsMgrProxy::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "start");
|
||||
MessageParcel data;
|
||||
@@ -514,6 +514,10 @@ void AmsMgrProxy::PrepareTerminate(const sptr<IRemoteObject> &token)
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteBool(clearMissionFlag)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Failed to write clearMissionFlag");
|
||||
return;
|
||||
}
|
||||
int32_t ret =
|
||||
SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY),
|
||||
data, reply, option);
|
||||
|
||||
@@ -351,7 +351,8 @@ int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParce
|
||||
int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<IRemoteObject> token = data.ReadRemoteObject();
|
||||
PrepareTerminate(token);
|
||||
bool clearMissionFlag = data.ReadBool();
|
||||
PrepareTerminate(token, clearMissionFlag);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +495,7 @@ void AppMgrClient::AbilityAttachTimeOut(const sptr<IRemoteObject> &token)
|
||||
amsService->AbilityAttachTimeOut(token);
|
||||
}
|
||||
|
||||
void AppMgrClient::PrepareTerminate(const sptr<IRemoteObject> &token)
|
||||
void AppMgrClient::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
@@ -505,7 +505,7 @@ void AppMgrClient::PrepareTerminate(const sptr<IRemoteObject> &token)
|
||||
if (amsService == nullptr) {
|
||||
return;
|
||||
}
|
||||
amsService->PrepareTerminate(token);
|
||||
amsService->PrepareTerminate(token, clearMissionFlag);
|
||||
}
|
||||
|
||||
void AppMgrClient::GetRunningProcessInfoByToken(const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info)
|
||||
@@ -854,6 +854,15 @@ int32_t AppMgrClient::NotifyAppFaultBySA(const AppFaultDataBySA &faultData)
|
||||
return service->NotifyAppFaultBySA(faultData);
|
||||
}
|
||||
|
||||
bool AppMgrClient::SetAppFreezeFilter(int32_t pid)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return service->SetAppFreezeFilter(pid);
|
||||
}
|
||||
|
||||
int32_t AppMgrClient::ChangeAppGcState(pid_t pid, int32_t state)
|
||||
{
|
||||
if (mgrHolder_ == nullptr) {
|
||||
@@ -1207,5 +1216,27 @@ AppMgrResultCode AppMgrClient::AttachedToStatusBar(const sptr<IRemoteObject> &to
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Service is not connected.");
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
int32_t AppMgrClient::NotifyProcessDependedOnWeb()
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "call");
|
||||
return service->NotifyProcessDependedOnWeb();
|
||||
}
|
||||
|
||||
void AppMgrClient::KillProcessDependedOnWeb()
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
|
||||
return;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "call");
|
||||
service->KillProcessDependedOnWeb();
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user