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