• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #include "ipc/installd_host.h"
17 
18 #include "app_log_tag_wrapper.h"
19 #include "bundle_constants.h"
20 #include "bundle_framework_services_ipc_interface_code.h"
21 #include "bundle_memory_guard.h"
22 #include "mem_mgr_client.h"
23 #include "parcel_macro.h"
24 #include "string_ex.h"
25 #include "system_ability_definition.h"
26 #include "system_ability_helper.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 namespace {
31 constexpr int16_t MAX_BATCH_QUERY_BUNDLE_SIZE = 1000;
32 constexpr uint16_t MAX_VEC_SIZE = 1024;
33 }
34 
InstalldHost()35 InstalldHost::InstalldHost()
36 {
37     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "installd host created");
38 }
39 
~InstalldHost()40 InstalldHost::~InstalldHost()
41 {
42     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "installd host destroyed");
43 }
44 
SetMemMgrStatus(bool started)45 void InstalldHost::SetMemMgrStatus(bool started)
46 {
47     criticalManager_.SetMemMgrStatus(started);
48 }
49 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int InstalldHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52     BundleMemoryGuard memoryGuard;
53     LOG_D(BMS_TAG_INSTALLD, "installd host receives message from client, code = %{public}d, flags = %{public}d",
54         code, option.GetFlags());
55     std::u16string descripter = InstalldHost::GetDescriptor();
56     std::u16string remoteDescripter = data.ReadInterfaceToken();
57     if (descripter != remoteDescripter) {
58         LOG_E(BMS_TAG_INSTALLD, "installd host fail to write reply message due to the reply is nullptr");
59         return OHOS::ERR_APPEXECFWK_PARCEL_ERROR;
60     }
61     criticalManager_.BeforeRequest();
62     bool result = true;
63     switch (code) {
64         case static_cast<uint32_t>(InstalldInterfaceCode::CREATE_BUNDLE_DIR):
65             result = this->HandleCreateBundleDir(data, reply);
66             break;
67         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_MODULE_FILES):
68             result = this->HandleExtractModuleFiles(data, reply);
69             break;
70         case static_cast<uint32_t>(InstalldInterfaceCode::RENAME_MODULE_DIR):
71             result = this->HandleRenameModuleDir(data, reply);
72             break;
73         case static_cast<uint32_t>(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR):
74             result = this->HandleCreateBundleDataDir(data, reply);
75             break;
76         case static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_BUNDLE_DATA_DIR):
77             result = this->HandleRemoveBundleDataDir(data, reply);
78             break;
79         case static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_MODULE_DATA_DIR):
80             result = this->HandleRemoveModuleDataDir(data, reply);
81             break;
82         case static_cast<uint32_t>(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR):
83             result = this->HandleCleanBundleDataDir(data, reply);
84             break;
85         case static_cast<uint32_t>(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR_BY_NAME):
86             result = this->HandleCleanBundleDataDirByName(data, reply);
87             break;
88         case static_cast<uint32_t>(InstalldInterfaceCode::SET_DIR_APL):
89             result = this->HandleSetDirApl(data, reply);
90             break;
91         case static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_DIR):
92             result = this->HandleRemoveDir(data, reply);
93             break;
94         case static_cast<uint32_t>(InstalldInterfaceCode::GET_BUNDLE_STATS):
95             result = this->HandleGetBundleStats(data, reply);
96             break;
97         case static_cast<uint32_t>(InstalldInterfaceCode::BATCH_GET_BUNDLE_STATS):
98             result = this->HandleBatchGetBundleStats(data, reply);
99             break;
100         case static_cast<uint32_t>(InstalldInterfaceCode::GET_ALL_BUNDLE_STATS):
101             result = this->HandleGetAllBundleStats(data, reply);
102             break;
103         case static_cast<uint32_t>(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH):
104             result = this->HandleGetBundleCachePath(data, reply);
105             break;
106         case static_cast<uint32_t>(InstalldInterfaceCode::SCAN_DIR):
107             result = this->HandleScanDir(data, reply);
108             break;
109         case static_cast<uint32_t>(InstalldInterfaceCode::MOVE_FILE):
110             result = this->HandleMoveFile(data, reply);
111             break;
112         case static_cast<uint32_t>(InstalldInterfaceCode::COPY_FILE):
113             result = this->HandleCopyFile(data, reply);
114             break;
115         case static_cast<uint32_t>(InstalldInterfaceCode::MOVE_HAP_TO_CODE_DIR):
116             result = this->HandleMoveHapToCodeDir(data, reply);
117             break;
118         case static_cast<uint32_t>(InstalldInterfaceCode::MKDIR):
119             result = this->HandleMkdir(data, reply);
120             break;
121         case static_cast<uint32_t>(InstalldInterfaceCode::GET_FILE_STAT):
122             result = this->HandleGetFileStat(data, reply);
123             break;
124         case static_cast<uint32_t>(InstalldInterfaceCode::CHANGE_FILE_STAT):
125             result = HandleChangeFileStat(data, reply);
126             break;
127         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_DIFF_FILES):
128             result = this->HandleExtractDiffFiles(data, reply);
129             break;
130         case static_cast<uint32_t>(InstalldInterfaceCode::APPLY_DIFF_PATCH):
131             result = this->HandleApplyDiffPatch(data, reply);
132             break;
133         case static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_DIR):
134             result = this->HandleIsExistDir(data, reply);
135             break;
136         case static_cast<uint32_t>(InstalldInterfaceCode::IS_DIR_EMPTY):
137             result = this->HandleIsDirEmpty(data, reply);
138             break;
139         case static_cast<uint32_t>(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR):
140             result = this->HandObtainQuickFixFileDir(data, reply);
141             break;
142         case static_cast<uint32_t>(InstalldInterfaceCode::COPY_FILES):
143             result = this->HandCopyFiles(data, reply);
144             break;
145         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_FILES):
146             result = this->HandleExtractFiles(data, reply);
147             break;
148         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_HNP_FILES):
149             result = this->HandleExtractHnpFiles(data, reply);
150             break;
151         case static_cast<uint32_t>(InstalldInterfaceCode::INSTALL_NATIVE):
152             result = this->HandleProcessBundleInstallNative(data, reply);
153             break;
154         case static_cast<uint32_t>(InstalldInterfaceCode::UNINSTALL_NATIVE):
155             result = this->HandleProcessBundleUnInstallNative(data, reply);
156             break;
157         case static_cast<uint32_t>(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES):
158             result = this->HandGetNativeLibraryFileNames(data, reply);
159             break;
160         case static_cast<uint32_t>(InstalldInterfaceCode::EXECUTE_AOT):
161             result = this->HandleExecuteAOT(data, reply);
162             break;
163         case static_cast<uint32_t>(InstalldInterfaceCode::PEND_SIGN_AOT):
164             result = this->HandlePendSignAOT(data, reply);
165             break;
166         case static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_FILE):
167             result = this->HandleIsExistFile(data, reply);
168             break;
169         case static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_AP_FILE):
170             result = this->HandleIsExistApFile(data, reply);
171             break;
172         case static_cast<uint32_t>(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE):
173             result = this->HandVerifyCodeSignature(data, reply);
174             break;
175         case static_cast<uint32_t>(InstalldInterfaceCode::CHECK_ENCRYPTION):
176             result = this->HandleCheckEncryption(data, reply);
177             break;
178         case static_cast<uint32_t>(InstalldInterfaceCode::MOVE_FILES):
179             result = this->HandMoveFiles(data, reply);
180             break;
181         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_DRIVER_SO_FILE):
182             result = this->HandExtractDriverSoFiles(data, reply);
183             break;
184         case static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_CODED_SO_FILE):
185             result = this->HandExtractEncryptedSoFiles(data, reply);
186             break;
187         case static_cast<uint32_t>(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE_FOR_HAP):
188             result = this->HandVerifyCodeSignatureForHap(data, reply);
189             break;
190         case static_cast<uint32_t>(InstalldInterfaceCode::DELIVERY_SIGN_PROFILE):
191             result = this->HandDeliverySignProfile(data, reply);
192             break;
193         case static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_SIGN_PROFILE):
194             result = this->HandRemoveSignProfile(data, reply);
195             break;
196         case static_cast<uint32_t>(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR_WITH_VECTOR):
197             result = this->HandleCreateBundleDataDirWithVector(data, reply);
198             break;
199         case static_cast<uint32_t>(InstalldInterfaceCode::STOP_AOT):
200             result = this->HandleStopAOT(data, reply);
201             break;
202         case static_cast<uint32_t>(InstalldInterfaceCode::SET_ENCRYPTION_DIR):
203             result = this->HandleSetEncryptionDir(data, reply);
204             break;
205         case static_cast<uint32_t>(InstalldInterfaceCode::DELETE_ENCRYPTION_KEY_ID):
206             result = this->HandleDeleteEncryptionKeyId(data, reply);
207             break;
208         case static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_EXTENSION_DIR):
209             result = this->HandleRemoveExtensionDir(data, reply);
210             break;
211         case static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_EXTENSION_DIR):
212             result = this->HandleIsExistExtensionDir(data, reply);
213             break;
214         case static_cast<uint32_t>(InstalldInterfaceCode::CREATE_EXTENSION_DATA_DIR):
215             result = this->HandleCreateExtensionDataDir(data, reply);
216             break;
217         case static_cast<uint32_t>(InstalldInterfaceCode::GET_DISK_USAGE):
218             result = this->HandleGetDiskUsage(data, reply);
219             break;
220         case static_cast<uint32_t>(InstalldInterfaceCode::GET_EXTENSION_SANDBOX_TYPE_LIST):
221             result = this->HandleGetExtensionSandboxTypeList(data, reply);
222             break;
223         case static_cast<uint32_t>(InstalldInterfaceCode::ADD_USER_DIR_DELETE_DFX):
224             result = this->HandleAddUserDirDeleteDfx(data, reply);
225             break;
226         case static_cast<uint32_t>(InstalldInterfaceCode::DELETE_UNINSTALL_TMP_DIRS):
227             result = this->HandleDeleteUninstallTmpDirs(data, reply);
228             break;
229         case static_cast<uint32_t>(InstalldInterfaceCode::GET_DISK_USAGE_FROM_PATH):
230             result = HandleGetDiskUsageFromPath(data, reply);
231             break;
232         case static_cast<uint32_t>(InstalldInterfaceCode::CREATE_DATA_GROUP_DIRS):
233             result = HandleCreateDataGroupDirs(data, reply);
234             break;
235         case static_cast<uint32_t>(InstalldInterfaceCode::DELETE_DATA_GROUP_DIRS):
236             result = HandleDeleteDataGroupDirs(data, reply);
237             break;
238         case static_cast<uint32_t>(InstalldInterfaceCode::MIGRATE_DATA):
239             result = HandleMigrateData(data, reply);
240             break;
241         case static_cast<uint32_t>(InstalldInterfaceCode::SET_ARK_STARTUP_CACHE_DIR_APL):
242             result = this->HandleSetArkStartupCacheApl(data, reply);
243             break;
244         case static_cast<uint32_t>(InstalldInterfaceCode::LOAD_INSTALLS):
245             result = HandleLoadInstalls(data, reply);
246             break;
247         case static_cast<uint32_t>(InstalldInterfaceCode::CLEAR_DIR):
248             result = HandleClearDir(data, reply);
249             break;
250         case static_cast<uint32_t>(InstalldInterfaceCode::RESTORE_CON_LIBS):
251             result = HandleRestoreconPath(data, reply);
252             break;
253         default :
254             LOG_W(BMS_TAG_INSTALLD, "installd host receives unknown code, code = %{public}u", code);
255             int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
256             criticalManager_.AfterRequest();
257             return ret;
258     }
259     LOG_D(BMS_TAG_INSTALLD, "installd host finish to process message from client");
260     criticalManager_.AfterRequest();
261     return result ? NO_ERROR : OHOS::ERR_APPEXECFWK_PARCEL_ERROR;
262 }
263 
HandleCreateBundleDir(MessageParcel & data,MessageParcel & reply)264 bool InstalldHost::HandleCreateBundleDir(MessageParcel &data, MessageParcel &reply)
265 {
266     std::string bundleDir = Str16ToStr8(data.ReadString16());
267     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "CreateBundleDir %{public}s", bundleDir.c_str());
268     ErrCode result = CreateBundleDir(bundleDir);
269     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
270     return true;
271 }
272 
HandleExtractModuleFiles(MessageParcel & data,MessageParcel & reply)273 bool InstalldHost::HandleExtractModuleFiles(MessageParcel &data, MessageParcel &reply)
274 {
275     std::string srcModulePath = Str16ToStr8(data.ReadString16());
276     std::string targetPath = Str16ToStr8(data.ReadString16());
277     std::string targetSoPath = Str16ToStr8(data.ReadString16());
278     std::string cpuAbi = Str16ToStr8(data.ReadString16());
279     LOG_NOFUNC_I(BMS_TAG_INSTALLD, "ExtractModuleFiles %{public}s", targetPath.c_str());
280     ErrCode result = ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi);
281     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
282     return true;
283 }
284 
HandleExtractFiles(MessageParcel & data,MessageParcel & reply)285 bool InstalldHost::HandleExtractFiles(MessageParcel &data, MessageParcel &reply)
286 {
287     std::unique_ptr<ExtractParam> info(data.ReadParcelable<ExtractParam>());
288     if (info == nullptr) {
289         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
290         return false;
291     }
292 
293     ErrCode result = ExtractFiles(*info);
294     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
295     return true;
296 }
297 
HandleExtractHnpFiles(MessageParcel & data,MessageParcel & reply)298 bool InstalldHost::HandleExtractHnpFiles(MessageParcel &data, MessageParcel &reply)
299 {
300     std::string hnpPackageInfo = Str16ToStr8(data.ReadString16());
301     std::unique_ptr<ExtractParam> info(data.ReadParcelable<ExtractParam>());
302     if (info == nullptr) {
303         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
304         return false;
305     }
306 
307     ErrCode result = ExtractHnpFiles(hnpPackageInfo, *info);
308     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
309     return true;
310 }
311 
HandleProcessBundleInstallNative(MessageParcel & data,MessageParcel & reply)312 bool InstalldHost::HandleProcessBundleInstallNative(MessageParcel &data, MessageParcel &reply)
313 {
314     std::string userId = Str16ToStr8(data.ReadString16());
315     std::string hnpRootPath = Str16ToStr8(data.ReadString16());
316     std::string hapPath = Str16ToStr8(data.ReadString16());
317     std::string cpuAbi = Str16ToStr8(data.ReadString16());
318     std::string packageName = Str16ToStr8(data.ReadString16());
319 
320     ErrCode result = ProcessBundleInstallNative(userId, hnpRootPath, hapPath, cpuAbi, packageName);
321     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
322     return true;
323 }
324 
HandleProcessBundleUnInstallNative(MessageParcel & data,MessageParcel & reply)325 bool InstalldHost::HandleProcessBundleUnInstallNative(MessageParcel &data, MessageParcel &reply)
326 {
327     std::string userId = Str16ToStr8(data.ReadString16());
328     std::string packageName = Str16ToStr8(data.ReadString16());
329 
330     ErrCode result = ProcessBundleUnInstallNative(userId, packageName);
331     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
332     return true;
333 }
334 
HandleExecuteAOT(MessageParcel & data,MessageParcel & reply)335 bool InstalldHost::HandleExecuteAOT(MessageParcel &data, MessageParcel &reply)
336 {
337     std::unique_ptr<AOTArgs> aotArgs(data.ReadParcelable<AOTArgs>());
338     if (aotArgs == nullptr) {
339         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
340         return false;
341     }
342 
343     std::vector<uint8_t> pendSignData;
344     ErrCode result = ExecuteAOT(*aotArgs, pendSignData);
345     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
346     if (result == ERR_APPEXECFWK_INSTALLD_SIGN_AOT_DISABLE) {
347         if (!reply.WriteUInt8Vector(pendSignData)) {
348             LOG_E(BMS_TAG_INSTALLD, "WriteParcelable ExecuteAOT failed");
349             return false;
350         }
351     }
352     return true;
353 }
354 
HandlePendSignAOT(MessageParcel & data,MessageParcel & reply)355 bool InstalldHost::HandlePendSignAOT(MessageParcel &data, MessageParcel &reply)
356 {
357     std::string anFileName = Str16ToStr8(data.ReadString16());
358     std::vector<uint8_t> signData;
359     if (!data.ReadUInt8Vector(&signData)) {
360         LOG_E(BMS_TAG_INSTALLD, "ReadUInt8Vector PendSignAOT failed");
361         return false;
362     }
363     ErrCode result = PendSignAOT(anFileName, signData);
364     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
365     return true;
366 }
367 
HandleStopAOT(MessageParcel & data,MessageParcel & reply)368 bool InstalldHost::HandleStopAOT(MessageParcel &data, MessageParcel &reply)
369 {
370     ErrCode result = StopAOT();
371     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
372     return true;
373 }
374 
HandleDeleteUninstallTmpDirs(MessageParcel & data,MessageParcel & reply)375 bool InstalldHost::HandleDeleteUninstallTmpDirs(MessageParcel &data, MessageParcel &reply)
376 {
377     uint32_t size = 0;
378     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, data, size);
379     uint32_t maxSize = 1000;
380     if (size > maxSize) {
381         LOG_E(BMS_TAG_INSTALLD, "size too large");
382         return false;
383     }
384     std::vector<std::string> dirs;
385     dirs.reserve(size);
386     for (uint32_t i = 0; i < size; i++) {
387         std::string dir;
388         READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, data, dir);
389         dirs.emplace_back(dir);
390     }
391     ErrCode result = DeleteUninstallTmpDirs(dirs);
392     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
393     return true;
394 }
395 
HandleRenameModuleDir(MessageParcel & data,MessageParcel & reply)396 bool InstalldHost::HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply)
397 {
398     std::string oldPath = Str16ToStr8(data.ReadString16());
399     std::string newPath = Str16ToStr8(data.ReadString16());
400     ErrCode result = RenameModuleDir(oldPath, newPath);
401     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
402     return true;
403 }
404 
HandleCreateBundleDataDir(MessageParcel & data,MessageParcel & reply)405 bool InstalldHost::HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply)
406 {
407     std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
408     if (info == nullptr) {
409         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
410         return false;
411     }
412     ErrCode result = CreateBundleDataDir(*info);
413     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
414     return true;
415 }
416 
HandleCreateBundleDataDirWithVector(MessageParcel & data,MessageParcel & reply)417 bool InstalldHost::HandleCreateBundleDataDirWithVector(MessageParcel &data, MessageParcel &reply)
418 {
419     auto createDirParamSize = data.ReadInt32();
420     if (createDirParamSize <= 0 || createDirParamSize > Constants::MAX_PARCEL_CAPACITY) {
421         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
422         return false;
423     }
424     std::vector<CreateDirParam> createDirParams;
425     for (int32_t index = 0; index < createDirParamSize; ++index) {
426         std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
427         if (info == nullptr) {
428             LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
429             return false;
430         }
431         createDirParams.emplace_back(*info);
432     }
433 
434     ErrCode result = CreateBundleDataDirWithVector(createDirParams);
435     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
436     return true;
437 }
438 
HandleRemoveBundleDataDir(MessageParcel & data,MessageParcel & reply)439 bool InstalldHost::HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply)
440 {
441     std::string bundleName = Str16ToStr8(data.ReadString16());
442     int32_t userId = data.ReadInt32();
443     bool isAtomicService = data.ReadBool();
444     bool async = data.ReadBool();
445     ErrCode result = RemoveBundleDataDir(bundleName, userId, isAtomicService, async);
446     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
447     return true;
448 }
449 
HandleRemoveModuleDataDir(MessageParcel & data,MessageParcel & reply)450 bool InstalldHost::HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply)
451 {
452     std::string moduleName = Str16ToStr8(data.ReadString16());
453     int userid = data.ReadInt32();
454     ErrCode result = RemoveModuleDataDir(moduleName, userid);
455     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
456     return true;
457 }
458 
HandleRemoveDir(MessageParcel & data,MessageParcel & reply)459 bool InstalldHost::HandleRemoveDir(MessageParcel &data, MessageParcel &reply)
460 {
461     std::string removedDir = Str16ToStr8(data.ReadString16());
462     ErrCode result = RemoveDir(removedDir);
463     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
464     return true;
465 }
466 
HandleGetDiskUsage(MessageParcel & data,MessageParcel & reply)467 bool InstalldHost::HandleGetDiskUsage(MessageParcel &data, MessageParcel &reply)
468 {
469     std::string dir = Str16ToStr8(data.ReadString16());
470     bool isRealPath = data.ReadBool();
471     int64_t statSize = 0;
472     ErrCode result = GetDiskUsage(dir, statSize, isRealPath);
473     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
474     if (!reply.WriteInt64(statSize)) {
475         LOG_E(BMS_TAG_INSTALLD, "HandleGetDiskUsage write failed");
476         return false;
477     }
478     return true;
479 }
480 
HandleGetDiskUsageFromPath(MessageParcel & data,MessageParcel & reply)481 bool InstalldHost::HandleGetDiskUsageFromPath(MessageParcel &data, MessageParcel &reply)
482 {
483     auto cachePathSize = data.ReadUint32();
484     if (cachePathSize == 0 || cachePathSize > Constants::MAX_CACHE_DIR_SIZE) {
485         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
486         return false;
487     }
488     std::vector<std::string> cachePaths;
489     cachePaths.reserve(cachePathSize);
490     for (uint32_t i = 0; i < cachePathSize; i++) {
491         std::string path;
492         READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, data, path);
493         cachePaths.emplace_back(path);
494     }
495     int64_t statSize = 0;
496     ErrCode result = GetDiskUsageFromPath(cachePaths, statSize);
497     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
498     if (!reply.WriteInt64(statSize)) {
499         LOG_E(BMS_TAG_INSTALLD, "HandleGetDiskUsageFromPath write failed");
500         return false;
501     }
502     return true;
503 }
504 
HandleCleanBundleDataDir(MessageParcel & data,MessageParcel & reply)505 bool InstalldHost::HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply)
506 {
507     std::string bundleDir = Str16ToStr8(data.ReadString16());
508     ErrCode result = CleanBundleDataDir(bundleDir);
509     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
510     return true;
511 }
512 
HandleCleanBundleDataDirByName(MessageParcel & data,MessageParcel & reply)513 bool InstalldHost::HandleCleanBundleDataDirByName(MessageParcel &data, MessageParcel &reply)
514 {
515     std::string bundleName = Str16ToStr8(data.ReadString16());
516     int userid = data.ReadInt32();
517     int appIndex = data.ReadInt32();
518     ErrCode result = CleanBundleDataDirByName(bundleName, userid, appIndex);
519     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
520     return true;
521 }
522 
HandleGetBundleStats(MessageParcel & data,MessageParcel & reply)523 bool InstalldHost::HandleGetBundleStats(MessageParcel &data, MessageParcel &reply)
524 {
525     std::string bundleName = Str16ToStr8(data.ReadString16());
526     int32_t userId = data.ReadInt32();
527     int32_t uid = data.ReadInt32();
528     int32_t appIndex = data.ReadInt32();
529     uint32_t statFlag = data.ReadUint32();
530     std::vector<std::string> moduleNameList;
531     if (!data.ReadStringVector(&moduleNameList)) {
532         return false;
533     }
534     std::vector<int64_t> bundleStats;
535     ErrCode result = GetBundleStats(bundleName, userId, bundleStats, uid, appIndex, statFlag, moduleNameList);
536     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
537     if (!reply.WriteInt64Vector(bundleStats)) {
538         LOG_E(BMS_TAG_INSTALLD, "HandleGetBundleStats write failed");
539         return false;
540     }
541     return true;
542 }
543 
HandleBatchGetBundleStats(MessageParcel & data,MessageParcel & reply)544 bool InstalldHost::HandleBatchGetBundleStats(MessageParcel &data, MessageParcel &reply)
545 {
546     int32_t size = 0;
547     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, data, size);
548     if (size < 0 || size > MAX_BATCH_QUERY_BUNDLE_SIZE) {
549         LOG_E(BMS_TAG_INSTALLD, "size out of range");
550         return false;
551     }
552     std::vector<std::string> bundleNames;
553     bundleNames.reserve(size);
554     for (int32_t i = 0; i < size; i++) {
555         std::string bundleName = Str16ToStr8(data.ReadString16());
556         bundleNames.emplace_back(bundleName);
557     }
558     int32_t userId = data.ReadInt32();
559     std::unordered_map<std::string, int32_t> uidMap;
560     int32_t uidMapSize = data.ReadInt32();
561     if (uidMapSize < 0 || uidMapSize > MAX_BATCH_QUERY_BUNDLE_SIZE) {
562         LOG_E(BMS_TAG_INSTALLD, "param invalid");
563         return false;
564     }
565     for (int32_t i = 0; i < uidMapSize; ++i) {
566         std::string bundleName = Str16ToStr8(data.ReadString16());
567         int32_t uids = data.ReadInt32();
568         uidMap.emplace(bundleName, uids);
569     }
570     std::vector<BundleStorageStats> bundleStats;
571     ErrCode result = BatchGetBundleStats(bundleNames, userId, uidMap, bundleStats);
572     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
573     int32_t statsSize = static_cast<int32_t>(bundleStats.size());
574     if (!reply.WriteInt32(statsSize)) {
575         LOG_E(BMS_TAG_INSTALLD, "Write bundleStats size failed");
576         return false;
577     }
578     for (const auto &stat : bundleStats) {
579         if (!reply.WriteParcelable(&stat)) {
580             LOG_E(BMS_TAG_INSTALLD, "Write BundleStats failed");
581             return false;
582         }
583     }
584     return true;
585 }
586 
HandleGetAllBundleStats(MessageParcel & data,MessageParcel & reply)587 bool InstalldHost::HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply)
588 {
589     int32_t userId = data.ReadInt32();
590     auto uidSize = data.ReadInt32();
591     if (uidSize == 0 || uidSize > Constants::CAPACITY_SIZE) {
592         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
593         return false;
594     }
595     std::vector<int32_t> uids;
596     for (int32_t index = 0; index < uidSize; ++index) {
597         int32_t uid = data.ReadInt32();
598         uids.emplace_back(uid);
599     }
600     std::vector<int64_t> bundleStats;
601     ErrCode result = GetAllBundleStats(userId, bundleStats, uids);
602     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
603     if (!reply.WriteInt64Vector(bundleStats)) {
604         LOG_E(BMS_TAG_INSTALLD, "HandleGetAllBundleStats write failed");
605         return false;
606     }
607     return true;
608 }
609 
HandleSetDirApl(MessageParcel & data,MessageParcel & reply)610 bool InstalldHost::HandleSetDirApl(MessageParcel &data, MessageParcel &reply)
611 {
612     std::string dataDir = Str16ToStr8(data.ReadString16());
613     std::string bundleName = Str16ToStr8(data.ReadString16());
614     std::string apl = Str16ToStr8(data.ReadString16());
615     bool isPreInstallApp = data.ReadBool();
616     bool debug = data.ReadBool();
617     int32_t uid = data.ReadInt32();
618     ErrCode result = SetDirApl(dataDir, bundleName, apl, isPreInstallApp, debug, uid);
619     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
620     return true;
621 }
622 
HandleSetArkStartupCacheApl(MessageParcel & data,MessageParcel & reply)623 bool InstalldHost::HandleSetArkStartupCacheApl(MessageParcel &data, MessageParcel &reply)
624 {
625     std::string dataDir = Str16ToStr8(data.ReadString16());
626     ErrCode result = SetArkStartupCacheApl(dataDir);
627     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
628     return true;
629 }
630 
HandleGetBundleCachePath(MessageParcel & data,MessageParcel & reply)631 bool InstalldHost::HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply)
632 {
633     std::string dir = Str16ToStr8(data.ReadString16());
634     std::vector<std::string> cachePath;
635     ErrCode result = GetBundleCachePath(dir, cachePath);
636     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
637     if (!reply.WriteStringVector(cachePath)) {
638         LOG_E(BMS_TAG_INSTALLD, "fail to GetBundleCachePath from reply");
639         return false;
640     }
641     return true;
642 }
643 
HandleScanDir(MessageParcel & data,MessageParcel & reply)644 bool InstalldHost::HandleScanDir(MessageParcel &data, MessageParcel &reply)
645 {
646     std::string dir = Str16ToStr8(data.ReadString16());
647     ScanMode scanMode = static_cast<ScanMode>(data.ReadInt32());
648     ResultMode resultMode = static_cast<ResultMode>(data.ReadInt32());
649     std::vector<std::string> paths;
650     ErrCode result = ScanDir(dir, scanMode, resultMode, paths);
651     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
652     if (!reply.WriteStringVector(paths)) {
653         LOG_E(BMS_TAG_INSTALLD, "fail to Scan from reply");
654         return false;
655     }
656 
657     return true;
658 }
659 
HandleMoveFile(MessageParcel & data,MessageParcel & reply)660 bool InstalldHost::HandleMoveFile(MessageParcel &data, MessageParcel &reply)
661 {
662     std::string oldPath = Str16ToStr8(data.ReadString16());
663     std::string newPath = Str16ToStr8(data.ReadString16());
664     ErrCode result = MoveFile(oldPath, newPath);
665     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
666     return true;
667 }
668 
HandleCopyFile(MessageParcel & data,MessageParcel & reply)669 bool InstalldHost::HandleCopyFile(MessageParcel &data, MessageParcel &reply)
670 {
671     std::string oldPath = Str16ToStr8(data.ReadString16());
672     std::string newPath = Str16ToStr8(data.ReadString16());
673     std::string signatureFilePath = Str16ToStr8(data.ReadString16());
674 
675     ErrCode result = CopyFile(oldPath, newPath, signatureFilePath);
676     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
677     return true;
678 }
679 
HandleMkdir(MessageParcel & data,MessageParcel & reply)680 bool InstalldHost::HandleMkdir(MessageParcel &data, MessageParcel &reply)
681 {
682     std::string dir = Str16ToStr8(data.ReadString16());
683     int32_t mode = data.ReadInt32();
684     int32_t uid = data.ReadInt32();
685     int32_t gid = data.ReadInt32();
686     ErrCode result = Mkdir(dir, mode, uid, gid);
687     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
688     return true;
689 }
690 
HandleGetFileStat(MessageParcel & data,MessageParcel & reply)691 bool InstalldHost::HandleGetFileStat(MessageParcel &data, MessageParcel &reply)
692 {
693     std::string file = Str16ToStr8(data.ReadString16());
694     FileStat fileStat;
695     ErrCode result = GetFileStat(file, fileStat);
696     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
697     if (!reply.WriteParcelable(&fileStat)) {
698         LOG_E(BMS_TAG_INSTALLD, "fail to GetFileStat from reply");
699         return false;
700     }
701 
702     return true;
703 }
704 
HandleChangeFileStat(MessageParcel & data,MessageParcel & reply)705 bool InstalldHost::HandleChangeFileStat(MessageParcel &data, MessageParcel &reply)
706 {
707     std::string file = Str16ToStr8(data.ReadString16());
708     std::unique_ptr<FileStat> info(data.ReadParcelable<FileStat>());
709     if (info == nullptr) {
710         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
711         return false;
712     }
713 
714     ErrCode result = ChangeFileStat(file, *info);
715     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
716     return true;
717 }
718 
HandleExtractDiffFiles(MessageParcel & data,MessageParcel & reply)719 bool InstalldHost::HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply)
720 {
721     std::string filePath = Str16ToStr8(data.ReadString16());
722     std::string targetPath = Str16ToStr8(data.ReadString16());
723     std::string cpuAbi = Str16ToStr8(data.ReadString16());
724     ErrCode result = ExtractDiffFiles(filePath, targetPath, cpuAbi);
725     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
726     return true;
727 }
728 
HandleApplyDiffPatch(MessageParcel & data,MessageParcel & reply)729 bool InstalldHost::HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply)
730 {
731     std::string oldSoPath = Str16ToStr8(data.ReadString16());
732     std::string diffFilePath = Str16ToStr8(data.ReadString16());
733     std::string newSoPath = Str16ToStr8(data.ReadString16());
734     int32_t uid = data.ReadInt32();
735 
736     ErrCode result = ApplyDiffPatch(oldSoPath, diffFilePath, newSoPath, uid);
737     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
738     return true;
739 }
740 
HandleIsExistDir(MessageParcel & data,MessageParcel & reply)741 bool InstalldHost::HandleIsExistDir(MessageParcel &data, MessageParcel &reply)
742 {
743     std::string path = Str16ToStr8(data.ReadString16());
744     bool isExist = false;
745     ErrCode result = IsExistDir(path, isExist);
746     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
747     if (!reply.WriteBool(isExist)) {
748         LOG_E(BMS_TAG_INSTALLD, "fail to IsExistDir from reply");
749         return false;
750     }
751     return true;
752 }
753 
HandleIsExistFile(MessageParcel & data,MessageParcel & reply)754 bool InstalldHost::HandleIsExistFile(MessageParcel &data, MessageParcel &reply)
755 {
756     std::string path = Str16ToStr8(data.ReadString16());
757     bool isExist = false;
758     ErrCode result = IsExistFile(path, isExist);
759     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
760     if (!reply.WriteBool(isExist)) {
761         LOG_E(BMS_TAG_INSTALLD, "fail to IsExistFile from reply");
762         return false;
763     }
764     return true;
765 }
766 
HandleIsExistApFile(MessageParcel & data,MessageParcel & reply)767 bool InstalldHost::HandleIsExistApFile(MessageParcel &data, MessageParcel &reply)
768 {
769     std::string path = Str16ToStr8(data.ReadString16());
770     bool isExist = false;
771     ErrCode result = IsExistApFile(path, isExist);
772     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
773     if (!reply.WriteBool(isExist)) {
774         LOG_E(BMS_TAG_INSTALLD, "fail to IsExistApFile from reply");
775         return false;
776     }
777     return true;
778 }
779 
HandleIsDirEmpty(MessageParcel & data,MessageParcel & reply)780 bool InstalldHost::HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply)
781 {
782     std::string dir = Str16ToStr8(data.ReadString16());
783     bool isDirEmpty = false;
784     ErrCode result = IsDirEmpty(dir, isDirEmpty);
785     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
786     if (!reply.WriteBool(isDirEmpty)) {
787         LOG_E(BMS_TAG_INSTALLD, "write isDirEmpty failed");
788         return false;
789     }
790     return true;
791 }
792 
HandObtainQuickFixFileDir(MessageParcel & data,MessageParcel & reply)793 bool InstalldHost::HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply)
794 {
795     std::string dir = Str16ToStr8(data.ReadString16());
796     std::vector<std::string> dirVec;
797     ErrCode result = ObtainQuickFixFileDir(dir, dirVec);
798     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
799     if ((result == ERR_OK) && !reply.WriteStringVector(dirVec)) {
800         LOG_E(BMS_TAG_INSTALLD, "fail to obtain quick fix file dir from reply");
801         return false;
802     }
803     return true;
804 }
805 
HandCopyFiles(MessageParcel & data,MessageParcel & reply)806 bool InstalldHost::HandCopyFiles(MessageParcel &data, MessageParcel &reply)
807 {
808     std::string sourceDir = Str16ToStr8(data.ReadString16());
809     std::string destinationDir = Str16ToStr8(data.ReadString16());
810 
811     ErrCode result = CopyFiles(sourceDir, destinationDir);
812     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
813     return true;
814 }
815 
HandGetNativeLibraryFileNames(MessageParcel & data,MessageParcel & reply)816 bool InstalldHost::HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply)
817 {
818     std::string filePath = Str16ToStr8(data.ReadString16());
819     std::string cupAbi = Str16ToStr8(data.ReadString16());
820     std::vector<std::string> fileNames;
821     ErrCode result = GetNativeLibraryFileNames(filePath, cupAbi, fileNames);
822     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
823     if ((result == ERR_OK) && !reply.WriteStringVector(fileNames)) {
824         LOG_E(BMS_TAG_INSTALLD, "fail to obtain fileNames from reply");
825         return false;
826     }
827     return true;
828 }
829 
HandVerifyCodeSignature(MessageParcel & data,MessageParcel & reply)830 bool InstalldHost::HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply)
831 {
832     std::unique_ptr<CodeSignatureParam> info(data.ReadParcelable<CodeSignatureParam>());
833     if (info == nullptr) {
834         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
835         return false;
836     }
837 
838     ErrCode result = VerifyCodeSignature(*info);
839     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
840     return true;
841 }
842 
HandleCheckEncryption(MessageParcel & data,MessageParcel & reply)843 bool InstalldHost::HandleCheckEncryption(MessageParcel &data, MessageParcel &reply)
844 {
845     std::unique_ptr<CheckEncryptionParam> info(data.ReadParcelable<CheckEncryptionParam>());
846     if (info == nullptr) {
847         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
848         return false;
849     }
850 
851     bool isEncryption = false;
852     ErrCode result = CheckEncryption(*info, isEncryption);
853     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
854     if (!reply.WriteBool(isEncryption)) {
855         LOG_E(BMS_TAG_INSTALLD, "write isEncryption failed");
856         return false;
857     }
858     return true;
859 }
860 
HandMoveFiles(MessageParcel & data,MessageParcel & reply)861 bool InstalldHost::HandMoveFiles(MessageParcel &data, MessageParcel &reply)
862 {
863     std::string srcDir = Str16ToStr8(data.ReadString16());
864     std::string desDir = Str16ToStr8(data.ReadString16());
865 
866     ErrCode result = MoveFiles(srcDir, desDir);
867     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
868     return true;
869 }
870 
871 
HandExtractDriverSoFiles(MessageParcel & data,MessageParcel & reply)872 bool InstalldHost::HandExtractDriverSoFiles(MessageParcel &data, MessageParcel &reply)
873 {
874     std::string srcPath = Str16ToStr8(data.ReadString16());
875     int32_t size = data.ReadInt32();
876     std::unordered_multimap<std::string, std::string> dirMap;
877     CONTAINER_SECURITY_VERIFY(data, size, &dirMap);
878     for (int32_t index = 0; index < size; ++index) {
879         std::string originalDir = Str16ToStr8(data.ReadString16());
880         std::string destinedDir = Str16ToStr8(data.ReadString16());
881         dirMap.emplace(originalDir, destinedDir);
882     }
883 
884     ErrCode result = ExtractDriverSoFiles(srcPath, dirMap);
885     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
886     return true;
887 }
888 
HandExtractEncryptedSoFiles(MessageParcel & data,MessageParcel & reply)889 bool InstalldHost::HandExtractEncryptedSoFiles(MessageParcel &data, MessageParcel &reply)
890 {
891     std::string hapPath = Str16ToStr8(data.ReadString16());
892     std::string realSoFilesPath = Str16ToStr8(data.ReadString16());
893     std::string cpuAbi = Str16ToStr8(data.ReadString16());
894     std::string tmpSoPath = Str16ToStr8(data.ReadString16());
895     int32_t uid = data.ReadInt32();
896 
897     ErrCode result = ExtractEncryptedSoFiles(hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid);
898     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
899     return true;
900 }
901 
HandVerifyCodeSignatureForHap(MessageParcel & data,MessageParcel & reply)902 bool InstalldHost::HandVerifyCodeSignatureForHap(MessageParcel &data, MessageParcel &reply)
903 {
904     std::unique_ptr<CodeSignatureParam> info(data.ReadParcelable<CodeSignatureParam>());
905     if (info == nullptr) {
906         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
907         return false;
908     }
909 
910     ErrCode result = VerifyCodeSignatureForHap(*info);
911     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
912     return true;
913 }
914 
HandDeliverySignProfile(MessageParcel & data,MessageParcel & reply)915 bool InstalldHost::HandDeliverySignProfile(MessageParcel &data, MessageParcel &reply)
916 {
917     std::string bundleName = Str16ToStr8(data.ReadString16());
918     int32_t profileBlockLength = data.ReadInt32();
919     if (profileBlockLength <= 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY) {
920         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
921         return false;
922     }
923     auto dataInfo = data.ReadRawData(profileBlockLength);
924     if (!dataInfo) {
925         LOG_E(BMS_TAG_INSTALLD, "readRawData failed");
926         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
927         return false;
928     }
929     const unsigned char *profileBlock = reinterpret_cast<const unsigned char *>(dataInfo);
930     if (profileBlock == nullptr) {
931         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
932         return false;
933     }
934     ErrCode result = DeliverySignProfile(bundleName, profileBlockLength, profileBlock);
935     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
936     return true;
937 }
938 
HandRemoveSignProfile(MessageParcel & data,MessageParcel & reply)939 bool InstalldHost::HandRemoveSignProfile(MessageParcel &data, MessageParcel &reply)
940 {
941     std::string bundleName = Str16ToStr8(data.ReadString16());
942 
943     ErrCode result = RemoveSignProfile(bundleName);
944     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
945     return true;
946 }
947 
HandleSetEncryptionDir(MessageParcel & data,MessageParcel & reply)948 bool InstalldHost::HandleSetEncryptionDir(MessageParcel &data, MessageParcel &reply)
949 {
950     std::unique_ptr<EncryptionParam> info(data.ReadParcelable<EncryptionParam>());
951     if (info == nullptr) {
952         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
953         return false;
954     }
955     std::string keyId = "";
956 
957     ErrCode result = SetEncryptionPolicy(*info, keyId);
958     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
959     if (!reply.WriteString(keyId)) {
960         APP_LOGE("write keyId failed");
961         return false;
962     }
963     return true;
964 }
965 
HandleDeleteEncryptionKeyId(MessageParcel & data,MessageParcel & reply)966 bool InstalldHost::HandleDeleteEncryptionKeyId(MessageParcel &data, MessageParcel &reply)
967 {
968     std::unique_ptr<EncryptionParam> info(data.ReadParcelable<EncryptionParam>());
969     if (info == nullptr) {
970         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
971         return false;
972     }
973 
974     ErrCode result = DeleteEncryptionKeyId(*info);
975     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
976     return true;
977 }
978 
HandleRemoveExtensionDir(MessageParcel & data,MessageParcel & reply)979 bool InstalldHost::HandleRemoveExtensionDir(MessageParcel &data, MessageParcel &reply)
980 {
981     int32_t userId = data.ReadInt32();
982     int32_t extensionBundleDirSize = data.ReadInt32();
983     if (extensionBundleDirSize <= 0 || extensionBundleDirSize > MAX_BATCH_QUERY_BUNDLE_SIZE) {
984         APP_LOGE("extensionBundleDirs count is error");
985         return false;
986     }
987     std::vector<std::string> extensionBundleDirs;
988     for (int32_t i = 0; i < extensionBundleDirSize; i++) {
989         std::string extensionBundleDir = data.ReadString();
990         if (extensionBundleDir.empty()) {
991             APP_LOGE("extensionBundleDirs %{public}d is empty", i);
992             return false;
993         }
994         extensionBundleDirs.push_back(extensionBundleDir);
995     }
996     ErrCode result = RemoveExtensionDir(userId, extensionBundleDirs);
997     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
998     return true;
999 }
1000 
HandleIsExistExtensionDir(MessageParcel & data,MessageParcel & reply)1001 bool InstalldHost::HandleIsExistExtensionDir(MessageParcel &data, MessageParcel &reply)
1002 {
1003     int32_t userId = data.ReadInt32();
1004     std::string extensionBundleDir = Str16ToStr8(data.ReadString16());
1005 
1006     bool isExist = false;
1007     ErrCode result = IsExistExtensionDir(userId, extensionBundleDir, isExist);
1008     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1009     if (!reply.WriteBool(isExist)) {
1010         LOG_E(BMS_TAG_INSTALLD, "fail to write bool from reply");
1011         return false;
1012     }
1013     return true;
1014 }
1015 
HandleGetExtensionSandboxTypeList(MessageParcel & data,MessageParcel & reply)1016 bool InstalldHost::HandleGetExtensionSandboxTypeList(MessageParcel &data, MessageParcel &reply)
1017 {
1018     std::vector<std::string> typeList;
1019     ErrCode result = GetExtensionSandboxTypeList(typeList);
1020     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1021     if (result == ERR_OK) {
1022         if (!reply.WriteStringVector(typeList)) {
1023             APP_LOGE("write failed");
1024             return false;
1025         }
1026     }
1027     return true;
1028 }
1029 
HandleAddUserDirDeleteDfx(MessageParcel & data,MessageParcel & reply)1030 bool InstalldHost::HandleAddUserDirDeleteDfx(MessageParcel &data, MessageParcel &reply)
1031 {
1032     int32_t userId = data.ReadInt32();
1033     ErrCode result = AddUserDirDeleteDfx(userId);
1034     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1035     if (result != ERR_OK) {
1036         return false;
1037     }
1038     return true;
1039 }
1040 
HandleCreateExtensionDataDir(MessageParcel & data,MessageParcel & reply)1041 bool InstalldHost::HandleCreateExtensionDataDir(MessageParcel &data, MessageParcel &reply)
1042 {
1043     std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
1044     if (info == nullptr) {
1045         LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
1046         return false;
1047     }
1048     ErrCode result = CreateExtensionDataDir(*info);
1049     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1050     return true;
1051 }
1052 
HandleMoveHapToCodeDir(MessageParcel & data,MessageParcel & reply)1053 bool InstalldHost::HandleMoveHapToCodeDir(MessageParcel &data, MessageParcel &reply)
1054 {
1055     std::string originPath = Str16ToStr8(data.ReadString16());
1056     std::string targetPath = Str16ToStr8(data.ReadString16());
1057 
1058     ErrCode result = MoveHapToCodeDir(originPath, targetPath);
1059     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1060     return true;
1061 }
1062 
HandleCreateDataGroupDirs(MessageParcel & data,MessageParcel & reply)1063 bool InstalldHost::HandleCreateDataGroupDirs(MessageParcel &data, MessageParcel &reply)
1064 {
1065     auto dataGroupSize = data.ReadUint32();
1066     if (dataGroupSize == 0 || dataGroupSize > MAX_VEC_SIZE) {
1067         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
1068         return false;
1069     }
1070     std::vector<CreateDirParam> params;
1071     for (uint32_t index = 0; index < dataGroupSize; ++index) {
1072         std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
1073         if (info == nullptr) {
1074             LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
1075             return false;
1076         }
1077         params.emplace_back(*info);
1078     }
1079 
1080     ErrCode result = CreateDataGroupDirs(params);
1081     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1082     return true;
1083 }
1084 
HandleDeleteDataGroupDirs(MessageParcel & data,MessageParcel & reply)1085 bool InstalldHost::HandleDeleteDataGroupDirs(MessageParcel &data, MessageParcel &reply)
1086 {
1087     uint32_t uuidSize = data.ReadUint32();
1088     if (uuidSize == 0 || uuidSize > MAX_VEC_SIZE) {
1089         APP_LOGE("uuidSize count is error");
1090         return false;
1091     }
1092     std::vector<std::string> uuidList;
1093     for (uint32_t i = 0; i < uuidSize; i++) {
1094         std::string uuid = data.ReadString();
1095         if (uuid.empty()) {
1096             APP_LOGE("uuid %{public}d is empty", i);
1097             return false;
1098         }
1099         uuidList.emplace_back(uuid);
1100     }
1101     int32_t userId = data.ReadInt32();
1102     ErrCode result = DeleteDataGroupDirs(uuidList, userId);
1103     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1104     return true;
1105 }
1106 
HandleMigrateData(MessageParcel & data,MessageParcel & reply)1107 bool InstalldHost::HandleMigrateData(MessageParcel &data, MessageParcel &reply)
1108 {
1109     int32_t size = data.ReadInt32();
1110     std::vector<std::string> sourcePaths;
1111     CONTAINER_SECURITY_VERIFY(data, size, &sourcePaths);
1112     for (int32_t index = 0; index < size; ++index) {
1113         std::string path = Str16ToStr8(data.ReadString16());
1114         sourcePaths.emplace_back(path);
1115     }
1116     std::string destinationPath = Str16ToStr8(data.ReadString16());
1117     ErrCode result = MigrateData(sourcePaths, destinationPath);
1118 
1119     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1120     return true;
1121 }
1122 
HandleLoadInstalls(MessageParcel & data,MessageParcel & reply)1123 bool InstalldHost::HandleLoadInstalls(MessageParcel &data, MessageParcel &reply)
1124 {
1125     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_OK);
1126     return true;
1127 }
1128 
HandleClearDir(MessageParcel & data,MessageParcel & reply)1129 bool InstalldHost::HandleClearDir(MessageParcel &data, MessageParcel &reply)
1130 {
1131     std::string dir = data.ReadString();
1132     ErrCode result = ClearDir(dir);
1133     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1134     return true;
1135 }
1136 
HandleRestoreconPath(MessageParcel & data,MessageParcel & reply)1137 bool InstalldHost::HandleRestoreconPath(MessageParcel &data, MessageParcel &reply)
1138 {
1139     std::string path = data.ReadString();
1140     ErrCode result = RestoreconPath(path);
1141     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
1142     return true;
1143 }
1144 }  // namespace AppExecFwk
1145 }  // namespace OHOS
1146