From 4bdb3443b67f0fea7898a9584403ae66bc04ba63 Mon Sep 17 00:00:00 2001 From: xubinMvq411 Date: Sat, 28 Dec 2024 14:39:33 +0800 Subject: [PATCH] =?UTF-8?q?AbilityStage=E6=96=B0=E5=A2=9EOnPrepareTerminat?= =?UTF-8?q?e=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xubin --- .../ability_constant_module.cpp | 21 ++++++ .../ability_runtime/app/ability_stage.cpp | 5 ++ .../ability_runtime/app/js_ability_stage.cpp | 36 ++++++++++- frameworks/native/appkit/app/main_thread.cpp | 11 ++++ .../native/appkit/app/ohos_application.cpp | 13 ++++ .../include/ability_stage_constant.h | 31 +++++++++ .../include/appmgr/ams_mgr_interface.h | 10 +++ .../include/appmgr/ams_mgr_proxy.h | 9 +++ .../app_manager/include/appmgr/ams_mgr_stub.h | 1 + .../include/appmgr/app_mgr_client.h | 9 +++ .../include/appmgr/app_scheduler_host.h | 1 + .../include/appmgr/app_scheduler_interface.h | 11 ++++ .../include/appmgr/app_scheduler_proxy.h | 10 +++ .../app_manager/src/appmgr/ams_mgr_proxy.cpp | 24 +++++++ .../app_manager/src/appmgr/ams_mgr_stub.cpp | 20 ++++++ .../app_manager/src/appmgr/app_mgr_client.cpp | 16 +++++ .../src/appmgr/app_scheduler_host.cpp | 20 ++++++ .../src/appmgr/app_scheduler_proxy.cpp | 31 +++++++++ .../ability_runtime/app/ability_stage.h | 1 + .../ability_runtime/app/js_ability_stage.h | 2 + .../kits/native/appkit/app/main_thread.h | 3 + .../kits/native/appkit/app/ohos_application.h | 2 + services/abilitymgr/include/app_scheduler.h | 9 +++ .../ui_ability_lifecycle_manager.h | 11 ++++ services/abilitymgr/src/app_scheduler.cpp | 6 ++ .../ui_ability_lifecycle_manager.cpp | 64 +++++++++++++++++-- services/appmgr/include/ams_mgr_scheduler.h | 2 + services/appmgr/include/app_lifecycle_deal.h | 2 + .../appmgr/include/app_mgr_service_inner.h | 2 + services/appmgr/include/app_running_record.h | 3 + services/appmgr/src/ams_mgr_scheduler.cpp | 10 +++ services/appmgr/src/app_lifecycle_deal.cpp | 12 ++++ services/appmgr/src/app_mgr_service_inner.cpp | 11 ++++ services/appmgr/src/app_running_record.cpp | 19 ++++++ .../include/mock_ams_mgr_scheduler.h | 1 + .../include/mock_app_scheduler.h | 2 + .../include/mock_app_scheduler_client.h | 2 + .../include/mock_application.h | 2 + .../include/mock_application_proxy.h | 2 + ...ams_ability_running_record_module_test.cpp | 4 ++ .../ams_app_mgr_service_module_test.cpp | 3 + 41 files changed, 448 insertions(+), 6 deletions(-) create mode 100644 interfaces/inner_api/ability_manager/include/ability_stage_constant.h diff --git a/frameworks/js/napi/ability_constant/ability_constant_module.cpp b/frameworks/js/napi/ability_constant/ability_constant_module.cpp index fcfdc45b519..16627aefbfc 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 02eb81a3b17..8ed6501b0b5 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 636d7059350..adf277e65fd 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 268592cb7f6..f04dc5315a2 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 05854b50aed..ab88f5749fb 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 00000000000..a1cad2f6ecd --- /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 3ac02d01bd0..051b575a5f4 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 95abd158abb..4a8c02344ff 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 da5b546ec95..f5e99641e67 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 09fe890ce5f..c273567c3c7 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 ccd75c0458a..db261a5e14f 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 6bef043e4a2..0e9945ab83c 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 33e47f5346c..f40d60bff09 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 a5f2cb01382..7f7d1eb6029 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 05371add424..99210072109 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 847223f924f..13df6fce93c 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 bce8f455d25..6b46e345cee 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 f1a59671c47..58dd8ef186c 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 2f098647792..3eab41b7b71 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 b3f64f0bcc2..9c0511086c0 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 394d0051434..80157f2de9d 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 5f619d5d76e..3e11a7133be 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 dcade12ffa6..e9631e2e081 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 1a2fe745ee4..46fcb563f06 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 7ded54bd6af..29503cf9939 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 6082ba15eeb..287df738342 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 0800927fc13..e321381ec9e 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 991b4a16e9a..a01131771e8 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 b83ac114970..4d44279c19f 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 0c031b27120..56e1b132e52 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 1840ee6d89f..420407a99c0 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 2ba5c15c5b5..d8ab248e27c 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 260d043cd65..480e4d61483 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 0266afdfc24..ce8dd31e931 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 fa1b34779eb..f6ff19e1806 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 5139f09bdea..3d707fa52ae 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 07262318016..0bd696f5edd 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 8a015c1610b..10e20579855 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 1a12a4e3bb5..3bf96e0c2b0 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 e4a506a64e8..eb56081e335 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, -- Gitee