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_EXECUTOR_H
17 #define FIRMWARE_INSTALL_EXECUTOR_H
18 
19 #include "firmware_component.h"
20 #include "firmware_common.h"
21 #include "firmware_iexecutor.h"
22 #include "firmware_task.h"
23 #include "firmware_preferences_utils.h"
24 #include "firmware_install.h"
25 
26 namespace OHOS {
27 namespace UpdateEngine {
28 class FirmwareInstallExecutor : public FirmwareIExecutor {
29 public:
FirmwareInstallExecutor(InstallType installType,FirmwareInstallExecutorCallback firmwareInstallCallback)30     FirmwareInstallExecutor(InstallType installType, FirmwareInstallExecutorCallback firmwareInstallCallback)
31         : installType_(installType), installCallback_(firmwareInstallCallback) {}
32     ~FirmwareInstallExecutor() = default;
33     void Execute() final;
34 
35 private:
36     void DoInstall();
37     void GetTask();
38     void HandleInstallProgress(const FirmwareComponent &component, const Progress &progress);
39     void HandleInstallResult(const bool result, const ErrorMessage &errMsg);
40 
41 private:
42     InstallType installType_;
43     FirmwareInstallExecutorCallback installCallback_;
44     InstallCallbackInfo installCallbackInfo_;
45     std::vector<FirmwareComponent> components_;
46     FirmwareTask tasks_;
47     Progress taskProgress_;
48     std::shared_ptr<FirmwarePreferencesUtil> preferencesUtil_ =
49         DelayedSingleton<FirmwarePreferencesUtil>::GetInstance();
50 };
51 } // namespace UpdateEngine
52 } // namespace OHOS
53 #endif // FIRMWARE_INSTALL_EXECUTOR_H