1 /* 2 * Copyright (c) 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 FIRMWARE_INSTALL_H 17 #define FIRMWARE_INSTALL_H 18 19 #include <string> 20 #include <vector> 21 22 #include "error_message.h" 23 #include "firmware_common.h" 24 #include "firmware_component.h" 25 #include "progress.h" 26 27 namespace OHOS { 28 namespace UpdateEngine { 29 constexpr int32_t SLEEP_INSTALL = 1; 30 31 struct InstallProgress { 32 Progress progress; 33 ErrorMessage errMsg; 34 }; 35 36 using OnFirmwareProgress = std::function<void(const FirmwareComponent &component)>; 37 using OnFirmwareEvent = std::function<void(const bool result, const ErrorMessage &errMsg)>; 38 using OnFirmwareStatus = std::function<void(const UpgradeStatus &status)>; 39 struct FirmwareInstallCallback { 40 OnFirmwareProgress onFirmwareProgress; 41 OnFirmwareEvent onFirmwareEvent; 42 OnFirmwareStatus onFirmwareStatus; 43 }; 44 45 class FirmwareInstall { 46 public: 47 virtual ~FirmwareInstall() = default; 48 void StartInstall(const std::vector<FirmwareComponent> &componentList, FirmwareInstallCallback &cb); 49 50 private: 51 virtual bool IsComponentLegal(const std::vector<FirmwareComponent> &componentList) = 0; 52 virtual bool PerformInstall(const std::vector<FirmwareComponent> &componentList) = 0; 53 54 void SetIsInstalling(bool isInstalling); 55 bool IsInstalling(); 56 void CallbackResult(FirmwareInstallCallback &cb, const bool result); 57 void CallbackFailedResult(FirmwareInstallCallback &cb, const std::string &errorMsg, int32_t errCode); 58 59 protected: 60 FirmwareInstallCallback onInstallCallback_; 61 ErrorMessage errMsg_; 62 63 private: 64 std::mutex mutex_; 65 bool isInstalling_ = false; 66 }; 67 } // namespace UpdateEngine 68 } // namespace OHOS 69 #endif // FIRMWARE_INSTALL_H