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_IEXECUTE_MODE_H
17 #define FIRMWARE_IEXECUTE_MODE_H
18 
19 #include "business_error.h"
20 #include "check_result.h"
21 #include "download_options.h"
22 #include "firmware_common.h"
23 #include "firmware_component.h"
24 #include "firmware_iexecutor.h"
25 #include "progress.h"
26 #include "upgrade_options.h"
27 
28 namespace OHOS {
29 namespace UpdateEngine {
30 using OnCheckComplete = std::function<void(BusinessError &businessError, CheckResult &checkResult)>;
31 using OnExecuteFinishCallback = std::function<void()>;
32 
33 class FirmwareIExecuteMode {
34 public:
35     virtual ~FirmwareIExecuteMode() = default;
GetNextStep(FirmwareStep step)36     virtual FirmwareStep GetNextStep(FirmwareStep step)
37     {
38         return FirmwareStep::COMPLETE;
39     };
40 
SetCheckResult(CheckStatus status,const Duration & duration,const std::vector<FirmwareComponent> & componentList,const CheckAndAuthInfo & checkAndAuthInfo)41     virtual void SetCheckResult(CheckStatus status, const Duration &duration,
42         const std::vector<FirmwareComponent> &componentList, const CheckAndAuthInfo &checkAndAuthInfo) {};
SetDownloadProgress(const Progress & progress)43     virtual void SetDownloadProgress(const Progress &progress) {};
SetInstallResult(const InstallCallbackInfo & installCallbackInfo)44     virtual void SetInstallResult(const InstallCallbackInfo &installCallbackInfo) {};
SetApplyResult(bool isSuccess)45     virtual void SetApplyResult(bool isSuccess) {};
46 
47     // HandleComplete 往FirmwareManager回调之后,当前mode会被析构掉,因此后续不应该再调用任何逻辑
HandleComplete()48     virtual void HandleComplete() {};
49 
GetDownloadOptions()50     virtual DownloadOptions GetDownloadOptions()
51     {
52         DownloadOptions downloadOptions;
53         return downloadOptions;
54     };
55 
GetUpgradeOptions()56     virtual UpgradeOptions GetUpgradeOptions()
57     {
58         UpgradeOptions upgradeOptions;
59         return upgradeOptions;
60     };
61 
GetInstallType()62     virtual InstallType GetInstallType()
63     {
64         return InstallType::UPDATER;
65     }
66 };
67 } // namespace UpdateEngine
68 } // namespace OHOS
69 #endif // FIRMWARE_IEXECUTE_MODE_H