diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 801ab8190a..86c80ca85b 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -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", diff --git a/frameworks/js/napi/ability_auto_startup_manager/js_ability_auto_startup_manager.cpp b/frameworks/js/napi/ability_auto_startup_manager/js_ability_auto_startup_manager.cpp index 2a77c55cb2..e91d874018 100644 --- a/frameworks/js/napi/ability_auto_startup_manager/js_ability_auto_startup_manager.cpp +++ b/frameworks/js/napi/ability_auto_startup_manager/js_ability_auto_startup_manager.cpp @@ -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; } diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index 07aa1ab107..b0901e706a 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -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; } diff --git a/frameworks/js/napi/app/context/context.js b/frameworks/js/napi/app/context/context.js index 0d2ba8d4fb..3ae52dbf6f 100644 --- a/frameworks/js/napi/app/context/context.js +++ b/frameworks/js/napi/app/context/context.js @@ -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; } diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 430acb6925..b212027ca2 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -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) { diff --git a/frameworks/js/napi/auto_fill_manager/BUILD.gn b/frameworks/js/napi/auto_fill_manager/BUILD.gn index 0d88f5ead4..8abd6e8e63 100644 --- a/frameworks/js/napi/auto_fill_manager/BUILD.gn +++ b/frameworks/js/napi/auto_fill_manager/BUILD.gn @@ -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" diff --git a/frameworks/js/napi/embeddable_ui_ability/BUILD.gn b/frameworks/js/napi/embeddable_ui_ability/BUILD.gn new file mode 100644 index 0000000000..badb91ce3d --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability/BUILD.gn @@ -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" +} diff --git a/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability.js b/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability.js new file mode 100644 index 0000000000..d2881ee0c3 --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability.js @@ -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; diff --git a/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability_module.cpp b/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability_module.cpp new file mode 100644 index 0000000000..5fd16f1eb2 --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability/embeddable_ui_ability_module.cpp @@ -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; + } +} diff --git a/frameworks/js/napi/embeddable_ui_ability_context/BUILD.gn b/frameworks/js/napi/embeddable_ui_ability_context/BUILD.gn new file mode 100644 index 0000000000..51fb6b3e4a --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability_context/BUILD.gn @@ -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" +} diff --git a/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context.js b/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context.js new file mode 100644 index 0000000000..56cd7a29b3 --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context.js @@ -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; \ No newline at end of file diff --git a/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context_module.cpp b/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context_module.cpp new file mode 100644 index 0000000000..4d502748c4 --- /dev/null +++ b/frameworks/js/napi/embeddable_ui_ability_context/embeddable_ui_ability_context_module.cpp @@ -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; + } +} \ No newline at end of file diff --git a/frameworks/js/napi/featureAbility/feature_ability.cpp b/frameworks/js/napi/featureAbility/feature_ability.cpp index 87b893b7f2..fdc2543f09 100644 --- a/frameworks/js/napi/featureAbility/feature_ability.cpp +++ b/frameworks/js/napi/featureAbility/feature_ability.cpp @@ -781,7 +781,10 @@ napi_value UnwrapForResultParam(CallAbilityParam ¶m, 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))) { diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp index 237de6bb3f..30fac4e746 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp @@ -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))) { diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index 21aabc34da..00d0e0922e 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -772,10 +772,17 @@ int32_t JsWantAgent::GetTriggerInfo(napi_env env, napi_value param, TriggerInfo std::shared_ptr 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(); 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; diff --git a/frameworks/native/ability/BUILD.gn b/frameworks/native/ability/BUILD.gn index b6c97756f8..f9e1e89693 100644 --- a/frameworks/native/ability/BUILD.gn +++ b/frameworks/native/ability/BUILD.gn @@ -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" ] } diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index 571d813a29..7136816ab6 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -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); diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 30a4120407..abbd41dd36 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -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" diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index 431b963dc3..3002dd888c 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -169,7 +169,9 @@ void Ability::OnStart(const Want &want, sptr sessionInfo) securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false); (const_cast(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 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 sessionToken) +{ + sessionToken_ = sessionToken; + if (abilityWindow_ == nullptr) { + HILOG_ERROR("Ability window is nullptr."); + return; + } + abilityWindow_->SetSessionToken(sessionToken_); +} #endif } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/ability/native/ability_context.cpp b/frameworks/native/ability/native/ability_context.cpp index 54d21a76a3..2b074e64f2 100644 --- a/frameworks/native/ability/native/ability_context.cpp +++ b/frameworks/native/ability/native/ability_context.cpp @@ -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 sessionInfo = new AAFwk::SessionInfo(); sessionInfo->want = resultWant_; sessionInfo->resultCode = resultCode_; HILOG_INFO("FA TerminateAbility resultCode is %{public}d", sessionInfo->resultCode); - auto ifaceSessionToken = iface_cast(sessionToken); + auto ifaceSessionToken = iface_cast(sessionToken_); auto err = ifaceSessionToken->TerminateSession(sessionInfo); HILOG_INFO("FA TerminateAbility. ret=%{public}d", err); return static_cast(err); diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 4d42f55cfd..7a290607b9 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -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); } diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index fc4c153aa8..0b78386fa7 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -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 systemModule = nullptr; + auto screenModePtr = reinterpret_cast *>(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(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(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(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, +void JsUIAbility::Init(std::shared_ptr record, const std::shared_ptr application, std::shared_ptr &handler, const sptr &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, 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, const std::string &moduleName, const std::string &srcPath) +void JsUIAbility::SetAbilityContext(std::shared_ptr abilityInfo, + std::shared_ptr 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(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(abilityContext_); - if (workContext == nullptr) { - HILOG_ERROR("workContext is nullptr."); - return; - } + CHECK_POINTER(workContext); + screenModePtr_ = std::make_shared(screenMode); + auto workScreenMode = new (std::nothrow) std::weak_ptr(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(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 *>(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(JsRuntime::LoadSystemModuleByEngine( + env, "application.AbilityContext", &contextObj, 1).release()); + } else { + contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env, + abilityContext_, nullptr, screenMode); + CHECK_POINTER(contextObj); + shellContextRef_ = std::shared_ptr(JsRuntime::LoadSystemModuleByEngine( + env, "application.EmbeddableUIAbilityContext", &contextObj, 1).release()); + } } void JsUIAbility::OnStart(const Want &want, sptr 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); } diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 80c9fa05d0..a88de3b327 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -283,6 +283,11 @@ int AbilityThread::CreateModalUIExtension(const Want &want) return ERR_INVALID_VALUE; } +void AbilityThread::UpdateSessionToken(sptr sessionToken) +{ + HILOG_DEBUG("called"); +} + #ifdef ABILITY_COMMAND_FOR_TEST int AbilityThread::BlockAbility() { diff --git a/frameworks/native/ability/native/ability_window.cpp b/frameworks/native/ability/native/ability_window.cpp index c440ca1946..f6231d0d32 100644 --- a/frameworks/native/ability/native/ability_window.cpp +++ b/frameworks/native/ability/native/ability_window.cpp @@ -48,8 +48,8 @@ bool AbilityWindow::InitWindow(std::shared_ptr & windowScene_ = std::make_shared(); } 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 &sessionInfo) +void AbilityWindow::SetSessionToken(sptr sessionToken) { - sessionInfo_ = sessionInfo; + sessionToken_ = sessionToken; } } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp b/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp index e28c001ca0..360f1298b1 100644 --- a/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp +++ b/frameworks/native/ability/native/action_extension_ability/js_action_extension.cpp @@ -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 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() diff --git a/frameworks/native/ability/native/app_module_checker.cpp b/frameworks/native/ability/native/app_module_checker.cpp index be5fe5244d..701be59d50 100644 --- a/frameworks/native/ability/native/app_module_checker.cpp +++ b/frameworks/native/ability/native/app_module_checker.cpp @@ -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 = nullptr; HILOG_INFO("check blocklist, moduleName = %{public}s, processExtensionType_ = %{public}d", moduleName, static_cast(processExtensionType_)); const auto& blockListIter = moduleBlocklist_.find(processExtensionType_); diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp index 13c0791c73..6c8a0d40ab 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp @@ -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 sessionInfo) { HILOG_DEBUG("Called."); - Extension::OnForeground(want); + Extension::OnForeground(want, sessionInfo); + ForegroundWindow(want, sessionInfo); HandleScope handleScope(jsRuntime_); CallObjectMethod("onForeground"); } diff --git a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp index 9e93b6e6f8..1817350456 100644 --- a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp +++ b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp @@ -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; } diff --git a/frameworks/native/ability/native/extension.cpp b/frameworks/native/ability/native/extension.cpp index 22ca37c8e5..64f6b934e6 100644 --- a/frameworks/native/ability/native/extension.cpp +++ b/frameworks/native/ability/native/extension.cpp @@ -110,7 +110,7 @@ void Extension::OnCommandWindow(const AAFwk::Want &want, const sptr sessionInfo) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("extension:%{public}s.", abilityInfo_->name.c_str()); diff --git a/frameworks/native/ability/native/extension_impl.cpp b/frameworks/native/ability/native/extension_impl.cpp index 1ac3530adb..92ca499bed 100644 --- a/frameworks/native/ability/native/extension_impl.cpp +++ b/frameworks/native/ability/native/extension_impl.cpp @@ -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 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; } diff --git a/frameworks/native/ability/native/fa_ability_thread.cpp b/frameworks/native/ability/native/fa_ability_thread.cpp index e372fcb374..368dd457df 100644 --- a/frameworks/native/ability/native/fa_ability_thread.cpp +++ b/frameworks/native/ability/native/fa_ability_thread.cpp @@ -1521,5 +1521,14 @@ int FAAbilityThread::CreateModalUIExtension(const Want &want) } return currentAbility_->CreateModalUIExtension(want); } + +void FAAbilityThread::UpdateSessionToken(sptr sessionToken) +{ + if (currentAbility_ == nullptr) { + HILOG_ERROR("current ability is nullptr"); + return; + } + currentAbility_->UpdateSessionToken(sessionToken); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp b/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp index 9973dffe5f..6dfdac643c 100644 --- a/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp +++ b/frameworks/native/ability/native/share_extension_ability/js_share_extension.cpp @@ -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 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() diff --git a/frameworks/native/ability/native/ui_ability.cpp b/frameworks/native/ability/native/ui_ability.cpp index c756357600..6551b6ff7b 100644 --- a/frameworks/native/ability/native/ui_ability.cpp +++ b/frameworks/native/ability/native/ui_ability.cpp @@ -54,14 +54,18 @@ UIAbility *UIAbility::Create(const std::unique_ptr &runtime) } } -void UIAbility::Init(const std::shared_ptr &abilityInfo, +void UIAbility::Init(std::shared_ptr record, const std::shared_ptr application, std::shared_ptr &handler, const sptr &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 s securityFlag_ = want.GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false); (const_cast(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 sessionToken) +{ + sessionToken_ = sessionToken; + auto abilityContextImpl = GetAbilityContext(); + if (abilityContextImpl == nullptr) { + HILOG_ERROR("abilityContext is nullptr"); + return; + } + abilityContextImpl->SetWeakSessionToken(sessionToken); +} #endif } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/ui_ability_impl.cpp b/frameworks/native/ability/native/ui_ability_impl.cpp index 219365b3c3..f486eb5ada 100644 --- a/frameworks/native/ability/native/ui_ability_impl.cpp +++ b/frameworks/native/ability/native/ui_ability_impl.cpp @@ -46,7 +46,7 @@ void UIAbilityImpl::Init(const std::shared_ptr &app ability_->SetSceneListener(sptr( 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."); diff --git a/frameworks/native/ability/native/ui_ability_thread.cpp b/frameworks/native/ability/native/ui_ability_thread.cpp index 6946e1e03e..a7ff38455e 100644 --- a/frameworks/native/ability/native/ui_ability_thread.cpp +++ b/frameworks/native/ability/native/ui_ability_thread.cpp @@ -694,5 +694,14 @@ int UIAbilityThread::CreateModalUIExtension(const Want &want) } return currentAbility_->CreateModalUIExtension(want); } + +void UIAbilityThread::UpdateSessionToken(sptr sessionToken) +{ + if (currentAbility_ == nullptr) { + HILOG_ERROR("current ability is nullptr"); + return; + } + currentAbility_->UpdateSessionToken(sessionToken); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp new file mode 100644 index 0000000000..11a158fb9a --- /dev/null +++ b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp @@ -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 +#include +#include + +#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& uiAbiContext, + const std::shared_ptr& uiExtContext, int32_t screenMode) +{ + jsAbilityContext_ = std::make_shared(uiAbiContext); + jsUIExtensionContext_ = std::make_shared(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(static_cast(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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 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 jsContext = std::make_unique( + 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 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 jsContext = std::make_unique( + 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 uiAbiContext, std::shared_ptr 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 \ No newline at end of file diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index 6b02fff834..d72aed40ca 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -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 *>(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(ptr); napi_wrap(env, contextObj, workContext, [](napi_env, void *data, void *) { @@ -137,6 +156,7 @@ void JsUIExtension::Init(const std::shared_ptr &record, const sptr &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 &record, return; } - BindContext(env, obj); + BindContext(env, obj, record->GetWant()); SetExtensionCommon( JsExtensionCommon::Create(jsRuntime_, static_cast(*jsObj_), shellContextRef_)); } -void JsUIExtension::BindContext(napi_env env, napi_value obj) +void JsUIExtension::CreateJSContext(napi_env env, napi_value &contextObj, + std::shared_ptr 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 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(context); + CHECK_POINTER(workContext); + screenModePtr_ = std::make_shared(screenMode); + auto workScreenMode = new (std::nothrow) std::weak_ptr(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*>(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 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(reinterpret_cast(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 &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(); + configUtils->UpdateGlobalConfig(configuration, context->GetResourceManager()); + auto fullConfig = context->GetConfiguration(); if (!fullConfig) { HILOG_ERROR("configuration is nullptr."); diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index 95fef9c8d3..8842beb368 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -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 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(); + configUtils->UpdateGlobalConfig(configuration, context_->GetResourceManager()); + HandleScope handleScope(jsRuntime_); auto fullConfig = context_->GetConfiguration(); if (!fullConfig) { diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp index 4f4b7591da..f3a30e59e2 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp @@ -43,7 +43,7 @@ constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; } // namespace -static std::map, key_compare> g_connects; +static std::map, 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, sptrSetJsConnectionObject(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"); diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 91dc2a73b2..db9dda6f5a 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -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", diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index 762973c476..cbc33b7aaf 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -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 \ No newline at end of file diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index a110001cca..478275a189 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -349,6 +349,20 @@ std::string ApplicationContext::GetTempDir() return (contextImpl_ != nullptr) ? contextImpl_->GetTempDir() : ""; } +void ApplicationContext::GetAllTempDir(std::vector &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() : ""; diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index bd4222d8c5..52e9404476 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -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 &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 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 resConfig(Global::Resource::CreateResConfig()); - std::string hapPath; - std::vector 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 resourceManager = InitOthersResourceManagerInner( diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 69afff3f28..1ad29b1361 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -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); diff --git a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp index c85db03469..d9eac9b8bc 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp @@ -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, 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); diff --git a/frameworks/native/appkit/app/application_impl.cpp b/frameworks/native/appkit/app/application_impl.cpp index 3f63bc9e2f..0473644b21 100644 --- a/frameworks/native/appkit/app/application_impl.cpp +++ b/frameworks/native/appkit/app/application_impl.cpp @@ -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; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index df3c8ce0f6..4a1bb844fb 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -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 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(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 diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 5f4cf191be..09164546b0 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -13,6 +13,12 @@ * limitations under the License. */ +#include +#include +#include + +#include + #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::GetInstance(); + if (bundleMgrHelpers == nullptr) { + HILOG_ERROR("Get bundle mgr is nullptr."); + return; + } + + std::vector 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:: + 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 diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 425863014d..0531b22c45 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -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) { auto nativeEngine = GetNativeEnginePointer(); diff --git a/frameworks/simulator/ability_simulator/BUILD.gn b/frameworks/simulator/ability_simulator/BUILD.gn index 19c343e8c5..406fb5ede8 100644 --- a/frameworks/simulator/ability_simulator/BUILD.gn +++ b/frameworks/simulator/ability_simulator/BUILD.gn @@ -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 { diff --git a/frameworks/simulator/ability_simulator/include/ability_context.h b/frameworks/simulator/ability_simulator/include/ability_context.h index d872944173..3fa1f71634 100644 --- a/frameworks/simulator/ability_simulator/include/ability_context.h +++ b/frameworks/simulator/ability_simulator/include/ability_context.h @@ -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; diff --git a/frameworks/simulator/ability_simulator/include/ability_stage_context.h b/frameworks/simulator/ability_simulator/include/ability_stage_context.h index 8a270290a3..8a33aa60f3 100644 --- a/frameworks/simulator/ability_simulator/include/ability_stage_context.h +++ b/frameworks/simulator/ability_simulator/include/ability_stage_context.h @@ -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; diff --git a/frameworks/simulator/ability_simulator/include/js_application_context_utils.h b/frameworks/simulator/ability_simulator/include/js_application_context_utils.h index 73719c0c45..16aa185e9a 100644 --- a/frameworks/simulator/ability_simulator/include/js_application_context_utils.h +++ b/frameworks/simulator/ability_simulator/include/js_application_context_utils.h @@ -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); diff --git a/frameworks/simulator/ability_simulator/src/ability_context.cpp b/frameworks/simulator/ability_simulator/src/ability_context.cpp index 988fa53393..9e88f9b9dd 100644 --- a/frameworks/simulator/ability_simulator/src/ability_context.cpp +++ b/frameworks/simulator/ability_simulator/src/ability_context.cpp @@ -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() : ""; diff --git a/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp b/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp index 5bcf6899e0..579f600553 100644 --- a/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp +++ b/frameworks/simulator/ability_simulator/src/ability_stage_context.cpp @@ -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 AbilityStageContext::GetConfiguration() @@ -122,6 +124,20 @@ std::string AbilityStageContext::GetTempDir() return dir; } +std::string AbilityStageContext::GetResourceDir() +{ + std::shared_ptr 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()) { diff --git a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp index fb1649cc90..d184807042 100644 --- a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp +++ b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp @@ -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); diff --git a/frameworks/simulator/ability_simulator/src/js_context_utils.cpp b/frameworks/simulator/ability_simulator/src/js_context_utils.cpp index b12c6dd3f7..6baf4cafbf 100644 --- a/frameworks/simulator/ability_simulator/src/js_context_utils.cpp +++ b/frameworks/simulator/ability_simulator/src/js_context_utils.cpp @@ -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, 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); diff --git a/frameworks/simulator/ability_simulator/src/simulator.cpp b/frameworks/simulator/ability_simulator/src/simulator.cpp index c842f56234..6c6031dd2e 100644 --- a/frameworks/simulator/ability_simulator/src/simulator.cpp +++ b/frameworks/simulator/ability_simulator/src/simulator.cpp @@ -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::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 diff --git a/frameworks/simulator/common/include/context.h b/frameworks/simulator/common/include/context.h index 4c3885bdb6..1ce2f95e38 100644 --- a/frameworks/simulator/common/include/context.h +++ b/frameworks/simulator/common/include/context.h @@ -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; diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 8031f9753b..af3c8f2080 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -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", ] } diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 8c0b37c902..96eb565aaf 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1374,6 +1374,12 @@ public: */ int32_t GetForegroundUIAbilities(std::vector &list); + /** + * @brief Update session info. + * @param sessionInfos The vector of session info. + */ + void UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId); + private: class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { public: diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index b3445e5c8e..44e2d12671 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1401,6 +1401,12 @@ public: { return 0; } + + /** + * @brief Update session info. + * @param sessionInfos The vector of session info. + */ + virtual void UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) {} }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 2fdc8c7649..cf4e285bb5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -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, diff --git a/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h b/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h index 0764416d3a..ed122a4061 100644 --- a/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h @@ -302,6 +302,12 @@ public: virtual void CallRequest() = 0; + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + virtual void UpdateSessionToken(sptr 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 diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index c926b731c7..491aeb640c 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -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 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 diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index cfb00a58e7..76a14b8be6 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -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 token) override; + private: bool WriteInterfaceToken(MessageParcel &data); int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index 56f8f398b9..e3e9f623cf 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -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 memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 436c267483..3fdf8473fa 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -583,6 +583,20 @@ public: */ int32_t UnregisterAppRunningStatusListener(const sptr &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 token) const; + private: void SetServiceManager(std::unique_ptr serviceMgr); /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 4cc4005c02..1e21b4fd49 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -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, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index cf14f23536..d46f3e7f14 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -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 diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 5be99c278c..bd09eb7955 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -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); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index cf90a097ad..0ee21d490d 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -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 memberFuncMap_; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index d1473b2343..41a8b10224 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -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, diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index e25420d550..81d470a5c9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -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, diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index e1fb8f274d..b144244d07 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -828,6 +828,25 @@ bool AmsMgrProxy::IsAttachDebug(const std::string &bundleName) return reply.ReadBool(); } +void AmsMgrProxy::ClearProcessByToken(sptr 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(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) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index ff24805c61..734adb2776 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -97,6 +97,8 @@ void AmsMgrStub::CreateMemberFuncMap() &AmsMgrStub::HandleRegisterAbilityDebugResponse; memberFuncMap_[static_cast(IAmsMgr::Message::IS_ATTACH_DEBUG)] = &AmsMgrStub::HandleIsAttachDebug; + memberFuncMap_[static_cast(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 token = data.ReadRemoteObject(); + ClearProcessByToken(token); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 25a46deb91..a956d3dbec 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -909,5 +909,30 @@ int32_t AppMgrClient::UnregisterAppRunningStatusListener(const sptrUnregisterAppRunningStatusListener(listener); } + +bool AppMgrClient::IsFinalAppProcess() +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + HILOG_ERROR("Service is nullptr."); + return false; + } + return service->IsFinalAppProcess(); +} + +void AppMgrClient::ClearProcessByToken(sptr token) const +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + HILOG_ERROR("Service is nullptr."); + return; + } + sptr amsService = service->GetAmsMgr(); + if (amsService == nullptr) { + HILOG_ERROR("amsService is nullptr."); + return; + } + amsService->ClearProcessByToken(token); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index bf59abc362..80eb5a733e 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -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 diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 5ce1a7721c..9d1caeb6fe 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -157,6 +157,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleAttachChildProcess; memberFuncMap_[static_cast(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY)] = &AppMgrStub::HandleExitChildProcessSafely; + memberFuncMap_[static_cast(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 diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp index 4d99aa79b9..e2c37c5c2c 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp @@ -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; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index df53384f8b..5190be72ee 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -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(IAppScheduler::Message::SCHEDULE_TERMINATE_APPLICATION_TRANSACTION), data, reply, option); if (ret != NO_ERROR) { diff --git a/interfaces/inner_api/auto_fill_manager/BUILD.gn b/interfaces/inner_api/auto_fill_manager/BUILD.gn index ed20afc81c..efaf4489df 100644 --- a/interfaces/inner_api/auto_fill_manager/BUILD.gn +++ b/interfaces/inner_api/auto_fill_manager/BUILD.gn @@ -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" diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 74eacbf211..38ee111899 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -77,6 +77,8 @@ public: void PostSyncTask(const std::function& 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) override; void NotifyApplicationState(bool isBackground) override; bool SuspendVM(uint32_t tid) override; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index d41e52e8d6..95c80440f5 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -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) = 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; diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h index c9492d1d81..e8957a58e4 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_client.h @@ -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 &remoteObject); void OnLoadSystemAbilityFail(); private: diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h index dbfe57fa0e..01bec2bc1f 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_interface.h @@ -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 diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h index d92c1a5d3e..a28faf118a 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_proxy.h @@ -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 delegator_; diff --git a/interfaces/inner_api/uri_permission/include/uri_permission_manager_stub.h b/interfaces/inner_api/uri_permission/include/uri_permission_manager_stub.h index 62440bfff8..eb340b7405 100644 --- a/interfaces/inner_api/uri_permission/include/uri_permission_manager_stub.h +++ b/interfaces/inner_api/uri_permission/include/uri_permission_manager_stub.h @@ -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 diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp index 1fa891ad97..20cde6f0d8 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_client.cpp @@ -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 UriPermissionManagerClient::ConnectUriPermService() { HILOG_DEBUG("UriPermissionManagerClient::ConnectUriPermService is called."); diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp index 437c196584..33ec391be6 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_proxy.cpp @@ -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) { diff --git a/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp b/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp index 37d397ef2d..03c3a507cf 100644 --- a/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp +++ b/interfaces/inner_api/uri_permission/src/uri_permission_manager_stub.cpp @@ -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 diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h index 62587a3146..008b75e18c 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h @@ -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; diff --git a/interfaces/kits/native/ability/native/ability.h b/interfaces/kits/native/ability/native/ability.h index f161b9f3fc..70e4db4975 100644 --- a/interfaces/kits/native/ability/native/ability.h +++ b/interfaces/kits/native/ability/native/ability.h @@ -1138,6 +1138,12 @@ public: */ int CreateModalUIExtension(const Want &want); + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken); + protected: class AbilityDisplayListener : public OHOS::Rosen::DisplayManager::IDisplayListener { public: diff --git a/interfaces/kits/native/ability/native/ability_context.h b/interfaces/kits/native/ability/native/ability_context.h index cb16408b1f..e5ec3916b5 100644 --- a/interfaces/kits/native/ability/native/ability_context.h +++ b/interfaces/kits/native/ability/native/ability_context.h @@ -188,7 +188,7 @@ protected: std::string callingAbilityName_; std::string callingModuleName_; std::map, sptr> abilityConnectionMap_; - sptr sessionInfo_; + sptr sessionToken_; private: /** diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h index 43d35ff2b3..019c774510 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h @@ -31,6 +31,7 @@ class NativeReference; namespace OHOS { namespace AbilityRuntime { struct NapiCallbackInfo; +class JsEmbeddableUIAbilityContext; class JsAbilityContext final { public: explicit JsAbilityContext(const std::shared_ptr& context) : context_(context) {} @@ -119,6 +120,7 @@ private: std::weak_ptr context_; int curRequestCode_ = 0; sptr freeInstallObserver_ = nullptr; + friend class JsEmbeddableUIAbilityContext; }; napi_value CreateJsAbilityContext(napi_env env, std::shared_ptr context); diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h b/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h index 1603f91d96..69d55fd9dd 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h @@ -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, const std::shared_ptr application, + void Init(std::shared_ptr record, + const std::shared_ptr application, std::shared_ptr &handler, const sptr &token) override; /** @@ -296,17 +298,19 @@ private: std::unique_ptr CreateAppWindowStage(); std::shared_ptr CreateADelegatorAbilityProperty(); sptr SetNewRuleFlagToCallee(napi_env env, napi_value remoteJsObj); - void SetAbilityContext( - const std::shared_ptr &abilityInfo, const std::string &moduleName, const std::string &srcPath); + void SetAbilityContext(std::shared_ptr abilityInfo, + std::shared_ptr 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 &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 shellContextRef_; std::shared_ptr jsAbilityObj_; + std::shared_ptr screenModePtr_; sptr remoteCallee_; }; } // namespace AbilityRuntime diff --git a/interfaces/kits/native/ability/native/ability_thread.h b/interfaces/kits/native/ability/native/ability_thread.h index d3eeb440b0..d9167be4b7 100644 --- a/interfaces/kits/native/ability/native/ability_thread.h +++ b/interfaces/kits/native/ability/native/ability_thread.h @@ -350,6 +350,12 @@ public: */ int CreateModalUIExtension(const Want &want) override; + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken) override; + #ifdef ABILITY_COMMAND_FOR_TEST /** * @brief Block ability. diff --git a/interfaces/kits/native/ability/native/ability_window.h b/interfaces/kits/native/ability/native/ability_window.h index ce2cf08a75..2847fcf1eb 100644 --- a/interfaces/kits/native/ability/native/ability_window.h +++ b/interfaces/kits/native/ability/native/ability_window.h @@ -92,7 +92,7 @@ public: * @return Returns ERR_OK if success. */ virtual ErrCode SetMissionIcon(const std::shared_ptr &icon); - void SetSessionInfo(sptr &sessionInfo); + void SetSessionToken(sptr sessionToken); #endif private: @@ -100,7 +100,7 @@ private: std::weak_ptr ability_; std::shared_ptr windowScene_; bool isWindowAttached = false; - sptr sessionInfo_ = nullptr; + sptr sessionToken_ = nullptr; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h b/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h index c6c4c3759f..53214c0f05 100644 --- a/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h +++ b/interfaces/kits/native/ability/native/action_extension_ability/js_action_extension.h @@ -103,7 +103,7 @@ public: * The extension in the STATE_FOREGROUND 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 sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. diff --git a/interfaces/kits/native/ability/native/app_module_checker.h b/interfaces/kits/native/ability/native/app_module_checker.h index 27a4360719..fb7d9b84e8 100644 --- a/interfaces/kits/native/ability/native/app_module_checker.h +++ b/interfaces/kits/native/ability/native/app_module_checker.h @@ -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) override; bool DiskCheckOnly() override; protected: int32_t processExtensionType_{EXTENSION_TYPE_UNKNOWN}; diff --git a/interfaces/kits/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.h b/interfaces/kits/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.h index c6bf664596..71edc60fe5 100644 --- a/interfaces/kits/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.h +++ b/interfaces/kits/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.h @@ -97,7 +97,7 @@ public: * The extension in the STATE_FOREGROUND 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 sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. diff --git a/interfaces/kits/native/ability/native/extension.h b/interfaces/kits/native/ability/native/extension.h index 97c11730ab..88d67f8f5d 100644 --- a/interfaces/kits/native/ability/native/extension.h +++ b/interfaces/kits/native/ability/native/extension.h @@ -204,7 +204,7 @@ public: * The extension in the STATE_FOREGROUND state is visible. * You can override this function to implement your own processing logic. */ - virtual void OnForeground(const Want &want); + virtual void OnForeground(const Want &want, sptr sessionInfo); /** * @brief Called when this extension enters the STATE_BACKGROUND state. diff --git a/interfaces/kits/native/ability/native/extension_impl.h b/interfaces/kits/native/ability/native/extension_impl.h index 7d24e02e59..a8959b6996 100644 --- a/interfaces/kits/native/ability/native/extension_impl.h +++ b/interfaces/kits/native/ability/native/extension_impl.h @@ -182,7 +182,7 @@ protected: * * @param want The Want object to switch the life cycle. */ - void Foreground(const Want &want); + void Foreground(const Want &want, sptr sessionInfo); /** * @brief Toggles the lifecycle status of Extension to AAFwk::ABILITY_STATE_BACKGROUND. And notifies the diff --git a/interfaces/kits/native/ability/native/fa_ability_thread.h b/interfaces/kits/native/ability/native/fa_ability_thread.h index 39c626f440..031932fb46 100644 --- a/interfaces/kits/native/ability/native/fa_ability_thread.h +++ b/interfaces/kits/native/ability/native/fa_ability_thread.h @@ -338,6 +338,12 @@ public: */ int CreateModalUIExtension(const Want &want) override; + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken) override; + private: /** * @brief Dump Ability Runner info. diff --git a/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h b/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h index fa01e213aa..ddbbd15aa4 100644 --- a/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h +++ b/interfaces/kits/native/ability/native/share_extension_ability/js_share_extension.h @@ -105,7 +105,7 @@ public: * The extension in the STATE_FOREGROUND 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 sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. diff --git a/interfaces/kits/native/ability/native/ui_ability.h b/interfaces/kits/native/ability/native/ui_ability.h index fcae8f4369..0560b29232 100644 --- a/interfaces/kits/native/ability/native/ui_ability.h +++ b/interfaces/kits/native/ability/native/ui_ability.h @@ -20,6 +20,7 @@ #include "ability_continuation_interface.h" #include "ability_lifecycle_executor.h" #include "ability_lifecycle_interface.h" +#include "ability_local_record.h" #include "ability_transaction_callback_info.h" #include "configuration.h" #include "context.h" @@ -91,7 +92,7 @@ public: * @param handler the UIability EventHandler object * @param token the remote token */ - virtual void Init(const std::shared_ptr &abilityInfo, + virtual void Init(std::shared_ptr record, const std::shared_ptr application, std::shared_ptr &handler, const sptr &token); @@ -500,6 +501,12 @@ public: */ int CreateModalUIExtension(const AAFwk::Want &want); + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken); + protected: class UIAbilityDisplayListener : public OHOS::Rosen::DisplayManager::IDisplayListener { public: diff --git a/interfaces/kits/native/ability/native/ui_ability_thread.h b/interfaces/kits/native/ability/native/ui_ability_thread.h index 705bf4bf27..a0e86516b7 100644 --- a/interfaces/kits/native/ability/native/ui_ability_thread.h +++ b/interfaces/kits/native/ability/native/ui_ability_thread.h @@ -146,6 +146,12 @@ public: */ int CreateModalUIExtension(const Want &want) override; + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken) override; + private: void DumpAbilityInfoInner(const std::vector ¶ms, std::vector &info); void DumpOtherInfo(std::vector &info); diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h new file mode 100644 index 0000000000..4659a291b5 --- /dev/null +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h @@ -0,0 +1,108 @@ +/* + * 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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_JS_EMBEDDABLE_UI_ABILITY_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_JS_EMBEDDABLE_UI_ABILITY_CONTEXT_H + +#include +#include +#include + +#include "ability_connect_callback.h" +#include "event_handler.h" +#include "foundation/ability/ability_runtime/interfaces/kits/native/ability/ability_runtime/ability_context.h" +#include "js_ability_context.h" +#include "js_free_install_observer.h" +#include "js_runtime.h" +#include "js_ui_extension_context.h" + +namespace OHOS { +namespace AbilityRuntime { +class JsEmbeddableUIAbilityContext final { +public: + JsEmbeddableUIAbilityContext(const std::shared_ptr& uiAbiContext, + const std::shared_ptr& uiExtContext, int32_t screenMode); + ~JsEmbeddableUIAbilityContext() = default; + static void Finalizer(napi_env env, void* data, void* hint); + static napi_value StartAbility(napi_env env, napi_callback_info info); + static napi_value StartAbilityForResult(napi_env env, napi_callback_info info); + static napi_value ConnectAbility(napi_env env, napi_callback_info info); + static napi_value DisconnectAbility(napi_env env, napi_callback_info info); + static napi_value TerminateSelf(napi_env env, napi_callback_info info); + static napi_value TerminateSelfWithResult(napi_env env, napi_callback_info info); + static napi_value CreateJsEmbeddableUIAbilityContext(napi_env env, std::shared_ptr uiAbiContext, + std::shared_ptr uiExtContext, int32_t screenMode); + static napi_value StartAbilityAsCaller(napi_env env, napi_callback_info info); + static napi_value StartAbilityWithAccount(napi_env env, napi_callback_info info); + static napi_value StartAbilityByCall(napi_env env, napi_callback_info info); + static napi_value StartAbilityForResultWithAccount(napi_env env, napi_callback_info info); + static napi_value StartServiceExtensionAbility(napi_env env, napi_callback_info info); + static napi_value StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info); + static napi_value StopServiceExtensionAbility(napi_env env, napi_callback_info info); + static napi_value StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info); + static napi_value ConnectAbilityWithAccount(napi_env env, napi_callback_info info); + static napi_value RestoreWindowStage(napi_env env, napi_callback_info info); + static napi_value IsTerminating(napi_env env, napi_callback_info info); + static napi_value StartRecentAbility(napi_env env, napi_callback_info info); + static napi_value RequestDialogService(napi_env env, napi_callback_info info); + static napi_value ReportDrawnCompleted(napi_env env, napi_callback_info info); + static napi_value SetMissionContinueState(napi_env env, napi_callback_info info); + static napi_value StartAbilityByType(napi_env env, napi_callback_info info); + +private: + static void WrapJsUIAbilityContext(napi_env env, std::shared_ptr uiAbiContext, + napi_value &objValue, int32_t screenMode); + static void WrapJsUIExtensionContext(napi_env env, std::shared_ptr uiExtContext, + napi_value &objValue, int32_t screenMode); + napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info); + napi_value OnConnectAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnDisconnectAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnTerminateSelf(napi_env env, NapiCallbackInfo& info); + napi_value OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityAsCaller(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityWithAccount(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityByCall(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityForResultWithAccount(napi_env env, NapiCallbackInfo& info); + napi_value OnStartExtensionAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnStartExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info); + napi_value OnStopExtensionAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnStopExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info); + napi_value OnConnectAbilityWithAccount(napi_env env, NapiCallbackInfo& info); + napi_value OnRestoreWindowStage(napi_env env, NapiCallbackInfo& info); + napi_value OnIsTerminating(napi_env env, NapiCallbackInfo& info); + napi_value OnStartRecentAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnRequestDialogService(napi_env env, NapiCallbackInfo& info); + napi_value OnReportDrawnCompleted(napi_env env, NapiCallbackInfo& info); + napi_value OnSetMissionContinueState(napi_env env, NapiCallbackInfo& info); + napi_value OnStartAbilityByType(napi_env env, NapiCallbackInfo& info); + +#ifdef SUPPORT_GRAPHICS +public: + static napi_value SetMissionLabel(napi_env env, napi_callback_info info); + static napi_value SetMissionIcon(napi_env env, napi_callback_info info); +private: + napi_value OnSetMissionLabel(napi_env env, NapiCallbackInfo& info); + napi_value OnSetMissionIcon(napi_env env, NapiCallbackInfo& info); +#endif + +private: + std::shared_ptr jsAbilityContext_; + std::shared_ptr jsUIExtensionContext_; + int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_EMBEDDABLE_UI_ABILITY_CONTEXT_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h index c044cf73f2..81f144ff3a 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension.h @@ -150,7 +150,7 @@ public: * The extension in the STATE_FOREGROUND state is visible. * You can override this function to implement your own processing logic. */ - virtual void OnForeground(const Want &want) override; + virtual void OnForeground(const Want &want, sptr sessionInfo) override; /** * @brief Called when this extension enters the STATE_BACKGROUND state. @@ -182,7 +182,9 @@ public: void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override; private: - virtual void BindContext(napi_env env, napi_value obj); + virtual void BindContext(napi_env env, napi_value obj, std::shared_ptr want); + void CreateJSContext(napi_env env, napi_value &contextObj, + std::shared_ptr context, int32_t screenMode); napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0, bool withResult = false); @@ -210,6 +212,8 @@ private: std::set foregroundWindows_; std::map> contentSessions_; std::shared_ptr abilityResultListeners_ = nullptr; + int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE; + std::shared_ptr screenModePtr_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h index 3c9111a76a..bdc17f779c 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_base.h @@ -106,7 +106,7 @@ public: * The extension in the STATE_FOREGROUND state is visible. * You can override this function to implement your own processing logic. */ - void OnForeground(const Want &want); + void OnForeground(const Want &want, sptr sessionInfo); /** * @brief Called when this extension enters the STATE_BACKGROUND state. diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_context.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_context.h index 91b0630060..1f6b2f6bb3 100755 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_context.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_ui_extension_context.h @@ -24,6 +24,8 @@ namespace OHOS { namespace AbilityRuntime { struct NapiCallbackInfo; +class JsEmbeddableUIAbilityContext; + class JsUIExtensionContext { public: explicit JsUIExtensionContext(const std::shared_ptr& context) : context_(context) {} @@ -47,6 +49,7 @@ protected: private: std::weak_ptr context_; + friend class JsEmbeddableUIAbilityContext; bool CheckStartAbilityInputParam(napi_env env, NapiCallbackInfo& info, AAFwk::Want& want, AAFwk::StartOptions& startOptions, size_t& unwrapArgc) const; @@ -73,13 +76,13 @@ private: int64_t connectionId_ = -1; }; -struct ConnectionKey { +struct UIExtensionConnectionKey { AAFwk::Want want; int64_t id; }; struct key_compare { - bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const + bool operator()(const UIExtensionConnectionKey &key1, const UIExtensionConnectionKey &key2) const { if (key1.id < key2.id) { return true; diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index 76cab03e83..08ff07ea44 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -86,6 +86,7 @@ public: ErrCode QueryExtensionAbilityInfosOnlyWithTypeName(const std::string &extensionTypeName, const uint32_t flag, const int32_t userId, std::vector &extensionInfos); sptr GetDefaultAppProxy(); + ErrCode CleanObsoleteBundleTempFiles(); private: sptr Connect(); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index f5e4d299a9..42ec548bd4 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -69,6 +69,8 @@ public: std::string GetBundleCodeDir() override; std::string GetCacheDir() override; std::string GetTempDir() override; + std::string GetResourceDir() override; + void GetAllTempDir(std::vector &tempPaths); std::string GetFilesDir() override; bool IsUpdatingConfigurations() override; bool PrintDrawnCompleted() override; diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context.h b/interfaces/kits/native/appkit/ability_runtime/context/context.h index c0ebb4c3b3..b9f52d680b 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context.h @@ -121,6 +121,8 @@ public: */ virtual std::string GetFilesDir() = 0; + virtual std::string GetResourceDir() = 0; + /** * @brief Checks whether the configuration of this ability is changing. * diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 716c1174aa..ae7eb6b707 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -77,6 +77,15 @@ public: */ std::string GetTempDir() override; + std::string GetResourceDir() override; + + /** + * @brief Get all temporary directories. + * + * @param tempPaths Return all temporary directories of the application. + */ + virtual void GetAllTempDir(std::vector &tempPaths); + /** * @brief Obtains the directory for storing files for the application on the device's internal storage. * @@ -356,6 +365,7 @@ private: static const std::string CONTEXT_FILES; static const std::string CONTEXT_HAPS; static const std::string CONTEXT_ELS[]; + static const std::string CONTEXT_RESOURCE_END; int flags_ = 0x00000000; void InitResourceManager(const AppExecFwk::BundleInfo &bundleInfo, const std::shared_ptr &appContext, diff --git a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h index 5588b999a6..ce15613b4f 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h @@ -81,6 +81,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); @@ -100,6 +101,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); diff --git a/interfaces/kits/native/appkit/app/application_impl.h b/interfaces/kits/native/appkit/app/application_impl.h index aa05069725..ad2df98b63 100644 --- a/interfaces/kits/native/appkit/app/application_impl.h +++ b/interfaces/kits/native/appkit/app/application_impl.h @@ -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 @@ -68,10 +68,12 @@ public: /** * @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 PerformTerminate(); + bool PerformTerminate(bool isLastProcess = false); /** * @brief Schedule the application to the APP_STATE_TERMINATED state. diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index d56d96784f..928c70069d 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -140,8 +140,9 @@ public: * * @brief Schedule the terminate lifecycle of application. * + * @param isLastProcess When it is the last application process, pass in true. */ - void ScheduleTerminateApplication() override; + void ScheduleTerminateApplication(bool isLastProcess = false) override; /** * @@ -376,7 +377,7 @@ private: * @brief Terminate the application. * */ - void HandleTerminateApplication(); + void HandleTerminateApplication(bool isLastProcess = false); /** * @@ -521,6 +522,8 @@ private: void UpdateRuntimeModuleChecker(const std::unique_ptr &runtime); static void HandleDumpHeap(bool isPrivate); + static void DestroyHeapProfiler(); + static void ForceFullGC(); static void HandleSignal(int signal, siginfo_t *siginfo, void *context); void NotifyAppFault(const FaultData &faultData); diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 709aaa4501..0f1092d124 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -210,7 +210,6 @@ public: /** * * @brief Will be called the application ends - * */ virtual void OnTerminate(); @@ -295,6 +294,9 @@ public: bool NotifyHotReloadPage(); bool NotifyUnLoadRepairPatch(const std::string &hqfFile); + + void CleanAppTempData(bool isLastProcess = false); + private: void DoCleanWorkAfterStageCleaned(const AbilityInfo &abilityInfo); private: diff --git a/js_environment/frameworks/js_environment/BUILD.gn b/js_environment/frameworks/js_environment/BUILD.gn index f583cfc0f6..805568685c 100644 --- a/js_environment/frameworks/js_environment/BUILD.gn +++ b/js_environment/frameworks/js_environment/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") import("../../js_environment.gni") config("js_environment_config") { @@ -41,13 +42,16 @@ ohos_shared_library("js_environment") { public_configs = [ ":public_js_environment_config" ] external_deps = [ - "ace_engine:ace_uicontent", "ets_runtime:libark_jsruntime", "ets_utils:console", "eventhandler:libeventhandler", "napi:ace_napi", ] + if (ability_runtime_graphics) { + external_deps += [ "ace_engine:ace_uicontent" ] + } + subsystem_name = "ability" innerapi_tags = [ "platformsdk_indirect" ] part_name = "ability_runtime" diff --git a/js_environment/frameworks/js_environment/src/js_environment.cpp b/js_environment/frameworks/js_environment/src/js_environment.cpp index 3d855ae35f..1acf7b9329 100644 --- a/js_environment/frameworks/js_environment/src/js_environment.cpp +++ b/js_environment/frameworks/js_environment/src/js_environment.cpp @@ -284,6 +284,15 @@ void JsEnvironment::StartProfiler(const char* libraryPath, uint32_t instanceId, panda::DFXJSNApi::StartProfiler(vm_, option, tid, instanceId, debuggerPostTask); } +void JsEnvironment::DestroyHeapProfiler() +{ + if (vm_ == nullptr) { + JSENV_LOG_E("Invalid vm."); + return; + } + panda::DFXJSNApi::DestroyHeapProfiler(vm_); +} + void JsEnvironment::ReInitJsEnvImpl(std::unique_ptr impl) { JSENV_LOG_I("ReInit jsenv impl."); diff --git a/js_environment/frameworks/js_environment/src/source_map.cpp b/js_environment/frameworks/js_environment/src/source_map.cpp index 12ee303599..a5d08b9681 100644 --- a/js_environment/frameworks/js_environment/src/source_map.cpp +++ b/js_environment/frameworks/js_environment/src/source_map.cpp @@ -556,11 +556,13 @@ bool SourceMap::GetLineAndColumnNumbers(int& line, int& column, SourceMapData& t void SourceMap::RegisterGetHapPathCallback(GetHapPathCallback getFunc) { + std::lock_guard lock(sourceMapMutex_); getHapPathFunc_ = getFunc; } std::string SourceMap::GetHapPath(const std::string& inputPath, const std::string& bundleName) { + std::lock_guard lock(sourceMapMutex_); if (getHapPathFunc_) { return getHapPathFunc_(inputPath, bundleName); } diff --git a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp index 3c4263c638..a6da0479ee 100644 --- a/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp +++ b/js_environment/frameworks/js_environment/src/uncaught_exception_callback.cpp @@ -53,7 +53,8 @@ void NapiUncaughtExceptionCallback::operator()(napi_value obj) std::string errorMsg = GetNativeStrFromJsTaggedObj(obj, "message"); std::string errorName = GetNativeStrFromJsTaggedObj(obj, "name"); std::string errorStack = GetNativeStrFromJsTaggedObj(obj, "stack"); - std::string summary = "Error message:" + errorMsg + "\n"; + std::string summary = "Error name:" + errorName + "\n"; + summary += "Error message:" + errorMsg + "\n"; const JsEnv::ErrorObject errorObj = { .name = errorName, .message = errorMsg, diff --git a/js_environment/interfaces/inner_api/js_environment.h b/js_environment/interfaces/inner_api/js_environment.h index 768966d5cc..e4cafb8869 100644 --- a/js_environment/interfaces/inner_api/js_environment.h +++ b/js_environment/interfaces/inner_api/js_environment.h @@ -88,6 +88,8 @@ public: void StartProfiler( const char* libraryPath, uint32_t instanceId, PROFILERTYPE profiler, int32_t interval, uint32_t tid); + void DestroyHeapProfiler(); + void ReInitJsEnvImpl(std::unique_ptr impl); void SetModuleLoadChecker(const std::shared_ptr& moduleCheckerDelegate); diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index cc38680de0..466c12cd8f 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -176,7 +176,7 @@ ohos_shared_library("abilityms") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwindow_extension_client", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwsutils", "window_manager:scene_session", "window_manager:sms", @@ -212,7 +212,11 @@ ohos_shared_library("abilityms") { "input:libmmi-client", "resource_management:global_resmgr", "window_manager:libdm", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwm", + "window_manager:libwsutils", + "window_manager:scene_session", + "window_manager:sms", ] } @@ -238,9 +242,16 @@ ohos_prebuilt_etc("uiextension_picker_config.json") { part_name = "ability_runtime" } +ohos_prebuilt_etc("proxy_authorization_uri.json") { + source = "resource/proxy_authorization_uri.json" + subsystem_name = "ability" + part_name = "ability_runtime" +} + group("ams_service_config") { deps = [ ":ams_service_config.json", + ":proxy_authorization_uri.json", ":uiextension_picker_config.json", ] } diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 858850a184..551b9c36a7 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -257,7 +257,7 @@ public: void TerminateAbilityWindowLocked(const std::shared_ptr &abilityRecord, const sptr &sessionInfo); - + void RemoveLauncherDeathRecipient(); // MSG 0 - 20 represents timeout message @@ -353,6 +353,7 @@ private: void HandleCommandTimeoutTask(const std::shared_ptr &abilityRecord); void HandleCommandWindowTimeoutTask(const std::shared_ptr &abilityRecord, const sptr &sessionInfo, WindowCommand winCmd); + void HandleForegroundTimeoutTask(const std::shared_ptr &abilityRecord); void HandleRestartResidentTask(const AbilityRequest &abilityRequest); void HandleActiveAbility(std::shared_ptr &targetService, std::shared_ptr &connectRecord); @@ -464,6 +465,9 @@ private: void HandleInactiveTimeout(const std::shared_ptr &ability); void MoveToTerminatingMap(const std::shared_ptr& abilityRecord); + void DoForegroundUIExtension(std::shared_ptr abilityRecord, const AbilityRequest &abilityRequest); + void SaveUIExtRequestSessionInfo(std::shared_ptr abilityRecord, sptr sessionInfo); + /** * When a service is under starting, enque the request and handle it after the service starting completes */ @@ -508,8 +512,8 @@ private: inline bool CheckUIExtensionAbilityLoaded(const AbilityRequest &abilityRequest); inline bool CheckUIExtensionAbilitySessionExistLocked(const std::shared_ptr &abilityRecord); inline void RemoveUIExtensionAbilityRecord(const std::shared_ptr &abilityRecord); - int32_t GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, const std::string &hostBundleName, - std::shared_ptr &extensionRecord, bool &isLoaded); + int32_t GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, bool isCreatedByConnect, + const std::string &hostBundleName, std::shared_ptr &extensionRecord, bool &isLoaded); private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; @@ -519,6 +523,8 @@ private: ConnectMapType connectMap_; ServiceMapType serviceMap_; ServiceMapType terminatingExtensionMap_; + + std::mutex recipientMapMutex_; RecipientMapType recipientMap_; RecipientMapType uiExtRecipientMap_; std::shared_ptr taskHandler_; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index eb86955a71..0cc9e8cb93 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -1114,6 +1114,12 @@ public: * @return int The file descriptor. */ virtual int32_t OpenFile(const Uri& uri, uint32_t flag) override; + + /** + * @brief Update session info. + * @param sessionInfos The vector of session info. + */ + virtual void UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) override; private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 2f0a56169d..86e9cebb22 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1454,6 +1454,12 @@ public: void RemoveLauncherDeathRecipient(int32_t userId); + /** + * @brief Update session info. + * @param sessionInfos The vector of session info. + */ + virtual void UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) override; + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; @@ -1713,6 +1719,9 @@ private: void AppRecoverKill(pid_t pid, int32_t reason); + int32_t GenerateEmbeddableUIAbilityRequest(const Want &want, AbilityRequest &request, + const sptr &callerToken, int32_t userId); + /** * Check if Caller is allowed to start ServiceAbility(FA) or ServiceExtension(Stage) or DataShareExtension(Stage). * diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index c7bd00670f..e5d20fcfcc 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -263,6 +263,7 @@ private: int PrepareTerminateAbilityBySCBInner(MessageParcel &data, MessageParcel &reply); int RegisterSessionHandlerInner(MessageParcel &data, MessageParcel &reply); + int32_t UpdateSessionInfoBySCBInner(MessageParcel &data, MessageParcel &reply); int32_t RegisterAppDebugListenerInner(MessageParcel &data, MessageParcel &reply); int32_t UnregisterAppDebugListenerInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 2ccbca2a83..d3d3cf0161 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -341,7 +341,7 @@ public: * */ void ForegroundAbility(uint32_t sceneFlag = 0); - void ForegroundAbility(const Closure &task, uint32_t sceneFlag = 0); + void ForegroundAbility(const Closure &task, sptr sessionInfo = nullptr, uint32_t sceneFlag = 0); /** * process request of foregrounding the ability. @@ -416,9 +416,16 @@ public: return scheduler_; } - inline sptr GetSessionInfo() const + sptr GetSessionInfo() const; + + sptr GetUIExtRequestSessionInfo() const { - return sessionInfo_; + return uiExtRequestSessionInfo_; + } + + void SetUIExtRequestSessionInfo(sptr sessionInfo) + { + uiExtRequestSessionInfo_ = sessionInfo; } /** @@ -551,7 +558,7 @@ public: * set the ability is created by connect ability mode. * */ - void SetCreateByConnectMode(); + void SetCreateByConnectMode(bool isCreatedByConnect = true); /** * active the ability. @@ -865,6 +872,7 @@ public: bool IsStartToForeground() const; void SetStartToForeground(const bool flag); void SetSessionInfo(sptr sessionInfo); + void UpdateSessionInfo(sptr sessionToken); void SetMinimizeReason(bool fromUser); bool IsMinimizeFromUser() const; void SetClearMissionFlag(bool clearMissionFlag); @@ -1112,8 +1120,10 @@ private: // scene session sptr sessionInfo_ = nullptr; + mutable ffrt::mutex sessionLock_; sptr abilityAppStateObserver_; std::map abilityWindowStateMap_; + sptr uiExtRequestSessionInfo_ = nullptr; #ifdef SUPPORT_GRAPHICS bool isStartingWindow_ = false; diff --git a/services/abilitymgr/include/ability_scheduler_proxy.h b/services/abilitymgr/include/ability_scheduler_proxy.h index d6b774a468..cdd8571026 100644 --- a/services/abilitymgr/include/ability_scheduler_proxy.h +++ b/services/abilitymgr/include/ability_scheduler_proxy.h @@ -325,6 +325,12 @@ public: void OnExecuteIntent(const Want &want) override; + /** + * @brief Update sessionToken. + * @param sessionToken The token of session. + */ + void UpdateSessionToken(sptr sessionToken) override; + #ifdef ABILITY_COMMAND_FOR_TEST int BlockAbility() override; #endif diff --git a/services/abilitymgr/include/ability_scheduler_stub.h b/services/abilitymgr/include/ability_scheduler_stub.h index aa4822c3f3..40291b9e25 100644 --- a/services/abilitymgr/include/ability_scheduler_stub.h +++ b/services/abilitymgr/include/ability_scheduler_stub.h @@ -74,6 +74,7 @@ private: int ContinueAbilityInner(MessageParcel &data, MessageParcel &reply); int ShareDataInner(MessageParcel &data, MessageParcel &reply); int CreateModalUIExtensionInner(MessageParcel &data, MessageParcel &reply); + int UpdateSessionTokenInner(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (AbilitySchedulerStub::*)(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; }; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 0ce02c8739..dd613f6d1d 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -398,6 +398,13 @@ public: */ bool IsAttachDebug(const std::string &bundleName); + /** + * To clear the process by ability token. + * + * @param token the unique identification to the ability. + */ + void ClearProcessByToken(sptr token) const; + protected: /** * OnAbilityRequestDone, app manager service call this interface after ability request done. diff --git a/services/abilitymgr/include/dialog_session_record.h b/services/abilitymgr/include/dialog_session_record.h index f693044480..7fe7f241a1 100644 --- a/services/abilitymgr/include/dialog_session_record.h +++ b/services/abilitymgr/include/dialog_session_record.h @@ -34,6 +34,7 @@ struct DialogCallerInfo { int requestCode = -1; sptr callerToken; Want targetWant; + bool isSelector = false; }; class DialogSessionRecord { diff --git a/services/abilitymgr/include/lifecycle_deal.h b/services/abilitymgr/include/lifecycle_deal.h index f6f8735429..d2b860d47b 100644 --- a/services/abilitymgr/include/lifecycle_deal.h +++ b/services/abilitymgr/include/lifecycle_deal.h @@ -63,6 +63,7 @@ public: void NotifyContinuationResult(int32_t result); void ShareData(const int32_t &uniqueId); bool PrepareTerminateAbility(); + void UpdateSessionToken(sptr sessionToken); private: sptr GetScheduler(); diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 4afdd06756..9053f0bc10 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -298,6 +298,12 @@ public: bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr &targetRecord, const int32_t oriValidUserId); + /** + * @brief Update session info. + * @param sessionInfos The vector of session info. + */ + void UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId); + private: std::shared_ptr GetAbilityRecordByToken(const sptr &token) const; int32_t GetPersistentIdByAbilityRequest(const AbilityRequest &abilityRequest, bool &reuse, int32_t userId) const; diff --git a/services/abilitymgr/resource/proxy_authorization_uri.json b/services/abilitymgr/resource/proxy_authorization_uri.json new file mode 100644 index 0000000000..223b9c38ce --- /dev/null +++ b/services/abilitymgr/resource/proxy_authorization_uri.json @@ -0,0 +1,32 @@ +{ + "proxyAuthorizationUri": + [ + { + "bundleName": "ohos.global.systemres" + }, + { + "bundleName": "com.ohos.camera" + }, + { + "bundleName": "com.ohos.photos" + }, + { + "bundleName": "com.ohos.medialibrary.medialibrarydata" + }, + { + "bundleName": "com.ohos.filepicker" + }, + { + "bundleName": "foundation" + }, + { + "bundleName": "wallpaper_service" + }, + { + "bundleName": "distributeddata" + }, + { + "bundleName": "pasteboard_service" + } + ] +} \ No newline at end of file diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index 2c186e47aa..55eedc3fca 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -705,6 +705,13 @@ int32_t AbilityAutoStartupService::CheckPermissionForSystem() HILOG_ERROR("The caller is not system-app, can not use system-api."); return ERR_NOT_SYSTEM_APP; } + + if (!PermissionVerification::GetInstance()->VerifyCallingPermission( + PermissionConstants::PERMISSION_MANAGE_APP_BOOT)) { + HILOG_ERROR("Not have PERMISSION_MANAGE_APP_BOOT approval."); + return CHECK_PERMISSION_FAILED; + } + return ERR_OK; } diff --git a/services/abilitymgr/src/ability_connect_callback_stub.cpp b/services/abilitymgr/src/ability_connect_callback_stub.cpp index 61d65887a4..4e6dd562e4 100644 --- a/services/abilitymgr/src/ability_connect_callback_stub.cpp +++ b/services/abilitymgr/src/ability_connect_callback_stub.cpp @@ -126,7 +126,7 @@ int AbilityConnectionStub::OnRemoteRequest( return ERR_INVALID_STATE; } - auto element = data.ReadParcelable(); + std::unique_ptr element(data.ReadParcelable()); if (element == nullptr) { HILOG_ERROR("callback stub receive element is nullptr"); return ERR_INVALID_VALUE; @@ -137,33 +137,27 @@ int AbilityConnectionStub::OnRemoteRequest( auto remoteObject = data.ReadRemoteObject(); if (remoteObject == nullptr) { HILOG_ERROR("callback stub receive remoteObject is nullptr"); - delete element; return ERR_INVALID_VALUE; } auto resultCode = data.ReadInt32(); + HILOG_INFO("AbilityConnectionStub ON_ABILITY_CONNECT_DONE"); OnAbilityConnectDone(*element, remoteObject, resultCode); HILOG_DEBUG("AbilityConnectionStub ON_ABILITY_CONNECT_DONE end"); - delete element; return NO_ERROR; } case IAbilityConnection::ON_ABILITY_DISCONNECT_DONE: { auto resultCode = data.ReadInt32(); OnAbilityDisconnectDone(*element, resultCode); HILOG_DEBUG("AbilityConnectionStub ON_ABILITY_DISCONNECT_DONE"); - delete element; return NO_ERROR; } case IAbilityConnection::ON_REMOTE_STATE_CHANGED: { int32_t abilityState = data.ReadInt32(); OnRemoteStateChanged(*element, abilityState); - delete element; return NO_ERROR; } default: { HILOG_INFO("AbilityConnectionStub default"); - if (element != nullptr) { - delete element; - } return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index a79e2618e5..414859ae95 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -23,11 +23,11 @@ #include "ability_manager_service.h" #include "ability_util.h" #include "appfreeze_manager.h" +#include "app_utils.h" #include "extension_config.h" #include "hitrace_meter.h" #include "hilog_wrapper.h" #include "in_process_call_wrapper.h" -#include "mock_session_manager_service.h" #include "parameter.h" #include "session/host/include/zidl/session_interface.h" #include "extension_record.h" @@ -50,11 +50,13 @@ const int LOAD_TIMEOUT_MULTIPLE = 150; const int CONNECT_TIMEOUT_MULTIPLE = 45; const int COMMAND_TIMEOUT_MULTIPLE = 75; const int COMMAND_WINDOW_TIMEOUT_MULTIPLE = 75; +const int UI_EXTENSION_CONSUME_SESSION_TIMEOUT_MULTIPLE = 45; #else const int LOAD_TIMEOUT_MULTIPLE = 10; const int CONNECT_TIMEOUT_MULTIPLE = 3; const int COMMAND_TIMEOUT_MULTIPLE = 5; const int COMMAND_WINDOW_TIMEOUT_MULTIPLE = 5; +const int UI_EXTENSION_CONSUME_SESSION_TIMEOUT_MULTIPLE = 3; #endif const int32_t AUTO_DISCONNECT_INFINITY = -1; const std::unordered_map trustMap = { @@ -123,7 +125,7 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque return ERR_NULL_OBJECT; } std::string hostBundleName = callerAbilityRecord->GetAbilityInfo().bundleName; - int32_t ret = GetOrCreateExtensionRecord(abilityRequest, hostBundleName, targetService, isLoadedAbility); + int32_t ret = GetOrCreateExtensionRecord(abilityRequest, false, hostBundleName, targetService, isLoadedAbility); if (ret != ERR_OK) { HILOG_ERROR("Failed to get or create extension record, ret: %{public}d", ret); return ret; @@ -142,6 +144,9 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque auto &remoteObj = abilityRequest.sessionInfo->sessionToken; uiExtensionMap_[remoteObj] = UIExtWindowMapValType(targetService, abilityRequest.sessionInfo); AddUIExtWindowDeathRecipient(remoteObj); + if (!isLoadedAbility) { + SaveUIExtRequestSessionInfo(targetService, abilityRequest.sessionInfo); + } } if (!isLoadedAbility) { @@ -151,12 +156,8 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque // It may have been started through connect targetService->SetWant(abilityRequest.want); CommandAbility(targetService); - } else if (IsUIExtensionAbility(targetService) && - targetService->IsReady() && !targetService->IsAbilityState(AbilityState::INACTIVATING) && - !targetService->IsAbilityState(AbilityState::BACKGROUNDING) && - targetService->IsAbilityWindowReady()) { - targetService->SetWant(abilityRequest.want); - CommandAbilityWindow(targetService, abilityRequest.sessionInfo, WIN_CMD_FOREGROUND); + } else if (IsUIExtensionAbility(targetService)) { + DoForegroundUIExtension(targetService, abilityRequest); } else { HILOG_INFO("Target service is already activating."); EnqueueStartServiceReq(abilityRequest); @@ -172,6 +173,48 @@ int AbilityConnectManager::StartAbilityLocked(const AbilityRequest &abilityReque return ERR_OK; } +void AbilityConnectManager::DoForegroundUIExtension(std::shared_ptr abilityRecord, + const AbilityRequest &abilityRequest) +{ + CHECK_POINTER(abilityRecord); + if (abilityRecord->IsReady() && !abilityRecord->IsAbilityState(AbilityState::INACTIVATING) && + !abilityRecord->IsAbilityState(AbilityState::FOREGROUNDING) && + !abilityRecord->IsAbilityState(AbilityState::BACKGROUNDING) && + abilityRecord->IsAbilityWindowReady()) { + if (abilityRecord->IsAbilityState(AbilityState::FOREGROUND)) { + abilityRecord->SetWant(abilityRequest.want); + CommandAbilityWindow(abilityRecord, abilityRequest.sessionInfo, WIN_CMD_FOREGROUND); + return; + } else { + if (abilityRecord->GetUIExtRequestSessionInfo() == nullptr) { + abilityRecord->SetWant(abilityRequest.want); + SaveUIExtRequestSessionInfo(abilityRecord, abilityRequest.sessionInfo); + DelayedSingleton::GetInstance()->MoveToForeground(abilityRecord->GetToken()); + return; + } + } + } + EnqueueStartServiceReq(abilityRequest); +} + +void AbilityConnectManager::SaveUIExtRequestSessionInfo(std::shared_ptr abilityRecord, + sptr sessionInfo) +{ + CHECK_POINTER(abilityRecord); + CHECK_POINTER(taskHandler_); + abilityRecord->SetUIExtRequestSessionInfo(sessionInfo); + auto callback = [abilityRecord, connectManager = shared_from_this()]() { + std::lock_guard guard{connectManager->Lock_}; + HILOG_ERROR("consume session timeout, abilityUri: %{public}s", abilityRecord->GetURI().c_str()); + abilityRecord->SetUIExtRequestSessionInfo(nullptr); + }; + + int consumeSessionTimeout = AmsConfigurationParameter::GetInstance().GetAppStartTimeoutTime() * + UI_EXTENSION_CONSUME_SESSION_TIMEOUT_MULTIPLE; + std::string taskName = std::string("ConsumeSessionTimeout_") + std::to_string(abilityRecord->GetRecordId()); + taskHandler_->SubmitTask(callback, taskName, consumeSessionTimeout); +} + void AbilityConnectManager::EnqueueStartServiceReq(const AbilityRequest &abilityRequest) { std::lock_guard guard(startServiceReqListLock_); @@ -256,7 +299,7 @@ int AbilityConnectManager::StopServiceAbilityLocked(const AbilityRequest &abilit return ERR_OK; } -int32_t AbilityConnectManager::GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, +int32_t AbilityConnectManager::GetOrCreateExtensionRecord(const AbilityRequest &abilityRequest, bool isCreatedByConnect, const std::string &hostBundleName, std::shared_ptr &extensionRecord, bool &isLoaded) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -269,6 +312,7 @@ int32_t AbilityConnectManager::GetOrCreateExtensionRecord(const AbilityRequest & if (ret != ERR_OK) { return ret; } + extensionRecord->SetCreateByConnectMode(isCreatedByConnect); std::string extensionRecordKey = element.GetURI() + std::to_string(extensionRecord->GetUIExtensionAbilityId()); extensionRecord->SetURI(extensionRecordKey); HILOG_DEBUG("Service map add, hostBundleName:%{public}s, key: %{public}s", hostBundleName.c_str(), @@ -357,9 +401,9 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq // 1. get target service ability record, and check whether it has been loaded. std::shared_ptr targetService; bool isLoadedAbility = false; - if (IsUIExtensionAbility(targetService) && connectInfo != nullptr) { + if (UIExtensionUtils::IsUIExtension(abilityRequest.abilityInfo.extensionAbilityType) && connectInfo != nullptr) { int32_t ret = GetOrCreateExtensionRecord( - abilityRequest, connectInfo->hostBundleName, targetService, isLoadedAbility); + abilityRequest, true, connectInfo->hostBundleName, targetService, isLoadedAbility); if (ret != ERR_OK || targetService == nullptr) { HILOG_ERROR("Failed to get or create extension record."); return ERR_NULL_OBJECT; @@ -389,11 +433,9 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq targetService->SetSessionInfo(sessionInfo); connectRecordList.push_back(connectRecord); if (isCallbackConnected) { - HILOG_INFO("callbackConnected remove connect"); RemoveConnectDeathRecipient(connect); connectMap_.erase(connectMap_.find(connect->AsObject())); } - HILOG_INFO("insert connect"); AddConnectDeathRecipient(connect); connectMap_.emplace(connect->AsObject(), connectRecordList); targetService->SetLaunchReason(LaunchReason::LAUNCHREASON_CONNECT_EXTENSION); @@ -404,12 +446,10 @@ int AbilityConnectManager::ConnectAbilityLocked(const AbilityRequest &abilityReq WindowExtMapValType(targetService->GetApplicationInfo().accessTokenId, abilityRequest.sessionInfo)); } - // 5. load or connect ability int ret = ERR_OK; if (!isLoadedAbility) { LoadAbility(targetService); } else if (targetService->IsAbilityState(AbilityState::ACTIVE)) { - // this service ability has connected already targetService->SetWant(abilityRequest.want); HandleActiveAbility(targetService, connectRecord); } else { @@ -561,7 +601,11 @@ int AbilityConnectManager::AttachAbilityThreadLocked( std::string element = abilityRecord->GetURI(); HILOG_DEBUG("Ability: %{public}s", element.c_str()); abilityRecord->SetScheduler(scheduler); - abilityRecord->Inactivate(); + if (IsUIExtensionAbility(abilityRecord) && !abilityRecord->IsCreateByConnect()) { + DelayedSingleton::GetInstance()->MoveToForeground(token); + } else { + abilityRecord->Inactivate(); + } return ERR_OK; } @@ -765,6 +809,7 @@ int AbilityConnectManager::ScheduleDisconnectAbilityDoneLocked(const sptrIsAbilityState(AbilityState::INACTIVE) || - abilityRecord->IsAbilityState(AbilityState::ACTIVE) || - abilityRecord->IsAbilityState(AbilityState::BACKGROUND) || - abilityRecord->IsAbilityState(AbilityState::BACKGROUNDING)) { - HILOG_DEBUG("Foreground %{public}s", element.c_str()); - DelayedSingleton::GetInstance()->MoveToForeground(token); - } - break; - } case ABILITY_CMD_BACKGROUND: { if (abilityRecord->IsAbilityState(AbilityState::INACTIVE) || abilityRecord->IsAbilityState(AbilityState::ACTIVE) || @@ -913,6 +948,9 @@ void AbilityConnectManager::CompleteStartServiceReq(const std::string &serviceUr if (it != startServiceReqList_.end()) { reqList = it->second; startServiceReqList_.erase(it); + if (taskHandler_) { + taskHandler_->CancelTask(std::string("start_service_timeout:") + serviceUri); + } } } @@ -1294,8 +1332,6 @@ int AbilityConnectManager::DispatchInactive(const std::shared_ptr abilityRecord->SetAbilityState(AbilityState::INACTIVE); if (abilityRecord->IsCreateByConnect()) { ConnectAbility(abilityRecord); - } else if (IsUIExtensionAbility(abilityRecord)) { - CommandAbilityWindow(abilityRecord, abilityRecord->GetSessionInfo(), WIN_CMD_FOREGROUND); } else { CommandAbility(abilityRecord); if (abilityRecord->GetConnectRecordList().size() > 0) { @@ -1460,8 +1496,7 @@ void AbilityConnectManager::TerminateDone(const std::shared_ptr & IN_PROCESS_CALL_WITHOUT_RET(abilityRecord->RevokeUriPermission()); abilityRecord->RemoveAbilityDeathRecipient(); if (IsSceneBoard(abilityRecord)) { - HILOG_INFO("SceneBoard exit normally."); - Rosen::MockSessionManagerService::GetInstance().NotifyNotKillService(); + HILOG_INFO("To kill processes because scb exit."); KillProcessesByUserId(); } DelayedSingleton::GetInstance()->TerminateAbility(abilityRecord->GetToken(), false); @@ -1512,37 +1547,49 @@ void AbilityConnectManager::RemoveServiceAbility(const std::shared_ptr &connect) { CHECK_POINTER(connect); - CHECK_POINTER(connect->AsObject()); - auto it = recipientMap_.find(connect->AsObject()); - if (it != recipientMap_.end()) { - HILOG_ERROR("This death recipient has been added."); - return; - } else { - std::weak_ptr thisWeakPtr(shared_from_this()); - sptr deathRecipient = - new AbilityConnectCallbackRecipient([thisWeakPtr](const wptr &remote) { - auto abilityConnectManager = thisWeakPtr.lock(); - if (abilityConnectManager) { - abilityConnectManager->OnCallBackDied(remote); - } - }); - if (!connect->AsObject()->AddDeathRecipient(deathRecipient)) { - HILOG_ERROR("AddDeathRecipient failed."); + auto connectObject = connect->AsObject(); + CHECK_POINTER(connectObject); + { + std::lock_guard guard(recipientMapMutex_); + auto it = recipientMap_.find(connectObject); + if (it != recipientMap_.end()) { + HILOG_ERROR("This death recipient has been added."); + return; } - recipientMap_.emplace(connect->AsObject(), deathRecipient); } + + std::weak_ptr thisWeakPtr(shared_from_this()); + sptr deathRecipient = + new AbilityConnectCallbackRecipient([thisWeakPtr](const wptr &remote) { + auto abilityConnectManager = thisWeakPtr.lock(); + if (abilityConnectManager) { + abilityConnectManager->OnCallBackDied(remote); + } + }); + if (!connectObject->AddDeathRecipient(deathRecipient)) { + HILOG_ERROR("AddDeathRecipient failed."); + } + std::lock_guard guard(recipientMapMutex_); + recipientMap_.emplace(connectObject, deathRecipient); } void AbilityConnectManager::RemoveConnectDeathRecipient(const sptr &connect) { CHECK_POINTER(connect); - CHECK_POINTER(connect->AsObject()); - auto it = recipientMap_.find(connect->AsObject()); - if (it != recipientMap_.end() && it->first != nullptr) { - it->first->RemoveDeathRecipient(it->second); + auto connectObject = connect->AsObject(); + CHECK_POINTER(connectObject); + sptr deathRecipient; + { + std::lock_guard guard(recipientMapMutex_); + auto it = recipientMap_.find(connectObject); + if (it == recipientMap_.end()) { + return; + } + deathRecipient = it->second; recipientMap_.erase(it); - return; } + + connectObject->RemoveDeathRecipient(deathRecipient); } void AbilityConnectManager::OnCallBackDied(const wptr &remote) @@ -1727,7 +1774,8 @@ void AbilityConnectManager::HandleAbilityDiedTask( HandleUIExtensionDied(abilityRecord); } - if (GetExtensionFromServiceMapInner(abilityRecord->GetToken()) == nullptr) { + auto token = abilityRecord->GetToken(); + if (GetExtensionFromServiceMapInner(token) == nullptr) { HILOG_ERROR("Died ability record is not exist in service map."); return; } @@ -1735,6 +1783,9 @@ void AbilityConnectManager::HandleAbilityDiedTask( MoveToTerminatingMap(abilityRecord); RemoveServiceAbility(abilityRecord); if (IsAbilityNeedKeepAlive(abilityRecord)) { + if ((IsLauncher(abilityRecord) || IsSceneBoard(abilityRecord)) && token != nullptr) { + DelayedSingleton::GetInstance()->ClearProcessByToken(token->AsObject()); + } HILOG_INFO("restart ability: %{public}s", abilityRecord->GetAbilityInfo().name.c_str()); RestartAbility(abilityRecord, currentUserId); } @@ -1778,13 +1829,12 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr requestInfo.restart = true; abilityRecord->SetRestarting(true); - if (currentUserId != userId_ && - abilityRecord->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME) { - HILOG_WARN("delay restart root launcher until switch user."); - return; - } - - if (abilityRecord->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME) { + if (AppUtils::GetInstance().IsLauncherAbility(abilityRecord->GetAbilityInfo().name)) { + if (currentUserId != userId_) { + HILOG_WARN("delay restart root launcher until switch user."); + return; + } + requestInfo.want.SetParam("ohos.app.recovery", true); requestInfo.restartCount = abilityRecord->GetRestartCount(); HILOG_DEBUG("restart root launcher, number:%{public}d", requestInfo.restartCount); StartAbilityLocked(requestInfo); @@ -2045,8 +2095,20 @@ void AbilityConnectManager::MoveToForeground(const std::shared_ptrPrintTimeOutLog(abilityRecord, AbilityManagerService::FOREGROUND_TIMEOUT_MSG); + selfObj->HandleForegroundTimeoutTask(abilityRecord); }; - abilityRecord->ForegroundAbility(task); + auto sessionInfo = abilityRecord->GetUIExtRequestSessionInfo(); + if (sessionInfo != nullptr) { + abilityRecord->ForegroundAbility(task, sessionInfo); + abilityRecord->SetUIExtRequestSessionInfo(nullptr); + } else { + HILOG_WARN("SessionInfo is nullptr. Move to background"); + abilityRecord->SetAbilityState(AbilityState::BACKGROUND); + DelayedSingleton::GetInstance()->MoveToBackground(abilityRecord->GetToken()); + } + if (taskHandler_) { + taskHandler_->CancelTask(std::string("ConsumeSessionTimeout_") + std::to_string(abilityRecord->GetRecordId())); + } } void AbilityConnectManager::MoveToBackground(const std::shared_ptr &abilityRecord) @@ -2077,17 +2139,37 @@ void AbilityConnectManager::MoveToBackground(const std::shared_ptr &abilityRecord) { std::lock_guard guard(Lock_); + if (abilityRecord == nullptr) { + HILOG_ERROR("abilityRecord is nullptr"); + return; + } if (abilityRecord->GetAbilityState() != AbilityState::FOREGROUNDING) { HILOG_ERROR("Ability state is %{public}d, it can't complete foreground.", abilityRecord->GetAbilityState()); return; } abilityRecord->SetAbilityState(AbilityState::FOREGROUND); + CompleteStartServiceReq(abilityRecord->GetURI()); +} + +void AbilityConnectManager::HandleForegroundTimeoutTask(const std::shared_ptr &abilityRecord) +{ + std::lock_guard guard(Lock_); + if (abilityRecord == nullptr) { + HILOG_ERROR("abilityRecord is nullptr"); + return; + } + abilityRecord->SetAbilityState(AbilityState::BACKGROUND); + CompleteStartServiceReq(abilityRecord->GetURI()); } void AbilityConnectManager::CompleteBackground(const std::shared_ptr &abilityRecord) { std::lock_guard guard(Lock_); + if (abilityRecord == nullptr) { + HILOG_ERROR("abilityRecord is nullptr"); + return; + } if (abilityRecord->GetAbilityState() != AbilityState::BACKGROUNDING) { HILOG_ERROR("Ability state is %{public}d, it can't complete background.", abilityRecord->GetAbilityState()); return; diff --git a/services/abilitymgr/src/ability_interceptor.cpp b/services/abilitymgr/src/ability_interceptor.cpp index 3b35bc8b75..e6053f8ea7 100644 --- a/services/abilitymgr/src/ability_interceptor.cpp +++ b/services/abilitymgr/src/ability_interceptor.cpp @@ -323,15 +323,22 @@ bool DisposedRuleInterceptor::CheckDisposedRule(const Want &want, AppExecFwk::Di ErrCode EcologicalRuleInterceptor::DoProcess(const Want &want, int requestCode, int32_t userId, bool isForeground, const sptr &callerToken) { - std::string supportErms = OHOS::system::GetParameter(ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE, "false"); - if (supportErms == "false") { - HILOG_ERROR("Abilityms not support Erms."); + if (want.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME) == + want.GetElement().GetBundleName()) { + HILOG_DEBUG("The same bundle, do not intercept."); return ERR_OK; } ErmsCallerInfo callerInfo; ExperienceRule rule; #ifdef SUPPORT_ERMS GetEcologicalCallerInfo(want, callerInfo, userId); + std::string supportErms = OHOS::system::GetParameter(ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE, "false"); + if (supportErms == "false" && callerInfo.targetAppType != TYPE_HARMONY_SERVICE && + callerInfo.callerAppType != TYPE_HARMONY_SERVICE) { + HILOG_ERROR("Abilityms not support Erms between applications."); + return ERR_OK; + } + int ret = IN_PROCESS_CALL(EcologicalRuleMgrServiceClient::GetInstance()->QueryStartExperience(want, callerInfo, rule)); if (ret != ERR_OK) { diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index fae810aa44..60c431172d 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -27,7 +27,7 @@ #include "iservice_registry.h" #include "scene_board_judgement.h" #include "session_info.h" -#include "session_manager.h" +#include "session_manager_lite.h" #include "string_ex.h" #include "system_ability_definition.h" #include "ws_common.h" @@ -42,7 +42,7 @@ static std::unordered_map SCB_TO_MISSION_ERROR_CODE_MAP }; } -using OHOS::Rosen::SessionManager; +using OHOS::Rosen::SessionManagerLite; std::shared_ptr AbilityManagerClient::instance_ = nullptr; std::recursive_mutex AbilityManagerClient::mutex_; #ifdef WITH_DLP @@ -323,7 +323,7 @@ ErrCode AbilityManagerClient::MoveAbilityToBackground(sptr token) ErrCode AbilityManagerClient::CloseAbility(sptr token, int resultCode, const Want *resultWant) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_DEBUG("call"); sptr info = new AAFwk::SessionInfo(); @@ -629,7 +629,7 @@ ErrCode AbilityManagerClient::NotifyContinuationResult(int32_t missionId, int32_ ErrCode AbilityManagerClient::LockMissionForCleanup(int32_t missionId) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->LockSession(missionId); @@ -646,7 +646,7 @@ ErrCode AbilityManagerClient::LockMissionForCleanup(int32_t missionId) ErrCode AbilityManagerClient::UnlockMissionForCleanup(int32_t missionId) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->UnlockSession(missionId); @@ -670,7 +670,7 @@ void AbilityManagerClient::SetLockedState(int32_t sessionId, bool lockedState) ErrCode AbilityManagerClient::RegisterMissionListener(sptr listener) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->RegisterSessionListener(listener); @@ -687,7 +687,7 @@ ErrCode AbilityManagerClient::RegisterMissionListener(sptr lis ErrCode AbilityManagerClient::UnRegisterMissionListener(sptr listener) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->UnRegisterSessionListener(listener); @@ -737,7 +737,7 @@ ErrCode AbilityManagerClient::GetMissionInfos(const std::string& deviceId, int32 std::vector &missionInfos) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->GetSessionInfos(deviceId, numMax, missionInfos); @@ -755,7 +755,7 @@ ErrCode AbilityManagerClient::GetMissionInfo(const std::string& deviceId, int32_ MissionInfo &missionInfo) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->GetSessionInfo(deviceId, missionId, missionInfo); @@ -772,7 +772,7 @@ ErrCode AbilityManagerClient::GetMissionInfo(const std::string& deviceId, int32_ ErrCode AbilityManagerClient::CleanMission(int32_t missionId) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->ClearSession(missionId); @@ -789,7 +789,7 @@ ErrCode AbilityManagerClient::CleanMission(int32_t missionId) ErrCode AbilityManagerClient::CleanAllMissions() { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->ClearAllSessions(); @@ -821,7 +821,7 @@ ErrCode AbilityManagerClient::MoveMissionsToForeground(const std::vectorMoveSessionsToForeground(missionIds, topMissionId); @@ -852,7 +852,7 @@ ErrCode AbilityManagerClient::MoveMissionsToBackground(const std::vectorMoveSessionsToBackground(missionIds, result); @@ -1013,7 +1013,7 @@ ErrCode AbilityManagerClient::GetMissionSnapshot(const std::string& deviceId, in MissionSnapshot& snapshot, bool isLowResolution) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->GetSessionSnapshot(deviceId, missionId, snapshot, isLowResolution); @@ -1046,7 +1046,7 @@ ErrCode AbilityManagerClient::GetTopAbility(sptr &token) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_DEBUG("call"); auto err = sceneSessionManager->GetFocusSessionToken(token); @@ -1079,7 +1079,7 @@ ErrCode AbilityManagerClient::CheckUIExtensionIsFocused(uint32_t uiExtensionToke ErrCode AbilityManagerClient::DelegatorDoAbilityForeground(sptr token) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_DEBUG("call"); sceneSessionManager->PendingSessionToForeground(token); @@ -1092,7 +1092,7 @@ ErrCode AbilityManagerClient::DelegatorDoAbilityForeground(sptr t ErrCode AbilityManagerClient::DelegatorDoAbilityBackground(sptr token) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_DEBUG("call"); sceneSessionManager->PendingSessionToBackgroundForDelegator(token); @@ -1106,7 +1106,7 @@ ErrCode AbilityManagerClient::SetMissionContinueState(sptr token, const AAFwk::ContinueState &state) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_DEBUG("call"); uint32_t value = static_cast(state); @@ -1123,7 +1123,7 @@ ErrCode AbilityManagerClient::SetMissionContinueState(sptr token, ErrCode AbilityManagerClient::SetMissionLabel(sptr token, const std::string& label) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->SetSessionLabel(token, label); @@ -1141,7 +1141,7 @@ ErrCode AbilityManagerClient::SetMissionIcon( sptr abilityToken, std::shared_ptr icon) { if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); HILOG_INFO("call"); auto err = sceneSessionManager->SetSessionIcon(abilityToken, icon); @@ -1378,7 +1378,7 @@ int32_t AbilityManagerClient::IsValidMissionIds( { HILOG_INFO("call"); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto sceneSessionManager = SessionManager::GetInstance().GetSceneSessionManagerProxy(); + auto sceneSessionManager = SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); CHECK_POINTER_RETURN_INVALID_VALUE(sceneSessionManager); std::vector isValidList; auto err = sceneSessionManager->IsValidSessionIds(missionIds, isValidList); @@ -1688,5 +1688,13 @@ int32_t AbilityManagerClient::OpenFile(const Uri& uri, uint32_t flag) } return abms->OpenFile(uri, flag); } + +void AbilityManagerClient::UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) +{ + HILOG_DEBUG("Called."); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN(abms); + abms->UpdateSessionInfoBySCB(sessionInfos, userId); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 0574c44b41..2c69bcb09c 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -307,8 +307,7 @@ int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &star return reply.ReadInt32(); } -int AbilityManagerProxy::StartAbilityAsCaller( - const Want &want, const sptr &callerToken, +int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const sptr &callerToken, sptr asCallerSourceToken, int32_t userId, int requestCode, bool isSendDialogResult) { int error; @@ -4782,6 +4781,42 @@ int32_t AbilityManagerProxy::OpenFile(const Uri& uri, uint32_t flag) return reply.ReadFileDescriptor(); } +void AbilityManagerProxy::UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("Write interface token failed."); + return; + } + auto size = static_cast(sessionInfos.size()); + int32_t threshold = 512; + if (size > threshold) { + HILOG_ERROR("Size of vector too large."); + return; + } + if (!data.WriteInt32(size)) { + HILOG_ERROR("Write size failed."); + return; + } + for (int32_t i = 0; i < size; i++) { + if (!data.WriteParcelable(&sessionInfos[i])) { + HILOG_ERROR("Write sessionInfo failed."); + return; + } + } + if (!data.WriteInt32(userId)) { + HILOG_ERROR("Write userId failed."); + return; + } + + MessageParcel reply; + MessageOption option; + auto ret = SendRequest(AbilityManagerInterfaceCode::UPDATE_SESSION_INFO, data, reply, option); + if (ret != NO_ERROR) { + HILOG_ERROR("Send request failed with %{public}d", ret); + } +} + ErrCode AbilityManagerProxy::SendRequest(AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply, MessageOption& option) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9e2c856676..3bedcf1f3d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -61,7 +61,9 @@ #include "mission_info.h" #include "mission_info_mgr.h" #include "mock_session_manager_service.h" +#include "modal_system_ui_extension.h" #include "os_account_manager_wrapper.h" +#include "modal_system_ui_extension.h" #include "parameters.h" #include "permission_constants.h" #include "recovery_param.h" @@ -228,6 +230,7 @@ const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; const std::string PERMISSIONMGR_BUNDLE_NAME = "com.ohos.permissionmanager"; const std::string PERMISSIONMGR_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; const std::string IS_CALL_BY_SCB = "isCallBySCB"; +const std::string PROCESS_SUFFIX = "embeddable"; const int DEFAULT_DMS_MISSION_ID = -1; const std::map AbilityManagerService::dumpMap = { std::map::value_type("--all", KEY_DUMP_ALL), @@ -853,7 +856,8 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrResetCallingIdentityAsCaller(abilityRequest.want.GetIntParam( Want::PARAM_RESV_CALLER_TOKEN, 0)); @@ -913,7 +917,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr sessionInfo) if (sessionInfo->want.GetBoolParam(IS_CALL_BY_SCB, true)) { HILOG_DEBUG("afterCheckExecuter_ called."); - result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : - afterCheckExecuter_->DoProcess(abilityRequest.want, requestCode, GetUserId(), true, sessionInfo->callerToken); + result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess( + abilityRequest.want, requestCode, GetUserId(), true, sessionInfo->callerToken); if (result != ERR_OK) { HILOG_ERROR("afterCheckExecuter_ is nullptr or DoProcess return error."); return result; @@ -2106,6 +2110,7 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptrGetAbilityInfo().bundleName; - focusInfo.abilityName = Record->GetAbilityInfo().name; + focusInfo.bundleName = record->GetAbilityInfo().bundleName; + focusInfo.abilityName = record->GetAbilityInfo().name; // Gets the abilityName, bundleName, modulename corresponding to the caller appliaction EventInfo callerInfo; @@ -2139,11 +2144,12 @@ int AbilityManagerService::RequestModalUIExtensionInner(const Want &want) // Compare if (focusInfo.bundleName == callerInfo.bundleName) { HILOG_DEBUG("CreateModalUIExtension is called!"); - return Record->CreateModalUIExtension(want); + return record->CreateModalUIExtension(want); } HILOG_DEBUG("Window Modal System Create UIExtension is called!"); - return ERR_OK; + auto connection = std::make_shared(); + return connection->CreateModalUIExtension(want); } int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sptr &callerToken, @@ -2382,7 +2388,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte abilityRequest.Voluation(extensionSessionInfo->want, DEFAULT_INVAL_VALUE, callerToken); abilityRequest.callType = AbilityCallType::START_EXTENSION_TYPE; abilityRequest.sessionInfo = extensionSessionInfo; - result = GenerateExtensionAbilityRequest(extensionSessionInfo->want, abilityRequest, callerToken, validUserId); + result = GenerateEmbeddableUIAbilityRequest(extensionSessionInfo->want, abilityRequest, callerToken, validUserId); CHECK_POINTER_AND_RETURN(abilityRequest.sessionInfo, ERR_INVALID_VALUE); abilityRequest.sessionInfo->uiExtensionComponentId = ( static_cast(callerRecord->GetRecordId()) << OFFSET) | @@ -9401,14 +9407,18 @@ int AbilityManagerService::CreateModalDialog(const Want &replaceWant, sptr(replaceWant)).SetParam("dialogSessionId", dialogSessionId); if (callerRecord->GetAbilityInfo().type == AppExecFwk::AbilityType::PAGE && token == callerToken) { HILOG_DEBUG("create modal ui extension for application"); - (const_cast(replaceWant)).SetParam("dialogSessionId", dialogSessionId); return callerRecord->CreateModalUIExtension(replaceWant); } HILOG_DEBUG("create modal ui extension for system"); - // mock modal system by wms - return ERR_OK; + auto connection = std::make_shared(); + if (connection == nullptr) { + HILOG_ERROR("connect ModalSystemUiExtension failed"); + return INNER_ERR; + } + return connection->CreateModalUIExtension(replaceWant); } int AbilityManagerService::SendDialogResult(const Want &want, const std::string dialogSessionId, bool isAllowed) @@ -9426,6 +9436,7 @@ int AbilityManagerService::SendDialogResult(const Want &want, const std::string } auto targetWant = dialogCallerInfo->targetWant; targetWant.SetElement(want.GetElement()); + targetWant.SetParam("isSelector", dialogCallerInfo->isSelector); sptr callerToken = dialogCallerInfo->callerToken; return StartAbilityAsCaller(targetWant, callerToken, nullptr, dialogCallerInfo->userId, dialogCallerInfo->requestCode, true); @@ -9440,5 +9451,36 @@ void AbilityManagerService::RemoveLauncherDeathRecipient(int32_t userId) } connectManager->RemoveLauncherDeathRecipient(); } + +int32_t AbilityManagerService::GenerateEmbeddableUIAbilityRequest( + const Want &want, AbilityRequest &request, const sptr &callerToken, int32_t userId) +{ + int32_t screenMode = want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE); + int32_t result = ERR_OK; + if (screenMode == AAFwk::HALF_SCREEN_MODE) { + result = GenerateAbilityRequest(want, -1, request, callerToken, userId); + request.abilityInfo.isModuleJson = true; + request.abilityInfo.isStageBasedModel = true; + request.abilityInfo.type = AppExecFwk::AbilityType::EXTENSION; + request.abilityInfo.extensionAbilityType = AppExecFwk::ExtensionAbilityType::UI; + struct timespec time = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time); + int64_t times = static_cast(time.tv_sec); + request.abilityInfo.process = request.abilityInfo.bundleName + PROCESS_SUFFIX + std::to_string(times); + } else { + result = GenerateExtensionAbilityRequest(want, request, callerToken, userId); + } + return result; +} + +void AbilityManagerService::UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) +{ + if (!CheckCallingTokenId(BUNDLE_NAME_SCENEBOARD)) { + HILOG_ERROR("Not sceneboard called, not allowed."); + return; + } + HILOG_INFO("The sceneboard is being restored."); + uiAbilityLifecycleManager_->UpdateSessionInfoBySCB(sessionInfos, userId); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 8b0db06fcd..8107c6e39d 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -371,6 +371,8 @@ void AbilityManagerStub::ThirdStepInit() &AbilityManagerStub::NotifySaveAsResultInner; requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE)] = &AbilityManagerStub::SetSessionManagerServiceInner; + requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UPDATE_SESSION_INFO)] = + &AbilityManagerStub::UpdateSessionInfoBySCBInner; } void AbilityManagerStub::FourthStepInit() @@ -3032,5 +3034,27 @@ int32_t AbilityManagerStub::GetForegroundUIAbilitiesInner(MessageParcel &data, M } return result; } + +int32_t AbilityManagerStub::UpdateSessionInfoBySCBInner(MessageParcel &data, MessageParcel &reply) +{ + auto size = data.ReadInt32(); + int32_t threshold = 512; + if (size > threshold) { + HILOG_ERROR("Size of vector too large."); + return ERR_ENOUGH_DATA; + } + std::vector sessionInfos; + for (auto i = 0; i < size; i++) { + std::unique_ptr info(data.ReadParcelable()); + if (info == nullptr) { + HILOG_ERROR("Read session info failed."); + return INNER_ERR; + } + sessionInfos.emplace_back(*info); + } + int32_t userId = data.ReadInt32(); + UpdateSessionInfoBySCB(sessionInfos, userId); + return ERR_OK; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 784fd12ba0..afc6a4bf1e 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -420,7 +420,7 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag) // earlier than above actions SetAbilityStateInner(AbilityState::FOREGROUNDING); lifeCycleStateInfo_.sceneFlag = sceneFlag; - lifecycleDeal_->ForegroundNew(GetWant(), lifeCycleStateInfo_, sessionInfo_); + lifecycleDeal_->ForegroundNew(GetWant(), lifeCycleStateInfo_, GetSessionInfo()); lifeCycleStateInfo_.sceneFlag = 0; lifeCycleStateInfo_.sceneFlagBak = 0; { @@ -438,7 +438,7 @@ void AbilityRecord::ForegroundAbility(uint32_t sceneFlag) } } -void AbilityRecord::ForegroundAbility(const Closure &task, uint32_t sceneFlag) +void AbilityRecord::ForegroundAbility(const Closure &task, sptr sessionInfo, uint32_t sceneFlag) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("name:%{public}s.", abilityInfo_.name.c_str()); @@ -465,7 +465,7 @@ void AbilityRecord::ForegroundAbility(const Closure &task, uint32_t sceneFlag) // earlier than above actions. SetAbilityStateInner(AbilityState::FOREGROUNDING); lifeCycleStateInfo_.sceneFlag = sceneFlag; - lifecycleDeal_->ForegroundNew(GetWant(), lifeCycleStateInfo_, sessionInfo_); + lifecycleDeal_->ForegroundNew(GetWant(), lifeCycleStateInfo_, GetSessionInfo()); lifeCycleStateInfo_.sceneFlag = 0; lifeCycleStateInfo_.sceneFlagBak = 0; { @@ -1194,7 +1194,7 @@ void AbilityRecord::BackgroundAbility(const Closure &task) // schedule background after updating AbilityState and sending timeout message to avoid ability async callback // earlier than above actions. SetAbilityStateInner(AbilityState::BACKGROUNDING); - lifecycleDeal_->BackgroundNew(GetWant(), lifeCycleStateInfo_, sessionInfo_); + lifecycleDeal_->BackgroundNew(GetWant(), lifeCycleStateInfo_, GetSessionInfo()); } bool AbilityRecord::PrepareTerminateAbility() @@ -1258,11 +1258,12 @@ void AbilityRecord::SetAbilityStateInner(AbilityState state) static_cast(state)); int ret = ERR_OK; if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - if (sessionInfo_ == nullptr) { - HILOG_ERROR("sessionInfo_ is nullptr"); + auto sessionInfo = GetSessionInfo(); + if (sessionInfo == nullptr) { + HILOG_ERROR("sessionInfo is nullptr"); return; } - int32_t persistentId = sessionInfo_->persistentId; + int32_t persistentId = sessionInfo->persistentId; switch (state) { case AbilityState::BACKGROUNDING: { ret = collaborator->NotifyMoveMissionToBackground(persistentId); @@ -1439,9 +1440,9 @@ bool AbilityRecord::IsCreateByConnect() const return isCreateByConnect_; } -void AbilityRecord::SetCreateByConnectMode() +void AbilityRecord::SetCreateByConnectMode(bool isCreatedByConnect) { - isCreateByConnect_ = true; + isCreateByConnect_ = isCreatedByConnect; } void AbilityRecord::Activate() @@ -1484,7 +1485,7 @@ void AbilityRecord::Inactivate() // schedule inactive after updating AbilityState and sending timeout message to avoid ability async callback // earlier than above actions. SetAbilityStateInner(AbilityState::INACTIVATING); - lifecycleDeal_->Inactivate(GetWant(), lifeCycleStateInfo_, sessionInfo_); + lifecycleDeal_->Inactivate(GetWant(), lifeCycleStateInfo_, GetSessionInfo()); } void AbilityRecord::Terminate(const Closure &task) @@ -2508,9 +2509,26 @@ void AbilityRecord::SetMission(const std::shared_ptr &mission) void AbilityRecord::SetSessionInfo(sptr sessionInfo) { + std::lock_guard guard(sessionLock_); sessionInfo_ = sessionInfo; } +sptr AbilityRecord::GetSessionInfo() const +{ + std::lock_guard guard(sessionLock_); + return sessionInfo_; +} + +void AbilityRecord::UpdateSessionInfo(sptr sessionToken) +{ + std::lock_guard guard(sessionLock_); + if (sessionInfo_ != nullptr) { + sessionInfo_->sessionToken = sessionToken; + CHECK_POINTER(lifecycleDeal_); + lifecycleDeal_->UpdateSessionToken(sessionToken); + } +} + void AbilityRecord::SetMinimizeReason(bool fromUser) { minimizeReason_ = fromUser; @@ -2824,9 +2842,9 @@ void AbilityRecord::GrantUriPermissionInner(Want &want, std::vector } else { fromTokenId = IPCSkeleton::GetCallingTokenID(); } - bool permission = - PermissionVerification::GetInstance()->VerifyCallingPermission(PERMISSION_PROXY_AUTHORIZATION_URI) || - PermissionVerification::GetInstance()->VerifyPermissionByTokenId(tokenId, PERMISSION_PROXY_AUTHORIZATION_URI); + auto permission = + AAFwk::UriPermissionManagerClient::GetInstance().IsAuthorizationUriAllowed(IPCSkeleton::GetCallingTokenID()) || + AAFwk::UriPermissionManagerClient::GetInstance().IsAuthorizationUriAllowed(tokenId); auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_IS_NULLPTR(bundleMgrHelper); auto userId = GetCurrentAccountId(); @@ -3150,10 +3168,7 @@ void AbilityRecord::SetAttachDebug(const bool isAttachDebug) void AbilityRecord::AddAbilityWindowStateMap(uint64_t uiExtensionComponentId, AbilityWindowState abilityWindowState) { - if (abilityWindowState == AbilityWindowState::FOREGROUNDING || - abilityWindowStateMap_.find(uiExtensionComponentId) != abilityWindowStateMap_.end()) { - abilityWindowStateMap_[uiExtensionComponentId] = abilityWindowState; - } + abilityWindowStateMap_[uiExtensionComponentId] = abilityWindowState; } void AbilityRecord::RemoveAbilityWindowStateMap(uint64_t uiExtensionComponentId) diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 6356cf99fd..2aa4fc671f 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -1130,6 +1130,24 @@ int32_t AbilitySchedulerProxy::CreateModalUIExtension(const Want &want) return reply.ReadInt32(); } +void AbilitySchedulerProxy::UpdateSessionToken(sptr sessionToken) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteRemoteObject(sessionToken)) { + HILOG_ERROR("Write sessionToken failed."); + return; + } + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + int32_t err = SendTransactCmd(IAbilityScheduler::UPDATE_SESSION_TOKEN, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("Fail to SendRequest. err: %{public}d", err); + } +} + #ifdef ABILITY_COMMAND_FOR_TEST int AbilitySchedulerProxy::BlockAbility() { diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index 08a906f055..3dcd5429a7 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -66,6 +66,7 @@ AbilitySchedulerStub::AbilitySchedulerStub() requestFuncMap_[SCHEDULE_SHARE_DATA] = &AbilitySchedulerStub::ShareDataInner; requestFuncMap_[SCHEDULE_ONEXECUTE_INTENT] = &AbilitySchedulerStub::OnExecuteIntentInner; requestFuncMap_[CREATE_MODAL_UI_EXTENSION] = &AbilitySchedulerStub::CreateModalUIExtensionInner; + requestFuncMap_[UPDATE_SESSION_TOKEN] = &AbilitySchedulerStub::UpdateSessionTokenInner; #ifdef ABILITY_COMMAND_FOR_TEST requestFuncMap_[BLOCK_ABILITY_INNER] = &AbilitySchedulerStub::BlockAbilityInner; @@ -670,6 +671,13 @@ int AbilitySchedulerStub::CreateModalUIExtensionInner(MessageParcel &data, Messa return NO_ERROR; } +int AbilitySchedulerStub::UpdateSessionTokenInner(MessageParcel &data, MessageParcel &reply) +{ + sptr sessionToken = data.ReadRemoteObject(); + UpdateSessionToken(sessionToken); + return NO_ERROR; +} + #ifdef ABILITY_COMMAND_FOR_TEST int AbilitySchedulerStub::BlockAbilityInner(MessageParcel &data, MessageParcel &reply) { diff --git a/services/abilitymgr/src/ams_configuration_parameter.cpp b/services/abilitymgr/src/ams_configuration_parameter.cpp index d918b6bfcb..8fb1757a3d 100644 --- a/services/abilitymgr/src/ams_configuration_parameter.cpp +++ b/services/abilitymgr/src/ams_configuration_parameter.cpp @@ -22,7 +22,7 @@ namespace AAFwk { namespace { const int LOAD_CONFIGURATION_FAILED = -1; const int LOAD_CONFIGURATION_SUCCESS = 0; -const int32_t TIME_OUT_UNIT_TIME_RATIO = 1000; +const int32_t TIME_OUT_UNIT_TIME_RATIO = 10; } AmsConfigurationParameter::AmsConfigurationParameter() diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 2323270949..aafcee79e0 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -541,5 +541,12 @@ bool AppScheduler::IsAttachDebug(const std::string &bundleName) } return ERR_OK; } + +void AppScheduler::ClearProcessByToken(sptr token) const +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + CHECK_POINTER(appMgrClient_); + appMgrClient_->ClearProcessByToken(token); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/dialog_session_record.cpp b/services/abilitymgr/src/dialog_session_record.cpp index ceada41556..d98ec4c08f 100644 --- a/services/abilitymgr/src/dialog_session_record.cpp +++ b/services/abilitymgr/src/dialog_session_record.cpp @@ -147,11 +147,12 @@ bool DialogSessionRecord::GenerateDialogSessionRecord(AbilityRequest &abilityReq } dialogSessionInfo->targetAbilityInfos.emplace_back(targetDialogAbilityInfo); } + std::shared_ptr dialogCallerInfo = std::make_shared(); if (dialogAppInfos.size() > 1 || dialogAppInfos.size() == 0) { dialogSessionInfo->parameters.SetParam("action", AAFwk::String::Box(abilityRequest.want.GetAction())); dialogSessionInfo->parameters.SetParam("wantType", AAFwk::String::Box(abilityRequest.want.GetType())); + dialogCallerInfo->isSelector = true; } - std::shared_ptr dialogCallerInfo = std::make_shared(); dialogCallerInfo->callerToken = callerToken; dialogCallerInfo->requestCode = abilityRequest.requestCode; dialogCallerInfo->targetWant = abilityRequest.want; diff --git a/services/abilitymgr/src/extension_record_manager.cpp b/services/abilitymgr/src/extension_record_manager.cpp index 867bfcefec..3769fa4065 100644 --- a/services/abilitymgr/src/extension_record_manager.cpp +++ b/services/abilitymgr/src/extension_record_manager.cpp @@ -129,7 +129,7 @@ std::shared_ptr ExtensionRecordManager::GetAbilityRecordBy { CHECK_POINTER_AND_RETURN(sessionInfo, nullptr); std::lock_guard lock(mutex_); - for (auto it : extensionRecords_) { + for (const auto& it : extensionRecords_) { if (it.second == nullptr) { continue; } @@ -142,6 +142,7 @@ std::shared_ptr ExtensionRecordManager::GetAbilityRecordBy continue; } if (recordSessionInfo->uiExtensionComponentId == sessionInfo->uiExtensionComponentId) { + HILOG_DEBUG("found record, uiExtensionComponentId: %{public}" PRIu64, sessionInfo->uiExtensionComponentId); return abilityRecord; } } @@ -176,6 +177,7 @@ int32_t ExtensionRecordManager::GetOrCreateExtensionRecordInner(const AAFwk::Abi if (AAFwk::UIExtensionUtils::IsUIExtension(abilityRequest.abilityInfo.extensionAbilityType)) { int32_t extensionRecordId = UIExtensionRecord::NeedReuse(abilityRequest); if (extensionRecordId != INVALID_EXTENSION_RECORD_ID) { + HILOG_DEBUG("reuse record, id: %{public}d", extensionRecordId); int32_t ret = GetExtensionRecord(extensionRecordId, hostBundleName, extensionRecord, isLoaded); if (ret == ERR_OK) { extensionRecord->Update(abilityRequest); @@ -194,8 +196,8 @@ int32_t ExtensionRecordManager::GetOrCreateExtensionRecordInner(const AAFwk::Abi return ret; } UpdateProcessName(abilityRequest, abilityRecord); - HILOG_DEBUG("extensionProcessMode:%{public}d, process: %{public}s", abilityRequest.extensionProcessMode, - abilityRecord->GetAbilityInfo().process.c_str()); + HILOG_DEBUG("extensionRecordId: %{public}d, extensionProcessMode:%{public}d, process: %{public}s", + extensionRecordId, abilityRequest.extensionProcessMode, abilityRecord->GetAbilityInfo().process.c_str()); isLoaded = false; return ERR_OK; } diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 605006a096..e311c0c638 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -115,6 +115,9 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ AAFwk::Want want; auto abilityMgr = DelayedSingleton::GetInstance(); + int32_t tokenId = request.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, + static_cast(IPCSkeleton::GetCallingTokenID())); + AddIdentity(tokenId, identity); if (dialogAppInfos.size() == 0 && (deviceType == STR_PHONE || deviceType == STR_DEFAULT)) { if ((request.want.GetFlags() & Want::FLAG_START_WITHOUT_TIPS) == Want::FLAG_START_WITHOUT_TIPS) { HILOG_INFO("hint dialog doesn't generate."); @@ -177,9 +180,6 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ ret = abilityMgr->StartAbilityAsCaller(want, request.callerToken, nullptr); // reset calling indentity IPCSkeleton::SetCallingIdentity(identity); - int32_t tokenId = request.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, - static_cast(IPCSkeleton::GetCallingTokenID())); - AddIdentity(tokenId, identity); return ret; } diff --git a/services/abilitymgr/src/lifecycle_deal.cpp b/services/abilitymgr/src/lifecycle_deal.cpp index 10e1d57001..8bf008b63b 100644 --- a/services/abilitymgr/src/lifecycle_deal.cpp +++ b/services/abilitymgr/src/lifecycle_deal.cpp @@ -186,5 +186,12 @@ bool LifecycleDeal::PrepareTerminateAbility() } return abilityScheduler->SchedulePrepareTerminateAbility(); } + +void LifecycleDeal::UpdateSessionToken(sptr sessionToken) +{ + auto abilityScheduler = GetScheduler(); + CHECK_POINTER(abilityScheduler); + abilityScheduler->UpdateSessionToken(sessionToken); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index cb0177d1cb..b2b6cdfb69 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1968,5 +1968,36 @@ void UIAbilityLifecycleManager::SetDevice(std::string deviceType) { isPcDevice_ = (deviceType == "pc" || deviceType == "2in1"); } + +void UIAbilityLifecycleManager::UpdateSessionInfoBySCB(const std::vector &sessionInfos, int32_t userId) +{ + auto SearchFunc = [] (const std::vector &sessionInfos, int32_t sessionId) -> sptr { + for (const auto& info : sessionInfos) { + if (info.persistentId == sessionId) { + return info.sessionToken; + } + } + return nullptr; + }; + std::unordered_set> abilitySet; + { + std::lock_guard guard(sessionLock_); + for (auto [sessionId, abilityRecord] : sessionAbilityMap_) { + if (abilityRecord->GetOwnerMissionUserId() != userId) { + continue; + } + auto searchRet = SearchFunc(sessionInfos, sessionId); + if (searchRet != nullptr) { + abilityRecord->UpdateSessionInfo(searchRet); + } else { + abilitySet.emplace(abilityRecord); + } + } + } + for (auto ability : abilitySet) { + CloseUIAbility(ability, -1, nullptr, false); + } + HILOG_INFO("The end of updating session info."); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 6fdfa1bf39..0ba9ef4a2d 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -113,7 +113,6 @@ ohos_shared_library("libappms") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwsutils", ] if (product_name != "ohcore") { @@ -126,6 +125,7 @@ ohos_shared_library("libappms") { external_deps += [ "i18n:intl_util", "window_manager:libwm", + "window_manager:libwsutils", ] } diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 477dfae5c9..379bd9d058 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -231,6 +231,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 token) override; + private: /** * @brief Judge whether the application service is ready. diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 0cfdf4b907..763cc3d697 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -73,9 +73,11 @@ public: * ScheduleTerminate, call ScheduleTerminateApplication() through proxy project, * Notify application to terminate. * + * @param isLastProcess When it is the last application process, pass in true. + * * @return */ - void ScheduleTerminate(); + void ScheduleTerminate(bool isLastProcess = false); /** * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project, @@ -123,7 +125,7 @@ public: * @return */ void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo); - + /** * LowMemoryWarning, call ScheduleLowMemory() through proxy project, * Notify application to low memory. @@ -197,7 +199,15 @@ public: int32_t AttachAppDebug(); int32_t DetachAppDebug(); + /** + * Whether the current application process is the last surviving process. + * + * @return Returns true is final application process, others return false. + */ + bool IsFinalAppProcess(); + private: + mutable std::mutex schedulerMutex_; sptr appThread_ = nullptr; }; } // namespace AppExecFwk diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 5d0066f2fc..b716128f5a 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -542,13 +542,20 @@ private: /** * 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. */ int32_t IsApplicationRunning(const std::string &bundleName, bool &isRunning) 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: std::shared_ptr appMgrServiceInner_; AppMgrServiceState appMgrServiceState_; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index f7944d9821..32333e1256 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -333,7 +333,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. @@ -905,6 +905,20 @@ public: */ void ExitChildProcessSafelyByChildPid(const pid_t pid); + /** + * Whether the current application process is the last surviving process. + * @param bundleName To query the bundle name of a process. + * @return Returns true is final application process, others return false. + */ + bool IsFinalAppProcessByBundleName(const std::string &bundleName); + + /** + * To clear the process by ability token. + * + * @param token the unique identification to the ability. + */ + void ClearProcessByToken(sptr token); + private: std::string FaultTypeToString(FaultDataType type); @@ -1114,6 +1128,8 @@ private: int VerifyProcessPermission() const; int VerifyProcessPermission(const std::string &bundleName) const; + + bool CheckCallerIsAppGallery(); void ApplicationTerminatedSendProcessEvent(const std::shared_ptr &appRecord); void ClearAppRunningDataForKeepAlive(const std::shared_ptr &appRecord); @@ -1236,6 +1252,7 @@ private: ffrt::mutex userTestLock_; ffrt::mutex appStateCallbacksLock_; ffrt::mutex renderUidSetLock_; + ffrt::mutex exceptionLock_; sptr startSpecifiedAbilityResponse_; ffrt::mutex configurationObserverLock_; std::vector> configurationObservers_; diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 782fe17d0c..275a29bc0a 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -237,6 +237,13 @@ public: std::shared_ptr GetAppRunningRecordByChildProcessPid(const pid_t pid); std::shared_ptr OnChildProcessRemoteDied(const wptr &remote); + /** + * @brief Obtain number of app through bundlename. + * @param bundleName The application bundle name. + * @return Returns the number of queries. + */ + int32_t GetAllAppRunningRecordCountByBundleName(const std::string &bundleName); + private: std::shared_ptr GetAbilityRunningRecord(const int64_t eventId); void AssignRunningProcessInfoByAppRecord( diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index ccb69db902..ef7aef79dd 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -40,6 +40,7 @@ const std::string TASK_ABILITY_BEHAVIOR_ANALYSIS = "AbilityBehaviorAnalysisTask" const std::string TASK_KILL_PROCESS_BY_ABILITY_TOKEN = "KillProcessByAbilityTokenTask"; const std::string TASK_KILL_PROCESSES_BY_USERID = "KillProcessesByUserIdTask"; const std::string TASK_KILL_APPLICATION = "KillApplicationTask"; +const std::string TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN = "ClearProcessByAbilityTokenTask"; }; // namespace AmsMgrScheduler::AmsMgrScheduler( @@ -433,5 +434,21 @@ bool AmsMgrScheduler::IsAttachDebug(const std::string &bundleName) } return amsMgrServiceInner_->IsAttachDebug(bundleName); } + +void AmsMgrScheduler::ClearProcessByToken(sptr token) +{ + if (!IsReady()) { + return; + } + + if (amsMgrServiceInner_->VerifyProcessPermission(token) != ERR_OK) { + HILOG_ERROR("%{public}s: Permission verification failed", __func__); + return; + } + + std::function clearProcessByTokenFunc = + std::bind(&AppMgrServiceInner::ClearProcessByToken, amsMgrServiceInner_, token); + amsHandler_->SubmitTask(clearProcessByTokenFunc, TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 752d624525..9db7d1e8ef 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -35,34 +35,38 @@ void AppLifeCycleDeal::LaunchApplication(const AppLaunchData &launchData, const { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); HILOG_INFO("LoadLifecycle: Launch application"); - if (appThread_) { - appThread_->ScheduleLaunchApplication(launchData, config); + auto appThread = GetApplicationClient(); + if (appThread) { + appThread->ScheduleLaunchApplication(launchData, config); } } void AppLifeCycleDeal::UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleUpdateApplicationInfoInstalled(appInfo); + appThread->ScheduleUpdateApplicationInfoInstalled(appInfo); } void AppLifeCycleDeal::AddAbilityStage(const HapModuleInfo &abilityStage) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleAbilityStage(abilityStage); + appThread->ScheduleAbilityStage(abilityStage); } void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr &ability) { - if (appThread_ && ability) { + auto appThread = GetApplicationClient(); + if (appThread && ability) { auto abilityInfo = ability->GetAbilityInfo(); if (abilityInfo == nullptr) { HILOG_WARN("LoadLifecycle: abilityInfo null."); @@ -75,140 +79,154 @@ void AppLifeCycleDeal::LaunchAbility(const std::shared_ptr FreezeUtil::GetInstance().AddLifecycleEvent(flow, entry); } HILOG_INFO("LoadLifecycle: Launch ability."); - appThread_->ScheduleLaunchAbility(*abilityInfo, ability->GetToken(), + appThread->ScheduleLaunchAbility(*abilityInfo, ability->GetToken(), ability->GetWant()); } else { HILOG_WARN("LoadLifecycle."); } } -void AppLifeCycleDeal::ScheduleTerminate() +void AppLifeCycleDeal::ScheduleTerminate(bool isLastProcess) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleTerminateApplication(); + appThread->ScheduleTerminateApplication(isLastProcess); } void AppLifeCycleDeal::ScheduleForegroundRunning() { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleForegroundApplication(); + appThread->ScheduleForegroundApplication(); } void AppLifeCycleDeal::ScheduleBackgroundRunning() { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleBackgroundApplication(); + appThread->ScheduleBackgroundApplication(); } void AppLifeCycleDeal::ScheduleTrimMemory(int32_t timeLevel) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleShrinkMemory(timeLevel); + appThread->ScheduleShrinkMemory(timeLevel); } void AppLifeCycleDeal::ScheduleMemoryLevel(int32_t Level) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleMemoryLevel(Level); + appThread->ScheduleMemoryLevel(Level); } void AppLifeCycleDeal::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleHeapMemory(pid, mallocInfo); + appThread->ScheduleHeapMemory(pid, mallocInfo); } void AppLifeCycleDeal::LowMemoryWarning() { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleLowMemory(); + appThread->ScheduleLowMemory(); } void AppLifeCycleDeal::ScheduleCleanAbility(const sptr &token) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleCleanAbility(token); + appThread->ScheduleCleanAbility(token); } void AppLifeCycleDeal::ScheduleProcessSecurityExit() { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleProcessSecurityExit(); + appThread->ScheduleProcessSecurityExit(); } void AppLifeCycleDeal::SetApplicationClient(const sptr &thread) { + std::lock_guard guard(schedulerMutex_); appThread_ = thread; } sptr AppLifeCycleDeal::GetApplicationClient() const { + std::lock_guard guard(schedulerMutex_); return appThread_; } void AppLifeCycleDeal::ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleAcceptWant(want, moduleName); + appThread->ScheduleAcceptWant(want, moduleName); } void AppLifeCycleDeal::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) { - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return; } - appThread_->ScheduleNewProcessRequest(want, moduleName); + appThread->ScheduleNewProcessRequest(want, moduleName); } int32_t AppLifeCycleDeal::UpdateConfiguration(const Configuration &config) { HILOG_DEBUG("call"); - if (!appThread_) { - HILOG_ERROR("appThread_ is nullptr"); + auto appThread = GetApplicationClient(); + if (!appThread) { + HILOG_ERROR("appThread is nullptr"); return ERR_INVALID_VALUE; } - appThread_->ScheduleConfigurationUpdated(config); + appThread->ScheduleConfigurationUpdated(config); return ERR_OK; } @@ -217,22 +235,24 @@ int32_t AppLifeCycleDeal::NotifyLoadRepairPatch(const std::string &bundleName, c { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("call"); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId); + return appThread->ScheduleNotifyLoadRepairPatch(bundleName, callback, recordId); } int32_t AppLifeCycleDeal::NotifyHotReloadPage(const sptr &callback, const int32_t recordId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("call"); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyHotReloadPage(callback, recordId); + return appThread->ScheduleNotifyHotReloadPage(callback, recordId); } int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName, @@ -240,52 +260,57 @@ int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName, { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId); + return appThread->ScheduleNotifyUnLoadRepairPatch(bundleName, callback, recordId); } int32_t AppLifeCycleDeal::NotifyAppFault(const FaultData &faultData) { HILOG_DEBUG("called."); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyAppFault(faultData); + return appThread->ScheduleNotifyAppFault(faultData); } int32_t AppLifeCycleDeal::ChangeAppGcState(int32_t state) { HILOG_DEBUG("called."); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleChangeAppGcState(state); + return appThread->ScheduleChangeAppGcState(state); } int32_t AppLifeCycleDeal::AttachAppDebug() { HILOG_DEBUG("Called."); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - appThread_->AttachAppDebug(); + appThread->AttachAppDebug(); return ERR_OK; } int32_t AppLifeCycleDeal::DetachAppDebug() { HILOG_DEBUG("Called."); - if (appThread_ == nullptr) { - HILOG_ERROR("appThread_ is nullptr."); + auto appThread = GetApplicationClient(); + if (appThread == nullptr) { + HILOG_ERROR("appThread is nullptr."); return ERR_INVALID_VALUE; } - appThread_->DetachAppDebug(); + appThread->DetachAppDebug(); return ERR_OK; } } // namespace AppExecFwk diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 6e2d01bf4f..cf5bed22a2 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1044,5 +1044,14 @@ void AppMgrService::ExitChildProcessSafely() .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE }); } + +bool AppMgrService::IsFinalAppProcess() +{ + if (!IsReady()) { + HILOG_ERROR("Not ready."); + return false; + } + return appMgrServiceInner_->IsFinalAppProcessByBundleName(""); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index a029b4a31e..8ee3cd08d5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -833,6 +833,10 @@ int32_t AppMgrServiceInner::KillApplication(const std::string &bundleName) return ERR_NO_INIT; } + if (CheckCallerIsAppGallery()) { + return KillApplicationByBundleName(bundleName); + } + auto result = VerifyProcessPermission(bundleName); if (result != ERR_OK) { HILOG_ERROR("Permission verification failed."); @@ -849,13 +853,15 @@ int32_t AppMgrServiceInner::KillApplicationByUid(const std::string &bundleName, return ERR_NO_INIT; } - auto result = VerifyProcessPermission(bundleName); - if (result != ERR_OK) { - HILOG_ERROR("Permission verification failed."); - return result; + int32_t result = ERR_OK; + if (!CheckCallerIsAppGallery()) { + result = VerifyProcessPermission(bundleName); + if (result != ERR_OK) { + HILOG_ERROR("Permission verification failed."); + return result; + } } - result = ERR_OK; int64_t startTime = SystemTimeMillisecond(); std::list pids; if (remoteClientManager_ == nullptr) { @@ -2382,8 +2388,13 @@ void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool is return; } - auto appRecord = appRunningManager_->OnRemoteDied(remote); - if (!appRecord) { + std::shared_ptr appRecord = nullptr; + { + std::lock_guard lock(exceptionLock_); + appRecord = appRunningManager_->OnRemoteDied(remote); + } + if (appRecord == nullptr) { + HILOG_INFO("app record is not exist."); return; } @@ -3631,6 +3642,40 @@ int AppMgrServiceInner::VerifyProcessPermission(const sptr &token return ERR_OK; } +bool AppMgrServiceInner::CheckCallerIsAppGallery() +{ + HILOG_DEBUG("called"); + if (!appRunningManager_) { + HILOG_ERROR("appRunningManager_ is nullptr"); + return false; + } + auto callerPid = IPCSkeleton::GetCallingPid(); + auto appRecord = appRunningManager_->GetAppRunningRecordByPid(callerPid); + if (!appRecord) { + HILOG_ERROR("Get app running record by calling pid failed. callingPId: %{public}d", callerPid); + return false; + } + auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + if (!bundleMgrHelper) { + HILOG_ERROR("The bundleMgrHelper is nullptr."); + return false; + } + auto callerBundleName = appRecord->GetBundleName(); + if (callerBundleName.empty()) { + HILOG_ERROR("callerBundleName is empty."); + return false; + } + std::string appGalleryBundleName; + if (!bundleMgrHelper->QueryAppGalleryBundleName(appGalleryBundleName)) { + HILOG_ERROR("QueryAppGalleryBundleName failed."); + return false; + } + HILOG_DEBUG("callerBundleName:%{public}s, appGalleryBundleName:%{public}s", callerBundleName.c_str(), + appGalleryBundleName.c_str()); + + return callerBundleName == appGalleryBundleName; +} + bool AppMgrServiceInner::VerifyAPL() const { if (!appRunningManager_) { @@ -4979,7 +5024,7 @@ int32_t AppMgrServiceInner::StartChildProcess(const pid_t hostPid, const std::st int32_t AppMgrServiceInner::StartChildProcessPreCheck(const pid_t callingPid) { - if (!AAFwk::AppUtils::GetInstance().JudgeMultiProcessModelDevice()) { + if (!AAFwk::AppUtils::GetInstance().JudgePCDevice()) { HILOG_ERROR("Multi process model is not enabled"); return ERR_INVALID_OPERATION; } @@ -5215,6 +5260,29 @@ void AppMgrServiceInner::SendAppLaunchEvent(const std::shared_ptrGetAppRunningRecordByPid(callingPid); + if (appRecord == nullptr) { + HILOG_ERROR("Get app running record is nullptr."); + return false; + } + name = appRecord->GetBundleName(); + } + + auto count = appRunningManager_->GetAllAppRunningRecordCountByBundleName(name); + HILOG_DEBUG("Get application %{public}s process list size[%{public}d].", name.c_str(), count); + return count == 1; +} + void AppMgrServiceInner::ParseServiceExtMultiProcessWhiteList() { auto serviceExtMultiProcessWhiteList = @@ -5225,5 +5293,36 @@ void AppMgrServiceInner::ParseServiceExtMultiProcessWhiteList() } SplitStr(serviceExtMultiProcessWhiteList, ";", serviceExtensionWhiteList_); } + +void AppMgrServiceInner::ClearProcessByToken(sptr token) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (token == nullptr) { + HILOG_ERROR("token is null"); + return; + } + + std::shared_ptr appRecord = nullptr; + { + std::lock_guard lock(exceptionLock_); + appRecord = GetAppRunningRecordByAbilityToken(token); + if (appRecord == nullptr) { + HILOG_INFO("app record is not exist for ability token"); + return; + } + appRecord->SetApplicationClient(nullptr); + auto recordId = appRecord->GetRecordId(); + if (appRunningManager_ == nullptr) { + HILOG_ERROR("appRunningManager_ is nullptr"); + return; + } + appRunningManager_->RemoveAppRunningRecordById(recordId); + } + + ClearAppRunningData(appRecord, false); + if (!GetAppRunningStateByBundleName(appRecord->GetBundleName())) { + RemoveRunningSharedBundleList(appRecord->GetBundleName()); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index da5cea54c0..81e2d5c0e7 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -141,6 +141,20 @@ bool AppRunningManager::CheckAppRunningRecordIsExistByBundleName(const std::stri return false; } +int32_t AppRunningManager::GetAllAppRunningRecordCountByBundleName(const std::string &bundleName) +{ + int32_t count = 0; + std::lock_guard guard(lock_); + for (const auto &item : appRunningRecordMap_) { + const auto &appRecord = item.second; + if (appRecord && appRecord->GetBundleName() == bundleName) { + count++; + } + } + + return count; +} + std::shared_ptr AppRunningManager::GetAppRunningRecordByPid(const pid_t pid) { std::lock_guard guard(lock_); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index e62c800f97..faf3ea6ca4 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -567,7 +567,12 @@ void AppRunningRecord::ScheduleTerminate() HILOG_WARN("appLifeCycleDeal_ is null"); return; } - appLifeCycleDeal_->ScheduleTerminate(); + bool isLastProcess = false; + auto serviceInner = appMgrServiceInner_.lock(); + if (serviceInner != nullptr) { + isLastProcess = serviceInner->IsFinalAppProcessByBundleName(GetBundleName()); + } + appLifeCycleDeal_->ScheduleTerminate(isLastProcess); } void AppRunningRecord::LaunchPendingAbilities() diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index bb1168a675..bc7377f82f 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -35,6 +35,10 @@ AppSpawnClient::AppSpawnClient(bool isNWebSpawn) ErrCode AppSpawnClient::OpenConnection() { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (state_ == SpawnConnectionState::STATE_CONNECTED) { + return ERR_OK; + } + if (!socket_) { HILOG_ERROR("failed to open connection without socket!"); return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET; @@ -79,14 +83,11 @@ ErrCode AppSpawnClient::PreStartNWebSpawnProcessImpl() return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET; } - ErrCode result = ERR_OK; // openconnection failed, return fail - if (state_ != SpawnConnectionState::STATE_CONNECTED) { - result = OpenConnection(); - if (FAILED(result)) { - HILOG_ERROR("connect to nwebspawn failed!"); - return result; - } + ErrCode result = OpenConnection(); + if (FAILED(result)) { + HILOG_ERROR("connect to nwebspawn failed!"); + return result; } std::unique_ptr autoCloseConnection( @@ -98,6 +99,10 @@ ErrCode AppSpawnClient::PreStartNWebSpawnProcessImpl() ErrCode AppSpawnClient::StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pid) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (!socket_) { + HILOG_ERROR("failed to startProcess without socket!"); + return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET; + } int32_t retryCount = 1; ErrCode errCode = StartProcessImpl(startMsg, pid); while (FAILED(errCode) && retryCount <= CONNECT_RETRY_MAX_TIMES) { @@ -112,19 +117,11 @@ ErrCode AppSpawnClient::StartProcess(const AppSpawnStartMsg &startMsg, pid_t &pi ErrCode AppSpawnClient::StartProcessImpl(const AppSpawnStartMsg &startMsg, pid_t &pid) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - if (!socket_) { - HILOG_ERROR("failed to startProcess without socket!"); - return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET; - } - - ErrCode result = ERR_OK; + ErrCode result = OpenConnection(); // open connection failed, return fail - if (state_ != SpawnConnectionState::STATE_CONNECTED) { - result = OpenConnection(); - if (FAILED(result)) { - HILOG_ERROR("connect to appSpawn failed!"); - return result; - } + if (FAILED(result)) { + HILOG_ERROR("connect to appSpawn failed!"); + return result; } std::unique_ptr autoCloseConnection( this, [](AppSpawnClient *client) { client->CloseConnection(); }); @@ -206,14 +203,11 @@ ErrCode AppSpawnClient::GetRenderProcessTerminationStatus(const AppSpawnStartMsg return ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET; } - ErrCode result = ERR_OK; + ErrCode result = OpenConnection(); // open connection failed, return fail - if (state_ != SpawnConnectionState::STATE_CONNECTED) { - result = OpenConnection(); - if (FAILED(result)) { - HILOG_ERROR("connect to appSpawn failed!"); - return result; - } + if (FAILED(result)) { + HILOG_ERROR("connect to appSpawn failed!"); + return result; } std::unique_ptr autoCloseConnection( this, [](AppSpawnClient *client) { client->CloseConnection(); }); diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 74f961268f..1093ad7988 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -115,9 +115,12 @@ ohos_shared_library("app_util") { external_deps = [ "hilog:libhilog", "init:libbegetutil", - "window_manager:libwsutils", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwsutils" ] + } + subsystem_name = "ability" part_name = "ability_runtime" } diff --git a/services/common/include/app_utils.h b/services/common/include/app_utils.h index 949de34f06..10a266d64b 100644 --- a/services/common/include/app_utils.h +++ b/services/common/include/app_utils.h @@ -26,14 +26,14 @@ class AppUtils { public: static AppUtils &GetInstance(); bool IsLauncher(const std::string &bundleName) const; + bool IsLauncherAbility(const std::string &abilityName) const; bool JudgePCDevice() const; - bool JudgeMultiProcessModelDevice() const; private: AppUtils(); ~AppUtils(); volatile bool isSceneBoard_ = false; - volatile bool isMultiProcesModelDevice_ = false; + volatile bool isPcDevice_ = false; DISALLOW_COPY_AND_MOVE(AppUtils); }; } // namespace AAFwk diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index c38a5a639c..a27179ed47 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -39,6 +39,7 @@ constexpr const char* PERMISSION_PROXY_AUTHORIZATION_URI = "ohos.permission.PROX constexpr const char* PERMISSION_EXEMPT_AS_CALLER = "ohos.permission.EXEMPT_AS_CALLER"; constexpr const char* PERMISSION_EXEMPT_AS_TARGET = "ohos.permission.EXEMPT_AS_TARGET"; constexpr const char* PERMISSION_PREPARE_TERMINATE = "ohos.permission.PREPARE_APP_TERMINATE"; +constexpr const char* PERMISSION_MANAGE_APP_BOOT = "ohos.permission.MANAGE_APP_BOOT"; constexpr const char* PERMISSION_START_ABILITY_WITH_ANIMATION = "ohos.permission.START_ABILITY_WITH_ANIMATION"; constexpr const char* PERMISSION_MANAGE_APP_BOOT_INTERNAL = "ohos.permission.MANAGE_APP_BOOT_INTERNAL"; constexpr const char* PERMISSION_CONNECT_UI_EXTENSION_ABILITY = "ohos.permission.CONNECT_UI_EXTENSION_ABILITY"; diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index bf99d1822b..9d0bfc7c1b 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -21,12 +21,14 @@ namespace OHOS { namespace AAFwk { +namespace { const std::string BUNDLE_NAME_LAUNCHER = "com.ohos.launcher"; const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; -namespace { - const std::string DEVICE_2IN1 = "2in1"; - const std::string DEVICE_PC = "pc"; - const std::string DEVICE_TABLET = "tablet"; +const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; +const std::string SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; +const std::string DEVICE_2IN1 = "2in1"; +const std::string DEVICE_PC = "pc"; +const std::string DEVICE_TABLET = "tablet"; } AppUtils::~AppUtils() {} @@ -36,8 +38,8 @@ AppUtils::AppUtils() isSceneBoard_ = true; } auto deviceType = system::GetDeviceType(); - if (deviceType.compare(DEVICE_2IN1) != 0 || deviceType.compare(DEVICE_TABLET) != 0) { - isMultiProcesModelDevice_ = true; + if (deviceType == DEVICE_2IN1 || deviceType == DEVICE_PC || deviceType == DEVICE_TABLET) { + isPcDevice_ = true; } } @@ -56,18 +58,18 @@ bool AppUtils::IsLauncher(const std::string &bundleName) const return bundleName == BUNDLE_NAME_LAUNCHER; } -bool AppUtils::JudgePCDevice() const +bool AppUtils::IsLauncherAbility(const std::string &abilityName) const { - auto deviceType = system::GetDeviceType(); - if (deviceType.compare(DEVICE_2IN1) != 0 || deviceType.compare(DEVICE_PC) != 0) { - return true; + if (isSceneBoard_) { + return abilityName == SCENEBOARD_ABILITY_NAME; } - return false; + + return abilityName == LAUNCHER_ABILITY_NAME; } -bool AppUtils::JudgeMultiProcessModelDevice() const +bool AppUtils::JudgePCDevice() const { - return isMultiProcesModelDevice_; + return isPcDevice_; } } // namespace AAFwk } // namespace OHOS diff --git a/services/quickfixmgr/include/quick_fix_manager_service.h b/services/quickfixmgr/include/quick_fix_manager_service.h index 9d6898151c..b78c2c762c 100644 --- a/services/quickfixmgr/include/quick_fix_manager_service.h +++ b/services/quickfixmgr/include/quick_fix_manager_service.h @@ -81,6 +81,7 @@ public: private: bool CheckTaskRunningState(const std::string &bundleName); void AddApplyTask(std::shared_ptr applyTask); + int32_t GetQuickFixInfo(const std::string &bundleName, bool &patchExists, bool &isSoContained); static std::mutex mutex_; static sptr instance_; diff --git a/services/quickfixmgr/quick_fix.cfg b/services/quickfixmgr/quick_fix.cfg index 0a87385556..dd576a60f0 100644 --- a/services/quickfixmgr/quick_fix.cfg +++ b/services/quickfixmgr/quick_fix.cfg @@ -7,7 +7,10 @@ "gid" : ["system"], "secon" : "u:r:quick_fix:s0", "apl" : "system_basic", - "permission" : ["ohos.permission.RUNNING_STATE_OBSERVER"] + "permission" : [ + "ohos.permission.RUNNING_STATE_OBSERVER", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + ] } ] } diff --git a/services/quickfixmgr/src/quick_fix_manager_service.cpp b/services/quickfixmgr/src/quick_fix_manager_service.cpp index 13ffce1c42..7a7f0bb947 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service.cpp @@ -140,30 +140,11 @@ int32_t QuickFixManagerService::RevokeQuickFix(const std::string &bundleName) return QUICK_FIX_DEPLOYING_TASK; } - auto bundleMgrHelper = DelayedSingleton::GetInstance(); - if (bundleMgrHelper == nullptr) { - HILOG_ERROR("Failed to get bundle manager helper."); - return QUICK_FIX_CONNECT_FAILED; - } - - AppExecFwk::BundleInfo bundleInfo; - if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, - AppExecFwk::Constants::ANY_USERID)) { - HILOG_ERROR("Get bundle info failed."); - return QUICK_FIX_GET_BUNDLE_INFO_FAILED; - } - - auto isSoContained = !bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath.empty(); - auto patchExists = true; - for (auto &item : bundleInfo.hapModuleInfos) { - if (!item.hqfInfo.moduleName.empty()) { - patchExists = false; - break; - } - } - - if (patchExists) { - HILOG_ERROR("Patch does not exist."); + auto patchExists = false; + auto isSoContained = false; + auto ret = GetQuickFixInfo(bundleName, patchExists, isSoContained); + if (ret != QUICK_FIX_OK || !patchExists) { + HILOG_ERROR("Get bundle info failed or patch does not exist."); return QUICK_FIX_GET_BUNDLE_INFO_FAILED; } @@ -222,5 +203,31 @@ bool QuickFixManagerService::CheckTaskRunningState(const std::string &bundleName HILOG_DEBUG("bundleName %{public}s not found in tasks.", bundleName.c_str()); return false; } + +int32_t QuickFixManagerService::GetQuickFixInfo(const std::string &bundleName, bool &patchExists, bool &isSoContained) +{ + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + if (bundleMgrHelper == nullptr) { + HILOG_ERROR("Failed to get bundle manager helper."); + return QUICK_FIX_CONNECT_FAILED; + } + + AppExecFwk::BundleInfo bundleInfo; + if (!bundleMgrHelper->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, + AppExecFwk::Constants::ANY_USERID)) { + HILOG_ERROR("Get bundle info failed."); + return QUICK_FIX_GET_BUNDLE_INFO_FAILED; + } + + for (auto &item : bundleInfo.hapModuleInfos) { + if (!item.hqfInfo.moduleName.empty()) { + patchExists = true; + break; + } + } + + isSoContained = !bundleInfo.applicationInfo.appQuickFix.deployedAppqfInfo.nativeLibraryPath.empty(); + return QUICK_FIX_OK; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index 7b3cf766a9..dd4cb39983 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -28,6 +28,7 @@ config("upms_config") { } libupms_sources = [ + "src/proxy_authorization_uri_config.cpp", "src/rdb/ability_rdb_open_callback.cpp", "src/rdb/rdb_data_manager.cpp", "src/rdb/uri_permission_rdb.cpp", diff --git a/services/uripermmgr/include/proxy_authorization_uri_config.h b/services/uripermmgr/include/proxy_authorization_uri_config.h new file mode 100644 index 0000000000..179fb6fbda --- /dev/null +++ b/services/uripermmgr/include/proxy_authorization_uri_config.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_PROXY_AUTHORIZATION_URI_CONFIG_H +#define OHOS_ABILITY_RUNTIME_PROXY_AUTHORIZATION_URI_CONFIG_H + +#include +#include +#include + +#include "singleton.h" + +namespace OHOS { +namespace AAFwk { +class ProxyAuthorizationUriConfig : public DelayedSingleton { +public: + ProxyAuthorizationUriConfig() = default; + virtual ~ProxyAuthorizationUriConfig() = default; + void LoadConfiguration(); + bool IsAuthorizationUriAllowed(uint32_t fromTokenId); +private: + void LoadBundleNameAllowedList(const nlohmann::json &object); + bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); + + std::set bundleNameAllowedList_; +}; +} // OHOS +} // AAFwk + +#endif // OHOS_ABILITY_RUNTIME_PROXY_AUTHORIZATION_URI_CONFIG_H \ No newline at end of file diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 9371bd6d87..8a74d6492b 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -67,6 +67,7 @@ public: bool CheckPersistableUriPermissionProxy(const Uri &uri, uint32_t flag, uint32_t tokenId) override; bool VerifyUriPermission(const Uri &uri, uint32_t flag, uint32_t tokenId) override; + bool IsAuthorizationUriAllowed(uint32_t fromTokenId) override; uint32_t GetTokenIdByBundleName(const std::string bundleName, int32_t appIndex); diff --git a/services/uripermmgr/src/proxy_authorization_uri_config.cpp b/services/uripermmgr/src/proxy_authorization_uri_config.cpp new file mode 100644 index 0000000000..00ab300747 --- /dev/null +++ b/services/uripermmgr/src/proxy_authorization_uri_config.cpp @@ -0,0 +1,122 @@ +/* + * 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 "proxy_authorization_uri_config.h" +#include +#include +#include + +#include "accesstoken_kit.h" +#include "parameters.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +namespace { +const std::string CONFIG_PATH_DEFAULT = "/system/etc/proxy_authorization_uri.json"; +const std::string CONFIG_PATH_PREFIX = "/system/variant/"; +const std::string CONFIG_PATH = "/base/etc/proxy_authorization_uri.json"; + +const std::string PROXY_AUTHORIZATION_URI_NAME = "proxyAuthorizationUri"; +const std::string BUNDLE_NAME = "bundleName"; +} + +void ProxyAuthorizationUriConfig::LoadConfiguration() +{ + HILOG_DEBUG("call"); + nlohmann::json jsonBuf; + std::string configPath = CONFIG_PATH_PREFIX + OHOS::system::GetDeviceType() + CONFIG_PATH; + if (ReadFileInfoJson(configPath, jsonBuf)) { + LoadBundleNameAllowedList(jsonBuf); + return; + } + nlohmann::json jsonBufDefault; + if (ReadFileInfoJson(CONFIG_PATH_DEFAULT, jsonBufDefault)) { + LoadBundleNameAllowedList(jsonBufDefault); + } +} + +bool ProxyAuthorizationUriConfig::IsAuthorizationUriAllowed(uint32_t fromTokenId) +{ + Security::AccessToken::NativeTokenInfo nativeInfo; + auto result = Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(fromTokenId, nativeInfo); + if (result == Security::AccessToken::AccessTokenKitRet::RET_SUCCESS && + bundleNameAllowedList_.find(nativeInfo.processName) != bundleNameAllowedList_.end()) { + return true; + } + + Security::AccessToken::HapTokenInfo hapInfo; + result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(fromTokenId, hapInfo); + if (result == Security::AccessToken::AccessTokenKitRet::RET_SUCCESS && + bundleNameAllowedList_.find(hapInfo.bundleName) != bundleNameAllowedList_.end()) { + return true; + } + return false; +} + +void ProxyAuthorizationUriConfig::LoadBundleNameAllowedList(const nlohmann::json &object) +{ + if (!object.contains(PROXY_AUTHORIZATION_URI_NAME)) { + HILOG_ERROR("Proxy authorization uri config not existed."); + return; + } + + for (auto &item : object.at(PROXY_AUTHORIZATION_URI_NAME).items()) { + const nlohmann::json& jsonObject = item.value(); + if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + continue; + } + std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); + bundleNameAllowedList_.insert(bundleName); + } +} + +bool ProxyAuthorizationUriConfig::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +{ + if (access(filePath.c_str(), F_OK) != 0) { + HILOG_DEBUG("%{public}s, not existed", filePath.c_str()); + return false; + } + + std::fstream in; + char errBuf[256]; + errBuf[0] = '\0'; + in.open(filePath, std::ios_base::in); + if (!in.is_open()) { + strerror_r(errno, errBuf, sizeof(errBuf)); + HILOG_ERROR("the file cannot be open due to %{public}s", errBuf); + return false; + } + + in.seekg(0, std::ios::end); + int64_t size = in.tellg(); + if (size <= 0) { + HILOG_ERROR("the file is an empty file"); + in.close(); + return false; + } + + in.seekg(0, std::ios::beg); + jsonBuf = nlohmann::json::parse(in, nullptr, false); + in.close(); + if (jsonBuf.is_discarded()) { + HILOG_ERROR("bad profile file"); + return false; + } + + return true; +} +} +} \ No newline at end of file diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 346026bec9..4d3e25216f 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -29,6 +29,7 @@ #include "parameter.h" #include "permission_constants.h" #include "permission_verification.h" +#include "proxy_authorization_uri_config.h" #include "system_ability_definition.h" #include "tokenid_kit.h" #include "want.h" @@ -53,6 +54,7 @@ void UriPermissionManagerStubImpl::Init() HILOG_INFO("Init uri permission database manager."); uriPermissionRdb_ = std::make_shared(); } + DelayedSingleton::GetInstance()->LoadConfiguration(); } bool UriPermissionManagerStubImpl::CheckPersistableUriPermissionProxy(const Uri& uri, uint32_t flag, uint32_t tokenId) @@ -105,6 +107,11 @@ bool UriPermissionManagerStubImpl::VerifyUriPermission(const Uri &uri, uint32_t return false; } +bool UriPermissionManagerStubImpl::IsAuthorizationUriAllowed(uint32_t fromTokenId) +{ + return DelayedSingleton::GetInstance()->IsAuthorizationUriAllowed(fromTokenId); +} + int UriPermissionManagerStubImpl::GrantUriPermission(const Uri &uri, unsigned int flag, const std::string targetBundleName, int32_t appIndex) { @@ -236,8 +243,7 @@ int UriPermissionManagerStubImpl::GetUriPermissionFlag(const Uri &uri, unsigned auto callerTokenId = IPCSkeleton::GetCallingTokenID(); Uri uri_inner = uri; auto&& authority = uri_inner.GetAuthority(); - auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI); + auto permission = IsAuthorizationUriAllowed(callerTokenId); if ((flag & Want::FLAG_AUTH_WRITE_URI_PERMISSION) != 0) { newFlag |= Want::FLAG_AUTH_WRITE_URI_PERMISSION; } else { @@ -586,8 +592,7 @@ int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, co auto uriTokenId = GetTokenIdByBundleName(authority, 0); auto tokenId = GetTokenIdByBundleName(bundleName, 0); auto callerTokenId = IPCSkeleton::GetCallingTokenID(); - auto permission = PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_PROXY_AUTHORIZATION_URI); + auto permission = IsAuthorizationUriAllowed(callerTokenId); bool authorityFlag = authority == "media" || authority == "docs"; if (!authorityFlag && (uriTokenId != callerTokenId) && (tokenId != callerTokenId)) { diff --git a/test/fuzztest/appmanager_fuzzer/BUILD.gn b/test/fuzztest/appmanager_fuzzer/BUILD.gn index b5364e4e13..b808c07fab 100644 --- a/test/fuzztest/appmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/appmanager_fuzzer/BUILD.gn @@ -55,8 +55,11 @@ ohos_fuzztest("AppManagerFuzzTest") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } ############################################################################### diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h index 436333769c..9df28895f3 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_client.h @@ -154,6 +154,7 @@ public: { return 0; } + virtual void UpdateSessionToken(sptr sessionToken) {} }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h index e860dcf518..6e3d43786e 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_scheduler_for_observer.h @@ -82,6 +82,7 @@ public: { return 0; } + virtual void UpdateSessionToken(sptr sessionToken) override {} }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_service.h index 8bb474dc61..7f1c5f6b8e 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_service.h @@ -220,12 +220,14 @@ public: return ERR_OK; } - ErrCode RegisterClickEventObserver(const sptr &observer) override + ErrCode RegisterClickEventObserver( + const std::string &bundleName, const std::string &formEventType, const sptr &observer) override { return ERR_OK; } - ErrCode UnregisterClickEventObserver(const sptr &observer) override + ErrCode UnregisterClickEventObserver( + const std::string &bundleName, const std::string &formEventType, const sptr &observer) override { return ERR_OK; } diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index d2026de8b4..1b459550f5 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -119,6 +119,7 @@ public: MOCK_METHOD1(KillApplication, int(const std::string& appName)); MOCK_METHOD2(KillApplicationByUid, int(const std::string&, const int uid)); + MOCK_METHOD0(IsFinalAppProcess, bool()); virtual sptr GetAmsMgr() override { @@ -204,10 +205,10 @@ public: callback_->OnAbilityRequestDone(token, st); } - void ScheduleTerminateApplication() + void ScheduleTerminateApplication(bool isLastProcess = false) { if (Appthread_ != nullptr) { - Appthread_->ScheduleTerminateApplication(); + Appthread_->ScheduleTerminateApplication(isLastProcess); } } diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index 8897901a8c..d3ef1047f4 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -62,6 +62,14 @@ public: { return; } + void DestroyHeapProfiler() override + { + return; + } + void ForceFullGC() override + { + return; + } void NotifyApplicationState(bool isBackground) override { return; diff --git a/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h b/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h index c1f6656998..0db18869ac 100644 --- a/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h +++ b/test/mock/services_abilitymgr_test/libs/aakit/include/ability_scheduler.h @@ -114,6 +114,7 @@ public: { return 0; }; + virtual void UpdateSessionToken(sptr sessionToken) override {} #ifdef ABILITY_COMMAND_FOR_TEST virtual int BlockAbility() override { diff --git a/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h b/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h index 06c4cfe2a4..f2d89eb9e3 100644 --- a/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h +++ b/test/mock/services_abilitymgr_test/libs/ability_scheduler_mock/ability_scheduler_mock.h @@ -162,6 +162,8 @@ public: return 0; } + virtual void UpdateSessionToken(sptr sessionToken) override {} + #ifdef ABILITY_COMMAND_FOR_TEST virtual int BlockAbility() { diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 4890589b5d..b3fd3d6547 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -91,6 +91,7 @@ public: MOCK_METHOD1(AttachChildProcess, void(const sptr &childScheduler)); MOCK_METHOD0(ExitChildProcessSafely, void()); + MOCK_METHOD0(IsFinalAppProcess, bool()); virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) { diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index 62c5153eb7..4672a934bc 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -31,7 +31,7 @@ public: virtual ~MockAppScheduler() = default; MOCK_METHOD0(ScheduleForegroundApplication, void()); MOCK_METHOD0(ScheduleBackgroundApplication, void()); - MOCK_METHOD0(ScheduleTerminateApplication, void()); + MOCK_METHOD1(ScheduleTerminateApplication, void(bool)); MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config)); MOCK_METHOD3(ScheduleLaunchAbility, void(const AbilityInfo&, const sptr&, const std::shared_ptr&)); diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index 589d79e51d..744d144d30 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -26,7 +26,7 @@ class MockApplication : public AppSchedulerHost { public: MOCK_METHOD0(ScheduleForegroundApplication, void()); MOCK_METHOD0(ScheduleBackgroundApplication, void()); - MOCK_METHOD0(ScheduleTerminateApplication, void()); + MOCK_METHOD1(ScheduleTerminateApplication, void(bool)); MOCK_METHOD1(ScheduleShrinkMemory, void(const int)); MOCK_METHOD0(ScheduleLowMemory, void()); MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level)); diff --git a/test/moduletest/ability_delegator_test/BUILD.gn b/test/moduletest/ability_delegator_test/BUILD.gn index 59ae21c491..3f2a77e328 100644 --- a/test/moduletest/ability_delegator_test/BUILD.gn +++ b/test/moduletest/ability_delegator_test/BUILD.gn @@ -193,8 +193,11 @@ ohos_moduletest("ability_delegator_moduletest") { "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } ohos_moduletest("js_test_runner_moduletest") { diff --git a/test/moduletest/ability_manager_service_dump_test/BUILD.gn b/test/moduletest/ability_manager_service_dump_test/BUILD.gn index 943089332c..30b4154084 100644 --- a/test/moduletest/ability_manager_service_dump_test/BUILD.gn +++ b/test/moduletest/ability_manager_service_dump_test/BUILD.gn @@ -42,9 +42,12 @@ ohos_moduletest("ability_manager_service_dump_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index 95b1b1f2ab..349a0cdf2a 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -85,13 +85,15 @@ ohos_moduletest("ability_moduletest") { "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", - "window_manager:libwsutils", - "window_manager:scene_session", ] if (ability_runtime_graphics) { deps += [ "${multimedia_path}/interfaces/innerkits:image_native" ] - external_deps += [ "input:libmmi-client" ] + external_deps += [ + "input:libmmi-client", + "window_manager:libwsutils", + "window_manager:scene_session", + ] } if (ecologic_rule_enabled) { @@ -146,11 +148,13 @@ ohos_moduletest("ability_conetxt_test") { "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", - "window_manager:libwsutils", - "window_manager:scene_session", ] if (ability_runtime_graphics) { - external_deps += [ "input:libmmi-client" ] + external_deps += [ + "input:libmmi-client", + "window_manager:libwsutils", + "window_manager:scene_session", + ] } if (ecologic_rule_enabled) { @@ -231,13 +235,15 @@ ohos_moduletest("data_ability_operation_moduletest") { "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", - "window_manager:libwsutils", - "window_manager:scene_session", ] if (ability_runtime_graphics) { deps += [ "${multimedia_path}/interfaces/innerkits:image_native" ] - external_deps += [ "input:libmmi-client" ] + external_deps += [ + "input:libmmi-client", + "window_manager:libwsutils", + "window_manager:scene_session", + ] } if (ecologic_rule_enabled) { diff --git a/test/moduletest/ability_timeout_module_test/BUILD.gn b/test/moduletest/ability_timeout_module_test/BUILD.gn index 0aa20520f8..8d09bce8fd 100644 --- a/test/moduletest/ability_timeout_module_test/BUILD.gn +++ b/test/moduletest/ability_timeout_module_test/BUILD.gn @@ -68,15 +68,6 @@ ohos_moduletest("ability_timeout_module_test") { "//third_party/jsoncpp:jsoncpp", ] - if (ability_runtime_graphics) { - deps += [ - "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", - "${global_path}/i18n/frameworks/intl:intl_util", - "${multimedia_path}/interfaces/innerkits:image_native", - "//third_party/icu/icu4c:shared_icuuc", - ] - } - external_deps = [ "ability_base:configuration", "ability_base:view_data", @@ -105,6 +96,7 @@ ohos_moduletest("ability_timeout_module_test") { "relational_store:native_dataability", "relational_store:native_rdb", "safwk:system_ability_fwk", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwsutils", "window_manager:sms", ] @@ -125,9 +117,17 @@ ohos_moduletest("ability_timeout_module_test") { } if (ability_runtime_graphics) { + deps += [ + "${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr", + "${global_path}/i18n/frameworks/intl:intl_util", + "${multimedia_path}/interfaces/innerkits:image_native", + "//third_party/icu/icu4c:shared_icuuc", + ] external_deps += [ "input:libmmi-client", "window_manager:libdm", + "window_manager:libwsutils", + "window_manager:sms", ] } } diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index 4db1f233d4..cf4591a62a 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -42,12 +42,15 @@ ohos_moduletest("call_ability_service_module_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("moduletest") { diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 13dc002575..d1117e1371 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -78,9 +78,12 @@ ohos_source_set("appmgr_mst_source") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn index 88c0aa6512..cd492a4417 100644 --- a/test/moduletest/common/ams/ability_running_record_test/BUILD.gn +++ b/test/moduletest/common/ams/ability_running_record_test/BUILD.gn @@ -37,13 +37,18 @@ ohos_moduletest("AmsAbilityRunningRecordModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", - "window_manager:libwsutils", ] if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("moduletest") { diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 3fbe834420..ca5bed89b3 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -79,7 +79,7 @@ public: { scheduled_ |= BACKGROUND_SCHEDULED; } - void ScheduleTerminateApplication() override + void ScheduleTerminateApplication(bool isLastProcess = false) override { scheduled_ |= TERMINATE_SCHEDULED; } diff --git a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp index 6754262fc8..4b560f7810 100644 --- a/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp +++ b/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp @@ -266,7 +266,7 @@ void AmsAppLifeCycleModuleTest::ChangeAppToTerminate(const sptrAbilityTerminated(token); EXPECT_NE(appRunningRecord, nullptr); diff --git a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn index e4decc8bc3..c81e31ccb7 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn +++ b/test/moduletest/common/ams/app_mgr_service_test/BUILD.gn @@ -35,10 +35,6 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] - if (ability_runtime_graphics) { - deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] - } - external_deps = [ "access_token:libnativetoken", "access_token:libtoken_setproc", @@ -48,9 +44,13 @@ ohos_moduletest("AmsAppMgrServiceModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index 05f67da7da..26f00dfcdf 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -46,7 +46,7 @@ public: {} void ScheduleBackgroundApplication() override {} - void ScheduleTerminateApplication() override + void ScheduleTerminateApplication(bool isLastProcess = false) override {} void ScheduleShrinkMemory(const int) override {} diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn index 38c0fe9af7..8f69d35254 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn @@ -43,9 +43,12 @@ ohos_moduletest("AppRunningProcessesInfoModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp b/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp index 65a81d0488..71217b199d 100644 --- a/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp +++ b/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp @@ -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 @@ -437,7 +437,7 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ApplicationStartAndQuit_005, TestSize.Le stateFromRec = record->GetState(); EXPECT_EQ(stateFromRec, ApplicationState::APP_STATE_BACKGROUND); - EXPECT_CALL(*mockApplication, ScheduleTerminateApplication()) + EXPECT_CALL(*mockApplication, ScheduleTerminateApplication(_)) .Times(1) .WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post)); // set application terminate diff --git a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn index c2ca3db1e0..71e27ad188 100644 --- a/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn +++ b/test/moduletest/common/ams/ipc_ams_mgr_test/BUILD.gn @@ -47,9 +47,12 @@ ohos_moduletest("AmsIpcAmsmgrModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp b/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp index 002705fb13..7294c95b24 100644 --- a/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp +++ b/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp @@ -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 @@ -118,7 +118,7 @@ HWTEST_F(AmsIpcAppSchedulerModuleTest, ExcuteApplicationIPCInterface_003, TestSi sptr mockApplication(new MockApplication()); sptr client = iface_cast(mockApplication); - EXPECT_CALL(*mockApplication, ScheduleTerminateApplication()) + EXPECT_CALL(*mockApplication, ScheduleTerminateApplication(_)) .Times(1) .WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post)); client->ScheduleTerminateApplication(); diff --git a/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn b/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn index 40f3fd857f..cbd69fd7c8 100644 --- a/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn +++ b/test/moduletest/common/ams/service_app_spawn_client_test/BUILD.gn @@ -33,13 +33,6 @@ ohos_moduletest("AmsServiceAppSpawnClientModuleTest") { "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] - if (ability_runtime_graphics) { - deps += [ - "${ability_runtime_native_path}/appkit:appkit_manager_helper", - "${global_path}/i18n/frameworks/intl:intl_util", - ] - } - external_deps = [ "bundle_framework:appexecfwk_base", "ffrt:libffrt", @@ -47,9 +40,16 @@ ohos_moduletest("AmsServiceAppSpawnClientModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + deps += [ + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${global_path}/i18n/frameworks/intl:intl_util", + ] + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/service_event_drive_test/BUILD.gn b/test/moduletest/common/ams/service_event_drive_test/BUILD.gn index 06aa47c4ac..3c933b25b2 100644 --- a/test/moduletest/common/ams/service_event_drive_test/BUILD.gn +++ b/test/moduletest/common/ams/service_event_drive_test/BUILD.gn @@ -34,10 +34,6 @@ ohos_moduletest("AmsServiceEventDriveModuleTest") { "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] - if (ability_runtime_graphics) { - deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] - } - external_deps = [ "access_token:libnativetoken", "access_token:libtoken_setproc", @@ -46,9 +42,13 @@ ohos_moduletest("AmsServiceEventDriveModuleTest") { "hicollie:libhicollie", "hilog:libhilog", "ipc:ipc_core", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/service_start_process_test/BUILD.gn b/test/moduletest/common/ams/service_start_process_test/BUILD.gn index 5bf1ce055c..cab8accd49 100644 --- a/test/moduletest/common/ams/service_start_process_test/BUILD.gn +++ b/test/moduletest/common/ams/service_start_process_test/BUILD.gn @@ -32,10 +32,6 @@ ohos_moduletest("AmsServiceStartModuleTest") { "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", ] - if (ability_runtime_graphics) { - deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] - } - external_deps = [ "bundle_framework:appexecfwk_base", "ffrt:libffrt", @@ -43,9 +39,13 @@ ohos_moduletest("AmsServiceStartModuleTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ] + external_deps += [ "window_manager:libwm" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 974a0dc83e..263a15a44b 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -44,12 +44,15 @@ ohos_moduletest("specified_ability_service_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("moduletest") { diff --git a/test/moduletest/mock/include/mock_ability_scheduler.h b/test/moduletest/mock/include/mock_ability_scheduler.h index 7f5ff3a9a7..571cab6fbf 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler.h +++ b/test/moduletest/mock/include/mock_ability_scheduler.h @@ -128,6 +128,7 @@ public: { return 0; } + virtual void UpdateSessionToken(sptr sessionToken) override {} #ifdef ABILITY_COMMAND_FOR_TEST virtual int BlockAbility() override { diff --git a/test/moduletest/mock/include/mock_ability_scheduler_stub.h b/test/moduletest/mock/include/mock_ability_scheduler_stub.h index 88db7f105f..17cffb695b 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler_stub.h +++ b/test/moduletest/mock/include/mock_ability_scheduler_stub.h @@ -68,6 +68,8 @@ public: return 0; } + virtual void UpdateSessionToken(sptr sessionToken) override {} + #ifdef ABILITY_COMMAND_FOR_TEST virtual int BlockAbility() override { diff --git a/test/moduletest/mock/include/mock_app_scheduler.h b/test/moduletest/mock/include/mock_app_scheduler.h index ac53daf20e..a98015be9a 100644 --- a/test/moduletest/mock/include/mock_app_scheduler.h +++ b/test/moduletest/mock/include/mock_app_scheduler.h @@ -33,7 +33,7 @@ public: MOCK_METHOD0(ScheduleForegroundApplication, void()); MOCK_METHOD0(ScheduleBackgroundApplication, void()); - MOCK_METHOD0(ScheduleTerminateApplication, void()); + MOCK_METHOD1(ScheduleTerminateApplication, void(bool)); MOCK_METHOD2(ScheduleLaunchApplication, void(const AppExecFwk::AppLaunchData&, const Configuration& config)); MOCK_METHOD3(ScheduleLaunchAbility, void(const AppExecFwk::AbilityInfo&, const sptr&, const std::shared_ptr&)); diff --git a/test/moduletest/on_new_want_module_test/BUILD.gn b/test/moduletest/on_new_want_module_test/BUILD.gn index 436124c22c..7c17e8c50c 100644 --- a/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/test/moduletest/on_new_want_module_test/BUILD.gn @@ -44,9 +44,12 @@ ohos_moduletest("on_new_want_module_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } diff --git a/test/moduletest/running_infos_module_test/BUILD.gn b/test/moduletest/running_infos_module_test/BUILD.gn index b56710f738..bcb0576020 100644 --- a/test/moduletest/running_infos_module_test/BUILD.gn +++ b/test/moduletest/running_infos_module_test/BUILD.gn @@ -110,6 +110,7 @@ ohos_moduletest("running_infos_module_test") { "relational_store:native_dataability", "relational_store:native_rdb", "safwk:system_ability_fwk", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwsutils", "window_manager:sms", ] @@ -133,6 +134,8 @@ ohos_moduletest("running_infos_module_test") { external_deps += [ "input:libmmi-client", "window_manager:libdm", + "window_manager:libwsutils", + "window_manager:sms", ] } } diff --git a/test/moduletest/start_option_display_id_test/BUILD.gn b/test/moduletest/start_option_display_id_test/BUILD.gn index eec8b23ae9..ffd2faca61 100644 --- a/test/moduletest/start_option_display_id_test/BUILD.gn +++ b/test/moduletest/start_option_display_id_test/BUILD.gn @@ -42,9 +42,12 @@ ohos_moduletest("start_option_module_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } diff --git a/test/moduletest/ui_extension_ability_test/ui_extension_connect_module_test/ui_extension_connect_module_test.cpp b/test/moduletest/ui_extension_ability_test/ui_extension_connect_module_test/ui_extension_connect_module_test.cpp index 8e635c976a..d79cd12905 100644 --- a/test/moduletest/ui_extension_ability_test/ui_extension_connect_module_test/ui_extension_connect_module_test.cpp +++ b/test/moduletest/ui_extension_ability_test/ui_extension_connect_module_test/ui_extension_connect_module_test.cpp @@ -48,6 +48,8 @@ const std::string TARGET_MODULE_NAME = "entry"; const std::string USER_BUNDLE_NAME = "com.ohos.uiextensionuser"; const std::string USER_ABILITY_NAME = "EntryAbility"; const std::string USER_MODULE_NAME = "entry"; +const std::string UIEXTENSION_ABILITY_ID = "ability.want.params.uiExtensionAbilityId"; + static void SetNativeToken() { @@ -87,6 +89,7 @@ public: void WaitUntilDisConnectDone(const sptr &connection); void WaitUntilProcessCreated(const sptr &observer); void WaitUntilProcessDied(const sptr &observer); + void CheckProcessNotDied(const sptr &observer); void WaitUntilAbilityForeground(const sptr &observer); void WaitUntilAbilityBackground(const sptr &observer); @@ -193,6 +196,17 @@ void UIExtensionConnectModuleTest::WaitUntilProcessDied(const sptrprocessDied_, true); } +void UIExtensionConnectModuleTest::CheckProcessNotDied(const sptr &observer) +{ + std::unique_lock lock(observer->observerMutex_); + auto waitStatus = observer->observerCondation_.wait_for(lock, std::chrono::milliseconds(CONNECT_TIMEOUT_MS), + [observer]() { + return observer->processDied_; + }); + EXPECT_EQ(waitStatus, false); + EXPECT_EQ(observer->processDied_, false); +} + void UIExtensionConnectModuleTest::WaitUntilAbilityForeground( const sptr &observer) { @@ -638,9 +652,190 @@ HWTEST_F(UIExtensionConnectModuleTest, ConnectUIExtensionAbility_0600, TestSize. // Wait until OnAbilityDisconnectDone has triggered. WaitUntilDisConnectDone(connection); + // Wait until ability has terminate + WaitUntilProcessDied(observer); + + SetSelfTokenID(currentId); + UnregisterApplicationStateObserver(observer); + HILOG_INFO("finish."); +} + +/** + * @tc.name: ConnectUIExtensionAbility_0700 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI8JARY + */ +HWTEST_F(UIExtensionConnectModuleTest, ConnectUIExtensionAbility_0700, TestSize.Level1) +{ + HILOG_INFO("start."); + + auto currentId = GetSelfTokenID(); + SetNativeToken(); + + auto observer = sptr::MakeSptr(); + RegisterApplicationStateObserver(observer); + + Want providerWant; + AppExecFwk::ElementName providerElement("0", TARGET_BUNDLE_NAME, TARGET_ABILITY_NAME, TARGET_MODULE_NAME); + providerWant.SetElement(providerElement); + + auto connection = sptr::MakeSptr(); + ASSERT_NE(connection, nullptr); + + auto sessionInfo = sptr::MakeSptr(); + ASSERT_NE(sessionInfo, nullptr); + + // Connect ui extension ability firstly. + auto connectInfo = sptr::MakeSptr(); + ASSERT_NE(connectInfo, nullptr); + connectInfo->hostBundleName = USER_BUNDLE_NAME; + connectInfo->uiExtensionAbilityId = 0; + auto ret = AbilityManagerClient::GetInstance()->ConnectUIExtensionAbility(providerWant, connection, sessionInfo, + DEFAULT_INVAL_VALUE, connectInfo); + EXPECT_EQ(ret, ERR_OK); + HILOG_INFO("UIExtensonAbility id %{public}d", connectInfo->uiExtensionAbilityId); + EXPECT_NE(connectInfo->uiExtensionAbilityId, 0); + + // Wait until OnAbilityConnectDone has triggered. + WaitUntilConnectDone(connection); + + // start ui extension user + Want userWant; + AppExecFwk::ElementName userElement("0", USER_BUNDLE_NAME, USER_ABILITY_NAME, USER_MODULE_NAME); + userWant.SetElement(userElement); + userWant.SetParam(UIEXTENSION_ABILITY_ID, connectInfo->uiExtensionAbilityId); + ret = AbilityManagerClient::GetInstance()->StartAbility(userWant); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has foregrounded + WaitUntilAbilityForeground(observer); + + // Destroy ui extension user. + sptr token = nullptr; + ret = AbilityManagerClient::GetInstance()->GetTopAbility(token); + EXPECT_EQ(ret, ERR_OK); + + // Minimize ui extension user + ret = AbilityManagerClient::GetInstance()->MinimizeAbility(token); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has background + WaitUntilAbilityBackground(observer); + + int resultCode = 0; + Want resultWant; + ret = AbilityManagerClient::GetInstance()->TerminateAbility(token, resultCode, &resultWant); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has background + WaitUntilAbilityBackground(observer); + + // check ability not terminated. + CheckProcessNotDied(observer); + + // Disconnect ui extension ability. + ret = AbilityManagerClient::GetInstance()->DisconnectAbility(connection); + EXPECT_EQ(ret, ERR_OK); + + // Wait until OnAbilityDisconnectDone has triggered. + WaitUntilDisConnectDone(connection); + + // Wait until ability has terminated. + WaitUntilProcessDied(observer); + + SetSelfTokenID(currentId); + UnregisterApplicationStateObserver(observer); + HILOG_INFO("finish."); +} + +/** + * @tc.name: ConnectUIExtensionAbility_0800 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI8JARY + */ +HWTEST_F(UIExtensionConnectModuleTest, ConnectUIExtensionAbility_0800, TestSize.Level1) +{ + HILOG_INFO("start."); + + auto currentId = GetSelfTokenID(); + SetNativeToken(); + + auto observer = sptr::MakeSptr(); + RegisterApplicationStateObserver(observer); + + Want providerWant; + AppExecFwk::ElementName providerElement("0", TARGET_BUNDLE_NAME, TARGET_ABILITY_NAME, TARGET_MODULE_NAME); + providerWant.SetElement(providerElement); + + auto connection = sptr::MakeSptr(); + ASSERT_NE(connection, nullptr); + + auto sessionInfo = sptr::MakeSptr(); + ASSERT_NE(sessionInfo, nullptr); + + // Connect ui extension ability firstly. + auto connectInfo = sptr::MakeSptr(); + ASSERT_NE(connectInfo, nullptr); + connectInfo->hostBundleName = USER_BUNDLE_NAME; + connectInfo->uiExtensionAbilityId = 0; + auto ret = AbilityManagerClient::GetInstance()->ConnectUIExtensionAbility(providerWant, connection, sessionInfo, + DEFAULT_INVAL_VALUE, connectInfo); + EXPECT_EQ(ret, ERR_OK); + HILOG_INFO("UIExtensonAbility id %{public}d", connectInfo->uiExtensionAbilityId); + EXPECT_NE(connectInfo->uiExtensionAbilityId, 0); + + // Wait until OnAbilityConnectDone has triggered. + WaitUntilConnectDone(connection); + + // start ui extension user + Want userWant; + AppExecFwk::ElementName userElement("0", USER_BUNDLE_NAME, USER_ABILITY_NAME, USER_MODULE_NAME); + userWant.SetElement(userElement); + userWant.SetParam(UIEXTENSION_ABILITY_ID, connectInfo->uiExtensionAbilityId); + ret = AbilityManagerClient::GetInstance()->StartAbility(userWant); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has foregrounded + WaitUntilAbilityForeground(observer); + + // Disconnect ui extension ability. + ret = AbilityManagerClient::GetInstance()->DisconnectAbility(connection); + EXPECT_EQ(ret, ERR_OK); + + // Wait until OnAbilityDisconnectDone has triggered. + WaitUntilDisConnectDone(connection); + + // check ability not terminated. + CheckProcessNotDied(observer); + + // Destroy ui extension user. + sptr token = nullptr; + ret = AbilityManagerClient::GetInstance()->GetTopAbility(token); + EXPECT_EQ(ret, ERR_OK); + + // Minimize ui extension user + ret = AbilityManagerClient::GetInstance()->MinimizeAbility(token); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has background + WaitUntilAbilityBackground(observer); + + int resultCode = 0; + Want resultWant; + ret = AbilityManagerClient::GetInstance()->TerminateAbility(token, resultCode, &resultWant); + EXPECT_EQ(ret, ERR_OK); + + // Wait until ability has background + WaitUntilAbilityBackground(observer); + + // Wait until ability has terminated. + WaitUntilProcessDied(observer); + SetSelfTokenID(currentId); UnregisterApplicationStateObserver(observer); HILOG_INFO("finish."); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/entryability/EntryAbility.ets b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/entryability/EntryAbility.ets index 078a52eb8b..18e2a81618 100644 --- a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/entryability/EntryAbility.ets +++ b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,6 +22,28 @@ import window from '@ohos.window'; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + if (want.parameters.hasOwnProperty("ability.want.params.uiExtensionAbilityId")) { + let uiExtensionAbilityId = want.parameters["ability.want.params.uiExtensionAbilityId"] + hilog.info(0x0000, 'testTag', 'uiExtensionAbilityId is %{public}d', uiExtensionAbilityId); + globalThis.uiExtensionComponentWant = { + bundleName: 'com.ohos.uiextensionprovider', + abilityName: 'UIExtensionProvider', + moduleName: 'entry', + parameters: { + 'ability.want.params.uiExtensionType': 'sys/commonUI', + 'ability.want.params.uiExtensionAbilityId': uiExtensionAbilityId + } + } + } else { + globalThis.uiExtensionComponentWant = { + bundleName: 'com.ohos.uiextensionprovider', + abilityName: 'UIExtensionProvider', + moduleName: 'entry', + parameters: { + 'ability.want.params.uiExtensionType': 'sys/commonUI', + } + } + } } onDestroy() { diff --git a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/pages/Index.ets b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/pages/Index.ets index 09e0cdc96d..8353b5faac 100644 --- a/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/pages/Index.ets +++ b/test/moduletest/ui_extension_ability_test/ui_extension_user_bundle/entry/src/main/ets/pages/Index.ets @@ -28,15 +28,7 @@ struct Index { .fontWeight(FontWeight.Bold) .textAlign(TextAlign.Center) - UIExtensionComponent( - { - bundleName: 'com.ohos.uiextensionprovider', - abilityName: 'UIExtensionProvider', - moduleName: 'entry', - parameters: { - 'ability.want.params.uiExtensionType': 'sys/commonUI', - } - }) + UIExtensionComponent(globalThis.uiExtensionComponentWant) .onRemoteReady((proxy) => { this.myProxy = proxy; }) @@ -72,4 +64,4 @@ struct Index { } .height('100%') } -} \ No newline at end of file +} diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 114ecc48fd..d31f3f0441 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -234,6 +234,7 @@ ohos_source_set("abilityms_test_source") { "relational_store:native_rdb", "resource_management:global_resmgr", "safwk:system_ability_fwk", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwsutils", "window_manager:sms", ] @@ -279,7 +280,10 @@ ohos_source_set("abilityms_test_source") { external_deps += [ "input:libmmi-client", "window_manager:libdm", + "window_manager:libmodal_system_ui_extension_client", "window_manager:libwm", + "window_manager:libwsutils", + "window_manager:sms", ] } @@ -309,6 +313,8 @@ group("unittest") { "ability_extension_module_loader_test:unittest", "ability_extension_running_info_test:unittest", "ability_extension_test:unittest", + "ability_foreground_state_observer_proxy_test:unittest", + "ability_foreground_state_observer_stub_test:unittest", "ability_interceptor_test:unittest", "ability_manager_client_branch_test:unittest", "ability_manager_proxy_test:unittest", @@ -352,6 +358,7 @@ group("unittest") { "app_debug_info_test:unittest", "app_debug_listener_proxy_test:unittest", "app_debug_listener_stub_test:unittest", + "app_debug_manager_test:unittest", "app_exit_reason_data_manager_test:unittest", "app_launch_data_test:unittest", "app_lifecycle_deal_test:unittest", @@ -366,6 +373,7 @@ group("unittest") { "app_recovery_test:unittest", "app_running_manager_test:unittest", "app_running_processes_info_test:unittest", + "app_running_record_test:unittest", "app_scheduler_host_test:unittest", "app_scheduler_proxy_test:unittest", "app_scheduler_test:unittest", diff --git a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp index 2ad1ff421c..681f36cbd1 100644 --- a/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp +++ b/test/unittest/ability_connect_manager_test/ability_connect_manager_test.cpp @@ -2784,12 +2784,14 @@ HWTEST_F(AbilityConnectManagerTest, OnAbilityRequestDone_001, TestSize.Level1) sptr token = abilityRecord->GetToken(); abilityRecord->abilityInfo_.extensionAbilityType = ExtensionAbilityType::UI; abilityRecord->SetAbilityState(AbilityState::INACTIVE); + abilityRecord->SetUIExtRequestSessionInfo(MockSessionInfo(0)); connectManager->serviceMap_.emplace("first", abilityRecord); connectManager->OnAbilityRequestDone(token, 2); EXPECT_EQ(abilityRecord->GetAbilityState(), AbilityState::FOREGROUNDING); connectManager->serviceMap_.erase("first"); abilityRecord->abilityInfo_.extensionAbilityType = ExtensionAbilityType::UNSPECIFIED; abilityRecord->SetAbilityState(AbilityState::INITIAL); + abilityRecord->SetUIExtRequestSessionInfo(nullptr); } /* @@ -2841,8 +2843,10 @@ HWTEST_F(AbilityConnectManagerTest, MoveToForeground_001, TestSize.Level1) { std::shared_ptr connectManager = std::make_shared(3); ASSERT_NE(connectManager, nullptr); + serviceRecord_->SetUIExtRequestSessionInfo(MockSessionInfo(0)); connectManager->MoveToForeground(serviceRecord_); EXPECT_EQ(serviceRecord_->GetAbilityState(), AbilityState::FOREGROUNDING); + serviceRecord_->SetUIExtRequestSessionInfo(nullptr); serviceRecord_->SetAbilityState(AbilityState::INITIAL); } diff --git a/test/unittest/ability_debug_deal_test/ability_debug_deal_test.cpp b/test/unittest/ability_debug_deal_test/ability_debug_deal_test.cpp index 0abe31263c..d885ceaa7d 100644 --- a/test/unittest/ability_debug_deal_test/ability_debug_deal_test.cpp +++ b/test/unittest/ability_debug_deal_test/ability_debug_deal_test.cpp @@ -47,7 +47,7 @@ void AbilityDebugDealTest::TearDownTestCase(void) void AbilityDebugDealTest::SetUp() { - deal_ = std::make_shared(); + deal_ = std::make_shared(); } void AbilityDebugDealTest::TearDown() @@ -73,9 +73,9 @@ HWTEST_F(AbilityDebugDealTest, RegisterAbilityDebugResponse_0100, TestSize.Level * @tc.type: FUNC */ HWTEST_F(AbilityDebugDealTest, OnAbilitysDebugStarted_0100, TestSize.Level1) -{ +{ EXPECT_NE(deal_, nullptr); - + Want want; OHOS::AppExecFwk::AbilityInfo abilityInfo; abilityInfo.process = STRING_PROCESS_NAME; diff --git a/test/unittest/ability_foreground_state_observer_proxy_test/BUILD.gn b/test/unittest/ability_foreground_state_observer_proxy_test/BUILD.gn new file mode 100644 index 0000000000..7b822ca680 --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_proxy_test/BUILD.gn @@ -0,0 +1,57 @@ +# 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_foreground_state_observer_proxy" + +ohos_unittest("ability_foreground_state_observer_proxy_test") { + module_out_path = module_output_path + + sources = [ + "${ability_runtime_innerkits_path}/ability_manager/src/ability_foreground_state_observer_proxy.cpp", + "ability_foreground_state_observer_proxy_test.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + + cflags = [] + + include_dirs = [ + "${ability_runtime_services_path}/common/include/", + "${ability_runtime_test_path}/unittest/ability_foreground_state_observer_stub_test/", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + +group("unittest") { + testonly = true + deps = [ ":ability_foreground_state_observer_proxy_test" ] +} diff --git a/test/unittest/ability_foreground_state_observer_proxy_test/ability_foreground_state_observer_proxy_test.cpp b/test/unittest/ability_foreground_state_observer_proxy_test/ability_foreground_state_observer_proxy_test.cpp new file mode 100644 index 0000000000..5858f5e8ff --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_proxy_test/ability_foreground_state_observer_proxy_test.cpp @@ -0,0 +1,90 @@ +/* + * 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 + +#define private public +#include "ability_foreground_state_observer_proxy.h" +#include "ability_state_data.h" +#undef private +#include "mock_ability_foreground_state_observer_stub.h" +#include "mock_ability_foreground_state_observer_server_stub.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AbilityRuntime { +class AbilityForegroundStateObserverProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + sptr observerProxy_ {nullptr}; + sptr mock_; +}; +void AbilityForegroundStateObserverProxyTest::SetUpTestCase() +{} + +void AbilityForegroundStateObserverProxyTest::TearDownTestCase() +{} + +void AbilityForegroundStateObserverProxyTest::SetUp() +{ + mock_ = new MockAbilityForegroundStateObserverStub(); + observerProxy_ = new AbilityForegroundStateObserverProxy(mock_); +} + +void AbilityForegroundStateObserverProxyTest::TearDown() +{} + +/** + * @tc.number: WriteInterfaceToken_0100 + * @tc.desc: Write token into parcel data. + * @tc.type: FUNC + */ +HWTEST_F(AbilityForegroundStateObserverProxyTest, WriteInterfaceToken_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteInterfaceToken_0100 start"; + MessageParcel data; + auto ret = observerProxy_->WriteInterfaceToken(data); + EXPECT_EQ(ret, true); + GTEST_LOG_(INFO) << "WriteInterfaceToken_0100 end"; +} + +/** + * @tc.number: OnAbilityStateChanged_0100 + * @tc.desc: Test by determine whether sendRequest has been executed. + * @tc.type: FUNC + */ +HWTEST_F(AbilityForegroundStateObserverProxyTest, OnAbilityStateChanged_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnAbilityStateChanged_0100 start"; + AbilityStateData abilityStateData; + sptr token = new MockAbilityForegroundStateObserverServerStub(); + abilityStateData.token = token; + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &MockAbilityForegroundStateObserverStub::InvokeSendRequest)); + observerProxy_->OnAbilityStateChanged(abilityStateData); + EXPECT_EQ( + static_cast(IAbilityForegroundStateObserver::Message::ON_ABILITY_STATE_CHANGED), mock_->GetCode()); + GTEST_LOG_(INFO) << "OnAbilityStateChanged_0100 end"; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/ability_foreground_state_observer_proxy_test/mock_ability_foreground_state_observer_stub.h b/test/unittest/ability_foreground_state_observer_proxy_test/mock_ability_foreground_state_observer_stub.h new file mode 100644 index 0000000000..bf8e9b01e3 --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_proxy_test/mock_ability_foreground_state_observer_stub.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_STUB_H +#define UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_STUB_H + +#include "gmock/gmock.h" + +#include "ability_foreground_state_observer_stub.h" +#include "ability_foreground_state_observer_interface.h" + +namespace OHOS { +namespace AppExecFwk { +class MockAbilityForegroundStateObserverStub : public AbilityForegroundStateObserverStub { +public: + MockAbilityForegroundStateObserverStub() = default; + virtual ~MockAbilityForegroundStateObserverStub() = default; + MOCK_METHOD1(OnAbilityStateChanged, void(const AbilityStateData &abilityStateData)); + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) + { + code_ = code; + return 0; + } + + int GetCode() + { + return code_; + } + +private: + int code_ = 0; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_STUB_H diff --git a/test/unittest/ability_foreground_state_observer_stub_test/BUILD.gn b/test/unittest/ability_foreground_state_observer_stub_test/BUILD.gn new file mode 100644 index 0000000000..f19c4461fb --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_stub_test/BUILD.gn @@ -0,0 +1,58 @@ +# 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_foreground_state_observer_stub" + +ohos_unittest("ability_foreground_state_observer_stub_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_innerkits_path}/app_manager/include/appmgr/", + "${ability_runtime_test_path}/unittest/ability_foreground_state_observer_stub_test/", + "//foundation/filemanagement/user_file_service/utils/", + "${ability_runtime_test_path}/unittest/ability_foreground_state_observer_stub_test", + ] + + sources = [ + "${ability_runtime_innerkits_path}/ability_manager/src/ability_foreground_state_observer_stub.cpp", + "ability_foreground_state_observer_stub_test.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + + cflags = [] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] +} + +group("unittest") { + testonly = true + deps = [ ":ability_foreground_state_observer_stub_test" ] +} diff --git a/test/unittest/ability_foreground_state_observer_stub_test/ability_foreground_state_observer_stub_test.cpp b/test/unittest/ability_foreground_state_observer_stub_test/ability_foreground_state_observer_stub_test.cpp new file mode 100644 index 0000000000..05a98d33f6 --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_stub_test/ability_foreground_state_observer_stub_test.cpp @@ -0,0 +1,111 @@ +/* + * 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 + +#define private public +#define protected public +#include "ability_foreground_state_observer_stub.h" +#undef private +#undef protected +#include "mock_ability_foreground_state_observer_server_stub.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AbilityRuntime { +class AbilityForegroundStateObserverStubTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + sptr observerStub_; +}; + +void AbilityForegroundStateObserverStubTest::SetUpTestCase() +{} + +void AbilityForegroundStateObserverStubTest::TearDownTestCase() +{} + +void AbilityForegroundStateObserverStubTest::SetUp() +{ + observerStub_ = new MockAbilityForegroundStateObserverServerStub(); +} + +void AbilityForegroundStateObserverStubTest::TearDown() +{} + +/** + * @tc.number: OnRemoteRequest_0100 + * @tc.desc: Verify the normal process of onremoterequest. + * @tc.type: FUNC + */ +HWTEST_F(AbilityForegroundStateObserverStubTest, OnRemoteRequest_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnRemoteRequest_0100 start"; + auto code = static_cast(IAbilityForegroundStateObserver::Message::ON_ABILITY_STATE_CHANGED); + MessageParcel data; + AbilityStateData abilityStateData; + data.WriteInterfaceToken(AbilityForegroundStateObserverStub::GetDescriptor()); + data.WriteParcelable(&abilityStateData); + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + int32_t result = observerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, NO_ERROR); + GTEST_LOG_(INFO) << "OnRemoteRequest_0100 end"; +} + +/** + * @tc.number: OnRemoteRequest_0200 + * @tc.desc: Verify the exception process of onremoterequest. + * @tc.type: FUNC + */ +HWTEST_F(AbilityForegroundStateObserverStubTest, OnRemoteRequest_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnRemoteRequest_0200 start"; + auto code = static_cast(IAbilityForegroundStateObserver::Message::ON_ABILITY_STATE_CHANGED); + MessageParcel data; + AbilityStateData abilityStateData; + data.WriteParcelable(&abilityStateData); + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + int32_t result = observerStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(result, ERR_INVALID_STATE); + GTEST_LOG_(INFO) << "OnRemoteRequest_0200 end"; +} + +/** + * @tc.number: HandleOnAbilityStateChanged_0100 + * @tc.desc: Verify the normal process of HandleOnAbilityStateChanged. + * @tc.type: FUNC + */ +HWTEST_F(AbilityForegroundStateObserverStubTest, HandleOnAbilityStateChanged_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HandleOnAbilityStateChanged_0100 start"; + AbilityStateData abilityStateData; + MessageParcel data; + data.WriteParcelable(&abilityStateData); + MessageParcel reply; + auto res = observerStub_->HandleOnAbilityStateChanged(data, reply); + EXPECT_EQ(res, NO_ERROR); + GTEST_LOG_(INFO) << "HandleOnAbilityStateChanged_0100 end"; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/ability_foreground_state_observer_stub_test/mock_ability_foreground_state_observer_server_stub.h b/test/unittest/ability_foreground_state_observer_stub_test/mock_ability_foreground_state_observer_server_stub.h new file mode 100644 index 0000000000..bf81584140 --- /dev/null +++ b/test/unittest/ability_foreground_state_observer_stub_test/mock_ability_foreground_state_observer_server_stub.h @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_SERVER_STUB_H +#define UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_SERVER_STUB_H + +#define private public +#define protected public +#include "ability_foreground_state_observer_stub.h" +#include "ability_foreground_state_observer_interface.h" +#undef private +#undef protected + +namespace OHOS { +namespace AppExecFwk { +class MockAbilityForegroundStateObserverServerStub : public AbilityForegroundStateObserverStub { +public: + MockAbilityForegroundStateObserverServerStub() = default; + virtual ~MockAbilityForegroundStateObserverServerStub() = default; + void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override {} + + bool AddDeathRecipient(const sptr &recipient) override + { + return true; + } +}; +} // namespace AAFwk +} // namespace OHOS +#endif // UNITTEST_OHOS_MOCK_ABILITY_FOREGROUND_STATE_OBSERVER_SERVER_STUB_H diff --git a/test/unittest/ability_manager_client_branch_test/BUILD.gn b/test/unittest/ability_manager_client_branch_test/BUILD.gn index d4708e06da..aed05b337b 100644 --- a/test/unittest/ability_manager_client_branch_test/BUILD.gn +++ b/test/unittest/ability_manager_client_branch_test/BUILD.gn @@ -24,6 +24,7 @@ ohos_unittest("ability_manager_client_branch_test") { "${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/unittest/app_debug_listener_stub_test", ] sources = [ @@ -70,8 +71,6 @@ ohos_unittest("ability_manager_client_branch_test") { "init:libbeget_proxy", "ipc:ipc_core", "napi:ace_napi", - "window_manager:libwsutils", - "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -79,7 +78,11 @@ ohos_unittest("ability_manager_client_branch_test") { } if (ability_runtime_graphics) { - external_deps += [ "image_framework:image_native" ] + external_deps += [ + "image_framework:image_native", + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ability_manager_proxy_test/BUILD.gn b/test/unittest/ability_manager_proxy_test/BUILD.gn index 4bfccd9cf3..5402ce7ce4 100644 --- a/test/unittest/ability_manager_proxy_test/BUILD.gn +++ b/test/unittest/ability_manager_proxy_test/BUILD.gn @@ -1,4 +1,4 @@ -# 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 @@ -21,10 +21,12 @@ ohos_unittest("ability_manager_proxy_test") { include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${ability_runtime_test_path}/unittest/ability_manager_proxy_test/", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/ability_scheduler_mock", "${ability_runtime_services_path}/common/include", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test", ] sources = [ diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index 4acdc8536e..8d96375c2c 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -25,6 +25,7 @@ #include "mock_ability_token.h" #include "ability_scheduler_mock.h" #include "ability_record.h" +#include "app_debug_listener_stub_mock.h" #include "ability_scheduler.h" #include "mission_snapshot.h" #include "want_sender_info.h" @@ -37,6 +38,7 @@ namespace OHOS { namespace AAFwk { namespace { const int USER_ID = 100; +constexpr int32_t REPLY_RESULT = 1; } // namespace class AbilityManagerProxyTest : public testing::Test { @@ -2396,6 +2398,84 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_IsAbilityControllerStart_0 proxy_->IsAbilityControllerStart(want); } +/** + * @tc.name: AbilityManagerProxy_RegisterAppDebugListener_0100 + * @tc.desc: Test the status of RegisterAppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RegisterAppDebugListener_0100, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + sptr listener = new AppDebugListenerStubMock(); + auto result = proxy_->RegisterAppDebugListener(listener); + EXPECT_EQ(result, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerProxy_RegisterAppDebugListener_0200 + * @tc.desc: Test the status of RegisterAppDebugListener, check nullptr listener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RegisterAppDebugListener_0200, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + sptr listener = nullptr; + auto result = proxy_->RegisterAppDebugListener(listener); + EXPECT_EQ(result, INNER_ERR); +} + +/** + * @tc.name: AbilityManagerProxy_UnregisterAppDebugListener_0100 + * @tc.desc: Test the status of UnregisterAppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UnregisterAppDebugListener_0100, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + sptr listener = new AppDebugListenerStubMock(); + auto result = proxy_->UnregisterAppDebugListener(listener); + EXPECT_EQ(result, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerProxy_UnregisterAppDebugListener_0200 + * @tc.desc: Test the status of UnregisterAppDebugListener, check nullptr listener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UnregisterAppDebugListener_0200, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + sptr listener = nullptr; + auto result = proxy_->UnregisterAppDebugListener(listener); + EXPECT_EQ(result, INNER_ERR); +} + +/** + * @tc.name: AbilityManagerProxy_AttachAppDebug_0100 + * @tc.desc: Test the state of AttachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_AttachAppDebug_0100, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + std::string bundleName = "bundleName"; + auto result = proxy_->AttachAppDebug(bundleName); + EXPECT_EQ(result, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerProxy_DetachAppDebug_0100 + * @tc.desc: Test the state of DetachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_DetachAppDebug_0100, TestSize.Level1) +{ + EXPECT_NE(proxy_, nullptr); + std::string bundleName = "bundleName"; + auto result = proxy_->DetachAppDebug(bundleName); + EXPECT_EQ(result, NO_ERROR); +} + /** * @tc.name: AbilityManagerProxy_GetForegroundUIAbilities_001 * @tc.desc: Test function GetForegroundUIAbilities when normally. diff --git a/test/unittest/ability_manager_service_anr_test/BUILD.gn b/test/unittest/ability_manager_service_anr_test/BUILD.gn index 451bb131ab..1d0b498e1a 100644 --- a/test/unittest/ability_manager_service_anr_test/BUILD.gn +++ b/test/unittest/ability_manager_service_anr_test/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("ability_manager_service_anr_test") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { @@ -67,7 +66,10 @@ ohos_unittest("ability_manager_service_anr_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ability_manager_service_dialog_test/BUILD.gn b/test/unittest/ability_manager_service_dialog_test/BUILD.gn index 8661dea5be..134d42b8dd 100644 --- a/test/unittest/ability_manager_service_dialog_test/BUILD.gn +++ b/test/unittest/ability_manager_service_dialog_test/BUILD.gn @@ -38,12 +38,15 @@ ohos_unittest("ability_manager_service_dialog_test") { "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", - "window_manager:libdm", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ability_manager_service_first_test/BUILD.gn b/test/unittest/ability_manager_service_first_test/BUILD.gn index f60e9e278b..c71e4c08a9 100644 --- a/test/unittest/ability_manager_service_first_test/BUILD.gn +++ b/test/unittest/ability_manager_service_first_test/BUILD.gn @@ -63,12 +63,15 @@ ohos_unittest("ability_manager_service_first_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp index 31388bf077..3482fea714 100644 --- a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp +++ b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp @@ -1484,5 +1484,40 @@ HWTEST_F(AbilityManagerServiceFirstTest, GetForegroundUIAbilities_001, TestSize. auto res = abilityMs_->GetForegroundUIAbilities(list); EXPECT_EQ(res, CHECK_PERMISSION_FAILED); } + +/* + * Feature: AbilityManagerService + * Function: GenerateEmbeddableUIAbilityRequest + * SubFunction: NA + * FunctionPoints: AbilityManagerService GenerateEmbeddableUIAbilityRequest + */ +HWTEST_F(AbilityManagerServiceFirstTest, GenerateEmbeddableUIAbilityRequest_001, TestSize.Level1) +{ + HILOG_INFO("AbilityManagerServiceSecondTest GenerateEmbeddableUIAbilityRequest_001 start"); + auto abilityMs_ = std::make_shared(); + Want want; + want.SetParam("ScreenMode", 1); + AbilityRequest request; + auto res = abilityMs_->GenerateEmbeddableUIAbilityRequest(want, request, nullptr, USER_ID_U100); + EXPECT_EQ(res, RESOLVE_ABILITY_ERR); + HILOG_INFO("AbilityManagerServiceSecondTest GenerateEmbeddableUIAbilityRequest_001 end"); +} + +/* + * Feature: AbilityManagerService + * Function: GenerateEmbeddableUIAbilityRequest + * SubFunction: NA + * FunctionPoints: AbilityManagerService GenerateEmbeddableUIAbilityRequest + */ +HWTEST_F(AbilityManagerServiceFirstTest, GenerateEmbeddableUIAbilityRequest_002, TestSize.Level1) +{ + HILOG_INFO("AbilityManagerServiceSecondTest GenerateEmbeddableUIAbilityRequest_002 start"); + auto abilityMs_ = std::make_shared(); + Want want; + AbilityRequest request; + auto res = abilityMs_->GenerateEmbeddableUIAbilityRequest(want, request, nullptr, USER_ID_U100); + EXPECT_EQ(res, RESOLVE_ABILITY_ERR); + HILOG_INFO("AbilityManagerServiceSecondTest GenerateEmbeddableUIAbilityRequest_002 end"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 2a61b1958b..27f107f36b 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -53,9 +53,12 @@ ohos_unittest("ability_manager_service_second_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 5fcafc5f2d..6fe59751fe 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -53,9 +53,12 @@ ohos_unittest("ability_manager_service_third_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } diff --git a/test/unittest/ability_manager_stub_test/BUILD.gn b/test/unittest/ability_manager_stub_test/BUILD.gn index 333963a7b4..2b138e56a5 100644 --- a/test/unittest/ability_manager_stub_test/BUILD.gn +++ b/test/unittest/ability_manager_stub_test/BUILD.gn @@ -20,10 +20,11 @@ ohos_unittest("ability_manager_stub_test") { module_out_path = module_output_path include_dirs = [ + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", "${distributedschedule_path}/samgr/utils/native/include/", - "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", ] sources = [ diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index 069ce5c9e7..67c1755208 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -14,9 +14,10 @@ */ #include -#include "iremote_proxy.h" #include "ability_manager_stub_impl_mock.h" #include "ability_scheduler.h" +#include "app_debug_listener_stub_mock.h" +#include "iremote_proxy.h" #include "mock_ability_connect_callback.h" #include "mock_ability_token.h" @@ -2456,6 +2457,130 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_IsAbilityControllerStartInne EXPECT_EQ(stub_->IsAbilityControllerStartInner(data, reply), NO_ERROR); } +/** + * @tc.name: AbilityManagerStub_RegisterAppDebugListenerInner_001 + * @tc.desc: Test the status of RegisterAppDebugListenerInner, check empty AppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterAppDebugListenerInner_001, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto res = stub_->RegisterAppDebugListenerInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/** + * @tc.name: AbilityManagerStub_RegisterAppDebugListenerInner_002 + * @tc.desc: Test the status of RegisterAppDebugListenerInner. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_RegisterAppDebugListenerInner_002, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto token = new AppExecFwk::AppDebugListenerStubMock(); + EXPECT_NE(token, nullptr); + auto ret = data.WriteRemoteObject(token); + EXPECT_EQ(ret, true); + int res = stub_->RegisterAppDebugListenerInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerStub_UnregisterAppDebugListenerInner_001 + * @tc.desc: Test the status of UnregisterAppDebugListenerInner, check empty appDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterAppDebugListenerInner_001, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto res = stub_->UnregisterAppDebugListenerInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/** + * @tc.name: AbilityManagerStub_UnregisterAppDebugListenerInner_002 + * @tc.desc: Test the status of UnregisterAppDebugListenerInner. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_UnregisterAppDebugListenerInner_002, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto token = new AppExecFwk::AppDebugListenerStubMock(); + EXPECT_NE(token, nullptr); + bool ret = data.WriteRemoteObject(token); + EXPECT_EQ(ret, true); + auto res = stub_->UnregisterAppDebugListenerInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerStub_AttachAppDebugInner_001 + * @tc.desc: Test the state of AttachAppDebugInner. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AttachAppDebugInner_001, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + std::string bundleName = "bundleName"; + data.WriteString(bundleName); + auto res = stub_->AttachAppDebugInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerStub_AttachAppDebugInner_002 + * @tc.desc: Test the state of AttachAppDebugInner, check empty bundleName; + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_AttachAppDebugInner_002, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto res = stub_->AttachAppDebugInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/** + * @tc.name: AbilityManagerStub_DetachAppDebugInner_001 + * @tc.desc: Test the state of DetachAppDebugInner. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_DetachAppDebugInner_001, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + std::string bundleName = "bundleName"; + data.WriteString(bundleName); + auto res = stub_->DetachAppDebugInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/** + * @tc.name: AbilityManagerStub_DetachAppDebugInner_002 + * @tc.desc: Test the state of DetachAppDebugInner, check empty bundleName. + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_DetachAppDebugInner_002, TestSize.Level1) +{ + EXPECT_NE(stub_, nullptr); + MessageParcel data; + MessageParcel reply; + auto res = stub_->DetachAppDebugInner(data, reply); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + /** * @tc.name: AbilityManagerStub_GetForegroundUIAbilitiesInner_001 * @tc.desc: Test function GetForegroundUIAbilitiesInner when normally. diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index eba0c91f5a..732043e2b1 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -2553,5 +2553,31 @@ HWTEST_F(AbilityRecordTest, NotifyTerminateMission_001, TestSize.Level1) abilityRecord_->collaboratorType_ = 1; abilityRecord_->SetAbilityStateInner(AbilityState::TERMINATING); } + +/** + * @tc.name: AbilityRecord_SetAttachDebug_001 + * @tc.desc: Test the correct value status of SetAttachDebug + * @tc.type: FUNC + */ +HWTEST_F(AbilityRecordTest, AbilityRecord_SetAttachDebug_001, TestSize.Level1) +{ + EXPECT_NE(abilityRecord_, nullptr); + bool isAttachDebug = true; + abilityRecord_->SetAttachDebug(isAttachDebug); + EXPECT_EQ(abilityRecord_->isAttachDebug_, true); +} + +/** + * @tc.name: AbilityRecord_SetAttachDebug_002 + * @tc.desc: Test the error value status of SetAttachDebug + * @tc.type: FUNC + */ +HWTEST_F(AbilityRecordTest, AbilityRecord_SetAttachDebug_002, TestSize.Level1) +{ + EXPECT_NE(abilityRecord_, nullptr); + bool isAttachDebug = false; + abilityRecord_->SetAttachDebug(isAttachDebug); + EXPECT_EQ(abilityRecord_->isAttachDebug_, false); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h b/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h index a33b173f45..01de3f9891 100644 --- a/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h +++ b/test/unittest/ability_scheduler_stub_test/ability_schedule_stub_mock.h @@ -157,6 +157,7 @@ public: { return 0; } + virtual void UpdateSessionToken(sptr sessionToken) override {} #ifdef ABILITY_COMMAND_FOR_TEST int BlockAbility() override { diff --git a/test/unittest/ability_service_extension_test/BUILD.gn b/test/unittest/ability_service_extension_test/BUILD.gn index c4611164b5..65789f67b0 100644 --- a/test/unittest/ability_service_extension_test/BUILD.gn +++ b/test/unittest/ability_service_extension_test/BUILD.gn @@ -20,6 +20,7 @@ ohos_unittest("ability_service_extension_test") { include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_native_path}/runtime", @@ -44,6 +45,7 @@ ohos_unittest("ability_service_extension_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:service_extension", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", @@ -57,12 +59,14 @@ ohos_unittest("ability_service_extension_test") { "ability_runtime:abilitykit_native", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", + "samgr:samgr_proxy", ] if (ability_runtime_graphics) { diff --git a/test/unittest/ability_timeout_test/BUILD.gn b/test/unittest/ability_timeout_test/BUILD.gn index 08907cd060..2c8f03851f 100644 --- a/test/unittest/ability_timeout_test/BUILD.gn +++ b/test/unittest/ability_timeout_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("ability_timeout_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { @@ -50,7 +49,10 @@ ohos_unittest("ability_timeout_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 5fe72fce6d..09b0001581 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -74,8 +74,11 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp b/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp index a4424828a8..c51626f94c 100644 --- a/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp +++ b/test/unittest/ams_ability_running_record_test/ams_ability_running_record_test.cpp @@ -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 @@ -485,7 +485,7 @@ HWTEST_F(AmsAbilityRunningRecordTest, UpdateAbilityRunningRecord_007, TestSize.L appRunningRecord->SetState(ApplicationState::APP_STATE_BACKGROUND); abilityRunningRecord->SetState(AbilityState::ABILITY_STATE_BACKGROUND); - EXPECT_CALL(*mockedAppClient_, ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*mockedAppClient_, ScheduleTerminateApplication(_)).Times(1); EXPECT_CALL(*mockedAppClient_, ScheduleCleanAbility(_)).Times(2); auto abilities = appRunningRecord->GetAbilities(); for (auto iter = abilities.begin(); iter != abilities.end(); iter++) { diff --git a/test/unittest/ams_app_death_recipient_test/BUILD.gn b/test/unittest/ams_app_death_recipient_test/BUILD.gn index 5e462c6a49..7bf4b66e46 100644 --- a/test/unittest/ams_app_death_recipient_test/BUILD.gn +++ b/test/unittest/ams_app_death_recipient_test/BUILD.gn @@ -65,8 +65,11 @@ ohos_unittest("AppDeathRecipientTest") { "hitrace:hitrace_meter", "init:libbeget_proxy", "ipc:ipc_core", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp b/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp index 56df2bd399..92a3146e75 100644 --- a/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp +++ b/test/unittest/ams_app_life_cycle_test/ams_app_life_cycle_test.cpp @@ -1020,7 +1020,7 @@ HWTEST_F(AmsAppLifeCycleTest, Schedule_043, TestSize.Level1) testAppRecord.appRecord_->LaunchPendingAbilities(); EXPECT_CALL(*(testAppRecord.mockAppScheduler_), ScheduleCleanAbility(_)).Times(1); serviceInner_->TerminateAbility(GetMockToken()); - EXPECT_CALL(*(testAppRecord.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(testAppRecord.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->AbilityTerminated(GetMockToken()); auto abilityRecord = testAppRecord.appRecord_->GetAbilityRunningRecordByToken(GetMockToken()); EXPECT_EQ(nullptr, abilityRecord); diff --git a/test/unittest/ams_app_mgr_client_test/BUILD.gn b/test/unittest/ams_app_mgr_client_test/BUILD.gn index cb89ac4660..35e389135d 100644 --- a/test/unittest/ams_app_mgr_client_test/BUILD.gn +++ b/test/unittest/ams_app_mgr_client_test/BUILD.gn @@ -58,8 +58,11 @@ ohos_unittest("AmsAppMgrClientTest") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_app_running_record_test/BUILD.gn b/test/unittest/ams_app_running_record_test/BUILD.gn index 0c95d24ba2..ca5686f886 100644 --- a/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/test/unittest/ams_app_running_record_test/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("AmsAppRunningRecordTest") { "${ability_runtime_services_path}/appmgr:libappms", "${ability_runtime_services_path}/common:task_handler_wrap", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${windowmanager_path}/utils:libwmutil_static", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -58,8 +59,11 @@ ohos_unittest("AmsAppRunningRecordTest") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index 31fce8b2ff..74f88d85c0 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -44,6 +44,7 @@ #include "mock_system_ability_manager.h" #include "refbase.h" #include "ui_extension_utils.h" +#include "window_visibility_info.h" using namespace testing::ext; using testing::_; @@ -615,7 +616,7 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbility_002, TestSize.Level1) HWTEST_F(AmsAppRunningRecordTest, ScheduleTerminate_001, TestSize.Level1) { auto record = GetTestAppRunningRecord(); - EXPECT_CALL(*mockAppSchedulerClient_, ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*mockAppSchedulerClient_, ScheduleTerminateApplication(_)).Times(1); record->ScheduleTerminate(); record->appLifeCycleDeal_ = nullptr; @@ -1307,7 +1308,7 @@ HWTEST_F(AmsAppRunningRecordTest, AbilityTerminated_001, TestSize.Level1) HILOG_INFO("AmsAppRunningRecordTest AbilityTerminated_001 start"); auto record = GetTestAppRunningRecord(); - EXPECT_CALL(*mockAppSchedulerClient_, ScheduleTerminateApplication()).Times(0); + EXPECT_CALL(*mockAppSchedulerClient_, ScheduleTerminateApplication(_)).Times(0); record->AbilityTerminated(nullptr); HILOG_INFO("AmsAppRunningRecordTest AbilityTerminated_001 end"); @@ -2970,5 +2971,132 @@ HWTEST_F(AmsAppRunningRecordTest, ChangeAppGcState_002, TestSize.Level1) EXPECT_EQ(ERR_INVALID_VALUE, record->ChangeAppGcState(0)); HILOG_DEBUG("ChangeAppGcState_002 end."); } + +/** + * @tc.name: IsAbilitiesBackgrounded_001 + * @tc.desc: verify that ModuleRunningRecord correctly judges Abilitiesbackground + * @tc.type: FUNC + */ +HWTEST_F(AmsAppRunningRecordTest, IsAbilitiesBackgrounded_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IsAbilitiesBackgrounded_001 start."; + + // 1. create AppInfo and AbilityInfo + std::shared_ptr appInfo = std::make_shared(); + EXPECT_NE(appInfo, nullptr); + appInfo->name = GetTestAppName(); + appInfo->bundleName = GetTestAppName(); + + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = GetTestAbilityName(); + abilityInfo->type = AbilityType::PAGE; + + // 2. create ModuleRunningRecord + std::shared_ptr moduleRecord = std::make_shared(appInfo, nullptr);; + EXPECT_NE(moduleRecord, nullptr); + + // 3. create AbilityRecord with AbilityInfo, add the record into ModuleRunningRecord + auto abilityRecord = std::make_shared(abilityInfo, GetMockToken()); + EXPECT_NE(abilityRecord, nullptr); + moduleRecord->abilities_.emplace(GetMockToken(), abilityRecord); + + // 4. verify function + EXPECT_EQ(abilityRecord->state_, AbilityState::ABILITY_STATE_CREATE); + EXPECT_FALSE(moduleRecord->IsAbilitiesBackgrounded()); + + moduleRecord->abilities_.clear(); + abilityRecord->state_ = AbilityState::ABILITY_STATE_BACKGROUND; + moduleRecord->abilities_.emplace(GetMockToken(), abilityRecord); + EXPECT_TRUE(moduleRecord->IsAbilitiesBackgrounded()); + GTEST_LOG_(INFO) << "IsAbilitiesBackgrounded_001 end."; +} + +/** + * @tc.name: IsAbilitytiesBackground_001 + * @tc.desc: verify that AppRunningRecord correctly judges Abilitytiesbackground + * @tc.type: FUNC + */ +HWTEST_F(AmsAppRunningRecordTest, IsAbilitytiesBackground_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IsAbilitytiesBackground_001 start."; + // 1. create AppRunningRecord and verify default status + auto record = GetTestAppRunningRecord(); + EXPECT_NE(record, nullptr); + EXPECT_TRUE(record->IsAbilitytiesBackground()); + + // 2. create AbilityInfo and AppInfo, and construct ModuleRunningRecord + std::shared_ptr appInfo = std::make_shared(); + EXPECT_NE(appInfo, nullptr); + appInfo->name = GetTestAppName(); + appInfo->bundleName = GetTestAppName(); + auto abilityInfo = std::make_shared(); + EXPECT_NE(abilityInfo, nullptr); + abilityInfo->name = GetTestAbilityName(); + abilityInfo->type = AbilityType::PAGE; + auto abilityRecord = std::make_shared(abilityInfo, GetMockToken()); + EXPECT_NE(abilityRecord, nullptr); + + std::shared_ptr moduleRecord = std::make_shared(appInfo, nullptr);; + EXPECT_NE(moduleRecord, nullptr); + moduleRecord->abilities_.emplace(GetMockToken(), abilityRecord); + std::vector> moduleRecords; + moduleRecords.push_back(moduleRecord); + const std::string bundleName = "bundleName"; + + // 3. add ModuleRunningRecord into hapModules_ of AppRunningRecord + record->hapModules_.emplace(bundleName, moduleRecords); + + // 4. verify function + EXPECT_FALSE(record->IsAbilitytiesBackground()); + + moduleRecord->abilities_.clear(); + abilityRecord->state_ = AbilityState::ABILITY_STATE_BACKGROUND; + moduleRecord->abilities_.emplace(GetMockToken(), abilityRecord); + moduleRecords.clear(); + moduleRecords.push_back(moduleRecord); + record->hapModules_.emplace(bundleName, moduleRecords); + EXPECT_TRUE(record->IsAbilitytiesBackground()); + GTEST_LOG_(INFO) << "IsAbilitytiesBackground_001 end."; +} + +/** + * @tc.name: AppRunningRecord_OnWindowVisibilityChanged_001 + * @tc.desc: verify that AppRunningRecord correctly handle window visibility change event + * @tc.type: FUNC + */ +HWTEST_F(AmsAppRunningRecordTest, OnWindowVisibilityChanged_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "OnWindowVisibilityChanged_001 start."; + // 1. create AppRunningRecord, set state and windowIds_ + auto record = GetTestAppRunningRecord(); + EXPECT_NE(record, nullptr); + uint32_t windowId = 123456; + record->windowIds_.insert(windowId); + record->curState_ = ApplicationState::APP_STATE_FOREGROUND; + + // 2. construct WindowVisibilityInfos + std::vector> windowVisibilityInfos; + auto info = new (std::nothrow) Rosen::WindowVisibilityInfo(); + EXPECT_NE(info, nullptr); + info->visibilityState_ = Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION; + info->windowId_ = windowId; + windowVisibilityInfos.emplace_back(info); + + //3. verify function + record->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_TRUE(record->isUpdateStateFromService_); + EXPECT_TRUE(record->windowIds_.empty()); + + info->visibilityState_ = Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION; + windowVisibilityInfos.clear(); + windowVisibilityInfos.emplace_back(info); + record->isUpdateStateFromService_ = false; + record->curState_ = ApplicationState::APP_STATE_BACKGROUND; + record->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_FALSE(record->windowIds_.empty()); + EXPECT_TRUE(record->isUpdateStateFromService_); + GTEST_LOG_(INFO) << "OnWindowVisibilityChanged_001 end."; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index ee953c6fd9..5b977f5f24 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -71,9 +71,14 @@ ohos_unittest("AmsWorkFlowTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", - "window_manager:libwsutils", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("unittest") { diff --git a/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp b/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp index ee8e1c5fa1..916dcdfaab 100644 --- a/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp +++ b/test/unittest/ams_app_workflow_test/ams_workflow_test.cpp @@ -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 @@ -327,7 +327,7 @@ HWTEST_F(AmsWorkFlowTest, BackKey_005, TestSize.Level1) EXPECT_CALL(*(appB.mockAppScheduler_), ScheduleForegroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(1); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenB, AbilityState::ABILITY_STATE_FOREGROUND); appB.appRecord_->SetUpdateStateFromService(true); @@ -370,7 +370,7 @@ HWTEST_F(AmsWorkFlowTest, BackKey_006, TestSize.Level1) EXPECT_CALL(*(appC.mockAppScheduler_), ScheduleForegroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(2); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(2); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenC, AbilityState::ABILITY_STATE_FOREGROUND); appC.appRecord_->SetUpdateStateFromService(true); @@ -421,7 +421,7 @@ HWTEST_F(AmsWorkFlowTest, BackKey_007, TestSize.Level1) EXPECT_CALL(*(appC.mockAppScheduler_), ScheduleForegroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(2); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(2); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenC, AbilityState::ABILITY_STATE_FOREGROUND); appC.appRecord_->SetUpdateStateFromService(true); @@ -543,7 +543,7 @@ HWTEST_F(AmsWorkFlowTest, ScreenOff_004, TestSize.Level1) appA.appRecord_->LaunchPendingAbilities(); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(1); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenA, AbilityState::ABILITY_STATE_BACKGROUND); appA.appRecord_->SetUpdateStateFromService(true); @@ -576,7 +576,7 @@ HWTEST_F(AmsWorkFlowTest, ScreenOff_005, TestSize.Level1) "B", tokenB, "A", AbilityState::ABILITY_STATE_FOREGROUND, ApplicationState::APP_STATE_FOREGROUND); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(2); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(2); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenA, AbilityState::ABILITY_STATE_BACKGROUND); serviceInner_->UpdateAbilityState(tokenB, AbilityState::ABILITY_STATE_BACKGROUND); @@ -614,7 +614,7 @@ HWTEST_F(AmsWorkFlowTest, ScreenOff_006, TestSize.Level1) "B", tokenB, "A", AbilityState::ABILITY_STATE_BACKGROUND, ApplicationState::APP_STATE_FOREGROUND); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(1); EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleCleanAbility(_)).Times(2); - EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication()).Times(1); + EXPECT_CALL(*(appA.mockAppScheduler_), ScheduleTerminateApplication(_)).Times(1); serviceInner_->UpdateAbilityState(tokenA, AbilityState::ABILITY_STATE_BACKGROUND); appA.appRecord_->SetUpdateStateFromService(true); diff --git a/test/unittest/ams_ipc_interface_test/ams_ipc_appscheduler_interface_test.cpp b/test/unittest/ams_ipc_interface_test/ams_ipc_appscheduler_interface_test.cpp index 836ffb4070..e0dfc43850 100644 --- a/test/unittest/ams_ipc_interface_test/ams_ipc_appscheduler_interface_test.cpp +++ b/test/unittest/ams_ipc_interface_test/ams_ipc_appscheduler_interface_test.cpp @@ -115,7 +115,7 @@ HWTEST_F(AmsIpcAppSchedulerInterfaceTest, Interface_003, TestSize.Level1) sptr mockApplication(new MockApplication()); sptr client = iface_cast(mockApplication); - EXPECT_CALL(*mockApplication, ScheduleTerminateApplication()) + EXPECT_CALL(*mockApplication, ScheduleTerminateApplication(_)) .Times(1) .WillOnce(InvokeWithoutArgs(mockApplication.GetRefPtr(), &MockApplication::Post)); client->ScheduleTerminateApplication(); diff --git a/test/unittest/ams_mgr_proxy_test/BUILD.gn b/test/unittest/ams_mgr_proxy_test/BUILD.gn index b5d57d1e4d..eeab9af11d 100644 --- a/test/unittest/ams_mgr_proxy_test/BUILD.gn +++ b/test/unittest/ams_mgr_proxy_test/BUILD.gn @@ -50,8 +50,11 @@ ohos_unittest("AmsMgrProxyTest") { "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn b/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn index fdd89ddb07..bf26300775 100644 --- a/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn +++ b/test/unittest/ams_mgr_scheduler_dump_test/BUILD.gn @@ -42,8 +42,11 @@ ohos_unittest("ams_mgr_scheduler_dump_test") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index 545d920d1a..e7afdd9734 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -850,5 +850,100 @@ HWTEST_F(AmsMgrSchedulerTest, SetCurrentUserId_001, TestSize.Level0) int userId = 1; amsMgrScheduler->SetCurrentUserId(userId); } + +/** + * @tc.name: RegisterAppDebugListener_001 + * @tc.desc: Test the state of RegisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerTest, RegisterAppDebugListener_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + EXPECT_NE(amsMgrScheduler, nullptr); + sptr listener = nullptr; + int32_t res = amsMgrScheduler->RegisterAppDebugListener(listener); + EXPECT_EQ(res, ERR_INVALID_OPERATION); + + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); + res = amsMgrScheduler->RegisterAppDebugListener(listener); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: UnregisterAppDebugListener_001 + * @tc.desc: Test the state of UnregisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerTest, UnregisterAppDebugListener_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + EXPECT_NE(amsMgrScheduler, nullptr); + sptr listener = nullptr; + int32_t res = amsMgrScheduler->UnregisterAppDebugListener(listener); + EXPECT_EQ(res, ERR_INVALID_OPERATION); + + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); + res = amsMgrScheduler->UnregisterAppDebugListener(listener); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: AttachAppDebug_001 + * @tc.desc: Test the state of AttachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerTest, AttachAppDebug_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + EXPECT_NE(amsMgrScheduler, nullptr); + std::string bundleName = ""; + int32_t res = amsMgrScheduler->AttachAppDebug(bundleName); + EXPECT_EQ(res, ERR_INVALID_OPERATION); + + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); + res = amsMgrScheduler->AttachAppDebug(bundleName); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: DetachAppDebug_001 + * @tc.desc: Test the state of DetachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerTest, DetachAppDebug_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + EXPECT_NE(amsMgrScheduler, nullptr); + std::string bundleName = ""; + int32_t res = amsMgrScheduler->DetachAppDebug(bundleName); + EXPECT_EQ(res, ERR_INVALID_OPERATION); + + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); + res = amsMgrScheduler->DetachAppDebug(bundleName); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/** + * @tc.name: RegisterAbilityDebugResponse_001 + * @tc.desc: Test the state of RegisterAbilityDebugResponse + * @tc.type: FUNC + */ +HWTEST_F(AmsMgrSchedulerTest, RegisterAbilityDebugResponse_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + EXPECT_NE(amsMgrScheduler, nullptr); + sptr response = nullptr; + int32_t res = amsMgrScheduler->RegisterAbilityDebugResponse(response); + EXPECT_EQ(res, ERR_INVALID_OPERATION); + + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsTaskHandler(); + res = amsMgrScheduler->RegisterAbilityDebugResponse(response); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/ams_mgr_stub_test/BUILD.gn b/test/unittest/ams_mgr_stub_test/BUILD.gn index d619291541..552c03a8ce 100644 --- a/test/unittest/ams_mgr_stub_test/BUILD.gn +++ b/test/unittest/ams_mgr_stub_test/BUILD.gn @@ -48,8 +48,11 @@ ohos_unittest("AmsMgrStubTest") { "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index edf9d5e2fa..2344db00c0 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -84,9 +84,14 @@ ohos_unittest("AmsRecentAppListTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", - "window_manager:libwsutils", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("unittest") { diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 7ec918e071..2dcd82ac9f 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -80,9 +80,12 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + subsystem_name = "ability" part_name = "ability_runtime" } diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index 327c5a124e..8011c6290e 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -85,8 +85,11 @@ ohos_unittest("AmsServiceEventDriveTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 87acfd93d3..15d52a5b9b 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -86,9 +86,14 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", - "window_manager:libwsutils", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("unittest") { diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 44fddf9d01..8860b47ef0 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -80,8 +80,11 @@ ohos_unittest("AmsServiceStartupTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_debug_listener_stub_test/BUILD.gn b/test/unittest/app_debug_listener_stub_test/BUILD.gn index 37f8b31313..6d380a0210 100644 --- a/test/unittest/app_debug_listener_stub_test/BUILD.gn +++ b/test/unittest/app_debug_listener_stub_test/BUILD.gn @@ -40,8 +40,11 @@ ohos_unittest("AppDebugListenerStubTest") { "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_debug_manager_test/BUILD.gn b/test/unittest/app_debug_manager_test/BUILD.gn new file mode 100644 index 0000000000..fc59c8df7b --- /dev/null +++ b/test/unittest/app_debug_manager_test/BUILD.gn @@ -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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("app_debug_manager_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_test_path}/unittest/app_debug_listener_stub_test", + ] + + sources = [ + "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", + "app_debug_manager_test.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "appspawn:appspawn_socket_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":app_debug_manager_test" ] +} diff --git a/test/unittest/app_debug_manager_test/app_debug_manager_test.cpp b/test/unittest/app_debug_manager_test/app_debug_manager_test.cpp new file mode 100644 index 0000000000..e938ac5885 --- /dev/null +++ b/test/unittest/app_debug_manager_test/app_debug_manager_test.cpp @@ -0,0 +1,240 @@ +/* + * 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 + +#define private public +#include "app_debug_manager.h" +#include "app_debug_listener_proxy.h" +#undef private + +#include "mock_app_debug_listener_stub.h" +#include "parcel.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS { +namespace AppExecFwk { +namespace { + std::string DEBUG_START_NAME = "debugStartBundle"; + std::string NO_DEBUG_START_NAME = "noDebugStartBundle"; + const bool IS_DEBUG_START = true; + const bool NO_DEBUG_START = false; + const unsigned int SIZE_ONE = 1; + const unsigned int SIZE_TWO = 2; +} +class AppDebugManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr manager_; + sptr listener_; +}; + +void AppDebugManagerTest::SetUpTestCase(void) +{} + +void AppDebugManagerTest::TearDownTestCase(void) +{} + +void AppDebugManagerTest::SetUp() +{ + manager_ = std::make_shared(); + listener_ = new MockAppDebugListenerStub(); + manager_->listeners_.insert(listener_); +} + +void AppDebugManagerTest::TearDown() +{} + +/** + * @tc.name: RegisterAppDebugListener_0100 + * @tc.desc: Register listener for app debug listener, check nullptr listener. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, RegisterAppDebugListener_0100, TestSize.Level1) +{ + sptr listener = new MockAppDebugListenerStub(); + AppDebugInfo appDebugInfo; + manager_->debugInfos_.push_back(appDebugInfo); + + EXPECT_CALL(*listener, OnAppDebugStarted(_)).Times(1); + auto result = manager_->RegisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_OK); + EXPECT_EQ(manager_->listeners_.size(), SIZE_TWO); + + listener = nullptr; + result = manager_->RegisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_INVALID_DATA); + EXPECT_EQ(manager_->listeners_.size(), SIZE_TWO); +} + +/** + * @tc.name: UnregisterAppDebugListener_0100 + * @tc.desc: Unregister listener for app debug listener, check nullptr listener. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, UnregisterAppDebugListener_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + sptr listener = nullptr; + auto result = manager_->UnregisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_INVALID_DATA); + EXPECT_EQ(manager_->listeners_.size(), SIZE_ONE); + + EXPECT_NE(listener_, nullptr); + result = manager_->UnregisterAppDebugListener(listener_); + EXPECT_EQ(result, ERR_OK); + EXPECT_TRUE(manager_->listeners_.empty()); +} + +/** + * @tc.name: StartDebug_0100 + * @tc.desc: Start debug by AppDebugInfo, notify AppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, StartDebug_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + EXPECT_TRUE(manager_->debugInfos_.empty()); + std::vector debugInfos; + AppDebugInfo info; + debugInfos.push_back(info); + + EXPECT_NE(listener_, nullptr); + EXPECT_CALL(*listener_, OnAppDebugStarted(_)).Times(1); + manager_->StartDebug(debugInfos); + EXPECT_FALSE(manager_->debugInfos_.empty()); +} + +/** + * @tc.name: StopDebug_0100 + * @tc.desc: Start debug by AppDebugInfo, notify AppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, StopDebug_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + EXPECT_TRUE(manager_->debugInfos_.empty()); + std::vector debugInfos; + AppDebugInfo info; + info.bundleName = DEBUG_START_NAME; + info.isDebugStart = IS_DEBUG_START; + info.pid = 10; + info.uid = 12345; + debugInfos.push_back(info); + manager_->debugInfos_ = debugInfos; + + EXPECT_NE(listener_, nullptr); + EXPECT_CALL(*listener_, OnAppDebugStoped(_)).Times(1); + manager_->StopDebug(debugInfos); + EXPECT_TRUE(manager_->debugInfos_.empty()); +} + +/** + * @tc.name: IsAttachDebug_0100 + * @tc.desc: Given the bundleName, return true if not DebugStart, otherwise return false. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, IsAttachDebug_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + AppDebugInfo debugStart_info; + debugStart_info.bundleName = DEBUG_START_NAME; + debugStart_info.isDebugStart = IS_DEBUG_START; + manager_->debugInfos_.push_back(debugStart_info); + + AppDebugInfo noDebugStart_info; + noDebugStart_info.bundleName = NO_DEBUG_START_NAME; + noDebugStart_info.isDebugStart = NO_DEBUG_START; + manager_->debugInfos_.push_back(noDebugStart_info); + + auto result = manager_->IsAttachDebug(DEBUG_START_NAME); + EXPECT_FALSE(result); + + result = manager_->IsAttachDebug(NO_DEBUG_START_NAME); + EXPECT_TRUE(result); +} + +/** + * @tc.name: GetIncrementAppDebugInfo_0100 + * @tc.desc: Add new debug info into debugInfos, or update the isDebugStart flag. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, GetIncrementAppDebugInfo_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + EXPECT_TRUE(manager_->debugInfos_.empty()); + + std::vector debugInfos; + std::vector increment; + AppDebugInfo debugStart_info; + debugStart_info.bundleName = DEBUG_START_NAME; + debugStart_info.isDebugStart = IS_DEBUG_START; + + int pid = 10; + int uid = 12345; + AppDebugInfo noDebugStart_info; + noDebugStart_info.bundleName = NO_DEBUG_START_NAME; + noDebugStart_info.isDebugStart = NO_DEBUG_START; + noDebugStart_info.pid = pid; + noDebugStart_info.pid = uid; + debugInfos.push_back(debugStart_info); + debugInfos.push_back(noDebugStart_info); + + manager_->GetIncrementAppDebugInfos(debugInfos, increment); + EXPECT_EQ(manager_->debugInfos_.size(), SIZE_TWO); + + increment.clear(); + debugInfos.clear(); + noDebugStart_info.isDebugStart = IS_DEBUG_START; + debugInfos.push_back(noDebugStart_info); + + manager_->GetIncrementAppDebugInfos(debugInfos, increment); + EXPECT_EQ(manager_->debugInfos_.size(), SIZE_TWO); + EXPECT_TRUE(manager_->debugInfos_.at(1).isDebugStart); +} + +/** + * @tc.name: RemoveAppDebugInfo_0100 + * @tc.desc: Remove app debug info with bundleName, pid, uid and isDebugStart flag. + * @tc.type: FUNC + */ +HWTEST_F(AppDebugManagerTest, RemoveAppDebugInfo_0100, TestSize.Level1) +{ + EXPECT_NE(manager_, nullptr); + EXPECT_TRUE(manager_->debugInfos_.empty()); + + std::vector debugInfos; + int pid = 10; + int uid = 12345; + AppDebugInfo debugInfo; + debugInfo.bundleName = DEBUG_START_NAME; + debugInfo.pid = pid; + debugInfo.uid = uid; + debugInfo.isDebugStart = IS_DEBUG_START; + + manager_->debugInfos_.push_back(debugInfo); + EXPECT_EQ(manager_->debugInfos_.size(), SIZE_ONE); + + EXPECT_CALL(*listener_, OnAppDebugStoped(_)).Times(1); + manager_->RemoveAppDebugInfo(debugInfo); + EXPECT_TRUE(manager_->debugInfos_.empty()); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_mgr_proxy_test/BUILD.gn b/test/unittest/app_mgr_proxy_test/BUILD.gn index a5c8cbc091..334ed7c375 100644 --- a/test/unittest/app_mgr_proxy_test/BUILD.gn +++ b/test/unittest/app_mgr_proxy_test/BUILD.gn @@ -21,8 +21,10 @@ ohos_unittest("AppMgrProxyTest") { configs = [ "${ability_runtime_services_path}/common:common_config" ] - include_dirs = - [ "${ability_runtime_test_path}/mock/services_appmgr_test/include" ] + include_dirs = [ + "${ability_runtime_test_path}/mock/services_appmgr_test/include", + "${ability_runtime_test_path}/unittest/ability_foreground_state_observer_proxy_test", + ] sources = [ "app_mgr_proxy_test.cpp" ] diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 37be99f0ef..3cd9649dce 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -15,10 +15,12 @@ #include -#include "mock_app_mgr_service.h" +#include "ability_foreground_state_observer_interface.h" #include "app_mgr_proxy.h" #include "hilog_wrapper.h" #include "quick_fix_callback_stub.h" +#include "mock_ability_foreground_state_observer_stub.h" +#include "mock_app_mgr_service.h" using namespace testing; using namespace testing::ext; @@ -344,5 +346,63 @@ HWTEST_F(AppMgrProxyTest, IsApplicationRunning_001, TestSize.Level1) appMgrProxy_->IsApplicationRunning(bundleName, isRunning); EXPECT_EQ(mockAppMgrService_->code_, static_cast(AppMgrInterfaceCode::IS_APPLICATION_RUNNING)); } -} // namespace AppExecFwk -} // namespace OHOS + +/** + * @tc.number: RegisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify that the RegisterAbilityForegroundStateObserver function is called normally. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + sptr observer = new MockAbilityForegroundStateObserverStub(); + EXPECT_NE(observer->AsObject(), nullptr); + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + appMgrProxy_->RegisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(mockAppMgrService_->code_, + static_cast(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER)); +} + +/** + * @tc.number: RegisterAbilityForegroundStateObserver_0200 + * @tc.desc: Verify that the RegisterAbilityForegroundStateObserver parameter of the function is null. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, RegisterAbilityForegroundStateObserver_0200, TestSize.Level1) +{ + sptr observer = nullptr; + auto result = appMgrProxy_->RegisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); +} + +/** + * @tc.number: UnregisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify that the UnregisterAbilityForegroundStateObserver function is called normally. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + sptr observer = new MockAbilityForegroundStateObserverStub(); + EXPECT_NE(observer->AsObject(), nullptr); + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + appMgrProxy_->UnregisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(mockAppMgrService_->code_, + static_cast(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER)); +} + +/** + * @tc.number: RegisterAbilityForegroundStateObserver_0200 + * @tc.desc: Verify that the UnregisterAbilityForegroundStateObserver parameter of the function is null. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, UnregisterAbilityForegroundStateObserver_0200, TestSize.Level1) +{ + sptr observer = nullptr; + auto result = appMgrProxy_->UnregisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_mgr_service_dump_test/BUILD.gn b/test/unittest/app_mgr_service_dump_test/BUILD.gn index 7f348021bd..66888f6a82 100644 --- a/test/unittest/app_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/app_mgr_service_dump_test/BUILD.gn @@ -47,8 +47,11 @@ ohos_unittest("app_mgr_service_dump_test") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index acc8a596dd..2e4eb1fa8b 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -80,9 +80,14 @@ ohos_unittest("AMSEventHandlerTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", - "window_manager:libwsutils", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn index 4ab595d82e..16899b4cb1 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_tdd_test/BUILD.gn @@ -57,13 +57,16 @@ ohos_unittest("app_mgr_service_inner_tdd_test") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] defines = [] if (background_task_mgr_continuous_task_enable) { defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_service_inner_test/BUILD.gn b/test/unittest/app_mgr_service_inner_test/BUILD.gn index 78fe7b2626..224485d723 100644 --- a/test/unittest/app_mgr_service_inner_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_test/BUILD.gn @@ -57,9 +57,12 @@ ohos_unittest("AppMgrServiceInnerTest") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } + defines = [] if (background_task_mgr_continuous_task_enable) { defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index abcbdb8973..340659bfee 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -39,6 +39,11 @@ using namespace testing::ext; namespace OHOS { namespace AppExecFwk { +namespace { +constexpr int32_t RECORD_ID = 1; +constexpr int32_t APP_DEBUG_INFO_PID = 0; +constexpr int32_t APP_DEBUG_INFO_UID = 0; +} static int recordId_ = 0; class AppMgrServiceInnerTest : public testing::Test { public: @@ -3506,6 +3511,180 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppFaultBySA_001, TestSize.Level1) HILOG_INFO("NotifyAppFaultBySA_001 end"); } +/** + * @tc.name: RegisterAppDebugListener_001 + * @tc.desc: Test the status of RegisterAppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, RegisterAppDebugListener_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + sptr listener = nullptr; + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->RegisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_INVALID_DATA); + appMgrServiceInner->appDebugManager_ = nullptr; + result = appMgrServiceInner->RegisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_NO_INIT); +} + +/** + * @tc.name: UnregisterAppDebugListener_001 + * @tc.desc: Test the status of UnregisterAppDebugListener. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, UnregisterAppDebugListener_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + sptr listener = nullptr; + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->UnregisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_INVALID_DATA); + appMgrServiceInner->appDebugManager_ = nullptr; + result = appMgrServiceInner->UnregisterAppDebugListener(listener); + EXPECT_EQ(result, ERR_NO_INIT); +} + +/** + * @tc.name: AttachAppDebug_001 + * @tc.desc: Test the status of AttachAppDebug. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + std::string bundleName; + appMgrServiceInner->appRunningManager_ = std::make_shared(); + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->AttachAppDebug(bundleName); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: AttachAppDebug_002 + * @tc.desc: Test the status of AttachAppDebug, check nullptr AppRunningManager. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, AttachAppDebug_002, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + std::string bundleName; + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->AttachAppDebug(bundleName); + EXPECT_EQ(result, ERR_NO_INIT); +} + +/** + * @tc.name: DetachAppDebug_001 + * @tc.desc: Test the status of DetachAppDebug. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + std::string bundleName; + appMgrServiceInner->appRunningManager_ = std::make_shared(); + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->DetachAppDebug(bundleName); + EXPECT_EQ(result, ERR_OK); +} + +/** + * @tc.name: DetachAppDebug_002 + * @tc.desc: Test the status of DetachAppDebug, check nullptr AppRunningManager. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, DetachAppDebug_002, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + std::string bundleName; + appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->DetachAppDebug(bundleName); + EXPECT_EQ(result, ERR_NO_INIT); +} + +/** + * @tc.name: RegisterAbilityDebugResponse_001 + * @tc.desc: Test the status of RegisterAbilityDebugResponse. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityDebugResponse_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + sptr response = nullptr; + auto result = appMgrServiceInner->RegisterAbilityDebugResponse(response); + EXPECT_EQ(result, ERR_INVALID_VALUE); +} + +/** + * @tc.name: NotifyAbilitysDebugChange_001 + * @tc.desc: Test the status of NotifyAbilitysDebugChange. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, NotifyAbilitysDebugChange_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + std::string bundleName; + bool isAppDebug = true; + appMgrServiceInner->appRunningManager_ = std::make_shared(); + appMgrServiceInner->appDebugManager_ = std::make_shared(); + auto result = appMgrServiceInner->NotifyAbilitysDebugChange(bundleName, isAppDebug); + EXPECT_EQ(result, ERR_NO_INIT); +} + +/** + * @tc.name: ProcessAppDebug_001 + * @tc.desc: Test the status of ProcessAppDebug. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, ProcessAppDebug_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + std::shared_ptr info = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName = "processName"; + std::shared_ptr appRecord = std::make_shared(info, recordId, processName); + bool isDebugStart = true; + appRecord->SetDebugApp(false); + appMgrServiceInner->ProcessAppDebug(appRecord, isDebugStart); + EXPECT_EQ(appRecord->IsDebugApp(), true); +} + +/** + * @tc.name: MakeAppDebugInfo_001 + * @tc.desc: Test the status of MakeAppDebugInfo. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, MakeAppDebugInfo_001, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + appMgrServiceInner->appRunningManager_ = std::make_shared(); + std::shared_ptr info = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName = "processName"; + std::shared_ptr appRecord = std::make_shared(info, recordId, processName); + bool isDebugStart = true; + appRecord->SetDebugApp(false); + auto appDebugInfo = appMgrServiceInner->MakeAppDebugInfo(appRecord, isDebugStart); + EXPECT_EQ(appDebugInfo.bundleName, ""); + EXPECT_EQ(appDebugInfo.pid, APP_DEBUG_INFO_PID); + EXPECT_EQ(appDebugInfo.uid, APP_DEBUG_INFO_UID); + EXPECT_EQ(appDebugInfo.isDebugStart, true); +} + /** * @tc.name: ChangeAppGcState_001 * @tc.desc: Change app Gc state @@ -3695,6 +3874,55 @@ HWTEST_F(AppMgrServiceInnerTest, IsMainProcess_001, TestSize.Level0) HILOG_INFO("IsMainProcess_001 end"); } +/** + * @tc.name: InitWindowVisibilityChangedListener_001 + * @tc.desc: init windowVisibilityChangedListener + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, InitWindowVisibilityChangedListener_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "InitWindowVisibilityChangedListener_001 start" ; + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->InitWindowVisibilityChangedListener(); + EXPECT_NE(appMgrServiceInner->windowVisibilityChangedListener_, nullptr); + GTEST_LOG_(INFO) << "InitWindowVisibilityChangedListener_001 end"; +} + +/** + * @tc.name: FreeWindowVisibilityChangedListener_001 + * @tc.desc: free windowVisibilityChangedListener + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, FreeWindowVisibilityChangedListener_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FreeWindowVisibilityChangedListener_001 start"; + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + appMgrServiceInner->FreeWindowVisibilityChangedListener(); + EXPECT_EQ(appMgrServiceInner->windowVisibilityChangedListener_, nullptr); + GTEST_LOG_(INFO) << "FreeWindowVisibilityChangedListener_001 end"; +} + +/** + * @tc.name: HandleWindowVisibilityChanged_001 + * @tc.desc: handle window visibility changed + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, HandleWindowVisibilityChanged_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HandleWindowVisibilityChanged_001 start"; + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::vector> visibilityInfos; + appMgrServiceInner->HandleWindowVisibilityChanged(visibilityInfos); + EXPECT_NE(appMgrServiceInner, nullptr); + GTEST_LOG_(INFO) << "HandleWindowVisibilityChanged_001 end"; +} + /** * @tc.name: IsApplicationRunning_001 * @tc.desc: Obtain application running status through bundleName. @@ -3735,5 +3963,31 @@ HWTEST_F(AppMgrServiceInnerTest, IsApplicationRunning_002, TestSize.Level1) EXPECT_EQ(ret, ERR_OK); EXPECT_FALSE(isRunning); } + +/** + * @tc.name: RegisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when observer is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + auto res = appMgrServiceInner->RegisterAbilityForegroundStateObserver(nullptr); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/** + * @tc.name: UnregisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when observer is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level0) +{ + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + auto res = appMgrServiceInner->UnregisterAbilityForegroundStateObserver(nullptr); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index c795f9238f..4c1e22186a 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -50,7 +50,6 @@ ohos_unittest("app_mgr_service_test") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] defines = [] @@ -61,6 +60,10 @@ ohos_unittest("app_mgr_service_test") { if (ability_command_for_test) { defines += [ "ABILITY_COMMAND_FOR_TEST" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index f8de2f16de..72423404b9 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1375,5 +1375,35 @@ HWTEST_F(AppMgrServiceTest, IsApplicationRunning_001, TestSize.Level1) int32_t res = appMgrService->IsApplicationRunning(bundleName, isRunning); EXPECT_EQ(res, ERR_OK); } + +/** + * @tc.name: RegisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when judgments is ready and observer is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + sptr appMgrService = new (std::nothrow) AppMgrService(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->RegisterAbilityForegroundStateObserver(nullptr); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/** + * @tc.name: UnregisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when judgments is ready and observer is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + sptr appMgrService = new (std::nothrow) AppMgrService(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = std::make_shared(taskHandler_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->UnregisterAbilityForegroundStateObserver(nullptr); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 7b4e6c313a..571083b666 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -15,7 +15,9 @@ #include +#define private public #include "app_mgr_stub.h" +#undef private #include "hilog_wrapper.h" #include "mock_app_mgr_service.h" @@ -364,5 +366,31 @@ HWTEST_F(AppMgrStubTest, IsApplicationRunning_0100, TestSize.Level1) static_cast(AppMgrInterfaceCode::IS_APPLICATION_RUNNING), data, reply, option); EXPECT_EQ(result, NO_ERROR); } -} // namespace AppExecFwk -} // namespace OHOS + +/** + * @tc.number: HandleRegisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when write result success. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, HandleRegisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto result = mockAppMgrService_->HandleRegisterAbilityForegroundStateObserver(data, reply); + EXPECT_EQ(result, NO_ERROR); +} + +/** + * @tc.number: HandleUnregisterAbilityForegroundStateObserver_0100 + * @tc.desc: Verify it when write result success. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, HandleUnregisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto result = mockAppMgrService_->HandleUnregisterAbilityForegroundStateObserver(data, reply); + EXPECT_EQ(result, NO_ERROR); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_recovery_test/BUILD.gn b/test/unittest/app_recovery_test/BUILD.gn index 9b9af5d57c..d4408955b2 100644 --- a/test/unittest/app_recovery_test/BUILD.gn +++ b/test/unittest/app_recovery_test/BUILD.gn @@ -23,6 +23,8 @@ ohos_unittest("AppRecoveryUnitTest") { include_dirs = [ "./", "mock", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", "${ability_runtime_test_path}/mock/services_appmgr_test/include", ] diff --git a/test/unittest/app_running_manager_test/BUILD.gn b/test/unittest/app_running_manager_test/BUILD.gn index 8097057b94..06991f5841 100644 --- a/test/unittest/app_running_manager_test/BUILD.gn +++ b/test/unittest/app_running_manager_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("app_running_manager_test") { "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:task_handler_wrap", + "${windowmanager_path}/utils:libwmutil_static", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -59,9 +60,14 @@ ohos_unittest("app_running_manager_test") { "memory_utils:libmeminfo", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", - "window_manager:libwsutils", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwm", + "window_manager:libwsutils", + ] + } } group("unittest") { diff --git a/test/unittest/app_running_manager_test/app_running_manager_test.cpp b/test/unittest/app_running_manager_test/app_running_manager_test.cpp index 6cee21eaa7..7ee2763442 100644 --- a/test/unittest/app_running_manager_test/app_running_manager_test.cpp +++ b/test/unittest/app_running_manager_test/app_running_manager_test.cpp @@ -18,6 +18,8 @@ #define private public #include "app_running_manager.h" #undef private +#include "hilog_wrapper.h" +#include "window_visibility_info.h" using namespace testing; using namespace testing::ext; @@ -28,6 +30,8 @@ namespace { constexpr int32_t DEBUGINFOS_SIZE = 0; constexpr int32_t ABILITYTOKENS_SIZE = 0; constexpr int32_t RECORD_ID = 1; +constexpr uint32_t WINDOW_ID = 100; +constexpr pid_t PID = 10; constexpr int32_t RECORD_MAP_SIZE = 1; constexpr int32_t DEBUG_INFOS_SIZE = 1; constexpr int32_t ABILITY_TOKENS_SIZE = 1; @@ -155,5 +159,45 @@ HWTEST_F(AppRunningManagerTest, AppRunningManager_GetAbilityTokensByBundleName_0 } } } + +/** + * @tc.name: AppRunningManager_OnWindowVisibilityChanged_0100 + * @tc.desc: verify the function of OnWindowVisibilityChanged : set windowIds and isUpdateStateFromService_ + * @tc.type: FUNC + */ +HWTEST_F(AppRunningManagerTest, AppRunningManager_OnWindowVisibilityChanged_0100, TestSize.Level1) +{ + // 1. create ApprunningManager + auto appRunningManager = std::make_shared(); + EXPECT_NE(appRunningManager, nullptr); + + // 2. createAppRunningRecord and put it into appRunningRecordMap_ of AppRunningManager + std::string processName = "processName"; + std::string appName = "appName"; + auto appInfo = std::make_shared(); + appInfo->name = appName; + int32_t recordId = AppRecordId::Create(); + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->curState_ = ApplicationState::APP_STATE_BACKGROUND; + appRunningRecord->isUpdateStateFromService_ = false; + appRunningRecord->GetPriorityObject()->SetPid(PID); + appRunningManager->appRunningRecordMap_.emplace(recordId, appRunningRecord); + + // 3. construct WindowVisibilityInfos + std::vector> windowVisibilityInfos; + auto info = new (std::nothrow) Rosen::WindowVisibilityInfo(); + EXPECT_NE(info, nullptr); + info->windowId_ = WINDOW_ID; + info->pid_ = PID; + info->visibilityState_ = Rosen::WindowVisibilityState::WINDOW_VISIBILITY_STATE_NO_OCCLUSION; + windowVisibilityInfos.push_back(info); + + // 4. verify the function + appRunningManager->OnWindowVisibilityChanged(windowVisibilityInfos); + EXPECT_FALSE(appRunningManager->appRunningRecordMap_.empty()); + EXPECT_FALSE(appRunningManager->appRunningRecordMap_.at(1)->windowIds_.empty()); + EXPECT_TRUE(appRunningManager->appRunningRecordMap_.at(1)->isUpdateStateFromService_); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 640d20c27d..b76af6d91c 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -77,8 +77,11 @@ ohos_unittest("AppRunningProcessesInfoTest") { "init:libbeget_proxy", "ipc:ipc_core", "memory_utils:libmeminfo", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_running_record_test/BUILD.gn b/test/unittest/app_running_record_test/BUILD.gn new file mode 100644 index 0000000000..48e74573fa --- /dev/null +++ b/test/unittest/app_running_record_test/BUILD.gn @@ -0,0 +1,73 @@ +# 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgrservice" + +ohos_unittest("app_running_record_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_test_path}/mock/services_appmgr_test/include/", + ] + + configs = [ "${ability_runtime_services_path}/appmgr:appmgr_config" ] + + sources = [ "app_running_record_test.cpp" ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:event_report", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_services_path}/common:task_handler_wrap", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "access_token:libaccesstoken_sdk", + "appspawn:appspawn_socket_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "kv_store:distributeddata_mgr", + "memory_utils:libmeminfo", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwm", + "window_manager:libwsutils", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":app_running_record_test" ] +} diff --git a/test/unittest/app_running_record_test/app_running_record_test.cpp b/test/unittest/app_running_record_test/app_running_record_test.cpp new file mode 100644 index 0000000000..26c7a3a385 --- /dev/null +++ b/test/unittest/app_running_record_test/app_running_record_test.cpp @@ -0,0 +1,180 @@ +/* + * 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 + +#define private public +#include "app_running_record.h" +#undef private +#include "mock_ability_token.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr int64_t TIMEOUT = 1; +constexpr int32_t RECORD_ID = 1; +constexpr int32_t EVENT_ID_1 = 1; +constexpr int32_t EVENT_ID_2 = 2; +constexpr int32_t START_PROCESS_SPECIFY_ABILITY_EVENT_ID = 1; +constexpr int32_t ADD_ABILITY_STAGE_INFO_EVENT_ID = 2; +constexpr int32_t TERMINATE_ABILITY_SIZE = 0; +} +class AppRunningRecordTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AppRunningRecordTest::SetUpTestCase(void) +{} + +void AppRunningRecordTest::TearDownTestCase(void) +{} + +void AppRunningRecordTest::SetUp() +{} + +void AppRunningRecordTest::TearDown() +{} + +/** + * @tc.name: AppRunningRecord_SendEvent_0100 + * @tc.desc: Test the status of SendEvent when msg is a value of 4. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_SendEvent_0100, TestSize.Level1) +{ + uint32_t msg = AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG; + int64_t timeOut = TIMEOUT; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + appRunningRecord->eventHandler_ = + std::make_shared(appRunningRecord->taskHandler_, appRunningRecord->appMgrServiceInner_); + appRunningRecord->isDebugApp_ = false; + appRunningRecord->isNativeDebug_ = false; + appRunningRecord->isAttachDebug_ = false; + appRunningRecord->SendEvent(msg, timeOut); + EXPECT_EQ(appRunningRecord->eventId_, EVENT_ID_1); + EXPECT_EQ(appRunningRecord->startProcessSpecifiedAbilityEventId_, START_PROCESS_SPECIFY_ABILITY_EVENT_ID); +} + +/** + * @tc.name: AppRunningRecord_SendEvent_0200 + * @tc.desc: Test the status of SendEvent when msg is a value of 2. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_SendEvent_0200, TestSize.Level1) +{ + uint32_t msg = AMSEventHandler::ADD_ABILITY_STAGE_INFO_TIMEOUT_MSG; + int64_t timeOut = TIMEOUT; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME); + appRunningRecord->eventHandler_ = + std::make_shared(appRunningRecord->taskHandler_, appRunningRecord->appMgrServiceInner_); + appRunningRecord->isDebugApp_ = false; + appRunningRecord->isNativeDebug_ = false; + appRunningRecord->isAttachDebug_ = false; + appRunningRecord->SendEvent(msg, timeOut); + EXPECT_EQ(appRunningRecord->eventId_, EVENT_ID_2); + EXPECT_EQ(appRunningRecord->addAbilityStageInfoEventId_, ADD_ABILITY_STAGE_INFO_EVENT_ID); +} + +/** + * @tc.name: AppRunningRecord_SetAttachDebug_0100 + * @tc.desc: Test the status of SetAttachDebug based on the isAttachDebug value being true. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_SetAttachDebug_0100, TestSize.Level1) +{ + bool isAttachDebug = true; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->SetAttachDebug(isAttachDebug); + EXPECT_EQ(appRunningRecord->isAttachDebug_, true); +} + +/** + * @tc.name: AppRunningRecord_SetAttachDebug_0200 + * @tc.desc: Test the status of SetAttachDebug based on the isAttachDebug value being false. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_SetAttachDebug_0200, TestSize.Level1) +{ + bool isAttachDebug = false; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->SetAttachDebug(isAttachDebug); + EXPECT_EQ(appRunningRecord->isAttachDebug_, false); +} + +/** + * @tc.name: AppRunningRecord_TerminateAbility_0100 + * @tc.desc: Test the status of TerminateAbility. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_TerminateAbility_0100, TestSize.Level1) +{ + bool isForce = true; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + sptr token = new (std::nothrow) MockAbilityToken(); + auto info = nullptr; + auto eventHandler = nullptr; + auto moduleRecord = std::make_shared(info, eventHandler); + EXPECT_NE(moduleRecord, nullptr); + appRunningRecord->TerminateAbility(token, isForce); + EXPECT_EQ(moduleRecord->terminateAbilities_.size(), TERMINATE_ABILITY_SIZE); +} + +/** + * @tc.name: AppRunningRecord_AbilityTerminated_0100 + * @tc.desc: Test the status of AbilityTerminated. + * @tc.type: FUNC + */ +HWTEST_F(AppRunningRecordTest, AppRunningRecord_AbilityTerminated_0100, TestSize.Level1) +{ + sptr token; + bool isForce = true; + std::shared_ptr appInfo = std::make_shared(); + int32_t recordId = RECORD_ID; + std::string processName; + auto appRunningRecord = std::make_shared(appInfo, recordId, processName); + EXPECT_NE(appRunningRecord, nullptr); + appRunningRecord->AbilityTerminated(token); + EXPECT_EQ(appRunningRecord->processType_, ProcessType::NORMAL); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_scheduler_test/BUILD.gn b/test/unittest/app_scheduler_test/BUILD.gn index 4841799dda..6e3445224a 100644 --- a/test/unittest/app_scheduler_test/BUILD.gn +++ b/test/unittest/app_scheduler_test/BUILD.gn @@ -22,9 +22,10 @@ ohos_unittest("app_scheduler_test") { module_out_path = module_output_path include_dirs = [ - "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", - "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${ability_runtime_test_path}/unittest/app_debug_listener_proxy_test", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", ] sources = [ "app_scheduler_test.cpp" ] diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index 0d43fdf2c9..3d08ecf70d 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -22,10 +22,11 @@ #include "app_scheduler.h" #undef private #undef protected -#include "app_state_call_back_mock.h" -#include "app_process_data.h" -#include "element_name.h" +#include "app_debug_listener_stub_mock.h" #include "app_mgr_client_mock.h" +#include "app_process_data.h" +#include "app_state_call_back_mock.h" +#include "element_name.h" using namespace testing; using namespace testing::ext; @@ -1160,5 +1161,89 @@ HWTEST_F(AppSchedulerTest, AppScheduler_NotifyFault_001, TestSize.Level1) int res = DelayedSingleton::GetInstance()->NotifyFault(faultData); EXPECT_EQ(res, INNER_ERR); } + +/** + * @tc.name: AppScheduler_RegisterAppDebugListener_001 + * @tc.desc: Test the state of RegisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_001, TestSize.Level1) +{ + sptr listener = nullptr; + int res = DelayedSingleton::GetInstance()->RegisterAppDebugListener(listener); + EXPECT_EQ(res, INNER_ERR); +} + +/** + * @tc.name: AppScheduler_RegisterAppDebugListener_002 + * @tc.desc: Test the state of RegisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAppDebugListener_002, TestSize.Level1) +{ + auto listener = new AppDebugListenerStubMock(); + int res = DelayedSingleton::GetInstance()->RegisterAppDebugListener(listener); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: AppScheduler_UnregisterAppDebugListener_001 + * @tc.desc: Test the state of UnregisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_001, TestSize.Level1) +{ + sptr listener = nullptr; + int res = DelayedSingleton::GetInstance()->UnregisterAppDebugListener(listener); + EXPECT_EQ(res, INNER_ERR); +} + +/** + * @tc.name: AppScheduler_UnregisterAppDebugListener_002 + * @tc.desc: Test the state of UnregisterAppDebugListener + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_UnregisterAppDebugListener_002, TestSize.Level1) +{ + auto listener = new AppDebugListenerStubMock(); + int res = DelayedSingleton::GetInstance()->UnregisterAppDebugListener(listener); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: AppScheduler_AttachAppDebug_001 + * @tc.desc: Test the state of AttachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_AttachAppDebug_001, TestSize.Level1) +{ + std::string bundleName = "bundleName"; + int res = DelayedSingleton::GetInstance()->AttachAppDebug(bundleName); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: AppScheduler_DetachAppDebug_001 + * @tc.desc: Test the state of DetachAppDebug + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_DetachAppDebug_001, TestSize.Level1) +{ + std::string bundleName = "bundleName"; + int res = DelayedSingleton::GetInstance()->DetachAppDebug(bundleName); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.name: AppScheduler_RegisterAbilityDebugResponse_001 + * @tc.desc: Test the state of RegisterAbilityDebugResponse + * @tc.type: FUNC + */ +HWTEST_F(AppSchedulerTest, AppScheduler_RegisterAbilityDebugResponse_001, TestSize.Level1) +{ + sptr response = nullptr; + int res = DelayedSingleton::GetInstance()->RegisterAbilityDebugResponse(response); + EXPECT_EQ(res, INNER_ERR); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/app_spawn_client_test/BUILD.gn b/test/unittest/app_spawn_client_test/BUILD.gn index ff071b6729..2f3009aea2 100644 --- a/test/unittest/app_spawn_client_test/BUILD.gn +++ b/test/unittest/app_spawn_client_test/BUILD.gn @@ -46,8 +46,11 @@ ohos_unittest("AppSpawnClientTest") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/app_state_observer_manager_test/BUILD.gn b/test/unittest/app_state_observer_manager_test/BUILD.gn index 7553dccb61..a27160f7af 100755 --- a/test/unittest/app_state_observer_manager_test/BUILD.gn +++ b/test/unittest/app_state_observer_manager_test/BUILD.gn @@ -22,6 +22,8 @@ ohos_unittest("app_state_observer_manager_test") { include_dirs = [ "${ability_runtime_services_path}/appmgr/include", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_test_path}/unittest/ability_foreground_state_observer_stub_test", ] sources = diff --git a/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp b/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp index 7f374a6a14..e08bfbbe61 100644 --- a/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp +++ b/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp @@ -15,10 +15,15 @@ #include +#include "ability_foreground_state_observer_proxy.h" #define private public #include "app_state_observer_manager.h" #undef private #include "application_state_observer_stub.h" +#include "app_foreground_state_observer_proxy.h" +#include "iapplication_state_observer.h" +#include "iremote_broker.h" +#include "mock_ability_foreground_state_observer_server_stub.h" using namespace testing; using namespace testing::ext; @@ -1142,5 +1147,128 @@ HWTEST_F(AppSpawnSocketTest, ObserverExist_002, TestSize.Level0) bool res = manager->ObserverExist(observer); EXPECT_TRUE(res); } -} // namespace AppExecFwk -} // namespace OHOS + +/** + * @tc.name: RegisterAbilityForegroundStateObserver_0100 + * @tc.desc: The test returns when the permission judgment is inconsistent. + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + sptr observer = new AbilityForegroundStateObserverProxy(nullptr); + manager->abilityforegroundObserverSet_.emplace(observer); + auto res = manager->RegisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(res, ERR_PERMISSION_DENIED); +} + +/** + * @tc.name: UnregisterAbilityForegroundStateObserver_0100 + * @tc.desc: The test returns when the permission judgment is inconsistent. + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level1) +{ + sptr observer = new AbilityForegroundStateObserverProxy(nullptr); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + manager->abilityforegroundObserverSet_.emplace(observer); + auto res = manager->UnregisterAbilityForegroundStateObserver(observer); + EXPECT_EQ(res, ERR_PERMISSION_DENIED); +} + +/** + * @tc.name: IsAbilityForegroundObserverExist_0100 + * @tc.desc: Test return when abilityforegroundObserverSet_ is not empty and + * the conditions within the loop are met. + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, IsAbilityForegroundObserverExist_0100, TestSize.Level1) +{ + sptr observer = new AppForegroundStateObserverProxy(nullptr); + sptr observers = new AbilityForegroundStateObserverProxy(nullptr); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + manager->abilityforegroundObserverSet_.emplace(observers); + auto res = manager->IsAbilityForegroundObserverExist(observer); + EXPECT_EQ(res, true); +} + +/** + * @tc.name: AddObserverDeathRecipient_0100 + * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(type is APPLICATION_STATE_OBSERVER) + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0100, TestSize.Level1) +{ + auto observerStub = new MockAbilityForegroundStateObserverServerStub(); + sptr observer = new AppForegroundStateObserverProxy(observerStub); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + ObserverType type = ObserverType::APPLICATION_STATE_OBSERVER; + manager->AddObserverDeathRecipient(observer, type); + ASSERT_FALSE(manager->recipientMap_.empty()); +} + +/** + * @tc.name: AddObserverDeathRecipient_0200 + * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(type is ABILITY_FOREGROUND_STATE_OBSERVER) + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0200, TestSize.Level1) +{ + auto observerStub = new MockAbilityForegroundStateObserverServerStub(); + sptr observer = new AppForegroundStateObserverProxy(observerStub); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER; + manager->AddObserverDeathRecipient(observer, type); + ASSERT_FALSE(manager->recipientMap_.empty()); +} + +/** + * @tc.name: AddObserverDeathRecipient_0300 + * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(observer is nullptr) + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0300, TestSize.Level1) +{ + sptr observer = new AppForegroundStateObserverProxy(nullptr); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER; + manager->AddObserverDeathRecipient(observer, type); + ASSERT_TRUE(manager->recipientMap_.empty()); +} + +/** + * @tc.name: RemoveObserverDeathRecipient_0100 + * @tc.desc: Verify that RemoveObserverDeathRecipient can be called normally + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_0100, TestSize.Level1) +{ + auto observerStub = new MockAbilityForegroundStateObserverServerStub(); + sptr observer = new AppForegroundStateObserverProxy(observerStub); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + manager->RemoveObserverDeathRecipient(observer); + ASSERT_TRUE(manager->recipientMap_.empty()); +} + +/** + * @tc.name: RemoveObserverDeathRecipient_0200 + * @tc.desc: Verify that RemoveObserverDeathRecipient can be called normally(observer is nullptr) + * @tc.type: FUNC + */ +HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_0200, TestSize.Level1) +{ + sptr observer = new AppForegroundStateObserverProxy(nullptr); + auto manager = std::make_shared(); + ASSERT_NE(manager, nullptr); + manager->RemoveObserverDeathRecipient(observer); + ASSERT_TRUE(manager->recipientMap_.empty()); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index b49aa40fba..95d39fc2c5 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -269,6 +269,11 @@ class MockAppMgrStub : public AppMgrStub { { return 0; } + + bool IsFinalAppProcess() override + { + return true; + } }; /* diff --git a/test/unittest/application_context_test/application_context_test.cpp b/test/unittest/application_context_test/application_context_test.cpp index cb377d8a93..8071445013 100644 --- a/test/unittest/application_context_test/application_context_test.cpp +++ b/test/unittest/application_context_test/application_context_test.cpp @@ -363,6 +363,35 @@ HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1) GTEST_LOG_(INFO) << "GetTempDir_0200 end"; } +/** + * @tc.number: GetResourceDir_0100 + * @tc.name: GetResourceDir + * @tc.desc: Get Resource Dir failed + */ +HWTEST_F(ApplicationContextTest, GetResourceDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetResourceDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetResourceDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetResourceDir_0100 end"; +} + +/** + * @tc.number: GetResourceDir_0200 + * @tc.name: GetResourceDir + * @tc.desc: Get Resource Dir failed + */ +HWTEST_F(ApplicationContextTest, GetResourceDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetResourceDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetResourceDir(); + EXPECT_EQ(ret, "/resfile"); + GTEST_LOG_(INFO) << "GetResourceDir_0200 end"; +} + /** * @tc.number: GetGroupDir_0100 * @tc.name: GetGroupDir diff --git a/test/unittest/application_context_test/mock_context_impl.cpp b/test/unittest/application_context_test/mock_context_impl.cpp index 9a93207b88..10eb334654 100644 --- a/test/unittest/application_context_test/mock_context_impl.cpp +++ b/test/unittest/application_context_test/mock_context_impl.cpp @@ -59,6 +59,11 @@ std::string MockContextImpl::GetTempDir() return "/temp"; } +std::string MockContextImpl::GetResourceDir() +{ + return "/resfile"; +} + std::string MockContextImpl::GetFilesDir() { return "/files"; diff --git a/test/unittest/application_context_test/mock_context_impl.h b/test/unittest/application_context_test/mock_context_impl.h index 5ee50b6f11..5ebc519aa7 100644 --- a/test/unittest/application_context_test/mock_context_impl.h +++ b/test/unittest/application_context_test/mock_context_impl.h @@ -38,6 +38,8 @@ public: std::string GetTempDir() override; + std::string GetResourceDir() override; + std::string GetFilesDir() override; std::string GetDatabaseDir() override; diff --git a/test/unittest/auto_fill_manager_test/BUILD.gn b/test/unittest/auto_fill_manager_test/BUILD.gn index c648e81d44..63e6405a0b 100644 --- a/test/unittest/auto_fill_manager_test/BUILD.gn +++ b/test/unittest/auto_fill_manager_test/BUILD.gn @@ -44,7 +44,6 @@ ohos_unittest("auto_fill_manager_test") { "ability_base:configuration", "ability_base:view_data", "ability_base:want", - "ace_engine:ace_uicontent", "bundle_framework:appexecfwk_base", "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", @@ -57,6 +56,10 @@ ohos_unittest("auto_fill_manager_test") { "ipc:ipc_core", "samgr:samgr_proxy", ] + + if (ability_runtime_graphics) { + external_deps += [ "ace_engine:ace_uicontent" ] + } } group("unittest") { diff --git a/test/unittest/call_container_test/BUILD.gn b/test/unittest/call_container_test/BUILD.gn index 084678e0d8..27660cb6d5 100644 --- a/test/unittest/call_container_test/BUILD.gn +++ b/test/unittest/call_container_test/BUILD.gn @@ -58,12 +58,15 @@ ohos_unittest("call_container_test") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/child_process_manager_test/child_process_manager_test.cpp b/test/unittest/child_process_manager_test/child_process_manager_test.cpp index 9db08dd7aa..f4bf57f9b4 100644 --- a/test/unittest/child_process_manager_test/child_process_manager_test.cpp +++ b/test/unittest/child_process_manager_test/child_process_manager_test.cpp @@ -65,7 +65,7 @@ HWTEST_F(ChildProcessManagerTest, StartChildProcessBySelfFork_0100, TestSize.Lev { pid_t pid; auto &appUtils = AAFwk::AppUtils::GetInstance(); - appUtils.isMultiProcesModelDevice_ = true; + appUtils.isPcDevice_ = true; ChildProcessManager::GetInstance().StartChildProcessBySelfFork("./ets/process/DemoProcess.ts", pid); EXPECT_TRUE(pid > 0); } diff --git a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn index a3e7e03f91..dd3343618d 100755 --- a/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn +++ b/test/unittest/dataobs_mgr_service_dump_test/BUILD.gn @@ -49,8 +49,11 @@ ohos_unittest("dataobs_mgr_service_dump_test") { "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:libwm", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } } group("unittest") { diff --git a/test/unittest/extension_manager_client_test/BUILD.gn b/test/unittest/extension_manager_client_test/BUILD.gn index f189124098..768366bedf 100644 --- a/test/unittest/extension_manager_client_test/BUILD.gn +++ b/test/unittest/extension_manager_client_test/BUILD.gn @@ -40,12 +40,15 @@ ohos_unittest("extension_manager_client_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/form_extension_context_test/BUILD.gn b/test/unittest/form_extension_context_test/BUILD.gn index 3702ecc71c..deea9f1702 100644 --- a/test/unittest/form_extension_context_test/BUILD.gn +++ b/test/unittest/form_extension_context_test/BUILD.gn @@ -75,7 +75,6 @@ ohos_unittest("form_extension_context_test") { "napi:ace_napi", "relational_store:native_dataability", "relational_store:native_rdb", - "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -85,6 +84,10 @@ ohos_unittest("form_extension_context_test") { if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn index 3152fbb88e..1e38998b66 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn @@ -59,9 +59,14 @@ ohos_unittest("ability_context_impl_test") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - "window_manager:libwsutils", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } } ohos_unittest("caller_call_back_ut_test") { diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_test.cpp index 81abd23eea..f3cc680d91 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_test.cpp @@ -556,6 +556,20 @@ HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0400, Functio EXPECT_EQ(ret, ERR_OK); } +/** + * @tc.number: Ability_Context_Impl_StartAbility_0500 + * @tc.name: StartAbility + * @tc.desc: Start Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0500, Function | MediumTest | Level1) +{ + AAFwk::Want want; + want.SetParam("ScreenMode", 1); + int32_t requestCode = 1; + auto ret = context_->StartAbility(want, requestCode); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + /** * @tc.number: Ability_Context_Impl_OnAbilityResult_0100 * @tc.name: OnAbilityResult @@ -739,6 +753,30 @@ HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetTempDir_0200, Function EXPECT_EQ(ret, ""); } +/** + * @tc.number: Ability_Context_Impl_GetResourceDir_0100 + * @tc.name: GetResourceDir + * @tc.desc: Get resource Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetResourceDir(); + EXPECT_EQ(ret, "/resfile"); +} + +/** + * @tc.number: Ability_Context_Impl_GetResourceDir_0200 + * @tc.name: GetResourceDir + * @tc.desc: Get resource Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetResourceDir(); + EXPECT_EQ(ret, ""); +} + /** * @tc.number: Ability_Context_Impl_GetGroupDir_0100 * @tc.name: GetGroupDir diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp index 2eb84bbc04..6372d48d30 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp @@ -61,6 +61,11 @@ std::string MockContext::GetTempDir() return "/temp"; } +std::string MockContext::GetResourceDir() +{ + return "/resfile"; +} + std::string MockContext::GetFilesDir() { return "/files"; diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h index 9ffcabffb1..4c44eb876f 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h @@ -41,6 +41,8 @@ public: std::string GetTempDir() override; + std::string GetResourceDir() override; + std::string GetFilesDir() override; std::string GetDatabaseDir() override; diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 67f369ff77..430b747fbc 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -30,6 +30,7 @@ config("module_private_config") { "${ability_runtime_innerkits_path}/ability_manager/include", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_path}/interfaces/kits/native/appkit/app/task", @@ -98,6 +99,7 @@ ohos_unittest("ability_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gmock_main", @@ -114,6 +116,7 @@ ohos_unittest("ability_test") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -551,6 +554,7 @@ ohos_unittest("ability_impl_active_test") { "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gtest_main", @@ -562,6 +566,7 @@ ohos_unittest("ability_impl_active_test") { "ability_base:zuri", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", @@ -592,6 +597,7 @@ ohos_unittest("ability_impl_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -644,6 +650,7 @@ ohos_unittest("ui_ability_impl_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gtest_main", @@ -662,6 +669,7 @@ ohos_unittest("ui_ability_impl_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", + "samgr:samgr_proxy", ] if (ability_runtime_graphics) { @@ -703,6 +711,7 @@ ohos_unittest("ability_thread_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${ability_runtime_services_path}/dataobsmgr:dataobsms_static", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -718,6 +727,7 @@ ohos_unittest("ability_thread_test") { "ability_runtime:ability_deps_wrapper", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -800,6 +810,7 @@ ohos_unittest("ui_ability_thread_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${ability_runtime_services_path}/dataobsmgr:dataobsms_static", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", @@ -814,6 +825,7 @@ ohos_unittest("ui_ability_thread_test") { "ability_runtime:ability_deps_wrapper", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1128,6 +1140,7 @@ ohos_unittest("data_ability_impl_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -1147,6 +1160,7 @@ ohos_unittest("data_ability_impl_test") { "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "data_share:datashare_common", @@ -1193,6 +1207,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -1207,6 +1222,7 @@ ohos_unittest("data_ability_impl_file_secondpart_test") { "ability_runtime:ability_deps_wrapper", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1247,6 +1263,7 @@ ohos_unittest("data_ability_impl_file_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -1261,6 +1278,7 @@ ohos_unittest("data_ability_impl_file_test") { "ability_runtime:ability_deps_wrapper", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1303,6 +1321,7 @@ ohos_unittest("ability_thread_dataability_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -1317,6 +1336,7 @@ ohos_unittest("ability_thread_dataability_test") { "ability_runtime:ability_deps_wrapper", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1530,6 +1550,7 @@ ohos_unittest("ui_ability_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gmock_main", @@ -1545,6 +1566,7 @@ ohos_unittest("ui_ability_test") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1638,6 +1660,7 @@ ohos_unittest("form_host_client_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gmock_main", @@ -1683,6 +1706,7 @@ ohos_unittest("continuation_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", @@ -1697,6 +1721,7 @@ ohos_unittest("continuation_test") { "ability_base:zuri", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1901,6 +1926,7 @@ ohos_unittest("ability_window_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "${graphic_path}/rosen/modules/render_service_client:librender_service_client", @@ -1915,8 +1941,8 @@ ohos_unittest("ability_window_test") { "ability_runtime:ability_context_native", "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", - "ace_engine:ace_uicontent", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -1934,6 +1960,7 @@ ohos_unittest("ability_window_test") { if (ability_runtime_graphics) { external_deps += [ + "ace_engine:ace_uicontent", "image_framework:image_native", "input:libmmi-client", ] @@ -1957,6 +1984,7 @@ ohos_unittest("ability_handler_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "//third_party/googletest:gtest_main", ] @@ -1967,12 +1995,15 @@ ohos_unittest("ability_handler_test") { "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_core", "napi:ace_napi", + "samgr:samgr_proxy", ] if (ability_runtime_graphics) { @@ -2002,6 +2033,7 @@ ohos_unittest("ability_impl_factory_test") { "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_native_path}/appkit:app_context_utils", "${ability_runtime_native_path}/appkit:appkit_delegator", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_services_path}/common:event_report", "//third_party/googletest:gtest_main", ] @@ -2018,6 +2050,7 @@ ohos_unittest("ability_impl_factory_test") { "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "hilog:libhilog", diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp index 57ee75086b..01ee48b39f 100644 --- a/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/extension_test.cpp @@ -384,7 +384,9 @@ HWTEST_F(ExtensionTest, AaFwk_Extension_1800, Function | MediumTest | Level1) Want want; want.SetElementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); EXPECT_TRUE(extension_ != nullptr); - extension_->OnForeground(want); + sptr session = new (std::nothrow) AAFwk::SessionInfo(); + EXPECT_NE(session, nullptr); + extension_->OnForeground(want, session); GTEST_LOG_(INFO) << "AaFwk_Extension_1800 end"; } diff --git a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp index 916d2cab20..e6247bc4bd 100644 --- a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp @@ -72,6 +72,11 @@ std::string MockAbilityRuntimeContext::GetTempDir() return {}; }; +std::string MockAbilityRuntimeContext::GetResourceDir() +{ + return {}; +}; + std::string MockAbilityRuntimeContext::GetFilesDir() { return {}; diff --git a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h index 2f765a6078..8d317bcdc0 100644 --- a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h +++ b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h @@ -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; bool IsUpdatingConfigurations() override; bool PrintDrawnCompleted() override; diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp index ae06996f89..1765e70695 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_test.cpp @@ -23,6 +23,7 @@ #include "ability_context_impl.h" #include "ability_handler.h" #include "ability_recovery.h" +#include "fa_ability_thread.h" #include "hilog_wrapper.h" #include "ohos_application.h" #include "runtime.h" @@ -69,7 +70,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_Name_0100, Function | MediumTest | Le std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); EXPECT_STREQ(abilityInfo->name.c_str(), ability_->GetAbilityName().c_str()); GTEST_LOG_(INFO) << "AbilityRuntime_Name_0100 end"; } @@ -89,7 +92,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetAbilityName_0100, Function | Mediu sptr token = nullptr; std::string name = "LOL"; abilityInfo->name = name; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); EXPECT_STREQ(ability_->GetAbilityName().c_str(), name.c_str()); GTEST_LOG_(INFO) << "AbilityRuntime_GetAbilityName_0100 end"; } @@ -107,7 +112,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetLifecycle_0100, Function | MediumT std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); std::shared_ptr lifeCycle = ability_->GetLifecycle(); EXPECT_NE(lifeCycle, nullptr); GTEST_LOG_(INFO) << "AaFwk_Ability_GetLifecycle_0100 end"; @@ -155,7 +162,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnNewWant_0100, Function | MediumTest std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnNewWant(want); GTEST_LOG_(INFO) << "AbilityRuntime_OnNewWant_0100 end"; @@ -174,7 +183,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnRestoreAbilityState_0100, Function std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); PacMap inState; ability_->OnRestoreAbilityState(inState); GTEST_LOG_(INFO) << "AbilityRuntime_OnRestoreAbilityState_0100 end"; @@ -193,7 +204,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_GetWindow_001, Function | MediumTest std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); EXPECT_EQ(ability_->GetWindow(), nullptr); GTEST_LOG_(INFO) << "AbilityRuntime_GetWindow_0100 end"; } @@ -213,7 +226,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0100, Function | MediumTest | std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnStart(want); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -264,7 +279,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStart_0300, TestSize.Level1) auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); sptr token = nullptr; - ability->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability->Init(abilityRecord, application, handler, token); Want want; ability->OnStart(want); HILOG_INFO("%{public}s end.", __func__); @@ -308,7 +325,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnStop_0100, Function | MediumTest | std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); ability_->OnStop(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); std::shared_ptr lifeCycle = ability_->GetLifecycle(); @@ -384,7 +403,9 @@ HWTEST_F(UIAbilityBaseTest, DestroyInstance_0100, TestSize.Level1) auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); sptr token = nullptr; - ability->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability->Init(abilityRecord, application, handler, token); ability->DestroyInstance(); HILOG_INFO("%{public}s end.", __func__); } @@ -403,7 +424,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0100, Function | MediumT std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnForeground(want); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -446,7 +469,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnForeground_0300, Function | MediumT std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->OnForeground(want); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -471,7 +496,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0100, Function | MediumT std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); std::shared_ptr lifeCycle = ability_->GetLifecycle(); @@ -493,7 +520,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0200, Function | MediumT std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); std::shared_ptr lifeCycle = ability_->GetLifecycle(); @@ -517,7 +546,9 @@ HWTEST_F(UIAbilityBaseTest, AaFwk_Ability_OnBackground_0300, Function | MediumTe std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); ability_->OnBackground(); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); std::shared_ptr lifeCycle = ability_->GetLifecycle(); @@ -552,7 +583,9 @@ HWTEST_F(UIAbilityBaseTest, AbilityRuntime_OnBackground_0400, TestSize.Level1) auto eventRunner = EventRunner::Create(abilityInfo->name); auto handler = std::make_shared(eventRunner); sptr token = nullptr; - ability->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability->Init(abilityRecord, application, handler, token); int32_t displayId = 0; sptr option = new Rosen::WindowOption(); ability->InitWindow(displayId, option); @@ -688,7 +721,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityContinuation_0300, TestSize.Level1) pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); Want want; bool success = false; ability->NotifyContinuationResult(want, success); @@ -925,7 +961,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionLabel_0100, TestSize.Level1) pageAbilityInfo->isStageBasedModel = true; std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); ret = ability->SetMissionLabel(label); EXPECT_EQ(ret, -1); int32_t displayId = 0; @@ -956,7 +995,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilitySetMissionIcon_0100, TestSize.Level1) pageAbilityInfo->isStageBasedModel = true; std::shared_ptr eventRunner = EventRunner::Create(pageAbilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); ret = ability->SetMissionIcon(icon); EXPECT_EQ(ret, -1); int32_t displayId = 0; @@ -982,7 +1024,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnChange_0100, TestSize.Level1) pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); // application is nullptr Rosen::DisplayId displayId = 0; @@ -994,7 +1039,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnChange_0100, TestSize.Level1) Configuration config; config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); application->SetConfiguration(config); - ability->Init(pageAbilityInfo, application, handler, nullptr); + ability->Init(abilityRecord, application, handler, nullptr); ability->OnChange(displayId); HILOG_INFO("%{public}s end.", __func__); } @@ -1014,7 +1059,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnDisplayMove_0100, TestSize.Level1) pageAbilityInfo->type = AppExecFwk::AbilityType::PAGE; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); // application is nullptr Rosen::DisplayId fromDisplayId = 1; @@ -1026,7 +1074,7 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityOnDisplayMove_0100, TestSize.Level1) Configuration config; config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); application->SetConfiguration(config); - ability->Init(pageAbilityInfo, application, handler, nullptr); + ability->Init(abilityRecord, application, handler, nullptr); ability->OnDisplayMove(fromDisplayId, toDisplayId); HILOG_INFO("%{public}s end.", __func__); } @@ -1051,7 +1099,10 @@ HWTEST_F(UIAbilityBaseTest, UIAbilityRequestFocus_0100, TestSize.Level1) pageAbilityInfo->isStageBasedModel = true; auto eventRunner = EventRunner::Create(pageAbilityInfo->name); auto handler = std::make_shared(eventRunner); - ability->Init(pageAbilityInfo, nullptr, handler, nullptr); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = + std::make_shared(pageAbilityInfo, abilityToken); + ability->Init(abilityRecord, nullptr, handler, nullptr); // window is nullptr ability->RequestFocus(want); @@ -1089,7 +1140,9 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_OnStop_AsyncCallback_0100, TestSize.Level1 std::shared_ptr application = nullptr; std::shared_ptr handler = nullptr; sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); bool isAsyncCallback = false; ability_->OnStop(nullptr, isAsyncCallback); AbilityLifecycleExecutor::LifecycleState state = ability_->GetState(); @@ -1131,7 +1184,9 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_InitWindow_0100, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); int32_t displayId = 0; sptr option = new Rosen::WindowOption(); ability_->InitWindow(displayId, option); @@ -1170,7 +1225,9 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_GetWindowOption_0100, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); CustomizeData custData = CustomizeData("ShowOnLockScreen", "0", ""); std::vector vecCustData; vecCustData.push_back(custData); @@ -1198,7 +1255,9 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0100, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->DoOnForeground(want); ASSERT_NE(ability_, nullptr); @@ -1222,7 +1281,9 @@ HWTEST_F(UIAbilityBaseTest, UIAbility_DoOnForeground_0200, TestSize.Level1) std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); std::shared_ptr handler = std::make_shared(eventRunner); sptr token = nullptr; - ability_->Init(abilityInfo, application, handler, token); + sptr abilityToken = sptr(new AbilityRuntime::FAAbilityThread()); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + ability_->Init(abilityRecord, application, handler, token); Want want; ability_->DoOnForeground(want); ASSERT_NE(ability_, nullptr); diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index b0b29379cc..c3357b2d67 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -21,6 +21,7 @@ ABILITY_INNERKITS_PATH = "${ability_runtime_innerkits_path}" config("module_private_config") { visibility = [ ":*" ] include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include", @@ -41,6 +42,7 @@ config("module_context_config") { "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_path}/interfaces/kits/native/appkit/app/task", "${ability_runtime_path}/interfaces/kits/native/ability/native", ] @@ -114,6 +116,7 @@ ohos_unittest("application_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", @@ -159,6 +162,7 @@ ohos_unittest("context_container_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", @@ -170,6 +174,7 @@ ohos_unittest("context_container_test") { "ability_base:zuri", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -214,6 +219,7 @@ ohos_unittest("context_deal_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock_main", @@ -226,6 +232,7 @@ ohos_unittest("context_deal_test") { "ability_base:zuri", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", @@ -266,6 +273,7 @@ ohos_unittest("application_impl_test") { "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", @@ -372,6 +380,7 @@ ohos_unittest("ability_stage_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:uiabilitykit_native", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", @@ -416,6 +425,7 @@ ohos_unittest("form_extension_context_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:form_extension", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_native_path}/appkit:appkit_native", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", @@ -426,6 +436,7 @@ ohos_unittest("form_extension_context_test") { "ability_base:want", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "form_fwk:fmskit_native", @@ -434,6 +445,7 @@ ohos_unittest("form_extension_context_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "napi:ace_napi", + "samgr:samgr_proxy", ] if (ability_runtime_graphics) { diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn index 8b00dbe289..1017a41143 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn @@ -144,8 +144,11 @@ ohos_unittest("ability_delegator_unittest") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } ohos_unittest("delegator_thread_unittest") { diff --git a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp index 6049f71348..12433baff3 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp @@ -315,6 +315,24 @@ HWTEST_F(ContextImplTest, GetTempDir_0100, TestSize.Level1) HILOG_INFO("%{public}s end.", __func__); } +/** + * @tc.name: GetResourceDir_0100 + * @tc.desc: Get resource directory basic test. + * @tc.type: FUNC + * @tc.require: issueI61P7Y + */ +HWTEST_F(ContextImplTest, GetResourceDir_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + + auto resourceDir = contextImpl->GetResourceDir(); + EXPECT_EQ(resourceDir, ""); + + HILOG_INFO("%{public}s end.", __func__); +} + /** * @tc.name: GetFilesDir_0100 * @tc.desc: Get files directory basic test. diff --git a/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h index f0e862cd77..51bcec35c8 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h +++ b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h @@ -259,11 +259,13 @@ public: { return ERR_OK; } - ErrCode RegisterClickEventObserver(const sptr &observer) override + ErrCode RegisterClickEventObserver( + const std::string &bundleName, const std::string &formEventType, const sptr &observer) override { return ERR_OK; } - ErrCode UnregisterClickEventObserver(const sptr &observer) override + ErrCode UnregisterClickEventObserver( + const std::string &bundleName, const std::string &formEventType, const sptr &observer) override { return ERR_OK; } diff --git a/test/unittest/free_install_manager_test/BUILD.gn b/test/unittest/free_install_manager_test/BUILD.gn index 1b9c5be322..789a991a0d 100644 --- a/test/unittest/free_install_manager_test/BUILD.gn +++ b/test/unittest/free_install_manager_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_unittest("free_install_manager_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { @@ -53,7 +52,10 @@ ohos_unittest("free_install_manager_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/lifecycle_test/BUILD.gn b/test/unittest/lifecycle_test/BUILD.gn index 4f5d3a3b0c..22b5b3d726 100644 --- a/test/unittest/lifecycle_test/BUILD.gn +++ b/test/unittest/lifecycle_test/BUILD.gn @@ -48,7 +48,6 @@ ohos_unittest("lifecycle_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { @@ -56,7 +55,10 @@ ohos_unittest("lifecycle_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp index 2b4f289800..f57e5b744e 100644 --- a/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp +++ b/test/unittest/quick_fix/quick_fix_manager_service_test/quick_fix_manager_service_test.cpp @@ -221,5 +221,28 @@ HWTEST_F(QuickFixManagerServiceTest, RevokeQuickFix_0300, TestSize.Level1) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.name: GetQuickFixInfo_0100 + * @tc.desc: RevokeQuickFix GetQuickFixInfo + * @tc.type: FUNC + */ +HWTEST_F(QuickFixManagerServiceTest, GetQuickFixInfo_0100, TestSize.Level1) +{ + HILOG_INFO("GetQuickFixInfo_0100 start."); + + auto mockGetBundleInstaller = []() { return mockBundleInstaller; }; + EXPECT_CALL(*mockBundleMgr, GetBundleInstaller()).WillOnce(testing::Invoke(mockGetBundleInstaller)); + + std::string bundleName = "com.ohos.quickfix"; + auto patchExists = false; + auto isSoContained = false; + auto ret = quickFixMs_->GetQuickFixInfo(bundleName, patchExists, isSoContained); + EXPECT_EQ(ret, QUICK_FIX_OK); + EXPECT_EQ(patchExists, true); + EXPECT_EQ(isSoContained, true); + + HILOG_INFO("GetQuickFixInfo_0100 end."); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/running_infos_test/BUILD.gn b/test/unittest/running_infos_test/BUILD.gn index c1aa105dfd..f4d9d6b8a4 100644 --- a/test/unittest/running_infos_test/BUILD.gn +++ b/test/unittest/running_infos_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("running_infos_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (ecologic_rule_enabled) { @@ -50,7 +49,10 @@ ohos_unittest("running_infos_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index e886a8584b..62870ff170 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -67,7 +67,6 @@ ohos_unittest("specified_mission_list_test") { "ipc:ipc_core", "kv_store:distributeddata_inner", "napi:ace_napi", - "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -77,6 +76,10 @@ ohos_unittest("specified_mission_list_test") { if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/start_option_display_id_test/BUILD.gn b/test/unittest/start_option_display_id_test/BUILD.gn index 468bc2f025..641e6eda59 100644 --- a/test/unittest/start_option_display_id_test/BUILD.gn +++ b/test/unittest/start_option_display_id_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("start_option_display_id_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -54,7 +53,10 @@ ohos_unittest("start_option_display_id_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "window_manager:libwm", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 5858a30091..356385d697 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -68,7 +68,6 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { "napi:ace_napi", "safwk:system_ability_fwk", "samgr:samgr_proxy", - "window_manager:scene_session", ] if (background_task_mgr_continuous_task_enable) { @@ -78,6 +77,10 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } } group("unittest") { diff --git a/test/unittest/user_controller_test/BUILD.gn b/test/unittest/user_controller_test/BUILD.gn index c61850a590..4b76f2e072 100644 --- a/test/unittest/user_controller_test/BUILD.gn +++ b/test/unittest/user_controller_test/BUILD.gn @@ -40,9 +40,12 @@ ohos_unittest("user_controller_test") { "ffrt:libffrt", "hilog:libhilog", "ipc:ipc_core", - "window_manager:scene_session", ] + if (ability_runtime_graphics) { + external_deps += [ "window_manager:scene_session" ] + } + if (ecologic_rule_enabled) { external_deps += [ "ecological_rule_manager:erms_client" ] } diff --git a/tools/aa/BUILD.gn b/tools/aa/BUILD.gn index 73794184ab..82addab9be 100644 --- a/tools/aa/BUILD.gn +++ b/tools/aa/BUILD.gn @@ -93,24 +93,6 @@ ohos_executable("aa") { symlink_target_name = [ "ability_tool" ] defines = [] - print("accessibility_enable = ", accessibility_enable) - if (accessibility_enable) { - sources += [ - "src/accessibility_ability_command.cpp", - "src/accessibility_ability_utils.cpp", - ] - - external_deps += [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "accessibility:accessibility_common", - "accessibility:accessibilityclient", - "accessibility:accessibilityconfig", - ] - defines += [ "A11Y_ENABLE" ] - symlink_target_name += [ "accessibility" ] - } install_enable = true diff --git a/tools/test/resource/aa/serviceAbilityBundleForStart/src/main/ets/ServiceAbility/service.ts b/tools/test/resource/aa/serviceAbilityBundleForStart/src/main/ets/ServiceAbility/service.ts index af219b5e18..e5043d02cc 100644 --- a/tools/test/resource/aa/serviceAbilityBundleForStart/src/main/ets/ServiceAbility/service.ts +++ b/tools/test/resource/aa/serviceAbilityBundleForStart/src/main/ets/ServiceAbility/service.ts @@ -1,3 +1,18 @@ +/* + * 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. + */ + export default { onStart() { console.info('ServiceAbility onStart');