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 UPDATE_SERVICE_KITS_IMPL_H
17 #define UPDATE_SERVICE_KITS_IMPL_H
18 
19 #include "singleton.h"
20 
21 #include "base_service_kits_impl.h"
22 #include "iupdate_callback.h"
23 #include "update_define.h"
24 #include "update_service_kits.h"
25 #include "update_callback.h"
26 #include "update_service_proxy.h"
27 
28 namespace OHOS::UpdateEngine {
29 class UpdateServiceKitsImpl final : public UpdateServiceKits,
30     public DelayedRefSingleton<UpdateServiceKitsImpl>,
31     public BaseServiceKitsImpl<IUpdateService> {
32     DECLARE_DELAYED_REF_SINGLETON(UpdateServiceKitsImpl);
33 
34 public:
35     DISALLOW_COPY_AND_MOVE(UpdateServiceKitsImpl);
36 
37     int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb) final;
38 
39     int32_t UnregisterUpdateCallback(const UpgradeInfo &info) final;
40 
41     int32_t CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult) final;
42 
43     int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
44         const DownloadOptions &downloadOptions, BusinessError &businessError) final;
45 
46     int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
47         const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) final;
48 
49     int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
50         const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) final;
51 
52     int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
53         const UpgradeOptions &upgradeOptions, BusinessError &businessError) final;
54 
55     int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
56         const ClearOptions &clearOptions, BusinessError &businessError) final;
57 
58     int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) final;
59 
60     int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo,
61         BusinessError &businessError) final;
62 
63     int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
64         const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo,
65         BusinessError &businessError) final;
66 
67     int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo &currentVersionInfo,
68         BusinessError &businessError) final;
69 
70     int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions,
71         VersionDescriptionInfo &currentVersionDescriptionInfo, BusinessError &businessError) final;
72 
73     int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) final;
74 
75     int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError) final;
76 
77     int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) final;
78 
79     int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) final;
80 
81     int32_t FactoryReset(BusinessError &businessError) final;
82 
83     int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile,
84         const std::vector<std::string> &packageNames, BusinessError &businessError) final;
85 
86     int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath,
87         BusinessError &businessError) final;
88 
89 protected:
90     void RegisterCallback() override;
91     void ResetService(const wptr<IRemoteObject> &remote) override;
92 
93 #ifndef UPDATER_UT
94 private:
95 #endif
96     std::map<UpgradeInfo, sptr<IUpdateCallback>> remoteUpdateCallbackMap_;
97     UpgradeInfo upgradeInfo_{};
98     int32_t retryTimes_ = 0;
99 };
100 } // namespace OHOS::UpdateEngine
101 #endif // UPDATE_SERVICE_KITS_IMPL_H
102