• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(bool bStreamUpgrade = false);
31     virtual int32_t StartUpdatePackageZip(const std::string &pkgPath);
32     virtual int32_t StartStreamUpdate();
33     virtual int32_t StopStreamUpdate();
34     virtual int32_t ProcessStreamData(const uint8_t *buffer, size_t size);
35     virtual int32_t SetUpdateCallback(sptr<ISysInstallerCallbackFunc> callback);
36     virtual int32_t GetUpdateStatus();
37     virtual int32_t StartUpdateParaZip(const std::string &pkgPath,
38         const std::string &location, const std::string &cfgDir);
39     virtual int32_t StartDeleteParaZip(const std::string &location, const std::string &cfgDir);
40     virtual int32_t AccDecompressAndVerifyPkg(const std::string &srcPath,
41         const std::string &dstPath, const uint32_t type);
42     virtual int32_t AccDeleteDir(const std::string &dstPath);
43     virtual void ResetService(const wptr<IRemoteObject> &remote);
44     sptr<ISysInstaller> GetService();
45 
46     void LoadServiceSuccess();
47     void LoadServiceFail();
48 
49 private:
50     int32_t Init();
51     SysInstallerKitsImpl() = default;
52     virtual ~SysInstallerKitsImpl() = default;
53 
54 #ifndef UPDATER_UT
55 private:
56 #else
57 public:
58 #endif
59     // For death event procession
60     class DeathRecipient final : public IRemoteObject::DeathRecipient {
61     public:
62         DeathRecipient() = default;
63         ~DeathRecipient() final = default;
64         DISALLOW_COPY_AND_MOVE(DeathRecipient);
65         virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
66     };
67     std::mutex sysInstallerLock_;
68     sptr<ISysInstaller> sysInstaller_ {};
69     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
70     sptr<ISysInstallerCallback> updateCallBack_ {};
71 
72     std::mutex serviceMutex_;
73     std::condition_variable serviceCv_;
74 };
75 } // namespace SysInstaller
76 } // namespace OHOS
77 #endif // SYS_INSTALLER_KITS_IMPL_H
78