1 /*
2  * Copyright (c) 2021-2024 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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "event_handler.h"
23 #include "event_runner.h"
24 #include "iremote_stub.h"
25 #include "ipc/installd_interface.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class InstalldHost : public IRemoteStub<IInstalld> {
30 public:
31     InstalldHost();
32     virtual ~InstalldHost() override;
33 
34     virtual int OnRemoteRequest(
35         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
36 
37 private:
38     /**
39      * @brief Handles the CreateBundleDir function called from a IInstalld proxy object.
40      * @param data Indicates the data to be read.
41      * @param reply Indicates the reply to be sent;
42      * @return Returns true if called successfully; returns false otherwise.
43      */
44     bool HandleCreateBundleDir(MessageParcel &data, MessageParcel &reply);
45     /**
46      * @brief Handles the ExtractModuleFiles function called from a IInstalld proxy object.
47      * @param data Indicates the data to be read.
48      * @param reply Indicates the reply to be sent;
49      * @return Returns true if called successfully; returns false otherwise.
50      */
51     bool HandleExtractModuleFiles(MessageParcel &data, MessageParcel &reply);
52     /**
53      * @brief Handles the HandleExtractFiles function called from a IInstalld proxy object.
54      * @param data Indicates the data to be read.
55      * @param reply Indicates the reply to be sent;
56      * @return Returns true if called successfully; returns false otherwise.
57      */
58     bool HandleExtractFiles(MessageParcel &data, MessageParcel &reply);
59     /**
60      * @brief Handles the HandleExtractHnpFiles function called from a IInstalld proxy object.
61      * @param data Indicates the data to be read.
62      * @param reply Indicates the reply to be sent;
63      * @return Returns true if called successfully; returns false otherwise.
64      */
65     bool HandleExtractHnpFiles(MessageParcel &data, MessageParcel &reply);
66 
67     bool HandleProcessBundleInstallNative(MessageParcel &data, MessageParcel &reply);
68     bool HandleProcessBundleUnInstallNative(MessageParcel &data, MessageParcel &reply);
69 
70     bool HandleExecuteAOT(MessageParcel &data, MessageParcel &reply);
71 
72     bool HandlePendSignAOT(MessageParcel &data, MessageParcel &reply);
73 
74     bool HandleStopAOT(MessageParcel &data, MessageParcel &reply);
75 
76     bool HandleDeleteUninstallTmpDirs(MessageParcel &data, MessageParcel &reply);
77     /**
78      * @brief Handles the RenameModuleDir function called from a IInstalld proxy object.
79      * @param data Indicates the data to be read.
80      * @param reply Indicates the reply to be sent;
81      * @return Returns true if called successfully; returns false otherwise.
82      */
83     bool HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply);
84     /**
85      * @brief Handles the CreateBundleDataDir function called from a IInstalld proxy object.
86      * @param data Indicates the data to be read.
87      * @param reply Indicates the reply to be sent;
88      * @return Returns true if called successfully; returns false otherwise.
89      */
90     bool HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply);
91 
92     bool HandleCreateBundleDataDirWithVector(MessageParcel &data, MessageParcel &reply);
93     /**
94      * @brief Handles the RemoveBundleDataDir function called from a IInstalld proxy object.
95      * @param data Indicates the data to be read.
96      * @param reply Indicates the reply to be sent;
97      * @return Returns true if called successfully; returns false otherwise.
98      */
99     bool HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply);
100     /**
101      * @brief Handles the RemoveModuleDataDir function called from a IInstalld proxy object.
102      * @param data Indicates the data to be read.
103      * @param reply Indicates the reply to be sent;
104      * @return Returns true if called successfully; returns false otherwise.
105      */
106     bool HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply);
107     /**
108      * @brief Handles the RemoveDir function called from a IInstalld proxy object.
109      * @param data Indicates the data to be read.
110      * @param reply Indicates the reply to be sent;
111      * @return Returns true if called successfully; returns false otherwise.
112      */
113     bool HandleRemoveDir(MessageParcel &data, MessageParcel &reply);
114     /**
115      * @brief Handles the GetDiskUsage function called from a IInstalld proxy object.
116      * @param data Indicates the data to be read.
117      * @param reply Indicates the reply to be sent;
118      * @return Returns true if called successfully; returns false otherwise.
119      */
120     bool HandleGetDiskUsage(MessageParcel &data, MessageParcel &reply);
121     /**
122      * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object.
123      * @param data Indicates the data to be read.
124      * @param reply Indicates the reply to be sent;
125      * @return Returns true if called successfully; returns false otherwise.
126      */
127     bool HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply);
128     /**
129      * @brief Handles the CleanBundleDataDirByName function called from a IInstalld proxy object.
130      * @param data Indicates the data to be read.
131      * @param reply Indicates the reply to be sent;
132      * @return Returns true if called successfully; returns false otherwise.
133      */
134     bool HandleCleanBundleDataDirByName(MessageParcel &data, MessageParcel &reply);
135     /**
136      * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object.
137      * @param data Indicates the data to be read.
138      * @param reply Indicates the reply to be sent;
139      * @return Returns true if called successfully; returns false otherwise.
140      */
141     bool HandleGetBundleStats(MessageParcel &data, MessageParcel &reply);
142 
143     bool HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply);
144 
145     /**
146      * @brief Handles the set dir apl function called from a IInstalld proxy object.
147      * @param data Indicates the data to be read.
148      * @param reply Indicates the reply to be sent;
149      * @return Returns true if called successfully; returns false otherwise.
150      */
151     bool HandleSetDirApl(MessageParcel &data, MessageParcel &reply);
152 
153     /**
154      * @brief Handles the all GetBundleCachePath function.
155      * @param data Indicates the data to be read.
156      * @param reply Indicates the reply to be sent;
157      * @return Returns true if called successfully; returns false otherwise.
158      */
159     bool HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply);
160 
161     bool HandleScanDir(MessageParcel &data, MessageParcel &reply);
162 
163     bool HandleMoveFile(MessageParcel &data, MessageParcel &reply);
164 
165     bool HandleCopyFile(MessageParcel &data, MessageParcel &reply);
166 
167     bool HandleMkdir(MessageParcel &data, MessageParcel &reply);
168 
169     bool HandleGetFileStat(MessageParcel &data, MessageParcel &reply);
170 
171     bool HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply);
172 
173     bool HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply);
174 
175     bool HandleIsExistDir(MessageParcel &data, MessageParcel &reply);
176 
177     bool HandleIsExistFile(MessageParcel &data, MessageParcel &reply);
178 
179     bool HandleIsExistApFile(MessageParcel &data, MessageParcel &reply);
180 
181     bool HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply);
182 
183     bool HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply);
184 
185     bool HandCopyFiles(MessageParcel &data, MessageParcel &reply);
186 
187     bool HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply);
188 
189     bool HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply);
190 
191     bool HandleCheckEncryption(MessageParcel &data, MessageParcel &reply);
192 
193     bool HandMoveFiles(MessageParcel &data, MessageParcel &reply);
194 
195     bool HandExtractDriverSoFiles(MessageParcel &data, MessageParcel &reply);
196 
197     bool HandExtractEncryptedSoFiles(MessageParcel &data, MessageParcel &reply);
198 
199     bool HandVerifyCodeSignatureForHap(MessageParcel &data, MessageParcel &reply);
200 
201     bool HandDeliverySignProfile(MessageParcel &data, MessageParcel &reply);
202 
203     bool HandRemoveSignProfile(MessageParcel &data, MessageParcel &reply);
204 
205     bool HandleSetEncryptionDir(MessageParcel &data, MessageParcel &reply);
206 
207     bool HandleDeleteEncryptionKeyId(MessageParcel &data, MessageParcel &reply);
208 
209     bool HandleRemoveExtensionDir(MessageParcel &data, MessageParcel &reply);
210 
211     bool HandleIsExistExtensionDir(MessageParcel &data, MessageParcel &reply);
212 
213     bool HandleCreateExtensionDataDir(MessageParcel &data, MessageParcel &reply);
214 
215     bool HandleGetExtensionSandboxTypeList(MessageParcel &data, MessageParcel &reply);
216 
217     bool HandleMoveHapToCodeDir(MessageParcel &data, MessageParcel &reply);
218 
219     void AddCloseInstalldTask();
220 
221     void RemoveCloseInstalldTask();
222 
223     void InitEventHandler();
224 
225     std::mutex unloadTaskMutex_;
226     std::shared_ptr<EventHandler> handler_ = nullptr;
227     std::shared_ptr<EventRunner> runner_ = nullptr;
228 };
229 }  // namespace AppExecFwk
230 }  // namespace OHOS
231 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_IPC_INSTALLD_HOST_H