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_STREAM_INSTALL_APPLY_MODE_H 17 #define FIRMWARE_STREAM_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 UpdateService { 31 class FirmwareStreamInstallApplyMode final : public FirmwareIExecuteMode { 32 public: FirmwareStreamInstallApplyMode(const UpgradeOptions & upgradeOptions,BusinessError & businessError,InstallType installType,OnExecuteFinishCallback onExecuteFinishCallback)33 FirmwareStreamInstallApplyMode(const UpgradeOptions &upgradeOptions, BusinessError &businessError, 34 InstallType installType, OnExecuteFinishCallback onExecuteFinishCallback) 35 : upgradeOptions_(upgradeOptions), 36 businessError_(businessError), 37 installType_(installType), 38 onExecuteFinishCallback_(onExecuteFinishCallback) {} 39 40 ~FirmwareStreamInstallApplyMode() = 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 54 void GetTask(); 55 void SetApplyResult(bool isSuccess); 56 57 private: 58 FirmwareInstallDataProcessor installStepDataProcessor_; 59 UpgradeOptions upgradeOptions_; 60 BusinessError &businessError_; 61 InstallType installType_; 62 OnExecuteFinishCallback onExecuteFinishCallback_; 63 FirmwareTask tasks_; 64 std::shared_ptr<FirmwarePreferencesUtil> preferencesUtil_ = 65 DelayedSingleton<FirmwarePreferencesUtil>::GetInstance(); 66 }; 67 } // namespace UpdateService 68 } // namespace OHOS 69 #endif // FIRMWARE_STREAM_INSTALL_APPLY_MODE_H