• 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 UPDATER_SERVICE_KITS_IMPL_H
17 #define UPDATER_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 update_engine {
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 UpdateContext &ctx, const UpdateCallbackInfo &cb) final;
34 
35     int32_t UnregisterUpdateCallback() final;
36 
37     int32_t CheckNewVersion() final;
38 
39     int32_t DownloadVersion() final;
40 
41     int32_t DoUpdate() final;
42 
43     int32_t GetNewVersion(VersionInfo &versionInfo) final;
44 
45     int32_t GetUpgradeStatus(UpgradeInfo &info) final;
46 
47     int32_t SetUpdatePolicy(const UpdatePolicy &policy) final;
48 
49     int32_t GetUpdatePolicy(UpdatePolicy &policy) final;
50 
51     int32_t Cancel(int32_t service);
52 
53     int32_t RebootAndClean(const std::string &miscFile, const std::string &cmd) final;
54 
55     int32_t RebootAndInstall(const std::string &miscFile, const std::string &packageName) final;
56 #ifndef UPDATER_UT
57 private:
58 #else
59 public:
60 #endif
61     // For call event procession
62     class RemoteUpdateCallback final : public UpdateCallback {
63     public:
64         RemoteUpdateCallback(const UpdateCallbackInfo &cb);
65         ~RemoteUpdateCallback();
66 
67         DISALLOW_COPY_AND_MOVE(RemoteUpdateCallback);
68 
69         void OnCheckVersionDone(const VersionInfo &info) final;
70 
71         void OnDownloadProgress(const Progress &progress) final;
72 
73         void OnUpgradeProgress(const Progress &progress) final;
74     private:
75         UpdateCallbackInfo updateCallback_ {};
76     };
77 
78     // For death event procession
79     class DeathRecipient final : public IRemoteObject::DeathRecipient {
80     public:
81         DeathRecipient() = default;
82         ~DeathRecipient() final = default;
83         DISALLOW_COPY_AND_MOVE(DeathRecipient);
84         void OnRemoteDied(const wptr<IRemoteObject>& remote) final;
85     };
86     void ResetService(const wptr<IRemoteObject>& remote);
87     sptr<IUpdateService> GetService();
88     std::mutex updateServiceLock_;
89     sptr<IUpdateService> updateService_ {};
90     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
91     sptr<IUpdateCallback> remoteUpdateCallback_ {};
92     UpdateContext updateContext_ {};
93 };
94 } // namespace update_engine
95 } // namespace OHOS
96 #endif // UPDATER_SERVICE_KITS_IMPL_H
97