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