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_DOWNLOAD_MODE_H 17 #define FIRMWARE_DOWNLOAD_MODE_H 18 19 #include "business_error.h" 20 #include "device_adapter.h" 21 #include "download_options.h" 22 #include "error_message.h" 23 #include "firmware_common.h" 24 #include "firmware_download_data_processor.h" 25 #include "firmware_iexecute_mode.h" 26 #include "firmware_install_data_processor.h" 27 #include "firmware_task.h" 28 #include "progress.h" 29 30 namespace OHOS { 31 namespace UpdateEngine { 32 class FirmwareDownloadMode final : public FirmwareIExecuteMode { 33 public: FirmwareDownloadMode(const DownloadOptions & downloadOptions,BusinessError & businessError,OnExecuteFinishCallback onExecuteFinishCallback)34 FirmwareDownloadMode(const DownloadOptions &downloadOptions, BusinessError &businessError, 35 OnExecuteFinishCallback onExecuteFinishCallback) 36 : downloadOptions_(downloadOptions), 37 businessError_(businessError), 38 onExecuteFinishCallback_(onExecuteFinishCallback) {} 39 40 ~FirmwareDownloadMode() = default; 41 FirmwareStep GetNextStep(FirmwareStep step) final; 42 void SetDownloadProgress(const Progress &progress) final; 43 DownloadOptions GetDownloadOptions() final; 44 void HandleComplete() final; 45 46 private: 47 FirmwareStep GetStepAfterInit(); 48 FirmwareStep GetStepAfterDownload(); 49 void GetTask(); 50 51 void DownloadSucessProcess(const FirmwareTask &task, const ErrorMessage &errorMessage); 52 void DownloadFailProcess(const FirmwareTask &task, const ErrorMessage &errorMessage); 53 void DownloadCancelProcess(const FirmwareTask &task, const ErrorMessage &errorMessage); 54 void DownloadPauseProcess(const FirmwareTask &task, const ErrorMessage &errorMessage); 55 56 private: 57 FirmwareDownloadDataProcessor downloadDataProcessor_; 58 DownloadOptions downloadOptions_; 59 BusinessError &businessError_; 60 OnExecuteFinishCallback onExecuteFinishCallback_; 61 FirmwareTask tasks_; 62 }; 63 } // namespace UpdateEngine 64 } // namespace OHOS 65 #endif // FIRMWARE_DOWNLOAD_MODE_H