diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 97018d8e01..61d0d28013 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1932,28 +1932,32 @@ void MainThread::CheckMainThreadIsAlive() } #endif // ABILITY_LIBRARY_LOADER -int32_t MainThread::ScheduleNotifyLoadRepairPatch(const std::string &bundleName) +int32_t MainThread::ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("ScheduleNotifyLoadRepairPatch function called."); wptr weak = this; - auto task = [weak, bundleName]() { + auto task = [weak, bundleName, callback]() { auto appThread = weak.promote(); - if (appThread == nullptr || appThread->application_ == nullptr) { - HILOG_ERROR("ScheduleNotifyLoadRepairPatch, app thread or application is nullptr."); + if (appThread == nullptr || appThread->application_ == nullptr || callback == nullptr) { + HILOG_ERROR("ScheduleNotifyLoadRepairPatch, parameter is nullptr."); return; } + bool ret = true; std::vector> hqfFilePair; if (appThread->GetHqfFileAndHapPath(bundleName, hqfFilePair)) { for (auto it = hqfFilePair.begin(); it != hqfFilePair.end(); it++) { HILOG_INFO("ScheduleNotifyLoadRepairPatch, LoadPatch, hqfFile: %{private}s, hapPath: %{private}s.", it->first.c_str(), it->second.c_str()); - appThread->application_->NotifyLoadRepairPatch(it->first, it->second); + ret = appThread->application_->NotifyLoadRepairPatch(it->first, it->second); } } else { HILOG_DEBUG("ScheduleNotifyLoadRepairPatch, There's no hqfFile need to load."); } + + callback->OnLoadPatchDone(ret ? NO_ERROR : ERR_INVALID_OPERATION); }; if (mainHandler_ == nullptr || !mainHandler_->PostTask(task)) { HILOG_ERROR("ScheduleNotifyLoadRepairPatch, Post task failed."); @@ -1963,18 +1967,19 @@ int32_t MainThread::ScheduleNotifyLoadRepairPatch(const std::string &bundleName) return NO_ERROR; } -int32_t MainThread::ScheduleNotifyHotReloadPage() +int32_t MainThread::ScheduleNotifyHotReloadPage(const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); wptr weak = this; - auto task = [weak]() { + auto task = [weak, callback]() { auto appThread = weak.promote(); - if (appThread == nullptr || appThread->application_ == nullptr) { - HILOG_ERROR("app thread or application is nullptr."); + if (appThread == nullptr || appThread->application_ == nullptr || callback == nullptr) { + HILOG_ERROR("parameter is nullptr."); return; } - appThread->application_->NotifyHotReloadPage(); + auto ret = appThread->application_->NotifyHotReloadPage(); + callback->OnReloadPageDone(ret ? NO_ERROR : ERR_INVALID_OPERATION); }; if (mainHandler_ == nullptr || !mainHandler_->PostTask(task)) { HILOG_ERROR("Post task failed."); @@ -2032,27 +2037,31 @@ bool MainThread::GetHqfFileAndHapPath(const std::string &bundleName, return true; } -int32_t MainThread::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t MainThread::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("ScheduleNotifyUnLoadRepairPatch function called."); wptr weak = this; - auto task = [weak, bundleName]() { + auto task = [weak, bundleName, callback]() { auto appThread = weak.promote(); - if (appThread == nullptr || appThread->application_ == nullptr) { - HILOG_ERROR("ScheduleNotifyUnLoadRepairPatch, app thread or application is nullptr."); + if (appThread == nullptr || appThread->application_ == nullptr || callback == nullptr) { + HILOG_ERROR("ScheduleNotifyUnLoadRepairPatch, parameter is nullptr."); return; } + bool ret = true; std::vector> hqfFilePair; if (appThread->GetHqfFileAndHapPath(bundleName, hqfFilePair)) { for (auto it = hqfFilePair.begin(); it != hqfFilePair.end(); it++) { HILOG_INFO("ScheduleNotifyUnLoadRepairPatch, UnloadPatch, hqfFile: %{private}s.", it->first.c_str()); - appThread->application_->NotifyUnLoadRepairPatch(it->first); + ret = appThread->application_->NotifyUnLoadRepairPatch(it->first); } } else { HILOG_DEBUG("ScheduleNotifyUnLoadRepairPatch, There's no hqfFile need to unload."); } + + callback->OnUnloadPatchDone(ret ? NO_ERROR : ERR_INVALID_OPERATION); }; if (mainHandler_ == nullptr || !mainHandler_->PostTask(task)) { HILOG_ERROR("ScheduleNotifyUnLoadRepairPatch, Post task failed."); diff --git a/frameworks/native/appkit/app/ohos_application.cpp b/frameworks/native/appkit/app/ohos_application.cpp index 4af5bf3880..35edf2aed3 100644 --- a/frameworks/native/appkit/app/ohos_application.cpp +++ b/frameworks/native/appkit/app/ohos_application.cpp @@ -662,34 +662,34 @@ void OHOSApplication::SetExtensionTypeMap(std::map map) extensionTypeMap_ = map; } -void OHOSApplication::NotifyLoadRepairPatch(const std::string &hqfFile, const std::string &hapPath) +bool OHOSApplication::NotifyLoadRepairPatch(const std::string &hqfFile, const std::string &hapPath) { if (runtime_ == nullptr) { HILOG_DEBUG("runtime is nullptr."); - return; + return true; } - runtime_->LoadRepairPatch(hqfFile, hapPath); + return runtime_->LoadRepairPatch(hqfFile, hapPath); } -void OHOSApplication::NotifyHotReloadPage() +bool OHOSApplication::NotifyHotReloadPage() { if (runtime_ == nullptr) { HILOG_DEBUG("runtime is nullptr."); - return; + return true; } - runtime_->NotifyHotReloadPage(); + return runtime_->NotifyHotReloadPage(); } -void OHOSApplication::NotifyUnLoadRepairPatch(const std::string &hqfFile) +bool OHOSApplication::NotifyUnLoadRepairPatch(const std::string &hqfFile) { if (runtime_ == nullptr) { HILOG_DEBUG("runtime is nullptr."); - return; + return true; } - runtime_->UnLoadRepairPatch(hqfFile); + return runtime_->UnLoadRepairPatch(hqfFile); } } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 476466e42c..d3fffe8705 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -25,9 +25,9 @@ #include "ability_constants.h" #include "connect_server_manager.h" +#include "ecmascript/napi/include/jsnapi.h" #include "event_handler.h" #include "file_path_utils.h" -#include "ecmascript/napi/include/jsnapi.h" #include "hdc_register.h" #include "hilog_wrapper.h" #include "hot_reloader.h" @@ -170,25 +170,25 @@ public: static_cast(nativeEngine_.get()), exportObj); } - void LoadRepairPatch(const std::string& hqfFile, const std::string& hapPath) override + bool LoadRepairPatch(const std::string& hqfFile, const std::string& hapPath) override { HILOG_DEBUG("LoadRepairPatch function called."); if (vm_ == nullptr) { HILOG_ERROR("LoadRepairPatch, vm is nullptr."); - return; + return false; } AbilityRuntime::RuntimeExtractor extractor(hqfFile); if (!extractor.Init()) { HILOG_ERROR("LoadRepairPatch, Extractor of %{private}s init failed.", hqfFile.c_str()); - return; + return false; } std::vector fileNames; extractor.GetSpecifiedTypeFiles(fileNames, ".abc"); if (fileNames.empty()) { HILOG_WARN("LoadRepairPatch, There's no abc file in hqf %{private}s.", hqfFile.c_str()); - return; + return true; } for (const auto &fileName : fileNames) { @@ -197,7 +197,7 @@ public: std::ostringstream outStream; if (!extractor.ExtractByName(fileName, outStream)) { HILOG_ERROR("LoadRepairPatch, Extract %{public}s failed.", patchFile.c_str()); - return; + return false; } const auto &outStr = outStream.str(); @@ -208,31 +208,33 @@ public: bool ret = panda::JSNApi::LoadPatch(vm_, patchFile, buffer.data(), buffer.size(), baseFile); if (!ret) { HILOG_ERROR("LoadRepairPatch, LoadPatch failed."); - return; + return false; } HILOG_DEBUG("LoadRepairPatch, Load patch %{private}s succeed.", patchFile.c_str()); } + + return true; } - void UnLoadRepairPatch(const std::string& hqfFile) override + bool UnLoadRepairPatch(const std::string& hqfFile) override { HILOG_DEBUG("UnLoadRepairPatch function called."); if (vm_ == nullptr) { HILOG_ERROR("UnLoadRepairPatch vm is nullptr."); - return; + return false; } AbilityRuntime::RuntimeExtractor extractor(hqfFile); if (!extractor.Init()) { HILOG_ERROR("UnLoadRepairPatch, Extractor of %{private}s init failed.", hqfFile.c_str()); - return; + return false; } std::vector fileNames; extractor.GetSpecifiedTypeFiles(fileNames, ".abc"); if (fileNames.empty()) { HILOG_WARN("UnLoadRepairPatch, There's no abc file in hqf %{private}s.", hqfFile.c_str()); - return; + return true; } for (const auto &fileName : fileNames) { @@ -241,16 +243,19 @@ public: bool ret = panda::JSNApi::UnloadPatch(vm_, patchFile); if (!ret) { HILOG_ERROR("UnLoadRepairPatch, UnLoadPatch failed."); - return; + return false; } HILOG_DEBUG("UnLoadRepairPatch, UnLoad patch %{private}s succeed.", patchFile.c_str()); } + + return true; } - void NotifyHotReloadPage() override + bool NotifyHotReloadPage() override { HILOG_DEBUG("function called."); Ace::HotReloader::HotReload(); + return true; } private: diff --git a/frameworks/native/runtime/utils/include/runtime_extractor.h b/frameworks/native/runtime/utils/include/runtime_extractor.h index 6aad3aa73d..b7bd1a166a 100644 --- a/frameworks/native/runtime/utils/include/runtime_extractor.h +++ b/frameworks/native/runtime/utils/include/runtime_extractor.h @@ -57,6 +57,7 @@ public: /** * @brief Get specified type names in a zip file. * @param fileNames Indicates the obtained file names in zip. + * @param suffix Indicates the suffix of file. */ void GetSpecifiedTypeFiles(std::vector &fileNames, const std::string &suffix); /** diff --git a/frameworks/native/runtime/utils/src/runtime_extractor.cpp b/frameworks/native/runtime/utils/src/runtime_extractor.cpp index 131f0bf158..cca0b76b05 100644 --- a/frameworks/native/runtime/utils/src/runtime_extractor.cpp +++ b/frameworks/native/runtime/utils/src/runtime_extractor.cpp @@ -201,7 +201,6 @@ void RuntimeExtractor::GetSpecifiedTypeFiles(std::vector &fileNames } } } - return; } bool RuntimeExtractor::IsStageBasedModel(std::string abilityName) diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index dc0493fd18..15029413d6 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -73,6 +73,8 @@ ohos_shared_library("app_manager") { "src/appmgr/process_data.cpp", "src/appmgr/process_info.cpp", "src/appmgr/profile.cpp", + "src/appmgr/quick_fix_callback_proxy.cpp", + "src/appmgr/quick_fix_callback_stub.cpp", "src/appmgr/render_scheduler_host.cpp", "src/appmgr/render_scheduler_proxy.cpp", "src/appmgr/running_process_info.cpp", 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 be2a5fdc0f..08b5a16186 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 @@ -30,6 +30,7 @@ #include "system_memory_attr.h" #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" +#include "iquick_fix_callback.h" namespace OHOS { namespace AppExecFwk { @@ -262,25 +263,28 @@ public: * @brief Notify application load patch. * * @param bundleName Bundle name + * @param callback called when LoadPatch finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t NotifyLoadRepairPatch(const std::string &bundleName) = 0; + virtual int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) = 0; /** * @brief Notify application reload page. * * @param bundleName Bundle name + * @param callback called when HotReload finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t NotifyHotReloadPage(const std::string &bundleName) = 0; + virtual int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) = 0; /** * @brief Notify application unload patch. * * @param bundleName Bundle name + * @param callback called when UnloadPatch finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t NotifyUnLoadRepairPatch(const std::string &bundleName) = 0; + virtual int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) = 0; #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE /** 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 b8b3068a68..d15993ccbf 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 @@ -246,11 +246,11 @@ public: bool GetAppRunningStateByBundleName(const std::string &bundleName) override; - int32_t NotifyLoadRepairPatch(const std::string &bundleName) override; + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; - int32_t NotifyHotReloadPage(const std::string &bundleName) override; + int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) override; - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName) override; + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override; 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 566fcc8edd..e054d15987 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 @@ -21,6 +21,7 @@ #include "app_launch_data.h" #include "configuration.h" #include "hap_module_info.h" +#include "iquick_fix_callback.h" #include "want.h" namespace OHOS { @@ -143,24 +144,29 @@ public: * @brief Notify application load patch. * * @param bundleName Bundle name + * @param callback called when LoadPatch finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName) = 0; + virtual int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) = 0; /** * @brief Notify application reload page. * + * @param callback called when HotReload finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t ScheduleNotifyHotReloadPage() = 0; + virtual int32_t ScheduleNotifyHotReloadPage(const sptr &callback) = 0; /** * @brief Notify application unload patch. * * @param bundleName Bundle name + * @param callback called when UnloadPatch finished. * @return Returns 0 on success, error code on failure. */ - virtual int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) = 0; + virtual int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) = 0; enum class Message { SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0, 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 c67dd48469..4306d7dce8 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 @@ -142,11 +142,13 @@ public: virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override; - int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName) override; + int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override; - int32_t ScheduleNotifyHotReloadPage() override; + int32_t ScheduleNotifyHotReloadPage(const sptr &callback) override; - int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) override; + int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override; private: bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/inner_api/app_manager/include/appmgr/iquick_fix_callback.h b/interfaces/inner_api/app_manager/include/appmgr/iquick_fix_callback.h new file mode 100644 index 0000000000..109d826fdb --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/iquick_fix_callback.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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_IQUICK_FIX_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_IQUICK_FIX_CALLBACK_H + +#include "iremote_broker.h" + +namespace OHOS { +namespace AppExecFwk { +class IQuickFixCallback : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.QuickFixCallback"); + + virtual void OnLoadPatchDone(int32_t resultCode) = 0; + virtual void OnUnloadPatchDone(int32_t resultCode) = 0; + virtual void OnReloadPageDone(int32_t resultCode) = 0; + + enum QuickFixCallbackCmd { + ON_NOTIFY_LOAD_PATCH = 0, // ipc id for OnLoadPatchDone + ON_NOTIFY_UNLOAD_PATCH = 1, // ipc id for OnUnloadPatchDone + ON_NOTIFY_RELOAD_PAGE = 2, // ipc id for OnReloadPageDone + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_IQUICK_FIX_CALLBACK_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_proxy.h new file mode 100644 index 0000000000..b23b5eb09b --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_proxy.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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_QUICK_FIX_CALLBACK_PROXY_H +#define OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_PROXY_H + +#include "iquick_fix_callback.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace AppExecFwk { +class QuickFixCallbackProxy : public IRemoteProxy { +public: + explicit QuickFixCallbackProxy(const sptr &impl) : IRemoteProxy(impl) {}; + virtual ~QuickFixCallbackProxy() = default; + + void OnLoadPatchDone(int32_t resultCode) override; + void OnUnloadPatchDone(int32_t resultCode) override; + void OnReloadPageDone(int32_t resultCode) override; + +private: + bool SendRequestWithCmd(uint32_t code, MessageParcel &data, MessageParcel &reply); + + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_PROXY_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_stub.h b/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_stub.h new file mode 100644 index 0000000000..e1a5e752b4 --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/quick_fix_callback_stub.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 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_QUICK_FIX_CALLBACK_STUB_H +#define OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_STUB_H + +#include + +#include "iquick_fix_callback.h" +#include "iremote_stub.h" +#include "message_parcel.h" +#include "nocopyable.h" + +namespace OHOS { +namespace AppExecFwk { +class QuickFixCallbackStub : public IRemoteStub { +public: + QuickFixCallbackStub(); + virtual ~QuickFixCallbackStub(); + + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t HandleOnLoadPatchDoneInner(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnUnloadPatchDoneInner(MessageParcel &data, MessageParcel &reply); + int32_t HandleOnReloadPageDoneInner(MessageParcel &data, MessageParcel &reply); + + using RequestFuncType = int32_t (QuickFixCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map requestFuncMap_; + + DISALLOW_COPY_AND_MOVE(QuickFixCallbackStub); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_CALLBACK_STUB_H 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 237423495c..b7e144cc2c 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 @@ -859,7 +859,7 @@ bool AppMgrProxy::GetAppRunningStateByBundleName(const std::string &bundleName) return reply.ReadBool(); } -int32_t AppMgrProxy::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrProxy::NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("NotifyLoadRepairPatch, function called."); @@ -874,6 +874,11 @@ int32_t AppMgrProxy::NotifyLoadRepairPatch(const std::string &bundleName) return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("NotifyLoadRepairPatch, Remote is nullptr."); @@ -892,7 +897,7 @@ int32_t AppMgrProxy::NotifyLoadRepairPatch(const std::string &bundleName) return reply.ReadInt32(); } -int32_t AppMgrProxy::NotifyHotReloadPage(const std::string &bundleName) +int32_t AppMgrProxy::NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -907,6 +912,11 @@ int32_t AppMgrProxy::NotifyHotReloadPage(const std::string &bundleName) return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("Remote is nullptr."); @@ -965,7 +975,7 @@ int32_t AppMgrProxy::SetContinuousTaskProcess(int32_t pid, bool isContinuousTask } #endif -int32_t AppMgrProxy::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrProxy::NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -980,6 +990,11 @@ int32_t AppMgrProxy::NotifyUnLoadRepairPatch(const std::string &bundleName) return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("Notify unload patch, Remote is nullptr."); 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 22710e6962..3511ae51fe 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 @@ -520,7 +520,8 @@ int32_t AppMgrStub::HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParc HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); std::string bundleName = data.ReadString(); - auto ret = NotifyLoadRepairPatch(bundleName); + auto callback = iface_cast(data.ReadRemoteObject()); + auto ret = NotifyLoadRepairPatch(bundleName, callback); if (!reply.WriteInt32(ret)) { return ERR_INVALID_VALUE; } @@ -532,7 +533,8 @@ int32_t AppMgrStub::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); std::string bundleName = data.ReadString(); - auto ret = NotifyHotReloadPage(bundleName); + auto callback = iface_cast(data.ReadRemoteObject()); + auto ret = NotifyHotReloadPage(bundleName, callback); if (!reply.WriteInt32(ret)) { return ERR_INVALID_VALUE; } @@ -559,7 +561,8 @@ int32_t AppMgrStub::HandleNotifyUnLoadRepairPatch(MessageParcel &data, MessagePa HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); std::string bundleName = data.ReadString(); - auto ret = NotifyUnLoadRepairPatch(bundleName); + auto callback = iface_cast(data.ReadRemoteObject()); + auto ret = NotifyUnLoadRepairPatch(bundleName, callback); if (!reply.WriteInt32(ret)) { return ERR_INVALID_VALUE; } 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 ac7191533a..7e43c64461 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 @@ -236,14 +236,16 @@ int32_t AppSchedulerHost::HandleNotifyLoadRepairPatch(MessageParcel &data, Messa { HITRACE_METER(HITRACE_TAG_APP); std::string bundleName = data.ReadString(); - ScheduleNotifyLoadRepairPatch(bundleName); + auto callback = iface_cast(data.ReadRemoteObject()); + ScheduleNotifyLoadRepairPatch(bundleName, callback); return NO_ERROR; } int32_t AppSchedulerHost::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); - ScheduleNotifyHotReloadPage(); + auto callback = iface_cast(data.ReadRemoteObject()); + ScheduleNotifyHotReloadPage(callback); return NO_ERROR; } @@ -251,7 +253,8 @@ int32_t AppSchedulerHost::HandleNotifyUnLoadRepairPatch(MessageParcel &data, Mes { HITRACE_METER(HITRACE_TAG_APP); std::string bundleName = data.ReadString(); - ScheduleNotifyUnLoadRepairPatch(bundleName); + auto callback = iface_cast(data.ReadRemoteObject()); + ScheduleNotifyUnLoadRepairPatch(bundleName, callback); return NO_ERROR; } } // namespace AppExecFwk 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 1e2740a7b7..941f653a3d 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 @@ -380,7 +380,8 @@ void AppSchedulerProxy::ScheduleAcceptWant(const AAFwk::Want &want, const std::s } } -int32_t AppSchedulerProxy::ScheduleNotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppSchedulerProxy::ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); MessageParcel data; @@ -394,6 +395,11 @@ int32_t AppSchedulerProxy::ScheduleNotifyLoadRepairPatch(const std::string &bund return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("ScheduleNotifyLoadRepairPatch, Remote is nullptr"); @@ -412,7 +418,7 @@ int32_t AppSchedulerProxy::ScheduleNotifyLoadRepairPatch(const std::string &bund return reply.ReadInt32(); } -int32_t AppSchedulerProxy::ScheduleNotifyHotReloadPage() +int32_t AppSchedulerProxy::ScheduleNotifyHotReloadPage(const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); MessageParcel data; @@ -421,6 +427,11 @@ int32_t AppSchedulerProxy::ScheduleNotifyHotReloadPage() return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("Remote is nullptr"); @@ -439,7 +450,8 @@ int32_t AppSchedulerProxy::ScheduleNotifyHotReloadPage() return reply.ReadInt32(); } -int32_t AppSchedulerProxy::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppSchedulerProxy::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); MessageParcel data; @@ -453,6 +465,11 @@ int32_t AppSchedulerProxy::ScheduleNotifyUnLoadRepairPatch(const std::string &bu return ERR_INVALID_DATA; } + if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { + HILOG_ERROR("Write callback failed."); + return ERR_INVALID_DATA; + } + sptr remote = Remote(); if (remote == nullptr) { HILOG_ERROR("Schedule notify unload patch, Remote is nullptr"); diff --git a/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_proxy.cpp new file mode 100644 index 0000000000..5de4b2fce0 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_proxy.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2022 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 "quick_fix_callback_proxy.h" + +#include "hilog_wrapper.h" +#include "message_parcel.h" +#include "parcel_macro_base.h" + +namespace OHOS { +namespace AppExecFwk { +void QuickFixCallbackProxy::OnLoadPatchDone(int32_t resultCode) +{ + HILOG_DEBUG("function called."); + + MessageParcel data; + MessageParcel reply; + WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor()); + WRITE_PARCEL_AND_RETURN(Int32, data, resultCode); + if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_LOAD_PATCH, data, reply)) { + return; + } + + HILOG_DEBUG("function finished."); + return; +} + +void QuickFixCallbackProxy::OnUnloadPatchDone(int32_t resultCode) +{ + HILOG_DEBUG("function called."); + + MessageParcel data; + MessageParcel reply; + WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor()); + WRITE_PARCEL_AND_RETURN(Int32, data, resultCode); + if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_UNLOAD_PATCH, data, reply)) { + return; + } + + HILOG_DEBUG("function finished."); + return; +} + +void QuickFixCallbackProxy::OnReloadPageDone(int32_t resultCode) +{ + HILOG_DEBUG("function called."); + + MessageParcel data; + MessageParcel reply; + WRITE_PARCEL_AND_RETURN(InterfaceToken, data, QuickFixCallbackProxy::GetDescriptor()); + WRITE_PARCEL_AND_RETURN(Int32, data, resultCode); + if (!SendRequestWithCmd(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_RELOAD_PAGE, data, reply)) { + return; + } + + HILOG_DEBUG("function finished."); + return; +} + +bool QuickFixCallbackProxy::SendRequestWithCmd(uint32_t code, MessageParcel &data, MessageParcel &reply) +{ + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote is nullptr."); + return false; + } + + MessageOption option(MessageOption::TF_SYNC); + auto ret = remote->SendRequest(code, data, reply, option); + if (ret != 0) { + HILOG_ERROR("Send request failed with error %{public}d.", ret); + return false; + } + + return true; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_stub.cpp new file mode 100644 index 0000000000..1c7d6a13f3 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/quick_fix_callback_stub.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 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 "quick_fix_callback_stub.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +QuickFixCallbackStub::QuickFixCallbackStub() +{ + requestFuncMap_[ON_NOTIFY_LOAD_PATCH] = &QuickFixCallbackStub::HandleOnLoadPatchDoneInner; + requestFuncMap_[ON_NOTIFY_UNLOAD_PATCH] = &QuickFixCallbackStub::HandleOnUnloadPatchDoneInner; + requestFuncMap_[ON_NOTIFY_RELOAD_PAGE] = &QuickFixCallbackStub::HandleOnReloadPageDoneInner; +} + +QuickFixCallbackStub::~QuickFixCallbackStub() +{ + requestFuncMap_.clear(); +} + +int QuickFixCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != IQuickFixCallback::GetDescriptor()) { + HILOG_ERROR("local descriptor is not equal to remote."); + return ERR_INVALID_STATE; + } + + auto itFunc = requestFuncMap_.find(code); + if (itFunc != requestFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + + HILOG_WARN("default case, need check value of code."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t QuickFixCallbackStub::HandleOnLoadPatchDoneInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t resultCode = data.ReadInt32(); + OnLoadPatchDone(resultCode); + return ERR_OK; +} + +int32_t QuickFixCallbackStub::HandleOnUnloadPatchDoneInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t resultCode = data.ReadInt32(); + OnUnloadPatchDone(resultCode); + return ERR_OK; +} + +int32_t QuickFixCallbackStub::HandleOnReloadPageDoneInner(MessageParcel &data, MessageParcel &reply) +{ + int32_t resultCode = data.ReadInt32(); + OnReloadPageDone(resultCode); + return ERR_OK; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/interfaces/inner_api/quick_fix/BUILD.gn b/interfaces/inner_api/quick_fix/BUILD.gn index 92cf40a00f..90d8e6c075 100644 --- a/interfaces/inner_api/quick_fix/BUILD.gn +++ b/interfaces/inner_api/quick_fix/BUILD.gn @@ -38,8 +38,6 @@ ohos_shared_library("quickfix_manager") { defines = [ "AMS_LOG_TAG = \"QuickFixService\"" ] - deps = [ "${ability_runtime_services_path}/common:perm_verification" ] - external_deps = [ "ability_base:want", "ability_runtime:app_manager", diff --git a/interfaces/inner_api/quick_fix/include/quick_fix_manager_interface.h b/interfaces/inner_api/quick_fix/include/quick_fix_manager_interface.h index 5ce083401c..08054a8f85 100644 --- a/interfaces/inner_api/quick_fix/include/quick_fix_manager_interface.h +++ b/interfaces/inner_api/quick_fix/include/quick_fix_manager_interface.h @@ -16,8 +16,6 @@ #ifndef OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_INTERFACE_H #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_INTERFACE_H -#include - #include "iremote_broker.h" #include "quick_fix_info.h" diff --git a/interfaces/inner_api/quick_fix/src/quick_fix_manager_proxy.cpp b/interfaces/inner_api/quick_fix/src/quick_fix_manager_proxy.cpp index 8f6a8b3e80..85d8a92a9b 100644 --- a/interfaces/inner_api/quick_fix/src/quick_fix_manager_proxy.cpp +++ b/interfaces/inner_api/quick_fix/src/quick_fix_manager_proxy.cpp @@ -15,10 +15,10 @@ #include "quick_fix_manager_proxy.h" +#include "appexecfwk_errors.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" #include "message_parcel.h" -#include "permission_verification.h" #include "quick_fix_error_utils.h" #include "quick_fix_util.h" @@ -29,10 +29,6 @@ int32_t QuickFixManagerProxy::ApplyQuickFix(const std::vector &quic HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) { - return QUICK_FIX_VERIFY_PERMISSION_FAILED; - } - auto bundleQuickFixMgr = QuickFixUtil::GetBundleQuickFixMgrProxy(); if (bundleQuickFixMgr == nullptr) { return QUICK_FIX_CONNECT_FAILED; @@ -40,9 +36,11 @@ int32_t QuickFixManagerProxy::ApplyQuickFix(const std::vector &quic HILOG_DEBUG("hqf file number need to apply: %{public}zu.", quickFixFiles.size()); std::vector destFiles; - if (bundleQuickFixMgr->CopyFiles(quickFixFiles, destFiles) != 0) { + auto copyRet = bundleQuickFixMgr->CopyFiles(quickFixFiles, destFiles); + if (copyRet != 0) { HILOG_ERROR("Copy files failed."); - return QUICK_FIX_COPY_FILES_FAILED; + return (copyRet == ERR_BUNDLEMANAGER_QUICK_FIX_PERMISSION_DENIED) ? QUICK_FIX_VERIFY_PERMISSION_FAILED : + QUICK_FIX_COPY_FILES_FAILED; } MessageParcel data; @@ -80,10 +78,6 @@ int32_t QuickFixManagerProxy::GetApplyedQuickFixInfo(const std::string &bundleNa HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) { - return QUICK_FIX_VERIFY_PERMISSION_FAILED; - } - MessageParcel data; if (!data.WriteInterfaceToken(AAFwk::IQuickFixManager::GetDescriptor())) { HILOG_ERROR("GetApplyedQuickFixInfo, Write interface token failed."); diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index ede667c73c..7350473f7a 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -66,9 +66,9 @@ public: virtual void NotifyApplicationState(bool isBackground) = 0; virtual void PreloadSystemModule(const std::string& moduleName) = 0; virtual void FinishPreload() = 0; - virtual void LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; - virtual void NotifyHotReloadPage() = 0; - virtual void UnLoadRepairPatch(const std::string& patchFile) = 0; + virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; + virtual bool NotifyHotReloadPage() = 0; + virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0; Runtime(const Runtime&) = delete; Runtime(Runtime&&) = delete; diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index debd745348..9158a6cb83 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -225,11 +225,13 @@ public: */ void CheckMainThreadIsAlive(); - int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName) override; + int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override; - int32_t ScheduleNotifyHotReloadPage() override; + int32_t ScheduleNotifyHotReloadPage(const sptr &callback) override; - int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) override; + int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override; private: /** diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index 96bd0144c9..58ecb12d0f 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -280,11 +280,11 @@ public: */ void SetExtensionTypeMap(std::map map); - void NotifyLoadRepairPatch(const std::string &hqfFile, const std::string &hapPath); + bool NotifyLoadRepairPatch(const std::string &hqfFile, const std::string &hapPath); - void NotifyHotReloadPage(); + bool NotifyHotReloadPage(); - void NotifyUnLoadRepairPatch(const std::string &hqfFile); + bool NotifyUnLoadRepairPatch(const std::string &hqfFile); private: std::list> abilityLifecycleCallbacks_; diff --git a/services/appmgr/include/app_lifecycle_deal.h b/services/appmgr/include/app_lifecycle_deal.h index 9b54341351..196de67bf3 100644 --- a/services/appmgr/include/app_lifecycle_deal.h +++ b/services/appmgr/include/app_lifecycle_deal.h @@ -151,11 +151,11 @@ public: */ int32_t UpdateConfiguration(const Configuration &config); - int32_t NotifyLoadRepairPatch(const std::string &bundleName); + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback); - int32_t NotifyHotReloadPage(); + int32_t NotifyHotReloadPage(const sptr &callback); - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName); + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback); private: sptr appThread_ = nullptr; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index bfe048189f..2415b8900b 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -242,11 +242,11 @@ public: bool GetAppRunningStateByBundleName(const std::string &bundleName) override; - int32_t NotifyLoadRepairPatch(const std::string &bundleName) override; + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; - int32_t NotifyHotReloadPage(const std::string &bundleName) override; + int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) override; - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName) override; + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 9163afd69a..bb945eb285 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -551,11 +551,11 @@ public: bool GetAppRunningStateByBundleName(const std::string &bundleName); - int32_t NotifyLoadRepairPatch(const std::string &bundleName); + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback); - int32_t NotifyHotReloadPage(const std::string &bundleName); + int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback); - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName); + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback); void HandleFocused(const sptr &focusChangeInfo); void HandleUnfocused(const sptr &focusChangeInfo); diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index f95a8ad29f..9930ad54a4 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -162,9 +162,9 @@ public: std::shared_ptr OnRemoteRenderDied(const wptr &remote); bool ProcessExitByPid(pid_t pid); bool GetAppRunningStateByBundleName(const std::string &bundleName); - int32_t NotifyLoadRepairPatch(const std::string &bundleName); - int32_t NotifyHotReloadPage(const std::string &bundleName); - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName); + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback); + int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr &callback); + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback); bool IsApplicationFirstForeground(const AppRunningRecord &foregroundingRecord); bool IsApplicationBackground(const std::string &bundleName); bool IsApplicationFirstFocused(const AppRunningRecord &foregroundingRecord); diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 06946e4ecc..a8d5ab4b5f 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -523,11 +523,11 @@ public: void PostTask(std::string msg, int64_t timeOut, const Closure &task); void RemoveTerminateAbilityTimeoutTask(const sptr& token) const; - int32_t NotifyLoadRepairPatch(const std::string &bundleName); + int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback); - int32_t NotifyHotReloadPage(); + int32_t NotifyHotReloadPage(const sptr &callback); - int32_t NotifyUnLoadRepairPatch(const std::string &bundleName); + int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback); bool IsContinuousTask(); diff --git a/services/appmgr/src/app_lifecycle_deal.cpp b/services/appmgr/src/app_lifecycle_deal.cpp index 378ffb29fa..8e36926ba0 100644 --- a/services/appmgr/src/app_lifecycle_deal.cpp +++ b/services/appmgr/src/app_lifecycle_deal.cpp @@ -163,7 +163,7 @@ int32_t AppLifeCycleDeal::UpdateConfiguration(const Configuration &config) return ERR_OK; } -int32_t AppLifeCycleDeal::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppLifeCycleDeal::NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("call %{public}s", __func__); @@ -171,10 +171,10 @@ int32_t AppLifeCycleDeal::NotifyLoadRepairPatch(const std::string &bundleName) HILOG_ERROR("appThread_ is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyLoadRepairPatch(bundleName); + return appThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback); } -int32_t AppLifeCycleDeal::NotifyHotReloadPage() +int32_t AppLifeCycleDeal::NotifyHotReloadPage(const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("call %{public}s", __func__); @@ -182,10 +182,11 @@ int32_t AppLifeCycleDeal::NotifyHotReloadPage() HILOG_ERROR("appThread_ is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyHotReloadPage(); + return appThread_->ScheduleNotifyHotReloadPage(callback); } -int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -193,7 +194,7 @@ int32_t AppLifeCycleDeal::NotifyUnLoadRepairPatch(const std::string &bundleName) HILOG_ERROR("appThread_ is nullptr."); return ERR_INVALID_VALUE; } - return appThread_->ScheduleNotifyUnLoadRepairPatch(bundleName); + return appThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 0c6c76d217..b8c444e104 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -548,24 +548,24 @@ bool AppMgrService::GetAppRunningStateByBundleName(const std::string &bundleName return appMgrServiceInner_->GetAppRunningStateByBundleName(bundleName); } -int32_t AppMgrService::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrService::NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) { if (!IsReady()) { HILOG_ERROR("AppMgrService is not ready."); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->NotifyLoadRepairPatch(bundleName); + return appMgrServiceInner_->NotifyLoadRepairPatch(bundleName, callback); } -int32_t AppMgrService::NotifyHotReloadPage(const std::string &bundleName) +int32_t AppMgrService::NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) { if (!IsReady()) { HILOG_ERROR("AppMgrService is not ready."); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->NotifyHotReloadPage(bundleName); + return appMgrServiceInner_->NotifyHotReloadPage(bundleName, callback); } #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE @@ -580,14 +580,14 @@ int32_t AppMgrService::SetContinuousTaskProcess(int32_t pid, bool isContinuousTa } #endif -int32_t AppMgrService::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrService::NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr &callback) { if (!IsReady()) { HILOG_ERROR("AppMgrService is not ready."); return ERR_INVALID_OPERATION; } - return appMgrServiceInner_->NotifyUnLoadRepairPatch(bundleName); + return appMgrServiceInner_->NotifyUnLoadRepairPatch(bundleName, callback); } } // 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 727c1d3a60..73f26b0c65 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2799,7 +2799,8 @@ bool AppMgrServiceInner::GetAppRunningStateByBundleName(const std::string &bundl return appRunningManager_->GetAppRunningStateByBundleName(bundleName); } -int32_t AppMgrServiceInner::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrServiceInner::NotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -2808,10 +2809,10 @@ int32_t AppMgrServiceInner::NotifyLoadRepairPatch(const std::string &bundleName) return ERR_INVALID_OPERATION; } - return appRunningManager_->NotifyLoadRepairPatch(bundleName); + return appRunningManager_->NotifyLoadRepairPatch(bundleName, callback); } -int32_t AppMgrServiceInner::NotifyHotReloadPage(const std::string &bundleName) +int32_t AppMgrServiceInner::NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -2820,7 +2821,7 @@ int32_t AppMgrServiceInner::NotifyHotReloadPage(const std::string &bundleName) return ERR_INVALID_OPERATION; } - return appRunningManager_->NotifyHotReloadPage(bundleName); + return appRunningManager_->NotifyHotReloadPage(bundleName, callback); } #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE @@ -2849,7 +2850,8 @@ int32_t AppMgrServiceInner::SetContinuousTaskProcess(int32_t pid, bool isContinu } #endif -int32_t AppMgrServiceInner::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppMgrServiceInner::NotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -2858,7 +2860,7 @@ int32_t AppMgrServiceInner::NotifyUnLoadRepairPatch(const std::string &bundleNam return ERR_INVALID_OPERATION; } - return appRunningManager_->NotifyUnLoadRepairPatch(bundleName); + return appRunningManager_->NotifyUnLoadRepairPatch(bundleName, callback); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 87fceec796..e8ecd36462 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -599,7 +599,7 @@ bool AppRunningManager::GetAppRunningStateByBundleName(const std::string &bundle return false; } -int32_t AppRunningManager::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppRunningManager::NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -610,7 +610,7 @@ int32_t AppRunningManager::NotifyLoadRepairPatch(const std::string &bundleName) const auto &appRecord = item.second; if (appRecord && appRecord->GetBundleName() == bundleName) { HILOG_DEBUG("Notify application [%{public}s] load patch.", appRecord->GetProcessName().c_str()); - result = appRecord->NotifyLoadRepairPatch(bundleName); + result = appRecord->NotifyLoadRepairPatch(bundleName, callback); if (result == ERR_OK) { loadSucceed = true; } @@ -619,7 +619,7 @@ int32_t AppRunningManager::NotifyLoadRepairPatch(const std::string &bundleName) return loadSucceed == true ? ERR_OK : result; } -int32_t AppRunningManager::NotifyHotReloadPage(const std::string &bundleName) +int32_t AppRunningManager::NotifyHotReloadPage(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -629,13 +629,14 @@ int32_t AppRunningManager::NotifyHotReloadPage(const std::string &bundleName) const auto &appRecord = item.second; if (appRecord && appRecord->GetBundleName() == bundleName) { HILOG_DEBUG("Notify application [%{public}s] reload page.", appRecord->GetProcessName().c_str()); - result = appRecord->NotifyHotReloadPage(); + result = appRecord->NotifyHotReloadPage(callback); } } return result; } -int32_t AppRunningManager::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppRunningManager::NotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -646,7 +647,7 @@ int32_t AppRunningManager::NotifyUnLoadRepairPatch(const std::string &bundleName const auto &appRecord = item.second; if (appRecord && appRecord->GetBundleName() == bundleName) { HILOG_DEBUG("Notify application [%{public}s] unload patch.", appRecord->GetProcessName().c_str()); - result = appRecord->NotifyUnLoadRepairPatch(bundleName); + result = appRecord->NotifyUnLoadRepairPatch(bundleName, callback); if (result == ERR_OK) { unLoadSucceed = true; } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 6262d6c716..933d14afbf 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1266,7 +1266,7 @@ void AppRunningRecord::RemoveTerminateAbilityTimeoutTask(const sptrRemoveTerminateAbilityTimeoutTask(token); } -int32_t AppRunningRecord::NotifyLoadRepairPatch(const std::string &bundleName) +int32_t AppRunningRecord::NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -1274,10 +1274,10 @@ int32_t AppRunningRecord::NotifyLoadRepairPatch(const std::string &bundleName) HILOG_ERROR("appLifeCycleDeal_ is null"); return ERR_INVALID_VALUE; } - return appLifeCycleDeal_->NotifyLoadRepairPatch(bundleName); + return appLifeCycleDeal_->NotifyLoadRepairPatch(bundleName, callback); } -int32_t AppRunningRecord::NotifyHotReloadPage() +int32_t AppRunningRecord::NotifyHotReloadPage(const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -1285,10 +1285,11 @@ int32_t AppRunningRecord::NotifyHotReloadPage() HILOG_ERROR("appLifeCycleDeal_ is null"); return ERR_INVALID_VALUE; } - return appLifeCycleDeal_->NotifyHotReloadPage(); + return appLifeCycleDeal_->NotifyHotReloadPage(callback); } -int32_t AppRunningRecord::NotifyUnLoadRepairPatch(const std::string &bundleName) +int32_t AppRunningRecord::NotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); @@ -1296,7 +1297,7 @@ int32_t AppRunningRecord::NotifyUnLoadRepairPatch(const std::string &bundleName) HILOG_ERROR("appLifeCycleDeal_ is null"); return ERR_INVALID_VALUE; } - return appLifeCycleDeal_->NotifyUnLoadRepairPatch(bundleName); + return appLifeCycleDeal_->NotifyUnLoadRepairPatch(bundleName, callback); } bool AppRunningRecord::IsContinuousTask() diff --git a/services/quickfixmgr/BUILD.gn b/services/quickfixmgr/BUILD.gn index 7e281ea474..0bf46b2ad0 100644 --- a/services/quickfixmgr/BUILD.gn +++ b/services/quickfixmgr/BUILD.gn @@ -42,6 +42,8 @@ ohos_shared_library("quickfixms") { defines = [ "AMS_LOG_TAG = \"QuickFixService\"" ] + deps = [ "${ability_runtime_services_path}/common:perm_verification" ] + external_deps = [ "ability_base:want", "ability_runtime:app_manager", diff --git a/services/quickfixmgr/include/quick_fix_manager_apply_task.h b/services/quickfixmgr/include/quick_fix_manager_apply_task.h index f26e7790a8..98269b95ce 100644 --- a/services/quickfixmgr/include/quick_fix_manager_apply_task.h +++ b/services/quickfixmgr/include/quick_fix_manager_apply_task.h @@ -45,12 +45,16 @@ public: void NotifyApplyStatus(int32_t applyResult); void RemoveSelf(); -private: - void PostDeployQuickFixTask(const std::vector &quickFixFiles); void PostSwitchQuickFixTask(); void PostDeleteQuickFixTask(); +private: + void PostDeployQuickFixTask(const std::vector &quickFixFiles); void PostTimeOutTask(); + void NotifyLoadRepairPatch(); + void NotifyUnloadRepairPatch(); + void NotifyHotReloadPage(); + void RegAppStateObserver(); sptr bundleQfMgr_ = nullptr; sptr appMgr_ = nullptr; diff --git a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp index 3f3562f580..e7aec31a1e 100644 --- a/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_apply_task.cpp @@ -21,6 +21,7 @@ #include "common_event_support.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "quick_fix_callback_stub.h" #include "quick_fix_error_utils.h" #include "quick_fix_manager_service.h" #include "quick_fix/quick_fix_status_callback_host.h" @@ -172,6 +173,58 @@ private: std::shared_ptr applyTask_; }; +class QuickFixNotifyCallback : public AppExecFwk::QuickFixCallbackStub { +public: + explicit QuickFixNotifyCallback(std::shared_ptr applyTask) + : applyTask_(applyTask) + {} + + virtual ~QuickFixNotifyCallback() = default; + + void OnLoadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + if (resultCode != 0) { + HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_LOAD_PATCH_FAILED); + applyTask_->RemoveSelf(); + return; + } + + applyTask_->PostDeleteQuickFixTask(); + } + + void OnUnloadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + if (resultCode != 0) { + HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); + applyTask_->RemoveSelf(); + return; + } + + applyTask_->PostSwitchQuickFixTask(); + } + + void OnReloadPageDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + if (resultCode != 0) { + HILOG_ERROR("Notify app load patch failed with %{public}d.", resultCode); + applyTask_->NotifyApplyStatus(QUICK_FIX_NOTIFY_RELOAD_PAGE_FAILED); + applyTask_->RemoveSelf(); + return; + } + + applyTask_->NotifyApplyStatus(QUICK_FIX_OK); + applyTask_->RemoveSelf(); + } + +private: + std::shared_ptr applyTask_; +}; + void QuickFixManagerApplyTask::Run(const std::vector &quickFixFiles) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -184,27 +237,9 @@ void QuickFixManagerApplyTask::HandlePatchDeployed() HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - if (appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr."); - NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); - RemoveSelf(); - return; - } - isRunning_ = GetRunningState(); if (isRunning_ && isSoContained_) { - HILOG_INFO("Start to register application state observer."); - std::vector bundleNameList; - bundleNameList.push_back(bundleName_); - sptr callback = new QuickFixMgrAppStateObserver(shared_from_this()); - auto ret = appMgr_->RegisterApplicationStateObserver(callback, bundleNameList); - if (ret != 0) { - HILOG_ERROR("Register application state observer failed."); - NotifyApplyStatus(QUICK_FIX_REGISTER_OBSERVER_FAILED); - RemoveSelf(); - } - HILOG_DEBUG("Register application state observer succeed."); - return; + return RegAppStateObserver(); } else if (isRunning_ && !isSoContained_) { ApplicationQuickFixInfo quickFixInfo; auto service = quickFixMgrService_.promote(); @@ -219,13 +254,7 @@ void QuickFixManagerApplyTask::HandlePatchDeployed() if (ret == QUICK_FIX_OK && !quickFixInfo.appqfInfo.hqfInfos.empty()) { // if there exist old version hqfInfo, need to unload. HILOG_DEBUG("Need unload patch firstly."); - ret = appMgr_->NotifyUnLoadRepairPatch(bundleName_); - if (ret != 0) { - HILOG_ERROR("Notify app unload patch failed."); - NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); - RemoveSelf(); - return; - } + return NotifyUnloadRepairPatch(); } } @@ -238,20 +267,7 @@ void QuickFixManagerApplyTask::HandlePatchSwitched() HILOG_DEBUG("function called."); if (isRunning_ && !isSoContained_) { - if (appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr."); - NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); - RemoveSelf(); - return; - } - - auto ret = appMgr_->NotifyLoadRepairPatch(bundleName_); - if (ret != 0) { - HILOG_ERROR("Notify app load patch failed."); - NotifyApplyStatus(QUICK_FIX_NOTIFY_LOAD_PATCH_FAILED); - RemoveSelf(); - return; - } + return NotifyLoadRepairPatch(); } PostDeleteQuickFixTask(); @@ -263,20 +279,7 @@ void QuickFixManagerApplyTask::HandlePatchDeleted() HILOG_DEBUG("function called."); if (isRunning_ && !isSoContained_ && type_ == AppExecFwk::QuickFixType::HOT_RELOAD) { - if (appMgr_ == nullptr) { - HILOG_ERROR("Appmgr is nullptr."); - NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); - RemoveSelf(); - return; - } - - auto ret = appMgr_->NotifyHotReloadPage(bundleName_); - if (ret != 0) { - HILOG_ERROR("Notify app reload page failed."); - NotifyApplyStatus(QUICK_FIX_NOTIFY_RELOAD_PAGE_FAILED); - RemoveSelf(); - return; - } + return NotifyHotReloadPage(); } NotifyApplyStatus(QUICK_FIX_OK); @@ -472,6 +475,82 @@ void QuickFixManagerApplyTask::NotifyApplyStatus(int32_t applyResult) EventFwk::CommonEventManager::PublishCommonEvent(commonData); } +void QuickFixManagerApplyTask::NotifyLoadRepairPatch() +{ + if (appMgr_ == nullptr) { + HILOG_ERROR("Appmgr is nullptr."); + NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); + RemoveSelf(); + return; + } + + sptr callback = new QuickFixNotifyCallback(shared_from_this()); + auto ret = appMgr_->NotifyLoadRepairPatch(bundleName_, callback); + if (ret != 0) { + HILOG_ERROR("Notify app load patch failed."); + NotifyApplyStatus(QUICK_FIX_NOTIFY_LOAD_PATCH_FAILED); + RemoveSelf(); + } +} + +void QuickFixManagerApplyTask::NotifyUnloadRepairPatch() +{ + if (appMgr_ == nullptr) { + HILOG_ERROR("Appmgr is nullptr."); + NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); + RemoveSelf(); + return; + } + + sptr callback = new QuickFixNotifyCallback(shared_from_this()); + auto ret = appMgr_->NotifyUnLoadRepairPatch(bundleName_, callback); + if (ret != 0) { + HILOG_ERROR("Notify app unload patch failed."); + NotifyApplyStatus(QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED); + RemoveSelf(); + } +} + +void QuickFixManagerApplyTask::NotifyHotReloadPage() +{ + if (appMgr_ == nullptr) { + HILOG_ERROR("Appmgr is nullptr."); + NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); + RemoveSelf(); + return; + } + + sptr callback = new QuickFixNotifyCallback(shared_from_this()); + auto ret = appMgr_->NotifyHotReloadPage(bundleName_, callback); + if (ret != 0) { + HILOG_ERROR("Notify app reload page failed."); + NotifyApplyStatus(QUICK_FIX_NOTIFY_RELOAD_PAGE_FAILED); + RemoveSelf(); + } +} + +void QuickFixManagerApplyTask::RegAppStateObserver() +{ + HILOG_DEBUG("Start to register application state observer."); + if (appMgr_ == nullptr) { + HILOG_ERROR("Appmgr is nullptr."); + NotifyApplyStatus(QUICK_FIX_APPMGR_INVALID); + RemoveSelf(); + return; + } + + std::vector bundleNameList; + bundleNameList.push_back(bundleName_); + sptr callback = new QuickFixMgrAppStateObserver(shared_from_this()); + auto ret = appMgr_->RegisterApplicationStateObserver(callback, bundleNameList); + if (ret != 0) { + HILOG_ERROR("Register application state observer failed."); + NotifyApplyStatus(QUICK_FIX_REGISTER_OBSERVER_FAILED); + RemoveSelf(); + } + HILOG_DEBUG("Register application state observer succeed."); +} + void QuickFixManagerApplyTask::RemoveSelf() { auto service = quickFixMgrService_.promote(); diff --git a/services/quickfixmgr/src/quick_fix_manager_service.cpp b/services/quickfixmgr/src/quick_fix_manager_service.cpp index 9eae7d66d8..56a7c0dfa4 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service.cpp @@ -17,6 +17,7 @@ #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "permission_verification.h" #include "quick_fix_error_utils.h" #include "quick_fix_util.h" @@ -58,6 +59,10 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector &qu HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); + if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) { + return QUICK_FIX_VERIFY_PERMISSION_FAILED; + } + auto bundleQfMgr = QuickFixUtil::GetBundleQuickFixMgrProxy(); if (bundleQfMgr == nullptr) { HILOG_ERROR("Bundle quick fix manager is nullptr."); @@ -84,6 +89,10 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); + if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) { + return QUICK_FIX_VERIFY_PERMISSION_FAILED; + } + auto bundleMgr = QuickFixUtil::GetBundleManagerProxy(); if (bundleMgr == nullptr) { HILOG_ERROR("Failed to get bundle manager."); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 7bb328e5ed..80d7cafb50 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -59,9 +59,11 @@ public: MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr &observer)); MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr &observer)); MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string &bundleName)); - MOCK_METHOD1(NotifyLoadRepairPatch, int32_t(const std::string &bundleName)); - MOCK_METHOD1(NotifyHotReloadPage, int32_t(const std::string &bundleName)); - MOCK_METHOD1(NotifyUnLoadRepairPatch, int32_t(const std::string &bundleName)); + MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); + MOCK_METHOD2(NotifyHotReloadPage, int32_t(const std::string &bundleName, const sptr &callback)); + MOCK_METHOD2(NotifyUnLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); void AttachApplication(const sptr &app) { diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index e63d1aeaf8..8dbd809812 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -34,9 +34,18 @@ public: } void StartDebugMode(bool needBreakPoint) {} void FinishPreload() {} - void LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) {} - void NotifyHotReloadPage() {} - void UnLoadRepairPatch(const std::string& patchFile) {} + bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) + { + return true; + } + bool NotifyHotReloadPage() + { + return true; + } + bool UnLoadRepairPatch(const std::string& patchFile) + { + return true; + } bool RunScript(const std::string& path, const std::string& hapPath) { return true; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index c48633fa98..95f5b2e229 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -66,9 +66,11 @@ public: MOCK_METHOD0(BlockAppService, int()); #endif MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string &bundleName)); - MOCK_METHOD1(NotifyLoadRepairPatch, int32_t(const std::string &bundleName)); - MOCK_METHOD1(NotifyHotReloadPage, int32_t(const std::string &bundleName)); - MOCK_METHOD1(NotifyUnLoadRepairPatch, int32_t(const std::string &bundleName)); + MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); + MOCK_METHOD2(NotifyHotReloadPage, int32_t(const std::string &bundleName, const sptr &callback)); + MOCK_METHOD2(NotifyUnLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) 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 70477d1f47..3acd977617 100644 --- a/test/mock/services_appmgr_test/include/mock_app_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_app_scheduler.h @@ -43,9 +43,11 @@ public: MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo &)); MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want &want, const std::string &moduleName)); - MOCK_METHOD1(ScheduleNotifyLoadRepairPatch, int32_t(const std::string &bundleName)); - MOCK_METHOD0(ScheduleNotifyHotReloadPage, int32_t()); - MOCK_METHOD1(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string &bundleName)); + MOCK_METHOD2(ScheduleNotifyLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); + MOCK_METHOD1(ScheduleNotifyHotReloadPage, int32_t(const sptr &callback)); + MOCK_METHOD2(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_appmgr_test/include/mock_application.h b/test/mock/services_appmgr_test/include/mock_application.h index 1fb25a62ff..4bfb83bd7d 100644 --- a/test/mock/services_appmgr_test/include/mock_application.h +++ b/test/mock/services_appmgr_test/include/mock_application.h @@ -38,9 +38,11 @@ public: MOCK_METHOD0(ScheduleProcessSecurityExit, void()); MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo &)); MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want &want, const std::string &moduleName)); - MOCK_METHOD1(ScheduleNotifyLoadRepairPatch, int32_t(const std::string &bundleName)); - MOCK_METHOD0(ScheduleNotifyHotReloadPage, int32_t()); - MOCK_METHOD1(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string &bundleName)); + MOCK_METHOD2(ScheduleNotifyLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); + MOCK_METHOD1(ScheduleNotifyHotReloadPage, int32_t(const sptr &callback)); + MOCK_METHOD2(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string &bundleName, + const sptr &callback)); void Post() { 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 6fa61859cc..ac1e6207c9 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 @@ -134,17 +134,19 @@ public: void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override {} - int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName) override + int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override { return 0; } - int32_t ScheduleNotifyHotReloadPage() override + int32_t ScheduleNotifyHotReloadPage(const sptr &callback) override { return 0; } - int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) override + int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override { return 0; } 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 cb5e74757c..a7b49a0887 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 @@ -71,15 +71,17 @@ public: {} void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override {} - int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName) override + int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override { return 0; } - int32_t ScheduleNotifyHotReloadPage() override + int32_t ScheduleNotifyHotReloadPage(const sptr &callback) override { return 0; } - int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName) override + int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName, + const sptr &callback) override { return 0; } diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 76dfaab6ec..9e829ab561 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -18,6 +18,7 @@ #include "mock_app_mgr_service.h" #include "app_mgr_proxy.h" #include "hilog_wrapper.h" +#include "quick_fix_callback_stub.h" using namespace testing; using namespace testing::ext; @@ -28,6 +29,27 @@ namespace { const int32_t USER_ID = 100; } // namespace +class QuickFixCallbackImpl : public AppExecFwk::QuickFixCallbackStub { +public: + QuickFixCallbackImpl() = default; + virtual ~QuickFixCallbackImpl() = default; + + void OnLoadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } + + void OnUnloadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } + + void OnReloadPageDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } +}; + class AppMgrProxyTest : public testing::Test { public: static void SetUpTestCase(); @@ -116,7 +138,8 @@ HWTEST_F(AppMgrProxyTest, NotifyLoadRepairPatch_0100, TestSize.Level0) .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); std::string bundleName = "testBundleName"; - appMgrProxy_->NotifyLoadRepairPatch(bundleName); + sptr callback = new QuickFixCallbackImpl(); + appMgrProxy_->NotifyLoadRepairPatch(bundleName, callback); EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::NOTIFY_LOAD_REPAIR_PATCH)); @@ -138,7 +161,8 @@ HWTEST_F(AppMgrProxyTest, NotifyHotReloadPage_0100, TestSize.Level0) .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); std::string bundleName = "testBundleName"; - appMgrProxy_->NotifyHotReloadPage(bundleName); + sptr callback = new QuickFixCallbackImpl(); + appMgrProxy_->NotifyHotReloadPage(bundleName, callback); EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::NOTIFY_HOT_RELOAD_PAGE)); @@ -160,7 +184,8 @@ HWTEST_F(AppMgrProxyTest, NotifyUnLoadRepairPatch_0100, TestSize.Level0) .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); std::string bundleName = "testBundleName"; - appMgrProxy_->NotifyUnLoadRepairPatch(bundleName); + sptr callback = new QuickFixCallbackImpl(); + appMgrProxy_->NotifyUnLoadRepairPatch(bundleName, callback); EXPECT_EQ(mockAppMgrService_->code_, static_cast(IAppMgr::Message::NOTIFY_UNLOAD_REPAIR_PATCH)); diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 1f2295bd65..fa1f74f070 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -134,7 +134,7 @@ HWTEST_F(AppMgrStubTest, HandleNotifyLoadRepairPatch_0100, TestSize.Level0) std::string bundleName = "testBundleName"; data.WriteString(bundleName); - EXPECT_CALL(*mockAppMgrService_, NotifyLoadRepairPatch(_)).Times(1); + EXPECT_CALL(*mockAppMgrService_, NotifyLoadRepairPatch(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(IAppMgr::Message::NOTIFY_LOAD_REPAIR_PATCH), data, reply, option); @@ -161,7 +161,7 @@ HWTEST_F(AppMgrStubTest, HandleNotifyHotReloadPage_0100, TestSize.Level0) std::string bundleName = "testBundleName"; data.WriteString(bundleName); - EXPECT_CALL(*mockAppMgrService_, NotifyHotReloadPage(_)).Times(1); + EXPECT_CALL(*mockAppMgrService_, NotifyHotReloadPage(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(IAppMgr::Message::NOTIFY_HOT_RELOAD_PAGE), data, reply, option); @@ -188,7 +188,7 @@ HWTEST_F(AppMgrStubTest, HandleNotifyUnLoadRepairPatch_0100, TestSize.Level0) std::string bundleName = "testBundleName"; data.WriteString(bundleName); - EXPECT_CALL(*mockAppMgrService_, NotifyUnLoadRepairPatch(_)).Times(1); + EXPECT_CALL(*mockAppMgrService_, NotifyUnLoadRepairPatch(_, _)).Times(1); auto result = mockAppMgrService_->OnRemoteRequest( static_cast(IAppMgr::Message::NOTIFY_UNLOAD_REPAIR_PATCH), data, reply, option); diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index a9926c02a0..2f3d543a64 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -23,6 +23,7 @@ #include "main_thread.h" #undef private #include "mock_bundle_manager.h" +#include "quick_fix_callback_stub.h" #include "system_ability_definition.h" #include "sys_mgr_client.h" @@ -31,6 +32,27 @@ using namespace testing::ext; namespace OHOS { namespace AppExecFwk { +class QuickFixCallbackImpl : public AppExecFwk::QuickFixCallbackStub { +public: + QuickFixCallbackImpl() = default; + virtual ~QuickFixCallbackImpl() = default; + + void OnLoadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } + + void OnUnloadPatchDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } + + void OnReloadPageDone(int32_t resultCode) override + { + HILOG_DEBUG("function called."); + } +}; + class MainThreadTest : public testing::Test { public: static void SetUpTestCase(); @@ -81,7 +103,8 @@ HWTEST_F(MainThreadTest, ScheduleNotifyLoadRepairPatch_0100, TestSize.Level1) { HILOG_INFO("%{public}s start.", __func__); std::string bundleName; - auto ret = mainThread_->ScheduleNotifyLoadRepairPatch(bundleName); + sptr callback = new QuickFixCallbackImpl(); + auto ret = mainThread_->ScheduleNotifyLoadRepairPatch(bundleName, callback); EXPECT_EQ(ret, NO_ERROR); HILOG_INFO("%{public}s end.", __func__); } @@ -95,7 +118,8 @@ HWTEST_F(MainThreadTest, ScheduleNotifyLoadRepairPatch_0100, TestSize.Level1) HWTEST_F(MainThreadTest, ScheduleNotifyHotReloadPage_0100, TestSize.Level1) { HILOG_INFO("%{public}s start.", __func__); - auto ret = mainThread_->ScheduleNotifyHotReloadPage(); + sptr callback = new QuickFixCallbackImpl(); + auto ret = mainThread_->ScheduleNotifyHotReloadPage(callback); EXPECT_EQ(ret, NO_ERROR); HILOG_INFO("%{public}s end.", __func__); } @@ -131,7 +155,8 @@ HWTEST_F(MainThreadTest, ScheduleNotifyUnLoadRepairPatch_0100, TestSize.Level1) { HILOG_INFO("%{public}s start.", __func__); std::string bundleName; - auto ret = mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName); + sptr callback = new QuickFixCallbackImpl(); + auto ret = mainThread_->ScheduleNotifyUnLoadRepairPatch(bundleName, callback); EXPECT_EQ(ret, NO_ERROR); HILOG_INFO("%{public}s end.", __func__); } diff --git a/test/unittest/quick_fix/BUILD.gn b/test/unittest/quick_fix/BUILD.gn index 05536896d8..7e8388f35e 100644 --- a/test/unittest/quick_fix/BUILD.gn +++ b/test/unittest/quick_fix/BUILD.gn @@ -15,6 +15,8 @@ group("unittest") { testonly = true deps = [ + "quick_fix_callback_proxy_test:unittest", + "quick_fix_callback_stub_test:unittest", "quick_fix_info_test:unittest", "quick_fix_manager_client_test:unittest", "quick_fix_manager_proxy_test:unittest", diff --git a/test/unittest/quick_fix/mock/include/mock_quick_fix_callback_stub.h b/test/unittest/quick_fix/mock/include/mock_quick_fix_callback_stub.h new file mode 100644 index 0000000000..cdc19575cc --- /dev/null +++ b/test/unittest/quick_fix/mock/include/mock_quick_fix_callback_stub.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021-2022 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_MOCK_QUICK_FIX_CALLBACK_STUB_H +#define OHOS_ABILITY_RUNTIME_MOCK_QUICK_FIX_CALLBACK_STUB_H + +#include "gmock/gmock.h" +#include "quick_fix_callback_stub.h" + +namespace OHOS { +namespace AppExecFwk { +class MockQuickFixCallbackStub : public QuickFixCallbackStub { +public: + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); + MOCK_METHOD1(OnLoadPatchDone, void(int32_t resultCode)); + MOCK_METHOD1(OnUnloadPatchDone, void(int32_t resultCode)); + MOCK_METHOD1(OnReloadPageDone, void(int32_t resultCode)); + + int InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) + { + code_ = code; + return 0; + } + +private: + int code_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_MOCK_QUICK_FIX_CALLBACK_STUB_H diff --git a/test/unittest/quick_fix/quick_fix_callback_proxy_test/BUILD.gn b/test/unittest/quick_fix/quick_fix_callback_proxy_test/BUILD.gn new file mode 100644 index 0000000000..2c06e9c338 --- /dev/null +++ b/test/unittest/quick_fix/quick_fix_callback_proxy_test/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("quick_fix_callback_proxy_test") { + module_out_path = "ability_runtime/quick_fix" + + include_dirs = + [ "${ability_runtime_test_path}/unittest/quick_fix/mock/include" ] + + sources = [ "quick_fix_callback_proxy_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + deps = [ ":quick_fix_callback_proxy_test" ] +} diff --git a/test/unittest/quick_fix/quick_fix_callback_proxy_test/quick_fix_callback_proxy_test.cpp b/test/unittest/quick_fix/quick_fix_callback_proxy_test/quick_fix_callback_proxy_test.cpp new file mode 100644 index 0000000000..857478f18a --- /dev/null +++ b/test/unittest/quick_fix/quick_fix_callback_proxy_test/quick_fix_callback_proxy_test.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "hilog_wrapper.h" +#define private public +#include "mock_quick_fix_callback_stub.h" +#include "quick_fix_callback_proxy.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class QuickFixCallbackProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + sptr mockCallbackService_ = nullptr; + sptr quickFixMgrProxy_ = nullptr; +}; + +void QuickFixCallbackProxyTest::SetUpTestCase(void) +{} + +void QuickFixCallbackProxyTest::TearDownTestCase(void) +{} + +void QuickFixCallbackProxyTest::SetUp() +{ + mockCallbackService_ = new MockQuickFixCallbackStub(); + ASSERT_NE(mockCallbackService_, nullptr); + + quickFixMgrProxy_ = new QuickFixCallbackProxy(mockCallbackService_); + ASSERT_NE(quickFixMgrProxy_, nullptr); +} + +void QuickFixCallbackProxyTest::TearDown() +{} + +/** + * @tc.name: OnLoadPatchDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackProxyTest, OnLoadPatchDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + EXPECT_CALL(*mockCallbackService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockCallbackService_.GetRefPtr(), &MockQuickFixCallbackStub::InvokeSendRequest)); + + int32_t resultCode = 0; + quickFixMgrProxy_->OnLoadPatchDone(resultCode); + + EXPECT_EQ(mockCallbackService_->code_, + static_cast(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_LOAD_PATCH)); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnUnloadPatchDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackProxyTest, OnUnloadPatchDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + EXPECT_CALL(*mockCallbackService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockCallbackService_.GetRefPtr(), &MockQuickFixCallbackStub::InvokeSendRequest)); + + int32_t resultCode = 0; + quickFixMgrProxy_->OnUnloadPatchDone(resultCode); + + EXPECT_EQ(mockCallbackService_->code_, + static_cast(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_UNLOAD_PATCH)); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnReloadPageDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackProxyTest, OnReloadPageDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + EXPECT_CALL(*mockCallbackService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockCallbackService_.GetRefPtr(), &MockQuickFixCallbackStub::InvokeSendRequest)); + + int32_t resultCode = 0; + quickFixMgrProxy_->OnReloadPageDone(resultCode); + + EXPECT_EQ(mockCallbackService_->code_, + static_cast(IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_RELOAD_PAGE)); + + HILOG_INFO("%{public}s end.", __func__); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/quick_fix/quick_fix_callback_stub_test/BUILD.gn b/test/unittest/quick_fix/quick_fix_callback_stub_test/BUILD.gn new file mode 100644 index 0000000000..e478e84ce5 --- /dev/null +++ b/test/unittest/quick_fix/quick_fix_callback_stub_test/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("quick_fix_callback_stub_test") { + module_out_path = "ability_runtime/quick_fix" + + include_dirs = + [ "${ability_runtime_test_path}/unittest/quick_fix/mock/include" ] + + sources = [ "quick_fix_callback_stub_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + deps = [ ":quick_fix_callback_stub_test" ] +} diff --git a/test/unittest/quick_fix/quick_fix_callback_stub_test/quick_fix_callback_stub_test.cpp b/test/unittest/quick_fix/quick_fix_callback_stub_test/quick_fix_callback_stub_test.cpp new file mode 100644 index 0000000000..155015d86a --- /dev/null +++ b/test/unittest/quick_fix/quick_fix_callback_stub_test/quick_fix_callback_stub_test.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#include "quick_fix_callback_stub.h" +#include "mock_quick_fix_callback_stub.h" +#undef private +#include "hilog_wrapper.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +class QuickFixCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + sptr mockQuickFixCallback_ = nullptr; +}; + +void QuickFixCallbackStubTest::SetUpTestCase(void) +{} + +void QuickFixCallbackStubTest::TearDownTestCase(void) +{} + +void QuickFixCallbackStubTest::SetUp() +{ + mockQuickFixCallback_ = new MockQuickFixCallbackStub(); + ASSERT_NE(mockQuickFixCallback_, nullptr); +} + +void QuickFixCallbackStubTest::TearDown() +{} + +/** + * @tc.name: OnLoadPatchDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackStubTest, OnLoadPatchDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(QuickFixCallbackStub::GetDescriptor()); + int32_t resultCode = 0; + data.WriteInt32(resultCode); + + EXPECT_CALL(*mockQuickFixCallback_, OnLoadPatchDone(_)).Times(1); + + auto result = mockQuickFixCallback_->OnRemoteRequest( + IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_LOAD_PATCH, data, reply, option); + EXPECT_EQ(result, NO_ERROR); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnUnloadPatchDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackStubTest, OnUnloadPatchDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(QuickFixCallbackStub::GetDescriptor()); + int32_t resultCode = 0; + data.WriteInt32(resultCode); + + EXPECT_CALL(*mockQuickFixCallback_, OnUnloadPatchDone(_)).Times(1); + + auto result = mockQuickFixCallback_->OnRemoteRequest( + IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_UNLOAD_PATCH, data, reply, option); + EXPECT_EQ(result, NO_ERROR); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnReloadPageDone_0100 + * @tc.desc: basic function test. + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackStubTest, OnReloadPageDone_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(QuickFixCallbackStub::GetDescriptor()); + int32_t resultCode = 0; + data.WriteInt32(resultCode); + + EXPECT_CALL(*mockQuickFixCallback_, OnReloadPageDone(_)).Times(1); + + auto result = mockQuickFixCallback_->OnRemoteRequest( + IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_RELOAD_PAGE, data, reply, option); + EXPECT_EQ(result, NO_ERROR); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnRemoteRequest_0100 + * @tc.desc: OnRemoteRequest + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackStubTest, OnRemoteRequest_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(u"fake_interface_token"); + int32_t resultCode = 0; + data.WriteInt32(resultCode); + + auto result = mockQuickFixCallback_->OnRemoteRequest( + IQuickFixCallback::QuickFixCallbackCmd::ON_NOTIFY_LOAD_PATCH, data, reply, option); + EXPECT_EQ(result, ERR_INVALID_STATE); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.name: OnRemoteRequest_0200 + * @tc.desc: OnRemoteRequest + * @tc.type: FUNC + * @tc.require: issueI5OD2E + */ +HWTEST_F(QuickFixCallbackStubTest, OnRemoteRequest_0200, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(QuickFixCallbackStub::GetDescriptor()); + std::string bundleName = "com.ohos.quickfix"; + data.WriteString(bundleName); + + uint32_t invalidCode = 10; + auto result = mockQuickFixCallback_->OnRemoteRequest(invalidCode, data, reply, option); + EXPECT_EQ(result, IPC_STUB_UNKNOW_TRANS_ERR); + + HILOG_INFO("%{public}s end.", __func__); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file