diff --git a/frameworks/js/napi/ability_constant/ability_constant_module.cpp b/frameworks/js/napi/ability_constant/ability_constant_module.cpp index fcfdc45b51934f58fb4eccb8098951864e2c71eb..16627aefbfcd0362b848c4c364ec01afd29909aa 100644 --- a/frameworks/js/napi/ability_constant/ability_constant_module.cpp +++ b/frameworks/js/napi/ability_constant/ability_constant_module.cpp @@ -20,6 +20,7 @@ #include "napi/native_api.h" #include "napi/native_common.h" #include "recovery_param.h" +#include "ability_stage_constant.h" namespace OHOS { namespace AAFwk { @@ -182,6 +183,19 @@ static napi_value InitCollaborateResultEnum(napi_env env) return object; } +static napi_value InitAbilityStagePrepareTerminationObject(napi_env env) +{ + TAG_LOGD(AAFwkTag::JSNAPI, "called"); + napi_value object; + NAPI_CALL(env, napi_create_object(env, &object)); + + NAPI_CALL(env, SetEnumItem(env, object, "TERMINATE_IMMEDIATELY", + static_cast(AppExecFwk::PrepareTermination::TERMINATE_IMMEDIATELY))); + NAPI_CALL(env, SetEnumItem(env, object, "CANCEL", + static_cast(AppExecFwk::PrepareTermination::CANCEL))); + return object; +} + /* * The module initialization. */ @@ -241,6 +255,12 @@ static napi_value AbilityConstantInit(napi_env env, napi_value exports) return nullptr; } + napi_value prepareTermination = InitAbilityStagePrepareTerminationObject(env); + if (prepareTermination == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "null prepareTermination"); + return nullptr; + } + napi_property_descriptor exportObjs[] = { DECLARE_NAPI_PROPERTY("LaunchReason", launchReason), DECLARE_NAPI_PROPERTY("LastExitReason", lastExitReason), @@ -251,6 +271,7 @@ static napi_value AbilityConstantInit(napi_env env, napi_value exports) DECLARE_NAPI_PROPERTY("OnSaveResult", saveResult), DECLARE_NAPI_PROPERTY("StateType", stateType), DECLARE_NAPI_PROPERTY("CollaborateResult", collaborateResult), + DECLARE_NAPI_PROPERTY("PrepareTermination", prepareTermination), }; napi_status status = napi_define_properties(env, exports, sizeof(exportObjs) / sizeof(exportObjs[0]), exportObjs); if (status != napi_ok) { diff --git a/frameworks/native/appkit/ability_runtime/app/ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/ability_stage.cpp index 02eb81a3b17facc7a505d85793f3ec042e781581..8ed6501b0b5f41a368959c67d763a588100c8fd0 100644 --- a/frameworks/native/appkit/ability_runtime/app/ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/ability_stage.cpp @@ -52,6 +52,11 @@ void AbilityStage::OnCreate(const AAFwk::Want &want) const void AbilityStage::OnDestroy() const {} +bool AbilityStage::OnPrepareTerminate(int &prepareTermination) const +{ + return false; +} + std::shared_ptr AbilityStage::GetContext() const { return context_; diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp index 636d70593504a6a7c6a8c66aea4057adaaddada6..adf277e65fdc113d2d8e4526abc57ea33812ab22 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp @@ -233,6 +233,41 @@ void JsAbilityStage::OnDestroy() const napi_call_function(env, obj, methodOnDestroy, 0, nullptr, nullptr); } +bool JsAbilityStage::OnPrepareTerminate(int32_t &prepareTermination) const +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + AbilityStage::OnPrepareTerminate(prepareTermination); + + if (!jsAbilityStageObj_) { + TAG_LOGW(AAFwkTag::APPKIT, "Not found AbilityStage.js"); + return false; + } + + HandleScope handleScope(jsRuntime_); + auto env = jsRuntime_.GetNapiEnv(); + + napi_value obj = jsAbilityStageObj_->GetNapiValue(); + if (!CheckTypeForNapiValue(env, obj, napi_object)) { + TAG_LOGE(AAFwkTag::APPKIT, "Fail to get AbilityStage object"); + return false; + } + + napi_value methodOnPrepareTerminate = nullptr; + napi_get_named_property(env, obj, "onPrepareTermination", &methodOnPrepareTerminate); + if (methodOnPrepareTerminate == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "onPrepareTermination is unimplemented"); + return false; + } + TAG_LOGI(AAFwkTag::APPKIT, "onPrepareTermination is implemented"); + napi_value result = nullptr; + napi_call_function(env, obj, methodOnPrepareTerminate, 0, nullptr, &result); + if (!ConvertFromJsValue(env, result, prepareTermination)) { + TAG_LOGE(AAFwkTag::APPKIT, "Fail to unwrap prepareTermination result"); + return false; + } + return true; +} + std::string JsAbilityStage::OnAcceptWant(const AAFwk::Want &want) { TAG_LOGD(AAFwkTag::APPKIT, "called"); @@ -266,7 +301,6 @@ std::string JsAbilityStage::OnAcceptWant(const AAFwk::Want &want) return AppExecFwk::UnwrapStringFromJS(env, flagNative); } - std::string JsAbilityStage::OnNewProcessRequest(const AAFwk::Want &want) { TAG_LOGD(AAFwkTag::APPKIT, "called"); diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 268592cb7f6c92417120f695f4855f19b7473186..f04dc5315a20ce6add1dcb8fcc3292e44fd1b75e 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -2989,6 +2989,17 @@ void MainThread::ScheduleAcceptWant(const AAFwk::Want &want, const std::string & } } +void MainThread::SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + if (!application_) { + TAG_LOGE(AAFwkTag::APPKIT, "null application_"); + return; + } + application_->SchedulePrepareTerminate(moduleName, prepareTermination, isExist); +} + void MainThread::HandleScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) { TAG_LOGD(AAFwkTag::APPKIT, "called"); diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 05854b50aedb96c3831e56c27b9ca77698f5c7ee..ab88f5749fbe936d9b3bb752b45a7d1ef82cee34 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -696,6 +696,19 @@ void OHOSApplication::ScheduleAcceptWant(const AAFwk::Want &want, const std::str } } +void OHOSApplication::SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + auto iter = abilityStages_.find(moduleName); + if (iter == abilityStages_.end() || iter->second == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "%{public}s is not in abilityStage", moduleName.c_str()); + return; + } + isExist = iter->second->OnPrepareTerminate(prepareTermination); + TAG_LOGD(AAFwkTag::APPKIT, "OnPrepareTerminate isExist = %{public}d", isExist); +} + void OHOSApplication::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName, std::string &flag) { diff --git a/interfaces/inner_api/ability_manager/include/ability_stage_constant.h b/interfaces/inner_api/ability_manager/include/ability_stage_constant.h new file mode 100644 index 0000000000000000000000000000000000000000..a1cad2f6ecdb462747637bc2c2d30116db60b255 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/ability_stage_constant.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H +#define OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H + +namespace OHOS { +namespace AppExecFwk { +/** + * @enum AbilityStage + * AbilityStage defines enums used in abilityStage. + */ +enum class PrepareTermination { + TERMINATE_IMMEDIATELY = 0, + CANCEL, +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_STAGE_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index 3ac02d01bd0f7a5f787655fadcaac24a6f07323c..051b575a5f45526c3186dd6672cd8295290fa0dc 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -246,6 +246,15 @@ public: */ virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response) = 0; + /** + * Prepare terminate application + * + * @param pid Process ID + * @param prepareTelrmination PrepareTermination Enum + * @param isExist whether this callback event exist + */ + virtual void PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) = 0; + /** * Start specified process. * @@ -526,6 +535,7 @@ public: SET_KEEP_ALIVE_DKV, KILL_PROCESSES_IN_BATCH, SEND_APP_SPAWN_UNINSTALL_DEBUG_HAP_MSG, + PREPARE_TERMINATE_APP, // Add enumeration values above END }; diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 95abd158abbe574b058049e8de5585b1caafb387..4a8c02344ff987ca7838e712aaab7fe1fbcbef5b 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -232,6 +232,15 @@ public: */ void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override; + /** + * Prepare terminate application + * + * @param pid Process ID + * @param prepareTelrmination PrepareTermination Enum + * @param isExist whether this callback event exist + */ + virtual void PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) override; + /** * Start specified ability. * diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h index da5b546ec9522d34814318f2b6a6eb1c72487517..f5e99641e675c4594fd9ab7511b5c99682452a7f 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_stub.h @@ -64,6 +64,7 @@ private: int32_t HandleKillApplicationSelf(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRunningProcessInfoByToken(MessageParcel &data, MessageParcel &reply); int32_t HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel &data, MessageParcel &reply); + int32_t HandlePrepareTerminateApp(MessageParcel &data, MessageParcel &reply); int32_t HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterStartSpecifiedAbilityResponse(MessageParcel &data, MessageParcel &reply); int32_t HandleGetApplicationInfoByProcessID(MessageParcel &data, MessageParcel &reply); 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 09fe890ce5f2cb160e3d12f582cb971d75467319..c273567c3c707177af64874c522a83c07741a87c 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 @@ -443,6 +443,15 @@ public: */ virtual void RegisterStartSpecifiedAbilityResponse(const sptr &response); + /** + * Prepare terminate application + * + * @param pid Process ID + * @param prepareTelrmination PrepareTermination Enum + * @param isExist whether this callback event exist + */ + virtual void PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist); + /** * Start specified process. * diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h index ccd75c0458aaba2a35d18c93aac00abae032b336..db261a5e14f6d59227b8a8a5dc587153eccfcecb 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_host.h @@ -51,6 +51,7 @@ private: int32_t HandleScheduleProcessSecurityExit(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleClearPageStack(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleAcceptWant(MessageParcel &data, MessageParcel &reply); + int32_t HandleSchedulePrepareTerminate(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleNewProcessRequest(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h index 6bef043e4a2c14d09b2e0455f5d27268369379eb..0e9945ab83c7cdc2a6c320a380f0b2ef9f4c9036 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_interface.h @@ -195,6 +195,16 @@ public: */ virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) = 0; + /** + * @brief Schedule prepare terminate application + * + * @param moduleName module name + * @param prepareTermination the return enum type PrepareTermination + * @param isExist whether the onPrepareTerminate exists + */ + virtual void SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) = 0; + virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) = 0; /** @@ -335,6 +345,7 @@ public: SCHEDULE_DUMP_FFRT, SCHEDULE_CACHE_PROCESS, SCHEDULE_CLEAR_PAGE_STACK, + SCHEDULE_PREPARE_TERMINATE, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h index 33e47f5346c3e1897388e4bbc2909bc991e598b3..f40d60bff09510521ea0d28495b253b336900689 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_scheduler_proxy.h @@ -188,6 +188,16 @@ public: */ virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; + /** + * @brief Schedule prepare terminate application + * + * @param moduleName module name + * @param prepareTermination the return enum type PrepareTermination + * @param isExist whether the onPrepareTerminate exists + */ + virtual void SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) override; + virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override; /** diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index a5f2cb0138248b11ad0f5fce3041f0302c64aa09..7f7d1eb602976e72a80e7451c50fabaa482243ba 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -665,6 +665,30 @@ void AmsMgrProxy::SetAbilityForegroundingFlagToAppRecord(const pid_t pid) } } +void AmsMgrProxy::PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "token write error"); + return; + } + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write PrepareTerminateApp pid failed."); + return; + } + auto ret = SendTransactCmd( + static_cast(IAmsMgr::Message::PREPARE_TERMINATE_APP), data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest PrepareTerminateApp err: %{public}d", ret); + return; + } + prepareTermination = reply.ReadInt32(); + isExist = reply.ReadBool(); + TAG_LOGD(AAFwkTag::APPMGR, "Get PrepareTerminateApp reply success"); +} + void AmsMgrProxy::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 05371add424de4bc724719e86d661ab90a72362f..992100721091b339964a77f3c405e2bbff399922 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -195,6 +195,8 @@ int32_t AmsMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data return HandleBlockProcessCacheByPids(data, reply); case static_cast(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB): return HandleIsKilledForUpgradeWeb(data, reply); + case static_cast(IAmsMgr::Message::PREPARE_TERMINATE_APP): + return HandlePrepareTerminateApp(data, reply); } return AAFwk::ERR_CODE_NOT_EXIST; } @@ -493,6 +495,24 @@ int32_t AmsMgrStub::HandleSetAbilityForegroundingFlagToAppRecord(MessageParcel & return NO_ERROR; } +int32_t AmsMgrStub::HandlePrepareTerminateApp(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + auto pid = static_cast(data.ReadInt32()); + int32_t prepareTermination = 0; + bool isExist = false; + PrepareTerminateApp(pid, prepareTermination, isExist); + if (!reply.WriteInt32(prepareTermination)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write prepareTermination failed."); + return ERR_INVALID_VALUE; + } + if (!reply.WriteBool(isExist)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write isExist failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AmsMgrStub::HandleStartSpecifiedAbility(MessageParcel &data, MessageParcel &reply) { AAFwk::Want *want = data.ReadParcelable(); 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 847223f924f3e487c46f8033332549a6bdde1208..13df6fce93c3fffa58f427c14071b95c4078bf2b 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 @@ -682,6 +682,22 @@ void AppMgrClient::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecF amsService->StartSpecifiedAbility(want, abilityInfo, requestId); } +void AppMgrClient::PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "service is nullptr"); + return; + } + sptr amsService = service->GetAmsMgr(); + if (amsService == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "amsService is nullptr"); + return; + } + amsService->PrepareTerminateApp(pid, prepareTermination, isExist); +} + void AppMgrClient::SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) { if (!IsAmsServiceReady()) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp index bce8f455d256a54e85f03001242a78174bbd3c3c..6b46e345ceec5f50c5f28998b4a23bb8c7320bb3 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_host.cpp @@ -111,6 +111,8 @@ int32_t AppSchedulerHost::OnRemoteRequestInnerSecond(uint32_t code, MessageParce return HandleScheduleClearPageStack(data, reply); case static_cast(IAppScheduler::Message::SCHEDULE_ACCEPT_WANT): return HandleScheduleAcceptWant(data, reply); + case static_cast(IAppScheduler::Message::SCHEDULE_PREPARE_TERMINATE): + return HandleSchedulePrepareTerminate(data, reply); case static_cast(IAppScheduler::Message::SCHEDULE_NEW_PROCESS_REQUEST): return HandleScheduleNewProcessRequest(data, reply); case static_cast(IAppScheduler::Message::SCHEDULE_NOTIFY_LOAD_REPAIR_PATCH): @@ -346,6 +348,24 @@ int32_t AppSchedulerHost::HandleScheduleAcceptWant(MessageParcel &data, MessageP return NO_ERROR; } +int32_t AppSchedulerHost::HandleSchedulePrepareTerminate(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + auto moduleName = data.ReadString(); + int32_t prepareTermination = 0; + bool isExist = false; + SchedulePrepareTerminate(moduleName, prepareTermination, isExist); + if (!reply.WriteInt32(prepareTermination)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write HandleSchedulePrepareTerminate prepareTermination failed."); + return ERR_INVALID_VALUE; + } + if (!reply.WriteBool(isExist)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write HandleSchedulePrepareTerminate isExist failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppSchedulerHost::HandleScheduleNewProcessRequest(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::APPMGR, "call."); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp index f1a59671c474d886d365b65531948c83875257dd..58dd8ef186c64e23b65e759eca219d2779249528 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_scheduler_proxy.cpp @@ -430,6 +430,37 @@ void AppSchedulerProxy::ScheduleAcceptWant(const AAFwk::Want &want, const std::s } } +void AppSchedulerProxy::SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "token write error"); + return; + } + if (!data.WriteString(moduleName)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write SchedulePrepareTerminate moduleName failed."); + return; + } + sptr remote = Remote(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL"); + return; + } + int32_t ret = remote->SendRequest( + static_cast(IAppScheduler::Message::SCHEDULE_PREPARE_TERMINATE), data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGW(AAFwkTag::APPMGR, "SendRequest SchedulePrepareTerminate err: %{public}d", ret); + return; + } + prepareTermination = reply.ReadInt32(); + isExist = reply.ReadBool(); + TAG_LOGD(AAFwkTag::APPMGR, "Get SchedulePrepareTerminate reply success"); +} + void AppSchedulerProxy::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) { MessageParcel data; diff --git a/interfaces/kits/native/appkit/ability_runtime/app/ability_stage.h b/interfaces/kits/native/appkit/ability_runtime/app/ability_stage.h index 2f09864779264f9f31ac4ceae84f89725e7ecb12..3eab41b7b71ad0252ae879acb5b02b9f6c767efe 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/ability_stage.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/ability_stage.h @@ -48,6 +48,7 @@ public: virtual ~AbilityStage() = default; virtual void OnCreate(const AAFwk::Want &want) const; virtual void OnDestroy() const; + virtual bool OnPrepareTerminate(int &prepareTermination) const; virtual std::string OnAcceptWant(const AAFwk::Want &want); virtual std::string OnNewProcessRequest(const AAFwk::Want &want); virtual void Init(const std::shared_ptr &context, diff --git a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h index b3f64f0bcc2d1bb9996a4c125fcda7d4a9dc5e59..9c0511086c08783bfeabe8c75994130a0591f9ba 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage.h @@ -48,6 +48,8 @@ public: void OnDestroy() const override; + bool OnPrepareTerminate(int &prepareTermination) const override; + std::string OnAcceptWant(const AAFwk::Want &want) override; std::string OnNewProcessRequest(const AAFwk::Want &want) override; diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 394d0051434e1767466988bafde6b0dcb65c5c13..80157f2de9dbc29f04b43cff93cc200bc44ca4c6 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -278,6 +278,9 @@ public: void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; + void SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) override; + void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override; /** diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 5f619d5d76ec8cc59ac69c73d2bc583514fcaeb0..3e11a7133bedb79839990ce4caffce52606563f4 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -183,6 +183,8 @@ public: void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName, std::string &flag); + void SchedulePrepareTerminate(const std::string &moduleName, int32_t &prepareTermination, bool &isExist); + void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName, std::string &flag); virtual std::shared_ptr GetConfiguration() const; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index dcade12ffa6d5e54a1ba4a54cabf2634fa5cf89a..e9631e2e0811f823d0c0f7588a738a128b37d34d 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -165,6 +165,15 @@ public: */ int TerminateAbility(const sptr &token, bool clearMissionFlag); + /** + * Prepare terminate application + * + * @param pid Process ID + * @param prepareTelrmination PrepareTermination Enum + * @param isExist whether this callback event exist + */ + void PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist); + /** * move ability to foreground. * diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 1a2fe745ee495e4658c8f50a996677e5607dbba1..46fcb563f066ce4c65a68721af9083b7fa5cabdd 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -425,6 +425,17 @@ private: void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr &abilityRecord) const; bool CheckPrepareTerminateEnable(const std::shared_ptr &abilityRecord); + + /** + * @brief Execute PrepareTerminateApp when it is implemented + * + * @param pid process id + * @param tokens the tokens of ability records + * @return Returns the tokens that still need to execute PrepareTerminate. + */ + std::vector> PrepareTerminateAppAndGetRemaining( + int32_t pid, std::vector> tokens); + bool GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const; bool CheckSessionInfo(sptr sessionInfo) const; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 7ded54bd6af1d4567ffbf366da514f194cdfe280..29503cf993922603dbbbbd74c8c901e52e63a0fa 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -361,6 +361,12 @@ void StartSpecifiedAbilityResponse::OnAcceptWantResponse( DelayedSingleton::GetInstance()->OnAcceptWantResponse(want, flag, requestId); } +void AppScheduler::PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) +{ + CHECK_POINTER(appMgrClient_); + appMgrClient_->PrepareTerminateApp(pid, prepareTermination, isExist); +} + void StartSpecifiedAbilityResponse::OnTimeoutResponse(const AAFwk::Want &want, int32_t requestId) { DelayedSingleton::GetInstance()->OnStartSpecifiedAbilityTimeoutResponse(want, requestId); diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 6082ba15eebd730787a471d204546f2a577b5cda..287df7383421d8f0cc657a0ef06e7ab8bffdc388 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -32,6 +32,7 @@ #include "session/host/include/zidl/session_interface.h" #include "startup_util.h" #include "ui_extension_utils.h" +#include "ability_stage_constant.h" #ifdef SUPPORT_GRAPHICS #include "ability_first_frame_state_observer_manager.h" #endif @@ -2301,7 +2302,7 @@ bool UIAbilityLifecycleManager::PrepareTerminateAbility(const std::shared_ptr>(); auto future = promise->get_future(); auto task = [promise, abilityRecord]() { @@ -2707,17 +2708,70 @@ int32_t UIAbilityLifecycleManager::DoCallerProcessAttachment(std::shared_ptrDoCallerProcessAttachment(abilityRecord); } +std::vector> UIAbilityLifecycleManager::PrepareTerminateAppAndGetRemaining( + int32_t pid, std::vector> tokens) +{ + if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Not supported device"); + return tokens; + } + std::vector> remainingTokens; + for (const auto& token: tokens) { + auto abilityRecord = Token::GetAbilityRecordByToken(token); + if (!CheckPrepareTerminateEnable(abilityRecord)) { + remainingTokens.emplace_back(token); + continue; + } + auto prepareTermination = std::make_shared(0); + auto isExist = std::make_shared(false); + // execute onPrepareTerminate until timeout + auto promise = std::make_shared>(); + auto future = promise->get_future(); + auto task = [promise, pid, prepareTermination, isExist]() { + DelayedSingleton::GetInstance()->PrepareTerminateApp(pid, *prepareTermination, *isExist); + promise->set_value(true); + }; + ffrt::submit(task); + std::future_status status = future.wait_for(std::chrono::milliseconds( + GlobalConstant::PREPARE_TERMINATE_TIMEOUT_TIME)); + if (status == std::future_status::timeout) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "onPrepareTermination timeout"); + remainingTokens.emplace_back(token); + continue; + } + if (!future.get() || prepareTermination == nullptr || isExist == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "PrepareTerminateApp error"); + remainingTokens.emplace_back(token); + continue; + } + if (!*isExist) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "onPrepareTermination is not exist"); + remainingTokens.emplace_back(token); + continue; + } + if (static_cast(*prepareTermination) + == AppExecFwk::PrepareTermination::CANCEL) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "PrepareTerminate cancel"); + continue; + } + // Terminate immediately by default + TAG_LOGI(AAFwkTag::ABILITYMGR, "PrepareTerminate immediately"); + TerminateSession(Token::GetAbilityRecordByToken(token)); + } + return remainingTokens; +} + int32_t UIAbilityLifecycleManager::TryPrepareTerminateByPids(const std::vector& pids) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::ABILITYMGR, "prepare terminate"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "prepare terminate app"); IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton::GetInstance()->BlockProcessCacheByPids(pids)); - for (const auto& pid: pids) { + for (const auto &pid : pids) { std::unordered_set> abilitysToTerminate; std::vector> tokens; IN_PROCESS_CALL_WITHOUT_RET( DelayedSingleton::GetInstance()->GetAbilityRecordsByProcessID(pid, tokens)); - for (const auto& token: tokens) { + for (const auto &token : PrepareTerminateAppAndGetRemaining(pid, tokens)) { auto abilityRecord = Token::GetAbilityRecordByToken(token); if (PrepareTerminateAbility(abilityRecord)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "terminate blocked"); @@ -2725,7 +2779,7 @@ int32_t UIAbilityLifecycleManager::TryPrepareTerminateByPids(const std::vector &response) override; + virtual void PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) override; + /** * Start specified process. * diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 0800927fc13392bb67d13bc38b5910bc31a132da..e321381ec9ee99c6bb690e0929531a07485d788a 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -191,6 +191,8 @@ public: * @param want the moduleName of which being scheduled. */ void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName); + + void SchedulePrepareTerminate(const std::string &moduleName, int32_t &prepareTermination, bool &isExist); void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName); diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 991b4a16e9a97ff5c978dbd129a54422e40a6725..a01131771e834a3c4e7485fc8a5ad6a34a9e0a25 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -842,6 +842,8 @@ public: */ void ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); + void SchedulePrepareTerminate(const pid_t pid, int32_t &prepareTermination, bool &isExist); + void ScheduleNewProcessRequestDone(const int32_t recordId, const AAFwk::Want &want, const std::string &flag); /** diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index b83ac114970073f02e4bf18eb90ad90ecd573002..4d44279c19fd89335d019dcee2164e09d6a1ca46 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -718,6 +718,9 @@ public: * Called when one specified request is finished to set the request id to -1 */ void ResetSpecifiedRequestId(); + + void SchedulePrepareTerminate(int32_t &prepareTermination, bool &isExist); + /** * call the scheduler to go acceptWant procedure */ diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 0c031b271205aff2f655f5047a60e89ad941f917..56e1b132e522b566704b995cd006fe7159f253ee 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -444,6 +444,16 @@ void AmsMgrScheduler::StartSpecifiedAbility(const AAFwk::Want &want, const AppEx }); } +void AmsMgrScheduler::PrepareTerminateApp(const pid_t pid, int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + if (!IsReady()) { + TAG_LOGW(AAFwkTag::APPMGR, "not ready"); + return; + } + amsMgrServiceInner_->SchedulePrepareTerminate(pid, prepareTermination, isExist); +} + void AmsMgrScheduler::StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId) { diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 1840ee6d89f039e52ce07b7cdc8387670ed780c6..420407a99c08b7e9aebfdb3b9fa8e1813451c089 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -230,6 +230,18 @@ void AppLifeCycleDeal::ScheduleAcceptWant(const AAFwk::Want &want, const std::st appThread->ScheduleAcceptWant(want, moduleName); } +void AppLifeCycleDeal::SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + auto appThread = GetApplicationClient(); + if (!appThread) { + TAG_LOGE(AAFwkTag::APPMGR, "null appThread"); + return; + } + appThread->SchedulePrepareTerminate(moduleName, prepareTermination, isExist); +} + void AppLifeCycleDeal::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) { auto appThread = GetApplicationClient(); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 2ba5c15c5b5b18cd79c2ec938847588de39b234a..d8ab248e27cf73bdb6664df9014279ead3fbce38 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -4856,6 +4856,17 @@ void AppMgrServiceInner::ScheduleAcceptWantDone( } } +void AppMgrServiceInner::SchedulePrepareTerminate(const pid_t pid, int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPKIT, "called"); + auto appRecord = GetAppRunningRecordByPid(pid); + if (appRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "get appRecord fail"); + return; + } + appRecord->SchedulePrepareTerminate(prepareTermination, isExist); +} + void AppMgrServiceInner::HandleStartSpecifiedAbilityTimeOut(std::shared_ptr appRecord) { TAG_LOGI(AAFwkTag::APPMGR, "startSpecifiedAbility timeOut"); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 260d043cd65600909ef8a40e70d27ea359d91355..480e4d614836f5d12a0aa2e3729150c3d553d9cc 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1693,6 +1693,25 @@ bool AppRunningRecord::IsStartSpecifiedAbility() const return specifiedRequestId_ != -1; } +void AppRunningRecord::SchedulePrepareTerminate(int32_t &prepareTermination, bool &isExist) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called"); + if (appLifeCycleDeal_ == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "null appLifeCycleDeal_"); + return; + } + std::lock_guard hapModulesLock(hapModulesLock_); + for (const auto &iter : hapModules_) { + for (const auto &moduleRecord : iter.second) { + if (moduleRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "null moduleRecord"); + continue; + } + appLifeCycleDeal_->SchedulePrepareTerminate(moduleRecord->GetModuleName(), prepareTermination, isExist); + } + } +} + void AppRunningRecord::ScheduleAcceptWant(const std::string &moduleName) { auto timeOUt = AMSEventHandler::START_SPECIFIED_ABILITY_TIMEOUT; diff --git a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h index 0266afdfc2496e8c97ffc1973ea6c90575b55708..ce8dd31e931cb53e33aef271ed39954a294df37d 100644 --- a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h @@ -44,6 +44,7 @@ public: MOCK_METHOD0(IsReady, bool()); MOCK_METHOD1(AbilityAttachTimeOut, void(const sptr& token)); MOCK_METHOD2(PrepareTerminate, void(const sptr& token, bool clearMissionFlag)); + MOCK_METHOD3(PrepareTerminateApp, void(const pid_t, int32_t &PrepareTermination, bool &isExist)); MOCK_METHOD2(GetRunningProcessInfoByToken, void(const sptr& token, OHOS::AppExecFwk::RunningProcessInfo& info)); MOCK_METHOD1(SetAbilityForegroundingFlagToAppRecord, void(const pid_t pid)); diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler.h b/test/mock/services_appmgr_test/include/mock_app_scheduler.h index fa1b34779eb149766adbad5395752c3557f703ed..f6ff19e1806c525ce5dd984851153c08fa396b59 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -46,6 +46,8 @@ public: MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level)); MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); + MOCK_METHOD3(SchedulePrepareTerminate, void(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist)); MOCK_METHOD2(ScheduleNewProcessRequest, void(const AAFwk::Want& want, const std::string& moduleName)); MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, const sptr& callback, const int32_t recordId)); diff --git a/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h b/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h index 5139f09bdea9e60f64f48d785ff591cd4339c1c5..3d707fa52ae41e588b4939ebe9269cc2b07e0857 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler_client.h @@ -46,6 +46,8 @@ public: MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level)); MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); + MOCK_METHOD3(SchedulePrepareTerminate, void(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist)); MOCK_METHOD2(ScheduleNewProcessRequest, void(const AAFwk::Want& want, const std::string& moduleName)); MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, const sptr& callback, const int32_t recordId)); diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index 0726231801683b9c69b85f75f471abb195bbb340..0bd696f5eddf1826d5692669c7964c59126c093b 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -41,6 +41,8 @@ public: MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&)); MOCK_METHOD1(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); + MOCK_METHOD3(SchedulePrepareTerminate, void(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist)); MOCK_METHOD2(ScheduleNewProcessRequest, void(const AAFwk::Want& want, const std::string& moduleName)); MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, const sptr& callback, const int32_t recordId)); diff --git a/test/mock/services_appmgr_test/include/mock_application_proxy.h b/test/mock/services_appmgr_test/include/mock_application_proxy.h index 8a015c1610b8ad8323315e99864f9c37196287a4..10e2057985546dff314cc313529651d159a2c839 100644 --- a/test/mock/services_appmgr_test/include/mock_application_proxy.h +++ b/test/mock/services_appmgr_test/include/mock_application_proxy.h @@ -42,6 +42,8 @@ public: MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&)); MOCK_METHOD1(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); + MOCK_METHOD3(SchedulePrepareTerminate, void(const std::string &moduleName, + int32_t &PrepareTermination, bool &isExist)); MOCK_METHOD2(ScheduleNewProcessRequest, void(const AAFwk::Want& want, const std::string& moduleName)); MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, const sptr& callback, const int32_t recordId)); diff --git a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp index 1a12a4e3bb561f544e9c26df57370c8038ad5567..3bf96e0c2b00065d3b6f4e4feb2c600c779d9467 100644 --- a/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp +++ b/test/moduletest/common/ams/ability_running_record_test/ams_ability_running_record_module_test.cpp @@ -143,6 +143,10 @@ public: void ScheduleAcceptWant(const AAFwk::Want& want, const std::string& moduleName) override {} + void SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) override + {} + void ScheduleNewProcessRequest(const AAFwk::Want& want, const std::string& moduleName) override {} diff --git a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp index e4a506a64e8be4ec45d1fb173c79b2017aeede24..eb56081e335bdece61598c048de9920840955370 100644 --- a/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp +++ b/test/moduletest/common/ams/app_mgr_service_test/ams_app_mgr_service_module_test.cpp @@ -76,6 +76,9 @@ public: {} void ScheduleAcceptWant(const AAFwk::Want& want, const std::string& moduleName) override {} + void SchedulePrepareTerminate(const std::string &moduleName, + int32_t &prepareTermination, bool &isExist) override + {} void ScheduleNewProcessRequest(const AAFwk::Want& want, const std::string& moduleName) override {} int32_t ScheduleNotifyLoadRepairPatch(const std::string& bundleName,