diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index da37cc67cf..7fc16f1dfa 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -18,6 +18,7 @@ #include #include +#include "ability_manager_client.h" #include "ability_manager_interface.h" #include "ability_runtime_error_util.h" #include "app_mgr_interface.h" @@ -189,6 +190,11 @@ public: return true; } + static napi_value PreloadApplication(napi_env env, napi_callback_info info) + { + GET_CB_INFO_AND_CALL(env, info, JsAppManager, OnPreloadApplication); + } + private: sptr appManager_ = nullptr; sptr abilityManager_ = nullptr; @@ -990,6 +996,48 @@ private: return result; } + napi_value OnPreloadApplication(napi_env env, size_t argc, napi_value *argv) + { + TAG_LOGD(AAFwkTag::APPMGR, "OnPreloadApplication called."); + if (argc < ARGC_THREE) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Invalid param count."); + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + PreloadApplicationParam param; + std::string errorMsg; + if (!ConvertPreloadApplicationParam(env, argc, argv, param, errorMsg)) { + ThrowInvalidParamError(env, errorMsg); + return CreateJsUndefined(env); + } + + wptr weak = appManager_; + auto innerErrorCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = + [param, innerErrorCode, weak]() { + sptr appMgr = weak.promote(); + if (appMgr == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication appMgr is nullptr."); + *innerErrorCode = static_cast(AbilityErrorCode::ERROR_CODE_INNER); + return; + } + *innerErrorCode = appMgr->PreloadApplication(param.bundleName, param.userId, param.preloadMode, + param.appIndex); + }; + NapiAsyncTask::CompleteCallback complete = + [innerErrorCode](napi_env env, NapiAsyncTask &task, int32_t status) { + if (*innerErrorCode == ERR_OK) { + task.ResolveWithNoError(env, CreateJsUndefined(env)); + } else { + task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode)); + } + }; + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JSAppManager::OnPreloadApplication", + env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result)); + return result; + } + bool CheckOnOffType(napi_env env, size_t argc, napi_value* argv) { if (argc < ARGC_ONE) { @@ -1056,6 +1104,7 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj) napi_set_named_property(env, exportObj, "ApplicationState", ApplicationStateInit(env)); napi_set_named_property(env, exportObj, "ProcessState", ProcessStateInit(env)); + napi_set_named_property(env, exportObj, "PreloadMode", PreloadModeInit(env)); const char *moduleName = "AppManager"; BindNativeFunction(env, exportObj, "on", moduleName, JsAppManager::On); @@ -1088,6 +1137,8 @@ napi_value JsAppManagerInit(napi_env env, napi_value exportObj) JsAppManager::GetRunningProcessInfoByBundleName); BindNativeFunction(env, exportObj, "isApplicationRunning", moduleName, JsAppManager::IsApplicationRunning); + BindNativeFunction(env, exportObj, "preloadApplication", moduleName, + JsAppManager::PreloadApplication); TAG_LOGD(AAFwkTag::APPMGR, "end"); return CreateJsUndefined(env); } 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 dca4f99aad..6e6b063284 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 @@ -25,6 +25,12 @@ namespace OHOS { namespace AbilityRuntime { +namespace { + constexpr const int32_t ARG_INDEX_0 = 0; + constexpr const int32_t ARG_INDEX_1 = 1; + constexpr const int32_t ARG_INDEX_2 = 2; + constexpr const int32_t ARG_INDEX_3 = 3; +} napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData) { TAG_LOGD(AAFwkTag::APPMGR, "called."); @@ -201,6 +207,49 @@ napi_value ProcessStateInit(napi_env env) return object; } +napi_value PreloadModeInit(napi_env env) +{ + TAG_LOGD(AAFwkTag::APPMGR, "PreloadModeInit enter."); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadModeInit, env is nullptr."); + return nullptr; + } + napi_value objValue = nullptr; + napi_create_object(env, &objValue); + + napi_set_named_property(env, objValue, "PRESS_DOWN", + CreateJsValue(env, static_cast(AppExecFwk::PreloadMode::PRESS_DOWN))); + + return objValue; +} + +bool ConvertPreloadApplicationParam(napi_env env, size_t argc, napi_value *argv, PreloadApplicationParam ¶m, + std::string &errorMsg) +{ + if (!ConvertFromJsValue(env, argv[ARG_INDEX_0], param.bundleName)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param bundleName failed."); + errorMsg = "Param bundleName must be a valid string."; + return false; + } + if (!ConvertFromJsValue(env, argv[ARG_INDEX_1], param.userId)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param userId failed."); + errorMsg = "Param userId must be a valid number."; + return false; + } + if (!ConvertFromJsValue(env, argv[ARG_INDEX_2], param.preloadMode) + || param.preloadMode != AppExecFwk::PreloadMode::PRESS_DOWN) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param preloadMode failed."); + errorMsg = "Unsupported preloadMode, must be PreloadMode.PRESS_DOWN."; + return false; + } + if (argc > ARG_INDEX_3 && !ConvertFromJsValue(env, argv[ARG_INDEX_3], param.appIndex)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication get param appIndex failed."); + errorMsg = "Param appIndex must be a valid number."; + return false; + } + return true; +} + JsAppProcessState ConvertToJsAppProcessState( const AppExecFwk::AppProcessState &appProcessState, const bool &isFocused) { 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 e175ae9524..4bb29199cc 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 @@ -39,6 +39,13 @@ enum JsAppProcessState { STATE_BACKGROUND, STATE_DESTROY }; +struct PreloadApplicationParam { + std::string bundleName; + int32_t userId; + AppExecFwk::PreloadMode preloadMode; + int32_t appIndex; +}; + napi_value CreateJsAppStateData(napi_env env, const AppStateData &appStateData); napi_value CreateJsAbilityStateData(napi_env env, const AbilityStateData &abilityStateData); #ifdef SUPPORT_GRAPHICS @@ -51,6 +58,9 @@ napi_value CreateJsRunningProcessInfoArray(napi_env env, const std::vector ERR_CODE_MAP = { { AbilityErrorCode::ERROR_ABILITY_ALREADY_RUNNING, ERROR_MSG_ABILITY_ALREADY_RUNNING }, { AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_CROSS_APP_START, ERROR_MSG_NOT_SUPPORT_CROSS_APP_START }, { AbilityErrorCode::ERROR_CODE_CANNOT_MATCH_ANY_COMPONENT, ERROR_MSG_CANNOT_MATCH_ANY_COMPONENT }, + { AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST }, }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -176,7 +178,8 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ERR_WUKONG_MODE_CANT_MOVE_STATE, AbilityErrorCode::ERROR_CODE_WUKONG_MODE_CANT_MOVE_STATE}, {ERR_OPERATION_NOT_SUPPORTED_ON_CURRENT_DEVICE, AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED}, {ERR_IMPLICIT_START_ABILITY_FAIL, AbilityErrorCode::ERROR_CODE_CANNOT_MATCH_ANY_COMPONENT}, - {ERR_START_OTHER_APP_FAILED, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_CROSS_APP_START} + {ERR_START_OTHER_APP_FAILED, AbilityErrorCode::ERROR_CODE_NOT_SUPPORT_CROSS_APP_START}, + {ERR_TARGET_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_TARGET_BUNDLE_NOT_EXIST}, }; } diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index 85d38670ee..3f8e7b1902 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -505,6 +505,22 @@ void JsUIAbility::OnSceneRestored() jsWindowStageObj_ = std::shared_ptr(jsAppWindowStage.release()); } +void JsUIAbility::OnSceneWillDestroy() +{ + TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str()); + HandleScope handleScope(jsRuntime_); + if (jsWindowStageObj_ == nullptr) { + TAG_LOGE(AAFwkTag::UIABILITY, "jsWindowStageObj_ is nullptr."); + return; + } + napi_value argv[] = {jsWindowStageObj_->GetNapiValue()}; + { + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "onWindowStageWillDestroy"); + std::string methodName = "onWindowStageWillDestroy"; + CallObjectMethod("onWindowStageWillDestroy", argv, ArraySize(argv)); + } +} + void JsUIAbility::onSceneDestroyed() { TAG_LOGD(AAFwkTag::UIABILITY, "Begin ability is %{public}s.", GetAbilityName().c_str()); diff --git a/frameworks/native/ability/native/ui_ability.cpp b/frameworks/native/ability/native/ui_ability.cpp index d07da04e5f..295c4ea36b 100644 --- a/frameworks/native/ability/native/ui_ability.cpp +++ b/frameworks/native/ability/native/ui_ability.cpp @@ -195,6 +195,7 @@ void UIAbility::OnStop() } // Call JS Func(onWindowStageDestroy) and Release the scene. if (scene_ != nullptr) { + OnSceneWillDestroy(); scene_->GoDestroy(); onSceneDestroyed(); } @@ -578,6 +579,11 @@ void UIAbility::OnSceneRestored() TAG_LOGD(AAFwkTag::UIABILITY, "Called."); } +void UIAbility::OnSceneWillDestroy() +{ + TAG_LOGD(AAFwkTag::UIABILITY, "Called."); +} + void UIAbility::onSceneDestroyed() { TAG_LOGD(AAFwkTag::UIABILITY, "Called."); diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 0ab4c6494d..8a6f331bb4 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1218,7 +1218,7 @@ bool GetBundleForLaunchApplication(std::shared_ptr bundleMgrHel void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, const Configuration &config) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::APPKIT, "called"); + TAG_LOGI(AAFwkTag::APPKIT, "HandleLaunchApplication called."); if (!CheckForHandleLaunchApplication(appLaunchData)) { TAG_LOGE(AAFwkTag::APPKIT, "CheckForHandleLaunchApplication failed."); return; 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 0f388c600b..d84f45668f 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -462,14 +462,29 @@ enum { * Native error(2097240) for memory size state unchanged. */ ERR_NATIVE_MEMORY_SIZE_STATE_UNCHANGED, + + /** + * Native error(2097241) for target bundle not exist. + */ + ERR_TARGET_BUNDLE_NOT_EXIST, /** - * Result(2097241) for get active extension list empty when record exit reason. + * Native error(2097242) for get launch ability info failed. + */ + ERR_GET_LAUNCH_ABILITY_INFO_FAILED, + + /** + * Native error(2097243) for check preload conditions failed. + */ + ERR_CHECK_PRELOAD_CONDITIONS_FAILED, + + /** + * Result(2097244) for get active extension list empty when record exit reason. */ ERR_GET_ACTIVE_EXTENSION_LIST_EMPTY, /** - * Result(2097242) for get ExtensionName by uid fail. + * Result(2097245) for get ExtensionName by uid fail. */ GET_EXTENSION_NAME_BY_UID_FAIL, }; 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 2e15f1066f..0be013e7d7 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 @@ -721,6 +721,18 @@ public: */ bool IsMemorySizeSufficent() const; + /** + * Preload application. + * + * @param bundleName The bundle name of the application to preload. + * @param userId Indicates the user identification. + * @param preloadMode Preload application mode. + * @param appIndex The index of application clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex = 0); + private: void SetServiceManager(std::unique_ptr serviceMgr); /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h index 6201b65dba..1f1bd0732a 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h @@ -85,6 +85,17 @@ enum class AppStartType { HOT, MULTI_INSTANCE, }; + +enum class PreloadMode { + PRESS_DOWN = 0, + PRE_MAKE = 1, +}; + +enum class PreloadState { + NONE = 0, + PRELOADING = 1, + PRELOADED = 2, +}; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_APP_MGR_CONSTANTS_H 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 9a203ca106..3b6fe16d0d 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 @@ -57,6 +57,21 @@ public: */ virtual void AttachApplication(const sptr &app) = 0; + /** + * Preload application. + * + * @param bundleName The bundle name of the application to preload. + * @param userId Indicates the user identification. + * @param preloadMode Preload application mode. + * @param appIndex The index of application clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex = 0) + { + return 0; + } + /** * ApplicationForegrounded, call ApplicationForegrounded() through proxy object, * set the application to Foreground State. 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 e2476c4b90..9b6a7841a1 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 @@ -96,6 +96,7 @@ enum class AppMgrInterfaceCode { GET_ALL_UI_EXTENSION_PROVIDER_PID = 70, UPDATE_CONFIGURATION_BY_BUNDLE_NAME = 71, NOTIFY_MEMORY_SIZE_STATE_CHANGED = 72, + PRELOAD_APPLICATION = 73, }; } // 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 dca1dde623..859cb88b29 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 @@ -40,6 +40,18 @@ public: */ virtual void AttachApplication(const sptr &obj) override; + /** + * Preload application. + * + * @param bundleName The bundle name of the application to preload. + * @param userId Indicates the user identification. + * @param preloadMode Preload application mode. + * @param appIndex The index of application clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex = 0) override; + /** * ApplicationForegrounded, call ApplicationForegrounded() through proxy object, * set the application to Foreground State. 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 461a84a890..8310f72032 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 @@ -57,6 +57,7 @@ public: private: int32_t HandleAttachApplication(MessageParcel &data, MessageParcel &reply); + int32_t HandlePreloadApplication(MessageParcel &data, MessageParcel &reply); int32_t HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply); int32_t HandleApplicationBackgrounded(MessageParcel &data, MessageParcel &reply); int32_t HandleApplicationTerminated(MessageParcel &data, MessageParcel &reply); 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 594efabe49..b5b63d9f56 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 @@ -1145,5 +1145,15 @@ bool AppMgrClient::IsMemorySizeSufficent() const } return amsService->IsMemorySizeSufficent(); } + +int32_t AppMgrClient::PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + return service->PreloadApplication(bundleName, userId, preloadMode, appIndex); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 52ae756230..5330568163 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 @@ -24,6 +24,16 @@ namespace OHOS { namespace AppExecFwk { +namespace { +#define PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(messageParcel, type, value) \ + do { \ + if (!(messageParcel).Write##type(value)) { \ + TAG_LOGE(AAFwkTag::APPMGR, \ + "failed to write %{public}s", #value); \ + return IPC_PROXY_ERR; \ + } \ + } while (0) +} constexpr int32_t CYCLE_LIMIT = 1000; AppMgrProxy::AppMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} @@ -55,6 +65,31 @@ void AppMgrProxy::AttachApplication(const sptr &obj) } } +int32_t AppMgrProxy::PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex) +{ + TAG_LOGD(AAFwkTag::APPMGR, "PreloadApplication called."); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Write interface token failed."); + return IPC_PROXY_ERR; + } + PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(bundleName)); + PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId); + PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, static_cast(preloadMode)); + PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, appIndex); + + int32_t error = SendRequest(AppMgrInterfaceCode::PRELOAD_APPLICATION, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Send request error: %{public}d.", error); + return error; + } + return reply.ReadInt32(); +} + void AppMgrProxy::ApplicationForegrounded(const int32_t recordId) { MessageParcel data; 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 8217b4b2cf..bec453714d 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 @@ -39,6 +39,8 @@ AppMgrStub::AppMgrStub() { memberFuncMap_[static_cast(AppMgrInterfaceCode::APP_ATTACH_APPLICATION)] = &AppMgrStub::HandleAttachApplication; + memberFuncMap_[static_cast(AppMgrInterfaceCode::PRELOAD_APPLICATION)] = + &AppMgrStub::HandlePreloadApplication; memberFuncMap_[static_cast(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED)] = &AppMgrStub::HandleApplicationForegrounded; memberFuncMap_[static_cast(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED)] = @@ -221,6 +223,22 @@ int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel & return NO_ERROR; } +int32_t AppMgrStub::HandlePreloadApplication(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + TAG_LOGD(AAFwkTag::APPMGR, "Stub HandlePreloadApplication called."); + std::string bundleName = Str16ToStr8(data.ReadString16()); + int32_t userId = data.ReadInt32(); + int32_t preloadMode = data.ReadInt32(); + int32_t appIndex = data.ReadInt32(); + auto result = PreloadApplication(bundleName, userId, static_cast(preloadMode), appIndex); + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::APPMGR, "Stub HandlePreloadApplication Write result failed."); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); 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 838b26629f..be7bcc4e07 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 @@ -155,6 +155,9 @@ enum class AbilityErrorCode { // observer not found. ERROR_CODE_OBSERVER_NOT_FOUND = 16300004, + + // target bundle not exist. + ERROR_CODE_TARGET_BUNDLE_NOT_EXIST = 16300005, }; std::string GetErrorMsg(const AbilityErrorCode& errCode); diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h b/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h index 1ca1430340..ac09ab6eaf 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ui_ability.h @@ -176,6 +176,12 @@ public: */ void OnSceneCreated() override; + /** + * @brief Called after ability stoped. + * You can override this function to implement your own processing logic. + */ + void OnSceneWillDestroy() override; + /** * @brief Called after ability stoped. * You can override this function to implement your own processing logic. diff --git a/interfaces/kits/native/ability/native/ui_ability.h b/interfaces/kits/native/ability/native/ui_ability.h index f4a12951cb..8e5184641f 100644 --- a/interfaces/kits/native/ability/native/ui_ability.h +++ b/interfaces/kits/native/ability/native/ui_ability.h @@ -365,6 +365,12 @@ public: */ virtual void OnSceneCreated(); + /** + * @brief Called after ability stoped. + * You can override this function to implement your own processing logic. + */ + virtual void OnSceneWillDestroy(); + /** * @brief Called after ability stoped. * You can override this function to implement your own processing logic. diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 847b2494cd..e84b8253a6 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("libappms") { "src/app_mgr_service.cpp", "src/app_mgr_service_event_handler.cpp", "src/app_mgr_service_inner.cpp", + "src/app_preloader.cpp", "src/app_process_manager.cpp", "src/app_running_manager.cpp", "src/app_running_record.cpp", diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 3f795e5328..36e2176a8f 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -70,6 +70,18 @@ public: */ virtual void AttachApplication(const sptr &app) override; + /** + * Preload application. + * + * @param bundleName The bundle name of the application to preload. + * @param userId Indicates the user identification. + * @param preloadMode Preload application mode. + * @param appIndex The index of application clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex) override; + // notify the ams update the state of an app, when it entered foreground. /** diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 10c034c144..ec0eb4e930 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -33,6 +33,7 @@ #include "app_foreground_state_observer_interface.h" #include "app_malloc_info.h" #include "app_mgr_constants.h" +#include "app_preloader.h" #include "app_process_manager.h" #include "app_record_id.h" #include "app_running_manager.h" @@ -185,6 +186,18 @@ public: */ virtual void AttachApplication(const pid_t pid, const sptr &appScheduler); + /** + * Preload application. + * + * @param bundleName The bundle name of the application to preload. + * @param userId Indicates the user identification. + * @param preloadMode Preload application mode. + * @param appIndex The index of application clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex); + /** * ApplicationForegrounded, set the application to Foreground State. * @@ -1087,7 +1100,8 @@ private: */ void StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags, std::shared_ptr appRecord, const int uid, const BundleInfo &bundleInfo, - const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag = true); + const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag = true, + bool isPreload = false); /** * PushAppFront, Adjust the latest application record to the top level. @@ -1330,6 +1344,22 @@ private: */ bool NotifyMemMgrPriorityChanged(const std::shared_ptr appRecord); + void HandlePreloadApplication(const PreloadRequest &request); + + std::string GetSpecifiedProcessFlag(std::shared_ptr abilityInfo, std::shared_ptr want); + + void LoadAbilityNoAppRecord(const std::shared_ptr appRecord, + sptr preToken, + std::shared_ptr appInfo, + std::shared_ptr abilityInfo, + const std::string &processName, + const std::string &specifiedProcessFlag, + const BundleInfo &bundleInfo, + const HapModuleInfo &hapModuleInfo, + std::shared_ptr want, + bool appExistFlag, + bool isPreload); + private: /** * Notify application status. @@ -1392,6 +1422,7 @@ private: std::vector serviceExtensionWhiteList_; std::shared_ptr securityModeManager_; std::shared_ptr dfxTaskHandler_; + std::shared_ptr appPreloader_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/include/app_preloader.h b/services/appmgr/include/app_preloader.h new file mode 100644 index 0000000000..841e09216d --- /dev/null +++ b/services/appmgr/include/app_preloader.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_APP_PRELOADER_H +#define OHOS_ABILITY_RUNTIME_APP_PRELOADER_H + +#include + +#include "ability_info.h" +#include "remote_client_manager.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +struct PreloadRequest { + std::shared_ptr abilityInfo = nullptr; + std::shared_ptr appInfo = nullptr; + std::shared_ptr want = nullptr; + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + int32_t appIndex = 0; // not used +}; + +class AppPreloader { +public: + AppPreloader(std::shared_ptr remoteClientManager); + ~AppPreloader() = default; + + int32_t GeneratePreloadRequest(const std::string &bundleName, int32_t userId, int32_t appIndex, + PreloadRequest &request); + +private: + bool GetLaunchWant(const std::string &bundleName, int32_t userId, AAFwk::Want &want); + + bool GetLaunchAbilityInfo(const AAFwk::Want &want, int32_t userId, AbilityInfo &abilityInfo); + + bool GetBundleAndHapInfo(const std::string &bundleName, int32_t userId, + const AbilityInfo &abilityInfo, BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo); + + bool CheckPreloadConditions(const AbilityInfo &abilityInfo); + + std::shared_ptr GetBundleManagerHelper(); + + std::shared_ptr remoteClientManager_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_APP_PRELOADER_H diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index bfbc80d133..4102bd9f8b 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -712,6 +712,12 @@ public: std::shared_ptr GetChildProcessRecordByPid(const pid_t pid); std::map> GetChildProcessRecordMap(); + void SetPreloadState(PreloadState state); + + bool IsPreloading() const; + + bool IsPreloaded() const; + /** * @brief Obtains the app record assign tokenId. * @@ -862,6 +868,7 @@ private: int64_t startTimeMillis_ = 0; // The time of app start(CLOCK_MONOTONIC) int64_t restartTimeMillis_ = 0; // The time of last trying app restart bool jitEnabled_ = false; + PreloadState preloadState_ = PreloadState::NONE; std::shared_ptr userTestRecord_ = nullptr; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 59fe6e61fa..d04fb65563 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -206,6 +206,17 @@ void AppMgrService::AttachApplication(const sptr &app) }); } +int32_t AppMgrService::PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex) +{ + TAG_LOGD(AAFwkTag::APPMGR, "PreloadApplication called"); + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication failed, appMgr not ready."); + return ERR_INVALID_OPERATION; + } + return appMgrServiceInner_->PreloadApplication(bundleName, userId, preloadMode, appIndex); +} + void AppMgrService::ApplicationForegrounded(const int32_t recordId) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 097c093ab0..164ef93ad5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -178,6 +178,7 @@ const std::string SYSTEM_CORE = "system_core"; const std::string ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId"; const std::string PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; const std::string KILL_PROCESS_REASON_PREFIX = "Kill Reason:"; +const std::string PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask"; constexpr int32_t ROOT_UID = 0; constexpr int32_t FOUNDATION_UID = 5523; @@ -191,6 +192,7 @@ constexpr int32_t NETSYS_SOCKET_GROUPID = 1097; #endif constexpr int32_t DEFAULT_INVAL_VALUE = -1; +constexpr int32_t NO_ABILITY_RECORD_ID = -1; int32_t GetUserIdByUid(int32_t uid) { @@ -237,7 +239,8 @@ AppMgrServiceInner::AppMgrServiceInner() configuration_(std::make_shared()), appDebugManager_(std::make_shared()), appRunningStatusModule_(std::make_shared()), - securityModeManager_(std::make_shared()) + securityModeManager_(std::make_shared()), + appPreloader_(std::make_shared(remoteClientManager_)) {} void AppMgrServiceInner::Init() @@ -297,6 +300,93 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap } } +int32_t AppMgrServiceInner::PreloadApplication(const std::string &bundleName, int32_t userId, + AppExecFwk::PreloadMode preloadMode, int32_t appIndex) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGI(AAFwkTag::APPMGR, + "PreloadApplication, bundleName:%{public}s, userId:%{public}d, preloadMode:%{public}d, appIndex:%{public}d", + bundleName.c_str(), userId, preloadMode, appIndex); + + CHECK_CALLER_IS_SYSTEM_APP; + auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyPreloadApplicationPermission(); + if (!isPerm) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication %{public}s: Permission verification failed", __func__); + return ERR_PERMISSION_DENIED; + } + if (!appPreloader_) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication appPreloader is nullptr."); + return ERR_INVALID_VALUE; + } + + // todo RSS preCheck + PreloadRequest request; + auto ret = appPreloader_->GeneratePreloadRequest(bundleName, userId, appIndex, request); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GeneratePreloadRequest failed."); + return ret; + } + + auto task = [inner = shared_from_this(), request] () { + if (!inner) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication appMgrServiceInner is nullptr."); + return; + } + inner->HandlePreloadApplication(request); + }; + if (!taskHandler_) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication taskHandler_ is nullptr."); + return ERR_INVALID_VALUE; + } + TAG_LOGI(AAFwkTag::APPMGR, "PreloadApplication Submit task, bundleName:%{public}s, userId:%{public}d.", + bundleName.c_str(), userId); + taskHandler_->SubmitTask(task, PRELOAD_APPLIATION_TASK); + return ERR_OK; +} + +void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + auto abilityInfo = request.abilityInfo; + if (!abilityInfo) { + TAG_LOGE(AAFwkTag::APPMGR, "HandlePreloadApplication request.abilityInfo is nullptr."); + return; + } + auto bundleInfo = request.bundleInfo; + TAG_LOGI(AAFwkTag::APPMGR, "HandlePreloadApplication, bundleName:%{public}s, abilityName:%{public}s, \ + appIndex:%{public}d", bundleInfo.name.c_str(), abilityInfo->name.c_str(), request.appIndex); + + auto appInfo = request.appInfo; + auto hapModuleInfo = request.hapModuleInfo; + std::string processName; + MakeProcessName(abilityInfo, appInfo, hapModuleInfo, request.appIndex, processName); + TAG_LOGD(AAFwkTag::APPMGR, "HandlePreloadApplication processName = %{public}s", processName.c_str()); + + auto want = request.want; + std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want); + std::shared_ptr appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, + processName, appInfo->uid, bundleInfo, specifiedProcessFlag); + if (appRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "HandlePreloadApplication AppRecord already exists, no need to preload."); + return; + } + + if (!appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "HandlePreloadApplication failed, appRunningManager_ is nullptr"); + return; + } + bool appExistFlag = appRunningManager_->CheckAppRunningRecordIsExistByBundleName(bundleInfo.name); + if (!appExistFlag) { + NotifyAppRunningStatusEvent( + bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); + } + appRecord = CreateAppRunningRecord(nullptr, nullptr, appInfo, abilityInfo, processName, bundleInfo, + hapModuleInfo, want, NO_ABILITY_RECORD_ID); + appRecord->SetPreloadState(PreloadState::PRELOADING); + LoadAbilityNoAppRecord(appRecord, nullptr, appInfo, abilityInfo, processName, specifiedProcessFlag, bundleInfo, + hapModuleInfo, want, appExistFlag, true); +} + void AppMgrServiceInner::LoadAbility(sptr token, sptr preToken, std::shared_ptr abilityInfo, std::shared_ptr appInfo, std::shared_ptr want, int32_t abilityRecordId) @@ -333,14 +423,8 @@ void AppMgrServiceInner::LoadAbility(sptr token, sptr appRecord; // for isolation process - std::string specifiedProcessFlag = ""; + std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want); bool isUIAbility = (abilityInfo->type == AppExecFwk::AbilityType::PAGE && abilityInfo->isStageBasedModel); - bool isSpecifiedProcess = abilityInfo->isolationProcess && - AAFwk::AppUtils::GetInstance().IsStartSpecifiedProcess() && isUIAbility; - if (isSpecifiedProcess) { - specifiedProcessFlag = want->GetStringParam(PARAM_SPECIFIED_PROCESS_FLAG); - TAG_LOGI(AAFwkTag::APPMGR, "specifiedProcessFlag = %{public}s", specifiedProcessFlag.c_str()); - } appRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, bundleInfo, specifiedProcessFlag); if (appRecord && isUIAbility) { @@ -356,32 +440,8 @@ void AppMgrServiceInner::LoadAbility(sptr token, sptrSetSpecifiedProcessFlag(specifiedProcessFlag); - } - if (hapModuleInfo.isStageBasedModel && !IsMainProcess(appInfo, hapModuleInfo)) { - appRecord->SetKeepAliveAppState(false, false); - TAG_LOGI(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); - } - OnAppStateChanged(appRecord, ApplicationState::APP_STATE_SET_COLD_START, false, false); - SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::COLD); - auto callRecord = GetAppRunningRecordByAbilityToken(preToken); - if (callRecord != nullptr) { - auto launchReson = (want == nullptr) ? 0 : want->GetIntParam("ohos.ability.launch.reason", 0); - TAG_LOGD(AAFwkTag::APPMGR, "req: %{public}d, proc: %{public}s, call:%{public}d,%{public}s", launchReson, - appInfo->name.c_str(), appRecord->GetCallerPid(), callRecord->GetBundleName().c_str()); - } - uint32_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo); - int32_t bundleIndex = (want == nullptr) ? 0 : want->GetIntParam(DLP_PARAMS_INDEX, 0); - StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord, - appInfo->uid, bundleInfo, appInfo->bundleName, bundleIndex, appExistFlag); - std::string perfCmd = (want == nullptr) ? "" : want->GetStringParam(PERF_CMD); - bool isSandboxApp = (want == nullptr) ? false : want->GetBoolParam(ENTER_SANDBOX, false); - (void)StartPerfProcess(appRecord, perfCmd, "", isSandboxApp); + LoadAbilityNoAppRecord(appRecord, preToken, appInfo, abilityInfo, processName, specifiedProcessFlag, + bundleInfo, hapModuleInfo, want, appExistFlag, false); } else { TAG_LOGI(AAFwkTag::APPMGR, "have apprecord"); SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::MULTI_INSTANCE); @@ -526,6 +586,67 @@ void AppMgrServiceInner::MakeProcessName( processName = appInfo->bundleName; } +void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr appRecord, + sptr preToken, std::shared_ptr appInfo, + std::shared_ptr abilityInfo, const std::string &processName, + const std::string &specifiedProcessFlag, const BundleInfo &bundleInfo, const HapModuleInfo &hapModuleInfo, + std::shared_ptr want, bool appExistFlag, bool isPreload) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGI(AAFwkTag::APPMGR, "LoadAbilityNoAppRecord, processName:%{public}s, isPreload:%{public}d", + processName.c_str(), isPreload); + if (!appRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "CreateAppRunningRecord failed, appRecord is nullptr"); + return; + } + if (!specifiedProcessFlag.empty()) { + appRecord->SetSpecifiedProcessFlag(specifiedProcessFlag); + } + if (hapModuleInfo.isStageBasedModel && !IsMainProcess(appInfo, hapModuleInfo)) { + appRecord->SetKeepAliveAppState(false, false); + TAG_LOGI(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); + } + OnAppStateChanged(appRecord, ApplicationState::APP_STATE_SET_COLD_START, false, false); + SendAppStartupTypeEvent(appRecord, abilityInfo, AppStartType::COLD); + if (preToken) { + auto callRecord = GetAppRunningRecordByAbilityToken(preToken); + if (callRecord != nullptr) { + auto launchReson = (want == nullptr) ? 0 : want->GetIntParam("ohos.ability.launch.reason", 0); + TAG_LOGD(AAFwkTag::APPMGR, "req: %{public}d, proc: %{public}s, call:%{public}d,%{public}s", launchReson, + appInfo->name.c_str(), appRecord->GetCallerPid(), callRecord->GetBundleName().c_str()); + } + } + uint32_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo); + int32_t bundleIndex = (want == nullptr) ? 0 : want->GetIntParam(DLP_PARAMS_INDEX, 0); + StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord, + appInfo->uid, bundleInfo, appInfo->bundleName, bundleIndex, appExistFlag, isPreload); + std::string perfCmd = (want == nullptr) ? "" : want->GetStringParam(PERF_CMD); + bool isSandboxApp = (want == nullptr) ? false : want->GetBoolParam(ENTER_SANDBOX, false); + (void)StartPerfProcess(appRecord, perfCmd, "", isSandboxApp); +} + +std::string AppMgrServiceInner::GetSpecifiedProcessFlag(std::shared_ptr abilityInfo, + std::shared_ptr want) +{ + if (!abilityInfo) { + TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr."); + return ""; + } + if (!want) { + TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr."); + return ""; + } + std::string specifiedProcessFlag = ""; + bool isUIAbility = (abilityInfo->type == AppExecFwk::AbilityType::PAGE && abilityInfo->isStageBasedModel); + bool isSpecifiedProcess = abilityInfo->isolationProcess && + AAFwk::AppUtils::GetInstance().IsStartSpecifiedProcess() && isUIAbility; + if (isSpecifiedProcess) { + specifiedProcessFlag = want->GetStringParam(PARAM_SPECIFIED_PROCESS_FLAG); + TAG_LOGI(AAFwkTag::APPMGR, "specifiedProcessFlag = %{public}s", specifiedProcessFlag.c_str()); + } + return specifiedProcessFlag; +} + bool AppMgrServiceInner::IsMainProcess(const std::shared_ptr &appInfo, const HapModuleInfo &hapModuleInfo) const { @@ -699,6 +820,7 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptrLaunchPendingAbilities(); + appRecord->SetPreloadState(PreloadState::PRELOADED); SendAppLaunchEvent(appRecord); } @@ -1938,7 +2060,8 @@ void AppMgrServiceInner::StartAbility(sptr token, sptrGetState(); if (appState == ApplicationState::APP_STATE_CREATE) { - TAG_LOGE(AAFwkTag::APPMGR, "in create state, don't launch ability"); + TAG_LOGE(AAFwkTag::APPMGR, "in create state, don't launch ability, bundleName:%{public}s, ability:%{public}s", + appInfo->bundleName.c_str(), abilityInfo->name.c_str()); return; } appRecord->LaunchAbility(ability); @@ -2249,7 +2372,7 @@ void AppMgrServiceInner::StartProcessVerifyPermission(const BundleInfo &bundleIn void AppMgrServiceInner::StartProcess(const std::string &appName, const std::string &processName, uint32_t startFlags, std::shared_ptr appRecord, const int uid, const BundleInfo &bundleInfo, - const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag) + const std::string &bundleName, const int32_t bundleIndex, bool appExistFlag, bool isPreload) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); if (!appRecord) { @@ -2321,8 +2444,9 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str SetOverlayInfo(bundleName, userId, startMsg); SetAppEnvInfo(bundleInfo, startMsg); - TAG_LOGI(AAFwkTag::APPMGR, "apl is %{public}s, bundleName is %{public}s, startFlags is %{public}d.", - startMsg.apl.c_str(), bundleName.c_str(), startFlags); + TAG_LOGI(AAFwkTag::APPMGR, + "apl is %{public}s, bundleName is %{public}s, startFlags is %{public}d, isPreload:%{public}d", + startMsg.apl.c_str(), bundleName.c_str(), startFlags, isPreload); bool bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleGidsByUid(bundleName, uid, startMsg.gids)); if (!bundleMgrResult) { diff --git a/services/appmgr/src/app_preloader.cpp b/services/appmgr/src/app_preloader.cpp new file mode 100644 index 0000000000..2c91c9a8d3 --- /dev/null +++ b/services/appmgr/src/app_preloader.cpp @@ -0,0 +1,160 @@ +/* + * 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 "app_preloader.h" + +#include + +#include "ability_manager_errors.h" +#include "in_process_call_wrapper.h" +#include "hilog_tag_wrapper.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace AppExecFwk { +AppPreloader::AppPreloader(std::shared_ptr remoteClientManager) +{ + remoteClientManager_ = remoteClientManager; +} + +int32_t AppPreloader::GeneratePreloadRequest(const std::string &bundleName, int32_t userId, int32_t appIndex, + PreloadRequest &request) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPMGR, "PreloadApplication GeneratePreloadRequest"); + + AAFwk::Want launchWant; + if (!GetLaunchWant(bundleName, userId, launchWant)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetLaunchWant failed"); + return AAFwk::ERR_TARGET_BUNDLE_NOT_EXIST; + } + + AbilityInfo abilityInfo; + if (!GetLaunchAbilityInfo(launchWant, userId, abilityInfo)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetLaunchAbilityInfo failed"); + return AAFwk::ERR_GET_LAUNCH_ABILITY_INFO_FAILED; + } + + if (!CheckPreloadConditions(abilityInfo)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication CheckPreloadConditions failed."); + return AAFwk::ERR_CHECK_PRELOAD_CONDITIONS_FAILED; + } + + BundleInfo bundleInfo; + HapModuleInfo hapModuleInfo; + if (!GetBundleAndHapInfo(bundleName, userId, abilityInfo, bundleInfo, hapModuleInfo)) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetBundleAndHapInfo failed"); + return AAFwk::GET_BUNDLE_INFO_FAILED; + } + + request.abilityInfo = std::make_shared(abilityInfo); + request.appInfo = std::make_shared(abilityInfo.applicationInfo); + request.want = std::make_shared(launchWant); + request.bundleInfo = bundleInfo; + request.hapModuleInfo = hapModuleInfo; + request.appIndex = appIndex; + + return ERR_OK; +} + +bool AppPreloader::GetLaunchWant(const std::string &bundleName, int32_t userId, AAFwk::Want &launchWant) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + auto bundleMgrHelper = GetBundleManagerHelper(); + if (!bundleMgrHelper) { + TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper is nullptr."); + return false; + } + + auto errCode = IN_PROCESS_CALL(bundleMgrHelper->GetLaunchWantForBundle(bundleName, launchWant, userId)); + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetLaunchWantForBundle failed, errCode: %{public}d.", errCode); + return false; + } + return true; +} + +bool AppPreloader::GetLaunchAbilityInfo(const AAFwk::Want &want, int32_t userId, AbilityInfo &abilityInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + auto bundleMgrHelper = GetBundleManagerHelper(); + if (!bundleMgrHelper) { + TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper is nullptr."); + return false; + } + + auto abilityInfoFlag = (AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION | + AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION | + AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_METADATA); + if (!IN_PROCESS_CALL(bundleMgrHelper->QueryAbilityInfo(want, abilityInfoFlag, userId, abilityInfo))) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetLaunchAbilityInfo failed."); + return false; + } + + return true; +} + +bool AppPreloader::GetBundleAndHapInfo(const std::string &bundleName, int32_t userId, + const AbilityInfo &abilityInfo, BundleInfo &bundleInfo, HapModuleInfo &hapModuleInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + auto bundleMgrHelper = GetBundleManagerHelper(); + if (!bundleMgrHelper) { + TAG_LOGE(AAFwkTag::APPMGR, "bundleMgrHelper is nullptr."); + return false; + } + + if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, + userId))) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetBundleInfo failed."); + return false; + } + + if (!IN_PROCESS_CALL(bundleMgrHelper->GetHapModuleInfo(abilityInfo, userId, hapModuleInfo))) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication GetHapModuleInfo failed."); + return false; + } + return true; +} + +bool AppPreloader::CheckPreloadConditions(const AbilityInfo &abilityInfo) +{ + if (abilityInfo.type != AppExecFwk::AbilityType::PAGE || !abilityInfo.isStageBasedModel) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Launch Ability type is not UIAbility"); + return false; + } + ApplicationInfo appInfo = abilityInfo.applicationInfo; + if (abilityInfo.name.empty() || appInfo.name.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication abilityInfo or appInfo name is empty"); + return false; + } + if (abilityInfo.applicationName != appInfo.name) { + TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication abilityInfo and appInfo have different appName, \ + don't load for it"); + return false; + } + return true; +} + +std::shared_ptr AppPreloader::GetBundleManagerHelper() +{ + if (!remoteClientManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "remoteClientManager_ is nullptr."); + return nullptr; + } + return remoteClientManager_->GetBundleManagerHelper(); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index f01db98e34..8a1acb6704 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1995,6 +1995,21 @@ bool AppRunningRecord::IsJITEnabled() const return jitEnabled_; } +void AppRunningRecord::SetPreloadState(PreloadState state) +{ + preloadState_ = state; +} + +bool AppRunningRecord::IsPreloading() const +{ + return preloadState_ == PreloadState::PRELOADING; +} + +bool AppRunningRecord::IsPreloaded() const +{ + return preloadState_ == PreloadState::PRELOADED; +} + int32_t AppRunningRecord::GetAssignTokenId() const { return assignTokenId_; diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index bc4fbcda85..f3abf7c179 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -46,6 +46,7 @@ constexpr const char* PERMISSION_CONNECT_UI_EXTENSION_ABILITY = "ohos.permission constexpr const char* PERMISSION_START_RECENT_ABILITY = "ohos.permission.START_RECENT_ABILITY"; constexpr const char* PERMISSION_NOTIFY_DEBUG_ASSERT_RESULT = "ohos.permission.NOTIFY_DEBUG_ASSERT_RESULT"; constexpr const char* PERMISSION_START_SHORTCUT = "ohos.permission.START_SHORTCUT"; +constexpr const char* PERMISSION_PRELOAD_APPLICATION = "ohos.permission.PRELOAD_APPLICATION"; } // namespace PermissionConstants } // namespace AAFwk } // namespace OHOS diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index 9e16d330dc..3e1d2a1b67 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -95,6 +95,8 @@ struct VerificationInfo { bool VerifyShellStartExtensionType(int32_t type) const; + bool VerifyPreloadApplicationPermission() const; + private: DISALLOW_COPY_AND_MOVE(PermissionVerification); diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index ab08996491..3a8b009593 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -435,5 +435,15 @@ bool PermissionVerification::VerifyShellStartExtensionType(int32_t type) const HILOG_DEBUG("VerifyShellStartExtensionType, reject start."); return false; } + +bool PermissionVerification::VerifyPreloadApplicationPermission() const +{ + if (VerifyCallingPermission(PermissionConstants::PERMISSION_PRELOAD_APPLICATION)) { + HILOG_DEBUG("Verify permission %{public}s succeed.", PermissionConstants::PERMISSION_PRELOAD_APPLICATION); + return true; + } + HILOG_ERROR("Verify permission %{public}s failed.", PermissionConstants::PERMISSION_PRELOAD_APPLICATION); + return false; +} } // namespace AAFwk } // namespace OHOS 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 6d1fd3d0bc..25cc16f339 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 @@ -63,6 +63,7 @@ public: MOCK_METHOD3(GetBundleNameByPid, int32_t(const int pid, std::string &bundleName, int32_t &uid)); MOCK_METHOD3(StartChildProcess, int32_t(const pid_t hostPid, const std::string &srcEntry, pid_t &childPid)); MOCK_METHOD1(GetChildProcessInfoForSelf, int32_t(ChildProcessInfo &info)); + MOCK_METHOD4(PreloadApplication, int32_t(const std::string&, int32_t, AppExecFwk::PreloadMode, int32_t)); void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) {} diff --git a/test/moduletest/ability_delegator_test/BUILD.gn b/test/moduletest/ability_delegator_test/BUILD.gn index db5633f432..092388dfe1 100644 --- a/test/moduletest/ability_delegator_test/BUILD.gn +++ b/test/moduletest/ability_delegator_test/BUILD.gn @@ -194,7 +194,10 @@ ohos_moduletest("ability_delegator_moduletest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/moduletest/ability_manager_service_dump_test/BUILD.gn b/test/moduletest/ability_manager_service_dump_test/BUILD.gn index 1027b19e02..4e5671e73c 100644 --- a/test/moduletest/ability_manager_service_dump_test/BUILD.gn +++ b/test/moduletest/ability_manager_service_dump_test/BUILD.gn @@ -45,7 +45,10 @@ ohos_moduletest("ability_manager_service_dump_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index 0358ec3c79..eb0180109b 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -93,7 +93,6 @@ ohos_moduletest("ability_moduletest") { external_deps += [ "input:libmmi-client", "window_manager:libwsutils", - "window_manager:scene_session", ] } } @@ -151,7 +150,6 @@ ohos_moduletest("ability_conetxt_test") { external_deps += [ "input:libmmi-client", "window_manager:libwsutils", - "window_manager:scene_session", ] } } @@ -236,7 +234,6 @@ ohos_moduletest("data_ability_operation_moduletest") { external_deps += [ "input:libmmi-client", "window_manager:libwsutils", - "window_manager:scene_session", ] } } diff --git a/test/moduletest/call_module_test/BUILD.gn b/test/moduletest/call_module_test/BUILD.gn index 341393428d..4689c9cc01 100644 --- a/test/moduletest/call_module_test/BUILD.gn +++ b/test/moduletest/call_module_test/BUILD.gn @@ -45,7 +45,10 @@ ohos_moduletest("call_ability_service_module_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn index 93279d3788..e8bc0d75a3 100644 --- a/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn +++ b/test/moduletest/common/ams/specified_ability_service_test/BUILD.gn @@ -48,7 +48,10 @@ ohos_moduletest("specified_ability_service_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/moduletest/on_new_want_module_test/BUILD.gn b/test/moduletest/on_new_want_module_test/BUILD.gn index 6725a2d0f2..8ebdd45d28 100644 --- a/test/moduletest/on_new_want_module_test/BUILD.gn +++ b/test/moduletest/on_new_want_module_test/BUILD.gn @@ -47,7 +47,10 @@ ohos_moduletest("on_new_want_module_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/moduletest/start_option_display_id_test/BUILD.gn b/test/moduletest/start_option_display_id_test/BUILD.gn index 7b581ed93a..6943527d23 100644 --- a/test/moduletest/start_option_display_id_test/BUILD.gn +++ b/test/moduletest/start_option_display_id_test/BUILD.gn @@ -45,7 +45,10 @@ ohos_moduletest("start_option_module_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } if (background_task_mgr_continuous_task_enable) { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 82b5423cd9..86e2fc43e3 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -391,6 +391,7 @@ group("unittest") { "app_mgr_service_inner_test:unittest", "app_mgr_service_test:unittest", "app_mgr_stub_test:unittest", + "app_preloader_test:unittest", "app_recovery_test:unittest", "app_running_manager_test:unittest", "app_running_processes_info_test:unittest", diff --git a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn index c61f6ce9f2..8fc128ff37 100644 --- a/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_data_manager_test/BUILD.gn @@ -57,7 +57,6 @@ ohos_unittest("ability_auto_startup_data_manager_test") { "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", - "window_manager:scene_session", ] } diff --git a/test/unittest/ability_auto_startup_service_test/BUILD.gn b/test/unittest/ability_auto_startup_service_test/BUILD.gn index 1ec0bd6617..2eafb6c7dd 100644 --- a/test/unittest/ability_auto_startup_service_test/BUILD.gn +++ b/test/unittest/ability_auto_startup_service_test/BUILD.gn @@ -67,8 +67,14 @@ ohos_unittest("ability_auto_startup_service_test") { "init:libbegetutil", "ipc:ipc_core", "kv_store:distributeddata_inner", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } } group("unittest") { testonly = true diff --git a/test/unittest/ability_manager_service_dialog_test/BUILD.gn b/test/unittest/ability_manager_service_dialog_test/BUILD.gn index b26a33e9aa..d8b190742f 100644 --- a/test/unittest/ability_manager_service_dialog_test/BUILD.gn +++ b/test/unittest/ability_manager_service_dialog_test/BUILD.gn @@ -43,6 +43,7 @@ ohos_unittest("ability_manager_service_dialog_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } diff --git a/test/unittest/ability_manager_service_first_test/BUILD.gn b/test/unittest/ability_manager_service_first_test/BUILD.gn index a1d31bfbec..3d8870adfb 100644 --- a/test/unittest/ability_manager_service_first_test/BUILD.gn +++ b/test/unittest/ability_manager_service_first_test/BUILD.gn @@ -75,7 +75,10 @@ ohos_unittest("ability_manager_service_first_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 2d66d08958..221a5ff902 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -60,7 +60,10 @@ ohos_unittest("ability_manager_service_second_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 089746c68a..6c7968b158 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -56,7 +56,10 @@ ohos_unittest("ability_manager_service_third_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ability_timeout_test/BUILD.gn b/test/unittest/ability_timeout_test/BUILD.gn index 69da1b0af2..0a445354f6 100644 --- a/test/unittest/ability_timeout_test/BUILD.gn +++ b/test/unittest/ability_timeout_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("ability_timeout_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } @@ -54,5 +55,5 @@ ohos_unittest("ability_timeout_test") { group("unittest") { testonly = true - # deps = [ ":ability_timeout_test" ] + deps = [ ":ability_timeout_test" ] } diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index 6d13760efa..9a8095842b 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { "${ability_runtime_services_path}/appmgr/src/app_death_recipient.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp", "${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/test/unittest/ams_app_life_cycle_test/BUILD.gn b/test/unittest/ams_app_life_cycle_test/BUILD.gn index 4b582cad20..32bfa8de2c 100644 --- a/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_unittest("AmsAppLifeCycleTest") { "${ability_runtime_services_path}/appmgr/src/app_lifecycle_deal.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index 96da7fbf6f..d2d44d62a2 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("AmsWorkFlowTest") { "${ability_runtime_services_path}/appmgr/src/app_lifecycle_deal.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index 833c553c0a..023828f6aa 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("AmsRecentAppListTest") { "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_lifecycle_deal.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 432db06c68..c10a3ff7ee 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { "${ability_runtime_services_path}/appmgr/src/app_mgr_service.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp", "${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index 25a66ef72f..b77de1fec4 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -39,6 +39,7 @@ ohos_unittest("AmsServiceEventDriveTest") { "${ability_runtime_services_path}/appmgr/src/app_mgr_service.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp", "${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index da04537877..cc9eef195e 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_lifecycle_deal.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 79c350e460..34abcdb85e 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("AmsServiceStartupTest") { "${ability_runtime_services_path}/appmgr/src/app_mgr_service.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp", "${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp index 27a45b37e5..3cd4afea90 100644 --- a/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp +++ b/test/unittest/app_mgr_client_test/app_mgr_client_test.cpp @@ -1010,5 +1010,26 @@ HWTEST_F(AppMgrClientTest, GetAllUIExtensionProviderPid_001, TestSize.Level0) EXPECT_NE(ret, AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED); EXPECT_EQ(providerPids.size(), 0); } + +/** + * @tc.name: PreloadApplication_001 + * @tc.desc: Preload application. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrClientTest, PreloadApplication_001, TestSize.Level0) +{ + auto appMgrClient = std::make_unique(); + EXPECT_NE(appMgrClient, nullptr); + + auto result = appMgrClient->ConnectAppMgrService(); + EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); + + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + PreloadMode preloadMode = PreloadMode::PRE_MAKE; + int32_t appIndex = 0; + int32_t ret = appMgrClient->PreloadApplication(bundleName, userId, preloadMode, appIndex); + EXPECT_EQ(ret, ERR_PERMISSION_DENIED); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 8f6e2714c0..d2cc4cec1f 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -539,5 +539,26 @@ HWTEST_F(AppMgrProxyTest, GetAllUIExtensionProviderPid_0100, TestSize.Level1) EXPECT_EQ(mockAppMgrService_->code_, static_cast(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_PROVIDER_PID)); } + +/** + * @tc.name: PreloadApplication_0100 + * @tc.desc: Preload application. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, PreloadApplication_0100, TestSize.Level1) +{ + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + PreloadMode preloadMode = PreloadMode::PRE_MAKE; + int32_t appIndex = 0; + auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex); + EXPECT_EQ(ret, NO_ERROR); + EXPECT_EQ(mockAppMgrService_->code_, + static_cast(AppMgrInterfaceCode::PRELOAD_APPLICATION)); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 507dd6e351..d63f835576 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_unittest("AMSEventHandlerTest") { "${ability_runtime_services_path}/appmgr/src/app_lifecycle_deal.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_process_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", 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 e61a77818b..5faecc1d3e 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 @@ -4152,5 +4152,23 @@ HWTEST_F(AppMgrServiceInnerTest, AddUIExtensionLauncherItem_0100, TestSize.Level EXPECT_EQ(want->HasParameter("ability.want.params.uiExtensionAbilityId"), false); EXPECT_EQ(want->HasParameter("ability.want.params.uiExtensionRootHostPid"), false); } + +/** + * @tc.name: PreloadApplication_0100 + * @tc.desc: Preload Application. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerTest, PreloadApplication_0100, TestSize.Level1) +{ + auto appMgrServiceInner = std::make_shared(); + ASSERT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + PreloadMode preloadMode = PreloadMode::PRE_MAKE; + int32_t appIndex = 0; + int32_t ret = appMgrServiceInner->PreloadApplication(bundleName, userId, preloadMode, appIndex); + EXPECT_EQ(ret, ERR_PERMISSION_DENIED); +} } // namespace AppExecFwk } // namespace OHOS 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 3d589dc168..9c10b3741a 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 @@ -19,6 +19,7 @@ #include "app_mgr_service.h" #include "app_utils.h" #undef private +#include "ability_manager_errors.h" #include "child_main_thread.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" @@ -1624,5 +1625,31 @@ HWTEST_F(AppMgrServiceTest, GetAllUIExtensionProviderPid_0100, TestSize.Level1) appMgrService->eventHandler_ = eventHandler_; EXPECT_EQ(appMgrService->GetAllUIExtensionProviderPid(hostPid, providerPids), ERR_OK); } + +/** + * @tc.name: PreloadApplication_0100 + * @tc.desc: Preload application. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceTest, PreloadApplication_0100, TestSize.Level1) +{ + auto appMgrService = std::make_shared(); + ASSERT_NE(appMgrService, nullptr); + appMgrService->SetInnerService(mockAppMgrServiceInner_); + appMgrService->taskHandler_ = taskHandler_; + appMgrService->eventHandler_ = eventHandler_; + + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + PreloadMode preloadMode = PreloadMode::PRE_MAKE; + int32_t appIndex = 0; + + EXPECT_CALL(*mockAppMgrServiceInner_, PreloadApplication(_, _, _, _)) + .Times(1) + .WillOnce(Return(ERR_OK)); + + int32_t ret = appMgrService->PreloadApplication(bundleName, userId, preloadMode, appIndex); + EXPECT_EQ(ret, ERR_OK); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 8c6e3965dc..9a55b012e1 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -24,6 +24,7 @@ #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" +#include "ipc_types.h" #include "mock_app_mgr_service.h" #include "render_state_observer_stub.h" @@ -547,5 +548,32 @@ HWTEST_F(AppMgrStubTest, HandleGetAllUIExtensionProviderPid_0100, TestSize.Level int32_t size = reply.ReadInt32(); EXPECT_EQ(size, 0); } + +/** + * @tc.name: PreloadApplication_0100 + * @tc.desc: Preload application. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, PreloadApplication_0100, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + WriteInterfaceToken(data); + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + PreloadMode preloadMode = PreloadMode::PRE_MAKE; + int32_t appIndex = 0; + + data.WriteString16(Str8ToStr16(bundleName)); + data.WriteInt32(userId); + data.WriteInt32(static_cast(preloadMode)); + data.WriteInt32(appIndex); + + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(AppMgrInterfaceCode::PRELOAD_APPLICATION), data, reply, option); + EXPECT_EQ(result, NO_ERROR); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_preloader_test/BUILD.gn b/test/unittest/app_preloader_test/BUILD.gn new file mode 100755 index 0000000000..cf88abff1c --- /dev/null +++ b/test/unittest/app_preloader_test/BUILD.gn @@ -0,0 +1,55 @@ +# 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/appmgrservice" + +ohos_unittest("app_preloader_test") { + module_out_path = module_output_path + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "include", + ] + + sources = [ + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", + "app_preloader_test.cpp", + ] + + deps = [ + "${ability_runtime_services_path}/appmgr:libappms", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":app_preloader_test" ] +} diff --git a/test/unittest/app_preloader_test/app_preloader_test.cpp b/test/unittest/app_preloader_test/app_preloader_test.cpp new file mode 100755 index 0000000000..647dba1dff --- /dev/null +++ b/test/unittest/app_preloader_test/app_preloader_test.cpp @@ -0,0 +1,64 @@ +/* + * 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 + +#include "app_preloader.h" +#include "hilog_tag_wrapper.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class AppPreloaderTest : public testing::Test { +public: + void SetUp(); + void TearDown(); + +protected: + std::shared_ptr remoteClientManager_ = nullptr; +}; + +void AppPreloaderTest::SetUp() +{ + remoteClientManager_ = std::make_shared(); + auto bundleMgrHelper = std::make_shared(); + remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper); +} + +void AppPreloaderTest::TearDown() +{} + +/** + * @tc.number: AppPreloaderTest_GeneratePreloadRequest_0100 + * @tc.desc: Test Init works + * @tc.type: FUNC + */ +HWTEST_F(AppPreloaderTest, AppPreloaderTest_GeneratePreloadRequest_0100, TestSize.Level0) +{ + TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GeneratePreloadRequest_0100 start."); + auto manager = std::make_shared(remoteClientManager_); + EXPECT_NE(manager, nullptr); + + std::string bundleName = "com.acts.preloadtest"; + int32_t userId = 100; + int32_t appIndex = 0; + PreloadRequest request; + auto ret = manager->GeneratePreloadRequest(bundleName, userId, appIndex, request); + EXPECT_EQ(ret, ERR_OK); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_preloader_test/include/bundle_mgr_helper.h b/test/unittest/app_preloader_test/include/bundle_mgr_helper.h new file mode 100644 index 0000000000..e9cd13e107 --- /dev/null +++ b/test/unittest/app_preloader_test/include/bundle_mgr_helper.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H +#define OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H + +#include "bundle_mgr_interface.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +using Want = OHOS::AAFwk::Want; + +class BundleMgrHelper : public std::enable_shared_from_this { +public: + BundleMgrHelper() = default;; + ~BundleMgrHelper() = default; + + ErrCode GetLaunchWantForBundle(const std::string &bundleName, Want &want, int32_t userId) + { + return ERR_OK; + } + + bool QueryAbilityInfo(const Want &want, int32_t flags, int32_t userId, AbilityInfo &abilityInfo) + { + abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityInfo.isStageBasedModel = true; + abilityInfo.name = "MainAbility"; + abilityInfo.applicationName = "com.acts.preloadtest"; + abilityInfo.applicationInfo.name = abilityInfo.applicationName; + return true; + } + + bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId) + { + return true; + } + + bool GetHapModuleInfo(const AbilityInfo &abilityInfo, int32_t userId, HapModuleInfo &hapModuleInfo) + { + return true; + } +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H \ No newline at end of file diff --git a/test/unittest/app_running_processes_info_test/BUILD.gn b/test/unittest/app_running_processes_info_test/BUILD.gn index 84db65c501..696e1a9ff6 100644 --- a/test/unittest/app_running_processes_info_test/BUILD.gn +++ b/test/unittest/app_running_processes_info_test/BUILD.gn @@ -32,6 +32,7 @@ ohos_unittest("AppRunningProcessesInfoTest") { "${ability_runtime_services_path}/appmgr/src/app_config_data_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_debug_manager.cpp", "${ability_runtime_services_path}/appmgr/src/app_mgr_service_inner.cpp", + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_record.cpp", "${ability_runtime_services_path}/appmgr/src/app_running_status_module.cpp", "${ability_runtime_services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/test/unittest/auto_startup_info_test/BUILD.gn b/test/unittest/auto_startup_info_test/BUILD.gn index ef3bfeea3c..6be971fc04 100644 --- a/test/unittest/auto_startup_info_test/BUILD.gn +++ b/test/unittest/auto_startup_info_test/BUILD.gn @@ -58,8 +58,14 @@ ohos_unittest("auto_startup_info_test") { "hilog:libhilog", "ipc:ipc_core", "kv_store:distributeddata_inner", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } } group("unittest") { diff --git a/test/unittest/call_container_test/BUILD.gn b/test/unittest/call_container_test/BUILD.gn index 93fccd2f4c..2912137766 100644 --- a/test/unittest/call_container_test/BUILD.gn +++ b/test/unittest/call_container_test/BUILD.gn @@ -58,8 +58,14 @@ ohos_unittest("call_container_test") { "hilog:libhilog", "ipc:ipc_core", "napi:ace_napi", - "window_manager:scene_session", ] + + if (ability_runtime_graphics) { + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] + } } group("unittest") { diff --git a/test/unittest/extension_manager_client_test/BUILD.gn b/test/unittest/extension_manager_client_test/BUILD.gn index 1c2a57339b..be3e5d5021 100644 --- a/test/unittest/extension_manager_client_test/BUILD.gn +++ b/test/unittest/extension_manager_client_test/BUILD.gn @@ -41,10 +41,6 @@ ohos_unittest("extension_manager_client_test") { "hilog:libhilog", "ipc:ipc_core", ] - - if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] - } } group("unittest") { diff --git a/test/unittest/form_extension_context_test/BUILD.gn b/test/unittest/form_extension_context_test/BUILD.gn index ca92d97814..c2043bc691 100644 --- a/test/unittest/form_extension_context_test/BUILD.gn +++ b/test/unittest/form_extension_context_test/BUILD.gn @@ -16,7 +16,7 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/abilitymgr" -ohos_unittest("form_extension_context_test") { +ohos_unittest("form_extension_context_first_test") { module_out_path = module_output_path include_dirs = [ @@ -85,14 +85,10 @@ ohos_unittest("form_extension_context_test") { if (background_task_mgr_continuous_task_enable) { external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] } - - if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] - } } group("unittest") { testonly = true - deps = [ ":form_extension_context_test" ] + deps = [ ":form_extension_context_first_test" ] } diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index d76d40278d..0011ac21fa 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -131,7 +131,6 @@ ohos_unittest("ability_test") { "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", - "window_manager:scene_session", ] if (ability_runtime_graphics) { @@ -139,6 +138,8 @@ ohos_unittest("ability_test") { "image_framework:image_native", "input:libmmi-client", "window_manager:libwm", + "window_manager:libwsutils", + "window_manager:scene_session", ] } } @@ -1624,7 +1625,6 @@ ohos_unittest("ui_ability_test") { "init:libbegetutil", "ipc:ipc_core", "napi:ace_napi", - "window_manager:scene_session", ] if (ability_runtime_graphics) { @@ -2017,6 +2017,7 @@ ohos_unittest("ability_window_test") { "relational_store:native_dataability", "relational_store:native_rdb", "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn index 71ce3d781b..e2a1a8515a 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_delegator/BUILD.gn @@ -144,7 +144,10 @@ ohos_unittest("ability_delegator_unittest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/free_install_manager_test/BUILD.gn b/test/unittest/free_install_manager_test/BUILD.gn index 92d945c71d..103d1d751f 100644 --- a/test/unittest/free_install_manager_test/BUILD.gn +++ b/test/unittest/free_install_manager_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("free_install_manager_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } diff --git a/test/unittest/lifecycle_test/BUILD.gn b/test/unittest/lifecycle_test/BUILD.gn index 02c4090374..29f5ffa9b6 100644 --- a/test/unittest/lifecycle_test/BUILD.gn +++ b/test/unittest/lifecycle_test/BUILD.gn @@ -53,6 +53,7 @@ ohos_unittest("lifecycle_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } diff --git a/test/unittest/running_infos_test/BUILD.gn b/test/unittest/running_infos_test/BUILD.gn index 80fe793f7e..1ce69eb1e7 100644 --- a/test/unittest/running_infos_test/BUILD.gn +++ b/test/unittest/running_infos_test/BUILD.gn @@ -47,6 +47,7 @@ ohos_unittest("running_infos_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index 541965ce4a..6f2374e2d3 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -75,7 +75,10 @@ ohos_unittest("specified_mission_list_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/start_option_display_id_test/BUILD.gn b/test/unittest/start_option_display_id_test/BUILD.gn index 07764f259a..9418fa7962 100644 --- a/test/unittest/start_option_display_id_test/BUILD.gn +++ b/test/unittest/start_option_display_id_test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("start_option_display_id_test") { if (ability_runtime_graphics) { external_deps += [ "window_manager:libwm", + "window_manager:libwsutils", "window_manager:scene_session", ] } diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index 7b8bf315e2..9372c31219 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -89,7 +89,10 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { } if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/ui_extension/ui_extension_get_host_info_test/BUILD.gn b/test/unittest/ui_extension/ui_extension_get_host_info_test/BUILD.gn index 34f818c093..e92c23f48b 100644 --- a/test/unittest/ui_extension/ui_extension_get_host_info_test/BUILD.gn +++ b/test/unittest/ui_extension/ui_extension_get_host_info_test/BUILD.gn @@ -61,7 +61,10 @@ ohos_unittest("ui_extension_get_host_info_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } } diff --git a/test/unittest/user_controller_test/BUILD.gn b/test/unittest/user_controller_test/BUILD.gn index fc3bd81169..0942a2072a 100644 --- a/test/unittest/user_controller_test/BUILD.gn +++ b/test/unittest/user_controller_test/BUILD.gn @@ -43,7 +43,10 @@ ohos_unittest("user_controller_test") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:scene_session" ] + external_deps += [ + "window_manager:libwsutils", + "window_manager:scene_session", + ] } }