fix megre master 1218

Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
xinking129
2023-12-18 11:21:33 +08:00
319 changed files with 5992 additions and 714 deletions
+2
View File
@@ -49,6 +49,8 @@ group("napi_packages") {
"${ability_runtime_napi_path}/configuration_constant:configurationconstant",
"${ability_runtime_napi_path}/configuration_constant:configurationconstant_napi",
"${ability_runtime_napi_path}/dataUriUtils:datauriutils_napi",
"${ability_runtime_napi_path}/embeddable_ui_ability:embeddableuiability_napi",
"${ability_runtime_napi_path}/embeddable_ui_ability_context:embeddableuiabilitycontext_napi",
"${ability_runtime_napi_path}/extension_ability:extensionability_napi",
"${ability_runtime_napi_path}/extensioncontext:extensioncontext_napi",
"${ability_runtime_napi_path}/featureAbility:featureability",
@@ -113,7 +113,11 @@ napi_value JsAbilityAutoStartupManager::OnRegisterAutoStartupCallback(napi_env e
if (ret != ERR_OK) {
jsAutoStartupCallback_ = nullptr;
HILOG_ERROR("Register auto start up listener wrong[%{public}d].", ret);
ThrowError(env, GetJsErrorCodeByNativeError(ret));
if (ret == CHECK_PERMISSION_FAILED) {
ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT);
} else {
ThrowError(env, GetJsErrorCodeByNativeError(ret));
}
return CreateJsUndefined(env);
}
}
@@ -155,7 +159,11 @@ napi_value JsAbilityAutoStartupManager::OnUnregisterAutoStartupCallback(napi_env
auto ret = AbilityManagerClient::GetInstance()->UnregisterAutoStartupSystemCallback(
jsAutoStartupCallback_->AsObject());
if (ret != ERR_OK) {
ThrowError(env, GetJsErrorCodeByNativeError(ret));
if (ret == CHECK_PERMISSION_FAILED) {
ThrowNoPermissionError(env, PermissionConstants::PERMISSION_MANAGE_APP_BOOT);
} else {
ThrowError(env, GetJsErrorCodeByNativeError(ret));
}
}
jsAutoStartupCallback_ = nullptr;
}
@@ -197,6 +197,10 @@ class ApplicationContext {
return this.__context_impl__.tempDir;
}
get resourceDir() {
return this.__context_impl__.resourceDir;
}
get filesDir() {
return this.__context_impl__.filesDir;
}
@@ -118,6 +118,10 @@ class Context {
return this.__context_impl__.tempDir;
}
get resourceDir() {
return this.__context_impl__.resourceDir;
}
get filesDir() {
return this.__context_impl__.filesDir;
}
@@ -795,7 +795,7 @@ private:
return result;
}
napi_value OnIsApplicationRunning(napi_env env, size_t argc, napi_value *argv)
napi_value OnIsApplicationRunning(napi_env env, size_t argc, napi_value *argv)
{
HILOG_DEBUG("Called.");
if (argc < ARGC_ONE) {
@@ -38,11 +38,14 @@ ohos_shared_library("autofillmanager_napi") {
external_deps = [
"ability_base:view_data",
"ace_engine:ace_uicontent",
"hilog:libhilog",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
external_deps += [ "ace_engine:ace_uicontent" ]
}
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
@@ -0,0 +1,50 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_embeddable_ui_ability_abc") {
src_js = rebase_path("embeddable_ui_ability.js")
dst_file = rebase_path(target_out_dir + "/embeddable_ui_ability.abc")
in_puts = [ "embeddable_ui_ability.js" ]
out_puts = [ target_out_dir + "/embeddable_ui_ability.abc" ]
extra_args = [ "--module" ]
}
gen_js_obj("embeddable_ui_ability_js") {
input = "embeddable_ui_ability.js"
output = target_out_dir + "/embeddable_ui_ability.o"
}
gen_js_obj("embeddable_ui_ability_abc") {
input = get_label_info(":gen_embeddable_ui_ability_abc", "target_out_dir") +
"/embeddable_ui_ability.abc"
output = target_out_dir + "/embeddable_ui_ability_abc.o"
dep = ":gen_embeddable_ui_ability_abc"
}
ohos_shared_library("embeddableuiability_napi") {
sources = [ "embeddable_ui_ability_module.cpp" ]
deps = [
":embeddable_ui_ability_abc",
":embeddable_ui_ability_js",
]
external_deps = [ "napi:ace_napi" ]
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 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.
*/
let UIAbility = requireNapi('app.ability.UIAbility');
class EmbeddableUIAbility extends UIAbility {
}
export default EmbeddableUIAbility;
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "native_engine/native_engine.h"
extern const char _binary_embeddable_ui_ability_js_start[];
extern const char _binary_embeddable_ui_ability_js_end[];
extern const char _binary_embeddable_ui_ability_abc_start[];
extern const char _binary_embeddable_ui_ability_abc_end[];
static napi_module _module = {
.nm_version = 0,
.nm_filename = "app/ability/libembeddableuiability_napi.so/embeddable_ui_ability.js",
.nm_modname = "app.ability.EmbeddableUIAbility",
};
extern "C" __attribute__((constructor)) void NAPI_app_ability_EmbeddableUIAbility_AutoRegister()
{
napi_module_register(&_module);
}
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_EmbeddableUIAbility_GetJSCode(
const char **buf, int *bufLen)
{
if (buf != nullptr) {
*buf = _binary_embeddable_ui_ability_js_start;
}
if (bufLen != nullptr) {
*bufLen = _binary_embeddable_ui_ability_js_end - _binary_embeddable_ui_ability_js_start;
}
}
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_EmbeddableUIAbility_GetABCCode(
const char **buf, int *buflen)
{
if (buf != nullptr) {
*buf = _binary_embeddable_ui_ability_abc_start;
}
if (buflen != nullptr) {
*buflen = _binary_embeddable_ui_ability_abc_end - _binary_embeddable_ui_ability_abc_start;
}
}
@@ -0,0 +1,51 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_embeddable_ui_ability_context_abc") {
src_js = rebase_path("embeddable_ui_ability_context.js")
dst_file = rebase_path(target_out_dir + "/embeddable_ui_ability_context.abc")
in_puts = [ "embeddable_ui_ability_context.js" ]
out_puts = [ target_out_dir + "/embeddable_ui_ability_context.abc" ]
extra_args = [ "--module" ]
}
gen_js_obj("embeddable_ui_ability_context_js") {
input = "embeddable_ui_ability_context.js"
output = target_out_dir + "/embeddable_ui_ability_context.o"
}
gen_js_obj("embeddable_ui_ability_context_abc") {
input =
get_label_info(":gen_embeddable_ui_ability_context_abc",
"target_out_dir") + "/embeddable_ui_ability_context.abc"
output = target_out_dir + "/embeddable_ui_ability_context_abc.o"
dep = ":gen_embeddable_ui_ability_context_abc"
}
ohos_shared_library("embeddableuiabilitycontext_napi") {
sources = [ "embeddable_ui_ability_context_module.cpp" ]
deps = [
":embeddable_ui_ability_context_abc",
":embeddable_ui_ability_context_js",
]
external_deps = [ "napi:ace_napi" ]
relative_install_dir = "module/application"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 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.
*/
let AbilityContext = requireNapi('application.AbilityContext');
class EmbeddableUIAbilityContext extends AbilityContext {
constructor(obj) {
super(obj);
this.abilityInfo = obj.abilityInfo;
this.currentHapModuleInfo = obj.currentHapModuleInfo;
this.config = obj.config;
}
onUpdateConfiguration(config) {
this.config = config;
}
}
export default EmbeddableUIAbilityContext;
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "native_engine/native_engine.h"
extern const char _binary_embeddable_ui_ability_context_js_start[];
extern const char _binary_embeddable_ui_ability_context_js_end[];
extern const char _binary_embeddable_ui_ability_context_abc_start[];
extern const char _binary_embeddable_ui_ability_context_abc_end[];
static napi_module _module = {
.nm_version = 0,
.nm_filename = "application/libembeddableuiabilitycontext_napi.so/embeddable_ui_ability_context.js",
.nm_modname = "application.EmbeddableUIAbilityContext",
};
extern "C" __attribute__((constructor)) void NAPI_application_EmbeddableUIAbilityContext_AutoRegister()
{
napi_module_register(&_module);
}
extern "C" __attribute__((visibility("default"))) void NAPI_application_EmbeddableUIAbilityContext_GetJSCode(
const char **buf, int *bufLen)
{
if (buf != nullptr) {
*buf = _binary_embeddable_ui_ability_context_js_start;
}
if (bufLen != nullptr) {
*bufLen = _binary_embeddable_ui_ability_context_js_end - _binary_embeddable_ui_ability_context_js_start;
}
}
// embeddable_ui_ability_context JS register
extern "C" __attribute__((visibility("default"))) void NAPI_application_EmbeddableUIAbilityContext_GetABCCode(
const char **buf, int *buflen)
{
if (buf != nullptr) {
*buf = _binary_embeddable_ui_ability_context_abc_start;
}
if (buflen != nullptr) {
*buflen = _binary_embeddable_ui_ability_context_abc_end - _binary_embeddable_ui_ability_context_abc_start;
}
}
@@ -781,7 +781,10 @@ napi_value UnwrapForResultParam(CallAbilityParam &param, napi_env env, napi_valu
}
// unwrap the param : abilityStartSetting (optional)
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSettings", napi_object);
if (jsSettingObj == nullptr) {
jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
}
if (jsSettingObj != nullptr) {
param.setting = AbilityStartSetting::GetEmptySetting();
if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) {
@@ -3135,7 +3135,10 @@ bool UnwrapParamForWant(napi_env env, napi_value args, AbilityType, CallAbilityP
ret = UnwrapWant(env, jsWant, param.want);
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
napi_value jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSettings", napi_object);
if (jsSettingObj == nullptr) {
jsSettingObj = GetPropertyValueByPropertyName(env, args, "abilityStartSetting", napi_object);
}
if (jsSettingObj != nullptr) {
param.setting = AbilityStartSetting::GetEmptySetting();
if (!UnwrapAbilityStartSetting(env, jsSettingObj, *(param.setting))) {
@@ -772,10 +772,17 @@ int32_t JsWantAgent::GetTriggerInfo(napi_env env, napi_value param, TriggerInfo
std::shared_ptr<AAFwk::WantParams> extraInfo = nullptr;
bool hasExtraInfo = false;
napi_has_named_property(env, param, "extraInfo", &hasExtraInfo);
napi_value jsExtraInfo = nullptr;
napi_has_named_property(env, param, "extraInfos", &hasExtraInfo);
if (hasExtraInfo) {
napi_get_named_property(env, param, "extraInfos", &jsExtraInfo);
} else {
napi_has_named_property(env, param, "extraInfo", &hasExtraInfo);
if (hasExtraInfo) {
napi_get_named_property(env, param, "extraInfo", &jsExtraInfo);
}
}
if (hasExtraInfo) {
napi_value jsExtraInfo = nullptr;
napi_get_named_property(env, param, "extraInfo", &jsExtraInfo);
extraInfo = std::make_shared<AAFwk::WantParams>();
if (!UnwrapWantParams(env, (jsExtraInfo),
*extraInfo)) {
@@ -913,10 +920,17 @@ int32_t JsWantAgent::GetWantAgentParam(napi_env env, napi_callback_info info, Wa
}
bool hasExtraInfo = false;
napi_has_named_property(env, argv[0], "extraInfo", &hasExtraInfo);
napi_value jsExtraInfo = nullptr;
napi_has_named_property(env, argv[0], "extraInfos", &hasExtraInfo);
if (hasExtraInfo) {
napi_get_named_property(env, argv[0], "extraInfos", &jsExtraInfo);
} else {
napi_has_named_property(env, argv[0], "extraInfo", &hasExtraInfo);
if (hasExtraInfo) {
napi_get_named_property(env, argv[0], "extraInfo", &jsExtraInfo);
}
}
if (hasExtraInfo) {
napi_value jsExtraInfo = nullptr;
napi_get_named_property(env, argv[0], "extraInfo", &jsExtraInfo);
if (!CheckTypeForNapiValue(env, jsExtraInfo, napi_object)) {
HILOG_ERROR("ExtraInfo type error!");
return PARAMETER_ERROR;
+9 -4
View File
@@ -75,7 +75,6 @@ ohos_shared_library("ability_context_native") {
"ability_base:want",
"access_token:libaccesstoken_sdk",
"access_token:libtoken_callback_sdk",
"ace_engine:ace_uicontent",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"faultloggerd:libdfx_dumpcatcher",
@@ -83,11 +82,17 @@ ohos_shared_library("ability_context_native") {
"hitrace:hitrace_meter",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:libwsutils",
"window_manager:scene_session",
"window_manager:session_manager",
]
if (ability_runtime_graphics) {
external_deps += [
"ace_engine:ace_uicontent",
"window_manager:libwsutils",
"window_manager:scene_session",
"window_manager:session_manager_lite",
]
}
if (hichecker_enabled) {
external_deps += [ "hichecker:libhichecker" ]
}
@@ -98,6 +98,11 @@ std::string AbilityContextImpl::GetTempDir()
return stageContext_ ? stageContext_->GetTempDir() : "";
}
std::string AbilityContextImpl::GetResourceDir()
{
return stageContext_ ? stageContext_->GetResourceDir() : "";
}
std::string AbilityContextImpl::GetFilesDir()
{
return stageContext_ ? stageContext_->GetFilesDir() : "";
@@ -140,6 +145,22 @@ ErrCode AbilityContextImpl::StartAbility(const AAFwk::Want& want, int requestCod
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("StartAbility");
int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
if (screenMode == AAFwk::HALF_SCREEN_MODE) {
auto uiContent = GetUIContent();
if (uiContent == nullptr) {
HILOG_ERROR("uiContent is nullptr");
return ERR_INVALID_VALUE;
}
Ace::ModalUIExtensionCallbacks callback;
Ace::ModalUIExtensionConfig config;
int32_t sessionId = uiContent->CreateModalUIExtension(want, callback, config);
if (sessionId == 0) {
HILOG_ERROR("CreateModalUIExtension failed");
return ERR_INVALID_VALUE;
}
return ERR_OK;
}
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, requestCode);
if (err != ERR_OK) {
HILOG_ERROR("StartAbility. ret=%{public}d", err);
+12 -5
View File
@@ -278,7 +278,6 @@ ohos_shared_library("abilitykit_native") {
"relational_store:native_rdb",
"resource_management:global_resmgr",
"samgr:samgr_proxy",
"window_manager:libwsutils",
]
defines = []
@@ -316,6 +315,7 @@ ohos_shared_library("abilitykit_native") {
"input:libmmi-client",
"window_manager:libdm",
"window_manager:libwm",
"window_manager:libwsutils",
"window_manager:windowstage_kit",
]
}
@@ -477,6 +477,7 @@ ohos_shared_library("uiabilitykit_native") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
"${ability_runtime_path}/utils/global/time/include",
]
@@ -497,6 +498,7 @@ ohos_shared_library("uiabilitykit_native") {
deps = [
":abilitykit_native",
":continuation_ipc",
":ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/runtime:runtime",
@@ -523,8 +525,6 @@ ohos_shared_library("uiabilitykit_native") {
"ipc:ipc_napi",
"napi:ace_napi",
"resource_management:global_resmgr",
"window_manager:libwsutils",
"window_manager:windowstage_kit",
]
if (ability_runtime_graphics) {
@@ -533,6 +533,8 @@ ohos_shared_library("uiabilitykit_native") {
"ability_base:session_info",
"window_manager:libdm",
"window_manager:libwm",
"window_manager:libwsutils",
"window_manager:windowstage_kit",
]
}
@@ -924,6 +926,7 @@ config("ui_extension_public_config") {
visibility = [ ":*" ]
include_dirs = [
"${ability_runtime_path}/interfaces/inner_api/insight_intent/insight_intent_context",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/insight_intent_executor",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability",
]
@@ -931,6 +934,7 @@ config("ui_extension_public_config") {
ohos_shared_library("ui_extension") {
sources = [
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_base.cpp",
"${ability_runtime_native_path}/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp",
@@ -950,6 +954,7 @@ ohos_shared_library("ui_extension") {
"${ability_runtime_native_path}/ability/native:ability_business_error",
"${ability_runtime_native_path}/ability/native:insight_intent_executor",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
]
external_deps = [
@@ -957,7 +962,6 @@ ohos_shared_library("ui_extension") {
"ability_base:want",
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"ace_engine:ace_uicontent",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
@@ -968,7 +972,10 @@ ohos_shared_library("ui_extension") {
]
if (ability_runtime_graphics) {
external_deps += [ "window_manager:libwm" ]
external_deps += [
"ace_engine:ace_uicontent",
"window_manager:libwm",
]
}
subsystem_name = "ability"
+14 -2
View File
@@ -169,7 +169,9 @@ void Ability::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false);
(const_cast<Want &>(want)).RemoveParam(DLP_PARAMS_SECURITY_FLAG);
SetWant(want);
sessionInfo_ = sessionInfo;
if (sessionInfo != nullptr) {
sessionToken_ = sessionInfo->sessionToken;
}
HILOG_INFO("AbilityName is %{public}s.", abilityInfo_->name.c_str());
#ifdef SUPPORT_GRAPHICS
if (abilityInfo_->type == AppExecFwk::AbilityType::PAGE) {
@@ -1594,7 +1596,7 @@ void Ability::InitWindow(int32_t displayId, sptr<Rosen::WindowOption> option)
HILOG_ERROR("Ability window is nullptr.");
return;
}
abilityWindow_->SetSessionInfo(sessionInfo_);
abilityWindow_->SetSessionToken(sessionToken_);
abilityWindow_->InitWindow(abilityContext_, sceneListener_, displayId, option, securityFlag_);
}
@@ -2116,6 +2118,16 @@ int Ability::CreateModalUIExtension(const Want &want)
}
return abilityContextImpl->CreateModalUIExtensionWithApp(want);
}
void Ability::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
{
sessionToken_ = sessionToken;
if (abilityWindow_ == nullptr) {
HILOG_ERROR("Ability window is nullptr.");
return;
}
abilityWindow_->SetSessionToken(sessionToken_);
}
#endif
} // namespace AppExecFwk
} // namespace OHOS
@@ -85,20 +85,15 @@ ErrCode AbilityContext::TerminateAbility()
case AppExecFwk::AbilityType::PAGE:
HILOG_DEBUG("Terminate ability begin, type is page, ability is %{public}s.", info->name.c_str());
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
if (sessionInfo_ == nullptr) {
HILOG_ERROR("sessionInfo_ is nullptr.");
return ERR_INVALID_VALUE;
}
auto sessionToken = sessionInfo_->sessionToken;
if (sessionToken == nullptr) {
HILOG_ERROR("sessionToken is nullptr.");
if (sessionToken_ == nullptr) {
HILOG_ERROR("sessionToken_ is nullptr.");
return ERR_INVALID_VALUE;
}
sptr<AAFwk::SessionInfo> sessionInfo = new AAFwk::SessionInfo();
sessionInfo->want = resultWant_;
sessionInfo->resultCode = resultCode_;
HILOG_INFO("FA TerminateAbility resultCode is %{public}d", sessionInfo->resultCode);
auto ifaceSessionToken = iface_cast<Rosen::ISession>(sessionToken);
auto ifaceSessionToken = iface_cast<Rosen::ISession>(sessionToken_);
auto err = ifaceSessionToken->TerminateSession(sessionInfo);
HILOG_INFO("FA TerminateAbility. ret=%{public}d", err);
return static_cast<int32_t>(err);
@@ -634,9 +634,9 @@ void JsAbility::DoOnForeground(const Want &want)
}
auto option = GetWindowOption(want);
Rosen::WMError ret = Rosen::WMError::WM_OK;
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
abilityContext_->SetWeakSessionToken(sessionInfo_->sessionToken);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionInfo_->sessionToken);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken_ != nullptr) {
abilityContext_->SetWeakSessionToken(sessionToken_);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken_);
} else {
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
}
@@ -36,6 +36,7 @@
#include "js_data_struct_converter.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "js_utils.h"
#ifdef SUPPORT_GRAPHICS
#include "js_window_stage.h"
#endif
@@ -70,10 +71,10 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info)
}
} // namespace
napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
napi_value AttachJsAbilityContext(napi_env env, void *value, void *extValue)
{
HILOG_DEBUG("Begin.");
if (value == nullptr) {
if (value == nullptr || extValue == nullptr) {
HILOG_ERROR("Invalid parameter.");
return nullptr;
}
@@ -82,14 +83,27 @@ napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
HILOG_ERROR("Invalid context.");
return nullptr;
}
napi_value object = CreateJsAbilityContext(env, ptr);
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityContext", &object, 1);
if (systemModule == nullptr) {
HILOG_ERROR("Invalid systemModule.");
std::shared_ptr<NativeReference> systemModule = nullptr;
auto screenModePtr = reinterpret_cast<std::weak_ptr<int32_t> *>(extValue)->lock();
if (screenModePtr == nullptr) {
HILOG_ERROR("Invalid screenModePtr.");
return nullptr;
}
if (*screenModePtr == AAFwk::IDLE_SCREEN_MODE) {
auto uiAbiObject = CreateJsAbilityContext(env, ptr);
CHECK_POINTER_AND_RETURN(uiAbiObject, nullptr);
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
"application.AbilityContext", &uiAbiObject, 1).release());
} else {
auto emUIObject = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
ptr, nullptr, *screenModePtr);
CHECK_POINTER_AND_RETURN(emUIObject, nullptr);
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
"application.EmbeddableUIAbilityContext", &emUIObject, 1).release());
}
CHECK_POINTER_AND_RETURN(systemModule, nullptr);
auto contextObj = systemModule->GetNapiValue();
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, nullptr);
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, extValue);
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(ptr);
napi_wrap(env, contextObj, workContext,
[](napi_env, void* data, void*) {
@@ -124,17 +138,21 @@ JsUIAbility::~JsUIAbility()
#endif
}
void JsUIAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
void JsUIAbility::Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
const std::shared_ptr<OHOSApplication> application, std::shared_ptr<AbilityHandler> &handler,
const sptr<IRemoteObject> &token)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
UIAbility::Init(abilityInfo, application, handler, token);
if (record == nullptr) {
HILOG_ERROR("AbilityLocalRecord is nullptr.");
return;
}
auto abilityInfo = record->GetAbilityInfo();
if (abilityInfo == nullptr) {
HILOG_ERROR("AbilityInfo is nullptr.");
return;
}
UIAbility::Init(record, application, handler, token);
#ifdef SUPPORT_GRAPHICS
if (abilityContext_ != nullptr) {
AppExecFwk::AppRecovery::GetInstance().AddAbility(
@@ -164,18 +182,18 @@ void JsUIAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
std::string moduleName(abilityInfo->moduleName);
moduleName.append("::").append(abilityInfo->name);
SetAbilityContext(abilityInfo, moduleName, srcPath);
SetAbilityContext(abilityInfo, record->GetWant(), moduleName, srcPath);
}
void JsUIAbility::SetAbilityContext(
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::string &moduleName, const std::string &srcPath)
void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
std::shared_ptr<AAFwk::Want> want, const std::string &moduleName, const std::string &srcPath)
{
HandleScope handleScope(jsRuntime_);
auto env = jsRuntime_.GetNapiEnv();
jsAbilityObj_ = jsRuntime_.LoadModule(
moduleName, srcPath, abilityInfo->hapPath, abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE);
if (jsAbilityObj_ == nullptr || abilityContext_ == nullptr) {
HILOG_ERROR("jsAbilityObj_ or abilityContext_ is nullptr.");
if (jsAbilityObj_ == nullptr || abilityContext_ == nullptr || want == nullptr) {
HILOG_ERROR("jsAbilityObj_ or abilityContext_ or want is nullptr.");
return;
}
napi_value obj = jsAbilityObj_->GetNapiValue();
@@ -183,10 +201,9 @@ void JsUIAbility::SetAbilityContext(
HILOG_ERROR("Failed to check type");
return;
}
napi_value contextObj = CreateJsAbilityContext(env, abilityContext_);
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
env, "application.AbilityContext", &contextObj, 1).release());
napi_value contextObj = nullptr;
int32_t screenMode = want->GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
CreateJSContext(env, contextObj, screenMode);
if (shellContextRef_ == nullptr) {
HILOG_ERROR("shellContextRef_ is nullptr.");
return;
@@ -197,16 +214,15 @@ void JsUIAbility::SetAbilityContext(
return;
}
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(abilityContext_);
if (workContext == nullptr) {
HILOG_ERROR("workContext is nullptr.");
return;
}
CHECK_POINTER(workContext);
screenModePtr_ = std::make_shared<int32_t>(screenMode);
auto workScreenMode = new (std::nothrow) std::weak_ptr<int32_t>(screenModePtr_);
CHECK_POINTER(workScreenMode);
napi_coerce_to_native_binding_object(
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, nullptr);
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, workScreenMode);
abilityContext_->Bind(jsRuntime_, shellContextRef_.get());
napi_set_named_property(env, obj, "context", contextObj);
HILOG_DEBUG("Set ability context");
if (abilityRecovery_ != nullptr) {
abilityRecovery_->SetJsAbility(reinterpret_cast<uintptr_t>(workContext));
}
@@ -214,8 +230,24 @@ void JsUIAbility::SetAbilityContext(
[](napi_env, void *data, void *) {
HILOG_DEBUG("Finalizer for weak_ptr ability context is called");
delete static_cast<std::weak_ptr<AbilityRuntime::AbilityContext> *>(data);
},
nullptr, nullptr);
}, nullptr, nullptr);
HILOG_DEBUG("Init end.");
}
void JsUIAbility::CreateJSContext(napi_env env, napi_value &contextObj, int32_t screenMode)
{
if (screenMode == AAFwk::IDLE_SCREEN_MODE) {
contextObj = CreateJsAbilityContext(env, abilityContext_);
CHECK_POINTER(contextObj);
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
env, "application.AbilityContext", &contextObj, 1).release());
} else {
contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
abilityContext_, nullptr, screenMode);
CHECK_POINTER(contextObj);
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
env, "application.EmbeddableUIAbilityContext", &contextObj, 1).release());
}
}
void JsUIAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
@@ -703,9 +735,9 @@ void JsUIAbility::DoOnForegroundForSceneIsNull(const Want &want)
}
auto option = GetWindowOption(want);
Rosen::WMError ret = Rosen::WMError::WM_OK;
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
abilityContext_->SetWeakSessionToken(sessionInfo_->sessionToken);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionInfo_->sessionToken);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken_ != nullptr) {
abilityContext_->SetWeakSessionToken(sessionToken_);
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option, sessionToken_);
} else {
ret = scene_->Init(displayId, abilityContext_, sceneListener_, option);
}
@@ -283,6 +283,11 @@ int AbilityThread::CreateModalUIExtension(const Want &want)
return ERR_INVALID_VALUE;
}
void AbilityThread::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
{
HILOG_DEBUG("called");
}
#ifdef ABILITY_COMMAND_FOR_TEST
int AbilityThread::BlockAbility()
{
@@ -48,8 +48,8 @@ bool AbilityWindow::InitWindow(std::shared_ptr<AbilityRuntime::AbilityContext> &
windowScene_ = std::make_shared<Rosen::WindowScene>();
}
Rosen::WMError ret = Rosen::WMError::WM_OK;
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionInfo_ != nullptr) {
ret = windowScene_->Init(displayId, abilityContext, listener, option, sessionInfo_->sessionToken);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && sessionToken_ != nullptr) {
ret = windowScene_->Init(displayId, abilityContext, listener, option, sessionToken_);
} else {
ret = windowScene_->Init(displayId, abilityContext, listener, option);
}
@@ -186,9 +186,9 @@ ErrCode AbilityWindow::SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMa
}
#endif
void AbilityWindow::SetSessionInfo(sptr<AAFwk::SessionInfo> &sessionInfo)
void AbilityWindow::SetSessionToken(sptr<IRemoteObject> sessionToken)
{
sessionInfo_ = sessionInfo;
sessionToken_ = sessionToken;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -110,17 +110,17 @@ void JsActionExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t
jsUIExtensionBase_->OnCommand(want, restart, startId);
}
void JsActionExtension::OnForeground(const Want &want)
void JsActionExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HILOG_DEBUG("called.");
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
Extension::OnForeground(want);
Extension::OnForeground(want, sessionInfo);
if (jsUIExtensionBase_ == nullptr) {
HILOG_ERROR("jsUIExtensionBase_ is nullptr");
return;
}
jsUIExtensionBase_->OnForeground(want);
jsUIExtensionBase_->OnForeground(want, sessionInfo);
}
void JsActionExtension::OnBackground()
@@ -18,8 +18,10 @@
#include "module_checker_delegate.h"
#include "utils/log.h"
bool AppModuleChecker::CheckModuleLoadable(const char* moduleName)
bool AppModuleChecker::CheckModuleLoadable(const char *moduleName,
std::unique_ptr<ApiAllowListChecker> &apiAllowListChecker)
{
apiAllowListChecker = nullptr;
HILOG_INFO("check blocklist, moduleName = %{public}s, processExtensionType_ = %{public}d",
moduleName, static_cast<int32_t>(processExtensionType_));
const auto& blockListIter = moduleBlocklist_.find(processExtensionType_);
@@ -403,10 +403,11 @@ void JsAutoFillExtension::OnCommand(const AAFwk::Want &want, bool restart, int s
HILOG_DEBUG("End.");
}
void JsAutoFillExtension::OnForeground(const Want &want)
void JsAutoFillExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HILOG_DEBUG("Called.");
Extension::OnForeground(want);
Extension::OnForeground(want, sessionInfo);
ForegroundWindow(want, sessionInfo);
HandleScope handleScope(jsRuntime_);
CallObjectMethod("onForeground");
}
@@ -121,7 +121,7 @@ void ChildProcessManager::HandleSigChild(int32_t signo)
ChildProcessManagerErrorCode ChildProcessManager::PreCheck()
{
if (!AAFwk::AppUtils::GetInstance().JudgeMultiProcessModelDevice()) {
if (!AAFwk::AppUtils::GetInstance().JudgePCDevice()) {
HILOG_ERROR("Multi process model is not enabled");
return ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED;
}
@@ -110,7 +110,7 @@ void Extension::OnCommandWindow(const AAFwk::Want &want, const sptr<AAFwk::Sessi
HILOG_DEBUG("call");
}
void Extension::OnForeground(const AAFwk::Want &want)
void Extension::OnForeground(const AAFwk::Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("extension:%{public}s.", abilityInfo_->name.c_str());
@@ -91,7 +91,10 @@ void ExtensionImpl::HandleExtensionTransaction(const Want &want, const AAFwk::Li
break;
}
case AAFwk::ABILITY_STATE_FOREGROUND_NEW: {
Foreground(want);
if (lifecycleState_ == AAFwk::ABILITY_STATE_INITIAL) {
Start(want, sessionInfo);
}
Foreground(want, sessionInfo);
break;
}
case AAFwk::ABILITY_STATE_BACKGROUND_NEW: {
@@ -423,7 +426,7 @@ void ExtensionImpl::SendResult(int requestCode, int resultCode, const Want &resu
HILOG_DEBUG("end.");
}
void ExtensionImpl::Foreground(const Want &want)
void ExtensionImpl::Foreground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HILOG_DEBUG("ExtensionImpl::Foreground begin");
if (extension_ == nullptr) {
@@ -431,7 +434,7 @@ void ExtensionImpl::Foreground(const Want &want)
return;
}
extension_->OnForeground(want);
extension_->OnForeground(want, sessionInfo);
lifecycleState_ = AAFwk::ABILITY_STATE_FOREGROUND_NEW;
}
@@ -1521,5 +1521,14 @@ int FAAbilityThread::CreateModalUIExtension(const Want &want)
}
return currentAbility_->CreateModalUIExtension(want);
}
void FAAbilityThread::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
{
if (currentAbility_ == nullptr) {
HILOG_ERROR("current ability is nullptr");
return;
}
currentAbility_->UpdateSessionToken(sessionToken);
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -110,17 +110,17 @@ void JsShareExtension::OnCommand(const AAFwk::Want &want, bool restart, int32_t
jsUIExtensionBase_->OnCommand(want, restart, startId);
}
void JsShareExtension::OnForeground(const Want &want)
void JsShareExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HILOG_DEBUG("called.");
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
Extension::OnForeground(want);
Extension::OnForeground(want, sessionInfo);
if (jsUIExtensionBase_ == nullptr) {
HILOG_ERROR("jsUIExtensionBase_ is nullptr");
return;
}
jsUIExtensionBase_->OnForeground(want);
jsUIExtensionBase_->OnForeground(want, sessionInfo);
}
void JsShareExtension::OnBackground()
@@ -54,14 +54,18 @@ UIAbility *UIAbility::Create(const std::unique_ptr<Runtime> &runtime)
}
}
void UIAbility::Init(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo,
void UIAbility::Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
const std::shared_ptr<AppExecFwk::OHOSApplication> application,
std::shared_ptr<AppExecFwk::AbilityHandler> &handler, const sptr<IRemoteObject> &token)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("Begin.");
if (record == nullptr) {
HILOG_ERROR("AbilityLocalRecord is nullptr.");
return;
}
application_ = application;
abilityInfo_ = abilityInfo;
abilityInfo_ = record->GetAbilityInfo();
handler_ = handler;
token_ = token;
#ifdef SUPPORT_GRAPHICS
@@ -124,9 +128,11 @@ void UIAbility::OnStart(const AAFwk::Want &want, sptr<AppExecFwk::SessionInfo> s
securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false);
(const_cast<AAFwk::Want &>(want)).RemoveParam(DLP_PARAMS_SECURITY_FLAG);
SetWant(want);
sessionInfo_ = sessionInfo;
HILOG_DEBUG("Begin ability is %{public}s.", abilityInfo_->name.c_str());
#ifdef SUPPORT_GRAPHICS
if (sessionInfo != nullptr) {
sessionToken_ = sessionInfo->sessionToken;
}
OnStartForSupportGraphics(want);
#endif
if (abilityLifecycleExecutor_ == nullptr) {
@@ -1008,6 +1014,17 @@ int UIAbility::CreateModalUIExtension(const AAFwk::Want &want)
}
return abilityContextImpl->CreateModalUIExtensionWithApp(want);
}
void UIAbility::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
{
sessionToken_ = sessionToken;
auto abilityContextImpl = GetAbilityContext();
if (abilityContextImpl == nullptr) {
HILOG_ERROR("abilityContext is nullptr");
return;
}
abilityContextImpl->SetWeakSessionToken(sessionToken);
}
#endif
} // namespace AbilityRuntime
} // namespace OHOS
@@ -46,7 +46,7 @@ void UIAbilityImpl::Init(const std::shared_ptr<AppExecFwk::OHOSApplication> &app
ability_->SetSceneListener(sptr<WindowLifeCycleImpl>(
new (std::nothrow) WindowLifeCycleImpl(token_, shared_from_this())));
#endif
ability_->Init(record->GetAbilityInfo(), application, handler, token);
ability_->Init(record, application, handler, token);
lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL;
abilityLifecycleCallbacks_ = application;
HILOG_DEBUG("End.");
@@ -694,5 +694,14 @@ int UIAbilityThread::CreateModalUIExtension(const Want &want)
}
return currentAbility_->CreateModalUIExtension(want);
}
void UIAbilityThread::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
{
if (currentAbility_ == nullptr) {
HILOG_ERROR("current ability is nullptr");
return;
}
currentAbility_->UpdateSessionToken(sessionToken);
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -0,0 +1,542 @@
/*
* Copyright (c) 2023 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_embeddable_ui_ability_context.h"
#include <chrono>
#include <cstdint>
#include <string>
#include "ability_manager_client.h"
#include "event_handler.h"
#include "hilog_wrapper.h"
#include "js_context_utils.h"
#include "js_data_struct_converter.h"
#include "js_error_utils.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi/native_api.h"
#include "napi_common_ability.h"
#include "napi_common_want.h"
#include "napi_common_util.h"
#include "napi_common_start_options.h"
#include "want.h"
namespace OHOS {
namespace AbilityRuntime {
#define CHECK_POINTER_RETURN(object) \
if (!(object)) { \
HILOG_ERROR("Context is nullptr"); \
return nullptr; \
}
namespace {
const std::string ERR_MSG_NOT_SUPPORT = "Not support the interface in half screen mode of atomic service.";
}
JsEmbeddableUIAbilityContext::JsEmbeddableUIAbilityContext(const std::shared_ptr<AbilityContext>& uiAbiContext,
const std::shared_ptr<UIExtensionContext>& uiExtContext, int32_t screenMode)
{
jsAbilityContext_ = std::make_shared<JsAbilityContext>(uiAbiContext);
jsUIExtensionContext_ = std::make_shared<JsUIExtensionContext>(uiExtContext);
screenMode_ = screenMode;
}
void JsEmbeddableUIAbilityContext::Finalizer(napi_env env, void* data, void* hint)
{
HILOG_DEBUG("The Finalizer of embeddable UI ability context is called.");
std::unique_ptr<JsEmbeddableUIAbilityContext>(static_cast<JsEmbeddableUIAbilityContext*>(data));
}
napi_value JsEmbeddableUIAbilityContext::StartAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbility);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityForResult(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityForResult);
}
napi_value JsEmbeddableUIAbilityContext::ConnectAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnConnectAbility);
}
napi_value JsEmbeddableUIAbilityContext::DisconnectAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnDisconnectAbility);
}
napi_value JsEmbeddableUIAbilityContext::TerminateSelf(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnTerminateSelf);
}
napi_value JsEmbeddableUIAbilityContext::TerminateSelfWithResult(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnTerminateSelfWithResult);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityAsCaller(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityAsCaller);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityWithAccount(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityWithAccount);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityByCall(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityByCall);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityForResultWithAccount(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityForResultWithAccount);
}
napi_value JsEmbeddableUIAbilityContext::StartServiceExtensionAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartExtensionAbility);
}
napi_value JsEmbeddableUIAbilityContext::StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartExtensionAbilityWithAccount);
}
napi_value JsEmbeddableUIAbilityContext::StopServiceExtensionAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStopExtensionAbility);
}
napi_value JsEmbeddableUIAbilityContext::StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStopExtensionAbilityWithAccount);
}
napi_value JsEmbeddableUIAbilityContext::ConnectAbilityWithAccount(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnConnectAbilityWithAccount);
}
napi_value JsEmbeddableUIAbilityContext::RestoreWindowStage(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnRestoreWindowStage);
}
napi_value JsEmbeddableUIAbilityContext::IsTerminating(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnIsTerminating);
}
napi_value JsEmbeddableUIAbilityContext::StartRecentAbility(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartRecentAbility);
}
napi_value JsEmbeddableUIAbilityContext::RequestDialogService(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnRequestDialogService);
}
napi_value JsEmbeddableUIAbilityContext::ReportDrawnCompleted(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnReportDrawnCompleted);
}
napi_value JsEmbeddableUIAbilityContext::SetMissionContinueState(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionContinueState);
}
napi_value JsEmbeddableUIAbilityContext::StartAbilityByType(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityByType);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability in half screen mode.");
CHECK_POINTER_RETURN(jsUIExtensionContext_);
return jsUIExtensionContext_->OnStartAbility(env, info);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability for result in half screen mode.");
CHECK_POINTER_RETURN(jsUIExtensionContext_);
return jsUIExtensionContext_->OnStartAbilityForResult(env, info);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityForResult(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnConnectAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Connect ability in half screen mode.");
CHECK_POINTER_RETURN(jsUIExtensionContext_);
return jsUIExtensionContext_->OnConnectAbility(env, info);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnConnectAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Disconnect ability in half screen mode.");
CHECK_POINTER_RETURN(jsUIExtensionContext_);
return jsUIExtensionContext_->OnDisconnectAbility(env, info);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnDisconnectAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Terminate self in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnTerminateSelf(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Terminate self with result in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnTerminateSelfWithResult(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability as caller in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityAsCaller(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability with account in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityWithAccount(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability by caller in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityByCall(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResultWithAccount(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability for result in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityForResultWithAccount(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start extension in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartExtensionAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start extensionin with account in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartExtensionAbilityWithAccount(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Stop extensionin in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStopExtensionAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Stop extensionin with account in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStopExtensionAbilityWithAccount(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnConnectAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Connect ability with account in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnConnectAbilityWithAccount(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnRestoreWindowStage(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Restore window stage with account in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnRestoreWindowStage(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnIsTerminating(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Get terminating state in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnIsTerminating(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartRecentAbility(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start recent ability in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartRecentAbility(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnRequestDialogService(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Request dialog service in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnRequestDialogService(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnReportDrawnCompleted(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Report drawn completed in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnReportDrawnCompleted(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Set mission continue state in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnSetMissionContinueState(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Start ability by type in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnStartAbilityByType(env, info);
}
#ifdef SUPPORT_GRAPHICS
napi_value JsEmbeddableUIAbilityContext::SetMissionLabel(napi_env env, napi_callback_info info)
{
HILOG_INFO("Set mission label is called.");
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionLabel);
}
napi_value JsEmbeddableUIAbilityContext::SetMissionIcon(napi_env env, napi_callback_info info)
{
HILOG_INFO("Set mission icon is called.");
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionIcon);
}
napi_value JsEmbeddableUIAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Set mission label in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnSetMissionLabel(env, info);
}
napi_value JsEmbeddableUIAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& info)
{
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
HILOG_INFO("Set mission icon in half screen mode.");
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
return CreateJsUndefined(env);
}
CHECK_POINTER_RETURN(jsAbilityContext_);
return jsAbilityContext_->OnSetMissionIcon(env, info);
}
#endif
void JsEmbeddableUIAbilityContext::WrapJsUIAbilityContext(napi_env env,
std::shared_ptr<AbilityContext> uiAbiContext, napi_value &objValue, int32_t screenMode)
{
if (uiAbiContext == nullptr) {
HILOG_ERROR("UI ability context is nullptr");
return;
}
objValue = CreateJsBaseContext(env, uiAbiContext);
std::unique_ptr<JsEmbeddableUIAbilityContext> jsContext = std::make_unique<JsEmbeddableUIAbilityContext>(
uiAbiContext, nullptr, screenMode);
napi_wrap(env, objValue, jsContext.release(), Finalizer, nullptr, nullptr);
auto abilityInfo = uiAbiContext->GetAbilityInfo();
if (abilityInfo != nullptr) {
napi_set_named_property(env, objValue, "abilityInfo", CreateJsAbilityInfo(env, *abilityInfo));
}
auto configuration = uiAbiContext->GetConfiguration();
if (configuration != nullptr) {
napi_set_named_property(env, objValue, "config", CreateJsConfiguration(env, *configuration));
}
}
void JsEmbeddableUIAbilityContext::WrapJsUIExtensionContext(napi_env env,
std::shared_ptr<UIExtensionContext> uiExtContext, napi_value &objValue, int32_t screenMode)
{
if (uiExtContext == nullptr) {
HILOG_ERROR("UI extension context is nullptr");
return;
}
objValue = CreateJsBaseContext(env, uiExtContext);
std::unique_ptr<JsEmbeddableUIAbilityContext> jsContext = std::make_unique<JsEmbeddableUIAbilityContext>(
nullptr, uiExtContext, screenMode);
napi_wrap(env, objValue, jsContext.release(), Finalizer, nullptr, nullptr);
auto abilityInfo = uiExtContext->GetAbilityInfo();
if (abilityInfo != nullptr) {
napi_set_named_property(env, objValue, "abilityInfo", CreateJsAbilityInfo(env, *abilityInfo));
}
auto configuration = uiExtContext->GetConfiguration();
if (configuration != nullptr) {
napi_set_named_property(env, objValue, "config", CreateJsConfiguration(env, *configuration));
}
}
napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi_env env,
std::shared_ptr<AbilityContext> uiAbiContext, std::shared_ptr<UIExtensionContext> uiExtContext, int32_t screenMode)
{
HILOG_DEBUG("Create JS embeddable UIAbility context begin.");
napi_value objValue = nullptr;
if (screenMode == AAFwk::FULL_SCREEN_MODE) {
WrapJsUIAbilityContext(env, uiAbiContext, objValue, screenMode);
} else if (screenMode == AAFwk::HALF_SCREEN_MODE) {
WrapJsUIExtensionContext(env, uiExtContext, objValue, screenMode);
}
const char* moduleName = "JsEmbeddableUIAbilityContext";
BindNativeFunction(env, objValue, "startAbility", moduleName, StartAbility);
BindNativeFunction(env, objValue, "startAbilityForResult", moduleName, StartAbilityForResult);
BindNativeFunction(env, objValue, "connectServiceExtensionAbility", moduleName, ConnectAbility);
BindNativeFunction(env, objValue, "disconnectServiceExtensionAbility", moduleName, DisconnectAbility);
BindNativeFunction(env, objValue, "terminateSelf", moduleName, TerminateSelf);
BindNativeFunction(env, objValue, "terminateSelfWithResult", moduleName, TerminateSelfWithResult);
BindNativeFunction(env, objValue, "startAbilityAsCaller", moduleName, StartAbilityAsCaller);
BindNativeFunction(env, objValue, "startAbilityWithAccount", moduleName, StartAbilityWithAccount);
BindNativeFunction(env, objValue, "startAbilityByCall", moduleName, StartAbilityByCall);
BindNativeFunction(env, objValue, "startAbilityForResultWithAccount", moduleName,
StartAbilityForResultWithAccount);
BindNativeFunction(env, objValue, "startServiceExtensionAbility", moduleName, StartServiceExtensionAbility);
BindNativeFunction(env, objValue, "startServiceExtensionAbilityWithAccount", moduleName,
StartServiceExtensionAbilityWithAccount);
BindNativeFunction(env, objValue, "stopServiceExtensionAbility", moduleName, StopServiceExtensionAbility);
BindNativeFunction(env, objValue, "stopServiceExtensionAbilityWithAccount", moduleName,
StopServiceExtensionAbilityWithAccount);
BindNativeFunction(env, objValue, "connectServiceExtensionAbilityWithAccount", moduleName,
ConnectAbilityWithAccount);
BindNativeFunction(env, objValue, "restoreWindowStage", moduleName, RestoreWindowStage);
BindNativeFunction(env, objValue, "isTerminating", moduleName, IsTerminating);
BindNativeFunction(env, objValue, "startRecentAbility", moduleName, StartRecentAbility);
BindNativeFunction(env, objValue, "requestDialogService", moduleName, RequestDialogService);
BindNativeFunction(env, objValue, "reportDrawnCompleted", moduleName, ReportDrawnCompleted);
BindNativeFunction(env, objValue, "setMissionContinueState", moduleName, SetMissionContinueState);
BindNativeFunction(env, objValue, "startAbilityByType", moduleName, StartAbilityByType);
#ifdef SUPPORT_GRAPHICS
BindNativeFunction(env, objValue, "setMissionLabel", moduleName, SetMissionLabel);
BindNativeFunction(env, objValue, "setMissionIcon", moduleName, SetMissionIcon);
#endif
return objValue;
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -19,6 +19,7 @@
#include "ability_info.h"
#include "ability_manager_client.h"
#include "ability_start_setting.h"
#include "configuration_utils.h"
#include "connection_manager.h"
#include "context.h"
#include "hitrace_meter.h"
@@ -26,12 +27,14 @@
#include "insight_intent_executor_info.h"
#include "insight_intent_executor_mgr.h"
#include "int_wrapper.h"
#include "js_embeddable_ui_ability_context.h"
#include "js_extension_common.h"
#include "js_extension_context.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "js_ui_extension_content_session.h"
#include "js_ui_extension_context.h"
#include "js_utils.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "napi_common_configuration.h"
@@ -48,10 +51,10 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
}
napi_value AttachUIExtensionContext(napi_env env, void *value, void *)
napi_value AttachUIExtensionContext(napi_env env, void *value, void *extValue)
{
HILOG_DEBUG("AttachUIExtensionContext");
if (value == nullptr) {
if (value == nullptr || extValue == nullptr) {
HILOG_ERROR("invalid parameter.");
return nullptr;
}
@@ -61,14 +64,30 @@ napi_value AttachUIExtensionContext(napi_env env, void *value, void *)
HILOG_ERROR("invalid context.");
return nullptr;
}
napi_value object = JsUIExtensionContext::CreateJsUIExtensionContext(env, ptr);
auto contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
&object, 1)->GetNapiValue();
auto screenModePtr = reinterpret_cast<std::weak_ptr<int32_t> *>(extValue)->lock();
if (screenModePtr == nullptr) {
HILOG_ERROR("Invalid screenModePtr.");
return nullptr;
}
napi_value contextObj = nullptr;
if (*screenModePtr == AAFwk::IDLE_SCREEN_MODE) {
auto uiExtObject = JsUIExtensionContext::CreateJsUIExtensionContext(env, ptr);
CHECK_POINTER_AND_RETURN(uiExtObject, nullptr);
contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
&uiExtObject, 1)->GetNapiValue();
} else {
auto emUIObject = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
nullptr, ptr, *screenModePtr);
CHECK_POINTER_AND_RETURN(emUIObject, nullptr);
contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.EmbeddableUIAbilityContext",
&emUIObject, 1)->GetNapiValue();
}
if (contextObj == nullptr) {
HILOG_ERROR("load context error.");
return nullptr;
}
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, value, nullptr);
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc,
AttachUIExtensionContext, value, extValue);
auto workContext = new (std::nothrow) std::weak_ptr<UIExtensionContext>(ptr);
napi_wrap(env, contextObj, workContext,
[](napi_env, void *data, void *) {
@@ -137,6 +156,7 @@ void JsUIExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
const sptr<IRemoteObject> &token)
{
HILOG_DEBUG("JsUIExtension begin init");
CHECK_POINTER(record);
UIExtension::Init(record, application, handler, token);
if (Extension::abilityInfo_ == nullptr || Extension::abilityInfo_->srcEntrance.empty()) {
HILOG_ERROR("JsUIExtension Init abilityInfo error");
@@ -165,13 +185,30 @@ void JsUIExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
return;
}
BindContext(env, obj);
BindContext(env, obj, record->GetWant());
SetExtensionCommon(
JsExtensionCommon::Create(jsRuntime_, static_cast<NativeReference&>(*jsObj_), shellContextRef_));
}
void JsUIExtension::BindContext(napi_env env, napi_value obj)
void JsUIExtension::CreateJSContext(napi_env env, napi_value &contextObj,
std::shared_ptr<UIExtensionContext> context, int32_t screenMode)
{
if (screenMode == AAFwk::IDLE_SCREEN_MODE) {
contextObj = JsUIExtensionContext::CreateJsUIExtensionContext(env, context);
CHECK_POINTER(contextObj);
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
&contextObj, ARGC_ONE);
} else {
contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
nullptr, context, screenMode);
CHECK_POINTER(contextObj);
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.EmbeddableUIAbilityContext",
&contextObj, ARGC_ONE);
}
}
void JsUIExtension::BindContext(napi_env env, napi_value obj, std::shared_ptr<AAFwk::Want> want)
{
auto context = GetContext();
if (context == nullptr) {
@@ -179,16 +216,15 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
return;
}
HILOG_DEBUG("BindContext CreateJsUIExtensionContext.");
napi_value contextObj = JsUIExtensionContext::CreateJsUIExtensionContext(env, context);
if (contextObj == nullptr) {
HILOG_ERROR("Create js ui extension context error.");
if (want == nullptr) {
HILOG_ERROR("Want info is null.");
return;
}
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
&contextObj, ARGC_ONE);
int32_t screenMode = want->GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
napi_value contextObj = nullptr;
CreateJSContext(env, contextObj, context, screenMode);
if (shellContextRef_ == nullptr) {
HILOG_ERROR("Failed to get LoadSystemModuleByEngine");
HILOG_ERROR("Failed to get LoadSystemModuleByEngine.");
return;
}
contextObj = shellContextRef_->GetNapiValue();
@@ -197,8 +233,12 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
return;
}
auto workContext = new (std::nothrow) std::weak_ptr<UIExtensionContext>(context);
CHECK_POINTER(workContext);
screenModePtr_ = std::make_shared<int32_t>(screenMode);
auto workScreenMode = new (std::nothrow) std::weak_ptr<int32_t>(screenModePtr_);
CHECK_POINTER(workScreenMode);
napi_coerce_to_native_binding_object(
env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, workContext, nullptr);
env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, workContext, workScreenMode);
context->Bind(jsRuntime_, shellContextRef_.get());
napi_set_named_property(env, obj, "context", contextObj);
napi_wrap(env, contextObj, workContext,
@@ -207,7 +247,6 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
delete static_cast<std::weak_ptr<UIExtensionContext>*>(data);
},
nullptr, nullptr);
HILOG_DEBUG("Init end.");
}
@@ -528,11 +567,13 @@ void JsUIExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId
HILOG_DEBUG("JsUIExtension OnCommand end.");
}
void JsUIExtension::OnForeground(const Want &want)
void JsUIExtension::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("JsUIExtension OnForeground begin.");
Extension::OnForeground(want);
Extension::OnForeground(want, sessionInfo);
ForegroundWindow(want, sessionInfo);
HandleScope handleScope(jsRuntime_);
CallObjectMethod("onForeground");
@@ -585,8 +626,15 @@ bool JsUIExtension::HandleSessionCreate(const AAFwk::Want &want, const sptr<AAFw
napi_create_reference(env, nativeContentSession, 1, &ref);
contentSessions_.emplace(
componentId, std::shared_ptr<NativeReference>(reinterpret_cast<NativeReference*>(ref)));
napi_value argv[] = {napiWant, nativeContentSession};
CallObjectMethod("onSessionCreate", argv, ARGC_TWO);
int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
if (screenMode == AAFwk::HALF_SCREEN_MODE) {
screenMode_ = AAFwk::HALF_SCREEN_MODE;
napi_value argv[] = {nullptr};
CallObjectMethod("onWindowStageCreate", argv, ARGC_ONE);
} else {
napi_value argv[] = {napiWant, nativeContentSession};
CallObjectMethod("onSessionCreate", argv, ARGC_TWO);
}
uiWindowMap_[componentId] = uiWindow;
if (context->GetWindow() == nullptr) {
context->SetWindow(uiWindow);
@@ -647,8 +695,13 @@ void JsUIExtension::DestroyWindow(const sptr<AAFwk::SessionInfo> &sessionInfo)
}
if (contentSessions_.find(componentId) != contentSessions_.end() && contentSessions_[componentId] != nullptr) {
HandleScope handleScope(jsRuntime_);
napi_value argv[] = {contentSessions_[componentId]->GetNapiValue()};
CallObjectMethod("onSessionDestroy", argv, ARGC_ONE);
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
screenMode_ = AAFwk::IDLE_SCREEN_MODE;
CallObjectMethod("onWindowStageDestroy");
} else {
napi_value argv[] = {contentSessions_[componentId]->GetNapiValue()};
CallObjectMethod("onSessionDestroy", argv, ARGC_ONE);
}
}
auto& uiWindow = uiWindowMap_[componentId];
if (uiWindow) {
@@ -788,6 +841,10 @@ void JsUIExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& conf
HILOG_ERROR("Failed to get context");
return;
}
auto configUtils = std::make_shared<ConfigurationUtils>();
configUtils->UpdateGlobalConfig(configuration, context->GetResourceManager());
auto fullConfig = context->GetConfiguration();
if (!fullConfig) {
HILOG_ERROR("configuration is nullptr.");
@@ -20,6 +20,7 @@
#include "ability_info.h"
#include "ability_manager_client.h"
#include "configuration_utils.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "insight_intent_executor_info.h"
@@ -365,9 +366,10 @@ void JsUIExtensionBase::OnCommand(const AAFwk::Want &want, bool restart, int32_t
CallObjectMethod("onRequest", argv, ARGC_TWO);
}
void JsUIExtensionBase::OnForeground(const Want &want)
void JsUIExtensionBase::OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
HILOG_DEBUG("called");
ForegroundWindow(want, sessionInfo);
HandleScope handleScope(jsRuntime_);
CallObjectMethod("onForeground");
}
@@ -540,6 +542,10 @@ void JsUIExtensionBase::OnConfigurationUpdated(const AppExecFwk::Configuration &
HILOG_ERROR("context is nullptr");
return;
}
auto configUtils = std::make_shared<ConfigurationUtils>();
configUtils->UpdateGlobalConfig(configuration, context_->GetResourceManager());
HandleScope handleScope(jsRuntime_);
auto fullConfig = context_->GetConfiguration();
if (!fullConfig) {
@@ -43,7 +43,7 @@ constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
} // namespace
static std::map<ConnectionKey, sptr<JSUIExtensionConnection>, key_compare> g_connects;
static std::map<UIExtensionConnectionKey, sptr<JSUIExtensionConnection>, key_compare> g_connects;
static int64_t g_serialNumber = 0;
void RemoveConnection(int64_t connectId)
{
@@ -86,7 +86,7 @@ bool CheckConnectionParam(napi_env env, napi_value value, sptr<JSUIExtensionConn
return false;
}
connection->SetJsConnectionObject(value);
ConnectionKey key;
UIExtensionConnectionKey key;
key.id = g_serialNumber;
key.want = want;
connection->SetConnectionId(key.id);
@@ -155,6 +155,11 @@ napi_value JsUIExtensionContext::OnStartAbility(napi_env env, NapiCallbackInfo&
return CreateJsUndefined(env);
}
if (want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE) == AAFwk::HALF_SCREEN_MODE) {
HILOG_ERROR("Not support half screen pulling up half screen");
return CreateJsUndefined(env);
}
NapiAsyncTask::CompleteCallback complete =
[weak = context_, want, startOptions, unwrapArgc](napi_env env, NapiAsyncTask& task, int32_t status) {
HILOG_DEBUG("startAbility begin");
+2
View File
@@ -94,6 +94,7 @@ ohos_shared_library("appkit_native") {
include_dirs = [
"native",
"${ability_runtime_path}/interfaces/kits/native/appkit",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/dfr",
@@ -151,6 +152,7 @@ ohos_shared_library("appkit_native") {
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment",
"${ability_runtime_path}/utils/global/freeze:freeze_util",
"${ability_runtime_services_path}/common:app_util",
@@ -699,5 +699,17 @@ ErrCode BundleMgrHelper::GetJsonProfile(ProfileType profileType, const std::stri
return bundleMgr->GetJsonProfile(profileType, bundleName, moduleName, profile, userId);
}
ErrCode BundleMgrHelper::CleanObsoleteBundleTempFiles()
{
HILOG_DEBUG("Called.");
auto bundleMgr = Connect();
if (bundleMgr == nullptr) {
HILOG_ERROR("Failed to connect.");
return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR;
}
return bundleMgr->CleanObsoleteBundleTempFiles();
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -349,6 +349,20 @@ std::string ApplicationContext::GetTempDir()
return (contextImpl_ != nullptr) ? contextImpl_->GetTempDir() : "";
}
void ApplicationContext::GetAllTempDir(std::vector<std::string> &tempPaths)
{
if (contextImpl_ == nullptr) {
HILOG_ERROR("The contextimpl is nullptr");
return;
}
contextImpl_->GetAllTempDir(tempPaths);
}
std::string ApplicationContext::GetResourceDir()
{
return (contextImpl_ != nullptr) ? contextImpl_->GetResourceDir() : "";
}
std::string ApplicationContext::GetFilesDir()
{
return (contextImpl_ != nullptr) ? contextImpl_->GetFilesDir() : "";
@@ -68,6 +68,7 @@ const std::string ContextImpl::CONTEXT_TEMP("/temp");
const std::string ContextImpl::CONTEXT_FILES("/files");
const std::string ContextImpl::CONTEXT_HAPS("/haps");
const std::string ContextImpl::CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"};
const std::string ContextImpl::CONTEXT_RESOURCE_END = "/resources/resfile";
Global::Resource::DeviceType ContextImpl::deviceType_ = Global::Resource::DeviceType::DEVICE_NOT_SET;
const std::string OVERLAY_STATE_CHANGED = "usual.event.OVERLAY_STATE_CHANGED";
const int32_t TYPE_RESERVE = 1;
@@ -257,6 +258,51 @@ std::string ContextImpl::GetTempDir()
return dir;
}
void ContextImpl::GetAllTempDir(std::vector<std::string> &tempPaths)
{
// Application temp dir
auto appTemp = GetTempDir();
if (OHOS::FileExists(appTemp)) {
tempPaths.push_back(appTemp);
}
// Module dir
if (applicationInfo_ == nullptr) {
HILOG_ERROR("The application info is empty");
return;
}
std::string baseDir;
if (IsCreateBySystemApp()) {
baseDir = CONTEXT_DATA_APP + currArea_ + CONTEXT_FILE_SEPARATOR + std::to_string(GetCurrentAccountId()) +
CONTEXT_FILE_SEPARATOR + CONTEXT_BASE + CONTEXT_FILE_SEPARATOR + GetBundleName();
} else {
baseDir = CONTEXT_DATA_STORAGE + currArea_ + CONTEXT_FILE_SEPARATOR + CONTEXT_BASE;
}
for (const auto &moudleItem: applicationInfo_->moduleInfos) {
auto moudleTemp = baseDir + CONTEXT_HAPS + CONTEXT_FILE_SEPARATOR + moudleItem.moduleName + CONTEXT_TEMP;
if (!OHOS::FileExists(moudleTemp)) {
HILOG_WARN("The application moudle[%{public}s] temp path not exists is empty, the path is %{public}s",
moudleItem.moduleName.c_str(), moudleTemp.c_str());
continue;
}
tempPaths.push_back(moudleTemp);
}
}
std::string ContextImpl::GetResourceDir()
{
std::shared_ptr<AppExecFwk::HapModuleInfo> hapModuleInfoPtr = GetHapModuleInfo();
if (hapModuleInfoPtr == nullptr || hapModuleInfoPtr->moduleName.empty()) {
return "";
}
std::string dir = std::string(LOCAL_CODE_PATH) + CONTEXT_FILE_SEPARATOR +
hapModuleInfoPtr->moduleName + CONTEXT_RESOURCE_END;
if (OHOS::FileExists(dir)) {
return dir;
}
return "";
}
std::string ContextImpl::GetFilesDir()
{
std::string dir = GetBaseDir() + CONTEXT_FILES;
@@ -573,17 +619,7 @@ void ContextImpl::InitResourceManager(const AppExecFwk::BundleInfo &bundleInfo,
HILOG_ERROR("InitResourceManager appContext is nullptr");
return;
}
std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
std::string hapPath;
std::vector<std::string> overlayPaths;
int32_t appType;
if (bundleInfo.applicationInfo.codePath == std::to_string(TYPE_RESERVE)) {
appType = TYPE_RESERVE;
} else if (bundleInfo.applicationInfo.codePath == std::to_string(TYPE_OTHERS)) {
appType = TYPE_OTHERS;
} else {
appType = 0;
}
if (bundleInfo.applicationInfo.codePath == std::to_string(TYPE_RESERVE) ||
bundleInfo.applicationInfo.codePath == std::to_string(TYPE_OTHERS)) {
std::shared_ptr<Global::Resource::ResourceManager> resourceManager = InitOthersResourceManagerInner(
@@ -148,6 +148,7 @@ napi_value JsApplicationContextUtils::OnSwitchArea(napi_env env, NapiCallbackInf
}
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
BindNativeProperty(env, object, "tempDir", GetTempDir);
BindNativeProperty(env, object, "resourceDir", GetResourceDir);
BindNativeProperty(env, object, "filesDir", GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
@@ -321,6 +322,23 @@ napi_value JsApplicationContextUtils::OnGetTempDir(napi_env env, NapiCallbackInf
return CreateJsValue(env, path);
}
napi_value JsApplicationContextUtils::GetResourceDir(napi_env env, napi_callback_info info)
{
HILOG_INFO("JsApplicationContextUtils::GetResourceDir is called");
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetResourceDir, APPLICATION_CONTEXT_NAME);
}
napi_value JsApplicationContextUtils::OnGetResourceDir(napi_env env, NapiCallbackInfo& info)
{
auto applicationContext = applicationContext_.lock();
if (!applicationContext) {
HILOG_WARN("applicationContext is already released");
return CreateJsUndefined(env);
}
std::string path = applicationContext->GetResourceDir();
return CreateJsValue(env, path);
}
napi_value JsApplicationContextUtils::GetFilesDir(napi_env env, napi_callback_info info)
{
HILOG_INFO("JsApplicationContextUtils::GetFilesDir is called");
@@ -1236,6 +1254,7 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_
{
BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir);
BindNativeProperty(env, object, "tempDir", JsApplicationContextUtils::GetTempDir);
BindNativeProperty(env, object, "resourceDir", JsApplicationContextUtils::GetResourceDir);
BindNativeProperty(env, object, "filesDir", JsApplicationContextUtils::GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", JsApplicationContextUtils::GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", JsApplicationContextUtils::GetDatabaseDir);
@@ -50,6 +50,7 @@ public:
napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetTempDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetResourceDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetFilesDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetDatabaseDir(napi_env env, NapiCallbackInfo& info);
@@ -59,6 +60,7 @@ public:
static napi_value GetCacheDir(napi_env env, napi_callback_info info);
static napi_value GetTempDir(napi_env env, napi_callback_info info);
static napi_value GetResourceDir(napi_env env, napi_callback_info info);
static napi_value GetFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDistributedFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDatabaseDir(napi_env env, napi_callback_info info);
@@ -129,6 +131,7 @@ napi_value JsBaseContext::OnSwitchArea(napi_env env, NapiCallbackInfo& info)
}
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
BindNativeProperty(env, object, "tempDir", GetTempDir);
BindNativeProperty(env, object, "resourceDir", GetResourceDir);
BindNativeProperty(env, object, "filesDir", GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
@@ -302,6 +305,23 @@ napi_value JsBaseContext::OnGetTempDir(napi_env env, NapiCallbackInfo& info)
return CreateJsValue(env, path);
}
napi_value JsBaseContext::GetResourceDir(napi_env env, napi_callback_info info)
{
HILOG_DEBUG("JsBaseContext::GetResourceDir is called");
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetResourceDir, BASE_CONTEXT_NAME);
}
napi_value JsBaseContext::OnGetResourceDir(napi_env env, NapiCallbackInfo& info)
{
auto context = context_.lock();
if (!context) {
HILOG_WARN("context is already released");
return CreateJsUndefined(env);
}
std::string path = context->GetResourceDir();
return CreateJsValue(env, path);
}
napi_value JsBaseContext::GetFilesDir(napi_env env, napi_callback_info info)
{
HILOG_DEBUG("JsBaseContext::GetFilesDir is called");
@@ -654,6 +674,7 @@ napi_value CreateJsBaseContext(napi_env env, std::shared_ptr<Context> context, b
BindNativeProperty(env, object, "cacheDir", JsBaseContext::GetCacheDir);
BindNativeProperty(env, object, "tempDir", JsBaseContext::GetTempDir);
BindNativeProperty(env, object, "resourceDir", JsBaseContext::GetResourceDir);
BindNativeProperty(env, object, "filesDir", JsBaseContext::GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", JsBaseContext::GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", JsBaseContext::GetDatabaseDir);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 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
@@ -96,13 +96,21 @@ bool ApplicationImpl::PerformBackground()
/**
* @brief Schedule the application to the APP_STATE_TERMINATED state.
*
* @param isLastProcess When it is the last application process, pass in true.
*
* @return Returns true if PerformTerminate is scheduled successfully;
* Returns false otherwise.
*/
bool ApplicationImpl::PerformTerminate()
bool ApplicationImpl::PerformTerminate(bool isLastProcess)
{
HILOG_DEBUG("ApplicationImpl::PerformTerminate called");
if (curState_ == APP_STATE_BACKGROUND && application_ != nullptr) {
if (application_ == nullptr) {
HILOG_ERROR("Application instance is nullptr");
return false;
}
application_->CleanAppTempData(isLastProcess);
if (curState_ == APP_STATE_BACKGROUND) {
application_->OnTerminate();
curState_ = APP_STATE_TERMINATED;
return true;
+69 -13
View File
@@ -116,8 +116,9 @@ enum class SignalType {
SIGNAL_JSHEAP_OLD,
SIGNAL_JSHEAP,
SIGNAL_JSHEAP_PRIV,
SIGNAL_START_SAMPLE,
SIGNAL_STOP_SAMPLE,
SIGNAL_NO_TRIGGERID,
SIGNAL_NO_TRIGGERID_PRIV,
SIGNAL_FORCE_FULLGC,
};
constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME";
@@ -506,18 +507,19 @@ void MainThread::ScheduleBackgroundApplication()
*
* @brief Schedule the terminate lifecycle of application.
*
* @param isLastProcess When it is the last application process, pass in true.
*/
void MainThread::ScheduleTerminateApplication()
void MainThread::ScheduleTerminateApplication(bool isLastProcess)
{
HILOG_DEBUG("ScheduleTerminateApplication");
wptr<MainThread> weak = this;
auto task = [weak]() {
auto task = [weak, isLastProcess]() {
auto appThread = weak.promote();
if (appThread == nullptr) {
HILOG_ERROR("appThread is nullptr, HandleTerminateApplication failed.");
return;
}
appThread->HandleTerminateApplication();
appThread->HandleTerminateApplication(isLastProcess);
};
if (!mainHandler_->PostTask(task, "MainThread:TerminateApplication")) {
HILOG_ERROR("MainThread::ScheduleTerminateApplication PostTask task failed");
@@ -1967,8 +1969,9 @@ void MainThread::HandleBackgroundApplication()
*
* @brief Terminate the application.
*
* @param isLastProcess When it is the last application process, pass in true.
*/
void MainThread::HandleTerminateApplication()
void MainThread::HandleTerminateApplication(bool isLastProcess)
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
HILOG_DEBUG("MainThread::handleTerminateApplication called start.");
@@ -1977,7 +1980,7 @@ void MainThread::HandleTerminateApplication()
return;
}
if (!applicationImpl_->PerformTerminate()) {
if (!applicationImpl_->PerformTerminate(isLastProcess)) {
HILOG_WARN("%{public}s: applicationImpl_->PerformTerminate() failed.", __func__);
}
@@ -2117,6 +2120,7 @@ void MainThread::HandleSignal(int signal, [[maybe_unused]] siginfo_t *siginfo, v
{
if (signal != MUSL_SIGNAL_JSHEAP) {
HILOG_ERROR("HandleSignal failed, signal is %{public}d", signal);
return;
}
HILOG_INFO("HandleSignal sival_int is %{public}d", siginfo->si_value.sival_int);
switch (static_cast<SignalType>(siginfo->si_value.sival_int)) {
@@ -2135,12 +2139,25 @@ void MainThread::HandleSignal(int signal, [[maybe_unused]] siginfo_t *siginfo, v
signalHandler_->PostTask(privateHeapFunc, "MainThread:SIGNAL_JSHEAP_PRIV");
break;
}
case SignalType::SIGNAL_START_SAMPLE: {
HILOG_ERROR("HandleSignal failed, SIGNAL_START_SAMPLE is retained");
case SignalType::SIGNAL_NO_TRIGGERID: {
auto heapFunc = std::bind(&MainThread::HandleDumpHeap, false);
signalHandler_->PostTask(heapFunc, "MainThread::SIGNAL_JSHEAP");
auto noTriggerIdFunc = std::bind(&MainThread::DestroyHeapProfiler);
signalHandler_->PostTask(noTriggerIdFunc, "MainThread::SIGNAL_NO_TRIGGERID");
break;
}
case SignalType::SIGNAL_STOP_SAMPLE: {
HILOG_ERROR("HandleSignal failed, SIGNAL_STOP_SAMPLE is retained");
case SignalType::SIGNAL_NO_TRIGGERID_PRIV: {
auto privateHeapFunc = std::bind(&MainThread::HandleDumpHeap, true);
signalHandler_->PostTask(privateHeapFunc, "MainThread:SIGNAL_JSHEAP_PRIV");
auto noTriggerIdFunc = std::bind(&MainThread::DestroyHeapProfiler);
signalHandler_->PostTask(noTriggerIdFunc, "MainThread::SIGNAL_NO_TRIGGERID_PRIV");
break;
}
case SignalType::SIGNAL_FORCE_FULLGC: {
auto forceFullGCFunc = std::bind(&MainThread::ForceFullGC);
signalHandler_->PostTask(forceFullGCFunc, "MainThread:SIGNAL_FORCE_FULLGC");
break;
}
default:
@@ -2167,12 +2184,50 @@ void MainThread::HandleDumpHeap(bool isPrivate)
mainHandler_->PostTask(task, "MainThread:DumpHeap");
}
void MainThread::DestroyHeapProfiler()
{
HILOG_DEBUG("Destory heap profiler.");
if (mainHandler_ == nullptr) {
HILOG_ERROR("DestroyHeapProfiler failed, mainHandler is nullptr");
return;
}
auto task = [] {
auto app = applicationForDump_.lock();
if (app == nullptr || app->GetRuntime() == nullptr) {
HILOG_ERROR("runtime is nullptr.");
return;
}
app->GetRuntime()->DestroyHeapProfiler();
};
mainHandler_->PostTask(task, "MainThread:DestroyHeapProfiler");
}
void MainThread::ForceFullGC()
{
HILOG_DEBUG("Force fullGC.");
if (mainHandler_ == nullptr) {
HILOG_ERROR("ForceFullGC failed, mainHandler is nullptr");
return;
}
auto task = [] {
auto app = applicationForDump_.lock();
if (app == nullptr || app->GetRuntime() == nullptr) {
HILOG_ERROR("runtime is nullptr.");
return;
}
app->GetRuntime()->ForceFullGC();
};
mainHandler_->PostTask(task, "MainThread:ForceFullGC");
}
void MainThread::Start()
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
HILOG_INFO("LoadLifecycle: MainThread start come.");
if (AAFwk::AppUtils::GetInstance().JudgeMultiProcessModelDevice()) {
if (AAFwk::AppUtils::GetInstance().JudgePCDevice()) {
ChildProcessInfo info;
if (IsStartChild(info)) {
ChildMainThread::Start(info);
@@ -2858,7 +2913,8 @@ void MainThread::DetachAppDebug()
bool MainThread::NotifyDeviceDisConnect()
{
HILOG_DEBUG("Called.");
ScheduleTerminateApplication();
bool isLastProcess = appMgr_->IsFinalAppProcess();
ScheduleTerminateApplication(isLastProcess);
return true;
}
} // namespace AppExecFwk
@@ -13,6 +13,12 @@
* limitations under the License.
*/
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <sys/stat.h>
#include "ohos_application.h"
#include "ability.h"
@@ -21,6 +27,7 @@
#include "app_loader.h"
#include "application_context.h"
#include "application_impl.h"
#include "bundle_mgr_helper.h"
#include "context_impl.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
@@ -35,6 +42,7 @@
namespace OHOS {
namespace AppExecFwk {
REGISTER_APPLICATION(OHOSApplication, OHOSApplication)
constexpr char MARK_SYMBOL[] = "_useless";
OHOSApplication::OHOSApplication()
{
@@ -539,7 +547,6 @@ void OHOSApplication::OnStart()
/**
*
* @brief Will be called the application ends
*
*/
void OHOSApplication::OnTerminate()
{
@@ -792,5 +799,42 @@ bool OHOSApplication::NotifyUnLoadRepairPatch(const std::string &hqfFile)
return runtime_->UnLoadRepairPatch(hqfFile);
}
void OHOSApplication::CleanAppTempData(bool isLastProcess)
{
HILOG_DEBUG("Called");
if (!isLastProcess) {
HILOG_ERROR("There are other survival processes in the current application.");
return;
}
if (abilityRuntimeContext_ == nullptr) {
HILOG_ERROR("Context is nullptr.");
return;
}
auto bundleMgrHelpers = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
if (bundleMgrHelpers == nullptr) {
HILOG_ERROR("Get bundle mgr is nullptr.");
return;
}
std::vector<std::string> tempPaths;
abilityRuntimeContext_->GetAllTempDir(tempPaths);
if (tempPaths.empty()) {
HILOG_ERROR("Get app temp path list is empty.");
return;
}
int64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
system_clock::now().time_since_epoch()).count();
std::ostringstream stream;
stream << std::hex << now;
for (const auto &path : tempPaths) {
auto newPath = path + MARK_SYMBOL + stream.str();
if (rename(path.c_str(), newPath.c_str()) != 0) {
HILOG_ERROR("Rename temp dir failed, msg is %{public}s", strerror(errno));
}
}
bundleMgrHelpers->CleanObsoleteBundleTempFiles();
}
} // namespace AppExecFwk
} // namespace OHOS
+13
View File
@@ -1056,6 +1056,19 @@ void JsRuntime::DumpHeapSnapshot(bool isPrivate)
nativeEngine->DumpHeapSnapshot(true, DumpFormat::JSON, isPrivate);
}
void JsRuntime::DestroyHeapProfiler()
{
CHECK_POINTER(jsEnv_);
jsEnv_->DestroyHeapProfiler();
}
void JsRuntime::ForceFullGC()
{
auto vm = GetEcmaVm();
CHECK_POINTER(vm);
panda::JSNApi::TriggerGC(vm, panda::JSNApi::TRIGGER_GC_TYPE::FULL_GC);
}
bool JsRuntime::BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames)
{
auto nativeEngine = GetNativeEnginePointer();
@@ -119,10 +119,15 @@ ohos_shared_library("ability_simulator_inner") {
"hilog:libhilog",
"napi:ace_napi",
"previewer:ide_extension",
"window_manager:previewer_window",
"window_manager:previewer_window_napi",
]
if (ability_runtime_graphics) {
external_deps += [
"window_manager:previewer_window",
"window_manager:previewer_window_napi",
]
}
if (is_mingw) {
external_deps += [ "resource_management:win_resmgr" ]
} else {
@@ -42,6 +42,7 @@ public:
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
std::string GetTempDir() override;
std::string GetResourceDir() override;
std::string GetFilesDir() override;
std::string GetDatabaseDir() override;
std::string GetPreferencesDir() override;
@@ -41,6 +41,7 @@ public:
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
std::string GetTempDir() override;
std::string GetResourceDir() override;
std::string GetFilesDir() override;
std::string GetDatabaseDir() override;
std::string GetPreferencesDir() override;
@@ -42,6 +42,7 @@ public:
static napi_value CreateModuleResourceManager(napi_env env, napi_callback_info info);
static napi_value GetCacheDir(napi_env env, napi_callback_info info);
static napi_value GetTempDir(napi_env env, napi_callback_info info);
static napi_value GetResourceDir(napi_env env, napi_callback_info info);
static napi_value GetFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDistributedFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDatabaseDir(napi_env env, napi_callback_info info);
@@ -54,6 +55,7 @@ public:
napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetTempDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetResourceDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetFilesDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo& info);
napi_value OnGetDatabaseDir(napi_env env, NapiCallbackInfo& info);
@@ -106,6 +106,11 @@ std::string AbilityContext::GetTempDir()
return stageContext_ ? stageContext_->GetTempDir() : "";
}
std::string AbilityContext::GetResourceDir()
{
return stageContext_ ? stageContext_->GetResourceDir() : "";
}
std::string AbilityContext::GetFilesDir()
{
return stageContext_ ? stageContext_->GetFilesDir() : "";
@@ -33,6 +33,8 @@ constexpr const char *CONTEXT_FILES("files");
constexpr const char *CONTEXT_HAPS("haps");
constexpr const char *CONTEXT_ASSET("asset");
constexpr const char *CONTEXT_ELS[] = {"el1", "el2", "el3", "el4"};
constexpr const char *CONTEXT_RESOURCE_BASE("/data/storage/el1/bundle");
constexpr const char *CONTEXT_RESOURCE_END("/resources/resfile");
constexpr int DIR_DEFAULT_PERM = 0770;
}
std::shared_ptr<AppExecFwk::Configuration> AbilityStageContext::GetConfiguration()
@@ -122,6 +124,20 @@ std::string AbilityStageContext::GetTempDir()
return dir;
}
std::string AbilityStageContext::GetResourceDir()
{
std::shared_ptr<AppExecFwk::HapModuleInfo> hapModuleInfoPtr = GetHapModuleInfo();
if (hapModuleInfoPtr == nullptr || hapModuleInfoPtr->moduleName.empty()) {
return "";
}
auto dir = std::string(CONTEXT_RESOURCE_BASE) +
CONTEXT_FILE_SEPARATOR + hapModuleInfoPtr->moduleName + CONTEXT_RESOURCE_END;
if (Access(dir)) {
return dir;
}
return "";
}
std::string AbilityStageContext::GetFilesDir()
{
if (GetPreviewPath().empty()) {
@@ -48,6 +48,7 @@ napi_value JsApplicationContextUtils::OnSwitchArea(napi_env env, NapiCallbackInf
}
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
BindNativeProperty(env, object, "tempDir", GetTempDir);
BindNativeProperty(env, object, "resourceDir", GetResourceDir);
BindNativeProperty(env, object, "filesDir", GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
@@ -83,6 +84,22 @@ napi_value JsApplicationContextUtils::OnGetTempDir(napi_env env, NapiCallbackInf
return CreateJsValue(env, path);
}
napi_value JsApplicationContextUtils::GetResourceDir(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetResourceDir, APPLICATION_CONTEXT_NAME);
}
napi_value JsApplicationContextUtils::OnGetResourceDir(napi_env env, NapiCallbackInfo &info)
{
auto context = context_.lock();
if (!context) {
HILOG_WARN("context is already released");
return CreateJsUndefined(env);
}
std::string path = context->GetResourceDir();
return CreateJsValue(env, path);
}
napi_value JsApplicationContextUtils::GetArea(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnGetArea, APPLICATION_CONTEXT_NAME);
@@ -290,6 +307,7 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_
{
BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir);
BindNativeProperty(env, object, "tempDir", JsApplicationContextUtils::GetTempDir);
BindNativeProperty(env, object, "resourceDir", JsApplicationContextUtils::GetResourceDir);
BindNativeProperty(env, object, "filesDir", JsApplicationContextUtils::GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", JsApplicationContextUtils::GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", JsApplicationContextUtils::GetDatabaseDir);
@@ -41,6 +41,7 @@ public:
static napi_value GetCacheDir(napi_env env, napi_callback_info info);
static napi_value GetTempDir(napi_env env, napi_callback_info info);
static napi_value GetResourceDir(napi_env env, napi_callback_info info);
static napi_value GetFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDistributedFilesDir(napi_env env, napi_callback_info info);
static napi_value GetDatabaseDir(napi_env env, napi_callback_info info);
@@ -49,6 +50,7 @@ public:
napi_value OnGetCacheDir(napi_env env, NapiCallbackInfo &info);
napi_value OnGetTempDir(napi_env env, NapiCallbackInfo &info);
napi_value OnGetResourceDir(napi_env env, NapiCallbackInfo &info);
napi_value OnGetFilesDir(napi_env env, NapiCallbackInfo &info);
napi_value OnGetDistributedFilesDir(napi_env env, NapiCallbackInfo &info);
napi_value OnGetDatabaseDir(napi_env env, NapiCallbackInfo &info);
@@ -111,6 +113,7 @@ napi_value JsBaseContext::OnSwitchArea(napi_env env, NapiCallbackInfo &info)
}
BindNativeProperty(env, object, "cacheDir", GetCacheDir);
BindNativeProperty(env, object, "tempDir", GetTempDir);
BindNativeProperty(env, object, "resourceDir", GetResourceDir);
BindNativeProperty(env, object, "filesDir", GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", GetDatabaseDir);
@@ -177,6 +180,22 @@ napi_value JsBaseContext::OnGetTempDir(napi_env env, NapiCallbackInfo &info)
return CreateJsValue(env, path);
}
napi_value JsBaseContext::GetResourceDir(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetResourceDir, BASE_CONTEXT_NAME);
}
napi_value JsBaseContext::OnGetResourceDir(napi_env env, NapiCallbackInfo &info)
{
auto context = context_.lock();
if (!context) {
HILOG_WARN("context is already released");
return CreateJsUndefined(env);
}
std::string path = context->GetResourceDir();
return CreateJsValue(env, path);
}
napi_value JsBaseContext::GetFilesDir(napi_env env, napi_callback_info info)
{
GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsBaseContext, OnGetFilesDir, BASE_CONTEXT_NAME);
@@ -293,6 +312,7 @@ napi_value CreateJsBaseContext(napi_env env, std::shared_ptr<Context> context, b
BindNativeProperty(env, object, "cacheDir", JsBaseContext::GetCacheDir);
BindNativeProperty(env, object, "tempDir", JsBaseContext::GetTempDir);
BindNativeProperty(env, object, "resourceDir", JsBaseContext::GetResourceDir);
BindNativeProperty(env, object, "filesDir", JsBaseContext::GetFilesDir);
BindNativeProperty(env, object, "distributedFilesDir", JsBaseContext::GetDistributedFilesDir);
BindNativeProperty(env, object, "databaseDir", JsBaseContext::GetDatabaseDir);
@@ -114,6 +114,7 @@ private:
bool ParseAbilityInfo(const std::string &abilitySrcPath);
bool LoadRuntimeEnv(napi_env env, napi_value globalObject);
static napi_value RequireNapi(napi_env env, napi_callback_info info);
inline void SetHostResolveBufferTracker();
panda::ecmascript::EcmaVM *CreateJSVM();
Options options_;
@@ -661,24 +662,7 @@ bool SimulatorImpl::OnInit()
return false;
}
panda::JSNApi::SetHostResolveBufferTracker(vm_,
[](const std::string &inputPath, uint8_t **buff, size_t *buffSize) -> bool {
if (inputPath.empty() || buff == nullptr || buffSize == nullptr) {
HILOG_ERROR("Param invalid.");
return false;
}
HILOG_DEBUG("Get module buffer, input path: %{public}s.", inputPath.c_str());
auto data = Ide::StageContext::GetInstance().GetModuleBuffer(inputPath);
if (data == nullptr) {
HILOG_ERROR("Get module buffer failed, input path: %{public}s.", inputPath.c_str());
return false;
}
*buff = data->data();
*buffSize = data->size();
return true;
});
SetHostResolveBufferTracker();
panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, (options_.debugPort != 0), options_.debugPort};
panda::JSNApi::StartDebugger(vm_, debugOption, 0,
std::bind(&DebuggerTask::OnPostTask, &debuggerTask_, std::placeholders::_1));
@@ -798,5 +782,27 @@ std::unique_ptr<Simulator> Simulator::Create(const Options &options)
}
return nullptr;
}
void SimulatorImpl::SetHostResolveBufferTracker()
{
panda::JSNApi::SetHostResolveBufferTracker(vm_,
[](const std::string &inputPath, uint8_t **buff, size_t *buffSize) -> bool {
if (inputPath.empty() || buff == nullptr || buffSize == nullptr) {
HILOG_ERROR("Param invalid.");
return false;
}
HILOG_DEBUG("Get module buffer, input path: %{public}s.", inputPath.c_str());
auto data = Ide::StageContext::GetInstance().GetModuleBuffer(inputPath);
if (data == nullptr) {
HILOG_ERROR("Get module buffer failed, input path: %{public}s.", inputPath.c_str());
return false;
}
*buff = data->data();
*buffSize = data->size();
return true;
});
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -41,6 +41,8 @@ public:
virtual std::string GetTempDir() = 0;
virtual std::string GetResourceDir() = 0;
virtual std::string GetFilesDir() = 0;
virtual std::string GetDatabaseDir() = 0;
@@ -140,8 +140,6 @@ ohos_shared_library("ability_manager") {
"relational_store:native_dataability",
"relational_store:native_rdb",
"samgr:samgr_proxy",
"window_manager:libwsutils",
"window_manager:session_manager",
]
if (ability_runtime_graphics) {
@@ -149,6 +147,8 @@ ohos_shared_library("ability_manager") {
external_deps += [
"ability_base:session_info",
"image_framework:image_native",
"window_manager:libwsutils",
"window_manager:session_manager_lite",
]
}
@@ -1374,6 +1374,12 @@ public:
*/
int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list);
/**
* @brief Update session info.
* @param sessionInfos The vector of session info.
*/
void UpdateSessionInfoBySCB(const std::vector<SessionInfo> &sessionInfos, int32_t userId);
private:
class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient {
public:
@@ -1401,6 +1401,12 @@ public:
{
return 0;
}
/**
* @brief Update session info.
* @param sessionInfos The vector of session info.
*/
virtual void UpdateSessionInfoBySCB(const std::vector<SessionInfo> &sessionInfos, int32_t userId) {}
};
} // namespace AAFwk
} // namespace OHOS
@@ -482,6 +482,8 @@ enum class AbilityManagerInterfaceCode {
// ipc id for register session handler
REGISTER_SESSION_HANDLER = 6010,
// ipc id for update session info
UPDATE_SESSION_INFO = 6011,
// ipc id for set application auto startup by EDM
SET_APPLICATION_AUTO_STARTUP_BY_EDM = 6113,
@@ -302,6 +302,12 @@ public:
virtual void CallRequest() = 0;
/**
* @brief Update sessionToken.
* @param sessionToken The token of session.
*/
virtual void UpdateSessionToken(sptr<IRemoteObject> sessionToken) = 0;
enum {
// ipc id for scheduling ability to a state of life cycle
SCHEDULE_ABILITY_TRANSACTION = 0,
@@ -398,7 +404,9 @@ public:
SCHEDULE_ONEXECUTE_INTENT,
CREATE_MODAL_UI_EXTENSION
CREATE_MODAL_UI_EXTENSION,
UPDATE_SESSION_TOKEN
};
};
} // namespace AAFwk
@@ -241,6 +241,13 @@ public:
*/
virtual bool IsAttachDebug(const std::string &bundleName) = 0;
/**
* To clear the process by ability token.
*
* @param token the unique identification to the ability.
*/
virtual void ClearProcessByToken(sptr<IRemoteObject> token) {}
enum class Message {
LOAD_ABILITY = 0,
TERMINATE_ABILITY,
@@ -274,6 +281,7 @@ public:
REGISTER_ABILITY_DEBUG_RESPONSE,
IS_ATTACH_DEBUG,
START_SPECIFIED_PROCESS,
CLEAR_PROCESS_BY_TOKEN,
};
};
} // namespace AppExecFwk
@@ -218,6 +218,13 @@ public:
*/
bool IsAttachDebug(const std::string &bundleName) override;
/**
* To clear the process by ability token.
*
* @param token the unique identification to the ability.
*/
virtual void ClearProcessByToken(sptr<IRemoteObject> token) override;
private:
bool WriteInterfaceToken(MessageParcel &data);
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
@@ -73,6 +73,7 @@ private:
int32_t HandleDetachAppDebug(MessageParcel &data, MessageParcel &reply);
int32_t HandleRegisterAbilityDebugResponse(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsAttachDebug(MessageParcel &data, MessageParcel &reply);
int32_t HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply);
using AmsMgrFunc = int32_t (AmsMgrStub::*)(MessageParcel &data, MessageParcel &reply);
std::map<uint32_t, AmsMgrFunc> memberFuncMap_;
@@ -583,6 +583,20 @@ public:
*/
int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener);
/**
* Whether the current application process is the last surviving process.
*
* @return Returns true is final application process, others return false.
*/
bool IsFinalAppProcess();
/**
* To clear the process by ability token.
*
* @param token the unique identification to the ability.
*/
void ClearProcessByToken(sptr<IRemoteObject> token) const;
private:
void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr);
/**
@@ -487,7 +487,7 @@ public:
/**
* Check whether the bundle is running.
*
*
* @param bundleName Indicates the bundle name of the bundle.
* @param isRunning Obtain the running status of the application, the result is true if running, false otherwise.
* @return Return ERR_OK if success, others fail.
@@ -521,7 +521,14 @@ public:
* Exit child process, called by itself.
*/
virtual void ExitChildProcessSafely() = 0;
/**
* Whether the current application process is the last surviving process.
*
* @return Returns true is final application process, others return false.
*/
virtual bool IsFinalAppProcess() = 0;
// please add new message item to the bottom in order to prevent some unexpected BUG
enum class Message {
APP_ATTACH_APPLICATION = 0,
@@ -83,6 +83,7 @@ enum class AppMgrInterfaceCode {
GET_CHILD_PROCCESS_INFO_FOR_SELF,
ATTACH_CHILD_PROCESS,
EXIT_CHILD_PROCESS_SAFELY,
IS_FINAL_APP_PROCESS,
};
} // AppExecFwk
} // OHOS
@@ -428,7 +428,7 @@ public:
/**
* Check whether the bundle is running.
*
*
* @param bundleName Indicates the bundle name of the bundle.
* @param isRunning Obtain the running status of the application, the result is true if running, false otherwise.
* @return Return ERR_OK if success, others fail.
@@ -463,6 +463,13 @@ public:
*/
void ExitChildProcessSafely() override;
/**
* Whether the current application process is the last surviving process.
*
* @return Returns true is final application process, others return false.
*/
bool IsFinalAppProcess() override;
private:
bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply);
bool WriteInterfaceToken(MessageParcel &data);
@@ -120,6 +120,7 @@ private:
int32_t HandleGetChildProcessInfoForSelf(MessageParcel &data, MessageParcel &reply);
int32_t HandleAttachChildProcess(MessageParcel &data, MessageParcel &reply);
int32_t HandleExitChildProcessSafely(MessageParcel &data, MessageParcel &reply);
int32_t HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply);
using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply);
std::map<uint32_t, AppMgrFunc> memberFuncMap_;
@@ -52,9 +52,9 @@ public:
* ScheduleTerminateApplication, call ScheduleTerminateApplication() through proxy project,
* Notify application to terminate.
*
* @return
* @param isLastProcess When it is the last application process, pass in true.
*/
virtual void ScheduleTerminateApplication() = 0;
virtual void ScheduleTerminateApplication(bool isLastProcess = false) = 0;
/**
* ScheduleShrinkMemory, call ScheduleShrinkMemory() through proxy project,
@@ -47,9 +47,9 @@ public:
* ScheduleTerminateApplication, call ScheduleTerminateApplication() through proxy project,
* Notify application to terminate.
*
* @return
* @param isLastProcess When it is the last application process, pass in true.
*/
virtual void ScheduleTerminateApplication() override;
virtual void ScheduleTerminateApplication(bool isLastProcess = false) override;
/**
* ScheduleShrinkMemory, call ScheduleShrinkMemory() through proxy project,
@@ -828,6 +828,25 @@ bool AmsMgrProxy::IsAttachDebug(const std::string &bundleName)
return reply.ReadBool();
}
void AmsMgrProxy::ClearProcessByToken(sptr<IRemoteObject> token)
{
MessageParcel data;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("Failed to write interface token.");
return;
}
if (!data.WriteRemoteObject(token)) {
HILOG_ERROR("Failed to write token");
return;
}
MessageParcel reply;
MessageOption option;
auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::CLEAR_PROCESS_BY_TOKEN), data, reply, option);
if (ret != NO_ERROR) {
HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
}
}
int32_t AmsMgrProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@@ -97,6 +97,8 @@ void AmsMgrStub::CreateMemberFuncMap()
&AmsMgrStub::HandleRegisterAbilityDebugResponse;
memberFuncMap_[static_cast<uint32_t>(IAmsMgr::Message::IS_ATTACH_DEBUG)] =
&AmsMgrStub::HandleIsAttachDebug;
memberFuncMap_[static_cast<uint32_t>(IAmsMgr::Message::CLEAR_PROCESS_BY_TOKEN)] =
&AmsMgrStub::HandleClearProcessByToken;
}
int AmsMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
@@ -504,5 +506,13 @@ int32_t AmsMgrStub::HandleIsAttachDebug(MessageParcel &data, MessageParcel &repl
}
return NO_ERROR;
}
int32_t AmsMgrStub::HandleClearProcessByToken(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER(HITRACE_TAG_APP);
sptr<IRemoteObject> token = data.ReadRemoteObject();
ClearProcessByToken(token);
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -909,5 +909,30 @@ int32_t AppMgrClient::UnregisterAppRunningStatusListener(const sptr<IRemoteObjec
}
return service->UnregisterAppRunningStatusListener(listener);
}
bool AppMgrClient::IsFinalAppProcess()
{
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
if (service == nullptr) {
HILOG_ERROR("Service is nullptr.");
return false;
}
return service->IsFinalAppProcess();
}
void AppMgrClient::ClearProcessByToken(sptr<IRemoteObject> token) const
{
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
if (service == nullptr) {
HILOG_ERROR("Service is nullptr.");
return;
}
sptr<IAmsMgr> amsService = service->GetAmsMgr();
if (amsService == nullptr) {
HILOG_ERROR("amsService is nullptr.");
return;
}
amsService->ClearProcessByToken(token);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -1593,5 +1593,26 @@ void AppMgrProxy::ExitChildProcessSafely()
HILOG_ERROR("ExitChildProcessSafely SendRequest is failed, error code: %{public}d", ret);
}
}
bool AppMgrProxy::IsFinalAppProcess()
{
HILOG_DEBUG("Called.");
MessageParcel data;
if (!WriteInterfaceToken(data)) {
HILOG_ERROR("Write interface token failed.");
return ERR_INVALID_DATA;
}
MessageParcel reply;
MessageOption option;
auto ret = SendRequest(AppMgrInterfaceCode::IS_FINAL_APP_PROCESS,
data, reply, option);
if (ret != NO_ERROR) {
HILOG_ERROR("Send request is failed, error code: %{public}d", ret);
return false;
}
return reply.ReadBool();
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -157,6 +157,8 @@ AppMgrStub::AppMgrStub()
&AppMgrStub::HandleAttachChildProcess;
memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY)] =
&AppMgrStub::HandleExitChildProcessSafely;
memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::IS_FINAL_APP_PROCESS)] =
&AppMgrStub::HandleIsFinalAppProcess;
}
AppMgrStub::~AppMgrStub()
@@ -1014,5 +1016,15 @@ int32_t AppMgrStub::HandleExitChildProcessSafely(MessageParcel &data, MessagePar
ExitChildProcessSafely();
return NO_ERROR;
}
int32_t AppMgrStub::HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply)
{
HILOG_DEBUG("Called.");
if (!reply.WriteBool(IsFinalAppProcess())) {
HILOG_ERROR("Fail to write bool result.");
return ERR_INVALID_VALUE;
}
return NO_ERROR;
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -118,7 +118,8 @@ int32_t AppSchedulerHost::HandleScheduleBackgroundApplication(MessageParcel &dat
int32_t AppSchedulerHost::HandleScheduleTerminateApplication(MessageParcel &data, MessageParcel &reply)
{
HITRACE_METER(HITRACE_TAG_APP);
ScheduleTerminateApplication();
auto isLastProcess = data.ReadBool();
ScheduleTerminateApplication(isLastProcess);
return NO_ERROR;
}
@@ -71,7 +71,7 @@ void AppSchedulerProxy::ScheduleBackgroundApplication()
}
}
void AppSchedulerProxy::ScheduleTerminateApplication()
void AppSchedulerProxy::ScheduleTerminateApplication(bool isLastProcess)
{
MessageParcel data;
MessageParcel reply;
@@ -79,6 +79,10 @@ void AppSchedulerProxy::ScheduleTerminateApplication()
if (!WriteInterfaceToken(data)) {
return;
}
if (!data.WriteBool(isLastProcess)) {
HILOG_ERROR("Write bool failed.");
return;
}
int32_t ret = SendTransactCmd(
static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_TERMINATE_APPLICATION_TRANSACTION), data, reply, option);
if (ret != NO_ERROR) {
@@ -46,12 +46,15 @@ ohos_shared_library("auto_fill_manager") {
"ability_base:base",
"ability_base:view_data",
"ability_base:want",
"ace_engine:ace_uicontent",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
]
if (ability_runtime_graphics) {
external_deps += [ "ace_engine:ace_uicontent" ]
}
innerapi_tags = [ "platformsdk" ]
subsystem_name = "ability"
part_name = "ability_runtime"
@@ -77,6 +77,8 @@ public:
void PostSyncTask(const std::function<void()>& task, const std::string& name);
void RemoveTask(const std::string& name);
void DumpHeapSnapshot(bool isPrivate) override;
void DestroyHeapProfiler() override;
void ForceFullGC() override;
bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) override;
void NotifyApplicationState(bool isBackground) override;
bool SuspendVM(uint32_t tid) override;
@@ -78,6 +78,8 @@ public:
virtual void StartDebugMode(bool needBreakPoint, const std::string &processName, bool isDebug = true) = 0;
virtual bool BuildJsStackInfoList(uint32_t tid, std::vector<JsFrames>& jsFrames) = 0;
virtual void DumpHeapSnapshot(bool isPrivate) = 0;
virtual void DestroyHeapProfiler() = 0;
virtual void ForceFullGC() = 0;
virtual void NotifyApplicationState(bool isBackground) = 0;
virtual bool SuspendVM(uint32_t tid) = 0;
virtual void ResumeVM(uint32_t tid) = 0;
@@ -113,6 +113,8 @@ public:
*/
bool VerifyUriPermission(const Uri& uri, uint32_t flag, uint32_t tokenId);
bool IsAuthorizationUriAllowed(uint32_t fromTokenId);
void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject);
void OnLoadSystemAbilityFail();
private:
@@ -116,6 +116,8 @@ public:
*/
virtual bool VerifyUriPermission(const Uri& uri, uint32_t flag, uint32_t tokenId) = 0;
virtual bool IsAuthorizationUriAllowed(uint32_t fromTokenId) = 0;
enum UriPermMgrCmd {
// ipc id for GrantUriPermission
ON_GRANT_URI_PERMISSION = 0,
@@ -142,6 +144,9 @@ public:
// ipc id for BatchGrantUriPermissionFor2In1
ON_BATCH_GRANT_URI_PERMISSION_FOR_2_IN_1,
//ipc id for IsAuthorizationUriAllowed
ON_IS_Authorization_URI_ALLOWED
};
};
} // namespace AAFwk
@@ -41,6 +41,7 @@ public:
virtual int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override;
virtual bool CheckPersistableUriPermissionProxy(const Uri& uri, uint32_t flag, uint32_t tokenId) override;
virtual bool VerifyUriPermission(const Uri &uri, uint32_t flag, uint32_t tokenId) override;
virtual bool IsAuthorizationUriAllowed(uint32_t fromTokenId) override;
private:
static inline BrokerDelegator<UriPermissionManagerProxy> delegator_;
@@ -44,6 +44,7 @@ private:
int HandleRevokeUriPermissionManually(MessageParcel &data, MessageParcel &reply);
int HandleCheckPerSiSTableUriPermissionProxy(MessageParcel &data, MessageParcel &reply);
int HandleVerifyUriPermission(MessageParcel &data, MessageParcel &reply);
int HandleIsAuthorizationUriAllowed(MessageParcel &data, MessageParcel &reply);
};
} // namespace AAFwk
} // namespace OHOS
@@ -133,6 +133,15 @@ bool UriPermissionManagerClient::VerifyUriPermission(const Uri& uri, uint32_t fl
return false;
}
bool UriPermissionManagerClient::IsAuthorizationUriAllowed(uint32_t fromTokenId)
{
auto uriPermMgr = ConnectUriPermService();
if (uriPermMgr) {
return uriPermMgr->IsAuthorizationUriAllowed(fromTokenId);
}
return false;
}
sptr<IUriPermissionManager> UriPermissionManagerClient::ConnectUriPermService()
{
HILOG_DEBUG("UriPermissionManagerClient::ConnectUriPermService is called.");
@@ -315,6 +315,28 @@ bool UriPermissionManagerProxy::VerifyUriPermission(const Uri& uri, uint32_t fla
return reply.ReadBool();
}
bool UriPermissionManagerProxy::IsAuthorizationUriAllowed(uint32_t fromTokenId)
{
HILOG_DEBUG("UriPermissionManagerProxy::IsAuthorizationUriAllowed is called.");
MessageParcel data;
if (!data.WriteInterfaceToken(IUriPermissionManager::GetDescriptor())) {
HILOG_ERROR("Write interface token failed.");
return false;
}
if (!data.WriteInt32(fromTokenId)) {
HILOG_ERROR("Write fromTokenId failed.");
return false;
}
MessageParcel reply;
MessageOption option;
int error = SendTransactCmd(UriPermMgrCmd::ON_IS_Authorization_URI_ALLOWED, data, reply, option);
if (error != ERR_OK) {
HILOG_ERROR("SendRequest fail, error: %{public}d", error);
return false;
}
return reply.ReadBool();
}
int32_t UriPermissionManagerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@@ -58,6 +58,9 @@ int UriPermissionManagerStub::OnRemoteRequest(
case UriPermMgrCmd::ON_BATCH_GRANT_URI_PERMISSION_FOR_2_IN_1 : {
return HandleBatchGrantUriPermissionFor2In1(data, reply);
}
case UriPermMgrCmd::ON_IS_Authorization_URI_ALLOWED : {
return HandleIsAuthorizationUriAllowed(data, reply);
}
default:
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
@@ -198,5 +201,13 @@ int UriPermissionManagerStub::HandleBatchGrantUriPermissionFor2In1(MessageParcel
reply.WriteInt32(result);
return ERR_OK;
}
int UriPermissionManagerStub::HandleIsAuthorizationUriAllowed(MessageParcel &data, MessageParcel &reply)
{
auto fromTokenId = data.ReadInt32();
bool result = IsAuthorizationUriAllowed(fromTokenId);
reply.WriteBool(result);
return ERR_OK;
}
} // namespace AAFwk
} // namespace OHOS
@@ -36,6 +36,7 @@ public:
std::string GetBundleCodeDir() override;
std::string GetCacheDir() override;
std::string GetTempDir() override;
std::string GetResourceDir() override;
std::string GetFilesDir() override;
bool IsUpdatingConfigurations() override;
bool PrintDrawnCompleted() override;
@@ -1138,6 +1138,12 @@ public:
*/
int CreateModalUIExtension(const Want &want);
/**
* @brief Update sessionToken.
* @param sessionToken The token of session.
*/
void UpdateSessionToken(sptr<IRemoteObject> sessionToken);
protected:
class AbilityDisplayListener : public OHOS::Rosen::DisplayManager::IDisplayListener {
public:
@@ -188,7 +188,7 @@ protected:
std::string callingAbilityName_;
std::string callingModuleName_;
std::map<sptr<AAFwk::IAbilityConnection>, sptr<IRemoteObject>> abilityConnectionMap_;
sptr<AAFwk::SessionInfo> sessionInfo_;
sptr<IRemoteObject> sessionToken_;
private:
/**
@@ -31,6 +31,7 @@ class NativeReference;
namespace OHOS {
namespace AbilityRuntime {
struct NapiCallbackInfo;
class JsEmbeddableUIAbilityContext;
class JsAbilityContext final {
public:
explicit JsAbilityContext(const std::shared_ptr<AbilityContext>& context) : context_(context) {}
@@ -119,6 +120,7 @@ private:
std::weak_ptr<AbilityContext> context_;
int curRequestCode_ = 0;
sptr<JsFreeInstallObserver> freeInstallObserver_ = nullptr;
friend class JsEmbeddableUIAbilityContext;
};
napi_value CreateJsAbilityContext(napi_env env, std::shared_ptr<AbilityContext> context);
@@ -18,6 +18,7 @@
#include "ability_delegator_infos.h"
#include "freeze_util.h"
#include "js_embeddable_ui_ability_context.h"
#include "ui_ability.h"
class NativeReference;
@@ -55,7 +56,8 @@ public:
* @param handler the UIability EventHandler object
* @param token the remote token
*/
void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> application,
void Init(std::shared_ptr<AppExecFwk::AbilityLocalRecord> record,
const std::shared_ptr<OHOSApplication> application,
std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
/**
@@ -296,17 +298,19 @@ private:
std::unique_ptr<NativeReference> CreateAppWindowStage();
std::shared_ptr<AppExecFwk::ADelegatorAbilityProperty> CreateADelegatorAbilityProperty();
sptr<IRemoteObject> SetNewRuleFlagToCallee(napi_env env, napi_value remoteJsObj);
void SetAbilityContext(
const std::shared_ptr<AbilityInfo> &abilityInfo, const std::string &moduleName, const std::string &srcPath);
void SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
std::shared_ptr<AAFwk::Want> want, const std::string &moduleName, const std::string &srcPath);
void DoOnForegroundForSceneIsNull(const Want &want);
void GetDumpInfo(
napi_env env, napi_value dumpInfo, napi_value onDumpInfo, std::vector<std::string> &info);
void AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
void AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
void CreateJSContext(napi_env env, napi_value &contextObj, int32_t screenMode);
JsRuntime &jsRuntime_;
std::shared_ptr<NativeReference> shellContextRef_;
std::shared_ptr<NativeReference> jsAbilityObj_;
std::shared_ptr<int32_t> screenModePtr_;
sptr<IRemoteObject> remoteCallee_;
};
} // namespace AbilityRuntime
@@ -350,6 +350,12 @@ public:
*/
int CreateModalUIExtension(const Want &want) override;
/**
* @brief Update sessionToken.
* @param sessionToken The token of session.
*/
void UpdateSessionToken(sptr<IRemoteObject> sessionToken) override;
#ifdef ABILITY_COMMAND_FOR_TEST
/**
* @brief Block ability.
@@ -92,7 +92,7 @@ public:
* @return Returns ERR_OK if success.
*/
virtual ErrCode SetMissionIcon(const std::shared_ptr<OHOS::Media::PixelMap> &icon);
void SetSessionInfo(sptr<AAFwk::SessionInfo> &sessionInfo);
void SetSessionToken(sptr<IRemoteObject> sessionToken);
#endif
private:
@@ -100,7 +100,7 @@ private:
std::weak_ptr<IAbilityEvent> ability_;
std::shared_ptr<Rosen::WindowScene> windowScene_;
bool isWindowAttached = false;
sptr<AAFwk::SessionInfo> sessionInfo_ = nullptr;
sptr<IRemoteObject> sessionToken_ = nullptr;
};
} // namespace AppExecFwk
} // namespace OHOS
@@ -103,7 +103,7 @@ public:
* The extension in the <b>STATE_FOREGROUND</b> state is visible.
* You can override this function to implement your own processing logic.
*/
void OnForeground(const Want &want) override;
void OnForeground(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo) override;
/**
* @brief Called when this extension enters the <b>STATE_BACKGROUND</b> state.
@@ -35,7 +35,8 @@ public:
: processExtensionType_(extensionType), moduleBlocklist_(std::move(blocklist)) {}
~AppModuleChecker() override = default;
bool CheckModuleLoadable(const char* moduleName) override;
bool CheckModuleLoadable(const char* moduleName,
std::unique_ptr<ApiAllowListChecker>& apiAllowListChecker) override;
bool DiskCheckOnly() override;
protected:
int32_t processExtensionType_{EXTENSION_TYPE_UNKNOWN};

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