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      * @brief Handles the RenameModuleDir function called from a IInstalld proxy object.
77      * @param data Indicates the data to be read.
78      * @param reply Indicates the reply to be sent;
79      * @return Returns true if called successfully; returns false otherwise.
80      */
81     bool HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply);
82     /**
83      * @brief Handles the CreateBundleDataDir function called from a IInstalld proxy object.
84      * @param data Indicates the data to be read.
85      * @param reply Indicates the reply to be sent;
86      * @return Returns true if called successfully; returns false otherwise.
87      */
88     bool HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply);
89 
90     bool HandleCreateBundleDataDirWithVector(MessageParcel &data, MessageParcel &reply);
91     /**
92      * @brief Handles the RemoveBundleDataDir function called from a IInstalld proxy object.
93      * @param data Indicates the data to be read.
94      * @param reply Indicates the reply to be sent;
95      * @return Returns true if called successfully; returns false otherwise.
96      */
97     bool HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply);
98     /**
99      * @brief Handles the RemoveModuleDataDir function called from a IInstalld proxy object.
100      * @param data Indicates the data to be read.
101      * @param reply Indicates the reply to be sent;
102      * @return Returns true if called successfully; returns false otherwise.
103      */
104     bool HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply);
105     /**
106      * @brief Handles the RemoveDir function called from a IInstalld proxy object.
107      * @param data Indicates the data to be read.
108      * @param reply Indicates the reply to be sent;
109      * @return Returns true if called successfully; returns false otherwise.
110      */
111     bool HandleRemoveDir(MessageParcel &data, MessageParcel &reply);
112     /**
113      * @brief Handles the GetDiskUsage function called from a IInstalld proxy object.
114      * @param data Indicates the data to be read.
115      * @param reply Indicates the reply to be sent;
116      * @return Returns true if called successfully; returns false otherwise.
117      */
118     bool HandleGetDiskUsage(MessageParcel &data, MessageParcel &reply);
119     /**
120      * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object.
121      * @param data Indicates the data to be read.
122      * @param reply Indicates the reply to be sent;
123      * @return Returns true if called successfully; returns false otherwise.
124      */
125     bool HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply);
126     /**
127      * @brief Handles the CleanBundleDataDirByName function called from a IInstalld proxy object.
128      * @param data Indicates the data to be read.
129      * @param reply Indicates the reply to be sent;
130      * @return Returns true if called successfully; returns false otherwise.
131      */
132     bool HandleCleanBundleDataDirByName(MessageParcel &data, MessageParcel &reply);
133     /**
134      * @brief Handles the CleanBundleDataDir function called from a IInstalld proxy object.
135      * @param data Indicates the data to be read.
136      * @param reply Indicates the reply to be sent;
137      * @return Returns true if called successfully; returns false otherwise.
138      */
139     bool HandleGetBundleStats(MessageParcel &data, MessageParcel &reply);
140 
141     bool HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply);
142 
143     /**
144      * @brief Handles the set dir apl function called from a IInstalld proxy object.
145      * @param data Indicates the data to be read.
146      * @param reply Indicates the reply to be sent;
147      * @return Returns true if called successfully; returns false otherwise.
148      */
149     bool HandleSetDirApl(MessageParcel &data, MessageParcel &reply);
150 
151     /**
152      * @brief Handles the all GetBundleCachePath function.
153      * @param data Indicates the data to be read.
154      * @param reply Indicates the reply to be sent;
155      * @return Returns true if called successfully; returns false otherwise.
156      */
157     bool HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply);
158 
159     bool HandleScanDir(MessageParcel &data, MessageParcel &reply);
160 
161     bool HandleMoveFile(MessageParcel &data, MessageParcel &reply);
162 
163     bool HandleCopyFile(MessageParcel &data, MessageParcel &reply);
164 
165     bool HandleMkdir(MessageParcel &data, MessageParcel &reply);
166 
167     bool HandleGetFileStat(MessageParcel &data, MessageParcel &reply);
168 
169     bool HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply);
170 
171     bool HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply);
172 
173     bool HandleIsExistDir(MessageParcel &data, MessageParcel &reply);
174 
175     bool HandleIsExistFile(MessageParcel &data, MessageParcel &reply);
176 
177     bool HandleIsExistApFile(MessageParcel &data, MessageParcel &reply);
178 
179     bool HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply);
180 
181     bool HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply);
182 
183     bool HandCopyFiles(MessageParcel &data, MessageParcel &reply);
184 
185     bool HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply);
186 
187     bool HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply);
188 
189     bool HandleCheckEncryption(MessageParcel &data, MessageParcel &reply);
190 
191     bool HandMoveFiles(MessageParcel &data, MessageParcel &reply);
192 
193     bool HandExtractDriverSoFiles(MessageParcel &data, MessageParcel &reply);
194 
195     bool HandExtractEncryptedSoFiles(MessageParcel &data, MessageParcel &reply);
196 
197     bool HandVerifyCodeSignatureForHap(MessageParcel &data, MessageParcel &reply);
198 
199     bool HandDeliverySignProfile(MessageParcel &data, MessageParcel &reply);
200 
201     bool HandRemoveSignProfile(MessageParcel &data, MessageParcel &reply);
202 
203     bool HandleSetEncryptionDir(MessageParcel &data, MessageParcel &reply);
204 
205     bool HandleDeleteEncryptionKeyId(MessageParcel &data, MessageParcel &reply);
206 
207     bool HandleRemoveExtensionDir(MessageParcel &data, MessageParcel &reply);
208 
209     bool HandleIsExistExtensionDir(MessageParcel &data, MessageParcel &reply);
210 
211     bool HandleCreateExtensionDataDir(MessageParcel &data, MessageParcel &reply);
212 
213     bool HandleGetExtensionSandboxTypeList(MessageParcel &data, MessageParcel &reply);
214 
215     bool HandleAddUserDirDeleteDfx(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