diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index a4173eb996..80a80d5382 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -200,6 +200,14 @@ class ApplicationContext { getCurrentAppCloneIndex() { return this.__context_impl__.getCurrentAppCloneIndex(); } + + getCurrentInstanceKey() { + return this.__context_impl__.getCurrentInstanceKey(); + } + + getAllRunningInstanceKeys() { + return this.__context_impl__.getAllRunningInstanceKeys(); + } set area(mode) { return this.__context_impl__.switchArea(mode); diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp index 5c58c8cb8f..edf277d5c2 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.cpp @@ -165,7 +165,10 @@ napi_value CreateJsRunningMultiAppInfo(napi_env env, const RunningMultiAppInfo & } napi_set_named_property(env, object, "bundleName", CreateJsValue(env, info.bundleName)); napi_set_named_property(env, object, "mode", CreateJsValue(env, info.mode)); - napi_set_named_property(env, object, "runningAppClones", CreateJsRunningAppCloneArray(env, info.runningAppClones)); + napi_set_named_property(env, object, "runningAppClones", + CreateJsRunningAppCloneArray(env, info.runningAppClones)); + napi_set_named_property(env, object, "runningMultiInstances", + CreateJsRunningMultiInstanceInfosArray(env, info.runningMultiIntanceInfos)); return object; } @@ -181,6 +184,17 @@ napi_value CreateJsRunningAppCloneArray(napi_env env, const std::vector& data) +{ + napi_value arrayValue = nullptr; + napi_create_array_with_length(env, data.size(), &arrayValue); + uint32_t index = 0; + for (const auto &item : data) { + napi_set_element(env, arrayValue, index++, CreateJsRunningMultiInstanceInfo(env, item)); + } + return arrayValue; +} + napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info) { napi_value object = nullptr; @@ -196,6 +210,21 @@ napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info) return object; } +napi_value CreateJsRunningMultiInstanceInfo(napi_env env, const RunningMultiInstanceInfo &info) +{ + napi_value object = nullptr; + napi_create_object(env, &object); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null obj"); + return nullptr; + } + napi_set_named_property(env, object, "instanceKey", CreateJsValue(env, info.instanceKey)); + napi_set_named_property(env, object, "uid", CreateJsValue(env, info.uid)); + napi_set_named_property(env, object, "pids", CreateNativeArray(env, info.pids)); + + return object; +} + napi_value ApplicationStateInit(napi_env env) { TAG_LOGD(AAFwkTag::APPMGR, "called"); diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.h b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.h index e2d0ad9297..9cfa189192 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.h +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager_utils.h @@ -32,6 +32,7 @@ using OHOS::AppExecFwk::ProcessData; using OHOS::AppExecFwk::RunningProcessInfo; using OHOS::AppExecFwk::RunningMultiAppInfo; using OHOS::AppExecFwk::RunningAppClone; +using OHOS::AppExecFwk::RunningMultiInstanceInfo; #ifdef SUPPORT_GRAPHICS using OHOS::AppExecFwk::AbilityFirstFrameStateData; #endif @@ -69,6 +70,8 @@ JsAppProcessState ConvertToJsAppProcessState( napi_value CreateJsRunningMultiAppInfo(napi_env env, const RunningMultiAppInfo &info); napi_value CreateJsRunningAppCloneArray(napi_env env, const std::vector& data); napi_value CreateJsRunningAppClone(napi_env env, const RunningAppClone &info); +napi_value CreateJsRunningMultiInstanceInfosArray(napi_env env, const std::vector& data); +napi_value CreateJsRunningMultiInstanceInfo(napi_env env, const RunningMultiInstanceInfo &info); } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_JS_APP_MANAGER_UTILS_H 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 980e7a0817..eadb55bead 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 @@ -89,6 +89,11 @@ constexpr const char* ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED = "The extension can not start the specified third party application."; constexpr const char* ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED = "The extension can not start the service."; constexpr const char* ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST = "The target free install task does not exist."; +constexpr const char* ERROR_MSG_MULTI_INSTANCE_NOT_SUPPORTED = "Multi-instance is not supported."; +constexpr const char* ERROR_MSG_INVALID_APP_INSTANCE_KEY = "The app instance key does not exist."; +constexpr const char* ERROR_MSG_UPPER_LIMIT = "The number of app instances reaches the limit."; +constexpr const char* ERROR_MSG_APP_INSTANCE_KEY_NOT_SUPPORT = "The APP_INSTANCE_KEY cannot be specified."; +constexpr const char* ERROR_MSG_CREATE_NEW_INSTANCE_NOT_SUPPORT = "Creating a new instance 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; @@ -150,7 +155,12 @@ static std::unordered_map ERR_CODE_MAP = { ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED }, { AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED, ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED}, { AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST}, - { AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST, ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST } + { AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST, ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST }, + { AbilityErrorCode::ERROR_MULTI_INSTANCE_NOT_SUPPORTED, ERROR_MSG_MULTI_INSTANCE_NOT_SUPPORTED }, + { AbilityErrorCode::ERROR_CODE_INVALID_APP_INSTANCE_KEY, ERROR_MSG_INVALID_APP_INSTANCE_KEY }, + { AbilityErrorCode::ERROR_CODE_UPPER_LIMIT, ERROR_MSG_UPPER_LIMIT }, + { AbilityErrorCode::ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORT, ERROR_MSG_APP_INSTANCE_KEY_NOT_SUPPORT }, + { AbilityErrorCode::ERROR_CODE_CREATE_NEW_INSTANCE_NOT_SUPPORT, ERROR_MSG_CREATE_NEW_INSTANCE_NOT_SUPPORT }, }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -215,6 +225,12 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {EXTENSION_BLOCKED_BY_SERVICE_LIST, AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED}, {ERR_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID}, {ERR_FREE_INSTALL_TASK_NOT_EXIST, AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST}, + {ERR_MULTI_INSTANCE_NOT_SUPPORTED, AbilityErrorCode::ERROR_MULTI_INSTANCE_NOT_SUPPORTED}, + {ERR_NOT_SUPPORT_APP_CLONE, AbilityErrorCode::ERROR_NOT_APP_CLONE}, + {ERR_INVALID_APP_INSTANCE_KEY, AbilityErrorCode::ERROR_CODE_INVALID_APP_INSTANCE_KEY}, + {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}, }; } diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 9ef32f5f3c..d3b82bfc07 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -598,6 +598,12 @@ int32_t ApplicationContext::GetProcessRunningInformation(AppExecFwk::RunningProc return (contextImpl_ != nullptr) ? contextImpl_->GetProcessRunningInformation(info) : -1; } +int32_t ApplicationContext::GetAllRunningInstanceKeys(const std::string& bundleName, + std::vector &instanceKeys) +{ + return (contextImpl_ != nullptr) ? contextImpl_->GetAllRunningInstanceKeys(bundleName, instanceKeys) : -1; +} + bool ApplicationContext::IsUpdatingConfigurations() { return (contextImpl_ != nullptr) ? contextImpl_->IsUpdatingConfigurations() : false; @@ -826,6 +832,11 @@ int32_t ApplicationContext::GetCurrentAppMode() return appMode_; } +std::string ApplicationContext::GetCurrentInstanceKey() +{ + TAG_LOGD(AAFwkTag::APPKIT, "getCurrentInstanceKey is %{public}s", instanceKey_.c_str()); + return instanceKey_; +} void ApplicationContext::SetAppRunningUniqueId(const std::string &appRunningUniqueId) { @@ -854,6 +865,12 @@ void ApplicationContext::SetCurrentAppMode(int32_t appMode) appMode_ = appMode; } +void ApplicationContext::SetCurrentInstanceKey(const std::string& instanceKey) +{ + TAG_LOGD(AAFwkTag::APPKIT, "setCurrentInstanceKey is %{public}s", instanceKey.c_str()); + instanceKey_ = instanceKey; +} + void ApplicationContext::ProcessSecurityExit(const AAFwk::ExitReason &exitReason) { if (appProcessExitCallback_ == nullptr) { diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index cc11655d05..522e09566e 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -1239,6 +1239,15 @@ int32_t ContextImpl::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo return result; } +int32_t ContextImpl::GetAllRunningInstanceKeys(const std::string& bundleName, + std::vector &instanceKeys) +{ + auto appMgrClient = DelayedSingleton::GetInstance(); + auto result = appMgrClient->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + TAG_LOGD(AAFwkTag::APPKIT, "result is %{public}d", result); + return result; +} + int32_t ContextImpl::RestartApp(const AAFwk::Want& want) { auto result = OHOS::AAFwk::AbilityManagerClient::GetInstance()->RestartApp(want); diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 26046c49c2..7afc1f2d2d 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -938,6 +938,70 @@ napi_value JsApplicationContextUtils::OnGetCurrentAppCloneIndex(napi_env env, Na return CreateJsValue(env, appIndex); } +napi_value JsApplicationContextUtils::GetCurrentInstanceKey(napi_env env, napi_callback_info info) +{ + GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, + OnGetCurrentInstanceKey, APPLICATION_CONTEXT_NAME); +} + +napi_value JsApplicationContextUtils::OnGetCurrentInstanceKey(napi_env env, NapiCallbackInfo& info) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Get current instance key"); + auto context = applicationContext_.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "context is nullptr."); + ThrowError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT); + return CreateJsUndefined(env); + } + if (context->GetCurrentAppMode() != static_cast(AppExecFwk::MultiAppModeType::MULTI_INSTANCE)) { + ThrowError(env, AbilityErrorCode::ERROR_MULTI_INSTANCE_NOT_SUPPORTED); + return CreateJsUndefined(env); + } + std::string instanceKey = context->GetCurrentInstanceKey(); + return CreateJsValue(env, instanceKey); +} + +napi_value JsApplicationContextUtils::GetAllRunningInstanceKeys(napi_env env, napi_callback_info info) +{ + GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, + OnGetAllRunningInstanceKeys, APPLICATION_CONTEXT_NAME); +} + +napi_value JsApplicationContextUtils::OnGetAllRunningInstanceKeys(napi_env env, NapiCallbackInfo& info) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Get all running instance keys"); + auto innerErrCode = std::make_shared(ERR_OK); + std::shared_ptr> instanceKeys; + NapiAsyncTask::ExecuteCallback execute = + [applicationContext = applicationContext_, innerErrCode, instanceKeys]() { + auto context = applicationContext.lock(); + if (!context) { + TAG_LOGE(AAFwkTag::APPKIT, "applicationContext is released"); + *innerErrCode = ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST; + return; + } + if (context->GetCurrentAppMode() != static_cast(AppExecFwk::MultiAppModeType::MULTI_INSTANCE)) { + *innerErrCode = static_cast(AbilityErrorCode::ERROR_MULTI_INSTANCE_NOT_SUPPORTED); + return; + } + std::string bundleName = context->GetBundleName(); + *innerErrCode = context->GetAllRunningInstanceKeys(bundleName, *instanceKeys); + }; + auto complete = [applicationContext = applicationContext_, innerErrCode, instanceKeys]( + napi_env env, NapiAsyncTask& task, int32_t status) { + if (*innerErrCode != ERR_OK) { + task.Reject(env, CreateJsError(env, *innerErrCode, "failed to get instance keys.")); + return; + } + task.ResolveWithNoError(env, CreateNativeArray(env, *instanceKeys)); + }; + + napi_value result = nullptr; + NapiAsyncTask::Schedule("JsApplicationContextUtils::OnGetRunningProcessInformation", + env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result)); + return result; +} + void JsApplicationContextUtils::Finalizer(napi_env env, void *data, void *hint) { TAG_LOGD(AAFwkTag::APPKIT, "called"); @@ -1536,7 +1600,8 @@ napi_value JsApplicationContextUtils::CreateJsApplicationContext(napi_env env) napi_set_named_property(env, object, "resourceManager", CreateJsResourceManager(env, resourceManager, context)); } - BindNativeApplicationContext(env, object); + BindNativeApplicationContextOne(env, object); + BindNativeApplicationContextTwo(env, object); return object; } @@ -1582,7 +1647,7 @@ napi_value JsApplicationContextUtils::OnSetSupportedProcessCacheSelf(napi_env en return CreateJsUndefined(env); } -void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_value object) +void JsApplicationContextUtils::BindNativeApplicationContextOne(napi_env env, napi_value object) { BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir); BindNativeProperty(env, object, "tempDir", JsApplicationContextUtils::GetTempDir); @@ -1619,6 +1684,10 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_ BindNativeFunction(env, object, "setFont", MD_NAME, JsApplicationContextUtils::SetFont); BindNativeFunction(env, object, "clearUpApplicationData", MD_NAME, JsApplicationContextUtils::ClearUpApplicationData); +} + +void JsApplicationContextUtils::BindNativeApplicationContextTwo(napi_env env, napi_value object) +{ BindNativeFunction(env, object, "preloadUIExtensionAbility", MD_NAME, JsApplicationContextUtils::PreloadUIExtensionAbility); BindNativeFunction(env, object, "getProcessRunningInformation", MD_NAME, @@ -1627,6 +1696,10 @@ void JsApplicationContextUtils::BindNativeApplicationContext(napi_env env, napi_ JsApplicationContextUtils::GetRunningProcessInformation); BindNativeFunction(env, object, "getCurrentAppCloneIndex", MD_NAME, JsApplicationContextUtils::GetCurrentAppCloneIndex); + BindNativeFunction(env, object, "getCurrentInstanceKey", MD_NAME, + JsApplicationContextUtils::GetCurrentInstanceKey); + BindNativeFunction(env, object, "getAllRunningInstanceKeys", MD_NAME, + JsApplicationContextUtils::GetAllRunningInstanceKeys); BindNativeFunction(env, object, "getGroupDir", MD_NAME, JsApplicationContextUtils::GetGroupDir); BindNativeFunction(env, object, "restartApp", MD_NAME, JsApplicationContextUtils::RestartApp); BindNativeFunction(env, object, "setSupportedProcessCache", MD_NAME, diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index d152a15c48..46531f9bd1 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1401,7 +1401,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con std::shared_ptr applicationContext = AbilityRuntime::ApplicationContext::GetInstance(); int32_t appIndex = appLaunchData.GetAppIndex(); + std::string instanceKey = appLaunchData.GetInstanceKey(); applicationContext->SetCurrentAppCloneIndex(appIndex); + applicationContext->SetCurrentInstanceKey(instanceKey); applicationContext->SetCurrentAppMode(static_cast(appInfo.multiAppMode.multiAppModeType)); applicationContext->AttachContextImpl(contextImpl); auto appRunningId = appLaunchData.GetAppRunningUniqueId(); 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 99ebf31172..bfef9e11c6 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -611,6 +611,41 @@ enum { */ ERR_ALL_APP_START_BLOCKED = 2097270, + /** + * Result(2097271) not support multi-instance. + */ + ERR_MULTI_INSTANCE_NOT_SUPPORTED = 2097271, + + /* + * Result (2097272) for not support app instance key. + */ + ERR_APP_INSTANCE_KEY_NOT_SUPPORT = 2097272, + + /* + * Result (2097273) for reach the upper limit. + */ + ERR_UPPER_LIMIT = 2097273, + + /* + * Result (2097274) for not support to create a new instance. + */ + ERR_CREATE_NEW_INSTANCE_NOT_SUPPORT = 2097274, + + /* + * Result (2097275) for invalid app instance key. + */ + ERR_INVALID_APP_INSTANCE_KEY = 2097275, + + /* + * Result (2097276) for not support app clone. + */ + ERR_NOT_SUPPORT_APP_CLONE = 2097276, + + /* + * Result (2097277) for invalid extension type. + */ + ERR_INVALID_EXTENSION_TYPE = 2097277, + /** * Native error(3000000) for target bundle not exist. */ diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h index 264466c88c..91f04eb17f 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h @@ -212,6 +212,16 @@ public: appRunningUniqueId_ = appRunningUniqueId; } + inline std::string GetInstanceKey() const + { + return instanceKey_; + } + + inline void SetInstanceKey(const std::string& instanceKey) + { + instanceKey_ = instanceKey; + } + /** * @brief read this Sequenceable object from a Parcel. * @@ -261,6 +271,7 @@ private: bool isMultiThread_ = false; bool isErrorInfoEnhance_ = false; std::string appRunningUniqueId_; + std::string instanceKey_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index a9210d68d1..7aefcf17b9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -234,6 +234,17 @@ public: */ virtual AppMgrResultCode GetProcessRunningInformation(RunningProcessInfo &info); + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys); + /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. * Obtains information about render processes that are running on the device. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index c41eac2d23..ba13c3b721 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -158,6 +158,17 @@ public: virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info) = 0; + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) = 0; + /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. * Obtains information about application processes by bundle type that are running on the device. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index b96c5b65be..cd7a225eaa 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -115,6 +115,7 @@ enum class AppMgrInterfaceCode { SET_SUPPORTED_PROCESS_CACHE = 89, REGISTER_KIA_INTERCEPTOR = 90, CHECK_IS_KIA_PROCESS = 91, + GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME = 92, }; } // AppExecFwk } // OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 30723a40b9..cae03fc441 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -135,6 +135,17 @@ public: virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info) override; + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) override; + /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. * Obtains information about application processes by bundle type that are running on the device. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index 6bdf62d82e..4ed56316d2 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -105,6 +105,7 @@ private: int32_t HandleDumpHeapMemory(MessageParcel &data, MessageParcel &reply); int32_t HandleDumpJsHeapMemory(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRunningMultiAppInfoByBundleName(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetAllRunningInstanceKeysByBundleName(MessageParcel &data, MessageParcel &reply); int32_t HandleIsAppRunning(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/include/appmgr/running_multi_info.h b/interfaces/inner_api/app_manager/include/appmgr/running_multi_info.h index 954c4cd109..aecd6051d4 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/running_multi_info.h +++ b/interfaces/inner_api/app_manager/include/appmgr/running_multi_info.h @@ -25,17 +25,25 @@ namespace OHOS { namespace AppExecFwk { -const int32_t MAX_CLONE_APP_NUM = 128; +constexpr int32_t MAX_CLONE_APP_NUM = 128; +constexpr int32_t MAX_INSTANCE_NUM = 10; struct RunningAppClone { int32_t appCloneIndex; int32_t uid; std::vector pids; }; +struct RunningMultiInstanceInfo { + std::string instanceKey; + int32_t uid; + std::vector pids; +}; + struct RunningMultiAppInfo : public Parcelable { std::string bundleName; int32_t mode; std::vector runningAppClones; + std::vector runningMultiIntanceInfos; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp index b2f3bf8966..6f407f319f 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp @@ -106,6 +106,11 @@ bool AppLaunchData::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteString(instanceKey_)) { + TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write instance key."); + return false; + } + return true; } @@ -152,6 +157,7 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel) appRunningUniqueId_ = parcel.ReadString(); isMultiThread_ = parcel.ReadBool(); isErrorInfoEnhance_ = parcel.ReadBool(); + instanceKey_ = parcel.ReadString(); return true; } diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index ef82685b22..0424fd2884 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -416,6 +416,20 @@ AppMgrResultCode AppMgrClient::GetProcessRunningInformation(AppExecFwk::RunningP return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } +AppMgrResultCode AppMgrClient::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service != nullptr) { + int32_t result = service->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + if (result == ERR_OK) { + return AppMgrResultCode::RESULT_OK; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_READY; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + AppMgrResultCode AppMgrClient::GetAllRenderProcesses(std::vector &info) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 85e4014ad2..c004d04055 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -219,6 +219,25 @@ int32_t AppMgrProxy::GetRunningMultiAppInfoByBundleName(const std::string &bundl return result; } +int32_t AppMgrProxy::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return ERR_FLATTEN_OBJECT; + } + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME, data, reply, option); + if (!reply.ReadStringVector(&instanceKeys)) { + return ERR_INVALID_DATA; + } + int32_t result = reply.ReadInt32(); + return result; +} + int32_t AppMgrProxy::GetRunningProcessesByBundleType(const BundleType bundleType, std::vector &info) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 0e9689bbad..8a2d849cbc 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -213,6 +213,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data return HandleStartNativeProcessForDebugger(data, reply); case static_cast(AppMgrInterfaceCode::NOTIFY_APP_FAULT): return HandleNotifyFault(data, reply); + case static_cast(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME): + return HandleGetAllRunningInstanceKeysByBundleName(data, reply); } return INVALID_FD; } @@ -493,6 +495,22 @@ int32_t AppMgrStub::HandleGetRunningMultiAppInfoByBundleName(MessageParcel &data return NO_ERROR; } +int32_t AppMgrStub::HandleGetAllRunningInstanceKeysByBundleName(MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName = data.ReadString(); + std::vector instanceKeys; + int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); + if (!reply.WriteStringVector(instanceKeys)) { + TAG_LOGE(AAFwkTag::APPMGR, "failed to write isntanceKeys"); + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::APPMGR, "fail to write result."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleGetRunningProcessesByBundleType(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); diff --git a/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp b/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp index 5c4aa852bf..0203439de2 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/running_multi_info.cpp @@ -39,6 +39,19 @@ bool RunningMultiAppInfo::ReadFromParcel(Parcel &parcel) parcel.ReadInt32Vector(&clone.pids); runningAppClones.emplace_back(clone); } + + int32_t runningMultiIntanceInfosSize; + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, runningMultiIntanceInfosSize); + if (runningMultiIntanceInfosSize > MAX_INSTANCE_NUM) { + return false; + } + for (auto i = 0; i < runningMultiIntanceInfosSize; i++) { + RunningMultiInstanceInfo instanceInfo; + instanceInfo.instanceKey = Str16ToStr8(parcel.ReadString16()); + instanceInfo.uid = parcel.ReadInt32(); + parcel.ReadInt32Vector(&instanceInfo.pids); + runningMultiIntanceInfos.emplace_back(instanceInfo); + } return true; } @@ -69,6 +82,18 @@ bool RunningMultiAppInfo::Marshalling(Parcel &parcel) const return false; } } + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, runningMultiIntanceInfos.size()); + if (runningMultiIntanceInfos.size() > MAX_INSTANCE_NUM) { + return false; + } + for (auto &instanceInfo : runningMultiIntanceInfos) { + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(instanceInfo.instanceKey)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, instanceInfo.uid); + if (!parcel.WriteInt32Vector(instanceInfo.pids)) { + TAG_LOGE(AAFwkTag::APPMGR, "write runningMultiIntanceInfos failed."); + return false; + } + } return true; } } // namespace AppExecFwk 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 d3a6717d8f..08bab4c4ea 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 @@ -162,6 +162,21 @@ enum class AbilityErrorCode { // Not support back to caller. ERROR_CODE_NOT_SUPPROT_BACK_TO_CALLER = 16000075, + // invalid app instance key. + ERROR_CODE_INVALID_APP_INSTANCE_KEY = 16000076, + + // upper limit. + ERROR_CODE_UPPER_LIMIT = 16000077, + + // The multi-instance is not supported. + ERROR_MULTI_INSTANCE_NOT_SUPPORTED = 16000078, + + // APP_INSTANCE_KEY cannot be specified. + ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORT = 16000079, + + // Not support to create a new instance. + ERROR_CODE_CREATE_NEW_INSTANCE_NOT_SUPPORT = 16000080, + // invalid caller. ERROR_CODE_INVALID_CALLER = 16200001, diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index c1ecac0b5c..5993329312 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -143,6 +143,10 @@ public: int32_t SetSupportedProcessCacheSelf(bool isSupport); int32_t GetCurrentAppCloneIndex(); void SetCurrentAppCloneIndex(int32_t appIndex); + std::string GetCurrentInstanceKey(); + void SetCurrentInstanceKey(const std::string& instanceKey); + int32_t GetAllRunningInstanceKeys(const std::string& bundleName, + std::vector &instanceKeys); int32_t GetCurrentAppMode(); void SetCurrentAppMode(int32_t appIndex); void ProcessSecurityExit(const AAFwk::ExitReason &exitReason); @@ -171,6 +175,7 @@ private: std::string appRunningUniqueId_; int32_t appIndex_ = 0; int32_t appMode_ = 0; + std::string instanceKey_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index df08abe162..ac9b86cd11 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -351,6 +351,14 @@ public: */ int32_t GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); + /** + * @brief Get all running instance keys for the current app + * + * @return error code + */ + int32_t GetAllRunningInstanceKeys(const std::string& bundleName, + std::vector &instanceKeys); + /** * @brief Restart app * diff --git a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h index cfeccb41cf..dd76d1fc7d 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/js_application_context_utils.h @@ -100,6 +100,8 @@ public: napi_value OnSetSupportedProcessCacheSelf(napi_env env, NapiCallbackInfo& info); napi_value OnPreloadUIExtensionAbility(napi_env env, NapiCallbackInfo& info); napi_value OnGetCurrentAppCloneIndex(napi_env env, NapiCallbackInfo& info); + napi_value OnGetCurrentInstanceKey(napi_env env, NapiCallbackInfo& info); + napi_value OnGetAllRunningInstanceKeys(napi_env env, NapiCallbackInfo& info); napi_value OnSetFontSizeScale(napi_env env, NapiCallbackInfo& info); static napi_value GetCacheDir(napi_env env, napi_callback_info info); @@ -124,6 +126,8 @@ public: static napi_value SetSupportedProcessCacheSelf(napi_env env, napi_callback_info info); static napi_value PreloadUIExtensionAbility(napi_env env, napi_callback_info info); static napi_value GetCurrentAppCloneIndex(napi_env env, napi_callback_info info); + static napi_value GetCurrentInstanceKey(napi_env env, napi_callback_info info); + static napi_value GetAllRunningInstanceKeys(napi_env env, napi_callback_info info); static napi_value SetFontSizeScale(napi_env env, napi_callback_info info); protected: @@ -139,7 +143,8 @@ private: napi_value OnCreateSystemHspModuleResourceManager(napi_env env, NapiCallbackInfo& info); napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo& info); bool CheckCallerIsSystemApp(); - static void BindNativeApplicationContext(napi_env env, napi_value object); + static void BindNativeApplicationContextOne(napi_env env, napi_value object); + static void BindNativeApplicationContextTwo(napi_env env, napi_value object); static JsAppProcessState ConvertToJsAppProcessState( const AppExecFwk::AppProcessState &appProcessState, const bool &isFocused); std::shared_ptr callback_; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index e152ea7e75..9ced8c4761 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2287,6 +2287,8 @@ private: void SendStartAbilityOtherExtensionEvent(const AppExecFwk::AbilityInfo& abilityInfo, const Want& want, uint32_t specifyTokenId); + + void SetMinimizedDuringFreeInstall(const sptr& sessionInfo); /** * @brief Check debug app in developer mode. diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 8f035611f5..7df38fd4ed 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -1093,6 +1093,11 @@ public: void RemoveConnectWant(); + inline std::string GetInstanceKey() const + { + return instanceKey_; + } + protected: void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false); @@ -1318,6 +1323,7 @@ private: ffrt::mutex connectWantLock_; bool isLaunching_ = true; LaunchDebugInfo launchDebugInfo_; + std::string instanceKey_ = ""; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_util.h b/services/abilitymgr/include/ability_util.h index 3816fd9093..d6c1e145f1 100644 --- a/services/abilitymgr/include/ability_util.h +++ b/services/abilitymgr/include/ability_util.h @@ -306,12 +306,29 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi } } +[[maybe_unused]] static void RemoveInstanceKey(Want &want) +{ + want.RemoveParam(Want::APP_INSTANCE_KEY); + want.RemoveParam(Want::CREATE_APP_INSTANCE_KEY); +} + [[maybe_unused]] static void RemoveWantKey(Want &want) { RemoveShowModeKey(want); RemoveWindowModeKey(want); } +[[maybe_unused]] static int32_t CheckInstanceKey(const Want &want) +{ + auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); + auto isCreating = want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); + if (!instanceKey.empty() || isCreating) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support multi-instance"); + return ERR_MULTI_INSTANCE_NOT_SUPPORTED; + } + return ERR_OK; +} + [[maybe_unused]] static void WantSetParameterWindowMode(Want &want, int32_t windowMode) { want.SetParam(Want::PARAM_RESV_WINDOW_MODE, windowMode); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 93d11920e3..136df08fef 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -139,7 +139,7 @@ public: */ int LoadAbility(sptr token, sptr preToken, const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, - const Want &want, int32_t abilityRecordId); + const Want &want, int32_t abilityRecordId, const std::string &instanceKey); /** * terminate ability with token. diff --git a/services/abilitymgr/include/utils/ability_permission_util.h b/services/abilitymgr/include/utils/ability_permission_util.h index d85ec5109f..74729154b3 100644 --- a/services/abilitymgr/include/utils/ability_permission_util.h +++ b/services/abilitymgr/include/utils/ability_permission_util.h @@ -38,10 +38,19 @@ public: // check dominate screen bool IsDominateScreen(const Want &want, bool isPendingWantCaller); + int32_t CheckMultiInstanceAndAppClone(Want &want, int32_t userId, int32_t appIndex, + sptr callerToken); + private: AbilityPermissionUtil() = default; ~AbilityPermissionUtil() = default; + int32_t CheckMultiInstance(Want &want, sptr callerToken, bool isCreating, + const std::string &instanceKey, int32_t maxCount); + + int32_t UpdateInstanceKey(Want &want, const std::string &originInstanceKey, + const std::vector &instanceKeyArray, const std::string &instanceKey); + DISALLOW_COPY_AND_MOVE(AbilityPermissionUtil); }; } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 99c29dac18..90eaafc9a9 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1392,7 +1392,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr &ab UpdateUIExtensionInfo(abilityRecord); DelayedSingleton::GetInstance()->LoadAbility( token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), - abilityRecord->GetWant(), abilityRecord->GetRecordId()); + abilityRecord->GetWant(), abilityRecord->GetRecordId(), ""); abilityRecord->SetLoadState(AbilityLoadState::LOADING); } diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 426def264e..6cf8e02c83 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -616,6 +616,7 @@ int32_t AbilityManagerService::StartAbilityByInsightIntent(const Want &want, con std::string bundleNameFromAbilityRecord = abilityRecord->GetAbilityInfo().bundleName; if (!bundleNameFromWant.empty() && bundleNameFromWant == bundleNameFromIntentMgr && bundleNameFromWant == bundleNameFromAbilityRecord) { + AbilityUtil::RemoveInstanceKey(const_cast(want)); TAG_LOGI(AAFwkTag::ABILITYMGR, "bundleName match"); return StartAbility(want, callerToken, userId, -1); } @@ -653,6 +654,7 @@ int AbilityManagerService::StartAbilityByUIContentSession(const Want &want, cons TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken unequal to top ablity token"); return NOT_TOP_ABILITY; } + AbilityUtil::RemoveInstanceKey(const_cast(want)); return StartAbility(want, callerToken, userId, requestCode); } @@ -1036,6 +1038,11 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want), + validUserId, appIndex, callerToken); + if (checkRet != ERR_OK) { + return checkRet; + } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), @@ -1066,6 +1073,10 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr 0 && callerToken != nullptr) { // for sa specify tokenId and caller token UpdateCallerInfoFromToken(abilityRequest.want, callerToken); @@ -1362,6 +1373,11 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) { return ERR_APP_CLONE_INDEX_INVALID; } + auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), + validUserId, appIndex, callerToken); + if (checkRet != ERR_OK) { + return checkRet; + } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), @@ -1396,6 +1412,10 @@ int AbilityManagerService::StartAbilityDetails(const Want &want, const AbilitySt AbilityRequest abilityRequest; #ifdef SUPPORT_SCREEN if (ImplicitStartProcessor::IsImplicitStartAction(want)) { + auto checkResult = AbilityUtil::CheckInstanceKey(want); + if (checkResult != ERR_OK) { + return checkResult; + } abilityRequest.Voluation( want, requestCode, callerToken, std::make_shared(abilityStartSetting)); abilityRequest.callType = AbilityCallType::START_SETTINGS_TYPE; @@ -1656,6 +1676,11 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) { return ERR_APP_CLONE_INDEX_INVALID; } + auto checkRet = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), + validUserId, appIndex, callerToken); + if (checkRet != ERR_OK) { + return checkRet; + } StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), @@ -1693,6 +1718,10 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St AbilityRequest abilityRequest; #ifdef SUPPORT_SCREEN if (ImplicitStartProcessor::IsImplicitStartAction(want)) { + auto checkResult = AbilityUtil::CheckInstanceKey(want); + if (checkResult != ERR_OK) { + return checkResult; + } abilityRequest.Voluation(want, requestCode, callerToken); if (PermissionVerification::GetInstance()->IsSystemAppCall()) { bool windowFocused = startOptions.GetWindowFocused(); @@ -3537,6 +3566,8 @@ int AbilityManagerService::CloseUIAbilityBySCB(const sptr &sessionI return ERR_WRONG_INTERFACE_CALL; } + SetMinimizedDuringFreeInstall(sessionInfo); + auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::ABILITYMGR, @@ -3771,6 +3802,51 @@ int AbilityManagerService::MinimizeUIExtensionAbility(const sptr &e return ERR_OK; } +void AbilityManagerService::SetMinimizedDuringFreeInstall(const sptr &sessionInfo) +{ + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo null"); + return; + } + + if (!(sessionInfo->want).HasParameter(KEY_SESSION_ID)) { + return; + } + + std::string sessionId = (sessionInfo->want).GetStringParam(KEY_SESSION_ID); + if (sessionId.empty()) { + return; + } + + if (freeInstallManager_ == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "freeInstallManager_ null"); + return; + } + FreeInstallInfo taskInfo; + if (!freeInstallManager_->GetFreeInstallTaskInfo(sessionId, taskInfo)) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "free install task with sessionId=%{public}s does not exist", + sessionId.c_str()); + return; + } + + if (taskInfo.isFreeInstallFinished) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "free install task finished"); + return; + } + + { + std::lock_guard guard(preStartSessionMapLock_); + preStartSessionMap_.insert(std::make_pair(sessionId, sessionInfo)); + auto it = preStartSessionMap_.find(sessionId); + if (it == preStartSessionMap_.end()) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "session info with sessionId=%{public}s does not exist", + sessionId.c_str()); + return; + } + it->second->isMinimizedDuringFreeInstall = true; + } +} + int AbilityManagerService::MinimizeUIAbilityBySCB(const sptr &sessionInfo, bool fromUser, uint32_t sceneFlag) { @@ -3786,6 +3862,8 @@ int AbilityManagerService::MinimizeUIAbilityBySCB(const sptr &sessi return ERR_WRONG_INTERFACE_CALL; } + SetMinimizedDuringFreeInstall(sessionInfo); + auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); auto abilityRecord = uiAbilityManager->GetUIAbilityRecordBySessionInfo(sessionInfo); @@ -7138,6 +7216,11 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr(want), + GetUserId(), appIndex, callerToken); + if (checkRet != ERR_OK) { + return checkRet; + } StartAbilityInfoWrap threadLocalInfo(want, GetUserId(), appIndex, callerToken); auto shouldBlockFunc = [aams = shared_from_this()]() { return aams->ShouldBlockAllAppStart(); }; AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), true, nullptr, @@ -8066,6 +8149,16 @@ int AbilityManagerService::StartUserTest(const Want &want, const sptrGetHandlerName() == StartAbilitySandboxSavefile::handlerName_) { @@ -10195,6 +10292,12 @@ void AbilityManagerService::StartSpecifiedAbilityBySCB(const Want &want) TAG_LOGE(AAFwkTag::ABILITYMGR, "no sceneboard called, no allowed"); return; } + int32_t appIndex = 0; + if (!StartAbilityUtils::GetAppIndex(want, nullptr, appIndex)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid app clone index"); + } + (void)AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(const_cast(want), + GetUserId(), appIndex, nullptr); auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER(uiAbilityManager); uiAbilityManager->StartSpecifiedAbilityBySCB(want); @@ -10645,6 +10748,7 @@ int32_t AbilityManagerService::StartAbilityWithInsightIntent(const Want &want, i CHECK_CALLER_IS_SYSTEM_APP; } AbilityUtil::RemoveShowModeKey(const_cast(want)); + AbilityUtil::RemoveInstanceKey(const_cast(want)); EventInfo eventInfo = BuildEventInfo(want, userId); SendAbilityEvent(EventName::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); int32_t ret = StartAbilityWrap(want, nullptr, requestCode, false, userId); @@ -10673,6 +10777,7 @@ int32_t AbilityManagerService::StartAbilityByCallWithInsightIntent(const Want &w } AbilityUtil::RemoveWantKey(const_cast(want)); + AbilityUtil::RemoveInstanceKey(const_cast(want)); AbilityRequest abilityRequest; abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE; abilityRequest.callerUid = IPCSkeleton::GetCallingUid(); @@ -11842,6 +11947,12 @@ int32_t AbilityManagerService::StartUIAbilityByPreInstall(const FreeInstallInfo (sessionInfo->want).SetElement(want.GetElement()); } + if (sessionInfo == nullptr || sessionInfo->isMinimizedDuringFreeInstall) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo is nullptr or ability is already minimized"); + RemovePreStartSession(sessionId); + return ERR_INVALID_VALUE; + } + int errCode = ERR_OK; bool isColdStart = true; if ((errCode = StartUIAbilityByPreInstallInner(sessionInfo, taskInfo.specifyTokenId, 0, isColdStart)) != ERR_OK) { @@ -12013,7 +12124,7 @@ ErrCode AbilityManagerService::OpenLink(const Want& want, sptr ca int32_t userId, int requestCode) { TAG_LOGI(AAFwkTag::ABILITYMGR, "call"); - + AbilityUtil::RemoveInstanceKey(const_cast(want)); std::string callerBundleName; Want convertedWant = want; if (!WantUtils::IsAtomicServiceUrl(want) || @@ -12059,6 +12170,8 @@ int32_t AbilityManagerService::CleanUIAbilityBySCB(const sptr &sess return ERR_WRONG_INTERFACE_CALL; } + SetMinimizedDuringFreeInstall(sessionInfo); + auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::ABILITYMGR, "user request clean session: %{public}d", sessionInfo->persistentId); diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 1fbea7e5f1..52493674aa 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -219,6 +219,9 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRecord->SetAppIndex(appIndex); abilityRecord->SetCallerAccessTokenId(abilityRequest.callerAccessTokenId); abilityRecord->sessionInfo_ = abilityRequest.sessionInfo; + if (abilityRequest.sessionInfo != nullptr) { + abilityRecord->instanceKey_ = abilityRequest.sessionInfo->instanceKey; + } if (!abilityRecord->Init()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "failed init"); return nullptr; @@ -331,7 +334,7 @@ int AbilityRecord::LoadAbility() std::lock_guard guard(wantLock_); want_.SetParam(ABILITY_OWNER_USERID, ownerMissionUserId_); auto result = DelayedSingleton::GetInstance()->LoadAbility( - token_, callerToken_, abilityInfo_, abilityInfo_.applicationInfo, want_, recordId_); + token_, callerToken_, abilityInfo_, abilityInfo_.applicationInfo, want_, recordId_, instanceKey_); want_.RemoveParam(ABILITY_OWNER_USERID); SetLoadState(AbilityLoadState::LOADING); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 32bfe70be2..02bc40ede2 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -68,7 +68,7 @@ bool AppScheduler::Init(const std::weak_ptr &callback) int AppScheduler::LoadAbility(sptr token, sptr preToken, const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, - const Want &want, int32_t abilityRecordId) + const Want &want, int32_t abilityRecordId, const std::string &instanceKey) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); @@ -80,6 +80,7 @@ int AppScheduler::LoadAbility(sptr token, sptr pre loadParam.isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); loadParam.token = token; loadParam.preToken = preToken; + loadParam.instanceKey = instanceKey; int ret = static_cast(IN_PROCESS_CALL( appMgrClient_->LoadAbility(abilityInfo, applicationInfo, want, loadParam))); if (ret != ERR_OK) { 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 66f9826de4..3ee71e7a7e 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -86,9 +86,9 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp } abilityRequest.sessionInfo = sessionInfo; - TAG_LOGI(AAFwkTag::ABILITYMGR, "session:%{public}d. bundle:%{public}s, ability:%{public}s", + TAG_LOGI(AAFwkTag::ABILITYMGR, "session:%{public}d. bundle:%{public}s, ability:%{public}s, instanceKey:%{public}s", sessionInfo->persistentId, abilityRequest.abilityInfo.bundleName.c_str(), - abilityRequest.abilityInfo.name.c_str()); + abilityRequest.abilityInfo.name.c_str(), sessionInfo->instanceKey.c_str()); std::shared_ptr uiAbilityRecord = nullptr; auto iter = sessionAbilityMap_.find(sessionInfo->persistentId); if (iter != sessionAbilityMap_.end()) { @@ -359,6 +359,10 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a auto sessionInfo = CreateSessionInfo(abilityRequest); sessionInfo->requestCode = abilityRequest.requestCode; sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); + auto instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); + if (!instanceKey.empty()) { + sessionInfo->instanceKey = instanceKey; + } sessionInfo->userId = userId_; sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); TAG_LOGI( @@ -1483,10 +1487,11 @@ bool UIAbilityLifecycleManager::CheckProperties(const std::shared_ptrGetAbilityInfo(); int32_t appIndex = 0; (void)AbilityRuntime::StartupUtil::GetAppIndex(abilityRequest.want, appIndex); + auto instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); return abilityInfo.launchMode == launchMode && abilityRequest.abilityInfo.name == abilityInfo.name && abilityRequest.abilityInfo.bundleName == abilityInfo.bundleName && abilityRequest.abilityInfo.moduleName == abilityInfo.moduleName && - appIndex == abilityRecord->GetAppIndex(); + appIndex == abilityRecord->GetAppIndex() && instanceKey == abilityRecord->GetInstanceKey(); } void UIAbilityLifecycleManager::OnTimeOut(uint32_t msgId, int64_t abilityRecordId, bool isHalf) @@ -1864,6 +1869,7 @@ int UIAbilityLifecycleManager::StartAbilityBySpecifed(const AbilityRequest &abil sessionInfo->requestCode = abilityRequest.requestCode; sessionInfo->processOptions = abilityRequest.processOptions; sessionInfo->startWindowOption = abilityRequest.startWindowOption; + sessionInfo->instanceKey = abilityRequest.want.GetStringParam(Want::APP_INSTANCE_KEY); SpecifiedInfo specifiedInfo; specifiedInfo.abilityName = abilityRequest.abilityInfo.name; specifiedInfo.bundleName = abilityRequest.abilityInfo.bundleName; diff --git a/services/abilitymgr/src/utils/ability_permission_util.cpp b/services/abilitymgr/src/utils/ability_permission_util.cpp index fed58a6219..bc26449759 100644 --- a/services/abilitymgr/src/utils/ability_permission_util.cpp +++ b/services/abilitymgr/src/utils/ability_permission_util.cpp @@ -25,6 +25,8 @@ #include "ipc_skeleton.h" #include "permission_constants.h" #include "permission_verification.h" +#include "start_ability_utils.h" +#include "utils/app_mgr_util.h" using OHOS::Security::AccessToken::AccessTokenKit; @@ -103,5 +105,95 @@ bool AbilityPermissionUtil::IsDominateScreen(const Want &want, bool isPendingWan TAG_LOGD(AAFwkTag::ABILITYMGR, "not dominate screen."); return false; } + +int32_t AbilityPermissionUtil::CheckMultiInstanceAndAppClone(Want &want, int32_t userId, int32_t appIndex, + sptr callerToken) +{ + auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); + auto isCreating = want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); + AppExecFwk::ApplicationInfo appInfo; + auto isSupportMultiInstance = AppUtils::GetInstance().IsSupportMultiInstance(); + if (isSupportMultiInstance) { + if (!StartAbilityUtils::GetApplicationInfo(want.GetBundle(), userId, appInfo)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "can't get applicationInfo through bundleName"); + return RESOLVE_APP_ERR; + } + if (appInfo.multiAppMode.multiAppModeType == AppExecFwk::MultiAppModeType::UNSPECIFIED) { + if (!instanceKey.empty() || isCreating || appIndex != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support multi-instance or appClone"); + return ERR_MULTI_APP_NOT_SUPPORTED; + } + } + if (appInfo.multiAppMode.multiAppModeType == AppExecFwk::MultiAppModeType::MULTI_INSTANCE) { + if (appIndex != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support appClone"); + return ERR_NOT_SUPPORT_APP_CLONE; + } + return CheckMultiInstance(want, callerToken, isCreating, instanceKey, appInfo.multiAppMode.maxCount); + } + } + if (!isSupportMultiInstance || appInfo.multiAppMode.multiAppModeType == AppExecFwk::MultiAppModeType::APP_CLONE) { + if (!instanceKey.empty() || isCreating) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support multi-instance"); + return ERR_MULTI_INSTANCE_NOT_SUPPORTED; + } + } + return ERR_OK; +} + +int32_t AbilityPermissionUtil::CheckMultiInstance(Want &want, sptr callerToken, + bool isCreating, const std::string &instanceKey, int32_t maxCount) +{ + auto appMgr = AppMgrUtil::GetAppMgr(); + if (appMgr == nullptr) { + TAG_LOGE(AAFwkTag::FREE_INSTALL, "null appMgr"); + return ERR_INVALID_VALUE; + } + auto callerRecord = Token::GetAbilityRecordByToken(callerToken); + std::vector instanceKeyArray; + auto result = appMgr->GetAllRunningInstanceKeysByBundleName(want.GetBundle(), instanceKeyArray); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::FREE_INSTALL, "Failed to get instance key"); + return ERR_INVALID_VALUE; + } + // in-app launch + if (callerRecord != nullptr && callerRecord->GetAbilityInfo().bundleName == want.GetBundle()) { + if (isCreating) { + if (!instanceKey.empty()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not allow to set instanceKey"); + return ERR_APP_INSTANCE_KEY_NOT_SUPPORT; + } + if (static_cast(instanceKeyArray.size()) == maxCount) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "reach upper limit"); + return ERR_UPPER_LIMIT; + } + return ERR_OK; + } + return UpdateInstanceKey(want, instanceKey, instanceKeyArray, callerRecord->GetInstanceKey()); + } + // inter-app launch + if (isCreating) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "not support to create a new instance"); + return ERR_CREATE_NEW_INSTANCE_NOT_SUPPORT; + } + std::string defaultInstanceKey = "app_instance_0"; + return UpdateInstanceKey(want, instanceKey, instanceKeyArray, defaultInstanceKey); +} + +int32_t AbilityPermissionUtil::UpdateInstanceKey(Want &want, const std::string &originInstanceKey, + const std::vector &instanceKeyArray, const std::string &instanceKey) +{ + if (originInstanceKey.empty()) { + want.SetParam(Want::APP_INSTANCE_KEY, instanceKey); + return ERR_OK; + } + for (const auto& key : instanceKeyArray) { + if (key == originInstanceKey) { + return ERR_OK; + } + } + TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid instanceKey"); + return ERR_INVALID_APP_INSTANCE_KEY; +} } // AAFwk } // OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/utils/modal_system_dialog_util.cpp b/services/abilitymgr/src/utils/modal_system_dialog_util.cpp index 25e11c409c..a2ed909ac2 100644 --- a/services/abilitymgr/src/utils/modal_system_dialog_util.cpp +++ b/services/abilitymgr/src/utils/modal_system_dialog_util.cpp @@ -24,8 +24,8 @@ namespace AbilityRuntime { namespace { constexpr char DEVELOPER_MODE_STATE[] = "const.security.developermode.state"; constexpr const char* RESOURCE_ID_GENERAL_GET_IT = "general_get_it"; -constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_TITLE = "ohos_lab_developer_mode_tips"; -constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_CONTENT = "ohos_desc_developer_mode_tips"; +constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_TITLE = "lab_developer_mode_tips"; +constexpr const char* RESOURCE_ID_DEVELOPER_DIALOG_CONTENT = "desc_developer_mode_tips"; } bool ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(const AppExecFwk::ApplicationInfo &applicationInfo) diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index bf2b7554b9..7290b87bff 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -160,6 +160,17 @@ public: virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info) override; + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) override; + /** * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project. * Obtains information about application processes by bundle type that are running on the device. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 3596fc045e..b24c754bc9 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -349,6 +349,17 @@ public: virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info); + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys); + /** * GetRunningProcessesByBundleType, Obtains information about application processes by bundle type. * @@ -465,15 +476,13 @@ public: int32_t StartNativeProcessForDebugger(const AAFwk::Want &want); std::shared_ptr CreateAppRunningRecord( - sptr token, - sptr preToken, + std::shared_ptr loadParam, std::shared_ptr appInfo, std::shared_ptr abilityInfo, const std::string &processName, const BundleInfo &bundleInfo, const HapModuleInfo &hapModuleInfo, std::shared_ptr want, - int32_t abilityRecordId, bool isKia = false); /** @@ -1482,6 +1491,8 @@ private: void GetRunningCloneAppInfo(const std::shared_ptr &appRecord, RunningMultiAppInfo &info); + void GetRunningMultiInstanceKeys(const std::shared_ptr &appRecord, + std::vector &instanceKeys); /** * To Prevent process being killed when ability is starting in an existing process, * we need notify memmgr to increase process priority. @@ -1568,6 +1579,11 @@ private: bool &isWatermarkEnabled, bool &isFileUri, std::string &processName); int32_t ProcessKia(bool isKia, std::shared_ptr appRecord, const std::string& watermarkBusinessName, bool isWatermarkEnabled); + bool CheckAppRecordAndPriorityObject(const std::shared_ptr &appRecord); + void GetAppCloneInfo(const std::shared_ptr &appRecord, + RunningMultiAppInfo &info); + void GetMultiInstanceInfo(const std::shared_ptr &appRecord, + RunningMultiAppInfo &info); const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; std::vector appStateCallbacks_; std::shared_ptr remoteClientManager_; diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index f3098a70d2..a3eb1c4ed6 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -58,8 +58,8 @@ public: * * @return AppRunningRecord pointer if success get or create. */ - std::shared_ptr CreateAppRunningRecord( - const std::shared_ptr &appInfo, const std::string &processName, const BundleInfo &bundleInfo); + std::shared_ptr CreateAppRunningRecord(const std::shared_ptr &appInfo, + const std::string &processName, const BundleInfo &bundleInfo, const std::string &instanceKey); /** * CheckAppRunningRecordIsExist, Get process record by application name and process Name. @@ -72,7 +72,7 @@ public: */ std::shared_ptr CheckAppRunningRecordIsExist(const std::string &appName, const std::string &processName, const int uid, const BundleInfo &bundleInfo, - const std::string &specifiedProcessFlag = "", bool *isProCache = nullptr); + const std::string &specifiedProcessFlag = "", bool *isProCache = nullptr, const std::string &instanceKey = ""); #ifdef APP_NO_RESPONSE_DIALOG /** diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index b40fd095bd..3c8b82fef4 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -630,6 +630,8 @@ public: bool IsKilling() const; void SetAppIndex(const int32_t appIndex); int32_t GetAppIndex() const; + void SetInstanceKey(const std::string& instanceKey); + std::string GetInstanceKey() const; void SetSecurityFlag(bool securityFlag); bool GetSecurityFlag() const; @@ -989,6 +991,7 @@ private: ffrt::mutex renderPidSetLock_; AppSpawnStartMsg startMsg_; int32_t appIndex_ = 0; + std::string instanceKey_; bool securityFlag_ = false; int32_t requestProcCode_ = 0; ProcessChangeReason processChangeReason_ = ProcessChangeReason::REASON_NONE; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 400305fb0c..c012ae1a43 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -397,6 +397,16 @@ int32_t AppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bun return appMgrServiceInner_->GetRunningMultiAppInfoByBundleName(bundleName, info); } + +int32_t AppMgrService::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) +{ + if (!IsReady()) { + return ERR_INVALID_OPERATION; + } + return appMgrServiceInner_->GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys); +} + int32_t AppMgrService::GetRunningProcessesByBundleType(BundleType bundleType, std::vector &info) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 1503aeb66a..c1c14be163 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -358,8 +358,9 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap auto abilityInfoPtr = std::make_shared(abilityInfo); MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName); TAG_LOGD(AAFwkTag::APPMGR, "processName = %{public}s", processName.c_str()); - auto mainAppRecord = - appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo); + auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); + auto mainAppRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, + bundleInfo, "", nullptr, instanceKey); if (mainAppRecord != nullptr) { TAG_LOGD(AAFwkTag::APPMGR, "main process exists."); mainAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); @@ -475,8 +476,8 @@ void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request) NotifyAppRunningStatusEvent( bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } - appRecord = CreateAppRunningRecord(nullptr, nullptr, appInfo, abilityInfo, processName, bundleInfo, - hapModuleInfo, want, NO_ABILITY_RECORD_ID); + auto loadParam = std::make_shared(); + appRecord = CreateAppRunningRecord(loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, want); if (appRecord != nullptr) { appRecord->SetPreloadState(PreloadState::PRELOADING); LoadAbilityNoAppRecord(appRecord, false, appInfo, abilityInfo, processName, specifiedProcessFlag, bundleInfo, @@ -603,7 +604,7 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s std::shared_ptr appRecord; bool isProcCache = false; appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, - processName, appInfo->uid, bundleInfo, specifiedProcessFlag, &isProcCache); + processName, appInfo->uid, bundleInfo, specifiedProcessFlag, &isProcCache, loadParam->instanceKey); if (appRecord && abilityInfo->type == AppExecFwk::AbilityType::PAGE) { NotifyMemMgrPriorityChanged(appRecord); } @@ -616,8 +617,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s NotifyAppRunningStatusEvent( bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } - appRecord = CreateAppRunningRecord(loadParam->token, loadParam->preToken, appInfo, abilityInfo, - processName, bundleInfo, hapModuleInfo, want, loadParam->abilityRecordId, isKia); + appRecord = CreateAppRunningRecord(loadParam, appInfo, abilityInfo, + processName, bundleInfo, hapModuleInfo, want, isKia); LoadAbilityNoAppRecord(appRecord, loadParam->isShellCall, appInfo, abilityInfo, processName, specifiedProcessFlag, bundleInfo, hapModuleInfo, want, appExistFlag, false, loadParam->token); if (ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled) != ERR_OK) { @@ -1820,8 +1821,140 @@ int32_t AppMgrServiceInner::GetRunningMultiAppInfoByBundleName(const std::string return ERR_OK; } +int32_t AppMgrServiceInner::GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) +{ + if (bundleName.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "bundlename null"); + return AAFwk::INVALID_PARAMETERS_ERR; + } + if (remoteClientManager_ == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "remoteClientManager_ null"); + return ERR_INVALID_VALUE; + } + auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + if (bundleMgrHelper == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper null"); + return ERR_INVALID_VALUE; + } + ApplicationInfo appInfo; + auto queryRet = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(bundleName, + ApplicationFlag::GET_BASIC_APPLICATION_INFO, currentUserId_, appInfo)); + if (!queryRet) { + TAG_LOGE(AAFwkTag::APPMGR, "bundle unexist"); + return AAFwk::ERR_BUNDLE_NOT_EXIST; + } + if (appInfo.multiAppMode.multiAppModeType != MultiAppModeType::MULTI_INSTANCE) { + TAG_LOGE(AAFwkTag::APPMGR, "bundle unsupport multi-instance"); + return AAFwk::ERR_MULTI_INSTANCE_NOT_SUPPORTED; + } + if (!appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager null"); + return ERR_INVALID_VALUE; + } + auto multiAppInfoMap = appRunningManager_->GetAppRunningRecordMap(); + for (const auto &item : multiAppInfoMap) { + const std::shared_ptr &appRecord = item.second; + if (appRecord == nullptr || appRecord->GetBundleName() != bundleName) { + continue; + } + if (GetUserIdByUid(appRecord->GetUid()) != currentUserId_) { + continue; + } + GetRunningMultiInstanceKeys(appRecord, instanceKeys); + } + return ERR_OK; +} + void AppMgrServiceInner::GetRunningCloneAppInfo(const std::shared_ptr &appRecord, RunningMultiAppInfo &info) +{ + if (info.mode == static_cast(MultiAppModeType::APP_CLONE)) { + GetAppCloneInfo(appRecord, info); + return; + } + if (info.mode == static_cast(MultiAppModeType::MULTI_INSTANCE)) { + GetMultiInstanceInfo(appRecord, info); + } +} + +bool AppMgrServiceInner::CheckAppRecordAndPriorityObject(const std::shared_ptr &appRecord) +{ + if (!appRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "appRecord null"); + return false; + } + if (appRecord->GetPriorityObject() == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "priorityObject null"); + return false; + } + return true; +} + +void AppMgrServiceInner::GetAppCloneInfo(const std::shared_ptr &appRecord, + RunningMultiAppInfo &info) +{ + if (!CheckAppRecordAndPriorityObject(appRecord)) { + return; + } + auto PriorityObject = appRecord->GetPriorityObject(); + size_t index = 0; + for (; index < info.runningAppClones.size(); index++) { + if (info.runningAppClones[index].appCloneIndex == appRecord->GetAppIndex()) { + break; + } + } + auto childProcessRecordMap = appRecord->GetChildProcessRecordMap(); + if (index < info.runningAppClones.size()) { + info.runningAppClones[index].pids.emplace_back(PriorityObject->GetPid()); + for (auto it : childProcessRecordMap) { + info.runningAppClones[index].pids.emplace_back(it.first); + } + return; + } + RunningAppClone cloneInfo; + cloneInfo.appCloneIndex = appRecord->GetAppIndex(); + cloneInfo.uid = appRecord->GetUid(); + cloneInfo.pids.emplace_back(PriorityObject->GetPid()); + for (auto it : childProcessRecordMap) { + cloneInfo.pids.emplace_back(it.first); + } + info.runningAppClones.emplace_back(cloneInfo); +} + +void AppMgrServiceInner::GetMultiInstanceInfo(const std::shared_ptr &appRecord, + RunningMultiAppInfo &info) +{ + if (!CheckAppRecordAndPriorityObject(appRecord)) { + return; + } + auto PriorityObject = appRecord->GetPriorityObject(); + size_t index = 0; + for (; index < info.runningMultiIntanceInfos.size(); index++) { + if (info.runningMultiIntanceInfos[index].instanceKey == appRecord->GetInstanceKey()) { + break; + } + } + auto childProcessRecordMap = appRecord->GetChildProcessRecordMap(); + if (index < info.runningMultiIntanceInfos.size()) { + info.runningMultiIntanceInfos[index].pids.emplace_back(PriorityObject->GetPid()); + for (auto it : childProcessRecordMap) { + info.runningMultiIntanceInfos[index].pids.emplace_back(it.first); + } + return; + } + RunningMultiInstanceInfo instanceInfo; + instanceInfo.instanceKey = appRecord->GetInstanceKey(); + instanceInfo.uid = appRecord->GetUid(); + instanceInfo.pids.emplace_back(PriorityObject->GetPid()); + for (auto it : childProcessRecordMap) { + instanceInfo.pids.emplace_back(it.first); + } + info.runningMultiIntanceInfos.emplace_back(instanceInfo); +} + +void AppMgrServiceInner::GetRunningMultiInstanceKeys(const std::shared_ptr &appRecord, + std::vector &instanceKeys) { if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "appRecord null"); @@ -1832,30 +1965,13 @@ void AppMgrServiceInner::GetRunningCloneAppInfo(const std::shared_ptr(MultiAppModeType::APP_CLONE)) { - size_t index = 0; - for (; index < info.runningAppClones.size(); index++) { - if (info.runningAppClones[index].appCloneIndex == appRecord->GetAppIndex()) { - break; - } - } - auto childProcessRecordMap = appRecord->GetChildProcessRecordMap(); - if (index < info.runningAppClones.size()) { - info.runningAppClones[index].pids.emplace_back(PriorityObject->GetPid()); - for (auto it : childProcessRecordMap) { - info.runningAppClones[index].pids.emplace_back(it.first); - } - } else { - RunningAppClone cloneInfo; - cloneInfo.appCloneIndex = appRecord->GetAppIndex(); - cloneInfo.uid = appRecord->GetUid(); - cloneInfo.pids.emplace_back(PriorityObject->GetPid()); - for (auto it : childProcessRecordMap) { - cloneInfo.pids.emplace_back(it.first); - } - info.runningAppClones.emplace_back(cloneInfo); + size_t index = 0; + for (; index < instanceKeys.size(); ++index) { + if (instanceKeys[index] == appRecord->GetInstanceKey()) { + return; } } + instanceKeys.emplace_back(appRecord->GetInstanceKey()); } int32_t AppMgrServiceInner::GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) @@ -2222,10 +2338,10 @@ std::shared_ptr AppMgrServiceInner::GetAppRunningRecordByPid(c return appRunningManager_->GetAppRunningRecordByPid(pid); } -std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(sptr token, - sptr preToken, std::shared_ptr appInfo, +std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord( + std::shared_ptr loadParam, std::shared_ptr appInfo, std::shared_ptr abilityInfo, const std::string &processName, const BundleInfo &bundleInfo, - const HapModuleInfo &hapModuleInfo, std::shared_ptr want, int32_t abilityRecordId, bool isKia) + const HapModuleInfo &hapModuleInfo, std::shared_ptr want, bool isKia) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); if (want != nullptr && (want->GetBoolParam(DEBUG_APP, false) || want->GetBoolParam(NATIVE_DEBUG, false))) { @@ -2234,11 +2350,12 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(spt return nullptr; } } - if (!appRunningManager_) { - TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager null"); + if (!appRunningManager_ || loadParam == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager or loadParam null"); return nullptr; } - auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo); + auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo, + loadParam->instanceKey); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "get appRecord fail"); return nullptr; @@ -2249,7 +2366,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(spt appRecord->SetEmptyKeepAliveAppState(false); appRecord->SetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); - appRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, want, abilityRecordId); + appRecord->AddModule(appInfo, abilityInfo, loadParam->token, hapModuleInfo, want, loadParam->abilityRecordId); appRecord->SetIsKia(isKia); if (want) { appRecord->SetDebugApp(want->GetBoolParam(DEBUG_APP, false)); @@ -3761,7 +3878,7 @@ void AppMgrServiceInner::StartEmptyResidentProcess( return; } - auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, info); + auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, info, ""); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "start process [%{public}s] fail", processName.c_str()); return; @@ -4056,7 +4173,7 @@ int AppMgrServiceInner::StartEmptyProcess(const AAFwk::Want &want, const sptrCreateAppRunningRecord(appInfo, processName, info); + auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, info, ""); CHECK_POINTER_AND_RETURN_VALUE(appRecord, ERR_INVALID_VALUE); auto isDebug = want.GetBoolParam(DEBUG_APP, false); @@ -4183,7 +4300,9 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap hapModules.emplace_back(hapModuleInfo); std::shared_ptr appRecord; - appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo); + auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); + appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo, + "", nullptr, instanceKey); if (!appRecord) { bool appExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByBundleName(bundleInfo.name); bool appMultiUserExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByUid(bundleInfo.uid); @@ -4192,7 +4311,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } // new app record - appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo); + appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo, instanceKey); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "start process [%{public}s] fail", processName.c_str()); return; diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index b43c160f3e..fbd793d90c 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -64,7 +64,8 @@ void AppRunningManager::initConfig(const Configuration &config) } std::shared_ptr AppRunningManager::CreateAppRunningRecord( - const std::shared_ptr &appInfo, const std::string &processName, const BundleInfo &bundleInfo) + const std::shared_ptr &appInfo, const std::string &processName, const BundleInfo &bundleInfo, + const std::string &instanceKey) { if (!appInfo) { TAG_LOGE(AAFwkTag::APPMGR, "param error"); @@ -96,6 +97,7 @@ std::shared_ptr AppRunningManager::CreateAppRunningRecord( appRecord->SetSignCode(signCode); appRecord->SetJointUserId(bundleInfo.jointUserId); appRecord->SetAppIdentifier(bundleInfo.signatureInfo.appIdentifier); + appRecord->SetInstanceKey(instanceKey); { std::lock_guard guard(runningRecordMapMutex_); appRunningRecordMap_.emplace(recordId, appRecord); @@ -109,7 +111,7 @@ std::shared_ptr AppRunningManager::CreateAppRunningRecord( std::shared_ptr AppRunningManager::CheckAppRunningRecordIsExist(const std::string &appName, const std::string &processName, const int uid, const BundleInfo &bundleInfo, - const std::string &specifiedProcessFlag, bool *isProCache) + const std::string &specifiedProcessFlag, bool *isProCache, const std::string &instanceKey) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::APPMGR, @@ -136,7 +138,7 @@ std::shared_ptr AppRunningManager::CheckAppRunningRecordIsExis } for (const auto &item : appRunningMap) { const auto &appRecord = item.second; - if (appRecord && appRecord->GetProcessName() == processName && + if (appRecord && appRecord->GetProcessName() == processName && appRecord->GetInstanceKey() == instanceKey && (specifiedProcessFlag.empty() || appRecord->GetSpecifiedProcessFlag() == specifiedProcessFlag) && !(appRecord->IsTerminating()) && !(appRecord->IsKilling()) && !(appRecord->GetRestartAppFlag()) && !(appRecord->IsUserRequestCleaning())) { diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 53101851e5..c86a018e1b 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -484,6 +484,7 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) launchData.SetUId(mainUid_); launchData.SetUserTestInfo(userTestRecord_); launchData.SetAppIndex(appIndex_); + launchData.SetInstanceKey(instanceKey_); launchData.SetDebugApp(isDebugApp_); launchData.SetPerfCmd(perfCmd_); launchData.SetErrorInfoEnhance(isErrorInfoEnhance_); @@ -1845,6 +1846,11 @@ void AppRunningRecord::SetAppIndex(const int32_t appIndex) appIndex_ = appIndex; } +void AppRunningRecord::SetInstanceKey(const std::string& instanceKey) +{ + instanceKey_ = instanceKey; +} + void AppRunningRecord::GetSplitModeAndFloatingMode(bool &isSplitScreenMode, bool &isFloatingWindowMode) { auto abilitiesMap = GetAbilities(); @@ -1877,6 +1883,11 @@ int32_t AppRunningRecord::GetAppIndex() const return appIndex_; } +std::string AppRunningRecord::GetInstanceKey() const +{ + return instanceKey_; +} + void AppRunningRecord::SetSecurityFlag(bool securityFlag) { securityFlag_ = securityFlag; diff --git a/services/common/include/app_utils.h b/services/common/include/app_utils.h index 2180463feb..db41523c07 100644 --- a/services/common/include/app_utils.h +++ b/services/common/include/app_utils.h @@ -53,6 +53,7 @@ public: bool EnableMoveUIAbilityToBackgroundApi(); bool IsLaunchEmbededUIAbility(); bool IsSupportNativeChildProcess(); + bool IsSupportMultiInstance(); bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); bool IsAllowNativeChildProcess(const std::string &appIdentifier); int32_t GetLimitMaximumExtensionsPerProc(); @@ -84,6 +85,7 @@ private: volatile DeviceConfiguration enableMoveUIAbilityToBackgroundApi_ = {false, true}; volatile DeviceConfiguration isLaunchEmbededUIAbility_ = {false, false}; volatile DeviceConfiguration isSupportNativeChildProcess_ = {false, false}; + volatile DeviceConfiguration isSupportMultiInstance_ = {false, false}; DeviceConfiguration>> residentProcessInExtremeMemory_ = {false, {}}; DeviceConfiguration> diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index cffc03dad3..cba32192b9 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -66,6 +66,7 @@ constexpr const char* BROKER_DELEGATE_BUNDLE_NAME = "const.sys.abilityms.broker_ constexpr const char* COLLABORATOR_BROKER_UID = "const.sys.abilityms.collaborator_broker_uid"; constexpr const char* COLLABORATOR_BROKER_RESERVE_UID = "const.sys.abilityms.collaborator_broker_reserve_uid"; constexpr const char* MAX_CHILD_PROCESS = "const.max_native_child_process"; +constexpr const char* SUPPORT_MULTI_INSTANCE = "const.abilityms.support_multi_instance"; } AppUtils::~AppUtils() {} @@ -438,5 +439,15 @@ int32_t AppUtils::MaxChildProcess() TAG_LOGD(AAFwkTag::DEFAULT, "MaxChildProcess: %{public}d", maxChildProcess_.value); return maxChildProcess_.value; } + +bool AppUtils::IsSupportMultiInstance() +{ + if (!isSupportMultiInstance_.isLoaded) { + isSupportMultiInstance_.value = system::GetBoolParameter(SUPPORT_MULTI_INSTANCE, false); + isSupportMultiInstance_.isLoaded = true; + } + TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isSupportMultiInstance_.value); + return isSupportMultiInstance_.value; +} } // namespace AAFwk } // namespace OHOS diff --git a/test/fuzztest/abilityappmgrapprunningmanager_fuzzer/abilityappmgrapprunningmanager_fuzzer.cpp b/test/fuzztest/abilityappmgrapprunningmanager_fuzzer/abilityappmgrapprunningmanager_fuzzer.cpp index 11515a7628..8d995c6087 100644 --- a/test/fuzztest/abilityappmgrapprunningmanager_fuzzer/abilityappmgrapprunningmanager_fuzzer.cpp +++ b/test/fuzztest/abilityappmgrapprunningmanager_fuzzer/abilityappmgrapprunningmanager_fuzzer.cpp @@ -175,7 +175,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::shared_ptr appInfo = std::make_shared(); std::string jsonStr(data, size); BundleInfo bundleInfo; - manager->CreateAppRunningRecord(appInfo, jsonStr, bundleInfo); + manager->CreateAppRunningRecord(appInfo, jsonStr, bundleInfo, ""); int uid = static_cast(GetU32Data(data)); manager->CheckAppRunningRecordIsExist(jsonStr, jsonStr, uid, bundleInfo, jsonStr); manager->CheckAppRunningRecordIsExistByBundleName(jsonStr); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 00fe29b877..2892c30c88 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -82,6 +82,8 @@ public: MOCK_METHOD2(UpdateRenderState, int32_t(pid_t renderPid, int32_t state)); MOCK_METHOD2(GetRunningMultiAppInfoByBundleName, int32_t(const std::string &bundleName, RunningMultiAppInfo &info)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD1(SetSupportedProcessCacheSelf, int32_t(bool isSupported)); MOCK_METHOD2(SetSupportedProcessCache, int32_t(int32_t pid, bool isSupport)); MOCK_METHOD3(StartNativeChildProcess, int32_t(const std::string &libName, int32_t childProcessCount, @@ -159,6 +161,12 @@ public: return 0; } + virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, + RunningMultiAppInfo &info) override + { + return 0; + } + virtual int GetRunningProcessesByBundleType(const BundleType bundleType, std::vector& info) override { diff --git a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h index c618ba0349..9a43ca00a7 100644 --- a/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h +++ b/test/mock/mock_appmgr_service/include/mock_app_mgr_service_inner.h @@ -46,6 +46,8 @@ public: int32_t(const std::string&, const int32_t, const pid_t, int32_t appCloneIndex, int32_t userId)); MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&)); MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector&)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector&)); MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); MOCK_METHOD1(RegisterAppStateCallback, void(const sptr& callback)); diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index f674e7b202..fb684aab95 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -129,6 +129,17 @@ public: */ virtual AppMgrResultCode GetAllRunningProcesses(std::vector& info); + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual AppMgrResultCode GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys); + /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. * Obtains information about render processes that are running on the device. diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h index 66744c1e6a..237b12a33e 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_interface.h @@ -111,6 +111,17 @@ public: */ virtual int GetAllRunningProcesses(std::vector& info) = 0; + /** + * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project. + * Obtains running isntance keys of multi-instance app that are running on the device. + * + * @param bundlename, bundle name in Application record. + * @param instanceKeys, output instance keys of the multi-insatnce app. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName, + std::vector &instanceKeys) = 0; + /** * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project. * Obtains information about render processes that are running on the device. diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index ba5eb645c9..ba1befa52c 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -43,7 +43,7 @@ bool AppScheduler::Init(const std::weak_ptr& callback) int AppScheduler::LoadAbility(sptr token, sptr preToken, const AppExecFwk::AbilityInfo& abilityInfo, const AppExecFwk::ApplicationInfo& applicationInfo, - const AAFwk::Want& want, int32_t abilityRecordId) + const AAFwk::Want& want, int32_t abilityRecordId, const std::string &instanceKey) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 99ddb9e92f..7d0091839a 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -93,6 +93,8 @@ public: std::vector &info)); MOCK_METHOD2(GetRunningMultiAppInfoByBundleName, int32_t(const std::string &bundleName, RunningMultiAppInfo &info)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning)); diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h index 3c5238c848..7b54480d7e 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service_inner.h @@ -49,6 +49,8 @@ public: MOCK_METHOD3(ClearUpApplicationDataBySelf, int32_t(int32_t, pid_t, int32_t userId)); MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&)); MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector&)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys)); MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector&)); MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); MOCK_METHOD1(RegisterAppStateCallback, void(const sptr& callback)); diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index e465bb85ac..fff738637f 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -401,6 +401,28 @@ HWTEST_F(AppMgrServiceModuleTest, GetAllRunningProcesses_001, TestSize.Level1) } } +/* + * Feature: AppMgrService + * Function: GetAllRunningInstanceKeysByBundleName + * SubFunction: NA + * FunctionPoints: AppMgrService => AppMgrServiceInner: GetAllRunningInstanceKeysByBundleName + * CaseDescription: Check GetAllRunningInstanceKeysByBundleName. + */ +HWTEST_F(AppMgrServiceModuleTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Level1) +{ + EXPECT_TRUE(appMgrService_); + EXPECT_TRUE(mockAppMgrServiceInner_); + + std::string testBundleName = "testBundleName"; + std::vector testInstanceKeys; + + EXPECT_CALL(*mockAppMgrServiceInner_, GetAllRunningInstanceKeysByBundleName(_, _)) + .Times(1).WillOnce(Return(ERR_OK)); + + auto result = appMgrService_->GetAllRunningInstanceKeysByBundleName(testBundleName, testInstanceKeys); + EXPECT_EQ(result, ERR_OK); +} + /* * Feature: AppMgrService * Function: KillApplication diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn index 867abb2ffe..96a2afaf95 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/BUILD.gn @@ -41,6 +41,7 @@ ohos_moduletest("AppRunningProcessesInfoModuleTest") { deps = [ "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:res_sched_util", "${ability_runtime_test_path}/moduletest/common/ams:appmgr_mst_source", diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp b/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp index 46219400bf..74e0e075a4 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp @@ -33,6 +33,7 @@ #include "mock_app_spawn_client.h" #include "mock_native_token.h" #include "mock_sa_call.h" +#include "param.h" using namespace testing::ext; using OHOS::iface_cast; @@ -199,8 +200,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_001, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; @@ -259,8 +262,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_002, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; @@ -321,8 +326,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_003, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; @@ -362,9 +369,9 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_003, TestSize.Level BundleInfo bundleInfo2; HapModuleInfo hapModuleInfo2; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo2, appInfo2, bundleInfo2, hapModuleInfo2)); - sptr mockToken = new (std::nothrow) MockAbilityToken(); + loadParam->token = new (std::nothrow) MockAbilityToken(); auto record2 = service_->CreateAppRunningRecord( - mockToken, nullptr, appInfo2, abilityInfo2, processName2, bundleInfo2, hapModuleInfo2, nullptr, 0); + loadParam, appInfo2, abilityInfo2, processName2, bundleInfo2, hapModuleInfo2, nullptr); record2->SetUid(uid); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; @@ -401,8 +408,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_004, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; @@ -459,8 +468,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_005, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); pid_t pid = 16738; record->GetPriorityObject()->SetPid(pid); @@ -521,8 +532,10 @@ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_006, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_FALSE(service_->GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo)); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, nullptr); record->SetUid(uid); pid_t pid = 16739; record->GetPriorityObject()->SetPid(pid); diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index 586f85c4cb..f391d4ec2f 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/common:app_util", "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_services_path}/common:res_sched_util", diff --git a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp index a232bf55cf..1b5be29b4d 100644 --- a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp +++ b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp @@ -29,6 +29,7 @@ #include "mock_ability_token.h" #include "mock_app_scheduler.h" #include "mock_app_spawn_client.h" +#include "param.h" using namespace testing::ext; using testing::_; @@ -135,8 +136,10 @@ TestApplicationPreRunningRecord AmsAppServiceFlowModuleTest::TestCreateApplicati auto appRecord = serviceInner_->appRunningManager_->CheckAppRunningRecordIsExist( appInfo->name, appName, appInfo->uid, bundleInfo); if (!appRecord) { + auto loadParam = std::make_shared(); + loadParam->token = token; appRecord = serviceInner_->CreateAppRunningRecord( - token, nullptr, appInfo, abilityInfo, appName, bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, appName, bundleInfo, hapModuleInfo, nullptr); appRecord->GetPriorityObject()->SetPid(TestApplicationPreRunningRecord::g_pid++); } else { serviceInner_->StartAbility(token, nullptr, abilityInfo, appRecord, hapModuleInfo, nullptr, 0); diff --git a/test/moduletest/mock/include/mock_app_mgr_client.h b/test/moduletest/mock/include/mock_app_mgr_client.h index 6fe255ef70..519f9e9692 100644 --- a/test/moduletest/mock/include/mock_app_mgr_client.h +++ b/test/moduletest/mock/include/mock_app_mgr_client.h @@ -37,6 +37,8 @@ public: MOCK_METHOD2(GetRunningProcessInfoByToken, void((const sptr& token, AppExecFwk::RunningProcessInfo& info))); MOCK_METHOD1(GetAllRunningProcesses, AppMgrResultCode(std::vector& info)); + MOCK_METHOD2(GetAllRunningInstanceKeysByBundleName, AppMgrResultCode(const std::string &bundleName, + std::vector &instanceKeys)); AppMgrResultCode GetProcessRunningInfosByUserId(std::vector& info, int32_t userId); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 8db44f4b3e..71462806f5 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -349,6 +349,7 @@ group("unittest") { "ability_manager_service_sixth_test:unittest", "ability_manager_service_third_test:unittest", "ability_manager_stub_test:unittest", + "ability_permission_util_test:unittest", "ability_record_dump_test:unittest", "ability_record_mgr_test:unittest", "ability_record_test:unittest", diff --git a/test/unittest/ability_permission_util_test/BUILD.gn b/test/unittest/ability_permission_util_test/BUILD.gn new file mode 100644 index 0000000000..2fe8ef429c --- /dev/null +++ b/test/unittest/ability_permission_util_test/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("ability_permission_util_test") { + module_out_path = module_output_path + + sources = [ "ability_permission_util_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + deps = [ + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "jsoncpp:jsoncpp", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":ability_permission_util_test" ] +} diff --git a/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp b/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp new file mode 100644 index 0000000000..ca2d158399 --- /dev/null +++ b/test/unittest/ability_permission_util_test/ability_permission_util_test.cpp @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#include "ability_record.h" +#include "utils/ability_permission_util.h" +#undef private +#include "app_utils.h" +#include "hilog_tag_wrapper.h" +#include "parameters.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AAFwk { +class AbilityPermissionUtilTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AbilityPermissionUtilTest::SetUpTestCase(void) {} +void AbilityPermissionUtilTest::TearDownTestCase(void) {} +void AbilityPermissionUtilTest::SetUp() {} +void AbilityPermissionUtilTest::TearDown() {} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100 start"); + Want want; + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 100, 0, nullptr); + + bool isSupportMultiInstance = AppUtils::GetInstance().IsSupportMultiInstance(); + std::string deviceType = OHOS::system::GetDeviceType(); + TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str()); + if (deviceType == "2in1") { + EXPECT_EQ(result, RESOLVE_APP_ERR); + } else { + EXPECT_EQ(result, ERR_OK); + } + + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200 start"); + Want want; + std::string instanceKey = "app_instance_0"; + want.SetParam(Want::APP_INSTANCE_KEY, instanceKey); + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 100, 0, nullptr); + + bool isSupportMultiInstance = AppUtils::GetInstance().IsSupportMultiInstance(); + std::string deviceType = OHOS::system::GetDeviceType(); + TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str()); + if (deviceType == "2in1") { + EXPECT_EQ(result, RESOLVE_APP_ERR); + } else { + EXPECT_EQ(result, ERR_MULTI_INSTANCE_NOT_SUPPORTED); + } + + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300 start"); + Want want; + want.SetParam(Want::CREATE_APP_INSTANCE_KEY, true); + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 100, 0, nullptr); + + bool isSupportMultiInstance = AppUtils::GetInstance().IsSupportMultiInstance(); + std::string deviceType = OHOS::system::GetDeviceType(); + TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str()); + if (deviceType == "2in1") { + EXPECT_EQ(result, RESOLVE_APP_ERR); + } else { + EXPECT_EQ(result, ERR_MULTI_INSTANCE_NOT_SUPPORTED); + } + + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0300 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0100 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstance_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0100 start"); + + Want want; + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, nullptr, true, "", 0); + EXPECT_EQ(result, ERR_CREATE_NEW_INSTANCE_NOT_SUPPORT); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0200 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstance_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0200 start"); + + std::string bundleName = "com.ohos.test"; + Want want; + want.SetBundle(bundleName); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.bundleName = bundleName; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + auto abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + auto isInitial = abilityRecord->Init(); + EXPECT_TRUE(isInitial); + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, abilityRecord->GetToken(), true, "", 1); + EXPECT_EQ(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0300 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstance_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0300 start"); + + std::string bundleName = "com.ohos.test"; + Want want; + want.SetBundle(bundleName); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.bundleName = bundleName; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + auto abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + auto isInitial = abilityRecord->Init(); + EXPECT_TRUE(isInitial); + std::string instanceKey = "app_instance_0"; + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, abilityRecord->GetToken(), true, + instanceKey, 1); + EXPECT_EQ(result, ERR_APP_INSTANCE_KEY_NOT_SUPPORT); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0300 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0400 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_CheckMultiInstance_0400, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0400 start"); + + std::string bundleName = "com.ohos.test"; + Want want; + want.SetBundle(bundleName); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.bundleName = bundleName; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + auto abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + auto isInitial = abilityRecord->Init(); + EXPECT_TRUE(isInitial); + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, abilityRecord->GetToken(), true, "", 0); + EXPECT_EQ(result, ERR_UPPER_LIMIT); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0400 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_UpdateInstanceKey_0100 + * @tc.desc: UpdateInstanceKey + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_UpdateInstanceKey_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0100 start"); + + Want want; + std::vector instanceKeyArray; + auto result = AbilityPermissionUtil::GetInstance().UpdateInstanceKey(want, "", instanceKeyArray, ""); + EXPECT_EQ(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_UpdateInstanceKey_0200 + * @tc.desc: UpdateInstanceKey + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_UpdateInstanceKey_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0200 start"); + + Want want; + std::string originInstanceKey = "app_instance_0"; + std::vector instanceKeyArray; + auto result = AbilityPermissionUtil::GetInstance().UpdateInstanceKey(want, originInstanceKey, instanceKeyArray, ""); + EXPECT_EQ(result, ERR_INVALID_APP_INSTANCE_KEY); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_UpdateInstanceKey_0300 + * @tc.desc: UpdateInstanceKey + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilTest, AbilityPermissionUtil_UpdateInstanceKey_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0300 start"); + + Want want; + std::string originInstanceKey = "app_instance_0"; + std::vector instanceKeyArray; + instanceKeyArray.push_back(originInstanceKey); + auto result = AbilityPermissionUtil::GetInstance().UpdateInstanceKey(want, originInstanceKey, instanceKeyArray, ""); + EXPECT_EQ(result, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_UpdateInstanceKey_0300 end"); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index d5bae1e963..9eb6f5b9d2 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -3546,5 +3546,20 @@ HWTEST_F(AbilityRecordTest, AbilityRecord_GetPermissionedUriList_006, TestSize.L EXPECT_EQ(paramStramUris.size(), 1); } +/* + * Feature: AbilityRecord + * Function: GetInstanceKey + * SubFunction: GetInstanceKey + * FunctionPoints: NA + * EnvConditions: NA + * CaseDescription: Verify AbilityRecord GetInstanceKey + */ +HWTEST_F(AbilityRecordTest, AbilityRecord_GetInstanceKey_001, TestSize.Level1) +{ + std::shared_ptr abilityRecord = GetAbilityRecord(); + auto instanceKey = abilityRecord->GetInstanceKey(); + EXPECT_EQ(instanceKey, ""); +} + } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp index c8d4377271..9c2120615a 100644 --- a/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp +++ b/test/unittest/ams_app_running_record_test/ams_app_running_record_test.cpp @@ -221,8 +221,10 @@ HWTEST_F(AmsAppRunningRecordTest, CreateAppRunningRecord_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); EXPECT_EQ(record->GetName(), GetTestAppName()); @@ -256,13 +258,14 @@ HWTEST_F(AmsAppRunningRecordTest, CreateAppRunningRecord_002, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); // Create - sptr token = GetMockToken(); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); record->SetUid(1010); // Get auto record1 = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record1 != nullptr); EXPECT_EQ(record1->GetName(), GetTestAppName()); EXPECT_EQ(record1->GetProcessName(), GetTestProcessName()); @@ -291,22 +294,23 @@ HWTEST_F(AmsAppRunningRecordTest, CreateAppRunningRecord_003, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); record->SetUid(1010); auto anotherAbilityInfo = std::make_shared(); anotherAbilityInfo->name = "Another_ability"; anotherAbilityInfo->applicationInfo.uid = 1010; - sptr anotherToken = new (std::nothrow) MockAbilityToken(); - auto record1 = service_->CreateAppRunningRecord(GetMockToken(), - anotherToken, + loadParam->preToken = new (std::nothrow) MockAbilityToken(); + auto record1 = service_->CreateAppRunningRecord(loadParam, appInfo, anotherAbilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, - nullptr, 0); + nullptr); EXPECT_EQ(record1->GetName(), GetTestAppName()); EXPECT_EQ(record1->GetProcessName(), GetTestProcessName()); @@ -335,8 +339,10 @@ HWTEST_F(AmsAppRunningRecordTest, CreateAppRunningRecord_004, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); // Create + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, nullptr, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, nullptr, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record == nullptr); } @@ -359,8 +365,10 @@ HWTEST_F(AmsAppRunningRecordTest, CreateAppRunningRecord_005, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); // Create + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, nullptr, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, nullptr, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); } @@ -747,8 +755,10 @@ HWTEST_F(AmsAppRunningRecordTest, DeleteAppRunningRecord_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetState(ApplicationState::APP_STATE_BACKGROUND); record->SetApplicationClient(GetMockedAppSchedulerClient()); @@ -957,8 +967,10 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_001, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchApplication(_, _)).Times(1); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchAbility(_, _, _, _)).Times(1); @@ -998,8 +1010,10 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_002, TestSize.Level1) const int EXPECT_ABILITY_LAUNCH_TIME = 3; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); sptr token2 = new (std::nothrow) MockAbilityToken(); record->AddModule(appInfo, abilityInfo2, token2, hapModuleInfo, nullptr, 0); @@ -1046,8 +1060,10 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_003, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); record->SetState(ApplicationState::APP_STATE_READY); record->SetApplicationClient(GetMockedAppSchedulerClient()); @@ -1090,8 +1106,10 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_004, TestSize.Level1) hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchApplication(_, _)).Times(1); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchAbility(_, _, _, _)).Times(1); @@ -1100,10 +1118,8 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_004, TestSize.Level1) EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_READY); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleLaunchApplication(_, _)).Times(0); - AbilityRuntime::LoadParam loadParam; - loadParam.token = new (std::nothrow) MockAbilityToken(); - auto loadParamPtr = std::make_shared(loadParam); - service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParamPtr); + loadParam->token = new (std::nothrow) MockAbilityToken(); + service_->LoadAbility(abilityInfo2, appInfo, nullptr, loadParam); TAG_LOGI(AAFwkTag::TEST, "AmsAppRunningRecordTest LaunchAbilityForApp_004 end"); } @@ -1137,8 +1153,10 @@ HWTEST_F(AmsAppRunningRecordTest, LaunchAbilityForApp_005, TestSize.Level1) const int EXPECT_ABILITY_LAUNCH_TIME = 2; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); sptr token2 = new (std::nothrow) MockAbilityToken(); record->AddModule(appInfo, abilityInfo2, token2, hapModuleInfo, nullptr, 0); @@ -1204,8 +1222,10 @@ HWTEST_F(AmsAppRunningRecordTest, TerminateAbility_002, TestSize.Level1) appInfo->name = GetTestAppName(); appInfo->bundleName = GetTestAppName(); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_CALL(*mockAppSchedulerClient_, ScheduleCleanAbility(_, _)).Times(0); record->TerminateAbility(GetMockToken(), false); @@ -1272,8 +1292,10 @@ HWTEST_F(AmsAppRunningRecordTest, SetUid_GetUid_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetUid(102); @@ -1307,8 +1329,10 @@ HWTEST_F(AmsAppRunningRecordTest, OnAbilityStateChanged_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); auto moduleRecord = record->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); EXPECT_TRUE(moduleRecord != nullptr); auto abilityRecord = record->GetAbilityRunningRecordByToken(GetMockToken()); @@ -1361,8 +1385,10 @@ HWTEST_F(AmsAppRunningRecordTest, AddModule_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo0, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo0, nullptr, 0); + loadParam, appInfo0, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo0, nullptr); EXPECT_TRUE(record != nullptr); auto moduleRecordList = record->GetAllModuleRecord(); EXPECT_TRUE(moduleRecordList.size() == 1); @@ -1412,8 +1438,10 @@ HWTEST_F(AmsAppRunningRecordTest, AddModule_002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); @@ -1456,7 +1484,7 @@ HWTEST_F(AmsAppRunningRecordTest, GetModuleRecordByModuleName_001, TestSize.Leve HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); - auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo); + auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo, ""); EXPECT_TRUE(record != nullptr); EXPECT_TRUE(record->hapModules_.size() == 0); auto moduleRecord = record->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); @@ -1506,8 +1534,10 @@ HWTEST_F(AmsAppRunningRecordTest, GetAbilities_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); @@ -1542,8 +1572,10 @@ HWTEST_F(AmsAppRunningRecordTest, GetAbilities_002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); @@ -1581,8 +1613,10 @@ HWTEST_F(AmsAppRunningRecordTest, RemoveModuleRecord_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); @@ -1786,8 +1820,10 @@ HWTEST_F(AmsAppRunningRecordTest, StartSpecifiedAbility_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); EXPECT_EQ(record->GetName(), GetTestAppName()); @@ -1818,8 +1854,10 @@ HWTEST_F(AmsAppRunningRecordTest, StartSpecifiedAbility_002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); EXPECT_EQ(record->GetName(), GetTestAppName()); @@ -1857,8 +1895,10 @@ HWTEST_F(AmsAppRunningRecordTest, Specified_LaunchApplication_001, TestSize.Leve hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); record->SetApplicationClient(GetMockedAppSchedulerClient()); record->specifiedRequestId_ = 1; @@ -2258,8 +2298,10 @@ HWTEST_F(AmsAppRunningRecordTest, GetAbilityRunningRecord_002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); std::shared_ptr record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); sptr token = new (std::nothrow) MockAbilityToken(); record->AddModule(appInfo, abilityInfo, token, hapModuleInfo, nullptr, 0); @@ -2302,8 +2344,10 @@ HWTEST_F(AmsAppRunningRecordTest, AddAbilityStage_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->AddAbilityStage(); @@ -2350,8 +2394,10 @@ HWTEST_F(AmsAppRunningRecordTest, AddAbilityStageBySpecifiedAbility_001, TestSiz HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->AddAbilityStageBySpecifiedAbility(bundleName1); @@ -2404,8 +2450,10 @@ HWTEST_F(AmsAppRunningRecordTest, AddAbilityStageDone_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->AddAbilityStageDone(); @@ -2454,7 +2502,7 @@ HWTEST_F(AmsAppRunningRecordTest, GetModuleRunningRecordByToken_001, TestSize.Le hapModuleInfo.moduleName = "module789"; sptr token = new (std::nothrow) MockAbilityToken(); EXPECT_TRUE(service_ != nullptr); - auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo); + auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo, ""); EXPECT_TRUE(record != nullptr); EXPECT_TRUE(record->hapModules_.size() == 0); @@ -2510,7 +2558,7 @@ HWTEST_F(AmsAppRunningRecordTest, GetModuleRunningRecordByTerminateLists_001, Te sptr token = new (std::nothrow) MockAbilityToken(); sptr token1 = new (std::nothrow) MockAbilityToken(); EXPECT_TRUE(service_ != nullptr); - auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo); + auto record = service_->appRunningManager_->CreateAppRunningRecord(appInfo, GetTestProcessName(), bundleInfo, ""); EXPECT_TRUE(record != nullptr); EXPECT_TRUE(record->hapModules_.size() == 0); @@ -2559,8 +2607,10 @@ HWTEST_F(AmsAppRunningRecordTest, UpdateAbilityFocusState_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); auto abilityRecord = record->GetAbilityRunningRecordByToken(GetMockToken()); @@ -2763,8 +2813,10 @@ HWTEST_F(AmsAppRunningRecordTest, IsUIExtension_001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); EXPECT_EQ(AAFwk::UIExtensionUtils::IsUIExtension(record->extensionType_), false); @@ -2799,8 +2851,10 @@ HWTEST_F(AmsAppRunningRecordTest, IsUIExtension_002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); EXPECT_EQ(AAFwk::UIExtensionUtils::IsUIExtension(record->extensionType_), true); diff --git a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp index 36d869a5c5..b18c7b33ce 100644 --- a/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp +++ b/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp @@ -1215,8 +1215,10 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess001, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = token; std::shared_ptr record = service_->CreateAppRunningRecord( - token, nullptr, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr); service_->StartProcess(abilityInfo->applicationName, GetTestAppName(), @@ -1265,8 +1267,10 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess002, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = token; std::shared_ptr record = service_->CreateAppRunningRecord( - token, nullptr, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr); service_->SetAppSpawnClient(nullptr); service_->StartProcess(abilityInfo->applicationName, @@ -1310,8 +1314,10 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess003, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = token; std::shared_ptr record = service_->CreateAppRunningRecord( - token, nullptr, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr); service_->StartProcess(abilityInfo->applicationName, GetTestAppName(), @@ -1361,8 +1367,10 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess004, TestSize.Level1) HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; + auto loadParam = std::make_shared(); + loadParam->token = token; std::shared_ptr record = service_->CreateAppRunningRecord( - token, nullptr, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestAppName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_NE(record, nullptr); CHECK_POINTER_IS_NULLPTR(record); diff --git a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp index b9b06a54dc..62e8318141 100644 --- a/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp +++ b/test/unittest/app_mgr_service_inner_second_test/app_mgr_service_inner_second_test.cpp @@ -28,6 +28,7 @@ #include "mock_native_token.h" #include "mock_permission_verification.h" #include "mock_sa_call.h" +#include "param.h" using namespace testing; using namespace testing::ext; @@ -185,8 +186,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_LoadAbilityN HapModuleInfo hapModuleInfo; hapModuleInfo.isStageBasedModel = true; hapModuleInfo.process = "testMainProcess"; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); ASSERT_NE(appRecord, nullptr); appRecord->SetEmptyKeepAliveAppState(true); appRecord->SetMainProcess(true); @@ -212,8 +216,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_LoadAbilityN HapModuleInfo hapModuleInfo; hapModuleInfo.isStageBasedModel = true; hapModuleInfo.process = TEST_PROCESS_NAME; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); ASSERT_NE(appRecord, nullptr); appRecord->SetEmptyKeepAliveAppState(true); @@ -250,8 +257,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_ForceKillApp auto appMgrServiceInner = std::make_shared(); const BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->GetPriorityObject()->SetPid(1); // kill Init process auto ret = appMgrServiceInner->ForceKillApplicationInner(TEST_BUNDLE_NAME, DEFAULT_INVAL_VALUE, appIndex); EXPECT_EQ(ret, ERR_OK); @@ -270,8 +280,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_ForceKillApp auto appMgrServiceInner = std::make_shared(); const BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->GetPriorityObject()->SetPid(INT_MAX); // kill not exist pid, expect ERR_KILL_PROCESS_NOT_EXIST @@ -326,8 +339,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_KillProcesse HapModuleInfo hapModuleInfo; const int32_t accessTokenId = 123; // 123 means tokenid applicationInfo_->accessTokenId = accessTokenId; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->SetSpawned(); appRecord->GetPriorityObject()->SetPid(INT_MAX); auto ret = appMgrServiceInner->KillProcessesByAccessTokenId(accessTokenId); @@ -351,8 +367,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_KillProcesse HapModuleInfo hapModuleInfo; const int32_t accessTokenId = 123; applicationInfo_->accessTokenId = accessTokenId; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->SetSpawned(); appRecord->GetPriorityObject()->SetPid(1); auto ret = appMgrServiceInner->KillProcessesByAccessTokenId(accessTokenId); @@ -405,8 +424,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_GetAllChildr auto appMgrServiceInner = std::make_shared(); BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); ChildProcessRequest request; auto record1 = std::make_shared(IPCSkeleton::GetCallingPid(), request, appRecord); appRecord->AddChildProcessRecord(1, record1); @@ -432,8 +454,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_GetAllChildr HapModuleInfo hapModuleInfo; const int32_t accessTokenId = 123; // 123 means tokenid applicationInfo_->accessTokenId = accessTokenId; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); ChildProcessRequest request; auto record1 = std::make_shared(IPCSkeleton::GetCallingPid(), request, appRecord); appRecord->AddChildProcessRecord(1, record1); @@ -507,8 +532,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyAppFau auto appMgrServiceInner = std::make_shared(); BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->GetPriorityObject()->SetPid(1); appRecord->SetState(ApplicationState::APP_STATE_TERMINATED); @@ -544,8 +572,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_BuildEventIn BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); AAFwk::EventInfo eventInfo {.bundleName = applicationInfo_->name, .versionName = applicationInfo_->versionName, @@ -575,8 +606,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_UpdateRender BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; - auto appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + auto appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); appRecord->GetPriorityObject()->SetPid(1); ret = appMgrServiceInner->UpdateRenderState(INT_MAX, 0); EXPECT_EQ(ret, ERR_INVALID_VALUE); @@ -609,8 +643,11 @@ HWTEST_F(AppMgrServiceInnerSecondTest, AppMgrServiceInnerSecondTest_NotifyMemMgr BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; std::shared_ptr appRecord = nullptr; - appRecord = appMgrServiceInner->CreateAppRunningRecord(token_, preToken_, applicationInfo_, abilityInfo_, - TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, 1, false); + auto loadParam = std::make_shared(); + loadParam->token = token_; + loadParam->preToken = preToken_; + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, applicationInfo_, abilityInfo_, + TEST_PROCESS_NAME, bundleInfo, hapModuleInfo, want_, false); ret = appMgrServiceInner->NotifyMemMgrPriorityChanged(appRecord); EXPECT_FALSE(ret); // stub err diff --git a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp index a11d27426f..921c72a8ab 100644 --- a/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp +++ b/test/unittest/app_mgr_service_inner_tdd_test/app_mgr_service_inner_tdd_test.cpp @@ -129,7 +129,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_002, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); EXPECT_TRUE(appMgrServiceInner->SendProcessStartEvent(appRecord)); TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_002 end"); @@ -151,7 +151,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_003, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -179,7 +179,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_004, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -210,7 +210,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_005, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -242,7 +242,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_006, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -275,7 +275,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_007, TestSize.Level1) std::string processName = "test_processName"; sptr token = sptr(new (std::nothrow) MockAbilityToken()); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -319,7 +319,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_008, TestSize.Level1) sptr token = sptr(new (std::nothrow) MockAbilityToken()); applicationInfo_->bundleName = ""; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -378,7 +378,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartFailedEvent_002, TestSize.Level BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_TRUE( appMgrServiceInner->SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::APPSPAWN_FAILED, 0)); TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_002 end"); @@ -401,7 +401,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartFailedEvent_003, TestSize.Level sptr token = sptr(new (std::nothrow) MockAbilityToken()); applicationInfo_->bundleName = "testBundleName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr appInfo = std::make_shared(); std::shared_ptr moduleRunningRecord = std::make_shared(appInfo, nullptr); @@ -530,7 +530,7 @@ HWTEST_F(AppMgrServiceInnerTest, StartRenderProcessImpl_001, TestSize.Level0) std::string bundleName = "test_bundleName"; sptr token = new MockAbilityToken(); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); pid_t hostPid = 1; std::string renderParam = "test_render_param"; diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 1ffbc840c1..831a8f7d1b 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -583,7 +583,7 @@ HWTEST_F(AppMgrServiceInnerTest, LaunchApplication_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; appMgrServiceInner->LaunchApplication(appRecord); @@ -637,7 +637,7 @@ HWTEST_F(AppMgrServiceInnerTest, AddAbilityStageDone_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; appMgrServiceInner->AddAbilityStageDone(recordId_); @@ -660,7 +660,7 @@ HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; appMgrServiceInner->ApplicationForegrounded(recordId_); @@ -681,7 +681,8 @@ HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_002, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; appMgrServiceInner->ApplicationForegrounded(recordId_); @@ -702,9 +703,11 @@ HWTEST_F(AppMgrServiceInnerTest, ApplicationForegrounded_003, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; - auto record2 = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record2 = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; std::shared_ptr priorityObject = std::make_shared(); std::string callerBundleName = "callerBundleName"; @@ -735,7 +738,7 @@ HWTEST_F(AppMgrServiceInnerTest, ApplicationBackgrounded_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; auto appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); EXPECT_NE(appRecord, nullptr); recordId_ += 1; @@ -764,7 +767,7 @@ HWTEST_F(AppMgrServiceInnerTest, ApplicationTerminated_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; auto appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); EXPECT_NE(appRecord, nullptr); recordId_ += 1; @@ -1146,7 +1149,6 @@ HWTEST_F(AppMgrServiceInnerTest, ProcessExist_001, TestSize.Level0) HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0) { TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 start"); - OHOS::sptr token = sptr(new (std::nothrow) MockAbilityToken()); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); @@ -1155,63 +1157,65 @@ HWTEST_F(AppMgrServiceInnerTest, CreateAppRunningRecord_001, TestSize.Level0) std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(nullptr, nullptr, - nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0); + auto loadParam = std::make_shared(); + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr); EXPECT_EQ(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0); + loadParam->token = sptr(new (std::nothrow) MockAbilityToken()); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + nullptr, nullptr, "", bundleInfo, hapModuleInfo, nullptr); EXPECT_EQ(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr, 0); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, nullptr, "", bundleInfo, hapModuleInfo, nullptr); EXPECT_EQ(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr, 0); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, "", bundleInfo, hapModuleInfo, nullptr); EXPECT_EQ(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); EXPECT_NE(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); EXPECT_NE(appRecord, nullptr); - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr, 0); + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, nullptr); EXPECT_NE(appRecord, nullptr); - std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + nullptr, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_EQ(appRecord1, nullptr); - std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord2, nullptr); want = std::make_shared(); const std::string COLD_START = "coldStart"; want->SetParam(COLD_START, true); - std::shared_ptr appRecord3 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord3 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord3, nullptr); want->SetParam(COLD_START, false); - std::shared_ptr appRecord4 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord4 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord4, nullptr); appMgrServiceInner->appRunningManager_ = nullptr; - std::shared_ptr appRecord5 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord5 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_EQ(appRecord5, nullptr); appMgrServiceInner->appRunningManager_ = nullptr; want->SetParam("multiThread", false); - std::shared_ptr appRecord6 = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + std::shared_ptr appRecord6 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_EQ(appRecord6, nullptr); TAG_LOGI(AAFwkTag::TEST, "CreateAppRunningRecord_001 end"); @@ -1263,14 +1267,17 @@ HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0) HapModuleInfo hapModuleInfo; std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, nullptr, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->UpdateAbilityState(token, AbilityState::ABILITY_STATE_CREATE); OHOS::sptr token1 = sptr(new (std::nothrow) MockAbilityToken()); - std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(token1, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + loadParam->token = token1; + std::shared_ptr appRecord1 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord1, nullptr); appMgrServiceInner->UpdateAbilityState(token1, AbilityState::ABILITY_STATE_READY); @@ -1295,8 +1302,9 @@ HWTEST_F(AppMgrServiceInnerTest, UpdateAbilityState_001, TestSize.Level0) OHOS::sptr token2 = sptr(new (std::nothrow) MockAbilityToken()); abilityInfo_->type = AbilityType::SERVICE; - std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(token2, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + loadParam->token = token2; + std::shared_ptr appRecord2 = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord2, nullptr); appMgrServiceInner->UpdateAbilityState(token2, AbilityState::ABILITY_STATE_CREATE); @@ -1341,8 +1349,10 @@ HWTEST_F(AppMgrServiceInnerTest, UpdateExtensionState_001, TestSize.Level0) HapModuleInfo hapModuleInfo; std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->UpdateExtensionState(token, ExtensionState::EXTENSION_STATE_CREATE); @@ -1502,8 +1512,10 @@ HWTEST_F(AppMgrServiceInnerTest, KillProcessByAbilityToken_001, TestSize.Level0) HapModuleInfo hapModuleInfo; std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->KillProcessByAbilityToken(token); @@ -1561,8 +1573,10 @@ HWTEST_F(AppMgrServiceInnerTest, StartAbility_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; - appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->StartAbility(token, nullptr, abilityInfo_, appRecord, hapModuleInfo, want, 0); appMgrServiceInner->StartAbility(token, preToken, abilityInfo_, appRecord, hapModuleInfo, want, 0); @@ -1616,8 +1630,10 @@ HWTEST_F(AppMgrServiceInnerTest, AbilityTerminated_001, TestSize.Level0) HapModuleInfo hapModuleInfo; std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->AbilityTerminated(token); @@ -1662,7 +1678,7 @@ HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false); @@ -1729,7 +1745,7 @@ HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0) std::string bundleName = "test_bundleName"; sptr token = new MockAbilityToken(); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleInfo, bundleName, 0); appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0); @@ -1784,7 +1800,7 @@ HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_002, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); appMgrServiceInner->ClearAppRunningData(appRecord, true); TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_002 end"); } @@ -1802,7 +1818,7 @@ HWTEST_F(AppMgrServiceInnerTest, ClearAppRunningData_003, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); appMgrServiceInner->ClearAppRunningData(appRecord, false); TAG_LOGI(AAFwkTag::TEST, "ClearAppRunningData_003 end"); } @@ -1903,7 +1919,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleTerminateApplicationTimeOut_001, TestSize std::string bundleName = "test_bundleName"; sptr token = new MockAbilityToken(); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->eventId_ = 0; appMgrServiceInner->HandleTerminateApplicationTimeOut(0); @@ -1941,7 +1957,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleAddAbilityStageTimeOut_001, TestSize.Leve std::string bundleName = "test_bundleName"; sptr token = new MockAbilityToken(); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->eventId_ = 0; appMgrServiceInner->HandleAddAbilityStageTimeOut(0); @@ -2168,7 +2184,7 @@ HWTEST_F(AppMgrServiceInnerTest, RestartResidentProcess_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->mainBundleName_ = "com.ohos.settings"; appMgrServiceInner->RestartResidentProcess(appRecord); @@ -2415,10 +2431,11 @@ HWTEST_F(AppMgrServiceInnerTest, FinishUserTest_001, TestSize.Level0) BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; std::shared_ptr want; - sptr token = new MockAbilityToken(); std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = new MockAbilityToken(); + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); pid = appRecord->GetPriorityObject()->GetPid(); appMgrServiceInner->FinishUserTest(msg, 0, bundleName, pid); @@ -2457,7 +2474,7 @@ HWTEST_F(AppMgrServiceInnerTest, FinishUserTestLocked_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); std::shared_ptr record = std::make_shared(); appRecord->SetUserTestInfo(record); @@ -2543,7 +2560,7 @@ HWTEST_F(AppMgrServiceInnerTest, ScheduleAcceptWantDone_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); appMgrServiceInner->ScheduleAcceptWantDone(appRecord->GetRecordId(), want, flag); sptr response; @@ -2573,7 +2590,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleStartSpecifiedAbilityTimeOut_001, TestSiz std::string bundleName = "test_bundleName"; sptr token = new MockAbilityToken(); std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->eventId_ = 0; appMgrServiceInner->HandleStartSpecifiedAbilityTimeOut(0); @@ -2719,7 +2736,7 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationByRecord_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord1 = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord1, nullptr); appMgrServiceInner->KillApplicationByRecord(appRecord); appMgrServiceInner->KillApplicationByRecord(appRecord1); @@ -2748,7 +2765,7 @@ HWTEST_F(AppMgrServiceInnerTest, SendHiSysEvent_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->eventId_ = 0; appMgrServiceInner->SendHiSysEvent(0, 0); @@ -2781,7 +2798,7 @@ HWTEST_F(AppMgrServiceInnerTest, GetAbilityRecordsByProcessID_001, TestSize.Leve BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); int pid = appRecord->GetPriorityObject()->GetPid(); appMgrServiceInner->GetAbilityRecordsByProcessID(pid, tokens); @@ -2808,7 +2825,7 @@ HWTEST_F(AppMgrServiceInnerTest, GetApplicationInfoByProcessID_001, TestSize.Lev BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); int pid = appRecord->GetPriorityObject()->GetPid(); appMgrServiceInner->GetApplicationInfoByProcessID(pid, application, debug); @@ -3122,7 +3139,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleFocused_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->GetPriorityObject()->SetPid(pid); appMgrServiceInner->HandleFocused(focusChangeInfo); @@ -3155,7 +3172,7 @@ HWTEST_F(AppMgrServiceInnerTest, HandleUnfocused_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->GetPriorityObject()->SetPid(pid); appMgrServiceInner->HandleUnfocused(focusChangeInfo); @@ -3247,7 +3264,7 @@ HWTEST_F(AppMgrServiceInnerTest, SetContinuousTaskProcess_001, TestSize.Level0) BundleInfo bundleInfo; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->GetPriorityObject()->SetPid(0); ret = appMgrServiceInner->SetContinuousTaskProcess(0, true); @@ -3383,7 +3400,7 @@ HWTEST_F(AppMgrServiceInnerTest, GetBundleNameByPid_002, TestSize.Level1) EXPECT_NE(appMgrServiceInner, nullptr); BundleInfo info; std::string processName = "test_processName"; - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); int32_t pid = 0; std::string name = "test_name"; int32_t uid = 0; @@ -3729,7 +3746,8 @@ HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_002, TestSize.Level1) AAFwk::EventInfo eventInfo; BundleInfo info; std::string processName = "test_processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; int64_t restartTime = std::chrono::duration_cast(std::chrono:: system_clock::now().time_since_epoch()).count(); @@ -3754,7 +3772,8 @@ HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_003, TestSize.Level1) eventInfo.callerBundleName = "callerBundleName"; BundleInfo info; std::string processName = "test_processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; int64_t restartTime = std::chrono::duration_cast(std::chrono:: system_clock::now().time_since_epoch()).count(); @@ -3780,7 +3799,8 @@ HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_004, TestSize.Level1) eventInfo.bundleName = "bundleName"; eventInfo.callerBundleName = "bundleName"; eventInfo.callerProcessName = processName; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; int64_t restartTime = std::chrono::duration_cast(std::chrono:: system_clock::now().time_since_epoch()).count(); @@ -3806,7 +3826,8 @@ HWTEST_F(AppMgrServiceInnerTest, SendReStartProcessEvent_005, TestSize.Level1) eventInfo.bundleName = "bundleName"; eventInfo.callerBundleName = "bundleName"; eventInfo.callerProcessName = "processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; int64_t restartTime = std::chrono::duration_cast(std::chrono:: system_clock::now().time_since_epoch()).count(); @@ -3832,10 +3853,10 @@ HWTEST_F(AppMgrServiceInnerTest, SendAppLaunchEvent_001, TestSize.Level0) BundleInfo info; std::string processName = "test_processName"; std::shared_ptr appRecord = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; std::shared_ptr appRecord2 = - appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); recordId_ += 1; appRecord->SetState(ApplicationState::APP_STATE_CREATE); appRecord->SetKeepAliveEnableState(false); @@ -4389,8 +4410,10 @@ HWTEST_F(AppMgrServiceInnerTest, AttachedToStatusBar_001, TestSize.Level1) HapModuleInfo hapModuleInfo; std::shared_ptr want; std::string processName = "test_processName"; - std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(token, nullptr, - applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want, 0); + auto loadParam = std::make_shared(); + loadParam->token = token; + std::shared_ptr appRecord = appMgrServiceInner->CreateAppRunningRecord(loadParam, + applicationInfo_, abilityInfo_, processName, bundleInfo, hapModuleInfo, want); EXPECT_NE(appRecord, nullptr); appMgrServiceInner->AttachedToStatusBar(token); } @@ -4407,7 +4430,8 @@ HWTEST_F(AppMgrServiceInnerTest, BlockProcessCacheByPids_001, TestSize.Level1) BundleInfo info; std::string processName = "test_processName"; - auto record = appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info); + auto record = + appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, info, ""); std::shared_ptr priorityObject = std::make_shared(); EXPECT_NE(priorityObject, nullptr); std::string callerBundleName = "callerBundleName"; diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index 04390a8e5b..aed54699b7 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -1736,7 +1736,7 @@ HWTEST_F(AppMgrServiceTest, SetSupportedProcessCacheSelf_002, TestSize.Level0) applicationInfo_->name = "hiservcie"; applicationInfo_->bundleName = "com.ix.hiservcie"; std::shared_ptr appRecord = - appRunningMgr->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo); + appRunningMgr->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo, ""); EXPECT_NE(appRecord, nullptr); appRecord->SetCallerTokenId(IPCSkeleton::GetCallingTokenID()); appRecord->SetCallerUid(IPCSkeleton::GetCallingUid()); diff --git a/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp b/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp index 14ad526ad4..deee8b998e 100644 --- a/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp +++ b/test/unittest/app_running_manager_second_test/app_running_manager_second_test.cpp @@ -108,7 +108,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_CheckAppRunningRecordIsE auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_CheckAppRunningRecordIsExistByUid_0100 start 2"); /** * @tc.steps: step2. SetUid USR_ID_100, SetRestartAppFlag false @@ -164,7 +164,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_CheckAppCloneRunningReco appInfo_->bundleName = BUNDLE_NAME; const std::string processName = "testProcessName"; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); ASSERT_NE(record, nullptr); /** @@ -234,7 +234,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_ProcessExitByBundleName_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); std::shared_ptr record1 = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); ASSERT_NE(record1, nullptr); record1->appInfos_.emplace(BUNDLE_NAME, appInfo_); @@ -280,7 +280,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_ProcessExitByBundleName_ EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record1 = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); ASSERT_NE(record1, nullptr); record1->appInfos_.emplace(BUNDLE_NAME, appInfo_); @@ -325,7 +325,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_GetPidsByBundleNameUserI appInfo_->appIndex = 0; appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record1 = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); ASSERT_NE(record1, nullptr); record1->appInfos_.emplace(BUNDLE_NAME, appInfo_); @@ -394,7 +394,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_OnRemoteDied_0100, TestS EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); ASSERT_NE(record, nullptr); std::shared_ptr appServiceInner = std::make_shared(); sptr mockApp1 = sptr::MakeSptr(); @@ -435,11 +435,11 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyMemoryLevel_0100, EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto recordId = AppRecordId::Create(); appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr); std::shared_ptr record2 = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record2->priorityObject_ = nullptr; auto ret = appRunningManager->NotifyMemoryLevel(1); @@ -460,11 +460,11 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyProcMemoryLevel_01 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto recordId = AppRecordId::Create(); appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr); std::shared_ptr record2 = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record2->priorityObject_ = nullptr; std::map procLevelMap; auto ret = appRunningManager->NotifyProcMemoryLevel(procLevelMap); @@ -487,9 +487,9 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_DumpHeapMemory_0100, Tes auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); - auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record2->priorityObject_ = nullptr; OHOS::AppExecFwk::MallocInfo mallocInfo; auto ret = appRunningManager->DumpHeapMemory(1, mallocInfo); @@ -512,8 +512,8 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_GetAppRunningRecordByRen auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); - auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); + auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto renderRecord = std::make_shared(0, "", -1, -1, -1, record2); record2->AddRenderRecord(renderRecord); auto ret = appRunningManager->GetAppRunningRecordByRenderPid(1); @@ -535,7 +535,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_01 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto ret = appRunningManager->NotifyLoadRepairPatch(BUNDLE_NAME, nullptr); /** @@ -560,7 +560,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_02 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); sptr mockApp1 = sptr::MakeSptr(); record1->SetApplicationClient(mockApp1); EXPECT_CALL(*mockApp1, ScheduleNotifyLoadRepairPatch(_, _, _)).Times(1).WillOnce(Return(ERR_OK)); @@ -591,7 +591,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_03 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto recordId = AppRecordId::Create(); appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr); @@ -617,7 +617,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0100 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto ret = appRunningManager->NotifyHotReloadPage(BUNDLE_NAME, nullptr); /** @@ -642,7 +642,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0200 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); sptr mockApp1 = sptr::MakeSptr(); record1->SetApplicationClient(mockApp1); EXPECT_CALL(*mockApp1, ScheduleNotifyHotReloadPage(_, _)).Times(1).WillOnce(Return(ERR_OK)); @@ -674,7 +674,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0300 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto recordId = AppRecordId::Create(); appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr); @@ -702,7 +702,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto ret = appRunningManager->NotifyUnLoadRepairPatch(BUNDLE_NAME, nullptr); /** @@ -728,7 +728,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); sptr mockApp1 = sptr::MakeSptr(); record1->SetApplicationClient(mockApp1); EXPECT_CALL(*mockApp1, ScheduleNotifyUnLoadRepairPatch(_, _, _)).Times(1).WillOnce(Return(ERR_OK)); @@ -760,7 +760,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto recordId = AppRecordId::Create(); appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr); @@ -923,7 +923,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step1. Initialize AppRunningManager instance @@ -953,7 +953,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI; /** @@ -983,7 +983,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI; /** @@ -1013,7 +1013,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE; record->SetAppIndex(0); @@ -1045,7 +1045,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE; record->SetAppIndex(1); record->SetState(ApplicationState::APP_STATE_FOREGROUND); @@ -1078,7 +1078,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForegr EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE; record->SetAppIndex(1); record->SetState(ApplicationState::APP_STATE_BACKGROUND); @@ -1163,7 +1163,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI; /** @@ -1191,7 +1191,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::WINDOW; /** @@ -1220,7 +1220,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_ EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE; record->SetState(ApplicationState::APP_STATE_FOREGROUND); @@ -1249,7 +1249,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_ auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE; record->SetAppIndex(1); record->SetState(ApplicationState::APP_STATE_BACKGROUND); @@ -1309,7 +1309,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocuse EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance @@ -1338,7 +1338,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocuse EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance @@ -1365,7 +1365,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocuse auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto abilityInfo = std::make_shared(); auto ability = std::make_shared(abilityInfo, nullptr, 0); record->AbilityFocused(ability); @@ -1397,7 +1397,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocuse auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto abilityInfo = std::make_shared(); auto ability = std::make_shared(abilityInfo, nullptr, 0); record->AbilityFocused(ability); @@ -1456,7 +1456,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0 EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance @@ -1483,7 +1483,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0 EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance @@ -1509,7 +1509,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0 auto appRunningManager = std::make_shared(); EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; - auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); auto abilityInfo = std::make_shared(); auto ability = std::make_shared(abilityInfo, nullptr, 0); record->AbilityFocused(ability); @@ -1566,7 +1566,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0200, EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance @@ -1593,7 +1593,7 @@ HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0300, EXPECT_NE(appRunningManager, nullptr); appInfo_->bundleName = BUNDLE_NAME; std::shared_ptr record = - appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo); + appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, ""); /** * @tc.steps: step2. Initialize AppRunningManager instance diff --git a/test/unittest/app_running_manager_test/app_running_manager_test.cpp b/test/unittest/app_running_manager_test/app_running_manager_test.cpp index ffef504734..0e9bfd816d 100644 --- a/test/unittest/app_running_manager_test/app_running_manager_test.cpp +++ b/test/unittest/app_running_manager_test/app_running_manager_test.cpp @@ -326,7 +326,7 @@ HWTEST_F(AppRunningManagerTest, RemoveAppRunningRecordById_0100, TestSize.Level1 std::shared_ptr appInfo = std::make_shared(); std::string processName = "test.ProcessName"; BundleInfo bundleInfo; - auto appRecord = appRunningManager->CreateAppRunningRecord(appInfo, processName, bundleInfo); + auto appRecord = appRunningManager->CreateAppRunningRecord(appInfo, processName, bundleInfo, ""); ASSERT_NE(appRecord, nullptr); int32_t uiExtensionAbilityId = 1000; @@ -351,7 +351,7 @@ HWTEST_F(AppRunningManagerTest, AppRunningRecord_0100, TestSize.Level1) std::shared_ptr appInfo = std::make_shared(); static std::string processName = "test.ProcessName"; BundleInfo bundleInfo; - auto appRecord = appRunningManager_Record0100->CreateAppRunningRecord(appInfo, processName, bundleInfo); + auto appRecord = appRunningManager_Record0100->CreateAppRunningRecord(appInfo, processName, bundleInfo, ""); ASSERT_NE(appRecord, nullptr); processName += "a"; diff --git a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp index 557cfee7f9..057c77835b 100644 --- a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp +++ b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp @@ -218,8 +218,10 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_001, TestSize.Level HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetState(ApplicationState::APP_STATE_FOREGROUND); record->SetApplicationClient(GetMockedAppSchedulerClient()); @@ -249,8 +251,10 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_002, TestSize.Level BundleInfo bundleInfo; HapModuleInfo hapModuleInfo; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetUid(uid); @@ -309,8 +313,10 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_004, TestSize.Level HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetState(ApplicationState::APP_STATE_BACKGROUND); record->SetApplicationClient(GetMockedAppSchedulerClient()); @@ -339,8 +345,10 @@ HWTEST_F(AppRunningProcessesInfoTest, UpdateAppRunningRecord_005, TestSize.Level HapModuleInfo hapModuleInfo; hapModuleInfo.moduleName = "module789"; EXPECT_TRUE(service_ != nullptr); + auto loadParam = std::make_shared(); + loadParam->token = GetMockToken(); auto record = service_->CreateAppRunningRecord( - GetMockToken(), nullptr, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr, 0); + loadParam, appInfo, abilityInfo, GetTestProcessName(), bundleInfo, hapModuleInfo, nullptr); EXPECT_TRUE(record != nullptr); record->SetState(ApplicationState::APP_STATE_BACKGROUND); record->SetApplicationClient(GetMockedAppSchedulerClient()); diff --git a/test/unittest/app_scheduler_test/app_scheduler_test.cpp b/test/unittest/app_scheduler_test/app_scheduler_test.cpp index ff91b9e776..a296c273ce 100644 --- a/test/unittest/app_scheduler_test/app_scheduler_test.cpp +++ b/test/unittest/app_scheduler_test/app_scheduler_test.cpp @@ -231,7 +231,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1) DelayedSingleton::GetInstance()->appMgrClient_ = nullptr; EXPECT_NE((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), record->GetWant(), 0)); + token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), record->GetWant(), 0, "")); } /* @@ -253,7 +253,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_LoadAbility_001, TestSize.Level1) Want want; DelayedSingleton::GetInstance()->appMgrClient_ = std::move(clientMock_); int res = DelayedSingleton::GetInstance()->LoadAbility( - token, preToken, abilityInfo, applicationInfo, want, 0); + token, preToken, abilityInfo, applicationInfo, want, 0, ""); EXPECT_EQ(res, INNER_ERR); } diff --git a/test/unittest/app_utils_test/app_utils_test.cpp b/test/unittest/app_utils_test/app_utils_test.cpp index 57e2c12603..3c235b9081 100644 --- a/test/unittest/app_utils_test/app_utils_test.cpp +++ b/test/unittest/app_utils_test/app_utils_test.cpp @@ -311,5 +311,25 @@ HWTEST_F(AppUtilsTest, AppUtilsTest_1400, TestSize.Level0) auto allow = AAFwk::AppUtils::GetInstance().IsAllowNativeChildProcess("com.test.demo"); EXPECT_FALSE(allow); } + +/** + * @tc.number: AppUtilsTest_1500 + * @tc.desc: Test IsSupportMultiInstance works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, AppUtilsTest_1500, TestSize.Level0) +{ + TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1500 called."); + bool isSupportMultiInstance = AAFwk::AppUtils::GetInstance().IsSupportMultiInstance(); + std::string deviceType = OHOS::system::GetDeviceType(); + TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str()); + if (deviceType == "default") { + EXPECT_TRUE(isSupportMultiInstance == false); + } else if (deviceType == "phone") { + EXPECT_TRUE(isSupportMultiInstance == false); + } else if (deviceType == "2in1") { + EXPECT_TRUE(isSupportMultiInstance == true); + } +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/utils/server/startup/include/param.h b/utils/server/startup/include/param.h index 81bd0b30d6..fd096cf47a 100644 --- a/utils/server/startup/include/param.h +++ b/utils/server/startup/include/param.h @@ -38,10 +38,11 @@ struct LoadParam : public Parcelable { static LoadParam *Unmarshalling(Parcel &parcel); bool ReadFromParcel(Parcel &parcel); - int32_t abilityRecordId = 0; + int32_t abilityRecordId = -1; bool isShellCall = false; sptr token = nullptr; sptr preToken = nullptr; + std::string instanceKey = ""; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/utils/server/startup/src/param.cpp b/utils/server/startup/src/param.cpp index 4d62ceec15..5905392a58 100644 --- a/utils/server/startup/src/param.cpp +++ b/utils/server/startup/src/param.cpp @@ -24,6 +24,9 @@ bool LoadParam::Marshalling(Parcel &parcel) const if (!parcel.WriteBool(isShellCall)) { return false; } + if (!parcel.WriteString(instanceKey)) { + return false; + } if (token == nullptr) { if (!parcel.WriteBool(false)) { return false; @@ -55,6 +58,7 @@ bool LoadParam::ReadFromParcel(Parcel &parcel) { abilityRecordId = parcel.ReadInt32(); isShellCall = parcel.ReadBool(); + instanceKey = parcel.ReadString(); if (parcel.ReadBool()) { token = (static_cast(&parcel))->ReadRemoteObject(); if (token == nullptr) {