From 16e78cb1b14d2f16b16071e58b9a24a29b495995 Mon Sep 17 00:00:00 2001 From: sty Date: Mon, 16 Jun 2025 12:14:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E8=80=85=E5=A3=B0=E6=98=8E=E5=A4=87=E9=80=89=E4=B8=BB=E6=8E=A7?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sty Change-Id: I546c9cf0fca8979920fa5f80ff59ec35786e1db4 --- .../application_context.js | 8 +++ .../context/application_context.cpp | 18 +++++ .../ability_runtime/context/context_impl.cpp | 30 ++++++++ .../context/js_application_context_utils.cpp | 72 +++++++++++++++++++ .../include/appmgr/app_mgr_client.h | 15 ++++ .../include/appmgr/app_mgr_interface.h | 4 ++ .../appmgr/app_mgr_ipc_interface_code.h | 2 + .../include/appmgr/app_mgr_proxy.h | 15 ++++ .../app_manager/include/appmgr/app_mgr_stub.h | 2 + .../app_manager/src/appmgr/app_mgr_client.cpp | 25 +++++++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 33 +++++++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 29 ++++++++ .../context/application_context.h | 2 + .../ability_runtime/context/context_impl.h | 16 +++++ .../context/js_application_context_utils.h | 7 ++ services/appmgr/include/app_mgr_service.h | 15 ++++ .../appmgr/include/app_mgr_service_inner.h | 15 ++++ services/appmgr/include/app_running_manager.h | 12 ++++ services/appmgr/include/app_running_record.h | 23 ++++++ services/appmgr/src/app_mgr_service.cpp | 20 ++++++ services/appmgr/src/app_mgr_service_inner.cpp | 71 +++++++++++++++--- services/appmgr/src/app_running_manager.cpp | 39 ++++++++++ .../include/mock_app_mgr_service.h | 9 +++ 23 files changed, 471 insertions(+), 11 deletions(-) diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index d590b80f4a3..8693ddd10eb 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -297,6 +297,14 @@ class ApplicationContext { return this.__context_impl__.createDisplayContext(displayId); } + promoteToStandbyMasterProcess(isInsertToHead) { + return this.__context_impl__.promoteToStandbyMasterProcess(isInsertToHead); + } + + demoteFromStandbyMasterProcess() { + return this.__context_impl__.demoteFromStandbyMasterProcess(); + } + set area(mode) { return this.__context_impl__.switchArea(mode); } diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 540797bc0c3..9a87426cb39 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -923,6 +923,24 @@ std::shared_ptr ApplicationContext::CreateAreaModeContext(int areaMode) return contextImpl_ ? contextImpl_->CreateAreaModeContext(areaMode) : nullptr; } +int32_t ApplicationContext::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + if (contextImpl_ != nullptr) { + return contextImpl_->PromoteToStandbyMasterProcess(isInsertToHead); + } + TAG_LOGE(AAFwkTag::APPKIT, "null contextImpl_"); + return ERR_INVALID_VALUE; +} + +int32_t ApplicationContext::DemoteFromStandbyMasterProcess() +{ + if (contextImpl_ != nullptr) { + return contextImpl_->DemoteFromStandbyMasterProcess(); + } + TAG_LOGE(AAFwkTag::APPKIT, "null contextImpl_"); + return ERR_INVALID_VALUE; +} + #ifdef SUPPORT_GRAPHICS std::shared_ptr ApplicationContext::CreateDisplayContext(uint64_t displayId) { diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index cab45fda83e..db45072178d 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -1741,6 +1741,36 @@ bool ContextImpl::UpdateDisplayConfiguration(std::shared_ptr &conte return true; } + +int64_t GetSteadyNanoSeconds() { + auto now = std::chrono::steady_clock::now().time_since_epoch(); + return std::chrono::duration_cast(now).count(); +} + +int32_t ContextImpl::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Called"); + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null appMgrClient"); + return ERR_INVALID_VALUE; + } + return appMgrClient->PromoteToStandbyMasterProcess(isInsertToHead); + +} + +int32_t ContextImpl::DemoteFromStandbyMasterProcess() +{ + + TAG_LOGD(AAFwkTag::APPKIT, "Called"); + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "null appMgrClient"); + return ERR_INVALID_VALUE; + } + return appMgrClient->DemoteFromStandbyMasterProcess(); +} + #ifdef SUPPORT_GRAPHICS std::shared_ptr ContextImpl::CreateDisplayContext(uint64_t displayId) { 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 c507ba81c46..a1e1f45bda9 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 @@ -1804,6 +1804,74 @@ napi_value JsApplicationContextUtils::OnSetSupportedProcessCacheSelf(napi_env en return CreateJsUndefined(env); } +napi_value JsApplicationContextUtils::PromoteToStandbyMasterProcess(napi_env env, napi_callback_info info) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnPromoteToStandbyMasterProcess, APPLICATION_CONTEXT_NAME); +} + +napi_value JsApplicationContextUtils::OnPromoteToStandbyMasterProcess(napi_env env, NapiCallbackInfo& info) +{ + // only support one params + if (info.argc == ARGC_ZERO) { + TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); + ThrowInvalidParamError(env, "Not enough params"); + return CreateJsUndefined(env); + } + auto applicationContext = applicationContext_.lock(); + if (!applicationContext) { + TAG_LOGW(AAFwkTag::APPKIT, "null applicationContext"); + return CreateJsUndefined(env); + } + + bool isInsertToHead = false; + if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], isInsertToHead)) { + TAG_LOGE(AAFwkTag::APPKIT, "Parse isInsertToHead failed"); + ThrowInvalidParamError(env, + "Parse param isSupport failed, isInsertToHead must be boolean."); + return CreateJsUndefined(env); + } + + auto errCode = applicationContext->PromoteToStandbyMasterProcess(isInsertToHead); + + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "promote to standby master process failed"); + AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR); + } + TAG_LOGE(AAFwkTag::APPKIT, "errCode:%{public}d.", errCode); + return CreateJsUndefined(env); +} + +napi_value JsApplicationContextUtils::DemoteFromStandbyMasterProcess(napi_env env, napi_callback_info info) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnDemoteFromStandbyMasterProcess, APPLICATION_CONTEXT_NAME); +} + +napi_value JsApplicationContextUtils::OnDemoteFromStandbyMasterProcess(napi_env env, NapiCallbackInfo& info) +{ + // only support 0 params + if (info.argc != ARGC_ZERO) { + TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); + ThrowInvalidParamError(env, "Not enough params"); + return CreateJsUndefined(env); + } + auto applicationContext = applicationContext_.lock(); + if (!applicationContext) { + TAG_LOGW(AAFwkTag::APPKIT, "null applicationContext"); + return CreateJsUndefined(env); + } + + auto errCode = applicationContext->DemoteFromStandbyMasterProcess(); + + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "Demote from standby master process failed"); + AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR); + } + TAG_LOGE(AAFwkTag::APPKIT, "errCode:%{public}d.", errCode); + return CreateJsUndefined(env); +} + void JsApplicationContextUtils::BindNativeApplicationContextOne(napi_env env, napi_value object) { BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir); @@ -1867,6 +1935,10 @@ void JsApplicationContextUtils::BindNativeApplicationContextTwo(napi_env env, na JsApplicationContextUtils::SetSupportedProcessCacheSelf); BindNativeFunction(env, object, "setFontSizeScale", MD_NAME, JsApplicationContextUtils::SetFontSizeScale); + BindNativeFunction(env, object, "promoteToStandbyMasterProcess", MD_NAME, + JsApplicationContextUtils::PromoteToStandbyMasterProcess); + BindNativeFunction(env, object, "demoteFromStandbyMasterProcess", MD_NAME, + JsApplicationContextUtils::DemoteFromStandbyMasterProcess); } } // namespace AbilityRuntime } // 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 485f59efb02..d234117e998 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 @@ -987,6 +987,21 @@ public: virtual AppMgrResultCode IsAppRunningByBundleNameAndUserId(const std::string &bundleName, int32_t userId, bool &isRunning); + /** + * Elevate the current process to be a standby master process. + * + * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @return Return ERR_OK if success, others fail. + */ + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + + /** + * Revoke current process as a standby master process. + * + * @return Return ERR_OK if success, others fail. + */ + int32_t DemoteFromStandbyMasterProcess(); + private: void SetServiceManager(std::unique_ptr serviceMgr); /** diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 78c33ca8ff1..dfa5010835b 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 @@ -1001,6 +1001,10 @@ public: { return 0; } + + virtual int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) = 0; + + virtual int32_t DemoteFromStandbyMasterProcess() = 0; }; } // namespace AppExecFwk } // namespace OHOS 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 8b68417f097..a70f180f69d 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 @@ -132,6 +132,8 @@ enum class AppMgrInterfaceCode { UNREGISTER_NATIVE_CHILD_EXIT_NOTIFY = 106, UPDATE_CONFIGURATION_POLICY = 107, DUMP_CJHEAP_MEMORY_PROCESS = 108, + PROMOTE_TO_STANDBY_MASTER_PROCESS = 109, + DEMOTE_FROM_STANDBY_MASTER_PROCESS = 110, }; } // 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 9473dcfbe3e..ed7643fa7bd 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 @@ -847,6 +847,21 @@ public: * @return Returns ERR_OK on success, others on failure. */ int32_t LaunchAbility(sptr token) override; + + /** + * Elevate the current process to be a standby master process. + * + * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @return Return ERR_OK if success, others fail. + */ + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) override; + + /** + * Revoke current process as a standby master process. + * + * @return Return ERR_OK if success, others fail. + */ + int32_t DemoteFromStandbyMasterProcess() override; private: bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); 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 ca9c4a8c4c2..d9ea33e9f5f 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 @@ -197,6 +197,8 @@ private: int32_t HandleUpdateProcessMemoryState(MessageParcel &data, MessageParcel &reply); int32_t HandleGetKilledProcessInfo(MessageParcel &data, MessageParcel &reply); int32_t HandleLaunchAbility(MessageParcel &data, MessageParcel &reply); + int32_t HandlePromoteToStandbyMasterProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandleDemoteFromStandbyMasterProcess(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(AppMgrStub); }; } // namespace AppExecFwk 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 03b60f74585..f3cf4835088 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 @@ -1592,5 +1592,30 @@ AppMgrResultCode AppMgrClient::IsAppRunningByBundleNameAndUserId(const std::stri } return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } + +int32_t AppMgrClient::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + TAG_LOGI(AAFwkTag::APPMGR, "Called"); + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + return service->PromoteToStandbyMasterProcess(isInsertToHead); +} + +int32_t AppMgrClient::DemoteFromStandbyMasterProcess() +{ + TAG_LOGI(AAFwkTag::APPMGR, "Called"); + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + return service->DemoteFromStandbyMasterProcess(); +} + + + } // 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 8464da2409b..35ccc3446fc 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 @@ -2424,5 +2424,38 @@ int32_t AppMgrProxy::LaunchAbility(sptr token) PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::LAUNCH_ABILITY, data, reply, option); return reply.ReadInt32(); } + +int32_t AppMgrProxy::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + MessageParcel data; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return ERR_INVALID_DATA; + } + PARCEL_UTIL_WRITE_RET_INT(data, Bool, isInsertToHead); + + MessageParcel reply; + MessageOption option; + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PROMOTE_TO_STANDBY_MASTER_PROCESS, data, reply, option); + return reply.ReadInt32(); +} + +int32_t AppMgrProxy::DemoteFromStandbyMasterProcess() +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return ERR_INVALID_DATA; + } + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::DEMOTE_FROM_STANDBY_MASTER_PROCESS, data, reply, option); + return reply.ReadInt32(); +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 262597ebb03..b33078409d2 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 @@ -400,6 +400,10 @@ int32_t AppMgrStub::OnRemoteRequestInnerEighth(uint32_t code, MessageParcel &dat return HandleLaunchAbility(data, reply); case static_cast(AppMgrInterfaceCode::UPDATE_CONFIGURATION_POLICY): return HandleUpdateConfigurationForBackgroundApp(data, reply); + case static_cast(AppMgrInterfaceCode::PROMOTE_TO_STANDBY_MASTER_PROCESS): + return HandlePromoteToStandbyMasterProcess(data, reply); + case static_cast(AppMgrInterfaceCode::DEMOTE_FROM_STANDBY_MASTER_PROCESS): + return HandleDemoteFromStandbyMasterProcess(data, reply); } return INVALID_FD; } @@ -2010,5 +2014,30 @@ int32_t AppMgrStub::HandleLaunchAbility(MessageParcel &data, MessageParcel &repl } return NO_ERROR; } + +int32_t AppMgrStub::HandlePromoteToStandbyMasterProcess(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + bool isInsertToHead = data.ReadBool(); + auto ret = PromoteToStandbyMasterProcess(isInsertToHead); + if (!reply.WriteInt32(ret)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write ret error."); + return IPC_STUB_ERR; + } + return NO_ERROR; +} + +int32_t AppMgrStub::HandleDemoteFromStandbyMasterProcess(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + int32_t ret = DemoteFromStandbyMasterProcess(); + if (!reply.WriteInt32(ret)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write ret error."); + return IPC_STUB_ERR; + } + + return NO_ERROR; +} + } // namespace AppExecFwk } // namespace OHOS 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 ba4b4085a44..f4501bad07b 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -163,6 +163,8 @@ public: static const size_t CONTEXT_TYPE_ID; std::string GetDataDir(); + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + int32_t DemoteFromStandbyMasterProcess(); protected: bool IsContext(size_t contextTypeId) override { 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 5e82b637987..99dcff68ba4 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -420,6 +420,21 @@ public: */ std::shared_ptr CreateAreaModeContext(int areaMode) override; + /** + * Elevate the current process to be a standby master process. + * + * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @return Return ERR_OK if success, others fail. + */ + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + + /** + * Revoke current process as a standby master process. + * + * @return Return ERR_OK if success, others fail. + */ + int32_t DemoteFromStandbyMasterProcess(); + #ifdef SUPPORT_GRAPHICS /** * @brief Create a context by displayId. This Context updates the density and direction properties @@ -527,6 +542,7 @@ private: void ShallowCopySelf(std::shared_ptr &contextImpl); bool UpdateDisplayConfiguration(std::shared_ptr &contextImpl, uint64_t displayId, float density, std::string direction); + #ifdef SUPPORT_GRAPHICS bool GetDisplayConfig(uint64_t displayId, float &density, std::string &directionStr); #endif 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 25e79d04b18..799c4c3ca85 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 @@ -53,6 +53,11 @@ public: static napi_value CancelAutoStartup(napi_env env, napi_callback_info info); static napi_value IsAutoStartup(napi_env env, napi_callback_info info); + static napi_value PromoteToStandbyMasterProcess(napi_env env, napi_callback_info info); + napi_value OnPromoteToStandbyMasterProcess(napi_env env, NapiCallbackInfo& info); + static napi_value DemoteFromStandbyMasterProcess(napi_env env, napi_callback_info info); + napi_value OnDemoteFromStandbyMasterProcess(napi_env env, NapiCallbackInfo& info); + napi_value OnRegisterAbilityLifecycleCallback(napi_env env, NapiCallbackInfo& info); napi_value OnUnregisterAbilityLifecycleCallback(napi_env env, NapiCallbackInfo& info); @@ -96,6 +101,8 @@ public: 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); static napi_value GetTempDir(napi_env env, napi_callback_info info); static napi_value GetResourceDir(napi_env env, napi_callback_info info); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 2777380081b..cbc46dda45a 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -791,6 +791,21 @@ public: int32_t SetProcessCacheEnable(int32_t pid, bool enable) override; + /** + * Elevate the current process to be a standby master process. + * + * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @return Return ERR_OK if success, others fail. + */ + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) override; + + /** + * Revoke current process as a standby master process. + * + * @return Return ERR_OK if success, others fail. + */ + int32_t DemoteFromStandbyMasterProcess() override; + /** * set browser channel for caller */ diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 43ea4ea946a..f806ecc06d9 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1297,6 +1297,21 @@ public: virtual int32_t UnregisterNativeChildExitNotify(const sptr &callback); + /** + * Elevate the current process to be a standby master process. + * + * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @return Return ERR_OK if success, others fail. + */ + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + + /** + * Revoke current process as a standby master process. + * + * @return Return ERR_OK if success, others fail. + */ + int32_t DemoteFromStandbyMasterProcess(); + /** * To clear the process by ability token. * diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 128af80f880..56b7f7a1371 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -102,6 +102,18 @@ public: bool CheckAppRunningRecordIsExist(const std::string &bundleName, const std::string &abilityName); #endif + /** + * CheckMasterProcessAppRunningRecordIsExist, Get master process record by application name and ability information. + * + * @param appName, the application name. + * @param abilityInfo, the ability information. + * @param uid, the process uid. + * + * @return process record. + */ + std::shared_ptr CheckMasterProcessAppRunningRecordIsExist(const std::string &appName, + const AppExecFwk::AbilityInfo &abilityInfo, const int uid); + /** * Check whether the process of the application exists. * diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 15ced140771..77f0c47535b 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -1098,6 +1098,26 @@ public: std::optional IsSupportMultiProcessDeviceFeature() const; void SetSupportMultiProcessDeviceFeature(bool support); + inline void SetMasterProcess(bool isMasterProcess) + { + isMasterProcess_ = isMasterProcess; + } + + inline bool GetIsMasterProcess() const + { + return isMasterProcess_; + } + + inline void SetTimeStamp(int64_t timeStamp) + { + timeStamp_ = timeStamp; + } + + inline int64_t GetTimeStamp() const + { + return timeStamp_; + } + private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. @@ -1278,6 +1298,9 @@ private: std::shared_ptr startupTaskData_ = nullptr; ffrt::mutex startupTaskDataLock_; mutable ffrt::mutex killReasonLock_; + + bool isMasterProcess_ = false; // Only MasterProcess can be keepalive + int64_t timeStamp_ = 0; // the flag of BackUpMainControlProcess }; } // namespace AppExecFwk diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index b4b8c50a408..53e7de69a56 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1904,5 +1904,25 @@ int32_t AppMgrService::LaunchAbility(sptr token) } return appMgrServiceInner_->LaunchAbility(token); } + +int32_t AppMgrService::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + TAG_LOGI(AAFwkTag::APPMGR, "call"); + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "not ready"); + return ERR_INVALID_OPERATION; + } + return appMgrServiceInner_->PromoteToStandbyMasterProcess(isInsertToHead); +} + +int32_t AppMgrService::DemoteFromStandbyMasterProcess() +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + if (!appMgrServiceInner_) { + TAG_LOGE(AAFwkTag::APPMGR, "not ready"); + return ERR_INVALID_VALUE; + } + return appMgrServiceInner_->DemoteFromStandbyMasterProcess(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 90206fe1dff..dae16578be0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -463,7 +463,8 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap std::string processName; auto abilityInfoPtr = std::make_shared(abilityInfo); - MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName, false); + std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want); + MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag , processName, false); TAG_LOGD(AAFwkTag::APPMGR, "processName = %{public}s", processName.c_str()); auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); std::string customProcessFlag = ""; @@ -472,23 +473,23 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap } else { customProcessFlag = abilityInfo.process; } - auto mainAppRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, - bundleInfo, "", nullptr, instanceKey, customProcessFlag); - if (mainAppRecord != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "main process exists."); - mainAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); - auto moduleRecord = mainAppRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); + auto masterAppRecord = appRunningManager_->CheckMasterProcessAppRunningRecordIsExist(appInfo->name, abilityInfo, + appInfo->uid); + if (masterAppRecord != nullptr) { + TAG_LOGI(AAFwkTag::APPMGR, "master process exists."); + masterAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); + auto moduleRecord = masterAppRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); if (!moduleRecord) { TAG_LOGI(AAFwkTag::APPMGR, "module record is nullptr, add modules"); std::vector hapModules = { hapModuleInfo }; - mainAppRecord->AddModules(appInfo, hapModules); - if (mainAppRecord->GetApplicationClient() != nullptr) { - mainAppRecord->AddAbilityStageBySpecifiedProcess(appInfo->bundleName); + masterAppRecord->AddModules(appInfo, hapModules); + if (masterAppRecord->GetApplicationClient() != nullptr) { + masterAppRecord->AddAbilityStageBySpecifiedProcess(appInfo->bundleName); } return; } TAG_LOGD(AAFwkTag::APPMGR, "schedule new process request."); - mainAppRecord->ScheduleNewProcessRequest(want, hapModuleInfo.moduleName); + masterAppRecord->ScheduleNewProcessRequest(want, hapModuleInfo.moduleName); return; } std::shared_ptr appRecord = nullptr; @@ -511,6 +512,7 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap TAG_LOGE(AAFwkTag::APPMGR, "create new appRecord failed"); return; } + newAppRecord->SetMasterProcess(true); newAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); bool appExistFlag = appRunningManager_->IsAppExist(bundleInfo.applicationInfo.accessTokenId); auto ret = StartProcess(abilityInfo.applicationName, processName, 0, newAppRecord, @@ -1134,6 +1136,10 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptrIsMainProcess()){ + appRecord->SetMasterProcess(true); + } + uint32_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo); int32_t bundleIndex = 0; if (want != nullptr) { @@ -10074,5 +10080,48 @@ bool AppMgrServiceInner::WrapBindInfo(std::shared_ptr &want, std::s bindInfo.processType = appRecord->GetProcessType(); return true; } + +int32_t AppMgrServiceInner::PromoteToStandbyMasterProcess(bool isInsertToHead) +{ + TAG_LOGI(AAFwkTag::APPMGR, "call"); + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (!appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); + return ERR_NO_INIT; + } + + auto callerPid = IPCSkeleton::GetCallingPid(); + auto appRecord = GetAppRunningRecordByPid(callerPid); + if (!appRecord) { + TAG_LOGE(AAFwkTag::APPMGR, "no appRecord, callerPid:%{public}d", callerPid); + return ERR_INVALID_VALUE; + } + + auto now = std::chrono::steady_clock::now().time_since_epoch(); + int64_t timeStamp = std::chrono::duration_cast(now).count(); + if(!isInsertToHead){ + timeStamp = -timeStamp; + } + appRecord->SetTimeStamp(timeStamp); + return ERR_OK; +} + +int32_t AppMgrServiceInner::DemoteFromStandbyMasterProcess() +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + int32_t pid = IPCSkeleton::GetCallingPid(); + auto appRecord = GetAppRunningRecordByPid(pid); + if (appRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "no appRecord"); + return ERR_INVALID_VALUE; + } + if(!appRecord->GetIsMasterProcess()){ + int64_t timeStamp = 0; + appRecord->SetTimeStamp(timeStamp); + } + + return ERR_OK; +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 3e7319ad46d..5dbaa0681f5 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -255,6 +255,45 @@ bool AppRunningManager::CheckAppRunningRecordIsExist(const std::string &bundleNa } #endif +std::shared_ptr AppRunningManager::CheckMasterProcessAppRunningRecordIsExist(const std::string &appName, + const AppExecFwk::AbilityInfo &abilityInfo, const int uid) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPMGR, "uid: %{public}d: appName: %{public}s", uid, appName.c_str()); + auto appRunningMap = GetAppRunningRecordMap(); + int64_t maxTimeStamp = INT64_MIN; + std::shared_ptr maxAppRecord = nullptr; + bool isUIAbility = (abilityInfo.type == AppExecFwk::AbilityType::PAGE); + bool isUIExtension = (abilityInfo.type == AppExecFwk::AbilityType::EXTENSION && + abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::UI); + for(const auto &item : appRunningMap){ + const auto &appRecord = item.second; + if(appRecord && appRecord->GetUid() == uid && appRecord->GetIsMasterProcess() && + ((appRecord->GetProcessType() == ProcessType::NORMAL && isUIAbility) || + (appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::UI && isUIExtension)) + ){ + return appRecord; + } + + if(appRecord && appRecord->GetUid() == uid && + appRecord->GetTimeStamp() !=0 && maxTimeStamp < appRecord->GetTimeStamp() && + ((appRecord->GetProcessType() == ProcessType::NORMAL && isUIAbility) || + (appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::UI && isUIExtension)) + ){ + maxTimeStamp = appRecord->GetTimeStamp(); + maxAppRecord = appRecord; + } + } + + if(maxAppRecord != nullptr){ + maxAppRecord->SetMasterProcess(true); + maxAppRecord->SetTimeStamp(0); + return maxAppRecord; + } + + return nullptr; +} + bool AppRunningManager::IsAppExist(uint32_t accessTokenId) { std::lock_guard guard(runningRecordMapMutex_); diff --git a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h index 1658031a2b4..9af8d1fdded 100644 --- a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h +++ b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h @@ -271,6 +271,15 @@ public: return 0; } + int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) + { + return 0; + } + + int32_t DemoteFromStandbyMasterProcess(){ + return ; + } + int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info) override; -- Gitee From df67a32457e5126e4335770c02403518717ec1b5 Mon Sep 17 00:00:00 2001 From: sty Date: Thu, 19 Jun 2025 10:22:08 +0800 Subject: [PATCH 2/2] mend Change-Id: Ieb3e73dd2280da8ef1759544c827acc13b63e1da Signed-off-by: sty --- .../application_context.js | 8 - frameworks/js/napi/application/BUILD.gn | 1 + .../js/napi/application/js_application.cpp | 86 ++++ .../js/napi/application/js_application.h | 4 + .../ability_business_error.cpp | 13 + .../context/application_context.cpp | 18 - .../ability_runtime/context/context_impl.cpp | 30 -- .../context/js_application_context_utils.cpp | 72 ---- .../include/ability_manager_errors.h | 15 + .../include/appmgr/app_mgr_client.h | 10 +- .../include/appmgr/app_mgr_interface.h | 10 +- .../appmgr/app_mgr_ipc_interface_code.h | 4 +- .../include/appmgr/app_mgr_proxy.h | 12 +- .../app_manager/include/appmgr/app_mgr_stub.h | 4 +- .../app_manager/src/appmgr/app_mgr_client.cpp | 8 +- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 10 +- .../app_manager/src/appmgr/app_mgr_stub.cpp | 16 +- .../ability_business_error.h | 6 + .../context/application_context.h | 2 - .../ability_runtime/context/context_impl.h | 16 - .../context/js_application_context_utils.h | 7 - services/appmgr/include/app_mgr_service.h | 10 +- .../appmgr/include/app_mgr_service_inner.h | 10 +- services/appmgr/include/app_running_manager.h | 7 +- services/appmgr/src/app_mgr_service.cpp | 16 +- services/appmgr/src/app_mgr_service_inner.cpp | 82 +++- services/appmgr/src/app_running_manager.cpp | 77 +++- .../BUILD.gn | 1 + .../app_mgr_service_inner_eighth_test.cpp | 74 ++++ .../mock/include/mock_app_utils.h | 396 ++++++++++++++++++ .../mock/include/mock_my_status.h | 1 + .../mock/src/mock_app_running_record.cpp | 14 + .../mock/src/mock_app_utils.cpp | 233 +++++++++++ .../include/mock_app_mgr_service.h | 9 - 34 files changed, 1029 insertions(+), 253 deletions(-) create mode 100644 test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_app_utils.h create mode 100644 test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_utils.cpp diff --git a/frameworks/js/napi/app/application_context/application_context.js b/frameworks/js/napi/app/application_context/application_context.js index 8693ddd10eb..d590b80f4a3 100644 --- a/frameworks/js/napi/app/application_context/application_context.js +++ b/frameworks/js/napi/app/application_context/application_context.js @@ -297,14 +297,6 @@ class ApplicationContext { return this.__context_impl__.createDisplayContext(displayId); } - promoteToStandbyMasterProcess(isInsertToHead) { - return this.__context_impl__.promoteToStandbyMasterProcess(isInsertToHead); - } - - demoteFromStandbyMasterProcess() { - return this.__context_impl__.demoteFromStandbyMasterProcess(); - } - set area(mode) { return this.__context_impl__.switchArea(mode); } diff --git a/frameworks/js/napi/application/BUILD.gn b/frameworks/js/napi/application/BUILD.gn index 6e38f0181c5..08b55e3f018 100644 --- a/frameworks/js/napi/application/BUILD.gn +++ b/frameworks/js/napi/application/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("application_napi") { configs = [ "${ability_runtime_services_path}/common:common_config" ] deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/error_utils:ability_runtime_error_util", "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", "${ability_runtime_innerkits_path}/runtime:runtime", diff --git a/frameworks/js/napi/application/js_application.cpp b/frameworks/js/napi/application/js_application.cpp index bb81f8aa625..11ba9a7a436 100644 --- a/frameworks/js/napi/application/js_application.cpp +++ b/frameworks/js/napi/application/js_application.cpp @@ -17,6 +17,7 @@ #include "ability_runtime_error_util.h" #include "accesstoken_kit.h" +#include "app_mgr_client.h" #include "context_impl.h" #include "hilog_tag_wrapper.h" #include "js_application_context_utils.h" @@ -24,6 +25,7 @@ #include "js_runtime_utils.h" #include "js_context_utils.h" #include "napi_base_context.h" +#include "singleton.h" namespace OHOS { namespace AbilityRuntime { @@ -400,6 +402,83 @@ napi_value JsApplication::CreateJsContext(napi_env env, const std::shared_ptr(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [isInsertToHead, errCode](){ + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Null appMgrClient"); + *errCode = AbilityErrorCode::ERROR_CODE_INNER; + } + *errCode = appMgrClient->PromoteCurrentToCandidateMasterProcess(isInsertToHead); + } + NapiAsyncTask::CompleteCallback complete = [errCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*errCode == ERR_OK) { + TAG_LOGD(AAFwkTag::APPKIT, "promote to standby master process success"); + task.ResolveWithNoError(env, CreateJsUndefined(env)); + return ; + } + task.Reject(env, CreateJsErrorByNativeErr(env, *errCode)); + } + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JsApplication::OnPromoteCurrentToCandidateMasterProcess", + env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result)); + return result; +} + +napi_value JsApplication::DemoteCurrentFromCandidateMasterProcess(napi_env env, napi_callback_info info) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + GET_NAPI_INFO_AND_CALL(env, info, JsApplication, OnDemoteCurrentFromCandidateMasterProcess); +} + +napi_value JsApplication::OnDemoteCurrentFromCandidateMasterProcess(napi_env env, NapiCallbackInfo& info) +{ + auto errCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [isInsertToHead, errCode](){ + auto appMgrClient = DelayedSingleton::GetInstance(); + if (appMgrClient == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Null appMgrClient"); + *errCode = AbilityErrorCode::ERROR_CODE_INNER; + } + *errCode = appMgrClient->DemoteCurrentFromCandidateMasterProcess(); + } + NapiAsyncTask::CompleteCallback complete = [errCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*errCode == ERR_OK) { + TAG_LOGD(AAFwkTag::APPKIT, "demote to standby master process success"); + task.ResolveWithNoError(env, CreateJsUndefined(env)); + return ; + } + task.Reject(env, CreateJsErrorByNativeErr(env, *errCode)); + } + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JsApplication::OnDemoteCurrentFromCandidateMasterProcess", + env, CreateAsyncTaskWithLastParam(env, nullptr, std::move(execute), std::move(complete), &result)); + return result; +} + napi_value ApplicationInit(napi_env env, napi_value exportObj) { TAG_LOGD(AAFwkTag::APPKIT, "Called"); @@ -423,6 +502,13 @@ napi_value ApplicationInit(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "createPluginModuleContext", moduleName, JsApplication::CreatePluginModuleContext); + + BindNativeFunction(env, exportObj, "promoteCurrentToCandidateMasterProcess", moduleName, + JsApplication::PromoteCurrentToCandidateMasterProcess); + + BindNativeFunction(env, exportObj, "demoteCurrentFromCandidateMasterProcess", moduleName, + JsApplication::DemoteCurrentFromCandidateMasterProcess); + return CreateJsUndefined(env); } } // namespace AbilityRuntime diff --git a/frameworks/js/napi/application/js_application.h b/frameworks/js/napi/application/js_application.h index 06785115152..13164547bbf 100644 --- a/frameworks/js/napi/application/js_application.h +++ b/frameworks/js/napi/application/js_application.h @@ -35,6 +35,8 @@ public: static napi_value CreateBundleContext(napi_env env, napi_callback_info info); static napi_value GetApplicationContext(napi_env env, napi_callback_info info); static napi_value CreatePluginModuleContext(napi_env env, napi_callback_info info); + static napi_value PromoteCurrentToCandidateMasterProcess(napi_env env, napi_callback_info info); + static napi_value DemoteCurrentFromCandidateMasterProcess(napi_env env, napi_callback_info info); private: napi_value OnCreateModuleContext(napi_env env, NapiCallbackInfo &info); @@ -46,6 +48,8 @@ private: bool CheckCallerIsSystemApp(); bool CheckCallerPermission(const std::string &permission); napi_value OnGetApplicationContext(napi_env env, NapiCallbackInfo &info); + napi_value OnPromoteCurrentToCandidateMasterProcess(napi_env env, NapiCallbackInfo& info); + napi_value OnDemoteCurrentFromCandidateMasterProcess(napi_env env, NapiCallbackInfo& info); }; napi_value ApplicationInit(napi_env env, napi_value exportObj); 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 96355dcd6c5..2cca9a6cdcc 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 @@ -124,6 +124,13 @@ constexpr const char* ERROR_MSG_NOT_IN_KIOSK_MODE = "The current application is not in the kiosk mode. Exit is not allowed."; constexpr const char* ERROR_MSG_APP_NOT_IN_FOCUS = "The current ability is not foreground."; +constexpr const char* ERROR_MSG_NOT_ISOLATION_PROCESS = "Current process is not running a component configured " + "with \"isolationProcess\", and cannot be set as a candidate master process."; +constexpr const char* ERROR_MSG_ALREADY_MASTER_PROCESS = + "Current process is already a master process, revocation is not supported."; +constexpr const char* ERROR_MSG_NOT_CANDIDATE_MASTER_PROCESS = + "Current process is not a candidate master process, no need to revocation."; + // follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220; @@ -214,6 +221,9 @@ static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_CODE_ALREADY_IN_KIOSK_MODE, ERROR_MSG_ALREADY_IN_KIOSK_MODE}, { AbilityErrorCode::ERROR_CODE_NOT_IN_KIOSK_MODE, ERROR_MSG_NOT_IN_KIOSK_MODE}, { AbilityErrorCode::ERROR_CODE_APP_NOT_IN_FOCUS, ERROR_MSG_APP_NOT_IN_FOCUS}, + { AbilityErrorCode::ERROR_CODE_NOT_ISOLATION_PROCESS, ERROR_MSG_NOT_ISOLATION_PROCESS}, + { AbilityErrorCode::ERROR_CODE_ALREADY_MASTER_PROCESS, ERROR_MSG_ALREADY_MASTER_PROCESS}, + { AbilityErrorCode::ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS, ERROR_MSG_NOT_CANDIDATE_MASTER_PROCESS }, }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -307,6 +317,9 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP {ERR_ALREADY_IN_KIOSK_MODE, AbilityErrorCode::ERROR_CODE_ALREADY_IN_KIOSK_MODE}, {ERR_NOT_IN_KIOSK_MODE, AbilityErrorCode::ERROR_CODE_NOT_IN_KIOSK_MODE}, {ERR_APP_NOT_IN_FOCUS, AbilityErrorCode::ERROR_CODE_APP_NOT_IN_FOCUS}, + {ERR_NOT_ISOLATION_PROCESS, AbilityErrorCode::ERROR_CODE_NOT_ISOLATION_PROCESS}, + {ERR_ALREADY_MASTER_PROCESS, AbilityErrorCode::ERROR_CODE_ALREADY_MASTER_PROCESS}, + {ERR_NOT_CANDIDATE_MASTER_PROCESS, AbilityErrorCode::ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS}, }; } diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 9a87426cb39..540797bc0c3 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -923,24 +923,6 @@ std::shared_ptr ApplicationContext::CreateAreaModeContext(int areaMode) return contextImpl_ ? contextImpl_->CreateAreaModeContext(areaMode) : nullptr; } -int32_t ApplicationContext::PromoteToStandbyMasterProcess(bool isInsertToHead) -{ - if (contextImpl_ != nullptr) { - return contextImpl_->PromoteToStandbyMasterProcess(isInsertToHead); - } - TAG_LOGE(AAFwkTag::APPKIT, "null contextImpl_"); - return ERR_INVALID_VALUE; -} - -int32_t ApplicationContext::DemoteFromStandbyMasterProcess() -{ - if (contextImpl_ != nullptr) { - return contextImpl_->DemoteFromStandbyMasterProcess(); - } - TAG_LOGE(AAFwkTag::APPKIT, "null contextImpl_"); - return ERR_INVALID_VALUE; -} - #ifdef SUPPORT_GRAPHICS std::shared_ptr ApplicationContext::CreateDisplayContext(uint64_t displayId) { diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index db45072178d..cab45fda83e 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -1741,36 +1741,6 @@ bool ContextImpl::UpdateDisplayConfiguration(std::shared_ptr &conte return true; } - -int64_t GetSteadyNanoSeconds() { - auto now = std::chrono::steady_clock::now().time_since_epoch(); - return std::chrono::duration_cast(now).count(); -} - -int32_t ContextImpl::PromoteToStandbyMasterProcess(bool isInsertToHead) -{ - TAG_LOGD(AAFwkTag::APPKIT, "Called"); - auto appMgrClient = DelayedSingleton::GetInstance(); - if (appMgrClient == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null appMgrClient"); - return ERR_INVALID_VALUE; - } - return appMgrClient->PromoteToStandbyMasterProcess(isInsertToHead); - -} - -int32_t ContextImpl::DemoteFromStandbyMasterProcess() -{ - - TAG_LOGD(AAFwkTag::APPKIT, "Called"); - auto appMgrClient = DelayedSingleton::GetInstance(); - if (appMgrClient == nullptr) { - TAG_LOGE(AAFwkTag::APPKIT, "null appMgrClient"); - return ERR_INVALID_VALUE; - } - return appMgrClient->DemoteFromStandbyMasterProcess(); -} - #ifdef SUPPORT_GRAPHICS std::shared_ptr ContextImpl::CreateDisplayContext(uint64_t displayId) { 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 a1e1f45bda9..c507ba81c46 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 @@ -1804,74 +1804,6 @@ napi_value JsApplicationContextUtils::OnSetSupportedProcessCacheSelf(napi_env en return CreateJsUndefined(env); } -napi_value JsApplicationContextUtils::PromoteToStandbyMasterProcess(napi_env env, napi_callback_info info) -{ - TAG_LOGD(AAFwkTag::APPKIT, "called"); - GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnPromoteToStandbyMasterProcess, APPLICATION_CONTEXT_NAME); -} - -napi_value JsApplicationContextUtils::OnPromoteToStandbyMasterProcess(napi_env env, NapiCallbackInfo& info) -{ - // only support one params - if (info.argc == ARGC_ZERO) { - TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); - ThrowInvalidParamError(env, "Not enough params"); - return CreateJsUndefined(env); - } - auto applicationContext = applicationContext_.lock(); - if (!applicationContext) { - TAG_LOGW(AAFwkTag::APPKIT, "null applicationContext"); - return CreateJsUndefined(env); - } - - bool isInsertToHead = false; - if (!ConvertFromJsValue(env, info.argv[INDEX_ZERO], isInsertToHead)) { - TAG_LOGE(AAFwkTag::APPKIT, "Parse isInsertToHead failed"); - ThrowInvalidParamError(env, - "Parse param isSupport failed, isInsertToHead must be boolean."); - return CreateJsUndefined(env); - } - - auto errCode = applicationContext->PromoteToStandbyMasterProcess(isInsertToHead); - - if (errCode != ERR_OK) { - TAG_LOGE(AAFwkTag::APPKIT, "promote to standby master process failed"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR); - } - TAG_LOGE(AAFwkTag::APPKIT, "errCode:%{public}d.", errCode); - return CreateJsUndefined(env); -} - -napi_value JsApplicationContextUtils::DemoteFromStandbyMasterProcess(napi_env env, napi_callback_info info) -{ - TAG_LOGD(AAFwkTag::APPKIT, "called"); - GET_NAPI_INFO_WITH_NAME_AND_CALL(env, info, JsApplicationContextUtils, OnDemoteFromStandbyMasterProcess, APPLICATION_CONTEXT_NAME); -} - -napi_value JsApplicationContextUtils::OnDemoteFromStandbyMasterProcess(napi_env env, NapiCallbackInfo& info) -{ - // only support 0 params - if (info.argc != ARGC_ZERO) { - TAG_LOGE(AAFwkTag::APPKIT, "Not enough params"); - ThrowInvalidParamError(env, "Not enough params"); - return CreateJsUndefined(env); - } - auto applicationContext = applicationContext_.lock(); - if (!applicationContext) { - TAG_LOGW(AAFwkTag::APPKIT, "null applicationContext"); - return CreateJsUndefined(env); - } - - auto errCode = applicationContext->DemoteFromStandbyMasterProcess(); - - if (errCode != ERR_OK) { - TAG_LOGE(AAFwkTag::APPKIT, "Demote from standby master process failed"); - AbilityRuntimeErrorUtil::Throw(env, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR); - } - TAG_LOGE(AAFwkTag::APPKIT, "errCode:%{public}d.", errCode); - return CreateJsUndefined(env); -} - void JsApplicationContextUtils::BindNativeApplicationContextOne(napi_env env, napi_value object) { BindNativeProperty(env, object, "cacheDir", JsApplicationContextUtils::GetCacheDir); @@ -1935,10 +1867,6 @@ void JsApplicationContextUtils::BindNativeApplicationContextTwo(napi_env env, na JsApplicationContextUtils::SetSupportedProcessCacheSelf); BindNativeFunction(env, object, "setFontSizeScale", MD_NAME, JsApplicationContextUtils::SetFontSizeScale); - BindNativeFunction(env, object, "promoteToStandbyMasterProcess", MD_NAME, - JsApplicationContextUtils::PromoteToStandbyMasterProcess); - BindNativeFunction(env, object, "demoteFromStandbyMasterProcess", MD_NAME, - JsApplicationContextUtils::DemoteFromStandbyMasterProcess); } } // namespace AbilityRuntime } // namespace OHOS 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 87c485af117..f6d481fca9f 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -903,6 +903,21 @@ enum { */ ERR_SA_INTERCEPTOR_READ_PARAMS_FAILED = 2097361, + /* + * Result(2097364) Current process is not running a component configured with "isolationProcess". + */ + ERR_NOT_ISOLATION_PROCESS = 2097364, + + /* + * Result(2097365) Current process is already a master process, revocation is not supported. + */ + ERR_ALREADY_MASTER_PROCESS = 2097365, + + /* + * Result(2097366) Current process is not a candidate master process, no need to revocation. + */ + ERR_NOT_CANDIDATE_MASTER_PROCESS = 2097366, + /** * Native error(3000000) for target bundle not exist. */ 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 d234117e998..a764ccb3358 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 @@ -988,19 +988,19 @@ public: bool &isRunning); /** - * Elevate the current process to be a standby master process. + * Elevate the current process to be a candidate master process. * - * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @param isInsertToHead Whether inset current process to the head of candidate master process list. * @return Return ERR_OK if success, others fail. */ - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + int32_t PromoteCurrentToCandidateMasterProcess(bool isInsertToHead); /** - * Revoke current process as a standby master process. + * Revoke current process as a candidate master process. * * @return Return ERR_OK if success, others fail. */ - int32_t DemoteFromStandbyMasterProcess(); + int32_t DemoteCurrentFromCandidateMasterProcess(); private: void SetServiceManager(std::unique_ptr serviceMgr); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index dfa5010835b..fe712b24851 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 @@ -1002,9 +1002,15 @@ public: return 0; } - virtual int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) = 0; + virtual int32_t PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) + { + return 0; + } - virtual int32_t DemoteFromStandbyMasterProcess() = 0; + virtual int32_t DemoteCurrentFromCandidateMasterProcess() + { + return 0; + } }; } // namespace AppExecFwk } // namespace OHOS 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 a70f180f69d..e11dac6b00e 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 @@ -132,8 +132,8 @@ enum class AppMgrInterfaceCode { UNREGISTER_NATIVE_CHILD_EXIT_NOTIFY = 106, UPDATE_CONFIGURATION_POLICY = 107, DUMP_CJHEAP_MEMORY_PROCESS = 108, - PROMOTE_TO_STANDBY_MASTER_PROCESS = 109, - DEMOTE_FROM_STANDBY_MASTER_PROCESS = 110, + PROMOTE_CURRENT_TO_CANDIDATE_MASTER_PROCESS = 109, + DEMOTE_CURRENT_FROM_CANDIDATE_MASTER_PROCESS = 110, }; } // 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 ed7643fa7bd..b9988bfb9dc 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 @@ -848,20 +848,20 @@ public: */ int32_t LaunchAbility(sptr token) override; - /** - * Elevate the current process to be a standby master process. +/** + * Elevate the current process to be a candidate master process. * - * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @param isInsertToHead Whether inset current process to the head of candidate master process list. * @return Return ERR_OK if success, others fail. */ - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) override; + int32_t PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) override; /** - * Revoke current process as a standby master process. + * Revoke current process as a candidate master process. * * @return Return ERR_OK if success, others fail. */ - int32_t DemoteFromStandbyMasterProcess() override; + int32_t DemoteCurrentFromCandidateMasterProcess() override; private: bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); 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 d9ea33e9f5f..bc71a74bf66 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 @@ -197,8 +197,8 @@ private: int32_t HandleUpdateProcessMemoryState(MessageParcel &data, MessageParcel &reply); int32_t HandleGetKilledProcessInfo(MessageParcel &data, MessageParcel &reply); int32_t HandleLaunchAbility(MessageParcel &data, MessageParcel &reply); - int32_t HandlePromoteToStandbyMasterProcess(MessageParcel &data, MessageParcel &reply); - int32_t HandleDemoteFromStandbyMasterProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandlePromoteCurrentToCandidateMasterProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandleDemoteCurrentFromCandidateMasterProcess(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(AppMgrStub); }; } // namespace AppExecFwk 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 f3cf4835088..bb49f3dad0f 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 @@ -1593,7 +1593,7 @@ AppMgrResultCode AppMgrClient::IsAppRunningByBundleNameAndUserId(const std::stri return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } -int32_t AppMgrClient::PromoteToStandbyMasterProcess(bool isInsertToHead) +int32_t AppMgrClient::PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) { TAG_LOGI(AAFwkTag::APPMGR, "Called"); sptr service = iface_cast(mgrHolder_->GetRemoteObject()); @@ -1601,10 +1601,10 @@ int32_t AppMgrClient::PromoteToStandbyMasterProcess(bool isInsertToHead) TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } - return service->PromoteToStandbyMasterProcess(isInsertToHead); + return service->PromoteCurrentToCandidateMasterProcess(isInsertToHead); } -int32_t AppMgrClient::DemoteFromStandbyMasterProcess() +int32_t AppMgrClient::DemoteCurrentFromCandidateMasterProcess() { TAG_LOGI(AAFwkTag::APPMGR, "Called"); sptr service = iface_cast(mgrHolder_->GetRemoteObject()); @@ -1612,7 +1612,7 @@ int32_t AppMgrClient::DemoteFromStandbyMasterProcess() TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } - return service->DemoteFromStandbyMasterProcess(); + return service->DemoteCurrentFromCandidateMasterProcess(); } 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 35ccc3446fc..60e5b97817f 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 @@ -2425,7 +2425,7 @@ int32_t AppMgrProxy::LaunchAbility(sptr token) return reply.ReadInt32(); } -int32_t AppMgrProxy::PromoteToStandbyMasterProcess(bool isInsertToHead) +int32_t AppMgrProxy::PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) { TAG_LOGD(AAFwkTag::APPMGR, "called"); MessageParcel data; @@ -2436,13 +2436,13 @@ int32_t AppMgrProxy::PromoteToStandbyMasterProcess(bool isInsertToHead) PARCEL_UTIL_WRITE_RET_INT(data, Bool, isInsertToHead); MessageParcel reply; - MessageOption option; + MessageOption option; - PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PROMOTE_TO_STANDBY_MASTER_PROCESS, data, reply, option); + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PROMOTE_CURRENT_TO_CANDIDATE_MASTER_PROCESS, data, reply, option); return reply.ReadInt32(); } -int32_t AppMgrProxy::DemoteFromStandbyMasterProcess() +int32_t AppMgrProxy::DemoteCurrentFromCandidateMasterProcess() { TAG_LOGD(AAFwkTag::APPMGR, "called"); MessageParcel data; @@ -2453,7 +2453,7 @@ int32_t AppMgrProxy::DemoteFromStandbyMasterProcess() return ERR_INVALID_DATA; } - PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::DEMOTE_FROM_STANDBY_MASTER_PROCESS, data, reply, option); + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::DEMOTE_CURRENT_FROM_CANDIDATE_MASTER_PROCESS, data, reply, option); return reply.ReadInt32(); } 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 b33078409d2..7e29aaca058 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 @@ -400,10 +400,10 @@ int32_t AppMgrStub::OnRemoteRequestInnerEighth(uint32_t code, MessageParcel &dat return HandleLaunchAbility(data, reply); case static_cast(AppMgrInterfaceCode::UPDATE_CONFIGURATION_POLICY): return HandleUpdateConfigurationForBackgroundApp(data, reply); - case static_cast(AppMgrInterfaceCode::PROMOTE_TO_STANDBY_MASTER_PROCESS): - return HandlePromoteToStandbyMasterProcess(data, reply); - case static_cast(AppMgrInterfaceCode::DEMOTE_FROM_STANDBY_MASTER_PROCESS): - return HandleDemoteFromStandbyMasterProcess(data, reply); + case static_cast(AppMgrInterfaceCode::PROMOTE_CURRENT_TO_CANDIDATE_MASTER_PROCESS): + return HandlePromoteCurrentToCandidateMasterProcess(data, reply); + case static_cast(AppMgrInterfaceCode::DEMOTE_CURRENT_FROM_CANDIDATE_MASTER_PROCESS): + return HandleDemoteCurrentFromCandidateMasterProcess(data, reply); } return INVALID_FD; } @@ -2015,11 +2015,11 @@ int32_t AppMgrStub::HandleLaunchAbility(MessageParcel &data, MessageParcel &repl return NO_ERROR; } -int32_t AppMgrStub::HandlePromoteToStandbyMasterProcess(MessageParcel &data, MessageParcel &reply) +int32_t AppMgrStub::HandlePromoteCurrentToCandidateMasterProcess(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::APPMGR, "called"); bool isInsertToHead = data.ReadBool(); - auto ret = PromoteToStandbyMasterProcess(isInsertToHead); + auto ret = PromoteCurrentToCandidateMasterProcess(isInsertToHead); if (!reply.WriteInt32(ret)) { TAG_LOGE(AAFwkTag::APPMGR, "Write ret error."); return IPC_STUB_ERR; @@ -2027,10 +2027,10 @@ int32_t AppMgrStub::HandlePromoteToStandbyMasterProcess(MessageParcel &data, Mes return NO_ERROR; } -int32_t AppMgrStub::HandleDemoteFromStandbyMasterProcess(MessageParcel &data, MessageParcel &reply) +int32_t AppMgrStub::HandleDemoteCurrentFromCandidateMasterProcess(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::APPMGR, "call"); - int32_t ret = DemoteFromStandbyMasterProcess(); + int32_t ret = DemoteCurrentFromCandidateMasterProcess(); if (!reply.WriteInt32(ret)) { TAG_LOGE(AAFwkTag::APPMGR, "Write ret error."); return IPC_STUB_ERR; 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 ef04055073d..4db6cf767e6 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 @@ -261,6 +261,12 @@ enum class AbilityErrorCode { ERROR_CODE_NOT_IN_KIOSK_MODE = 16000112, ERROR_CODE_APP_NOT_IN_FOCUS = 16000113, + + ERROR_CODE_NOT_ISOLATION_PROCESS = 16000115, + + ERROR_CODE_ALREADY_MASTER_PROCESS = 16000116, + + ERROR_CODE_NOT_CANDIDATE_MASTER_PROCESS = 16000117, // target bundle is not in u1 ERROR_CODE_NO_U1 = 16000204, 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 f4501bad07b..ba4b4085a44 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -163,8 +163,6 @@ public: static const size_t CONTEXT_TYPE_ID; std::string GetDataDir(); - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); - int32_t DemoteFromStandbyMasterProcess(); protected: bool IsContext(size_t contextTypeId) override { 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 99dcff68ba4..5e82b637987 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -420,21 +420,6 @@ public: */ std::shared_ptr CreateAreaModeContext(int areaMode) override; - /** - * Elevate the current process to be a standby master process. - * - * @param isInsertToHead Whether inset current process to the head of standby master process list. - * @return Return ERR_OK if success, others fail. - */ - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); - - /** - * Revoke current process as a standby master process. - * - * @return Return ERR_OK if success, others fail. - */ - int32_t DemoteFromStandbyMasterProcess(); - #ifdef SUPPORT_GRAPHICS /** * @brief Create a context by displayId. This Context updates the density and direction properties @@ -542,7 +527,6 @@ private: void ShallowCopySelf(std::shared_ptr &contextImpl); bool UpdateDisplayConfiguration(std::shared_ptr &contextImpl, uint64_t displayId, float density, std::string direction); - #ifdef SUPPORT_GRAPHICS bool GetDisplayConfig(uint64_t displayId, float &density, std::string &directionStr); #endif 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 799c4c3ca85..25e79d04b18 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 @@ -53,11 +53,6 @@ public: static napi_value CancelAutoStartup(napi_env env, napi_callback_info info); static napi_value IsAutoStartup(napi_env env, napi_callback_info info); - static napi_value PromoteToStandbyMasterProcess(napi_env env, napi_callback_info info); - napi_value OnPromoteToStandbyMasterProcess(napi_env env, NapiCallbackInfo& info); - static napi_value DemoteFromStandbyMasterProcess(napi_env env, napi_callback_info info); - napi_value OnDemoteFromStandbyMasterProcess(napi_env env, NapiCallbackInfo& info); - napi_value OnRegisterAbilityLifecycleCallback(napi_env env, NapiCallbackInfo& info); napi_value OnUnregisterAbilityLifecycleCallback(napi_env env, NapiCallbackInfo& info); @@ -101,8 +96,6 @@ public: 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); static napi_value GetTempDir(napi_env env, napi_callback_info info); static napi_value GetResourceDir(napi_env env, napi_callback_info info); diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index cbc46dda45a..d787e0bee26 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -792,19 +792,19 @@ public: int32_t SetProcessCacheEnable(int32_t pid, bool enable) override; /** - * Elevate the current process to be a standby master process. + * Elevate the current process to be a candidate master process. * - * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @param isInsertToHead Whether inset current process to the head of candidate master process list. * @return Return ERR_OK if success, others fail. */ - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) override; + int32_t PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) override; /** - * Revoke current process as a standby master process. + * Revoke current process as a candidate master process. * * @return Return ERR_OK if success, others fail. */ - int32_t DemoteFromStandbyMasterProcess() override; + int32_t DemoteCurrentFromCandidateMasterProcess() override; /** * set browser channel for caller diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index f806ecc06d9..f49c65482a0 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1298,19 +1298,19 @@ public: virtual int32_t UnregisterNativeChildExitNotify(const sptr &callback); /** - * Elevate the current process to be a standby master process. + * Elevate the current process to be a candidate master process. * - * @param isInsertToHead Whether inset current process to the head of standby master process list. + * @param isInsertToHead Whether inset current process to the head of candidate master process list. * @return Return ERR_OK if success, others fail. */ - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead); + int32_t PromoteCurrentToCandidateMasterProcess(bool isInsertToHead); /** - * Revoke current process as a standby master process. + * Revoke current process as a candidate master process. * * @return Return ERR_OK if success, others fail. */ - int32_t DemoteFromStandbyMasterProcess(); + int32_t DemoteCurrentFromCandidateMasterProcess(); /** * To clear the process by ability token. diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 56b7f7a1371..4ed1444c118 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -111,7 +111,10 @@ public: * * @return process record. */ - std::shared_ptr CheckMasterProcessAppRunningRecordIsExist(const std::string &appName, + std::shared_ptr FindMasterProcessAppRunningRecord(const std::string &appName, + const AppExecFwk::AbilityInfo &abilityInfo, const int uid); + + bool CheckMasterProcessAppRunningRecordIsExist(const std::string &appName, const AppExecFwk::AbilityInfo &abilityInfo, const int uid); /** @@ -450,6 +453,8 @@ private: void RemoveTimeoutDeadAppRecord(); void ExecuteConfigurationTask(const BackgroundAppInfo& info, const int32_t userId); bool UpdateConfiguration(std::shared_ptr &appRecord, Rosen::ConfigMode configMode); + bool IsSameAbilityType( + const std::shared_ptr &appRecord, const AppExecFwk::AbilityInfo &abilityInfo); private: std::mutex runningRecordMapMutex_; std::map> appRunningRecordMap_; diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 53e7de69a56..43d3c630963 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1905,24 +1905,24 @@ int32_t AppMgrService::LaunchAbility(sptr token) return appMgrServiceInner_->LaunchAbility(token); } -int32_t AppMgrService::PromoteToStandbyMasterProcess(bool isInsertToHead) +int32_t AppMgrService::PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) { - TAG_LOGI(AAFwkTag::APPMGR, "call"); + TAG_LOGD(AAFwkTag::APPMGR, "call"); if (!IsReady()) { TAG_LOGE(AAFwkTag::APPMGR, "not ready"); - return ERR_INVALID_OPERATION; + return AAFwk::ERR_NULL_APP_MGR_SERVICE_INNER; } - return appMgrServiceInner_->PromoteToStandbyMasterProcess(isInsertToHead); + return appMgrServiceInner_->PromoteCurrentToCandidateMasterProcess(isInsertToHead); } -int32_t AppMgrService::DemoteFromStandbyMasterProcess() +int32_t AppMgrService::DemoteCurrentFromCandidateMasterProcess() { TAG_LOGD(AAFwkTag::APPMGR, "called"); - if (!appMgrServiceInner_) { + if (!IsReady()) { TAG_LOGE(AAFwkTag::APPMGR, "not ready"); - return ERR_INVALID_VALUE; + return AAFwk::ERR_NULL_APP_MGR_SERVICE_INNER; } - return appMgrServiceInner_->DemoteFromStandbyMasterProcess(); + return appMgrServiceInner_->DemoteCurrentFromCandidateMasterProcess(); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index dae16578be0..d8821a1d2e6 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -463,20 +463,27 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap std::string processName; auto abilityInfoPtr = std::make_shared(abilityInfo); - std::string specifiedProcessFlag = GetSpecifiedProcessFlag(abilityInfo, want); - MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag , processName, false); + MakeProcessName(abilityInfoPtr, appInfo, hapModuleInfo, appIndex, "", processName, false); TAG_LOGD(AAFwkTag::APPMGR, "processName = %{public}s", processName.c_str()); auto instanceKey = want.GetStringParam(Want::APP_INSTANCE_KEY); + auto customProcessFlag = abilityInfo.process; + auto masterAppRecord = appRunningManager_->FindMasterProcessAppRunningRecord(appInfo->name, abilityInfo, + appInfo->uid); std::string customProcessFlag = ""; - if (AAFwk::UIExtensionUtils::IsUIExtension(abilityInfo.extensionAbilityType)) { - customProcessFlag = customProcess; - } else { - customProcessFlag = abilityInfo.process; + if (masterAppRecord == nullptr) { + if (AAFwk::UIExtensionUtils::IsUIExtension(abilityInfo.extensionAbilityType)) { + customProcessFlag = customProcess; + } else { + customProcessFlag = abilityInfo.process; + } + masterAppRecord = appRunningManager_->CheckAppRunningRecordIsExist(appInfo->name, processName, appInfo->uid, + bundleInfo, "", nullptr, instanceKey, customProcessFlag); + if(masterAppRecord != nullptr){ + masterAppRecord->SetMasterProcess(true); + } } - auto masterAppRecord = appRunningManager_->CheckMasterProcessAppRunningRecordIsExist(appInfo->name, abilityInfo, - appInfo->uid); if (masterAppRecord != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "master process exists."); + TAG_LOGI(AAFwkTag::APPMGR, "master process exists: %{public}s.", masterAppRecord->GetProcessName().c_str()); masterAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); auto moduleRecord = masterAppRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName); if (!moduleRecord) { @@ -857,6 +864,15 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s } appRecord = CreateAppRunningRecord(loadParam, appInfo, abilityInfo, processName, bundleInfo, hapModuleInfo, want, isKia); + + if (abilityInfo->isolationProcess) { + bool isMasterProcessExist = appRunningManager_->CheckMasterProcessAppRunningRecordIsExist( + appInfo->name, *abilityInfo, appInfo->uid); + if (!isMasterProcessExist) { + appRecord->SetMasterProcess(true); + } + } + if (appRecord != nullptr) { appRecord->SetExtensionSandBoxFlag(isExtensionSandBox); } @@ -1135,11 +1151,6 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptrSetMainProcess(false); TAG_LOGI(AAFwkTag::APPMGR, "%{public}s will not alive", hapModuleInfo.process.c_str()); } - - if(appRecord->IsMainProcess()){ - appRecord->SetMasterProcess(true); - } - uint32_t startFlags = (want == nullptr) ? 0 : AppspawnUtil::BuildStartFlags(*want, *abilityInfo); int32_t bundleIndex = 0; if (want != nullptr) { @@ -10081,20 +10092,33 @@ bool AppMgrServiceInner::WrapBindInfo(std::shared_ptr &want, std::s return true; } -int32_t AppMgrServiceInner::PromoteToStandbyMasterProcess(bool isInsertToHead) +int32_t AppMgrServiceInner::PromoteCurrentToCandidateMasterProcess(bool isInsertToHead) { TAG_LOGI(AAFwkTag::APPMGR, "call"); HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (!appRunningManager_) { TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ null"); - return ERR_NO_INIT; + return AAFwk::ERR_NOT_ISOLATION_PROCESS; } auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "no appRecord, callerPid:%{public}d", callerPid); - return ERR_INVALID_VALUE; + return AAFwk::ERR_NOT_ISOLATION_PROCESS; + } + + if (!AAFwk::AppUtils::GetInstance().IsStartSpecifiedProcess()) { + TAG_LOGE(AAFwkTag::APPMGR, "Capability not support"); + return AAFwk::ERR_CAPABILITY_NOT_SUPPORT; + } + + if (appRecord->GetSpecifiedProcessFlag() == "" && + !appRecord->GetIsMasterProcess()) { + TAG_LOGE(AAFwkTag::APPMGR, "Current process is not running a component " + "configured with \"isolationProcess\"."); + return AAFwk::ERR_NOT_ISOLATION_PROCESS; } auto now = std::chrono::steady_clock::now().time_since_epoch(); @@ -10106,19 +10130,33 @@ int32_t AppMgrServiceInner::PromoteToStandbyMasterProcess(bool isInsertToHead) return ERR_OK; } -int32_t AppMgrServiceInner::DemoteFromStandbyMasterProcess() +int32_t AppMgrServiceInner::DemoteCurrentFromCandidateMasterProcess() { TAG_LOGD(AAFwkTag::APPMGR, "call"); int32_t pid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(pid); if (appRecord == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "no appRecord"); - return ERR_INVALID_VALUE; + return AAFwk::ERR_NOT_CANDIDATE_MASTER_PROCESS; } - if(!appRecord->GetIsMasterProcess()){ - int64_t timeStamp = 0; - appRecord->SetTimeStamp(timeStamp); + + if (!AAFwk::AppUtils::GetInstance().IsStartSpecifiedProcess()) { + TAG_LOGE(AAFwkTag::APPMGR, "Capability not support"); + return AAFwk::ERR_CAPABILITY_NOT_SUPPORT; + } + + if (appRecord->GetIsMasterProcess()) { + TAG_LOGE(AAFwkTag::APPMGR, "Current process is already a master process"); + return AAFwk::ERR_ALREADY_MASTER_PROCESS; } + + if (appRecord->GetTimeStamp() == 0) { + TAG_LOGE(AAFwkTag::APPMGR, "Current process is not a candidate master process"); + return AAFwk::ERR_NOT_CANDIDATE_MASTER_PROCESS; + } + + int64_t timeStamp = 0; + appRecord->SetTimeStamp(timeStamp); return ERR_OK; } diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 5dbaa0681f5..a3a46976865 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -255,45 +255,90 @@ bool AppRunningManager::CheckAppRunningRecordIsExist(const std::string &bundleNa } #endif -std::shared_ptr AppRunningManager::CheckMasterProcessAppRunningRecordIsExist(const std::string &appName, - const AppExecFwk::AbilityInfo &abilityInfo, const int uid) +bool AppRunningManager::IsSameAbilityType(const std::shared_ptr &appRecord, + const AppExecFwk::AbilityInfo &abilityInfo) +{ + if (appRecord == nullptr) { + return false; + } + bool isUIAbility = (abilityInfo.type == AppExecFwk::AbilityType::PAGE); + bool isUIExtension = (abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI); + if (((appRecord->GetProcessType() == ProcessType::NORMAL || + appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::SERVICE || + appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::DATASHARE) && isUIAbility)|| + (appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI && isUIExtension)) { + return true; + } + return false; +} + +std::shared_ptr AppRunningManager::FindMasterProcessAppRunningRecord( + const std::string &appName, const AppExecFwk::AbilityInfo &abilityInfo, const int uid) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::APPMGR, "uid: %{public}d: appName: %{public}s", uid, appName.c_str()); auto appRunningMap = GetAppRunningRecordMap(); int64_t maxTimeStamp = INT64_MIN; - std::shared_ptr maxAppRecord = nullptr; + int64_t minAppRecordId = INT32_MAX; + std::shared_ptr maxAppRecord; + std::shared_ptr minAppRecord; bool isUIAbility = (abilityInfo.type == AppExecFwk::AbilityType::PAGE); - bool isUIExtension = (abilityInfo.type == AppExecFwk::AbilityType::EXTENSION && - abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::UI); - for(const auto &item : appRunningMap){ + bool isUIExtension = (abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI); + for (const auto &item : appRunningMap) { const auto &appRecord = item.second; - if(appRecord && appRecord->GetUid() == uid && appRecord->GetIsMasterProcess() && - ((appRecord->GetProcessType() == ProcessType::NORMAL && isUIAbility) || - (appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::UI && isUIExtension)) - ){ + if (!(appRecord && appRecord->GetUid() == uid)) { + continue; + } + + if (appRecord->GetIsMasterProcess() && IsSameAbilityType(appRecord, abilityInfo)) { return appRecord; } - if(appRecord && appRecord->GetUid() == uid && - appRecord->GetTimeStamp() !=0 && maxTimeStamp < appRecord->GetTimeStamp() && - ((appRecord->GetProcessType() == ProcessType::NORMAL && isUIAbility) || - (appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::UI && isUIExtension)) - ){ + if (appRecord->GetTimeStamp() != 0 && maxTimeStamp < appRecord->GetTimeStamp() && + IsSameAbilityType(appRecord, abilityInfo)) { maxTimeStamp = appRecord->GetTimeStamp(); maxAppRecord = appRecord; } + + if ((appRecord->GetExtensionType() == AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI && isUIExtension) && + appRecord->GetRecordId() < minAppRecordId) { + minAppRecordId = appRecord->GetRecordId(); + minAppRecord = appRecord; + } } - if(maxAppRecord != nullptr){ + if (maxAppRecord != nullptr) { maxAppRecord->SetMasterProcess(true); maxAppRecord->SetTimeStamp(0); return maxAppRecord; } + if (minAppRecord != nullptr) { + minAppRecord->SetMasterProcess(true); + return minAppRecord; + } + return nullptr; } +bool AppRunningManager::CheckMasterProcessAppRunningRecordIsExist( + const std::string &appName, const AppExecFwk::AbilityInfo &abilityInfo, const int uid) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::APPMGR, "uid: %{public}d: appName: %{public}s", uid, appName.c_str()); + auto appRunningMap = GetAppRunningRecordMap(); + bool isUIAbility = (abilityInfo.type == AppExecFwk::AbilityType::PAGE); + bool isUIExtension = (abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYS_COMMON_UI); + for (const auto &item : appRunningMap) { + const auto &appRecord = item.second; + if (appRecord && appRecord->GetUid() == uid && appRecord->GetIsMasterProcess() && + IsSameAbilityType(appRecord, abilityInfo)) { + return true; + } + } + return false; +} + bool AppRunningManager::IsAppExist(uint32_t accessTokenId) { std::lock_guard guard(runningRecordMapMutex_); diff --git a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn index 579917b5a5d..e4a0184befb 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn +++ b/test/unittest/app_mgr_service_inner_eighth_test/BUILD.gn @@ -85,6 +85,7 @@ ohos_unittest("app_mgr_service_inner_eighth_test") { "mock/src/mock_permission_verification.cpp", "mock/src/mock_remote_client_manager.cpp", "mock/src/mock_user_record_manager.cpp", + "mock/src/mock_app_utils.cpp", ] configs = [] diff --git a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp index a76ce33ce28..1ef96717e4e 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -29,6 +29,8 @@ #include "overlay_manager_proxy.h" #include "ability_connect_callback_stub.h" #include "app_scheduler_const.h" +#include "mock_app_utils.h" + using namespace testing; using namespace testing::ext; using namespace OHOS::AAFwk; @@ -2682,5 +2684,77 @@ HWTEST_F(AppMgrServiceInnerEighthTest, SetPreloadDebugApp_0100, TestSize.Level1) EXPECT_EQ(debugApp, true); TAG_LOGI(AAFwkTag::TEST, "SetPreloadDebugApp_0100 end"); } + +/** + * @tc.name: PromoteCurrentToCandidateMasterProcess_0100 + * @tc.desc: test SetPreloadDebugApp + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerEighthTest, PromoteCurrentToCandidateMasterProcess_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 start"); + auto appMgrServiceInner = std::make_shared(); + ASSERT_NE(appMgrServiceInner, nullptr); + AAFwk::MyStatus::GetInstance().getCallingUid_ = RESOURCE_MANAGER_UID; + AAFwk::MyStatus::GetInstance().getAppRunningRecordByPid_ = std::make_shared(nullptr, 0, "", false, 1); + int32_t res = appMgrServiceInner->PromoteCurrentToCandidateMasterProcess(true); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 end"); +} + +/** + * @tc.name: PromoteCurrentToCandidateMasterProcess_0200 + * @tc.desc: test SetPreloadDebugApp + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerEighthTest, PromoteCurrentToCandidateMasterProcess_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 start"); + auto appMgrServiceInner = std::make_shared(); + ASSERT_NE(appMgrServiceInner, nullptr); + AFwk::MyStatus::GetInstance().IsStartSpecifiedProcess_ = true; + AAFwk::MyStatus::GetInstance().getCallingUid_ = RESOURCE_MANAGER_UID; + AAFwk::MyStatus::GetInstance().getAppRunningRecordByPid_ = std::make_shared(nullptr, 0, "", true, 1); + int32_t res = appMgrServiceInner->PromoteCurrentToCandidateMasterProcess(true); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 end"); +} + +/** + * @tc.name: PromoteCurrentToCandidateMasterProcess_0200 + * @tc.desc: test SetPreloadDebugApp + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerEighthTest, PromoteCurrentToCandidateMasterProcess_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 start"); + auto appMgrServiceInner = std::make_shared(); + ASSERT_NE(appMgrServiceInner, nullptr); + AFwk::MyStatus::GetInstance().IsStartSpecifiedProcess_ = true; + AAFwk::MyStatus::GetInstance().getCallingUid_ = RESOURCE_MANAGER_UID; + AAFwk::MyStatus::GetInstance().getAppRunningRecordByPid_ = std::make_shared(nullptr, 0, "", true, 1); + int32_t res = appMgrServiceInner->PromoteCurrentToCandidateMasterProcess(true); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 end"); +} + +/** + * @tc.name: PromoteCurrentToCandidateMasterProcess_0200 + * @tc.desc: test SetPreloadDebugApp + * @tc.type: FUNC + */ +HWTEST_F(AppMgrServiceInnerEighthTest, PromoteCurrentToCandidateMasterProcess_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 start"); + auto appMgrServiceInner = std::make_shared(); + ASSERT_NE(appMgrServiceInner, nullptr); + AFwk::MyStatus::GetInstance().IsStartSpecifiedProcess_ = false; + AAFwk::MyStatus::GetInstance().getCallingUid_ = RESOURCE_MANAGER_UID; + AAFwk::MyStatus::GetInstance().getAppRunningRecordByPid_ = std::make_shared(nullptr, 0, "", true, 1); + int32_t res = appMgrServiceInner->PromoteCurrentToCandidateMasterProcess(true); + EXPECT_EQ(res, ERR_OK); + TAG_LOGI(AAFwkTag::TEST, "PromoteCurrentToCandidateMasterProcess_0100 end"); +} + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_app_utils.h b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_app_utils.h new file mode 100644 index 00000000000..2175d9bed90 --- /dev/null +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_app_utils.h @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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_UTILS_H +#define OHOS_ABILITY_RUNTIME_APP_UTILS_H + +#include +#include + +#include "nocopyable.h" + +namespace OHOS { +namespace AAFwk { +constexpr const int32_t DEFAULT_MAX_EXT_PER_PROC = 10; +constexpr const int32_t DEFAULT_MAX_EXT_PER_DEV = 100; +constexpr const int32_t DEFAULT_INVALID_VALUE = -1; +constexpr const int32_t DEFAULT_MAX_CHILD_PROCESS = 0; +template +class DeviceConfiguration { +public: + bool isLoaded = false; + T value; +}; + +/** + * @class AppUtils + * provides app utils. + */ +class AppUtils { +public: + /** + * GetInstance, get an instance of AppUtils. + * + * @return An instance of AppUtils. + */ + static AppUtils &GetInstance(); + + /** + * AppUtils, destructor. + * + */ + ~AppUtils(); + + /** + * IsLauncher, check if it is a launcher. + * + * @param bundleName The bundle name. + * @return Whether it is a launcher. + */ + bool IsLauncher(const std::string &bundleName) const; + + /** + * IsLauncherAbility, check if it is a launcher ability. + * + * @param abilityName The ability name. + * @return Whether it is a launcher ability. + */ + bool IsLauncherAbility(const std::string &abilityName) const; + + /** + * IsInheritWindowSplitScreenMode, check if it is inherit window split screen mode. + * + * @return Whether it is inherit window split screen mode. + */ + bool IsInheritWindowSplitScreenMode(); + + /** + * IsSupportAncoApp, check if it supports anco app. + * + * @return Whether it supports anco app. + */ + bool IsSupportAncoApp(); + + /** + * GetTimeoutUnitTimeRatio, get timeout unit time ratio. + * + * @return Timeout unit time ratio. + */ + int32_t GetTimeoutUnitTimeRatio(); + + /** + * IsSelectorDialogDefaultPossion, check if selector dialog is on the default position. + * + * @return Whether selector dialog is on the default position. + */ + bool IsSelectorDialogDefaultPossion(); + + /** + * IsStartSpecifiedProcess, check whether or not to start specified process. + * + * @return Whether or not to start specified process. + */ + bool IsStartSpecifiedProcess(); + + /** + * IsUseMultiRenderProcess, check whether uses multi-render process. + * + * @return Whether uses multi-render process. + */ + bool IsUseMultiRenderProcess(); + + /** + * IsLimitMaximumOfRenderProcess, check limit maximum of render process. + * + * @return Whether limit maximum of render process. + */ + bool IsLimitMaximumOfRenderProcess(); + + /** + * IsGrantPersistUriPermission, check whether to grant persist uri permission. + * + * @return Whether to grant persist uri permission. + */ + bool IsGrantPersistUriPermission(); + + /** + * IsStartOptionsWithAnimation, check whether the start options have animation. + * + * @return Whether the start options have animation. + */ + bool IsStartOptionsWithAnimation(); + + /** + * IsStartOptionsWithAnimation, check whether it is a multi-process model. + * + * @return Whether it is a multi-process model. + */ + bool IsMultiProcessModel(); + + /** + * IsStartOptionsWithProcessOptions, check whether the start options have process options. + * + * @return Whether the start options have process options. + */ + bool IsStartOptionsWithProcessOptions(); + + /** + * EnableMoveUIAbilityToBackgroundApi, enable move ui-ability to background api. + * + * @return Whether the enable move ui-ability to background api is successful. + */ + bool EnableMoveUIAbilityToBackgroundApi(); + + /** + * IsLaunchEmbededUIAbility, check if it is to launch embedded ui-ability. + * + * @return Whether it is to launch embedded ui-ability. + */ + bool IsLaunchEmbededUIAbility(); + + /** + * IsSupportNativeChildProcess, check if it supports native child process. + * + * @return Whether it supports native child process. + */ + bool IsSupportNativeChildProcess(); + + /** + * IsSupportMultiInstance, check if it supports multi-instance. + * + * @return Whether it supports multi-instance. + */ + bool IsSupportMultiInstance(); + + /** + * IsAllowResidentInExtremeMemory, check if it allows resident in extrem low memory. + * + * @param bundleName The bundle name. + * @param abilityName The ability name. + * @return Whether it allows resident in extrem low memory. + */ + bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); + + /** + * IsAllowNativeChildProcess, check if it allows native child process. + * + * @param appIdentifier The app identifier. + * @return Whether it allows native child process. + */ + bool IsAllowNativeChildProcess(const std::string &appIdentifier); + + /** + * GetLimitMaximumExtensionsPerProc, get limit max extensions per proc. + * + * @return Limit max extensions per proc. + */ + int32_t GetLimitMaximumExtensionsPerProc(); + + /** + * IsBigMemoryUnrelatedKeepAliveProc, check if it refuses resident in memory quick kill. + * + * @param bundleName The bundle name. + */ + bool IsBigMemoryUnrelatedKeepAliveProc(const std::string &bundleName); + + /** + * IsRequireBigMemoryProcess, check if it requires big memory. + * + * @param bundleName The bundle name. + */ + bool IsRequireBigMemoryProcess(const std::string &bundleName); + + /** + * GetLimitMaximumExtensionsPerDevice, get limit max extensions per device. + * + * @return Limit max extensions per device. + */ + int32_t GetLimitMaximumExtensionsPerDevice(); + + /** + * GetCacheExtensionTypeList, get cache extension type list. + * + * @return Cache extension type list. + */ + std::string GetCacheExtensionTypeList(); + + /** + * IsAllowStartAbilityWithoutCallerToken, check if it allows start ability without caller token. + * + * @param bundleName The bundle name. + * @param abilityName The ability name. + * @return Whether it allows start ability without caller token. + */ + bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); + + /** + * GetBrokerDelegateBundleName, get broker delegate bundle name. + * + * @return Broker delegate bundle name. + */ + std::string GetBrokerDelegateBundleName(); + + /** + * GetCollaboratorBrokerUID, get collaborator broker id. + * + * @return Collaborator broker id. + */ + int32_t GetCollaboratorBrokerUID(); + + /** + * GetCollaboratorBrokerReserveUID, get collaborator broker reserve uid. + * + * @return Collaborator broker reserve uid. + */ + int32_t GetCollaboratorBrokerReserveUID(); + + /** + * MaxChildProcess, get max child process. + * + * @return Max child process. + */ + int32_t MaxChildProcess(); + + /** + * GetMigrateClientBundleName, get migrate client bundle name. + * + * @return Migrate client bundle name. + */ + std::string GetMigrateClientBundleName(); + + /** + * IsConnectSupportCrossUser, check if it support cross-user. + * + * @return Whether it supports cross-user. + */ + bool IsConnectSupportCrossUser(); + + /** + * IsPrepareTerminateEnabled, check if it supports prepare terminate. + * + * @return Whether it supports prepare terminate. + */ + bool IsPrepareTerminateEnabled(); + + /** + * IsCacheExtensionAbilityByList, check if it allows cache extension ability by list. + * + * @param bundleName The bundle name. + * @param abilityName The ability name. + * @return Whether it allows cache extensionability. + */ + bool IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName); + + /** + * IsSystemReasonMessage, check if it supports launch reason message. + * + * @param reasonMessage The launch reason message. + * @return Whether it supports launch reason message. + */ + bool IsSystemReasonMessage(const std::string &reasonMessage); + +private: + /** + * LoadResidentProcessInExtremeMemory, load resident process in extreme low memory. + * + */ + void LoadResidentProcessInExtremeMemory(); + + /** + * LoadAllowNativeChildProcessApps, load allow native child process apps. + * + */ + void LoadAllowNativeChildProcessApps(); + + /** + * LoadStartAbilityWithoutCallerToken, load start ability without caller token. + * + */ + void LoadStartAbilityWithoutCallerToken(); + + /** + * IsCacheAbilityEnabled, check cache ability parameter switch. + * + */ + bool IsCacheAbilityEnabled(); + + /** + * LoadCacheAbilityList, load cache ability list from file. + * + */ + void LoadCacheAbilityList(); + + /** + * LoadProcessProhibitedFromRestarting, load process prohibited in big memory. + * + */ + void LoadProcessProhibitedFromRestarting(); + + /** + * LoadRequireBigMemoryApp, load app name that require big memory. + * + */ + void LoadRequireBigMemoryApp(); + + /** + * AppUtils, private constructor. + * + */ + AppUtils(); + + volatile bool isSceneBoard_ = false; + volatile DeviceConfiguration isInheritWindowSplitScreenMode_ = {false, true}; + volatile DeviceConfiguration isSupportAncoApp_ = {false, false}; + volatile DeviceConfiguration timeoutUnitTimeRatio_ = {false, 1}; + volatile DeviceConfiguration isSelectorDialogDefaultPossion_ = {false, true}; + volatile DeviceConfiguration isStartSpecifiedProcess_ = {false, false}; + volatile DeviceConfiguration isUseMultiRenderProcess_ = {false, true}; + volatile DeviceConfiguration isLimitMaximumOfRenderProcess_ = {false, true}; + volatile DeviceConfiguration isGrantPersistUriPermission_ = {false, false}; + volatile DeviceConfiguration isStartOptionsWithAnimation_ = {false, false}; + volatile DeviceConfiguration isMultiProcessModel_ = {false, false}; + volatile DeviceConfiguration isStartOptionsWithProcessOptions_ = {false, false}; + volatile DeviceConfiguration enableMoveUIAbilityToBackgroundApi_ = {false, true}; + volatile DeviceConfiguration isLaunchEmbededUIAbility_ = {false, false}; + volatile DeviceConfiguration isSupportNativeChildProcess_ = {false, false}; + volatile DeviceConfiguration isSupportMultiInstance_ = {false, false}; + std::mutex isConnectSupportCrossUserMutex_; + volatile DeviceConfiguration isConnectSupportCrossUser_ = {false, false}; + DeviceConfiguration>> + residentProcessInExtremeMemory_ = {false, {}}; + std::mutex residentProcessInExtremeMemoryMutex_; + DeviceConfiguration> processProhibitedFromRestarting_ = {false, {}}; + std::mutex processProhibitedFromRestartingMutex_; + DeviceConfiguration> requireBigMemoryApp_ = {false, {}}; + std::mutex requireBigMemoryAppMutex_; + DeviceConfiguration> + allowStartNativeProcessApps_ = {false, {}}; + volatile DeviceConfiguration limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; + volatile DeviceConfiguration limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; + DeviceConfiguration>> + startAbilityWithoutCallerToken_ = {false, {}}; + std::mutex startAbilityWithoutCallerTokenMutex_; + DeviceConfiguration brokerDelegateBundleName_ = {false, ""}; + volatile DeviceConfiguration collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE}; + volatile DeviceConfiguration collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE}; + volatile DeviceConfiguration maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; + DeviceConfiguration migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"}; + DeviceConfiguration>> + cacheAbilityList_ = {false, {}}; + DISALLOW_COPY_AND_MOVE(AppUtils); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h index 5436fc4dbf6..aa610cb9e62 100755 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/include/mock_my_status.h @@ -137,6 +137,7 @@ public: ErrCode handleMemorySizeInSufficent_ = ERR_OK; ErrCode handleRequireBigMemoryOptimization_ = ERR_OK; ErrCode handleNoRequireBigMemoryOptimization_ = ERR_OK; + bool IsStartSpecifiedProcess_ = true; private: MyStatus() = default; }; diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp index 1e7dd5eb60e..d6bc6e4c071 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_running_record.cpp @@ -29,6 +29,20 @@ AppRunningRecord::AppRunningRecord( } } +AppRunningRecord::AppRunningRecord( + const std::shared_ptr &info, const int32_t recordId, const std::string &processName, + bool isMasterProcess, int64_t timeStamp) : appRecordId_(recordId), processName_(processName) +{ + if (info) { + appInfo_ = info; + mainBundleName_ = info->bundleName; + isLauncherApp_ = info->isLauncherApp; + mainAppName_ = info->name; + } + isMasterProcess_ = isMasterProcess; + timeStamp_ = timeStamp; +} + void AppRunningRecord::SetApplicationClient(const sptr &thread) { } diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_utils.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_utils.cpp new file mode 100644 index 00000000000..e74a36e6f5c --- /dev/null +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_app_utils.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 "mock_app_utils.h" +#include "mock_my_status.h" + + +namespace OHOS { +namespace AAFwk { + +AppUtils::~AppUtils() {} + +AppUtils::AppUtils() {} + +AppUtils &AppUtils::GetInstance() +{ + static AppUtils utils; + return utils; +} + +bool AppUtils::IsLauncher(const std::string &bundleName) const +{ + return true; +} + +bool AppUtils::IsLauncherAbility(const std::string &abilityName) const +{ + return true; +} + +bool AppUtils::IsInheritWindowSplitScreenMode() +{ + return true; +} + +bool AppUtils::IsSupportAncoApp() +{ + return true; +} + +int32_t AppUtils::GetTimeoutUnitTimeRatio() +{ + return 0; +} + +bool AppUtils::IsSelectorDialogDefaultPossion() +{ + return true; +} + +bool AppUtils::IsStartSpecifiedProcess() +{ + return AFwk::MyStatus::GetInstance().IsStartSpecifiedProcess_; +} + +bool AppUtils::IsUseMultiRenderProcess() +{ + return true; +} + +bool AppUtils::IsLimitMaximumOfRenderProcess() +{ + return true; +} + +bool AppUtils::IsGrantPersistUriPermission() +{ + return true; +} + +bool AppUtils::IsStartOptionsWithAnimation() +{ + return true; +} + +bool AppUtils::IsMultiProcessModel() +{ + return true; +} + +bool AppUtils::IsStartOptionsWithProcessOptions() +{ + return true; +} + +bool AppUtils::EnableMoveUIAbilityToBackgroundApi() +{ + return true; +} + +bool AppUtils::IsLaunchEmbededUIAbility() +{ + return MyStatus::GetInstance().auIsLaunchEmbededUIAbility_; +} + +bool AppUtils::IsSupportNativeChildProcess() +{ + return true; +} + +bool AppUtils::IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName) +{ + return true; +} + +bool AppUtils::IsBigMemoryUnrelatedKeepAliveProc(const std::string &bundleName) +{ + return true; +} + +bool AppUtils::IsRequireBigMemoryProcess(const std::string &bundleName) +{ + return true; +} + +void AppUtils::LoadProcessProhibitedFromRestarting() +{ +} + +void AppUtils::LoadRequireBigMemoryApp() +{ +} + +void AppUtils::LoadResidentProcessInExtremeMemory() +{ +} + +bool AppUtils::IsAllowNativeChildProcess(const std::string &appIdentifier) +{ + return true; +} + +void AppUtils::LoadAllowNativeChildProcessApps() +{ +} + +int32_t AppUtils::GetLimitMaximumExtensionsPerProc() +{ + return 0; +} + +int32_t AppUtils::GetLimitMaximumExtensionsPerDevice() +{ + return 0; +} + +std::string AppUtils::GetCacheExtensionTypeList() +{ + return ""; +} + +bool AppUtils::IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName) +{ + return true; +} + +void AppUtils::LoadStartAbilityWithoutCallerToken() +{ +} + +std::string AppUtils::GetBrokerDelegateBundleName() +{ + return ""; +} + +int32_t AppUtils::GetCollaboratorBrokerUID() +{ + return 0; +} + +int32_t AppUtils::GetCollaboratorBrokerReserveUID() +{ + return 0; +} + +int32_t AppUtils::MaxChildProcess() +{ + return 0; +} + +bool AppUtils::IsSupportMultiInstance() +{ + return true; +} + +std::string AppUtils::GetMigrateClientBundleName() +{ + return ""; +} + +bool AppUtils::IsConnectSupportCrossUser() +{ + return true; +} + +bool AppUtils::IsPrepareTerminateEnabled() +{ + return true; +} + +bool AppUtils::IsSystemReasonMessage(const std::string &reasonMessage) +{ + return true; +} + +bool AppUtils::IsCacheAbilityEnabled() +{ + return true; +} + +void AppUtils::LoadCacheAbilityList() +{ +} + +bool AppUtils::IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName) +{ + return true; +} + +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h index 9af8d1fdded..1658031a2b4 100644 --- a/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h +++ b/test/unittest/multi_app_utils_test/include/mock_app_mgr_service.h @@ -271,15 +271,6 @@ public: return 0; } - int32_t PromoteToStandbyMasterProcess(bool isInsertToHead) - { - return 0; - } - - int32_t DemoteFromStandbyMasterProcess(){ - return ; - } - int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, RunningMultiAppInfo &info) override; -- Gitee