1 /*
2  * Copyright (c) 2022 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_KITS_IMPL_H
17 #define SYS_INSTALLER_KITS_IMPL_H
18 
19 #include "singleton.h"
20 #include "isys_installer.h"
21 #include "isys_installer_callback.h"
22 #include "isys_installer_callback_func.h"
23 
24 namespace OHOS {
25 namespace SysInstaller {
26 class SysInstallerKitsImpl {
27 public:
28     DISALLOW_COPY_AND_MOVE(SysInstallerKitsImpl);
29     static SysInstallerKitsImpl &GetInstance();
30     virtual int32_t SysInstallerInit();
31     virtual int32_t StartUpdatePackageZip(const std::string &pkgPath);
32     virtual int32_t SetUpdateCallback(sptr<ISysInstallerCallbackFunc> callback);
33     virtual int32_t GetUpdateStatus();
34     virtual int32_t StartUpdateParaZip(const std::string &pkgPath,
35         const std::string &location, const std::string &cfgDir);
36     virtual int32_t StartDeleteParaZip(const std::string &location, const std::string &cfgDir);
37     virtual int32_t AccDecompressAndVerifyPkg(const std::string &srcPath,
38         const std::string &dstPath, const uint32_t type);
39     virtual int32_t AccDeleteDir(const std::string &dstPath);
40     virtual void ResetService(const wptr<IRemoteObject> &remote);
41     sptr<ISysInstaller> GetService();
42 
43     void LoadServiceSuccess();
44     void LoadServiceFail();
45 
46 private:
47     int32_t Init();
48     SysInstallerKitsImpl() = default;
49     virtual ~SysInstallerKitsImpl() = default;
50 
51 #ifndef UPDATER_UT
52 private:
53 #else
54 public:
55 #endif
56     // For death event procession
57     class DeathRecipient final : public IRemoteObject::DeathRecipient {
58     public:
59         DeathRecipient() = default;
60         ~DeathRecipient() final = default;
61         DISALLOW_COPY_AND_MOVE(DeathRecipient);
62         virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
63     };
64     std::mutex sysInstallerLock_;
65     sptr<ISysInstaller> sysInstaller_ {};
66     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
67     sptr<ISysInstallerCallback> updateCallBack_ {};
68 
69     std::mutex serviceMutex_;
70     std::condition_variable serviceCv_;
71 };
72 } // namespace SysInstaller
73 } // namespace OHOS
74 #endif // SYS_INSTALLER_KITS_IMPL_H
75