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_MANAGER_H 17 #define FIRMWARE_MANAGER_H 18 19 #include "singleton.h" 20 21 #include "constant.h" 22 #include "firmware_common.h" 23 #include "firmware_flow_manager.h" 24 #include "firmware_result_process.h" 25 #include "firmware_task.h" 26 #include "device_adapter.h" 27 #include "firmware_preferences_utils.h" 28 #include "schedule_task.h" 29 #include "update_helper.h" 30 31 namespace OHOS { 32 namespace UpdateEngine { 33 class FirmwareManager : public DelayedSingleton<FirmwareManager> { 34 DECLARE_DELAYED_SINGLETON(FirmwareManager); 35 36 public: 37 void Init(StartupReason startupReason); 38 bool IsIdle(); 39 std::vector<ScheduleTask> GetScheduleTasks(); 40 bool Exit(); 41 42 void DoCheck(OnCheckComplete onCheckComplete); 43 void DoDownload(const DownloadOptions &downloadOptions, BusinessError &businessError); 44 void DoInstall(const UpgradeOptions &upgradeOptions, BusinessError &businessError, InstallType installType); 45 void DoAutoDownloadSwitchChanged(bool isDownloadSwitchOn); 46 void DoClearError(BusinessError &businessError); 47 void HandleEvent(CommonEventType event); 48 void DoCancelDownload(BusinessError &businessError); 49 void DoTerminateUpgrade(BusinessError &businessError); 50 51 private: 52 void DelayInit(StartupReason startupReason); 53 void RestoreUpdate(); 54 void HandleBootComplete(); 55 void HandleNetChanged(); 56 void NotifyInitEvent(); 57 58 void HandleBootInstallOnStatusProcess(FirmwareTask &task); 59 void HandleBootApplyOnStatusProcess(const FirmwareTask &task); 60 void HandleBootUpdateOnStatusProcess(const FirmwareTask &task); 61 void HandleBootDownloadOnStatusProcess(FirmwareTask &task); 62 void HandleBootDownloadPauseStatusProcess(FirmwareTask &task); 63 void HandleBootDownloadedStatusProcess(FirmwareTask &task); 64 void HandleBootUpdateSuccess(const FirmwareTask &task, const std::map<std::string, UpdateResult> &resultMap); 65 void HandleBootUpdateFail(const FirmwareTask &task, const std::map<std::string, UpdateResult> &resultMap); 66 void DoAutoDownload(const FirmwareTask &task); 67 68 void HandleResumeDownload(FirmwareTask &task); 69 bool CanInstall(void); 70 71 private: 72 std::shared_ptr<FirmwarePreferencesUtil> preferencesUtil_ = 73 DelayedSingleton<FirmwarePreferencesUtil>::GetInstance(); 74 }; 75 } // namespace UpdateEngine 76 } // namespace OHOS 77 #endif // FIRMWARE_MANAGER_H