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