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 SYS_INSTALLER_MODULE_UPDATE_KITS_IMPL_H
17 #define SYS_INSTALLER_MODULE_UPDATE_KITS_IMPL_H
18 
19 #include "imodule_update.h"
20 #include "module_update_kits.h"
21 #include "singleton.h"
22 
23 namespace OHOS {
24 namespace SysInstaller {
25 class ModuleUpdateKitsImpl final : public ModuleUpdateKits,
26     public DelayedRefSingleton<ModuleUpdateKitsImpl> {
27     DECLARE_DELAYED_REF_SINGLETON(ModuleUpdateKitsImpl);
28 public:
29     DISALLOW_COPY_AND_MOVE(ModuleUpdateKitsImpl);
30 
31     int32_t InitModuleUpdate() final;
32     int32_t InstallModulePackage(const std::string &pkgPath) final;
33     int32_t UninstallModulePackage(const std::string &hmpName) final;
34     int32_t GetModulePackageInfo(const std::string &hmpName,
35         std::list<ModulePackageInfo> &modulePackageInfos) final;
36     int32_t ExitModuleUpdate() final;
37 
38     std::vector<HmpVersionInfo> GetHmpVersionInfo() final;
39     int32_t StartUpdateHmpPackage(const std::string &path,
40         sptr<ISysInstallerCallbackFunc> callback) final;
41     std::vector<HmpUpdateInfo> GetHmpUpdateResult() final;
42 
43     void LoadServiceSuccess() final;
44     void LoadServiceFail() final;
45 
46 #ifndef UPDATER_UT
47 private:
48 #endif
49     int32_t Init();
50     // For death event procession
51     class DeathRecipient final : public IRemoteObject::DeathRecipient {
52     public:
53         DeathRecipient() = default;
54         ~DeathRecipient() final = default;
55         DISALLOW_COPY_AND_MOVE(DeathRecipient);
56         void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
57     };
58 
59     void ResetService(const wptr<IRemoteObject> &remote);
60     sptr<IModuleUpdate> GetService();
61 
62     std::mutex moduleUpdateLock_;
63     sptr<IModuleUpdate> moduleUpdate_ {};
64     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
65     sptr<ISysInstallerCallback> updateCallBack_ {};
66     std::mutex serviceMutex_;
67     std::condition_variable serviceCv_;
68 };
69 } // namespace SysInstaller
70 } // namespace OHOS
71 #endif // SYS_INSTALLER_MODULE_UPDATE_KITS_IMPL_H
72