From bb5c28a5c0dd048dac75bd3e54539bc2d1e38cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E8=8F=B2=E5=A2=A8?= Date: Fri, 4 Jul 2025 12:47:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EstartUIAbilities=20and=20TDD1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱菲墨 --- .../service_extension_context.js | 7 +- .../ui_extension_context.js | 7 +- frameworks/native/ability/native/BUILD.gn | 2 + .../ability_business_error.cpp | 30 + .../native/ability/native/ability_thread.cpp | 6 +- .../native/extension_ability_thread.cpp | 23 + .../ability/native/js_deferred_callback.cpp | 50 ++ .../native/js_service_extension_context.cpp | 90 ++- .../native/js_start_abilities_observer.cpp | 52 ++ .../js_ui_extension_context.cpp | 87 +++ .../ui_extension_context.cpp | 7 + .../service_extension_context.cpp | 8 + .../include/ability_manager_client.h | 11 + .../include/ability_manager_errors.h | 30 + .../include/ability_manager_interface.h | 14 + .../ability_manager_ipc_interface_code.h | 3 + .../include/ability_scheduler_interface.h | 9 +- .../ability_business_error.h | 14 + .../native/ability/native/ability_thread.h | 4 +- .../ability/native/extension_ability_thread.h | 2 + .../ability/native/js_deferred_callback.h | 37 + .../native/js_start_abilities_observer.h | 41 + .../js_ui_extension_context.h | 3 + .../ui_extension_base/ui_extension_context.h | 2 + .../service_extension_context.h | 2 + .../include/ability_manager_proxy.h | 11 + .../include/ability_manager_service.h | 18 +- .../abilitymgr/include/ability_manager_stub.h | 1 + services/abilitymgr/include/ability_record.h | 1 + .../include/ability_scheduler_proxy.h | 4 +- .../include/ability_scheduler_stub.h | 3 +- services/abilitymgr/include/lifecycle_deal.h | 3 +- .../ui_ability_lifecycle_manager.h | 30 +- .../include/utils/start_ability_utils.h | 5 +- .../abilitymgr/src/ability_manager_client.cpp | 13 + .../abilitymgr/src/ability_manager_proxy.cpp | 55 ++ .../src/ability_manager_service.cpp | 242 +++++- .../abilitymgr/src/ability_manager_stub.cpp | 37 + services/abilitymgr/src/ability_record.cpp | 6 + .../src/ability_scheduler_proxy.cpp | 28 +- .../abilitymgr/src/ability_scheduler_stub.cpp | 12 +- services/abilitymgr/src/lifecycle_deal.cpp | 9 +- .../ui_ability_lifecycle_manager.cpp | 230 +++++- .../src/utils/start_ability_utils.cpp | 34 +- services/common/include/app_utils.h | 8 + services/common/src/app_utils.cpp | 11 + .../attachabilitythread_fuzzer.cpp | 3 + .../include/mock_ability_manager_client.h | 3 + .../mock_ability_scheduler_for_observer.h | 3 + .../libs/aakit/include/ability_scheduler.h | 3 + .../ability_scheduler_mock.h | 1 + .../ability_manager_client_test.cpp | 16 + .../mock/include/mock_ability_scheduler.h | 3 + .../include/mock_ability_scheduler_stub.h | 3 + .../mock_ui_ability_lifecycle_manager.h | 10 +- .../src/mock_ui_ability_lifecycle_manager.cpp | 11 +- ...bility_manager_service_thirteenth_test.cpp | 704 ++++++++++++++++++ .../mock/include/mock_app_utils.h | 7 + .../mock/include/mock_my_status.h | 2 + .../mock_ui_ability_lifecycle_manager.h | 12 +- .../mock/src/mock_app_utils.cpp | 6 +- .../src/mock_ui_ability_lifecycle_manager.cpp | 17 +- .../ability_schedule_stub_second_mock.h | 3 + .../ability_schedule_stub_mock.h | 2 + ..._ability_lifecycle_manager_second_test.cpp | 9 +- .../ui_ability_lifecycle_manager_test.cpp | 622 +++++++++++++++- ...i_ability_lifecycle_manager_third_test.cpp | 29 +- 67 files changed, 2655 insertions(+), 116 deletions(-) create mode 100644 frameworks/native/ability/native/js_deferred_callback.cpp create mode 100644 frameworks/native/ability/native/js_start_abilities_observer.cpp create mode 100644 interfaces/kits/native/ability/native/js_deferred_callback.h create mode 100644 interfaces/kits/native/ability/native/js_start_abilities_observer.h diff --git a/frameworks/js/napi/service_extension_context/service_extension_context.js b/frameworks/js/napi/service_extension_context/service_extension_context.js index c81ba0f512..1d7d4baf2d 100644 --- a/frameworks/js/napi/service_extension_context/service_extension_context.js +++ b/frameworks/js/napi/service_extension_context/service_extension_context.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -79,6 +79,11 @@ class ServiceExtensionContext extends ExtensionContext { return this.__context_impl__.startServiceExtensionAbilityWithAccount(want, accountId, callback); } + startUIAbilities(wantList) { + hilog.sLogI(domainID, TAG, 'startUIAbilities'); + return this.__context_impl__.startUIAbilities(wantList); + } + stopServiceExtensionAbility(want, callback) { hilog.sLogI(domainID, TAG, 'stopServiceExtensionAbility'); return this.__context_impl__.stopServiceExtensionAbility(want, callback); diff --git a/frameworks/js/napi/ui_extension_context/ui_extension_context.js b/frameworks/js/napi/ui_extension_context/ui_extension_context.js index cae8c4be3b..182bd61c1e 100755 --- a/frameworks/js/napi/ui_extension_context/ui_extension_context.js +++ b/frameworks/js/napi/ui_extension_context/ui_extension_context.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 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 @@ -71,6 +71,11 @@ class UIExtensionContext extends ExtensionContext { return this.__context_impl__.startAbilityForResultAsCaller(want, options, callback); } + startUIAbilities(wantList) { + hilog.sLogI(domainID, TAG, 'startUIAbilities'); + return this.__context_impl__.startUIAbilities(wantList); + } + terminateSelfWithResult(abilityResult, callback) { hilog.sLogI(domainID, TAG, 'terminateSelfWithResult'); return this.__context_impl__.terminateSelfWithResult(abilityResult, callback); diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 5fc696de08..1645d49429 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -313,8 +313,10 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", "${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp", + "${ability_runtime_native_path}/ability/native/js_deferred_callback.cpp", "${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp", "${ability_runtime_native_path}/ability/native/js_query_erms_observer.cpp", + "${ability_runtime_native_path}/ability/native/js_start_abilities_observer.cpp", "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", "${ability_runtime_native_path}/ability/native/query_erms_observer_proxy.cpp", "${ability_runtime_native_path}/ability/native/query_erms_observer_stub.cpp", diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index 09a5e85262..f8a89baf39 100644 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -131,6 +131,19 @@ constexpr const char* ERROR_MSG_ALREADY_MASTER_PROCESS = "The current process is already a master process and does not support cancellation."; constexpr const char* ERROR_MSG_NOT_CANDIDATE_MASTER_PROCESS = "The current process is not a candidate master process and does not support cancellation."; +constexpr const char* ERROR_MSG_EXCEEDS_WANT_LIST_MAXIMUM_SIZE = + "A maximum of four UIAbility instances can be started simultaneously." + "The current parameter exceeds the maximum number."; +constexpr const char* ERROR_MSG_TARGET_TYPE_NOT_UI_ABILITY = "The target component type is not a UIAbility."; +constexpr const char* ERROR_MSG_TARGET_BLOCKED_BY_SYSTEM_MODULE = + "The target component is blocked by the system module and does not support startup."; +constexpr const char* ERROR_MSG_NOT_SUPPORT_IMPLICIT_START = "Implicit startup is not supported."; +constexpr const char* ERROR_MSG_NOT_SUPPORT_START_REMOTE_UI_ABILITY = + "Starting a remote UIAbility is not supported."; +constexpr const char* ERROR_MSG_NOT_SUPPORT_START_PLUGIN_UI_ABILITY = + "Starting a plugin UIAbility is not supported."; +constexpr const char* ERROR_MSG_NOT_SUPPORT_START_DLP_FILES = + "Starting DLP files is not supported."; // follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220; @@ -225,6 +238,13 @@ static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_CODE_NOT_ISOLATION_PROCESS, ERROR_MSG_NOT_ISOLATION_PROCESS}, { AbilityErrorCode::ERROR_CODE_ALREADY_MASTER_PROCESS, ERROR_MSG_ALREADY_MASTER_PROCESS}, { AbilityErrorCode::ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS, ERROR_MSG_NOT_CANDIDATE_MASTER_PROCESS }, + { AbilityErrorCode::ERROR_CODE_EXCEEDS_WANT_LIST_MAXIMUM_SIZE, ERROR_MSG_EXCEEDS_WANT_LIST_MAXIMUM_SIZE }, + { AbilityErrorCode::ERROR_CODE_TARGET_TYPE_NOT_UI_ABILITY, ERROR_MSG_TARGET_TYPE_NOT_UI_ABILITY }, + { AbilityErrorCode::ERROR_CODE_TARGET_BLOCKED_BY_SYSTEM_MODULE, ERROR_MSG_TARGET_BLOCKED_BY_SYSTEM_MODULE }, + { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_IMPLICIT_START, ERROR_MSG_NOT_SUPPORT_IMPLICIT_START }, + { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_REMOTE_UI_ABILITY, ERROR_MSG_NOT_SUPPORT_START_REMOTE_UI_ABILITY }, + { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_PLUGIN_UI_ABILITY, ERROR_MSG_NOT_SUPPORT_START_PLUGIN_UI_ABILITY }, + { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_DLP_FILES, ERROR_MSG_NOT_SUPPORT_START_DLP_FILES }, }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -239,6 +259,7 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ABILITY_VISIBLE_FALSE_DENY_REQUEST, AbilityErrorCode::ERROR_CODE_NO_INVISIBLE_PERMISSION}, {ERR_STATIC_CFG_PERMISSION, AbilityErrorCode::ERROR_CODE_STATIC_CFG_PERMISSION}, {ERR_CROSS_USER, AbilityErrorCode::ERROR_CODE_CROSS_USER}, + {START_UI_ABILITIES_NOT_SUPPORT_CROSS_USER, AbilityErrorCode::ERROR_CODE_CROSS_USER}, {ERR_CROWDTEST_EXPIRED, AbilityErrorCode::ERROR_CODE_CROWDTEST_EXPIRED}, {ERR_WOULD_BLOCK, AbilityErrorCode::ERROR_CODE_WUKONG_MODE}, {ERR_INVALID_CONTINUATION_FLAG, AbilityErrorCode::ERROR_CODE_CONTINUATION_FLAG}, @@ -299,6 +320,8 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ERR_UPPER_LIMIT, AbilityErrorCode::ERROR_CODE_UPPER_LIMIT}, {ERR_APP_INSTANCE_KEY_NOT_SUPPORT, AbilityErrorCode::ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORT}, {ERR_CREATE_NEW_INSTANCE_NOT_SUPPORT, AbilityErrorCode::ERROR_CODE_CREATE_NEW_INSTANCE_NOT_SUPPORT}, + {START_UI_ABILITIES_NOT_SUPPORT_CREATE_APP_INSTANCE_KEY, + AbilityErrorCode::ERROR_CODE_CREATE_NEW_INSTANCE_NOT_SUPPORT}, {ERR_UI_ABILITY_IS_STARTING, AbilityErrorCode::ERROR_CODE_UI_ABILITY_IS_STARTING}, {ERR_EXTENSION_START_ABILITY_CONTROLEED, AbilityErrorCode::ERROR_CODE_EXTENSION_START_ABILITY_CONTROLLED}, {ERR_NOT_HOOK, AbilityErrorCode::ERROR_CODE_NOT_HOOK}, @@ -321,6 +344,13 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ERR_NOT_ISOLATION_PROCESS, AbilityErrorCode::ERROR_CODE_NOT_ISOLATION_PROCESS}, {ERR_ALREADY_MASTER_PROCESS, AbilityErrorCode::ERROR_CODE_ALREADY_MASTER_PROCESS}, {ERR_NOT_CANDIDATE_MASTER_PROCESS, AbilityErrorCode::ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS}, + {START_UI_ABILITIES_WANT_LIST_SIZE_ERROR, AbilityErrorCode::ERROR_CODE_EXCEEDS_WANT_LIST_MAXIMUM_SIZE }, + {START_UI_ABILITIES_ONLY_SUPPORT_UI_ABILITY, AbilityErrorCode::ERROR_CODE_TARGET_TYPE_NOT_UI_ABILITY }, + {START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED, AbilityErrorCode::ERROR_CODE_TARGET_BLOCKED_BY_SYSTEM_MODULE }, + {START_UI_ABILITIES_NOT_SUPPORT_IMPLICIT_START, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_IMPLICIT_START }, + {START_UI_ABILITIES_NOT_SUPPORT_OPERATE_REMOTE, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_REMOTE_UI_ABILITY }, + {START_UI_ABILITIES_NOT_SUPPORT_START_PLUGIN, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_PLUGIN_UI_ABILITY }, + {START_UI_ABILITIES_NOT_SUPPORT_DLP, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_START_DLP_FILES }, }; } diff --git a/frameworks/native/ability/native/ability_thread.cpp b/frameworks/native/ability/native/ability_thread.cpp index 4832062a63..b105cd8a8b 100644 --- a/frameworks/native/ability/native/ability_thread.cpp +++ b/frameworks/native/ability/native/ability_thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -301,5 +301,9 @@ void AbilityThread::ScheduleAbilityRequestSuccess(const std::string &requestId, { TAG_LOGD(AAFwkTag::ABILITY, "called"); } + +void AbilityThread::ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) +{ +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/ability/native/extension_ability_thread.cpp b/frameworks/native/ability/native/extension_ability_thread.cpp index d44ae3c676..529323f391 100644 --- a/frameworks/native/ability/native/extension_ability_thread.cpp +++ b/frameworks/native/ability/native/extension_ability_thread.cpp @@ -22,6 +22,7 @@ #include "freeze_util.h" #include "hilog_tag_wrapper.h" #include "hitrace_meter.h" +#include "js_start_abilities_observer.h" #include "ui_extension_utils.h" namespace OHOS { @@ -576,6 +577,28 @@ void ExtensionAbilityThread::SendResult(int requestCode, int resultCode, const W TAG_LOGD(AAFwkTag::EXT, "End"); } +void ExtensionAbilityThread::ScheduleAbilitiesRequestDone(const std::string &requestKey, + const int32_t resultCode) +{ + TAG_LOGD(AAFwkTag::EXT, "ScheduleAbilitiesRequestDone"); + if (abilityHandler_ == nullptr) { + TAG_LOGE(AAFwkTag::EXT, "null abilityHandler_"); + return; + } + + wptr weak = this; + auto task = [weak, requestKey, resultCode]() { + auto abilityThread = weak.promote(); + if (abilityThread == nullptr) { + TAG_LOGE(AAFwkTag::EXT, "null abilityThread"); + return; + } + + JsStartAbilitiesObserver::GetInstance().HandleFinished(requestKey, resultCode); + }; + abilityHandler_->PostTask(task); +} + void ExtensionAbilityThread::NotifyMemoryLevel(int32_t level) { TAG_LOGD(AAFwkTag::EXT, "result: %{public}d", level); diff --git a/frameworks/native/ability/native/js_deferred_callback.cpp b/frameworks/native/ability/native/js_deferred_callback.cpp new file mode 100644 index 0000000000..d56da5b94e --- /dev/null +++ b/frameworks/native/ability/native/js_deferred_callback.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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_deferred_callback.h" + +#include "ability_manager_errors.h" +#include "ability_business_error.h" +#include "hilog_tag_wrapper.h" +#include "js_error_utils.h" +#include "js_runtime_utils.h" + +namespace OHOS { +namespace AbilityRuntime { +JsDeferredCallback::JsDeferredCallback(napi_env env): env_(env) +{ + if (env_ == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "null env_"); + return; + } + napi_create_promise(env_, &deferred_, &result); +} + +void JsDeferredCallback::operator()(int32_t resultCode) +{ + if (deferred_ == nullptr) { + TAG_LOGE(AAFwkTag::ABILITY, "null deferred_"); + return; + } + if (resultCode == ERR_OK) { + napi_value value = CreateJsUndefined(env_); + napi_resolve_deferred(env_, deferred_, value); + } else { + napi_value error = CreateJsError(env_, GetJsErrorCodeByNativeError(resultCode)); + napi_reject_deferred(env_, deferred_, error); + } +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 7cb500eb22..2c33dfca2c 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -24,8 +24,10 @@ #include "js_extension_context.h" #include "js_error_utils.h" #include "js_data_struct_converter.h" +#include "js_deferred_callback.h" #include "js_runtime.h" #include "js_runtime_utils.h" +#include "js_start_abilities_observer.h" #include "napi/native_api.h" #include "napi_common_ability.h" #include "napi_common_want.h" @@ -45,6 +47,7 @@ constexpr int32_t INDEX_ZERO = 0; constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_TWO = 2; constexpr int32_t INDEX_THREE = 3; +constexpr int32_t INDEX_FOUR = 4; constexpr int32_t ERROR_CODE_ONE = 1; constexpr int32_t ERROR_CODE_TWO = 2; constexpr size_t ARGC_ZERO = 0; @@ -128,6 +131,11 @@ public: GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnStartAbilityWithAccount); } + static napi_value StartUIAbilities(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnStartUIAbilities); + } + static napi_value ConnectAbilityWithAccount(napi_env env, napi_callback_info info) { GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnConnectAbilityWithAccount); @@ -809,6 +817,84 @@ private: return true; } + napi_value OnStartUIAbilities(napi_env env, NapiCallbackInfo& info) + { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "call OnStartUIAbilities"); + if (info.argc < ARGC_ONE) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "Too few parameters."); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + std::vector wantList; + std::string requestKey = std::to_string(std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count()); + + if (!UnwrapWantList(env, info, wantList)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "Unwrap wantList param failed."); + return CreateJsUndefined(env); + } + + TAG_LOGD(AAFwkTag::SERVICE_EXT, "startUIAbilities wantListLength: %{public}zu", wantList.size()); + + JsDeferredCallback callback(env); + JsStartAbilitiesObserver::GetInstance().AddObserver(requestKey, callback); + auto innerErrCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [weak = context_, wantList, requestKey, innerErrCode]() { + auto context = weak.lock(); + if (!context) { + TAG_LOGW(AAFwkTag::SERVICE_EXT, "null context"); + *innerErrCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return; + } + *innerErrCode = context->StartUIAbilities(wantList, requestKey); + }; + + NapiAsyncTask::CompleteCallback complete = [innerErrCode, weak = context_, requestKey] + (napi_env, NapiAsyncTask&, int32_t) { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "startUIAbilities complete innerErrCode: %{public}d", *innerErrCode); + if (*innerErrCode == AAFwk::START_UI_ABILITIES_WAITING_SPECIFIED_CODE) { + TAG_LOGI(AAFwkTag::SERVICE_EXT, "startUIAbilities waiting specified."); + return; + } + JsStartAbilitiesObserver::GetInstance().HandleFinished(requestKey, *innerErrCode); + }; + + NapiAsyncTask::ScheduleHighQos("JSServiceExtensionContext::OnStartUIAbilities", env, + CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), nullptr)); + return callback.result; + } + + bool UnwrapWantList(napi_env env, NapiCallbackInfo &info, std::vector &wantList) + { + AppExecFwk::ComplexArrayData jsWantList; + if (!AppExecFwk::UnwrapArrayComplexFromJS(env, info.argv[INDEX_ZERO], jsWantList)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "wantList not array."); + ThrowInvalidParamError(env, "WantList is not an array."); + return false; + } + + size_t jsWantSize = jsWantList.objectList.size(); + if (jsWantSize < INDEX_ONE || jsWantSize > INDEX_FOUR) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "wantList size not support"); + ThrowErrorByNativeErr(env, AAFwk::START_UI_ABILITIES_WANT_LIST_SIZE_ERROR); + return false; + } + + for (uint32_t index = 0; index < jsWantSize; index++) { + AAFwk::Want curWant; + if (!OHOS::AppExecFwk::UnwrapWant(env, jsWantList.objectList[index], curWant)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "startUIAbilities parse want failed"); + ThrowInvalidParamError(env, "Parse param want failed, want must be Want."); + return false; + } + TAG_LOGD(AAFwkTag::SERVICE_EXT, "startUIAbilities ability:%{public}s", + curWant.GetElement().GetAbilityName().c_str()); + wantList.emplace_back(curWant); + } + return true; + } + bool CheckConnectAbilityWithAccountInputParam( napi_env env, NapiCallbackInfo& info, AAFwk::Want& want, int32_t& accountId, sptr& connection) const @@ -1470,12 +1556,12 @@ napi_value CreateJsServiceExtensionContext(napi_env env, std::shared_ptr &&callback) +{ + std::lock_guard lock(jsObserverObjectListLock_); + jsObserverObjectList_.emplace(requestKey, std::move(callback)); +} + +void JsStartAbilitiesObserver::HandleFinished(const std::string &requestKey, int32_t resultCode) +{ + std::function callback; + { + std::lock_guard lock(jsObserverObjectListLock_); + auto it = jsObserverObjectList_.find(requestKey); + if (it != jsObserverObjectList_.end()) { + callback = std::move(it->second); + jsObserverObjectList_.erase(it); + } + } + if (callback) { + callback(resultCode); + return; + } + TAG_LOGE(AAFwkTag::ABILITY, "null callback"); +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ability/native/ui_extension_base/js_ui_extension_context.cpp b/frameworks/native/ability/native/ui_extension_base/js_ui_extension_context.cpp index 14efb57ff1..e5e8e580ba 100755 --- a/frameworks/native/ability/native/ui_extension_base/js_ui_extension_context.cpp +++ b/frameworks/native/ability/native/ui_extension_base/js_ui_extension_context.cpp @@ -26,8 +26,10 @@ #include "js_extension_context.h" #include "js_error_utils.h" #include "js_data_struct_converter.h" +#include "js_deferred_callback.h" #include "js_runtime.h" #include "js_runtime_utils.h" +#include "js_start_abilities_observer.h" #include "js_uiservice_uiext_connection.h" #include "js_ui_service_proxy.h" #include "napi/native_api.h" @@ -51,6 +53,7 @@ constexpr int32_t INDEX_ZERO = 0; constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_TWO = 2; constexpr int32_t INDEX_THREE = 3; +constexpr int32_t INDEX_FOUR = 4; constexpr size_t ARGC_ZERO = 0; constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; @@ -144,6 +147,11 @@ napi_value JsUIExtensionContext::StartAbilityForResultAsCaller(napi_env env, nap GET_NAPI_INFO_AND_CALL(env, info, JsUIExtensionContext, OnStartAbilityForResultAsCaller); } +napi_value JsUIExtensionContext::StartUIAbilities(napi_env env, napi_callback_info info) +{ + GET_NAPI_INFO_AND_CALL(env, info, JsUIExtensionContext, OnStartUIAbilities); +} + napi_value JsUIExtensionContext::TerminateSelfWithResult(napi_env env, napi_callback_info info) { GET_NAPI_INFO_AND_CALL(env, info, JsUIExtensionContext, OnTerminateSelfWithResult); @@ -564,6 +572,84 @@ napi_value JsUIExtensionContext::OnStartAbilityForResultAsCaller(napi_env env, N return result; } +napi_value JsUIExtensionContext::OnStartUIAbilities(napi_env env, NapiCallbackInfo& info) +{ + TAG_LOGI(AAFwkTag::UI_EXT, "call OnStartUIAbilities"); + if (info.argc < ARGC_ONE) { + TAG_LOGE(AAFwkTag::UI_EXT, "Too few parameters."); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + std::vector wantList; + std::string requestKey = std::to_string(std::chrono::duration_cast(std::chrono:: + system_clock::now().time_since_epoch()).count()); + + if (!UnwrapWantList(env, info, wantList)) { + TAG_LOGE(AAFwkTag::UI_EXT, "Unwrap wantList param failed."); + return CreateJsUndefined(env); + } + + TAG_LOGD(AAFwkTag::UI_EXT, "startUIAbilities wantListLength: %{public}zu", wantList.size()); + + JsDeferredCallback callback(env); + JsStartAbilitiesObserver::GetInstance().AddObserver(requestKey, callback); + auto innerErrCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [weak = context_, wantList, requestKey, innerErrCode]() { + auto context = weak.lock(); + if (!context) { + TAG_LOGW(AAFwkTag::UI_EXT, "null context"); + *innerErrCode = static_cast(AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return; + } + *innerErrCode = context->StartUIAbilities(wantList, requestKey); + }; + + NapiAsyncTask::CompleteCallback complete = [innerErrCode, weak = context_, requestKey] + (napi_env, NapiAsyncTask&, int32_t) { + TAG_LOGI(AAFwkTag::UI_EXT, "startUIAbilities complete innerErrCode: %{public}d", *innerErrCode); + if (*innerErrCode == AAFwk::START_UI_ABILITIES_WAITING_SPECIFIED_CODE) { + TAG_LOGI(AAFwkTag::UI_EXT, "startUIAbilities waiting specified."); + return; + } + JsStartAbilitiesObserver::GetInstance().HandleFinished(requestKey, *innerErrCode); + }; + + NapiAsyncTask::ScheduleHighQos("JSUIExtensionConnection::OnStartUIAbilities", env, + CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), nullptr)); + return callback.result; +} + +bool JsUIExtensionContext::UnwrapWantList(napi_env env, NapiCallbackInfo &info, std::vector &wantList) +{ + AppExecFwk::ComplexArrayData jsWantList; + if (!AppExecFwk::UnwrapArrayComplexFromJS(env, info.argv[INDEX_ZERO], jsWantList)) { + TAG_LOGE(AAFwkTag::UI_EXT, "wantList not array."); + ThrowInvalidParamError(env, "WantList is not an array."); + return false; + } + + size_t jsWantSize = jsWantList.objectList.size(); + if (jsWantSize < INDEX_ONE || jsWantSize > INDEX_FOUR) { + TAG_LOGE(AAFwkTag::UI_EXT, "wantList size not support"); + ThrowErrorByNativeErr(env, AAFwk::START_UI_ABILITIES_WANT_LIST_SIZE_ERROR); + return false; + } + + for (uint32_t index = 0; index < jsWantSize; index++) { + AAFwk::Want curWant; + if (!OHOS::AppExecFwk::UnwrapWant(env, jsWantList.objectList[index], curWant)) { + TAG_LOGE(AAFwkTag::UI_EXT, "startUIAbilities parse want failed"); + ThrowInvalidParamError(env, "Parse param want failed, want must be Want."); + return false; + } + TAG_LOGD(AAFwkTag::UI_EXT, "startUIAbilities ability:%{public}s", + curWant.GetElement().GetAbilityName().c_str()); + wantList.emplace_back(curWant); + } + return true; +} + napi_value JsUIExtensionContext::OnConnectAbility(napi_env env, NapiCallbackInfo& info) { TAG_LOGD(AAFwkTag::UI_EXT, "called"); @@ -1331,6 +1417,7 @@ napi_value JsUIExtensionContext::CreateJsUIExtensionContext(napi_env env, BindNativeFunction(env, objValue, "startAbilityForResult", moduleName, StartAbilityForResult); BindNativeFunction(env, objValue, "terminateSelfWithResult", moduleName, TerminateSelfWithResult); BindNativeFunction(env, objValue, "startAbilityForResultAsCaller", moduleName, StartAbilityForResultAsCaller); + BindNativeFunction(env, objValue, "startUIAbilities", moduleName, StartUIAbilities); BindNativeFunction(env, objValue, "connectServiceExtensionAbility", moduleName, ConnectAbility); BindNativeFunction(env, objValue, "disconnectServiceExtensionAbility", moduleName, DisconnectAbility); BindNativeFunction(env, objValue, "reportDrawnCompleted", moduleName, ReportDrawnCompleted); diff --git a/frameworks/native/ability/native/ui_extension_base/ui_extension_context.cpp b/frameworks/native/ability/native/ui_extension_base/ui_extension_context.cpp index 27cfbbf3ed..01b59a0747 100755 --- a/frameworks/native/ability/native/ui_extension_base/ui_extension_context.cpp +++ b/frameworks/native/ability/native/ui_extension_base/ui_extension_context.cpp @@ -136,6 +136,13 @@ ErrCode UIExtensionContext::StartServiceExtensionAbility(const AAFwk::Want& want return ret; } +ErrCode UIExtensionContext::StartUIAbilities(const std::vector &wantList, const std::string &requestKey) +{ + TAG_LOGD(AAFwkTag::UI_EXT, "call StartUIAbilities"); + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartUIAbilities(wantList, requestKey, token_); + return err; +} + ErrCode UIExtensionContext::StartAbilityForResult(const AAFwk::Want &want, int requestCode, RuntimeTask &&task) { TAG_LOGD(AAFwkTag::UI_EXT, "begin"); diff --git a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp index d391de66e5..993ff5a475 100644 --- a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp +++ b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp @@ -154,6 +154,14 @@ ErrCode ServiceExtensionContext::StartAbilityWithAccount( return err; } +ErrCode ServiceExtensionContext::StartUIAbilities(const std::vector &wantList, + const std::string &requestKey) +{ + TAG_LOGD(AAFwkTag::APPKIT, "call StartUIAbilities"); + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartUIAbilities(wantList, requestKey, token_); + return err; +} + ErrCode ServiceExtensionContext::StartServiceExtensionAbility(const AAFwk::Want &want, int32_t accountId) const { TAG_LOGD(AAFwkTag::APPKIT, "begin"); 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 ad5f9d31b8..db8e8e1112 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -284,6 +284,17 @@ public: int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE); + /** + * Start UI abilities simultaneously. + * + * @param wantList a list of want to start UI abilities. + * @param requestKey, The unique key of this StartUIAbilities request. + * @param callerToken current caller ability token. + * @return Returns ERR_OK if success. + */ + ErrCode StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken); + /** * Start ui session ability with extension session info, send session info to ability manager service. * diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 4f60741dc1..568986bed6 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -923,6 +923,36 @@ enum { */ ERR_NOT_CANDIDATE_MASTER_PROCESS = 2097366, + /** + * Result (2097370-2097379) for StartUIAbilities Error. + */ + START_UI_ABILITIES_NOT_SUPPORT_DLP = 2097370, + + START_UI_ABILITIES_NOT_SUPPORT_START_PLUGIN = 2097371, + + START_UI_ABILITIES_NOT_SUPPORT_CREATE_APP_INSTANCE_KEY = 2097372, + + START_UI_ABILITIES_NOT_SUPPORT_OPERATE_REMOTE = 2097373, + + START_UI_ABILITIES_NOT_SUPPORT_CROSS_USER = 2097374, + + START_UI_ABILITIES_NOT_SUPPORT_IMPLICIT_START = 2097375, + + START_UI_ABILITIES_ONLY_SUPPORT_UI_ABILITY = 2097376, + + START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED = 2097377, + + START_UI_ABILITIES_WAITING_SPECIFIED_CODE = 2097378, + + START_UI_ABILITIES_WANT_LIST_SIZE_ERROR = 2097379, + + /* + * Result(2097380) for IPC write Int32 failed. + */ + ERR_WRITE_INT32_FAILED = 2097380, + + ERR_WRITE_STRING_FAILED = 2097381, + /** * Native error(3000000) for target bundle not exist. */ 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 984f313c71..84bb4815ed 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -304,6 +304,20 @@ public: return 0; } + /** + * Start UI abilities simultaneously. + * + * @param wantList a list of want to start UI abilities. + * @param requestKey, The unique key of this StartUIAbilities request. + * @param callerToken current caller ability token. + * @return Returns ERR_OK if success. + */ + virtual ErrCode StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken) + { + return 0; + } + /** * Start ui session ability with extension session info, send session info to ability manager service. * 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 2ee34a410a..37a97fecfc 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 @@ -420,6 +420,9 @@ enum class AbilityManagerInterfaceCode { SET_ON_NEW_WANT_SKIP_SCENARIOS = 1071, + // ipc id for start UI abilities + START_UI_ABILITIES = 1072, + // ipc id for continue ability(1101) START_CONTINUATION = 1101, 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 a9365cf1c3..f1be91f337 100644 --- a/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_scheduler_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -312,6 +312,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) = 0; + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, + int32_t resultCode) = 0; + enum { // ipc id for scheduling ability to a state of life cycle SCHEDULE_ABILITY_TRANSACTION = 0, @@ -413,7 +416,9 @@ public: SCHEDULE_ABILITY_REQUEST_FAILURE, - SCHEDULE_ABILITY_REQUEST_SUCCESS + SCHEDULE_ABILITY_REQUEST_SUCCESS, + + SCHEDULE_ABILITIES_REQUEST_DONE, }; }; } // namespace AAFwk diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 4db6cf767e..fc00e2a877 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -268,6 +268,20 @@ enum class AbilityErrorCode { ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS = 16000117, + ERROR_CODE_EXCEEDS_WANT_LIST_MAXIMUM_SIZE = 16000120, + + ERROR_CODE_TARGET_TYPE_NOT_UI_ABILITY = 16000121, + + ERROR_CODE_TARGET_BLOCKED_BY_SYSTEM_MODULE = 16000122, + + ERROR_CODE_NOT_SUPPORT_IMPLICIT_START = 16000123, + + ERROR_CODE_NOT_SUPPORT_START_REMOTE_UI_ABILITY = 16000124, + + ERROR_CODE_NOT_SUPPORT_START_PLUGIN_UI_ABILITY = 16000125, + + ERROR_CODE_NOT_SUPPORT_START_DLP_FILES = 16000126, + // target bundle is not in u1 ERROR_CODE_NO_U1 = 16000204, diff --git a/interfaces/kits/native/ability/native/ability_thread.h b/interfaces/kits/native/ability/native/ability_thread.h index 6dd0fe9cde..8ce76dc496 100644 --- a/interfaces/kits/native/ability/native/ability_thread.h +++ b/interfaces/kits/native/ability/native/ability_thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -364,6 +364,8 @@ public: void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override; + void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override; + sptr token_; std::shared_ptr abilityHandler_ = nullptr; std::shared_ptr runner_ = nullptr; diff --git a/interfaces/kits/native/ability/native/extension_ability_thread.h b/interfaces/kits/native/ability/native/extension_ability_thread.h index 7df082e083..7b166680de 100644 --- a/interfaces/kits/native/ability/native/extension_ability_thread.h +++ b/interfaces/kits/native/ability/native/extension_ability_thread.h @@ -135,6 +135,8 @@ public: void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override; + void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override; + private: /** * @brief Dump Ability Info Inner diff --git a/interfaces/kits/native/ability/native/js_deferred_callback.h b/interfaces/kits/native/ability/native/js_deferred_callback.h new file mode 100644 index 0000000000..ac2a5b217a --- /dev/null +++ b/interfaces/kits/native/ability/native/js_deferred_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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_DEFERRED_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_JS_DEFERRED_CALLBACK_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +struct JsDeferredCallback { +public: + explicit JsDeferredCallback(napi_env env); + void operator()(int32_t resultCode); + + napi_value result = nullptr; + +private: + napi_env env_ = nullptr; + napi_deferred deferred_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_JS_DEFERRED_CALLBACK_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/js_start_abilities_observer.h b/interfaces/kits/native/ability/native/js_start_abilities_observer.h new file mode 100644 index 0000000000..1bbce54816 --- /dev/null +++ b/interfaces/kits/native/ability/native/js_start_abilities_observer.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 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_START_ABILITIES_OBSERVER_H +#define OHOS_ABILITY_RUNTIME_JS_START_ABILITIES_OBSERVER_H + +#include +#include +#include +#include + +namespace OHOS { +namespace AbilityRuntime { +class JsStartAbilitiesObserver { +public: + static JsStartAbilitiesObserver &GetInstance(); + ~JsStartAbilitiesObserver() = default; + void AddObserver(const std::string &requestKey, std::function &&callback); + void HandleFinished(const std::string &requestKey, int32_t resultCode); +protected: + JsStartAbilitiesObserver() = default; +private: + std::mutex jsObserverObjectListLock_; + std::map> jsObserverObjectList_; +}; +} // namespace AbilityRuntime +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_JS_START_ABILITIES_OBSERVER_H \ No newline at end of file diff --git a/interfaces/kits/native/ability/native/ui_extension_base/js_ui_extension_context.h b/interfaces/kits/native/ability/native/ui_extension_base/js_ui_extension_context.h index 041003c4cb..3d6f5661a0 100755 --- a/interfaces/kits/native/ability/native/ui_extension_base/js_ui_extension_context.h +++ b/interfaces/kits/native/ability/native/ui_extension_base/js_ui_extension_context.h @@ -40,6 +40,7 @@ public: static napi_value CreateJsUIExtensionContext(napi_env env, std::shared_ptr context); static napi_value StartAbilityForResult(napi_env env, napi_callback_info info); static napi_value StartAbilityForResultAsCaller(napi_env env, napi_callback_info info); + static napi_value StartUIAbilities(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 ReportDrawnCompleted(napi_env env, napi_callback_info info); @@ -60,6 +61,7 @@ protected: virtual napi_value OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo& info); virtual napi_value OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info); virtual napi_value OnStartAbilityForResultAsCaller(napi_env env, NapiCallbackInfo &info); + virtual napi_value OnStartUIAbilities(napi_env env, NapiCallbackInfo& info); virtual napi_value OnConnectAbility(napi_env env, NapiCallbackInfo& info); virtual napi_value OnDisconnectAbility(napi_env env, NapiCallbackInfo& info); virtual napi_value OnReportDrawnCompleted(napi_env env, NapiCallbackInfo& info); @@ -93,6 +95,7 @@ private: const AAFwk::StartOptions &options, size_t unwrapArgc); void AddFreeInstallObserver(napi_env env, const AAFwk::Want &want, napi_value callback, napi_value* result, bool isAbilityResult = false, bool isOpenLink = false); + bool UnwrapWantList(napi_env env, NapiCallbackInfo &info, std::vector &wantList); bool CreateOpenLinkTask(const napi_env &env, const napi_value &lastParam, AAFwk::Want &want, int &requestCode); napi_value OnOpenLink(napi_env env, NapiCallbackInfo& info); diff --git a/interfaces/kits/native/ability/native/ui_extension_base/ui_extension_context.h b/interfaces/kits/native/ability/native/ui_extension_base/ui_extension_context.h index e1d2c24f7e..8890c260ed 100755 --- a/interfaces/kits/native/ability/native/ui_extension_base/ui_extension_context.h +++ b/interfaces/kits/native/ability/native/ui_extension_base/ui_extension_context.h @@ -98,6 +98,8 @@ public: */ ErrCode StartServiceExtensionAbility(const AAFwk::Want &want, int32_t accountId = -1); + ErrCode StartUIAbilities(const std::vector &wantList, const std::string &requestKey); + /** * Start other ability for result. * diff --git a/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h b/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h index bd66558ba3..7f58104bd8 100644 --- a/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h @@ -122,6 +122,8 @@ public: ErrCode StartAbilityWithAccount( const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const; + + ErrCode StartUIAbilities(const std::vector &wantList, const std::string &requestKey); ErrCode StartServiceExtensionAbility(const AAFwk::Want &want, int32_t accountId = -1) const; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 10fb1eacb9..9aad7b8d1e 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -216,6 +216,17 @@ public: int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE) override; + /** + * Start UI abilities simultaneously. + * + * @param wantList a list of want to start UI abilities. + * @param requestKey, The unique key of this StartUIAbilities request. + * @param callerToken current caller ability token. + * @return Returns ERR_OK if success. + */ + ErrCode StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken) override; + /** * Start ui session ability with extension session info, send session info to ability manager service. * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 98ac7c2412..63e2b4b6a1 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -335,6 +335,17 @@ public: int requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE) override; + /** + * Start UI abilities simultaneously. + * + * @param wantList a list of want to start UI abilities. + * @param requestKey, The unique key of this StartUIAbilities request. + * @param callerToken current caller ability token. + * @return Returns ERR_OK if success. + */ + ErrCode StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken) override; + /** * Start ui session ability with extension session info, send session info to ability manager service. * @@ -1262,8 +1273,6 @@ public: void RemoveSelectorIdentity(int32_t tokenId); - void SetTargetCloneIndexInSameBundle(const Want &want, sptr callerToken); - virtual int RegisterAbilityFirstFrameStateObserver(const sptr &observer, const std::string &bundleName) override; @@ -2545,6 +2554,11 @@ private: virtual int RegisterSessionHandler(const sptr &object) override; + int32_t StartUIAbilitiesHandleWant(const Want &want, sptr callerToken, + std::vector &abilityRequestList); + int32_t StartUIAbilitiesCheckDlp(const Want &want, sptr callerToken, int32_t userId); + int32_t StartUIAbilitiesInterceptorCheck(const Want &want, AbilityRequest &abilityRequest, + sptr callerToken, int32_t appIndex); /** * Start switch user dialog Extension ability. */ diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 4a75d14956..2181b8adb0 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -296,6 +296,7 @@ private: int StartAbilityForResultAsCallerInner(MessageParcel &data, MessageParcel &reply); int StartAbilityForResultAsCallerForOptionsInner(MessageParcel &data, MessageParcel &reply); + int32_t StartUIAbilitiesInner(MessageParcel &data, MessageParcel &reply); int32_t StartAbilityOnlyUIAbilityInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index dd86c57283..be8158b0c4 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1182,6 +1182,7 @@ public: const std::string &message); void NotifyAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element); + void NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode); void ScheduleCollaborate(const Want &want); diff --git a/services/abilitymgr/include/ability_scheduler_proxy.h b/services/abilitymgr/include/ability_scheduler_proxy.h index e25c6ac659..c1412b08bc 100644 --- a/services/abilitymgr/include/ability_scheduler_proxy.h +++ b/services/abilitymgr/include/ability_scheduler_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -338,6 +338,8 @@ public: void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override; + void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override; + private: bool WriteInterfaceToken(MessageParcel &data); int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); diff --git a/services/abilitymgr/include/ability_scheduler_stub.h b/services/abilitymgr/include/ability_scheduler_stub.h index e85b2d94fa..4c32117470 100644 --- a/services/abilitymgr/include/ability_scheduler_stub.h +++ b/services/abilitymgr/include/ability_scheduler_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -82,6 +82,7 @@ private: int CollaborateDataInner(MessageParcel &data); int ScheduleAbilityRequestFailureInner(MessageParcel &data); int ScheduleAbilityRequestSuccessInner(MessageParcel &data); + int ScheduleAbilitiesRequestDoneInner(MessageParcel &data); }; /** diff --git a/services/abilitymgr/include/lifecycle_deal.h b/services/abilitymgr/include/lifecycle_deal.h index 85132710b3..f0082b7633 100644 --- a/services/abilitymgr/include/lifecycle_deal.h +++ b/services/abilitymgr/include/lifecycle_deal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -89,6 +89,7 @@ public: void NotifyAbilityRequestFailure(const std::string &requestId, const AppExecFwk::ElementName &element, const std::string &message); void NotifyAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element); + void NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode); 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 13f6d6db75..bdb93551ba 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -46,6 +46,7 @@ struct SpecifiedRequest { SpecifiedProcessState specifiedProcessState = SpecifiedProcessState::STATE_NONE; int32_t requestId = 0; int32_t persistentId = 0; + int32_t requestListId = -1; uint32_t sceneFlag = 0; uint32_t callingTokenId = 0; AbilityRequest abilityRequest; @@ -53,6 +54,14 @@ struct SpecifiedRequest { SpecifiedRequest(int32_t requestId, AbilityRequest request) : requestId(requestId), abilityRequest(request) {} }; +struct AbilitiesRequest { + int32_t requestListId = -1; + std::string requestKey; + std::vector>> sessionInfoList; + uint32_t doneCount = 0; + sptr callerToken; +}; + class UIAbilityLifecycleManager : public std::enable_shared_from_this { public: UIAbilityLifecycleManager() = default; @@ -155,6 +164,8 @@ public: void SetRootSceneSession(const sptr &rootSceneSession); int NotifySCBToStartUIAbility(AbilityRequest &abilityRequest); + int32_t NotifySCBToStartUIAbilities(std::vector &abilityRequestList, + const std::string &requestKey); int NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest, sptr &sessionInfo); @@ -429,6 +440,8 @@ private: sptr CreateSessionInfo(const AbilityRequest &abilityRequest) const; int NotifySCBPendingActivation(sptr &sessionInfo, const AbilityRequest &abilityRequest, std::string &errMsg); + int32_t BatchNotifySCBPendingActivations(const AbilitiesRequest &abilitiesRequest); + void HandleAbilitiesRequestDone(int32_t requestId, int32_t requestListId, sptr sessionInfo); bool IsHookModule(const AbilityRequest &abilityRequest) const; int ResolveAbility(const std::shared_ptr &targetAbility, const AbilityRequest &abilityRequest) const; std::vector> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element); @@ -437,11 +450,11 @@ private: void NotifyStartSpecifiedAbility(AbilityRequest &request, const AAFwk::Want &want); void NotifyRestartSpecifiedAbility(const AbilityRequest &request, const sptr &token); - int MoveAbilityToFront(const AbilityRequest &abilityRequest, const std::shared_ptr &abilityRecord, - std::shared_ptr callerAbility, std::shared_ptr startOptions, int32_t requestId); + int32_t MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + const std::shared_ptr abilityRecord, std::shared_ptr callerAbility); int SendSessionInfoToSCB(std::shared_ptr &callerAbility, sptr &sessionInfo); - int StartAbilityBySpecifed(const AbilityRequest &abilityRequest, std::shared_ptr &callerAbility, - int32_t requestId); + int32_t StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility); void SetLastExitReason(std::shared_ptr &abilityRecord) const; void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr &abilityRecord) const; @@ -489,7 +502,7 @@ private: bool HandleStartSpecifiedCold(AbilityRequest &abilityRequest, sptr sessionInfo, uint32_t sceneFlag); bool HandleColdAcceptWantDone(const AAFwk::Want &want, const std::string &flag, const SpecifiedRequest &specifiedRequest); - void HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, + void HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want); std::shared_ptr GetSpecifiedRequest(int32_t requestId); bool CheckPrepareTerminateTokens(const std::vector> &tokens, @@ -504,7 +517,11 @@ private: std::shared_ptr uiAbilityRecord, bool isColdStart); bool TryProcessHookModule(SpecifiedRequest &specifiedRequest, bool isHookModule); bool IsStartSpecifiedProcessRequest(const AbilityRequest &abilityRequest); - int32_t StartSpecifiedProcessRequest(const AbilityRequest &abilityRequest); + int32_t StartSpecifiedProcessRequest(const AbilityRequest &abilityRequest, + std::shared_ptr abilitiesRequest); + int32_t HandleUIAbilityRequestList(std::vector &abilityRequestList); + void HandleAbilitiesNormalSessionInfo(AbilityRequest &abilityRequest, + std::shared_ptr abilitiesRequest, int32_t requestId); void RemoveInstanceKey(const AbilityRequest &abilityRequest) const; int32_t userId_ = -1; @@ -544,6 +561,7 @@ private: std::vector> prepareTerminateByPidRecords_; std::unordered_map> hookSpecifiedMap_; + std::map> abilitiesRequestMap_; std::mutex startingPidsMutex_; std::vector startingPids_; }; diff --git a/services/abilitymgr/include/utils/start_ability_utils.h b/services/abilitymgr/include/utils/start_ability_utils.h index f6a62e2cb5..8129583fb4 100644 --- a/services/abilitymgr/include/utils/start_ability_utils.h +++ b/services/abilitymgr/include/utils/start_ability_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -59,6 +59,9 @@ struct StartAbilityUtils { static std::vector GetCloneAppIndexes(const std::string &bundleName, int32_t userId); static bool IsCallFromAncoShellOrBroker(const sptr &callerToken); + static void SetTargetCloneIndexInSameBundle(const Want &want, sptr callerToken); + static int32_t StartUIAbilitiesProcessAppIndex(Want &want, + sptr callerToken, int32_t &appIndex); static thread_local std::shared_ptr startAbilityInfo; static thread_local std::shared_ptr callerAbilityInfo; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 679c9b6ba5..c8804eed1f 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -261,6 +261,19 @@ ErrCode AbilityManagerClient::StartAbilityForResultAsCaller(const Want &want, co return abms->StartAbilityForResultAsCaller(want, startOptions, callerToken, requestCode, userId); } +ErrCode AbilityManagerClient::StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGI(AAFwkTag::ABILITYMGR, "call StartUIAbilities"); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + for (const Want &item : wantList) { + HandleDlpApp(const_cast(item)); + } + return abms->StartUIAbilities(wantList, requestKey, callerToken); +} + ErrCode AbilityManagerClient::StartAbilityByUIContentSession(const Want &want, const StartOptions &startOptions, sptr callerToken, sptr sessionInfo, int requestCode, int32_t userId) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 18b0d31a77..188d5a5f4a 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -41,8 +41,11 @@ namespace { } using AutoStartupInfo = AbilityRuntime::AutoStartupInfo; constexpr int32_t CYCLE_LIMIT = 1000; +constexpr int32_t INDEX_ONE = 1; constexpr int32_t MAX_AUTO_STARTUP_COUNT = 100; constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100; +constexpr int32_t MAX_WANT_LIST_SIZE = 4; +constexpr int32_t MAX_IPC_CAPACITY_FOR_WANT_LIST = 4 * 216 * 1024; bool AbilityManagerProxy::WriteInterfaceToken(MessageParcel &data) { if (!data.WriteInterfaceToken(AbilityManagerProxy::GetDescriptor())) { @@ -507,6 +510,58 @@ int AbilityManagerProxy::StartAbilityForResultAsCaller(const Want &want, const S return reply.ReadInt32(); } +ErrCode AbilityManagerProxy::StartUIAbilities(const std::vector &wantList, + const std::string &requestKey, sptr callerToken) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (callerToken == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken"); + return INVALID_CALLER_TOKEN; + } + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail"); + return ERR_WRITE_INTERFACE_TOKEN_FAILED; + } + + int32_t size = static_cast(wantList.size()); + if (size < INDEX_ONE || size > MAX_WANT_LIST_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "vector size error"); + return START_UI_ABILITIES_WANT_LIST_SIZE_ERROR; + } + + (data).SetMaxCapacity(MAX_IPC_CAPACITY_FOR_WANT_LIST); + + if (!data.WriteInt32(size)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write size fail"); + return ERR_WRITE_INT32_FAILED; + } + for (const Want &item : wantList) { + if (!data.WriteParcelable(&item)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail"); + return ERR_WRITE_WANT; + } + } + + if (!data.WriteString(requestKey)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestKey fail"); + return ERR_WRITE_STRING_FAILED; + } + + if (!data.WriteRemoteObject(callerToken)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail"); + return ERR_WRITE_CALLER_TOKEN_FAILED; + } + + auto error = SendRequest(AbilityManagerInterfaceCode::START_UI_ABILITIES, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error); + return error; + } + return reply.ReadInt32(); +} + int AbilityManagerProxy::CheckUISessionParams(MessageParcel &data, const sptr &callerToken, const sptr &sessionInfo, int32_t userId, int requestCode) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a7f5e4f69f..2748e40f8f 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -201,6 +201,7 @@ constexpr size_t INDEX_ZERO = 0; constexpr size_t INDEX_ONE = 1; constexpr size_t INDEX_TWO = 2; constexpr size_t ARGC_THREE = 3; +constexpr size_t INDEX_FOUR = 4; constexpr static char WANT_PARAMS_VIEW_DATA_KEY[] = "ohos.ability.params.viewData"; constexpr const char* WANT_PARAMS_HOST_WINDOW_ID_KEY = "ohos.extra.param.key.hostwindowid"; @@ -1188,7 +1189,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr &wantList, + const std::string &requestKey, sptr callerToken) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + XCOLLIE_TIMER_DEFAULT(__PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call StartUIAbilities"); + std::vector abilityRequestList; + int32_t oriValidUserId = GetValidUserId(DEFAULT_INVAL_VALUE); + + if (!AppUtils::GetInstance().IsSupportStartAbilities() || + !Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities is not supported"); + return ERR_CAPABILITY_NOT_SUPPORT; + } + + if (wantList.size() < INDEX_ONE || wantList.size() > INDEX_FOUR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities wantList size not support"); + return START_UI_ABILITIES_WANT_LIST_SIZE_ERROR; + } + + if (callerToken == nullptr || !VerificationAllToken(callerToken)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities %{public}s verificationAllToken failed", __func__); + return ERR_INVALID_CALLER; + } + + for (const Want &want : wantList) { + int32_t ret = StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities want process block"); + return ret; + } + } + + TAG_LOGD(AAFwkTag::ABILITYMGR, "StartUIAbilities ready to NotifySCBToStartUIAbilities"); + for (AbilityRequest &abilityRequest : abilityRequestList) { + auto abilityInfo = abilityRequest.abilityInfo; + ReportEventToRSS(abilityInfo, abilityRequest.callerToken); + abilityRequest.userId = oriValidUserId; + abilityRequest.want.SetParam(ServerConstant::IS_CALL_BY_SCB, false); + } + auto uiAbilityManager = GetUIAbilityManagerByUserId(oriValidUserId); + CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); + return uiAbilityManager->NotifySCBToStartUIAbilities(abilityRequestList, requestKey); +} + +int32_t AbilityManagerService::StartUIAbilitiesHandleWant(const Want &want, sptr callerToken, + std::vector &abilityRequestList) +{ + int32_t userId = DEFAULT_INVAL_VALUE; + int32_t validUserId = GetValidUserId(userId); + uint32_t specifyTokenId = 0; + int32_t requestCode = DEFAULT_INVAL_VALUE; + + AbilityUtil::RemoveShowModeKey(const_cast(want)); + + if (!want.HasParameter(AppExecFwk::INSIGHT_INTENT_EXECUTE_OPENLINK_FLAG)) { + InsightIntentExecuteParam::RemoveInsightIntent(const_cast(want)); + } + +#ifdef SUPPORT_SCREEN + DmsUtil::GetInstance().UpdateFlagForCollaboration(want); +#endif + + if (AbilityRuntime::StartupUtil::IsStartPlugin(want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities not support StartPlugin"); + return START_UI_ABILITIES_NOT_SUPPORT_START_PLUGIN; + } + + AbilityUtil::RemoveWindowModeKey(const_cast(want)); + + if (want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities not support CREATE_APP_INSTANCE_KEY"); + return START_UI_ABILITIES_NOT_SUPPORT_CREATE_APP_INSTANCE_KEY; + } + + int32_t ret = StartUIAbilitiesCheckDlp(want, callerToken, validUserId); + if (ret != ERR_OK) { + return ret; + } + + int32_t appIndex = 0; + ret = StartAbilityUtils::StartUIAbilitiesProcessAppIndex(const_cast(want), callerToken, appIndex); + if (ret != ERR_OK) { + return ret; + } + ret = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone( + const_cast(want), validUserId, appIndex, callerToken, false); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities CheckMultiInstanceAndAppClone failed"); + return ret; + } + + StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); + + if (CheckIfOperateRemote(want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities not support StartRemoteAbility"); + return START_UI_ABILITIES_NOT_SUPPORT_OPERATE_REMOTE; + } + + if (!JudgeMultiUserConcurrency(validUserId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities multi-user non-concurrent unsatisfied"); + return START_UI_ABILITIES_NOT_SUPPORT_CROSS_USER; + } +#ifdef SUPPORT_SCREEN + if (ImplicitStartProcessor::IsImplicitStartAction(want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities not support implicit start"); + return START_UI_ABILITIES_NOT_SUPPORT_IMPLICIT_START; + } +#endif + AbilityRequest abilityRequest; + auto result = GenerateAbilityRequest(want, requestCode, abilityRequest, callerToken, validUserId); + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + std::string callerBundleName = abilityRecord ? abilityRecord->GetAbilityInfo().bundleName : ""; + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request local error"); + return result; + } + + UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(abilityRequest.want, callerToken); + + auto abilityInfo = abilityRequest.abilityInfo; + if (abilityInfo.type != AbilityType::PAGE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities only support UIAbility"); + return START_UI_ABILITIES_ONLY_SUPPORT_UI_ABILITY; + } + + result = CheckStaticCfgPermission(abilityRequest, false, + abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0), false, false, false); + if (result != AppExecFwk::Constants::PERMISSION_GRANTED) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "StartUIAbilities checkStaticCfgPermission error, result:%{public}d", result); + return ERR_STATIC_CFG_PERMISSION; + } + result = CheckCallPermission(want, abilityInfo, abilityRequest, false, + false, specifyTokenId, callerBundleName); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "StartUIAbilities checkCallPermission error, result:%{public}d", result); + return result; + } + + result = StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex); + if (result != ERR_OK) { + return result; + } + + Want newWant = abilityRequest.want; + bool isReplaceWantExist = newWant.GetBoolParam("queryWantFromErms", false); + newWant.RemoveParam("queryWantFromErms"); + + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + RemoveUnauthorizedLaunchReasonMessage(want, abilityRequest, callerTokenId); + + if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "StartUIAbilities isAbilityControllerStart failed:%{public}s", abilityInfo.bundleName.c_str()); + return ERR_WOULD_BLOCK; + } + abilityRequest.want.RemoveParam(SPECIFY_TOKEN_ID); + abilityRequest.want.RemoveParam(PARAM_SPECIFIED_PROCESS_FLAG); + abilityRequestList.emplace_back(abilityRequest); + return ERR_OK; +} + +int32_t AbilityManagerService::StartUIAbilitiesCheckDlp(const Want &want, sptr callerToken, + int32_t userId) +{ +#ifdef WITH_DLP + if (AbilityUtil::HandleDlpApp(const_cast(want))) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities not support Dlp"); + return START_UI_ABILITIES_NOT_SUPPORT_DLP; + } + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "CHECK_DLP"); + if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || + VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || + !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "StartUIAbilities Dlp %{public}s: permission verification failed", __func__); + return CHECK_PERMISSION_FAILED; + } +#endif // WITH_DLP + return ERR_OK; +} + +int32_t AbilityManagerService::StartUIAbilitiesInterceptorCheck(const Want &want, AbilityRequest &abilityRequest, + sptr callerToken, int32_t appIndex) +{ + int32_t requestCode = DEFAULT_INVAL_VALUE; + Want newWant = abilityRequest.want; + auto abilityInfo = abilityRequest.abilityInfo; + auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + true, nullptr, shouldBlockFunc); + int32_t result = interceptorExecuter_ == nullptr ? ERR_NULL_INTERCEPTOR_EXECUTER : + interceptorExecuter_->DoProcess(interceptorParam); + if (result == ERR_CROWDTEST_EXPIRED) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities ERR_CROWDTEST_EXPIRED"); + return result; + } + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities interceptorExecuter_ null or DoProcess error"); + return START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED; + } + + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + true, callerToken, std::make_shared(abilityInfo), false, appIndex); + result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : + afterCheckExecuter_->DoProcess(afterCheckParam); + if (result == ERR_CROWDTEST_EXPIRED) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities ERR_CROWDTEST_EXPIRED"); + return result; + } + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities afterCheckExecuter_ null or DoProcess error"); + return START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED; + } + return ERR_OK; +} + int32_t AbilityManagerService::RequestDialogService(const Want &want, const sptr &callerToken) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -12330,24 +12550,6 @@ void AbilityManagerService::RemoveSelectorIdentity(int32_t tokenId) implicitStartProcessor_->RemoveIdentity(tokenId); } -void AbilityManagerService::SetTargetCloneIndexInSameBundle(const Want &want, sptr callerToken) -{ - auto callerRecord = Token::GetAbilityRecordByToken(callerToken); - CHECK_POINTER(callerRecord); - if (callerRecord->GetAbilityInfo().bundleName != want.GetElement().GetBundleName()) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "not the same bundle"); - return; - } - if (want.HasParameter(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY)) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "want with app clone index."); - return; - } - int32_t appIndex = callerRecord->GetApplicationInfo().appIndex; - if (appIndex >= 0 && appIndex < AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { - (const_cast(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, appIndex); - } -} - void AbilityManagerService::RemoveLauncherDeathRecipient(int32_t userId) { auto connectManager = GetConnectManagerByUserId(userId); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 37bc99ed15..cdad56fff5 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -32,8 +32,10 @@ using AutoStartupInfo = AbilityRuntime::AutoStartupInfo; namespace { const std::u16string extensionDescriptor = u"ohos.aafwk.ExtensionManager"; constexpr int32_t CYCLE_LIMIT = 1000; +constexpr int32_t INDEX_ONE = 1; constexpr int32_t MAX_KILL_PROCESS_PID_COUNT = 100; constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100; +constexpr int32_t MAX_WANT_LIST_SIZE = 4; } // namespace AbilityManagerStub::AbilityManagerStub() {} @@ -578,6 +580,9 @@ int AbilityManagerStub::OnRemoteRequestInnerFourteenth(uint32_t code, MessagePar if (interfaceCode == AbilityManagerInterfaceCode::CLOSE_UI_EXTENSION_ABILITY_BY_SCB) { return CloseUIExtensionAbilityBySCBInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_ABILITIES) { + return StartUIAbilitiesInner(data, reply); + } return ERR_CODE_NOT_EXIST; } @@ -3865,6 +3870,38 @@ int AbilityManagerStub::StartAbilityForResultAsCallerInner(MessageParcel &data, return NO_ERROR; } +int32_t AbilityManagerStub::StartUIAbilitiesInner(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "call StartUIAbilitiesInner"); + + std::vector wantList; + int32_t size = data.ReadInt32(); + if (size < INDEX_ONE || size > MAX_WANT_LIST_SIZE) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "vector size error"); + return START_UI_ABILITIES_WANT_LIST_SIZE_ERROR; + } + for (auto i = 0; i < size; i++) { + std::unique_ptr want(data.ReadParcelable()); + if (want == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null want"); + return ERR_NATIVE_IPC_PARCEL_FAILED; + } + wantList.emplace_back(*want); + } + + std::string requestKey = data.ReadString(); + + sptr callerToken = data.ReadRemoteObject(); + if (callerToken == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken"); + return INVALID_CALLER_TOKEN; + } + + int32_t result = StartUIAbilities(wantList, requestKey, callerToken); + reply.WriteInt32(result); + return NO_ERROR; +} + int AbilityManagerStub::StartAbilityForResultAsCallerForOptionsInner(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 26896799fc..4c7fc8aecd 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -3879,6 +3879,12 @@ void AbilityRecord::NotifyAbilityRequestSuccess(const std::string &requestId, co lifecycleDeal_->NotifyAbilityRequestSuccess(requestId, element); } +void AbilityRecord::NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) +{ + CHECK_POINTER(lifecycleDeal_); + lifecycleDeal_->NotifyAbilitiesRequestDone(requestKey, resultCode); +} + void AbilityRecord::UpdateUIExtensionBindInfo(const WantParams &wantParams) { if (!UIExtensionUtils::IsUIExtension(GetAbilityInfo().extensionAbilityType)) { diff --git a/services/abilitymgr/src/ability_scheduler_proxy.cpp b/services/abilitymgr/src/ability_scheduler_proxy.cpp index 0e5bfb278c..fd1bac5689 100644 --- a/services/abilitymgr/src/ability_scheduler_proxy.cpp +++ b/services/abilitymgr/src/ability_scheduler_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -1294,5 +1294,31 @@ void AbilitySchedulerProxy::ScheduleAbilityRequestSuccess(const std::string &req } return; } + +void AbilitySchedulerProxy::ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed"); + return; + } + + if (!data.WriteString(requestKey)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestKey failed"); + return; + } + if (!data.WriteInt32(resultCode)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed"); + return; + } + + int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITIES_REQUEST_DONE, data, reply, option); + if (err != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err); + } + return; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index 47ee11a031..43269a019d 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -160,6 +160,8 @@ int AbilitySchedulerStub::OnRemoteRequestInnerThird( return ScheduleAbilityRequestFailureInner(data); case SCHEDULE_ABILITY_REQUEST_SUCCESS: return ScheduleAbilityRequestSuccessInner(data); + case SCHEDULE_ABILITIES_REQUEST_DONE: + return ScheduleAbilitiesRequestDoneInner(data); } return ERR_CODE_NOT_EXIST; } @@ -780,6 +782,14 @@ int AbilitySchedulerStub::ScheduleAbilityRequestSuccessInner(MessageParcel &data return NO_ERROR; } +int AbilitySchedulerStub::ScheduleAbilitiesRequestDoneInner(MessageParcel &data) +{ + std::string requestKey = data.ReadString(); + int32_t resultCode = data.ReadInt32(); + ScheduleAbilitiesRequestDone(requestKey, resultCode); + return NO_ERROR; +} + void AbilitySchedulerRecipient::OnRemoteDied(const wptr &remote) { TAG_LOGE(AAFwkTag::ABILITYMGR, "call"); diff --git a/services/abilitymgr/src/lifecycle_deal.cpp b/services/abilitymgr/src/lifecycle_deal.cpp index 8fc5a02041..adc2c5081a 100644 --- a/services/abilitymgr/src/lifecycle_deal.cpp +++ b/services/abilitymgr/src/lifecycle_deal.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -215,5 +215,12 @@ void LifecycleDeal::NotifyAbilityRequestSuccess(const std::string &requestId, co CHECK_POINTER(abilityScheduler); abilityScheduler->ScheduleAbilityRequestSuccess(requestId, element); } + +void LifecycleDeal::NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) +{ + auto abilityScheduler = GetScheduler(); + CHECK_POINTER(abilityScheduler); + abilityScheduler->ScheduleAbilitiesRequestDone(requestKey, resultCode); +} } // 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 960bd0f800..9fde5cb373 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -70,6 +70,7 @@ constexpr int32_t MAX_FIND_UIEXTENSION_CALLER_TIMES = 10; constexpr int32_t START_UI_ABILITY_PER_SECOND_UPPER_LIMIT = 20; constexpr int32_t API20 = 20; constexpr int32_t API_VERSION_MOD = 100; +constexpr int32_t REQUEST_LIST_ID_INIT = -1; constexpr const char* IS_CALLING_FROM_DMS = "supportCollaborativeCallingFromDmsInAAFwk"; constexpr int REMOVE_STARTING_BUNDLE_TIMEOUT_MICRO_SECONDS = 5000000; // 5s @@ -594,7 +595,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability return StartWithPersistentIdByDistributed(abilityRequest, persistentId); } if (IsStartSpecifiedProcessRequest(abilityRequest)) { - return StartSpecifiedProcessRequest(abilityRequest); + return StartSpecifiedProcessRequest(abilityRequest, nullptr); } const auto &abilityInfo = abilityRequest.abilityInfo; auto requestId = RequestIdUtil::GetRequestId(); @@ -644,12 +645,183 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability return ret; } +int UIAbilityLifecycleManager::NotifySCBToStartUIAbilities(std::vector &abilityRequestList, + const std::string &requestKey) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call NotifySCBToStartUIAbilities"); + + int32_t ret = HandleUIAbilityRequestList(abilityRequestList); + if (ret != ERR_OK) { + return ret; + } + + std::lock_guard guard(sessionLock_); + auto abilitiesRequest = std::make_shared(); + int32_t requestListId = RequestIdUtil::GetRequestId(); + abilitiesRequest->requestListId = requestListId; + abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + abilitiesRequest->requestKey = requestKey; + for (AbilityRequest &abilityRequest : abilityRequestList) { + abilitiesRequest->callerToken = abilityRequest.callerToken; + if (IsStartSpecifiedProcessRequest(abilityRequest)) { + ret = StartSpecifiedProcessRequest(abilityRequest, abilitiesRequest); + if (ret != ERR_OK) { + return ret; + } + continue; + } + const auto &abilityInfo = abilityRequest.abilityInfo; + auto requestId = RequestIdUtil::GetRequestId(); + if (abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) { + auto specifiedRequest = std::make_shared(requestId, abilityRequest); + specifiedRequest->preCreateProcessName = true; + specifiedRequest->requestListId = abilitiesRequest->requestListId; + abilitiesRequest->sessionInfoList.emplace_back(requestId, nullptr); + AddSpecifiedRequest(specifiedRequest); + continue; + } + HandleAbilitiesNormalSessionInfo(abilityRequest, abilitiesRequest, requestId); + } + + if (abilitiesRequest->doneCount < abilityRequestList.size()) { + return START_UI_ABILITIES_WAITING_SPECIFIED_CODE; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "StartUIAbilities normal, size: %{public}zu", abilityRequestList.size()); + ret = BatchNotifySCBPendingActivations(*abilitiesRequest); + for (auto &[id, sessionInfo] : abilitiesRequest->sessionInfoList) { + sessionInfo->want.RemoveAllFd(); + } + abilitiesRequestMap_.erase(requestListId); + return ret; +} + +int32_t UIAbilityLifecycleManager::HandleUIAbilityRequestList(std::vector &abilityRequestList) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call HandleUIAbilityRequestList"); + for (AbilityRequest &abilityRequest : abilityRequestList) { + if (!AddStartCallerTimestamp(abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_UID, -1))) { + return ERR_INVALID_VALUE; + } + abilityRequest.want.SetParam(IS_SHELL_CALL, AAFwk::PermissionVerification::GetInstance()->IsShellCall()); + std::string callerKey = std::to_string(IPCSkeleton::GetCallingPid()) + ":" + + std::to_string(IPCSkeleton::GetCallingUid()); + bool isCallerKilling = IN_PROCESS_CALL( + DelayedSingleton::GetInstance()->IsCallerKilling(callerKey)); + if (isCallerKilling) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities caller is killing"); + return ERR_INVALID_VALUE; + } + abilityRequest.want.SetParam(Want::PARAMS_REAL_CALLER_KEY, callerKey); + } + return ERR_OK; +} + +void UIAbilityLifecycleManager::HandleAbilitiesNormalSessionInfo(AbilityRequest &abilityRequest, + std::shared_ptr abilitiesRequest, int32_t requestId) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call HandleAbilitiesNormalSessionInfo"); + const auto &abilityInfo = abilityRequest.abilityInfo; + auto sessionInfo = CreateSessionInfo(abilityRequest); + sessionInfo->requestCode = abilityRequest.requestCode; + sessionInfo->requestId = requestId; + sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); + sessionInfo->userId = userId_; + sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); + TAG_LOGI(AAFwkTag::ABILITYMGR, "Reused sessionId: %{public}d, userId: %{public}d, requestId: %{public}d", + sessionInfo->persistentId, userId_, requestId); + + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->doneCount++; +} + +int32_t UIAbilityLifecycleManager::BatchNotifySCBPendingActivations(const AbilitiesRequest &abilitiesRequest) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call BatchNotifySCBPendingActivations"); + std::vector> sessionInfoList; + for (const auto &[id, sessionInfo] : abilitiesRequest.sessionInfoList) { + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo nullptr"); + continue; + } + sessionInfoList.push_back(sessionInfo); + bool hasStartWindowOption = (sessionInfo->startWindowOption != nullptr); + bool hasStartWindow = hasStartWindowOption ? sessionInfo->startWindowOption->hasStartWindow : false; + std::string backgroundColor = + hasStartWindowOption ? sessionInfo->startWindowOption->startWindowBackgroundColor : ""; + TAG_LOGI(AAFwkTag::ABILITYMGR, "appCloneIndex:%{public}d, instanceKey:%{public}s, " + "hasStartWindow:%{public}d, backgroundColor:%{public}s", + (sessionInfo->want).GetIntParam(Want::PARAM_APP_CLONE_INDEX_KEY, 0), sessionInfo->instanceKey.c_str(), + hasStartWindow, backgroundColor.c_str()); + } + + auto callerAbilityRecord = GetAbilityRecordByToken(abilitiesRequest.callerToken); + if (callerAbilityRecord == nullptr || callerAbilityRecord->GetRestartAppFlag()) { + auto tmpSceneSession = iface_cast(rootSceneSession_); + if (tmpSceneSession == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null tmpSceneSession, scb does not exist"); + return ERR_INVALID_VALUE; + } + for (auto sessionInfo : sessionInfoList) { + sessionInfo->canStartAbilityFromBackground = true; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, + "scb call, StartUIAbilities BatchPendingSessionsActivation for rootSceneSession"); + return static_cast(tmpSceneSession->BatchPendingSessionsActivation(sessionInfoList)); + } + auto callerSessionInfo = callerAbilityRecord->GetSessionInfo(); + CHECK_POINTER_AND_RETURN(callerSessionInfo, ERR_INVALID_VALUE); + CHECK_POINTER_AND_RETURN(callerSessionInfo->sessionToken, ERR_INVALID_VALUE); + auto callerSession = iface_cast(callerSessionInfo->sessionToken); + CHECK_POINTER_AND_RETURN(callerSession, ERR_INVALID_VALUE); + for (auto sessionInfo : sessionInfoList) { + CheckCallerFromBackground(callerAbilityRecord, sessionInfo); + auto requestId = sessionInfo->want.GetStringParam(KEY_REQUEST_ID); + if (!requestId.empty()) { + callerAbilityRecord->NotifyAbilityRequestSuccess(requestId, sessionInfo->want.GetElement()); + } + sessionInfo->want.RemoveParam(KEY_REQUEST_ID); + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "scb call, StartUIAbilities BatchPendingSessionsActivation for callerSession"); + return static_cast(callerSession->BatchPendingSessionsActivation(sessionInfoList)); +} + +void UIAbilityLifecycleManager::HandleAbilitiesRequestDone(int32_t requestId, int32_t requestListId, + sptr sessionInfo) +{ + auto it = abilitiesRequestMap_.find(requestListId); + if (it == abilitiesRequestMap_.end()) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "requestListId: %{public}d not found", requestListId); + return; + } + auto abilitiesRequest = it->second; + CHECK_POINTER_LOG(abilitiesRequest, "abilitiesUIRequest nullptr"); + abilitiesRequest->doneCount++; + auto &sessionInfoList = abilitiesRequest->sessionInfoList; + for (auto &item : sessionInfoList) { + if (item.first == requestId) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "requestdone %{public}d", requestId); + item.second = sessionInfo; + } + } + if (abilitiesRequest->doneCount == sessionInfoList.size()) { + int32_t ret = BatchNotifySCBPendingActivations(*abilitiesRequest); + abilitiesRequestMap_.erase(it); + auto callerRecord = Token::GetAbilityRecordByToken(abilitiesRequest->callerToken); + if (callerRecord == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "callerRecord not exist."); + return; + } + callerRecord->NotifyAbilitiesRequestDone(abilitiesRequest->requestKey, ret); + } +} + int32_t UIAbilityLifecycleManager::NotifySCBToRecoveryAfterInterception(const AbilityRequest &abilityRequest) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::lock_guard guard(sessionLock_); if (IsStartSpecifiedProcessRequest(abilityRequest)) { - return StartSpecifiedProcessRequest(abilityRequest); + return StartSpecifiedProcessRequest(abilityRequest, nullptr); } const auto &abilityInfo = abilityRequest.abilityInfo; auto isPlugin = StartupUtil::IsStartPlugin(abilityRequest.want); @@ -2116,13 +2288,14 @@ void UIAbilityLifecycleManager::OnAcceptWantResponse(const AAFwk::Want &want, co } } - HandleLegacyAcceptWantDone(request->abilityRequest, requestId, flag, want); + HandleLegacyAcceptWantDone(*request, flag, want); } -void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, +void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want) { TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s", want.GetElement().GetURI().c_str()); + auto &abilityRequest = specifiedRequest.abilityRequest; auto callerAbility = GetAbilityRecordByToken(abilityRequest.callerToken); abilityRequest.specifiedFlag = flag; if (!flag.empty()) { @@ -2139,13 +2312,13 @@ void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(AbilityRequest &abili abilityRecord = iter->second; CHECK_POINTER_LOG(abilityRecord, "OnAcceptWantResponse abilityRecord null"); UpdateAbilityRecordLaunchReason(abilityRequest, abilityRecord); - MoveAbilityToFront(abilityRequest, abilityRecord, callerAbility, nullptr, requestId); + MoveAbilityToFront(specifiedRequest, abilityRecord, callerAbility); NotifyRestartSpecifiedAbility(abilityRequest, abilityRecord->GetToken()); return; } } NotifyStartSpecifiedAbility(abilityRequest, want); - StartAbilityBySpecifed(abilityRequest, callerAbility, requestId); + StartAbilityBySpecifed(specifiedRequest, callerAbility); } void UIAbilityLifecycleManager::OnStartSpecifiedAbilityTimeoutResponse(int32_t requestId) @@ -2181,6 +2354,7 @@ void UIAbilityLifecycleManager::OnStartSpecifiedFailed(int32_t requestId) RemoveInstanceKey(curRequest->abilityRequest); } + HandleAbilitiesRequestDone(requestId, curRequest->requestListId, nullptr); auto nextRequest = PopAndGetNextSpecified(requestId); if (nextRequest) { StartSpecifiedRequest(*nextRequest); @@ -2224,6 +2398,10 @@ void UIAbilityLifecycleManager::OnStartSpecifiedProcessResponse(const std::strin (abilityRequest.abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); TAG_LOGI(AAFwkTag::ABILITYMGR, "reused sessionId: %{public}d, userId: %{public}d", sessionInfo->persistentId, abilityRequest.userId); + if (request->requestListId != REQUEST_LIST_ID_INIT) { + HandleAbilitiesRequestDone(requestId, request->requestListId, sessionInfo); + return; + } std::string errMsg; NotifySCBPendingActivation(sessionInfo, abilityRequest, errMsg); } @@ -2236,6 +2414,7 @@ void UIAbilityLifecycleManager::OnStartSpecifiedProcessTimeoutResponse(int32_t r if (request != nullptr) { TAG_LOGI(AAFwkTag::ABILITYMGR, "removing instance key"); RemoveInstanceKey(request->abilityRequest); + HandleAbilitiesRequestDone(requestId, request->requestListId, nullptr); } auto nextRequest = PopAndGetNextSpecified(requestId); if (nextRequest) { @@ -2269,7 +2448,8 @@ bool UIAbilityLifecycleManager::IsStartSpecifiedProcessRequest(const AbilityRequ return true; } -int32_t UIAbilityLifecycleManager::StartSpecifiedProcessRequest(const AbilityRequest &abilityRequest) +int32_t UIAbilityLifecycleManager::StartSpecifiedProcessRequest(const AbilityRequest &abilityRequest, + std::shared_ptr abilitiesRequest) { auto isCreating = abilityRequest.want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); const auto &abilityInfo = abilityRequest.abilityInfo; @@ -2289,6 +2469,10 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedProcessRequest(const AbilityReq TAG_LOGI(AAFwkTag::ABILITYMGR, "StartSpecifiedProcess, requestId:%{public}d", requestId); auto specifiedRequest = std::make_shared(requestId, abilityRequest); specifiedRequest->specifiedProcessState = SpecifiedProcessState::STATE_PROCESS; + if (abilitiesRequest != nullptr) { + abilitiesRequest->sessionInfoList.emplace_back(requestId, nullptr); + specifiedRequest->requestListId = abilitiesRequest->requestListId; + } AddSpecifiedRequest(specifiedRequest); return ERR_OK; } @@ -2301,7 +2485,7 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedAbilityBySCB(AbilityRequest &ab std::lock_guard guard(sessionLock_); // support specified process mode if (IsStartSpecifiedProcessRequest(abilityRequest)) { - return StartSpecifiedProcessRequest(abilityRequest); + return StartSpecifiedProcessRequest(abilityRequest, nullptr); } AddSpecifiedRequest(std::make_shared(RequestIdUtil::GetRequestId(), abilityRequest)); return ERR_OK; @@ -2348,14 +2532,16 @@ void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abil } } -int UIAbilityLifecycleManager::MoveAbilityToFront(const AbilityRequest &abilityRequest, - const std::shared_ptr &abilityRecord, std::shared_ptr callerAbility, - std::shared_ptr startOptions, int32_t requestId) +int32_t UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { if (!abilityRecord) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ability record failed"); return ERR_INVALID_VALUE; } + const auto &abilityRequest = specifiedRequest.abilityRequest; + int32_t requestId = specifiedRequest.requestId; + int32_t requestListId = specifiedRequest.requestListId; sptr sessionInfo = abilityRecord->GetSessionInfo(); CHECK_POINTER_AND_RETURN(sessionInfo, ERR_INVALID_VALUE); sessionInfo->want = abilityRequest.want; @@ -2372,11 +2558,12 @@ int UIAbilityLifecycleManager::MoveAbilityToFront(const AbilityRequest &abilityR sessionInfo->specifiedFlag = abilityRequest.specifiedFlag; TAG_LOGI(AAFwkTag::ABILITYMGR, "MoveAbilityToFront: %{public}d-%{public}s", requestId, abilityRequest.specifiedFlag.c_str()); + if (requestListId != REQUEST_LIST_ID_INIT) { + HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + return ERR_OK; + } SendSessionInfoToSCB(callerAbility, sessionInfo); abilityRecord->RemoveWindowMode(); - if (startOptions != nullptr) { - abilityRecord->SetWindowMode(startOptions->GetWindowMode()); - } return ERR_OK; } @@ -2431,11 +2618,12 @@ int UIAbilityLifecycleManager::SendSessionInfoToSCB(std::shared_ptr &callerAbility, int32_t requestId) +int32_t UIAbilityLifecycleManager::StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); sptr sessionInfo = new SessionInfo(); + const auto &abilityRequest = specifiedRequest.abilityRequest; sessionInfo->callerToken = abilityRequest.callerToken; sessionInfo->want = abilityRequest.want; sessionInfo->requestCode = abilityRequest.requestCode; @@ -2443,10 +2631,14 @@ int UIAbilityLifecycleManager::StartAbilityBySpecifed(const AbilityRequest &abil sessionInfo->startWindowOption = abilityRequest.startWindowOption; sessionInfo->instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); sessionInfo->isFromIcon = abilityRequest.isFromIcon; - sessionInfo->requestId = requestId; + sessionInfo->requestId = specifiedRequest.requestId; sessionInfo->specifiedFlag = abilityRequest.specifiedFlag; TAG_LOGI(AAFwkTag::ABILITYMGR, "specified flag:%{public}s", abilityRequest.specifiedFlag.c_str()); - SendSessionInfoToSCB(callerAbility, sessionInfo); + if (specifiedRequest.requestListId != REQUEST_LIST_ID_INIT) { + HandleAbilitiesRequestDone(specifiedRequest.requestId, specifiedRequest.requestListId, sessionInfo); + } else { + SendSessionInfoToSCB(callerAbility, sessionInfo); + } return ERR_OK; } @@ -3629,7 +3821,7 @@ void UIAbilityLifecycleManager::StartSpecifiedRequest(SpecifiedRequest &specifie return; } if (specifiedRequest.specifiedProcessState == SpecifiedProcessState::STATE_NONE && - !IsSpecifiedModuleLoaded(request)) { + specifiedRequest.requestListId == REQUEST_LIST_ID_INIT && !IsSpecifiedModuleLoaded(request)) { specifiedRequest.isCold = true; auto sessionInfo = CreateSessionInfo(request); sessionInfo->requestCode = request.requestCode; diff --git a/services/abilitymgr/src/utils/start_ability_utils.cpp b/services/abilitymgr/src/utils/start_ability_utils.cpp index c063882735..32a8ae1f97 100644 --- a/services/abilitymgr/src/utils/start_ability_utils.cpp +++ b/services/abilitymgr/src/utils/start_ability_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 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 @@ -395,5 +395,37 @@ bool StartAbilityUtils::IsCallFromAncoShellOrBroker(const sptr &c } return false; } + +void StartAbilityUtils::SetTargetCloneIndexInSameBundle(const Want &want, sptr callerToken) +{ + auto callerRecord = Token::GetAbilityRecordByToken(callerToken); + CHECK_POINTER(callerRecord); + if (callerRecord->GetAbilityInfo().bundleName != want.GetElement().GetBundleName()) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "not the same bundle"); + return; + } + if (want.HasParameter(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY)) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "want with app clone index."); + return; + } + int32_t appIndex = callerRecord->GetApplicationInfo().appIndex; + if (appIndex >= 0 && appIndex < AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { + (const_cast(want)).SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, appIndex); + } +} + +int32_t StartAbilityUtils::StartUIAbilitiesProcessAppIndex(Want &want, + sptr callerToken, int32_t &appIndex) +{ + SetTargetCloneIndexInSameBundle(want, callerToken); + if (!want.HasParameter(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY)) { + want.SetParam(AAFwk::Want::PARAM_APP_CLONE_INDEX_KEY, 0); + } + if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilities GetAppIndex failed."); + return ERR_APP_CLONE_INDEX_INVALID; + } + return ERR_OK; +} } } \ No newline at end of file diff --git a/services/common/include/app_utils.h b/services/common/include/app_utils.h index e488a9148a..955a7c3c60 100644 --- a/services/common/include/app_utils.h +++ b/services/common/include/app_utils.h @@ -139,6 +139,13 @@ public: */ bool IsStartOptionsWithAnimation(); + /** + * IsSupportStartAbilities, check whether the StartUIAbilities API is supported. + * + * @return Whether the StartUIAbilities API is supported. + */ + bool IsSupportStartAbilities(); + /** * IsStartOptionsWithAnimation, check whether it is a multi-process model. * @@ -424,6 +431,7 @@ private: volatile DeviceConfiguration isConnectSupportCrossUser_ = {false, false}; volatile DeviceConfiguration isSupportAppServiceExtension_ = {false, false}; volatile DeviceConfiguration isGrantTempUriPermission_ = {false, true}; + volatile DeviceConfiguration isSupportStartAbilities_ = {false, false}; DeviceConfiguration>> residentProcessInExtremeMemory_ = {false, {}}; std::mutex residentProcessInExtremeMemoryMutex_; diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index d4ab9a9775..9cfdf3c578 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -42,6 +42,7 @@ constexpr const char* LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.l constexpr const char* GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission"; constexpr const char* GRANT_TEMPORARY_URI_PERMISSION = "persist.sys.abilityms.grant_temporary_uri_permission"; constexpr const char* START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation"; +constexpr const char* SUPPORT_START_ABILITIES = "persist.sys.abilityms.enable_start_abilities"; constexpr const char* MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model"; constexpr const char* PARAM_ANCO_APP_IDENTIFIER = "persist.hmos_fusion_mgr.anco_identifier"; constexpr const char* ALLOW_CHILD_PROCESS_IN_MULTI_PROCESS_FEATURE_APP = @@ -227,6 +228,16 @@ bool AppUtils::IsStartOptionsWithAnimation() return isStartOptionsWithAnimation_.value; } +bool AppUtils::IsSupportStartAbilities() +{ + if (!isSupportStartAbilities_.isLoaded) { + isSupportStartAbilities_.value = system::GetBoolParameter(SUPPORT_START_ABILITIES, false); + isSupportStartAbilities_.isLoaded = true; + } + TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportStartAbilities_.value); + return isSupportStartAbilities_.value; +} + bool AppUtils::IsMultiProcessModel() { if (!isMultiProcessModel_.isLoaded) { diff --git a/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp b/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp index 623122f94c..96fd342dcd 100755 --- a/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp +++ b/test/fuzztest/attachabilitythread_fuzzer/attachabilitythread_fuzzer.cpp @@ -164,6 +164,9 @@ public: void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; sptr GetFuzzAbilityToken(AbilityType type) { 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 cd9abffc05..0f67bb7021 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 @@ -160,6 +160,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) + {} }; } // 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 79d93b21d4..950191a81d 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 @@ -89,6 +89,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; } // namespace AppExecFwk } // namespace OHOS 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 fa940a4c67..61d6f4cd2b 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 @@ -125,6 +125,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} private: AbilityResult result_; }; 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 b74ebd3efa..d2d7c84e0b 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 @@ -48,6 +48,7 @@ public: MOCK_METHOD2(DumpAbilityInfo, void(const std::vector& params, std::vector& info)); MOCK_METHOD1(ScheduleShareData, void(const int32_t &uniqueId)); MOCK_METHOD0(SchedulePrepareTerminateAbility, bool()); + MOCK_METHOD2(ScheduleAbilitiesRequestDone, void(const std::string &, int32_t)); int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) { code_ = code; diff --git a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp index 8286f39e33..91f7e42f11 100644 --- a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp @@ -488,6 +488,22 @@ HWTEST_F(AbilityManagerClientTest, StartAbilityByCallWithErrMsg_0100, TestSize.L TAG_LOGI(AAFwkTag::TEST, "StartAbilityByCallWithErrMsg_0100 end"); } +/** + * @tc.name: AbilityManagerClient_StartUIAbilities_0100 + * @tc.desc: StartUIAbilities + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientTest, StartUIAbilities_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "StartUIAbilities_0100 start"); + std::vector wantList(2); + std::string requestKey = "12345"; + sptr callToken = sptr::MakeSptr(); + auto result = AbilityManagerClient::GetInstance()->StartUIAbilities(wantList, requestKey, callToken); + EXPECT_EQ(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "StartUIAbilities_0100 end"); +} + /** * @tc.name: AbilityManagerClient_QueryPreLoadUIExtensionRecord_0100 * @tc.desc: QueryPreLoadUIExtensionRecord diff --git a/test/moduletest/mock/include/mock_ability_scheduler.h b/test/moduletest/mock/include/mock_ability_scheduler.h index 2c63f80087..a077c276a1 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler.h +++ b/test/moduletest/mock/include/mock_ability_scheduler.h @@ -139,6 +139,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; } // namespace AAFwk } // namespace OHOS diff --git a/test/moduletest/mock/include/mock_ability_scheduler_stub.h b/test/moduletest/mock/include/mock_ability_scheduler_stub.h index 2bb18f053b..e43727e345 100644 --- a/test/moduletest/mock/include/mock_ability_scheduler_stub.h +++ b/test/moduletest/mock/include/mock_ability_scheduler_stub.h @@ -79,6 +79,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_fourteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h b/test/unittest/ability_manager_service_fourteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h index f7a4201b6d..4e6679fb60 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h +++ b/test/unittest/ability_manager_service_fourteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h @@ -445,11 +445,11 @@ private: void NotifyStartSpecifiedAbility(AbilityRequest &request, const AAFwk::Want &want); void NotifyRestartSpecifiedAbility(const AbilityRequest &request, const sptr &token); - int MoveAbilityToFront(const AbilityRequest &abilityRequest, const std::shared_ptr &abilityRecord, - std::shared_ptr callerAbility, std::shared_ptr startOptions, int32_t requestId); + int MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + const std::shared_ptr abilityRecord, std::shared_ptr callerAbility); int SendSessionInfoToSCB(std::shared_ptr &callerAbility, sptr &sessionInfo); - int StartAbilityBySpecifed(const AbilityRequest &abilityRequest, std::shared_ptr &callerAbility, - int32_t requestId); + int StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility); void SetLastExitReason(std::shared_ptr &abilityRecord) const; void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr &abilityRecord) const; @@ -505,7 +505,7 @@ private: bool HandleStartSpecifiedCold(AbilityRequest &abilityRequest, sptr sessionInfo, uint32_t sceneFlag); bool HandleColdAcceptWantDone(const AAFwk::Want &want, const std::string &flag, const SpecifiedRequest &specifiedRequest); - void HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, + void HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want); std::shared_ptr GetSpecifiedRequest(int32_t requestId); bool CheckPrepareTerminateTokens(const std::vector> &tokens, diff --git a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp index b52247e189..051de577be 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp +++ b/test/unittest/ability_manager_service_fourteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp @@ -395,7 +395,7 @@ void UIAbilityLifecycleManager::OnAcceptWantResponse(const AAFwk::Want &want, co { } -void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, +void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want) { } @@ -431,9 +431,8 @@ void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abil { } -int UIAbilityLifecycleManager::MoveAbilityToFront(const AbilityRequest &abilityRequest, - const std::shared_ptr &abilityRecord, std::shared_ptr callerAbility, - std::shared_ptr startOptions, int32_t requestId) +int UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + const std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { return ERR_OK; } @@ -444,8 +443,8 @@ int UIAbilityLifecycleManager::SendSessionInfoToSCB(std::shared_ptr &callerAbility, int32_t requestId) +int UIAbilityLifecycleManager::StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility) { return ERR_OK; } diff --git a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp index 7b4bc299e7..689183fe77 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp @@ -29,12 +29,15 @@ using OHOS::AppExecFwk::ExtensionAbilityType; constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; constexpr const char* DEBUG_APP = "debugApp"; +constexpr const char* DLP_PARAMS_SANDBOX = "ohos.dlp.params.sandbox"; +constexpr const char* DLP_INDEX = "ohos.dlp.params.index"; constexpr const char* START_ABILITY_TYPE = "ABILITY_INNER_START_WITH_ACCOUNT"; constexpr int32_t ONE = 1; constexpr int32_t TWO = 2; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t DMS_UID = 5522; constexpr int32_t LOW_MEMORY_KILL_WHILE_STARTING = 1111; +constexpr int32_t DEFAULT_INVAL_VALUE = -1; namespace OHOS { namespace AAFwk { @@ -1228,6 +1231,707 @@ HWTEST_F(AbilityManagerServiceThirteenthTest, KillProcessWithReason_002, TestSiz TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest KillProcessWithReason_002 end"); } +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_001 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities CCM false SCB false + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_001 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector wantList; + std::string requestKey; + sptr callerToken = nullptr; + + MyStatus::GetInstance().isSupportStartAbilities_ = false; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = false; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_CAPABILITY_NOT_SUPPORT); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_002 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities CCM true SCB false + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_002 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector wantList; + std::string requestKey; + sptr callerToken = nullptr; + + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = false; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_CAPABILITY_NOT_SUPPORT); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_003 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities CCM false SCB true + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_003 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector wantList; + std::string requestKey; + sptr callerToken = nullptr; + + MyStatus::GetInstance().isSupportStartAbilities_ = false; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_CAPABILITY_NOT_SUPPORT); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_004 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities CCM true SCB true listSize = 0 + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_004 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector wantList(6); + std::string requestKey; + sptr callerToken = nullptr; + + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), START_UI_ABILITIES_WANT_LIST_SIZE_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_004 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_005 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities listSize > 4 + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_005 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector wantList(5); + std::string requestKey; + sptr callerToken = nullptr; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), START_UI_ABILITIES_WANT_LIST_SIZE_ERROR); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_005 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_006 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities callerToken = nullptr + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_006 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + auto mockSubManagersHelper = std::make_shared(nullptr, nullptr); + EXPECT_NE(mockSubManagersHelper, nullptr); + auto mockCurrentUIAbilityManager = std::make_shared(0); + EXPECT_NE(mockCurrentUIAbilityManager, nullptr); + abilityMs_->subManagersHelper_ = mockSubManagersHelper; + abilityMs_->subManagersHelper_->currentUIAbilityManager_ = mockCurrentUIAbilityManager; + + std::vector wantList(2); + std::string requestKey; + sptr callerToken = nullptr; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_INVALID_CALLER); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_006 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_007 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities verifyToken failed + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_007 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + auto mockSubManagersHelper = std::make_shared(nullptr, nullptr); + EXPECT_NE(mockSubManagersHelper, nullptr); + auto mockCurrentUIAbilityManager = std::make_shared(0); + EXPECT_NE(mockCurrentUIAbilityManager, nullptr); + abilityMs_->subManagersHelper_ = mockSubManagersHelper; + abilityMs_->subManagersHelper_->currentUIAbilityManager_ = mockCurrentUIAbilityManager; + + std::vector wantList(2); + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().smhVerificationAllToken_ = false; + + EXPECT_EQ(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_INVALID_CALLER); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_007 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilities_008 + * Function: StartUIAbilities + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilities handleWant failed + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilities_008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_008 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + auto mockSubManagersHelper = std::make_shared(nullptr, nullptr); + EXPECT_NE(mockSubManagersHelper, nullptr); + auto mockCurrentUIAbilityManager = std::make_shared(0); + EXPECT_NE(mockCurrentUIAbilityManager, nullptr); + abilityMs_->subManagersHelper_ = mockSubManagersHelper; + abilityMs_->subManagersHelper_->currentUIAbilityManager_ = mockCurrentUIAbilityManager; + + std::vector wantList(2); + std::string requestKey; + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + EXPECT_NE(abilityMs_->StartUIAbilities(wantList, requestKey, callerToken), ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilities_008 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_001 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant startPlugin + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_001 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(AAFwk::Want::DESTINATION_PLUGIN_ABILITY, true); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + START_UI_ABILITIES_NOT_SUPPORT_START_PLUGIN); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_002 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant createInstance + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_002 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(AAFwk::Want::CREATE_APP_INSTANCE_KEY, true); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + START_UI_ABILITIES_NOT_SUPPORT_CREATE_APP_INSTANCE_KEY); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_003 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant dlp failed with dlp + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_003 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(DLP_PARAMS_SANDBOX, true); + want.SetElementName("com.ohos.test", "MainAbility"); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + START_UI_ABILITIES_NOT_SUPPORT_DLP); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_004 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant appCloneIndexError + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_004 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + want.SetParam(Want::PARAM_APP_CLONE_INDEX_KEY, -5); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + ERR_APP_CLONE_INDEX_INVALID); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_004 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_005 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant multiInstanceError + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_005 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetElementName("com.ohos.test", "MainAbility"); + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + want.SetParam(Want::APP_INSTANCE_KEY, 2); + MyStatus::GetInstance().isSupportMultiInstance_ = false; + + EXPECT_NE(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + ERR_OK); + + MyStatus::GetInstance().isSupportMultiInstance_ = true; + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_005 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_006 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant OperateRemoteError + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_006 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetElementName("com.ohos.test", "MainAbility"); + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + want.SetDeviceId("deviceId"); + + EXPECT_NE(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_006 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_007 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant CrossUserError? + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_007 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetElementName("com.ohos.test", "MainAbility"); + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + want.SetDeviceId("deviceId"); + + EXPECT_NE(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_007 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_008 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant ImplicitStartError + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_008 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + START_UI_ABILITIES_NOT_SUPPORT_IMPLICIT_START); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_008 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesHandleWant_009 + * Function: StartUIAbilitiesHandleWant + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesHandleWant generateRequestPass + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesHandleWant_009, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_009 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + want.SetElementName("com.ohos.test", "MainAbility"); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesHandleWant(want, callerToken, abilityRequestList), + RESOLVE_ABILITY_ERR); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesHandleWant_009 end"); +} + +#ifdef WITH_DLP +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesCheckDlp_001 + * Function: StartUIAbilitiesCheckDlp + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesCheckDlp handleDLP == true + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesCheckDlp_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_001 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + sptr callerToken = MockToken(AbilityType::EXTENSION); + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(DLP_PARAMS_SANDBOX, true); + want.SetElementName("com.ohos.test", "MainAbility"); + int32_t userId = DEFAULT_INVAL_VALUE; + + + EXPECT_EQ(abilityMs_->StartUIAbilitiesCheckDlp(want, callerToken, userId), + START_UI_ABILITIES_NOT_SUPPORT_DLP); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_001 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesCheckDlp_002 + * Function: StartUIAbilitiesCheckDlp + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesCheckDlp false false false + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesCheckDlp_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_002 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + + EXPECT_EQ(abilityMs_->StartUIAbilitiesCheckDlp(want, callerToken, userId), + ERR_OK); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_002 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesCheckDlp_003 + * Function: StartUIAbilitiesCheckDlp + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesCheckDlp true false false + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesCheckDlp_003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_003 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(DLP_INDEX, 1); + MyStatus::GetInstance().permPermission_ = false; + int32_t userId = DEFAULT_INVAL_VALUE; + sptr callerToken = MockToken(AbilityType::EXTENSION); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesCheckDlp(want, callerToken, userId), + CHECK_PERMISSION_FAILED); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_003 end"); +} + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesCheckDlp_004 + * Function: StartUIAbilitiesCheckDlp + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesCheckDlp true true false + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesCheckDlp_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_004 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + std::vector abilityRequestList; + std::string requestKey; + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + Want want; + want.SetParam(DLP_INDEX, 1); + MyStatus::GetInstance().permPermission_ = false; + int32_t userId = 0; + sptr callerToken = MockToken(AbilityType::EXTENSION); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesCheckDlp(want, callerToken, userId), + CHECK_PERMISSION_FAILED); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesCheckDlp_004 end"); +} +#endif // WITH_DLP + +/* + * Feature: AbilityManagerService + * Name: StartUIAbilitiesInterceptorCheck_001 + * Function: StartUIAbilitiesInterceptorCheck + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIAbilitiesInterceptorCheck generateRequestPass + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, StartUIAbilitiesInterceptorCheck_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesInterceptorCheck_001 start"); + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + MyStatus::GetInstance().isSupportStartAbilities_ = true; + MyStatus::GetInstance().sbjIsSceneBoardEnabled_ = true; + MyStatus::GetInstance().smhVerificationAllToken_ = true; + + int32_t appIndex = 0; + Want want; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + int32_t userId = DEFAULT_INVAL_VALUE; + MyStatus::GetInstance().permPermission_ = true; + want.SetElementName("com.ohos.test", "MainAbility"); + + EXPECT_EQ(abilityMs_->StartUIAbilitiesInterceptorCheck(want, abilityRequest, callerToken, appIndex), + START_UI_ABILITIES_INTERCEPTOR_CHECK_FAILED); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest StartUIAbilitiesInterceptorCheck_001 end"); +} + /* * Feature: AbilityManagerService * Name: DelegatorDoAbilityForeground_001 diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_app_utils.h b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_app_utils.h index 07d4a48424..33ce5aeab6 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_app_utils.h +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_app_utils.h @@ -132,6 +132,13 @@ public: */ bool IsStartOptionsWithAnimation(); + /** + * IsSupportStartAbilities, check whether the StartUIAbilities API is supported. + * + * @return Whether the StartUIAbilities API is supported. + */ + bool IsSupportStartAbilities(); + /** * IsStartOptionsWithAnimation, check whether it is a multi-process model. * diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_my_status.h b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_my_status.h index 7d665628f5..2e70cea868 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_my_status.h +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_my_status.h @@ -52,6 +52,8 @@ public: bool paramGetBoolParameter_ = true; std::shared_ptr acmGetUIExtensionBySessionInfo_ = nullptr; std::shared_ptr acmGetUIExtensionBySessionFromServiceMap_ = nullptr; + bool isSupportStartAbilities_ = true; + bool isSupportMultiInstance_ = true; }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h index b098c90c03..1cc055bd5f 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/include/mock_ui_ability_lifecycle_manager.h @@ -164,6 +164,8 @@ public: void SetRootSceneSession(const sptr &rootSceneSession); int NotifySCBToStartUIAbility(AbilityRequest &abilityRequest); + int32_t NotifySCBToStartUIAbilities(std::vector &abilityRequestList, + const std::string &requestKey); int NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest, sptr &sessionInfo); @@ -446,11 +448,11 @@ private: void NotifyStartSpecifiedAbility(AbilityRequest &request, const AAFwk::Want &want); void NotifyRestartSpecifiedAbility(const AbilityRequest &request, const sptr &token); - int MoveAbilityToFront(const AbilityRequest &abilityRequest, const std::shared_ptr &abilityRecord, - std::shared_ptr callerAbility, std::shared_ptr startOptions, int32_t requestId); + int MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + const std::shared_ptr abilityRecord, std::shared_ptr callerAbility); int SendSessionInfoToSCB(std::shared_ptr &callerAbility, sptr &sessionInfo); - int StartAbilityBySpecifed(const AbilityRequest &abilityRequest, std::shared_ptr &callerAbility, - int32_t requestId); + int StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility); void SetLastExitReason(std::shared_ptr &abilityRecord) const; void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr &abilityRecord) const; @@ -506,7 +508,7 @@ private: bool HandleStartSpecifiedCold(AbilityRequest &abilityRequest, sptr sessionInfo, uint32_t sceneFlag); bool HandleColdAcceptWantDone(const AAFwk::Want &want, const std::string &flag, const SpecifiedRequest &specifiedRequest); - void HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, + void HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want); std::shared_ptr GetSpecifiedRequest(int32_t requestId); bool CheckPrepareTerminateTokens(const std::vector> &tokens, diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_utils.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_utils.cpp index 823ef5308c..0ee52995e3 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_utils.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_app_utils.cpp @@ -192,7 +192,7 @@ int32_t AppUtils::MaxChildProcess() bool AppUtils::IsSupportMultiInstance() { - return true; + return MyStatus::GetInstance().isSupportMultiInstance_; } std::string AppUtils::GetMigrateClientBundleName() @@ -248,5 +248,9 @@ bool AppUtils::IsSupportAppServiceExtension() return true; } +bool AppUtils::IsSupportStartAbilities() +{ + return MyStatus::GetInstance().isSupportStartAbilities_; +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp index 64c379a1ee..79f1e97075 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp @@ -122,6 +122,12 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(AbilityRequest &ability return ERR_OK; } +int32_t UIAbilityLifecycleManager::NotifySCBToStartUIAbilities(std::vector &abilityRequestList, + const std::string &requestKey) +{ + return ERR_OK; +} + int32_t UIAbilityLifecycleManager::NotifySCBToRecoveryAfterInterception(const AbilityRequest &abilityRequest) { return ERR_OK; @@ -398,7 +404,7 @@ void UIAbilityLifecycleManager::OnAcceptWantResponse(const AAFwk::Want &want, co { } -void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(AbilityRequest &abilityRequest, int32_t requestId, +void UIAbilityLifecycleManager::HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest, const std::string &flag, const AAFwk::Want &want) { } @@ -434,9 +440,8 @@ void UIAbilityLifecycleManager::NotifyStartSpecifiedAbility(AbilityRequest &abil { } -int UIAbilityLifecycleManager::MoveAbilityToFront(const AbilityRequest &abilityRequest, - const std::shared_ptr &abilityRecord, std::shared_ptr callerAbility, - std::shared_ptr startOptions, int32_t requestId) +int UIAbilityLifecycleManager::MoveAbilityToFront(const SpecifiedRequest &specifiedRequest, + const std::shared_ptr abilityRecord, std::shared_ptr callerAbility) { return ERR_OK; } @@ -447,8 +452,8 @@ int UIAbilityLifecycleManager::SendSessionInfoToSCB(std::shared_ptr &callerAbility, int32_t requestId) +int UIAbilityLifecycleManager::StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest, + std::shared_ptr callerAbility) { return ERR_OK; } diff --git a/test/unittest/ability_scheduler_stub_second_test/ability_schedule_stub_second_mock.h b/test/unittest/ability_scheduler_stub_second_test/ability_schedule_stub_second_mock.h index 9a8c2b476b..2e2c18dc6a 100644 --- a/test/unittest/ability_scheduler_stub_second_test/ability_schedule_stub_second_mock.h +++ b/test/unittest/ability_scheduler_stub_second_test/ability_schedule_stub_second_mock.h @@ -173,6 +173,9 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + + virtual void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; class MockDataAbilityObserverStub : public DataAbilityObserverStub { 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 c8db58fd67..8d0bf66ed7 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 @@ -170,6 +170,8 @@ public: virtual void ScheduleAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element) override {} + void ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode) override + {} }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp b/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp index e2f953e665..e3016c7e2d 100644 --- a/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_second_test/ui_ability_lifecycle_manager_second_test.cpp @@ -126,11 +126,12 @@ HWTEST_F(UIAbilityLifecycleManagerSecondTest, HandleLegacyAcceptWantDone_001, Te bool reuse = false; std::string flag = ""; int32_t requestId = 1; - mgr->HandleLegacyAcceptWantDone(abilityRequest, requestId, flag, want); - EXPECT_EQ(abilityRequest.specifiedFlag, ""); + SpecifiedRequest specifiedRequest(requestId, abilityRequest); + mgr->HandleLegacyAcceptWantDone(specifiedRequest, flag, want); + EXPECT_EQ(specifiedRequest.abilityRequest.specifiedFlag, ""); flag = "specified"; - mgr->HandleLegacyAcceptWantDone(abilityRequest, requestId, flag, want); - EXPECT_EQ(abilityRequest.specifiedFlag, flag); + mgr->HandleLegacyAcceptWantDone(specifiedRequest, flag, want); + EXPECT_EQ(specifiedRequest.abilityRequest.specifiedFlag, flag); TAG_LOGI(AAFwkTag::TEST, "HandleLegacyAcceptWantDone_001 end."); } diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 841620d8dd..0448a57a03 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -26,6 +26,7 @@ #undef protected #undef private #include "app_mgr_client.h" +#include "hilog_tag_wrapper.h" #include "mock_ability_info_callback_stub.h" #include "process_options.h" #include "session/host/include/session.h" @@ -2576,19 +2577,19 @@ HWTEST_F(UIAbilityLifecycleManagerTest, MoveAbilityToFront_001, TestSize.Level1) { auto uiAbilityLifecycleManager = std::make_shared(); AbilityRequest abilityRequest; - int res = uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, nullptr, nullptr, nullptr, 0); + SpecifiedRequest specifiedRequest(0, abilityRequest); + int res = uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, nullptr, nullptr); EXPECT_EQ(res, ERR_INVALID_VALUE); - abilityRequest.sessionInfo = new SessionInfo(); - abilityRequest.appInfo.bundleName = "com.example.unittest"; - abilityRequest.abilityInfo.name = "MainAbility"; - abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; - std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); - res = uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, nullptr, nullptr, 0); + specifiedRequest.abilityRequest.sessionInfo = new SessionInfo(); + specifiedRequest.abilityRequest.appInfo.bundleName = "com.example.unittest"; + specifiedRequest.abilityRequest.abilityInfo.name = "MainAbility"; + specifiedRequest.abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(specifiedRequest.abilityRequest); + res = uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, nullptr); EXPECT_EQ(res, ERR_OK); - auto startOptions = std::make_shared(); - res = uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, nullptr, nullptr, 0); + res = uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, nullptr); EXPECT_EQ(res, ERR_OK); uiAbilityLifecycleManager.reset(); @@ -2702,8 +2703,26 @@ HWTEST_F(UIAbilityLifecycleManagerTest, StartAbilityBySpecifed_001, TestSize.Lev auto uiAbilityLifecycleManager = std::make_shared(); EXPECT_NE(uiAbilityLifecycleManager, nullptr); AbilityRequest request; + SpecifiedRequest specifiedRequest(0, request); std::shared_ptr callerAbility = nullptr; - uiAbilityLifecycleManager->StartAbilityBySpecifed(request, callerAbility, 0); + uiAbilityLifecycleManager->StartAbilityBySpecifed(specifiedRequest, callerAbility); + uiAbilityLifecycleManager.reset(); +} + +/** + * @tc.name: UIAbilityLifecycleManager_StartAbilityBySpecifed_0200 + * @tc.desc: StartAbilityBySpecifed + * @tc.type: FUNC + */ +HWTEST_F(UIAbilityLifecycleManagerTest, StartAbilityBySpecifed_0200, TestSize.Level1) +{ + auto uiAbilityLifecycleManager = std::make_shared(); + EXPECT_NE(uiAbilityLifecycleManager, nullptr); + AbilityRequest request; + SpecifiedRequest specifiedRequest(0, request); + specifiedRequest.requestListId = 0; + std::shared_ptr callerAbility = nullptr; + uiAbilityLifecycleManager->StartAbilityBySpecifed(specifiedRequest, callerAbility); uiAbilityLifecycleManager.reset(); } @@ -5345,6 +5364,589 @@ HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToStartUIAbility_0003, TestSize ret = mgr->NotifySCBToStartUIAbility(request); } +/** + * @tc.name: NotifySCBToStartUIAbilities_0001 + * @tc.desc: handleListError + */ +HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToStartUIAbilities_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0001 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + std::string requestKey = "requestKey"; + AbilityRequest request; + request.want.SetParam(Want::PARAM_RESV_CALLER_UID, 12345); + for (int i = 0; i < 20; ++i) { + mgr->AddStartCallerTimestamp(12345); + } + requestList.emplace_back(request); + + int ret = mgr->NotifySCBToStartUIAbilities(requestList, requestKey); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0001 end"); +} + +/** + * @tc.name: NotifySCBToStartUIAbilities_0002 + * @tc.desc: SpecifiedProcess true + */ +HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToStartUIAbilities_0002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0002 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + std::string requestKey = "requestKey"; + AppUtils::GetInstance().isStartSpecifiedProcess_.isLoaded = true; + AppUtils::GetInstance().isStartSpecifiedProcess_.value = true; + AbilityRequest request; + request.abilityInfo.isolationProcess = true; + request.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + request.abilityInfo.isStageBasedModel = true; + requestList.emplace_back(request); + + int ret = mgr->NotifySCBToStartUIAbilities(requestList, requestKey); + EXPECT_EQ(ret, START_UI_ABILITIES_WAITING_SPECIFIED_CODE); + + AppUtils::GetInstance().isStartSpecifiedProcess_.isLoaded = false; + AppUtils::GetInstance().isStartSpecifiedProcess_.value = false; + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0002 end"); +} + +/** + * @tc.name: NotifySCBToStartUIAbilities_0003 + * @tc.desc: launchMode Specified + */ +HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToStartUIAbilities_0003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0003 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + std::string requestKey = "requestKey"; + AbilityRequest request; + request.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; + requestList.emplace_back(request); + + int ret = mgr->NotifySCBToStartUIAbilities(requestList, requestKey); + EXPECT_EQ(ret, START_UI_ABILITIES_WAITING_SPECIFIED_CODE); + + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0003 end"); +} + +/** + * @tc.name: NotifySCBToStartUIAbilities_0004 + * @tc.desc: normal + */ +HWTEST_F(UIAbilityLifecycleManagerTest, NotifySCBToStartUIAbilities_0004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0004 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + std::string requestKey = "requestKey"; + AbilityRequest request; + request.abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD; + request.abilityInfo.bundleName = "com.example.bundle"; + request.abilityInfo.name = "AbilityA"; + request.abilityInfo.moduleName = "moduleA"; + request.abilityInfo.isStageBasedModel = true; + request.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + + requestList.emplace_back(request); + + int ret = mgr->NotifySCBToStartUIAbilities(requestList, requestKey); + EXPECT_NE(ret, ERR_OK); + + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest NotifySCBToStartUIAbilities_0004 end"); +} + + +/** + * @tc.name: HandleUIAbilityRequestList_0001 + * @tc.desc: callerUid's timeStamps >= limit + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleUIAbilityRequestList_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleUIAbilityRequestList_0001 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + AbilityRequest request; + request.want.SetParam(Want::PARAM_RESV_CALLER_UID, 12345); + for (int i = 0; i < 20; ++i) { + mgr->AddStartCallerTimestamp(12345); + } + requestList.emplace_back(request); + + int ret = mgr->HandleUIAbilityRequestList(requestList); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleUIAbilityRequestList_0001 end"); +} + +/** + * @tc.name: HandleUIAbilityRequestList_0002 + * @tc.desc: isCallerKilling true? ERR_OK + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleUIAbilityRequestList_0002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleUIAbilityRequestList_0002 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + std::vector requestList; + AbilityRequest request; + requestList.emplace_back(request); + + int ret = mgr->HandleUIAbilityRequestList(requestList); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleUIAbilityRequestList_0002 end"); +} + +/** + * @tc.name: HandleAbilitiesNormalSessionInfo_0001 + * @tc.desc: isCallerKilling true? ERR_OK + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesNormalSessionInfo_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesNormalSessionInfo_0001 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + AbilityRequest request; + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + mgr->HandleAbilitiesNormalSessionInfo(request, abilitiesRequest, requestId); + EXPECT_EQ(abilitiesRequest->doneCount, 1); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesNormalSessionInfo_0001 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0001 + * @tc.desc: sessionInfo nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0001 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + sptr sessionInfo = nullptr; + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_NE(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0001 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0002 + * @tc.desc: callerAbilityRecord nullptr rootSS null + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0002 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->callerToken = nullptr; + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0002 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0003 + * @tc.desc: callerAbilityRecord restart rootSS null + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0003 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + abilityRecord->SetRestartAppFlag(true); + + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0003 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0004 + * @tc.desc: callerAbilityRecord nullptr has rootSS + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0004 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->callerToken = nullptr; + Rosen::SessionInfo rootInfo; + mgr->rootSceneSession_ = new Rosen::Session(rootInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0004 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0005 + * @tc.desc: normal callerAbilityRecord callerSessionInfo nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0005 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0005 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0006 + * @tc.desc: normal callerAbilityRecord callerSessionInfo->sessionToken nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0006 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + + sptr callerSessionInfo = new SessionInfo(); + callerSessionInfo->sessionToken = nullptr; + abilityRecord->SetSessionInfo(callerSessionInfo); + + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0006 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0007 + * @tc.desc: normal callerAbilityRecord callerSession nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0007 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + + sptr callerSessionInfo = new SessionInfo(); + callerSessionInfo->sessionToken = new OHOS::IPCObjectStub(u"desc2"); + abilityRecord->SetSessionInfo(callerSessionInfo); + + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0007 end"); +} + +/** + * @tc.name: BatchNotifySCBPendingActivations_0008 + * @tc.desc: normal callerAbilityRecord ERR_OK + */ +HWTEST_F(UIAbilityLifecycleManagerTest, BatchNotifySCBPendingActivations_0008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0008 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t requestId = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + + sptr callerSessionInfo = new SessionInfo(); + abilityRecord->SetSessionInfo(callerSessionInfo); + + Rosen::SessionInfo info; + sptr sessionInfo(new SessionInfo()); + sessionInfo->sessionToken = new Rosen::Session(info); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + + int32_t ret = mgr->BatchNotifySCBPendingActivations(*abilitiesRequest); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest BatchNotifySCBPendingActivations_0008 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0001 + * @tc.desc: requestListId not found + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0001 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0001 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0002 + * @tc.desc: requestListId found but nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0002 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + mgr->abilitiesRequestMap_.emplace(requestListId, nullptr); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0002 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0003 + * @tc.desc: requestListId found;requestId found;all End;callerRecord nullptr + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0003, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0003 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->doneCount = 1; + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0003 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0004 + * @tc.desc: requestListId found;requestId found;all End;callerRecord exist + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0004 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->doneCount = 1; + + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0004 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0005 + * @tc.desc: requestListId found;requestId found; not End + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0005, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0005 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + abilitiesRequest->sessionInfoList.emplace_back(requestId, sessionInfo); + abilitiesRequest->doneCount = 0; + + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0005 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0006 + * @tc.desc: requestListId found;requestId not found; not End + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0006, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0006 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t otherRequestId = 2; + abilitiesRequest->sessionInfoList.emplace_back(otherRequestId, sessionInfo); + abilitiesRequest->doneCount = 0; + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0006 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0007 + * @tc.desc: requestListId found;requestId not found; End; caller not exist + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0007, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0007 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t otherRequestId = 2; + abilitiesRequest->sessionInfoList.emplace_back(otherRequestId, sessionInfo); + abilitiesRequest->doneCount = 1; + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0007 end"); +} + +/** + * @tc.name: HandleAbilitiesRequestDone_0008 + * @tc.desc: requestListId found;requestId not found; End; caller exist + */ +HWTEST_F(UIAbilityLifecycleManagerTest, HandleAbilitiesRequestDone_0008, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0008 start"); + auto mgr = std::make_shared(); + EXPECT_NE(mgr, nullptr); + int32_t requestId = 1; + int32_t requestListId = 1; + sptr sessionInfo = new SessionInfo(); + + auto abilitiesRequest = std::make_shared(); + EXPECT_NE(abilitiesRequest, nullptr); + int32_t otherRequestId = 2; + abilitiesRequest->sessionInfoList.emplace_back(otherRequestId, sessionInfo); + abilitiesRequest->doneCount = 1; + AbilityRequest abilityRequest; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + EXPECT_NE(abilityRecord, nullptr); + sptr callerToken = abilityRecord->GetToken(); + abilitiesRequest->callerToken = callerToken; + mgr->abilitiesRequestMap_.emplace(requestListId, abilitiesRequest); + + mgr->HandleAbilitiesRequestDone(requestId, requestListId, sessionInfo); + mgr->abilitiesRequestMap_.clear(); + TAG_LOGI(AAFwkTag::TEST, "UIAbilityLifecycleManagerTest HandleAbilitiesRequestDone_0008 end"); +} + /** * @tc.name: NotifySCBToRecoveryAfterInterception_0001 * @tc.desc: launchMode is SPECIFIED diff --git a/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp b/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp index f3cbbf7b62..e524e46078 100644 --- a/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_third_test/ui_ability_lifecycle_manager_third_test.cpp @@ -845,8 +845,8 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, MoveAbilityToFront_001, TestSize.Le abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; AppUtils::isStartOptionsWithAnimation_ = true; - - uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, abilityRecord, nullptr, 0); + SpecifiedRequest specifiedRequest(0, abilityRequest); + uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, abilityRecord); auto sessionInfo = abilityRecord->GetSessionInfo(); EXPECT_NE(sessionInfo->processOptions, nullptr); @@ -870,8 +870,8 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, MoveAbilityToFront_002, TestSize.Le abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; AppUtils::isStartOptionsWithAnimation_ = false; - - uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, abilityRecord, nullptr, 0); + SpecifiedRequest specifiedRequest(0, abilityRequest); + uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, abilityRecord); auto sessionInfo = abilityRecord->GetSessionInfo(); EXPECT_EQ(sessionInfo->processOptions, nullptr); @@ -898,13 +898,12 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, MoveAbilityToFront_003, TestSize.Le AppUtils::isStartOptionsWithAnimation_ = false; - auto startOptions = std::make_shared(); - startOptions->windowMode_ = AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY; - - uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, abilityRecord, startOptions, 0); + SpecifiedRequest specifiedRequest(0, abilityRequest); + specifiedRequest.requestListId = 0; + uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, abilityRecord); auto ret = abilityRecord->want_.GetIntParam(Want::PARAM_RESV_WINDOW_MODE, -1); - EXPECT_EQ(ret, AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY); + EXPECT_EQ(ret, AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); } /** @@ -928,10 +927,8 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, MoveAbilityToFront_004, TestSize.Le AppUtils::isStartOptionsWithAnimation_ = false; - auto startOptions = std::make_shared(); - startOptions->windowMode_ = AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY; - - uiAbilityLifecycleManager->MoveAbilityToFront(abilityRequest, abilityRecord, abilityRecord, nullptr, 0); + SpecifiedRequest specifiedRequest(0, abilityRequest); + uiAbilityLifecycleManager->MoveAbilityToFront(specifiedRequest, abilityRecord, abilityRecord); auto ret = abilityRecord->want_.GetIntParam(Want::PARAM_RESV_WINDOW_MODE, -1); EXPECT_EQ(ret, -1); @@ -1452,7 +1449,7 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, StartSpecifiedAbilityBySCB_002, Tes abilityRequest.abilityInfo.isStageBasedModel = true; AppUtils::isStartSpecifiedProcess_ = true; auto result = uiAbilityLifecycleManager->StartSpecifiedAbilityBySCB(abilityRequest); - EXPECT_EQ(result, uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest)); + EXPECT_EQ(result, uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest, nullptr)); } /** @@ -1474,7 +1471,7 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, StartSpecifiedProcessRequest_0100, abilityRequest.abilityInfo.applicationInfo.multiAppMode.multiAppModeType = AppExecFwk::MultiAppModeType::MULTI_INSTANCE; abilityRequest.want.SetParam(Want::CREATE_APP_INSTANCE_KEY, true); - auto result = uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest); + auto result = uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest, nullptr); EXPECT_EQ(result, ERR_CREATE_INSTANCE_KEY_FAILED); } @@ -1497,7 +1494,7 @@ HWTEST_F(UIAbilityLifecycleManagerThirdTest, StartSpecifiedProcessRequest_0200, abilityRequest.abilityInfo.applicationInfo.multiAppMode.multiAppModeType = AppExecFwk::MultiAppModeType::MULTI_INSTANCE; abilityRequest.want.SetParam(Want::CREATE_APP_INSTANCE_KEY, true); - auto result = uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest); + auto result = uiAbilityLifecycleManager->StartSpecifiedProcessRequest(abilityRequest, nullptr); EXPECT_EQ(result, ERR_OK); } } // namespace AAFwk