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 "singleton.h" 24 #include "quick_fix_manager_interface.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 * @return returns 0 on success, error code on failure. 42 */ 43 int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles); 44 45 /** 46 * @brief Get applyed quick fix info. 47 * 48 * @param bundleName bundle name of quick fix info. 49 * @param quickFixInfo quick fix info, including bundleName, bundleVersion and so on. 50 * @return int32_t returns 0 on success, error code on failure. 51 */ 52 int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo); 53 54 /** 55 * @brief Revoke quick fix by bundle name. 56 * 57 * @param bundleName quick fix files need to revoke. 58 * @return returns QUICK_FIX_OK on success, error code on failure. 59 */ 60 int32_t RevokeQuickFix(const std::string &bundleName); 61 62 void OnLoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject); 63 void OnLoadSystemAbilityFail(); 64 65 private: 66 sptr<IQuickFixManager> GetQuickFixMgrProxy(); 67 void ClearProxy(); 68 bool LoadQuickFixMgrService(); 69 void SetQuickFixMgr(const sptr<IRemoteObject> &remoteObject); 70 sptr<IQuickFixManager> GetQuickFixMgr(); 71 72 class QfmsDeathRecipient : public IRemoteObject::DeathRecipient { 73 public: QfmsDeathRecipient(const ClearProxyCallback & proxy)74 explicit QfmsDeathRecipient(const ClearProxyCallback &proxy) : proxy_(proxy) {} 75 virtual ~QfmsDeathRecipient() = default; 76 void OnRemoteDied([[maybe_unused]] const wptr<IRemoteObject> &remote) override; 77 78 private: 79 ClearProxyCallback proxy_; 80 }; 81 82 private: 83 std::condition_variable loadSaCondation_; 84 std::mutex loadSaMutex_; 85 bool loadSaFinished_; 86 std::mutex mutex_; 87 sptr<IQuickFixManager> quickFixMgr_ = nullptr; 88 89 DISALLOW_COPY_AND_MOVE(QuickFixManagerClient); 90 }; 91 } // namespace AAFwk 92 } // namespace OHOS 93 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_CLIENT_H 94