• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "update_service_kits.h"
20 #include "update_helper.h"
21 #include "singleton.h"
22 #include "iupdate_callback.h"
23 #include "update_callback.h"
24 
25 namespace OHOS {
26 namespace UpdateEngine {
27 class UpdateServiceKitsImpl final : public UpdateServiceKits,
28     public DelayedRefSingleton<UpdateServiceKitsImpl> {
29     DECLARE_DELAYED_REF_SINGLETON(UpdateServiceKitsImpl);
30 public:
31     DISALLOW_COPY_AND_MOVE(UpdateServiceKitsImpl);
32 
33     int32_t RegisterUpdateCallback(const UpgradeInfo &info, const UpdateCallbackInfo &cb) final;
34 
35     int32_t UnregisterUpdateCallback(const UpgradeInfo &info) final;
36 
37     int32_t CheckNewVersion(const UpgradeInfo &info) final;
38 
39     int32_t Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
40         const DownloadOptions &downloadOptions, BusinessError &businessError) final;
41 
42     int32_t PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
43         const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError) final;
44 
45     int32_t ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
46         const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError) final;
47 
48     int32_t Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
49         const UpgradeOptions &upgradeOptions, BusinessError &businessError) final;
50 
51     int32_t ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigest,
52         const ClearOptions &clearOptions, BusinessError &businessError) final;
53 
54     int32_t TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError) final;
55 
56     int32_t GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo,
57         BusinessError &businessError) final;
58 
59     int32_t GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
60         const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo,
61         BusinessError &businessError) final;
62 
63     int32_t GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo &currentVersionInfo,
64         BusinessError &businessError) final;
65 
66     int32_t GetCurrentVersionDescription(const UpgradeInfo &info, const DescriptionOptions &descriptionOptions,
67         VersionDescriptionInfo &currentVersionDescriptionInfo, BusinessError &businessError) final;
68 
69     int32_t GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError) final;
70 
71     int32_t SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy, BusinessError &businessError) final;
72 
73     int32_t GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError) final;
74 
75     int32_t Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError) final;
76 
77     int32_t FactoryReset(BusinessError &businessError) final;
78 
79     int32_t ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile, const std::string &packageName,
80         BusinessError &businessError) final;
81 
82     int32_t VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath,
83         BusinessError &businessError) final;
84 
85 #ifndef UPDATER_UT
86 private:
87 #endif
88     // For call event procession
89     class RemoteUpdateCallback final : public UpdateCallback {
90     public:
91         RemoteUpdateCallback(const UpdateCallbackInfo &cb);
92         ~RemoteUpdateCallback();
93 
94         DISALLOW_COPY_AND_MOVE(RemoteUpdateCallback);
95 
96         void OnCheckVersionDone(const BusinessError &businessError, const CheckResultEx &checkResultEx) final;
97 
98         void OnEvent(const EventInfo &eventInfo) final;
99     private:
100         UpdateCallbackInfo updateCallback_ {};
101     };
102 
103     // For death event procession
104     class DeathRecipient final : public IRemoteObject::DeathRecipient {
105     public:
106         DeathRecipient() = default;
107         ~DeathRecipient() final = default;
108         DISALLOW_COPY_AND_MOVE(DeathRecipient);
109         void OnRemoteDied(const wptr<IRemoteObject>& remote) final;
110     };
111 
112     void ResetService(const wptr<IRemoteObject>& remote);
113     sptr<IUpdateService> GetService();
114 
115     std::mutex updateServiceLock_;
116     sptr<IUpdateService> updateService_ {};
117     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
118     std::map<UpgradeInfo, sptr<IUpdateCallback>> remoteUpdateCallbackMap_;
119     UpgradeInfo upgradeInfo_ {};
120 };
121 } // namespace UpdateEngine
122 } // namespace OHOS
123 #endif // UPDATE_SERVICE_KITS_IMPL_H
124