• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_INSTALLER_INSTALL_H
17 #define FIRMWARE_STREAM_INSTALLER_INSTALL_H
18 
19 #include <string>
20 #include <condition_variable>
21 #include <mutex>
22 #include <chrono>
23 
24 #include "firmware_component.h"
25 #include "firmware_install.h"
26 #include "progress_thread.h"
27 
28 namespace OHOS {
29 namespace UpdateService {
30 
31 constexpr int16_t MAX_RETRY_COUNT = 3; // 重试次数
32 constexpr int32_t RETRY_INTERVAL_TIME = 100 * 1000; // 重试间隔时间50ms
33 
34 class StreamInstallerInstall final : public FirmwareInstall {
35 private:
36     bool IsComponentLegal(const std::vector<FirmwareComponent> &componentList) final;
37     bool PerformInstall(const std::vector<FirmwareComponent> &componentList, UpgradeStatus &status) final;
38     int32_t StartInstallProcess(FirmwareComponent &component);
39     int32_t DoSysInstall(const FirmwareComponent &component);
40     bool InstallComponentWithRetry(const FirmwareComponent &component);
41     int32_t WaitInstallResult();
42     int32_t InitSysInstaller(const std::string &versionId);
43     int32_t SetInstallerCallback(FirmwareComponent &component);
44     void NotifyCondition();
45 
46 private:
47     Progress downloadProgress_;
48     Progress sysInstallProgress_;
49     std::shared_ptr<StreamProgressThread> downloadThread_ = nullptr;
50     std::mutex installMutex_;
51     std::condition_variable installCond_;
52 };
53 } // namespace UpdateService
54 } // namespace OHOS
55 #endif // FIRMWARE_STREAM_INSTALLER_INSTALL_H