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_APPLY_MODE_H 17 #define FIRMWARE_INSTALL_APPLY_MODE_H 18 19 #include "business_error.h" 20 #include "device_adapter.h" 21 #include "firmware_common.h" 22 #include "firmware_download_data_processor.h" 23 #include "firmware_iexecute_mode.h" 24 #include "firmware_install_data_processor.h" 25 #include "firmware_preferences_utils.h" 26 #include "firmware_task.h" 27 #include "upgrade_options.h" 28 29 namespace OHOS { 30 namespace UpdateEngine { 31 class FirmwareInstallApplyMode final : public FirmwareIExecuteMode { 32 public: FirmwareInstallApplyMode(const UpgradeOptions & upgradeOptions,BusinessError & businessError,InstallType installType,OnExecuteFinishCallback onExecuteFinishCallback)33 FirmwareInstallApplyMode(const UpgradeOptions &upgradeOptions, BusinessError &businessError, 34 InstallType installType, OnExecuteFinishCallback onExecuteFinishCallback) 35 : upgradeOptions_(upgradeOptions), 36 businessError_(businessError), 37 installType_(installType), 38 onExecuteFinishCallback_(onExecuteFinishCallback) {} 39 40 ~FirmwareInstallApplyMode() = default; 41 FirmwareStep GetNextStep(FirmwareStep step) final; 42 void SetInstallResult(const InstallCallbackInfo &installCallbackInfo) final; 43 UpgradeOptions GetUpgradeOptions() final; 44 InstallType GetInstallType(); 45 void HandleComplete() final; 46 47 private: 48 FirmwareStep GetStepAfterInit(); 49 FirmwareStep GetStepAfterInstall(); 50 FirmwareStep GetStepAfterApply(); 51 FirmwareStep GetStepForInstallAndApplyOrder(); 52 bool IsAllowInstall(); 53 bool IsUpgradeFilesReady(); 54 55 void GetTask(); 56 void SetApplyResult(bool isSuccess); 57 58 private: 59 FirmwareInstallDataProcessor installStepDataProcessor_; 60 UpgradeOptions upgradeOptions_; 61 BusinessError &businessError_; 62 InstallType installType_; 63 OnExecuteFinishCallback onExecuteFinishCallback_; 64 FirmwareTask tasks_; 65 std::shared_ptr<FirmwarePreferencesUtil> preferencesUtil_ = 66 DelayedSingleton<FirmwarePreferencesUtil>::GetInstance(); 67 }; 68 } // namespace UpdateEngine 69 } // namespace OHOS 70 #endif // FIRMWARE_INSTALL_APPLY_MODE_H