1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H 18 19 #include <condition_variable> 20 #include <functional> 21 #include <vector> 22 23 #include "iquick_fix_manager.h" 24 #include "singleton.h" 25 #include "quick_fix_info.h" 26 27 namespace OHOS { 28 namespace AAFwk { 29 using ClearProxyCallback = std::function<void(const wptr<IRemoteObject>&)>; 30 31 class QuickFixManagerClient : public DelayedSingleton<QuickFixManagerClient>, 32 public std::enable_shared_from_this<QuickFixManagerClient> { 33 public: 34 QuickFixManagerClient() = default; 35 virtual ~QuickFixManagerClient() = default; 36 37 /** 38 * @brief Apply quick fix. 39 * 40 * @param quickFixFiles quick fix files need to apply, this value should include file path and file name. 41 * @param isDebug this value is for the quick fix debug mode selection. 42 * @return returns 0 on success, error code on failure. 43 */ 44 int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles, bool isDebug = false); 45 46 /** 47 * @brief Get applyed quick fix info. 48 * 49 * @param bundleName bundle name of quick fix info. 50 * @param quickFixInfo quick fix info, including bundleName, bundleVersion and so on. 51 * @return int32_t returns 0 on success, error code on failure. 52 */ 53 int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo); 54 55 /** 56 * @brief Revoke quick fix by bundle name. 57 * 58 * @param bundleName quick fix files need to revoke. 59 * @return returns QUICK_FIX_OK on success, error code on failure. 60 */ 61 int32_t RevokeQuickFix(const std::string &bundleName); 62 63 void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject); 64 void OnLoadSystemAbilityFail(); 65 66 private: 67 sptr<IQuickFixManager> GetQuickFixMgrProxy(); 68 void ClearProxy(); 69 bool LoadQuickFixMgrService(); 70 void SetQuickFixMgr(const sptr<IRemoteObject> &remoteObject); 71 sptr<IQuickFixManager> GetQuickFixMgr(); 72 73 class QfmsDeathRecipient : public IRemoteObject::DeathRecipient { 74 public: QfmsDeathRecipient(const ClearProxyCallback & proxy)75 explicit QfmsDeathRecipient(const ClearProxyCallback &proxy) : proxy_(proxy) {} 76 virtual ~QfmsDeathRecipient() = default; 77 void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override; 78 79 private: 80 ClearProxyCallback proxy_; 81 }; 82 83 private: 84 std::condition_variable loadSaCondation_; 85 std::mutex loadSaMutex_; 86 bool loadSaFinished_; 87 std::mutex mutex_; 88 sptr<IQuickFixManager> quickFixMgr_ = nullptr; 89 90 DISALLOW_COPY_AND_MOVE(QuickFixManagerClient); 91 }; 92 } // namespace AAFwk 93 } // namespace OHOS 94 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H 95