1 /* 2 * Copyright (c) 2022 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 * @return Returns 0 on success, error code on failure. 54 */ 55 int32_t ApplyQuickFix(const std::vector<std::string> &quickFixFiles) override; 56 57 /** 58 * @brief Get applyed quick fix info. 59 * 60 * @param bundleName Bundle name of quick fix info. 61 * @param quickFixInfo Quick fix info, including bundleName, bundleVersion and so on. 62 * @return Returns 0 on success, error code on failure. 63 */ 64 int32_t GetApplyedQuickFixInfo(const std::string &bundleName, ApplicationQuickFixInfo &quickFixInfo) override; 65 66 /** 67 * @brief Remove quick fix apply task. 68 * 69 */ 70 void RemoveApplyTask(std::shared_ptr<QuickFixManagerApplyTask> applyTask); 71 72 private: 73 void AddApplyTask(std::shared_ptr<QuickFixManagerApplyTask> applyTask); 74 75 static std::mutex mutex_; 76 static sptr<QuickFixManagerService> instance_; 77 std::shared_ptr<AppExecFwk::EventRunner> eventRunner_; 78 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 79 std::vector<std::shared_ptr<QuickFixManagerApplyTask>> applyTasks_; 80 81 DISALLOW_COPY_AND_MOVE(QuickFixManagerService); 82 }; 83 } // namespace AAFwk 84 } // namespace OHOS 85 #endif // OHOS_ABILITY_RUNTIME_QUICK_FIX_MANAGER_SERVICE_H 86