1190978c3Sopenharmony_ci/*
2190978c3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3190978c3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4190978c3Sopenharmony_ci * you may not use this file except in compliance with the License.
5190978c3Sopenharmony_ci * You may obtain a copy of the License at
6190978c3Sopenharmony_ci *
7190978c3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8190978c3Sopenharmony_ci *
9190978c3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10190978c3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11190978c3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12190978c3Sopenharmony_ci * See the License for the specific language governing permissions and
13190978c3Sopenharmony_ci * limitations under the License.
14190978c3Sopenharmony_ci */
15190978c3Sopenharmony_ci
16190978c3Sopenharmony_ci#ifndef UPDATE_SERVICE_IMPL_FIRMWARE_H
17190978c3Sopenharmony_ci#define UPDATE_SERVICE_IMPL_FIRMWARE_H
18190978c3Sopenharmony_ci
19190978c3Sopenharmony_ci#include <condition_variable>
20190978c3Sopenharmony_ci
21190978c3Sopenharmony_ci#include "iservice_online_updater.h"
22190978c3Sopenharmony_ci
23190978c3Sopenharmony_ci#include "firmware_preferences_utils.h"
24190978c3Sopenharmony_ci#include "firmware_task.h"
25190978c3Sopenharmony_ci
26190978c3Sopenharmony_cinamespace OHOS {
27190978c3Sopenharmony_cinamespace UpdateEngine {
28190978c3Sopenharmony_ciclass UpdateServiceImplFirmware final : public IServiceOnlineUpdater {
29190978c3Sopenharmony_cipublic:
30190978c3Sopenharmony_ci    UpdateServiceImplFirmware() = default;
31190978c3Sopenharmony_ci
32190978c3Sopenharmony_ci    ~UpdateServiceImplFirmware() = default;
33190978c3Sopenharmony_ci
34190978c3Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(UpdateServiceImplFirmware);
35190978c3Sopenharmony_ci
36190978c3Sopenharmony_ci    int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) final;
37190978c3Sopenharmony_ci
38190978c3Sopenharmony_ci    int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
39190978c3Sopenharmony_ci        const DownloadOptions &downloadOptions, BusinessError &businessError) final;
40190978c3Sopenharmony_ci
41190978c3Sopenharmony_ci    int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
42190978c3Sopenharmony_ci        const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) final;
43190978c3Sopenharmony_ci
44190978c3Sopenharmony_ci    int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
45190978c3Sopenharmony_ci        const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) final;
46190978c3Sopenharmony_ci
47190978c3Sopenharmony_ci    int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
48190978c3Sopenharmony_ci        const UpgradeOptions &upgradeOptions, BusinessError &businessError) final;
49190978c3Sopenharmony_ci
50190978c3Sopenharmony_ci    int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
51190978c3Sopenharmony_ci        const ClearOptions &clearOptions, BusinessError &businessError) final;
52190978c3Sopenharmony_ci
53190978c3Sopenharmony_ci    int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) final;
54190978c3Sopenharmony_ci
55190978c3Sopenharmony_ci    int32_t GetNewVersionInfo(
56190978c3Sopenharmony_ci        const UpgradeInfo &info, NewVersionInfo &newVersionInfo, BusinessError &businessError) final;
57190978c3Sopenharmony_ci
58190978c3Sopenharmony_ci    int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
59190978c3Sopenharmony_ci        const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo,
60190978c3Sopenharmony_ci        BusinessError &businessError) final;
61190978c3Sopenharmony_ci
62190978c3Sopenharmony_ci    int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo &currentVersionInfo,
63190978c3Sopenharmony_ci        BusinessError &businessError) final;
64190978c3Sopenharmony_ci
65190978c3Sopenharmony_ci    int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions,
66190978c3Sopenharmony_ci        VersionDescriptionInfo &currentVersionDescriptionInfo, BusinessError &businessError) final;
67190978c3Sopenharmony_ci
68190978c3Sopenharmony_ci    int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) final;
69190978c3Sopenharmony_ci
70190978c3Sopenharmony_ci    int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy,
71190978c3Sopenharmony_ci        BusinessError &businessError) final;
72190978c3Sopenharmony_ci
73190978c3Sopenharmony_ci    int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) final;
74190978c3Sopenharmony_ci
75190978c3Sopenharmony_ci    int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) final;
76190978c3Sopenharmony_ci
77190978c3Sopenharmony_ciprivate:
78190978c3Sopenharmony_ci    std::shared_ptr<FirmwarePreferencesUtil> preferencesUtil_ =
79190978c3Sopenharmony_ci        DelayedSingleton<FirmwarePreferencesUtil>::GetInstance();
80190978c3Sopenharmony_ci    std::condition_variable conditionVariable_;
81190978c3Sopenharmony_ci    std::mutex checkNewVersionMutex_;
82190978c3Sopenharmony_ci    bool checkComplete_ = false;
83190978c3Sopenharmony_ci    void GetChangelogContent(std::string &dataXml, const std::string &language);
84190978c3Sopenharmony_ci};
85190978c3Sopenharmony_ci} // namespace UpdateEngine
86190978c3Sopenharmony_ci} // namespace OHOS
87190978c3Sopenharmony_ci#endif // UPDATE_SERVICE_IMPL_FIRMWARE_H