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_SERVICE_H 17 #define OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_SERVICE_H 18 19 #include <mutex> 20 21 #include "event_runner.h" 22 #include "event_handler.h" 23 #include "quick_fix/quick_fix_manager_interface.h" 24 #include "quick_fix_manager_apply_task.h" 25 #include "quick_fix_manager_stub.h" 26 27 namespace OHOS { 28 namespace AAFwk { 29 class QuickFixManagerService : public QuickFixManagerStub, 30 public std::enable_shared_from_this<QuickFixManagerService> { 31 public: 32 QuickFixManagerService() = default; 33 virtual ~QuickFixManagerService() = default; 34 35 /** 36 * @brief Get the instance of quick fix manager service. 37 * 38 * @return Returns the instance. 39 */ 40 static sptr<QuickFixManagerService> GetInstance(); 41 42 /** 43 * @brief Init quick fix manager service, such as event runner and event handler. 44 * 45 * @return Returns true when init succeed, false when init failed. 46 */ 47 bool Init(); 48 49 /** 50 * @brief Apply quick fix. 51 * 52 * @param quickFixFiles Quick fix files need to apply, this value should include file path and file name. 53 * @param isDebug this value is for the quick fix debug mode selection. 54 * @param isReplace this value is for the quick fix replace mode selection. 55 * @return Returns 0 on success, error code on failure. 56 */ 57 int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles, bool isDebug = false, 58 bool isReplace = false) override; 59 60 /** 61 * @brief Get applyed quick fix info. 62 * 63 * @param bundleName Bundle name of quick fix info. 64 * @param quickFixInfo Quick fix info, including bundleName, bundleVersion and so on. 65 * @return Returns 0 on success, error code on failure. 66 */ 67 int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo) override; 68 69 /** 70 * @brief Revoke quick fix by bundle name. 71 * 72 * @param bundleName quick fix files need to revoke. 73 * @return returns QUICK_FIX_OK on success, error code on failure. 74 */ 75 int32_t RevokeQuickFix(const std::string &bundleName) override; 76 77 /** 78 * @brief Remove quick fix apply task. 79 * 80 */ 81 void RemoveApplyTask(std::shared_ptr<QuickFixManagerApplyTask> applyTask); 82 83 private: 84 bool CheckTaskRunningState(const std::string &bundleName); 85 void AddApplyTask(std::shared_ptr<QuickFixManagerApplyTask> applyTask); 86 int32_t GetQuickFixInfo(const std::string &bundleName, bool &patchExists, bool &isSoContained); 87 88 static std::mutex mutex_; 89 static sptr<QuickFixManagerService> instance_; 90 std::mutex eventMutex_; 91 std::mutex taskMutex_; 92 std::shared_ptr<AppExecFwk::EventRunner> eventRunner_; 93 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 94 std::vector<std::shared_ptr<QuickFixManagerApplyTask>> applyTasks_; 95 96 DISALLOW_COPY_AND_MOVE(QuickFixManagerService); 97 }; 98 } // namespace AAFwk 99 } // namespace OHOS 100 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_SERVICE_H 101