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