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 default :
218 LOG_W(BMS_TAG_INSTALLD, "installd host receives unknown code, code = %{public}u", code);
219 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
220 }
221 LOG_D(BMS_TAG_INSTALLD, "installd host finish to process message from client");
222 AddCloseInstalldTask();
223 return result ? NO_ERROR : OHOS::ERR_APPEXECFWK_PARCEL_ERROR;
224 }
225
InitEventHandler()226 void InstalldHost::InitEventHandler()
227 {
228 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
229 runner_ = EventRunner::Create(UNLOAD_QUEUE_NAME);
230 if (runner_ == nullptr) {
231 LOG_E(BMS_TAG_INSTALLD, "init event runner failed");
232 return;
233 }
234 handler_ = std::make_shared<EventHandler>(runner_);
235 handler_->PostTask([]() { BundleMemoryGuard memoryGuard; },
236 AppExecFwk::EventQueue::Priority::IMMEDIATE);
237 }
238
HandleCreateBundleDir(MessageParcel & data,MessageParcel & reply)239 bool InstalldHost::HandleCreateBundleDir(MessageParcel &data, MessageParcel &reply)
240 {
241 std::string bundleDir = Str16ToStr8(data.ReadString16());
242 LOG_NOFUNC_I(BMS_TAG_INSTALLD, "HandleCreateBundleDir %{public}s", bundleDir.c_str());
243 ErrCode result = CreateBundleDir(bundleDir);
244 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
245 return true;
246 }
247
HandleExtractModuleFiles(MessageParcel & data,MessageParcel & reply)248 bool InstalldHost::HandleExtractModuleFiles(MessageParcel &data, MessageParcel &reply)
249 {
250 std::string srcModulePath = Str16ToStr8(data.ReadString16());
251 std::string targetPath = Str16ToStr8(data.ReadString16());
252 std::string targetSoPath = Str16ToStr8(data.ReadString16());
253 std::string cpuAbi = Str16ToStr8(data.ReadString16());
254 LOG_I(BMS_TAG_INSTALLD, "extract module %{public}s", targetPath.c_str());
255 ErrCode result = ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi);
256 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
257 return true;
258 }
259
HandleExtractFiles(MessageParcel & data,MessageParcel & reply)260 bool InstalldHost::HandleExtractFiles(MessageParcel &data, MessageParcel &reply)
261 {
262 std::unique_ptr<ExtractParam> info(data.ReadParcelable<ExtractParam>());
263 if (info == nullptr) {
264 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
265 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
266 }
267
268 ErrCode result = ExtractFiles(*info);
269 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
270 return true;
271 }
272
HandleExtractHnpFiles(MessageParcel & data,MessageParcel & reply)273 bool InstalldHost::HandleExtractHnpFiles(MessageParcel &data, MessageParcel &reply)
274 {
275 std::string hnpPackageInfo = Str16ToStr8(data.ReadString16());
276 std::unique_ptr<ExtractParam> info(data.ReadParcelable<ExtractParam>());
277 if (info == nullptr) {
278 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
279 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
280 }
281
282 ErrCode result = ExtractHnpFiles(hnpPackageInfo, *info);
283 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
284 return true;
285 }
286
HandleProcessBundleInstallNative(MessageParcel & data,MessageParcel & reply)287 bool InstalldHost::HandleProcessBundleInstallNative(MessageParcel &data, MessageParcel &reply)
288 {
289 std::string userId = Str16ToStr8(data.ReadString16());
290 std::string hnpRootPath = Str16ToStr8(data.ReadString16());
291 std::string hapPath = Str16ToStr8(data.ReadString16());
292 std::string cpuAbi = Str16ToStr8(data.ReadString16());
293 std::string packageName = Str16ToStr8(data.ReadString16());
294
295 ErrCode result = ProcessBundleInstallNative(userId, hnpRootPath, hapPath, cpuAbi, packageName);
296 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
297 return true;
298 }
299
HandleProcessBundleUnInstallNative(MessageParcel & data,MessageParcel & reply)300 bool InstalldHost::HandleProcessBundleUnInstallNative(MessageParcel &data, MessageParcel &reply)
301 {
302 std::string userId = Str16ToStr8(data.ReadString16());
303 std::string packageName = Str16ToStr8(data.ReadString16());
304
305 ErrCode result = ProcessBundleUnInstallNative(userId, packageName);
306 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
307 return true;
308 }
309
HandleExecuteAOT(MessageParcel & data,MessageParcel & reply)310 bool InstalldHost::HandleExecuteAOT(MessageParcel &data, MessageParcel &reply)
311 {
312 std::unique_ptr<AOTArgs> aotArgs(data.ReadParcelable<AOTArgs>());
313 if (aotArgs == nullptr) {
314 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
315 return false;
316 }
317
318 std::vector<uint8_t> pendSignData;
319 ErrCode result = ExecuteAOT(*aotArgs, pendSignData);
320 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
321 if (result == ERR_APPEXECFWK_INSTALLD_SIGN_AOT_DISABLE) {
322 if (!reply.WriteUInt8Vector(pendSignData)) {
323 LOG_E(BMS_TAG_INSTALLD, "WriteParcelable ExecuteAOT failed");
324 return false;
325 }
326 }
327 return true;
328 }
329
HandlePendSignAOT(MessageParcel & data,MessageParcel & reply)330 bool InstalldHost::HandlePendSignAOT(MessageParcel &data, MessageParcel &reply)
331 {
332 std::string anFileName = Str16ToStr8(data.ReadString16());
333 std::vector<uint8_t> signData;
334 if (!data.ReadUInt8Vector(&signData)) {
335 LOG_E(BMS_TAG_INSTALLD, "ReadUInt8Vector PendSignAOT failed");
336 return false;
337 }
338 ErrCode result = PendSignAOT(anFileName, signData);
339 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
340 return true;
341 }
342
HandleStopAOT(MessageParcel & data,MessageParcel & reply)343 bool InstalldHost::HandleStopAOT(MessageParcel &data, MessageParcel &reply)
344 {
345 ErrCode result = StopAOT();
346 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
347 return true;
348 }
349
HandleDeleteUninstallTmpDirs(MessageParcel & data,MessageParcel & reply)350 bool InstalldHost::HandleDeleteUninstallTmpDirs(MessageParcel &data, MessageParcel &reply)
351 {
352 uint32_t size = 0;
353 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, data, size);
354 uint32_t maxSize = 1000;
355 if (size > maxSize) {
356 LOG_E(BMS_TAG_INSTALLD, "size too large");
357 return false;
358 }
359 std::vector<std::string> dirs;
360 dirs.reserve(size);
361 for (uint32_t i = 0; i < size; i++) {
362 std::string dir;
363 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, data, dir);
364 dirs.emplace_back(dir);
365 }
366 ErrCode result = DeleteUninstallTmpDirs(dirs);
367 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
368 return true;
369 }
370
HandleRenameModuleDir(MessageParcel & data,MessageParcel & reply)371 bool InstalldHost::HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply)
372 {
373 std::string oldPath = Str16ToStr8(data.ReadString16());
374 std::string newPath = Str16ToStr8(data.ReadString16());
375 ErrCode result = RenameModuleDir(oldPath, newPath);
376 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
377 return true;
378 }
379
HandleCreateBundleDataDir(MessageParcel & data,MessageParcel & reply)380 bool InstalldHost::HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply)
381 {
382 std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
383 if (info == nullptr) {
384 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
385 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
386 }
387 ErrCode result = CreateBundleDataDir(*info);
388 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
389 return true;
390 }
391
HandleCreateBundleDataDirWithVector(MessageParcel & data,MessageParcel & reply)392 bool InstalldHost::HandleCreateBundleDataDirWithVector(MessageParcel &data, MessageParcel &reply)
393 {
394 auto createDirParamSize = data.ReadInt32();
395 if (createDirParamSize == 0 || createDirParamSize > Constants::MAX_PARCEL_CAPACITY) {
396 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
397 return false;
398 }
399 std::vector<CreateDirParam> createDirParams;
400 for (int32_t index = 0; index < createDirParamSize; ++index) {
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 createDirParams.emplace_back(*info);
407 }
408
409 ErrCode result = CreateBundleDataDirWithVector(createDirParams);
410 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
411 return true;
412 }
413
HandleRemoveBundleDataDir(MessageParcel & data,MessageParcel & reply)414 bool InstalldHost::HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply)
415 {
416 std::string bundleName = Str16ToStr8(data.ReadString16());
417 int32_t userId = data.ReadInt32();
418 bool isAtomicService = data.ReadBool();
419 bool async = data.ReadBool();
420 ErrCode result = RemoveBundleDataDir(bundleName, userId, isAtomicService, async);
421 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
422 return true;
423 }
424
HandleRemoveModuleDataDir(MessageParcel & data,MessageParcel & reply)425 bool InstalldHost::HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply)
426 {
427 std::string moduleNmae = Str16ToStr8(data.ReadString16());
428 int userid = data.ReadInt32();
429 ErrCode result = RemoveModuleDataDir(moduleNmae, userid);
430 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
431 return true;
432 }
433
HandleRemoveDir(MessageParcel & data,MessageParcel & reply)434 bool InstalldHost::HandleRemoveDir(MessageParcel &data, MessageParcel &reply)
435 {
436 std::string removedDir = Str16ToStr8(data.ReadString16());
437 ErrCode result = RemoveDir(removedDir);
438 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
439 return true;
440 }
441
HandleGetDiskUsage(MessageParcel & data,MessageParcel & reply)442 bool InstalldHost::HandleGetDiskUsage(MessageParcel &data, MessageParcel &reply)
443 {
444 std::string dir = Str16ToStr8(data.ReadString16());
445 bool isRealPath = data.ReadBool();
446
447 ErrCode result = GetDiskUsage(dir, isRealPath);
448 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
449 return true;
450 }
451
HandleCleanBundleDataDir(MessageParcel & data,MessageParcel & reply)452 bool InstalldHost::HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply)
453 {
454 std::string bundleDir = Str16ToStr8(data.ReadString16());
455 ErrCode result = CleanBundleDataDir(bundleDir);
456 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
457 return true;
458 }
459
HandleCleanBundleDataDirByName(MessageParcel & data,MessageParcel & reply)460 bool InstalldHost::HandleCleanBundleDataDirByName(MessageParcel &data, MessageParcel &reply)
461 {
462 std::string bundleName = Str16ToStr8(data.ReadString16());
463 int userid = data.ReadInt32();
464 int appIndex = data.ReadInt32();
465 ErrCode result = CleanBundleDataDirByName(bundleName, userid, appIndex);
466 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
467 return true;
468 }
469
HandleGetBundleStats(MessageParcel & data,MessageParcel & reply)470 bool InstalldHost::HandleGetBundleStats(MessageParcel &data, MessageParcel &reply)
471 {
472 std::string bundleName = Str16ToStr8(data.ReadString16());
473 int32_t userId = data.ReadInt32();
474 int32_t uid = data.ReadInt32();
475 int32_t appIndex = data.ReadInt32();
476 uint32_t statFlag = data.ReadUint32();
477 std::vector<std::string> moduleNameList;
478 if (!data.ReadStringVector(&moduleNameList)) {
479 return false;
480 }
481 std::vector<int64_t> bundleStats;
482 ErrCode result = GetBundleStats(bundleName, userId, bundleStats, uid, appIndex, statFlag, moduleNameList);
483 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
484 if (!reply.WriteInt64Vector(bundleStats)) {
485 LOG_E(BMS_TAG_INSTALLD, "HandleGetBundleStats write failed");
486 return false;
487 }
488 return true;
489 }
490
HandleGetAllBundleStats(MessageParcel & data,MessageParcel & reply)491 bool InstalldHost::HandleGetAllBundleStats(MessageParcel &data, MessageParcel &reply)
492 {
493 int32_t userId = data.ReadInt32();
494 auto uidSize = data.ReadInt32();
495 if (uidSize == 0) {
496 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
497 return false;
498 }
499 std::vector<int32_t> uids;
500 for (int32_t index = 0; index < uidSize; ++index) {
501 int32_t uid = data.ReadInt32();
502 uids.emplace_back(uid);
503 }
504 std::vector<int64_t> bundleStats;
505 ErrCode result = GetAllBundleStats(userId, bundleStats, uids);
506 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
507 if (!reply.WriteInt64Vector(bundleStats)) {
508 LOG_E(BMS_TAG_INSTALLD, "HandleGetAllBundleStats write failed");
509 return false;
510 }
511 return true;
512 }
513
HandleSetDirApl(MessageParcel & data,MessageParcel & reply)514 bool InstalldHost::HandleSetDirApl(MessageParcel &data, MessageParcel &reply)
515 {
516 std::string dataDir = Str16ToStr8(data.ReadString16());
517 std::string bundleName = Str16ToStr8(data.ReadString16());
518 std::string apl = Str16ToStr8(data.ReadString16());
519 bool isPreInstallApp = data.ReadBool();
520 bool debug = data.ReadBool();
521 ErrCode result = SetDirApl(dataDir, bundleName, apl, isPreInstallApp, debug);
522 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
523 return true;
524 }
525
HandleGetBundleCachePath(MessageParcel & data,MessageParcel & reply)526 bool InstalldHost::HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply)
527 {
528 std::string dir = Str16ToStr8(data.ReadString16());
529 std::vector<std::string> cachePath;
530 ErrCode result = GetBundleCachePath(dir, cachePath);
531 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
532 if (!reply.WriteStringVector(cachePath)) {
533 LOG_E(BMS_TAG_INSTALLD, "fail to GetBundleCachePath from reply");
534 return false;
535 }
536 return true;
537 }
538
HandleScanDir(MessageParcel & data,MessageParcel & reply)539 bool InstalldHost::HandleScanDir(MessageParcel &data, MessageParcel &reply)
540 {
541 std::string dir = Str16ToStr8(data.ReadString16());
542 ScanMode scanMode = static_cast<ScanMode>(data.ReadInt32());
543 ResultMode resultMode = static_cast<ResultMode>(data.ReadInt32());
544 std::vector<std::string> paths;
545 ErrCode result = ScanDir(dir, scanMode, resultMode, paths);
546 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
547 if (!reply.WriteStringVector(paths)) {
548 LOG_E(BMS_TAG_INSTALLD, "fail to Scan from reply");
549 return false;
550 }
551
552 return true;
553 }
554
HandleMoveFile(MessageParcel & data,MessageParcel & reply)555 bool InstalldHost::HandleMoveFile(MessageParcel &data, MessageParcel &reply)
556 {
557 std::string oldPath = Str16ToStr8(data.ReadString16());
558 std::string newPath = Str16ToStr8(data.ReadString16());
559 ErrCode result = MoveFile(oldPath, newPath);
560 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
561 return true;
562 }
563
HandleCopyFile(MessageParcel & data,MessageParcel & reply)564 bool InstalldHost::HandleCopyFile(MessageParcel &data, MessageParcel &reply)
565 {
566 std::string oldPath = Str16ToStr8(data.ReadString16());
567 std::string newPath = Str16ToStr8(data.ReadString16());
568 std::string signatureFilePath = Str16ToStr8(data.ReadString16());
569
570 ErrCode result = CopyFile(oldPath, newPath, signatureFilePath);
571 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
572 return true;
573 }
574
HandleMkdir(MessageParcel & data,MessageParcel & reply)575 bool InstalldHost::HandleMkdir(MessageParcel &data, MessageParcel &reply)
576 {
577 std::string dir = Str16ToStr8(data.ReadString16());
578 int32_t mode = data.ReadInt32();
579 int32_t uid = data.ReadInt32();
580 int32_t gid = data.ReadInt32();
581 ErrCode result = Mkdir(dir, mode, uid, gid);
582 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
583 return true;
584 }
585
HandleGetFileStat(MessageParcel & data,MessageParcel & reply)586 bool InstalldHost::HandleGetFileStat(MessageParcel &data, MessageParcel &reply)
587 {
588 std::string file = Str16ToStr8(data.ReadString16());
589 FileStat fileStat;
590 ErrCode result = GetFileStat(file, fileStat);
591 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
592 if (!reply.WriteParcelable(&fileStat)) {
593 LOG_E(BMS_TAG_INSTALLD, "fail to GetFileStat from reply");
594 return false;
595 }
596
597 return true;
598 }
599
HandleExtractDiffFiles(MessageParcel & data,MessageParcel & reply)600 bool InstalldHost::HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply)
601 {
602 std::string filePath = Str16ToStr8(data.ReadString16());
603 std::string targetPath = Str16ToStr8(data.ReadString16());
604 std::string cpuAbi = Str16ToStr8(data.ReadString16());
605 ErrCode result = ExtractDiffFiles(filePath, targetPath, cpuAbi);
606 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
607 return true;
608 }
609
HandleApplyDiffPatch(MessageParcel & data,MessageParcel & reply)610 bool InstalldHost::HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply)
611 {
612 std::string oldSoPath = Str16ToStr8(data.ReadString16());
613 std::string diffFilePath = Str16ToStr8(data.ReadString16());
614 std::string newSoPath = Str16ToStr8(data.ReadString16());
615 int32_t uid = data.ReadInt32();
616
617 ErrCode result = ApplyDiffPatch(oldSoPath, diffFilePath, newSoPath, uid);
618 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
619 return true;
620 }
621
HandleIsExistDir(MessageParcel & data,MessageParcel & reply)622 bool InstalldHost::HandleIsExistDir(MessageParcel &data, MessageParcel &reply)
623 {
624 std::string path = Str16ToStr8(data.ReadString16());
625 bool isExist = false;
626 ErrCode result = IsExistDir(path, isExist);
627 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
628 if (!reply.WriteBool(isExist)) {
629 LOG_E(BMS_TAG_INSTALLD, "fail to IsExistDir from reply");
630 return false;
631 }
632 return true;
633 }
634
HandleIsExistFile(MessageParcel & data,MessageParcel & reply)635 bool InstalldHost::HandleIsExistFile(MessageParcel &data, MessageParcel &reply)
636 {
637 std::string path = Str16ToStr8(data.ReadString16());
638 bool isExist = false;
639 ErrCode result = IsExistFile(path, isExist);
640 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
641 if (!reply.WriteBool(isExist)) {
642 LOG_E(BMS_TAG_INSTALLD, "fail to IsExistFile from reply");
643 return false;
644 }
645 return true;
646 }
647
HandleIsExistApFile(MessageParcel & data,MessageParcel & reply)648 bool InstalldHost::HandleIsExistApFile(MessageParcel &data, MessageParcel &reply)
649 {
650 std::string path = Str16ToStr8(data.ReadString16());
651 bool isExist = false;
652 ErrCode result = IsExistApFile(path, isExist);
653 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
654 if (!reply.WriteBool(isExist)) {
655 LOG_E(BMS_TAG_INSTALLD, "fail to IsExistApFile from reply");
656 return false;
657 }
658 return true;
659 }
660
HandleIsDirEmpty(MessageParcel & data,MessageParcel & reply)661 bool InstalldHost::HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply)
662 {
663 std::string dir = Str16ToStr8(data.ReadString16());
664 bool isDirEmpty = false;
665 ErrCode result = IsDirEmpty(dir, isDirEmpty);
666 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
667 if (!reply.WriteBool(isDirEmpty)) {
668 LOG_E(BMS_TAG_INSTALLD, "write isDirEmpty failed");
669 return false;
670 }
671 return true;
672 }
673
HandObtainQuickFixFileDir(MessageParcel & data,MessageParcel & reply)674 bool InstalldHost::HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply)
675 {
676 std::string dir = Str16ToStr8(data.ReadString16());
677 std::vector<std::string> dirVec;
678 ErrCode result = ObtainQuickFixFileDir(dir, dirVec);
679 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
680 if ((result == ERR_OK) && !reply.WriteStringVector(dirVec)) {
681 LOG_E(BMS_TAG_INSTALLD, "fail to obtain quick fix file dir from reply");
682 return false;
683 }
684 return true;
685 }
686
HandCopyFiles(MessageParcel & data,MessageParcel & reply)687 bool InstalldHost::HandCopyFiles(MessageParcel &data, MessageParcel &reply)
688 {
689 std::string sourceDir = Str16ToStr8(data.ReadString16());
690 std::string destinationDir = Str16ToStr8(data.ReadString16());
691
692 ErrCode result = CopyFiles(sourceDir, destinationDir);
693 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
694 return true;
695 }
696
HandGetNativeLibraryFileNames(MessageParcel & data,MessageParcel & reply)697 bool InstalldHost::HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply)
698 {
699 std::string filePath = Str16ToStr8(data.ReadString16());
700 std::string cupAbi = Str16ToStr8(data.ReadString16());
701 std::vector<std::string> fileNames;
702 ErrCode result = GetNativeLibraryFileNames(filePath, cupAbi, fileNames);
703 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
704 if ((result == ERR_OK) && !reply.WriteStringVector(fileNames)) {
705 LOG_E(BMS_TAG_INSTALLD, "fail to obtain fileNames from reply");
706 return false;
707 }
708 return true;
709 }
710
HandVerifyCodeSignature(MessageParcel & data,MessageParcel & reply)711 bool InstalldHost::HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply)
712 {
713 std::unique_ptr<CodeSignatureParam> info(data.ReadParcelable<CodeSignatureParam>());
714 if (info == nullptr) {
715 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
716 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
717 }
718
719 ErrCode result = VerifyCodeSignature(*info);
720 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
721 return true;
722 }
723
HandleCheckEncryption(MessageParcel & data,MessageParcel & reply)724 bool InstalldHost::HandleCheckEncryption(MessageParcel &data, MessageParcel &reply)
725 {
726 std::unique_ptr<CheckEncryptionParam> info(data.ReadParcelable<CheckEncryptionParam>());
727 if (info == nullptr) {
728 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
729 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
730 }
731
732 bool isEncryption = false;
733 ErrCode result = CheckEncryption(*info, isEncryption);
734 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
735 if (!reply.WriteBool(isEncryption)) {
736 LOG_E(BMS_TAG_INSTALLD, "write isEncryption failed");
737 return false;
738 }
739 return true;
740 }
741
HandMoveFiles(MessageParcel & data,MessageParcel & reply)742 bool InstalldHost::HandMoveFiles(MessageParcel &data, MessageParcel &reply)
743 {
744 std::string srcDir = Str16ToStr8(data.ReadString16());
745 std::string desDir = Str16ToStr8(data.ReadString16());
746
747 ErrCode result = MoveFiles(srcDir, desDir);
748 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
749 return true;
750 }
751
752
HandExtractDriverSoFiles(MessageParcel & data,MessageParcel & reply)753 bool InstalldHost::HandExtractDriverSoFiles(MessageParcel &data, MessageParcel &reply)
754 {
755 std::string srcPath = Str16ToStr8(data.ReadString16());
756 int32_t size = data.ReadInt32();
757 std::unordered_multimap<std::string, std::string> dirMap;
758 CONTAINER_SECURITY_VERIFY(data, size, &dirMap);
759 for (int32_t index = 0; index < size; ++index) {
760 std::string originalDir = Str16ToStr8(data.ReadString16());
761 std::string destinedDir = Str16ToStr8(data.ReadString16());
762 dirMap.emplace(originalDir, destinedDir);
763 }
764
765 ErrCode result = ExtractDriverSoFiles(srcPath, dirMap);
766 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
767 return true;
768 }
769
HandExtractEncryptedSoFiles(MessageParcel & data,MessageParcel & reply)770 bool InstalldHost::HandExtractEncryptedSoFiles(MessageParcel &data, MessageParcel &reply)
771 {
772 std::string hapPath = Str16ToStr8(data.ReadString16());
773 std::string realSoFilesPath = Str16ToStr8(data.ReadString16());
774 std::string cpuAbi = Str16ToStr8(data.ReadString16());
775 std::string tmpSoPath = Str16ToStr8(data.ReadString16());
776 int32_t uid = data.ReadInt32();
777
778 ErrCode result = ExtractEncryptedSoFiles(hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid);
779 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
780 return true;
781 }
782
HandVerifyCodeSignatureForHap(MessageParcel & data,MessageParcel & reply)783 bool InstalldHost::HandVerifyCodeSignatureForHap(MessageParcel &data, MessageParcel &reply)
784 {
785 std::unique_ptr<CodeSignatureParam> info(data.ReadParcelable<CodeSignatureParam>());
786 if (info == nullptr) {
787 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
788 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
789 }
790
791 ErrCode result = VerifyCodeSignatureForHap(*info);
792 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
793 return true;
794 }
795
HandDeliverySignProfile(MessageParcel & data,MessageParcel & reply)796 bool InstalldHost::HandDeliverySignProfile(MessageParcel &data, MessageParcel &reply)
797 {
798 std::string bundleName = Str16ToStr8(data.ReadString16());
799 int32_t profileBlockLength = data.ReadInt32();
800 if (profileBlockLength == 0 || profileBlockLength > Constants::MAX_PARCEL_CAPACITY) {
801 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
802 return false;
803 }
804 auto dataInfo = data.ReadRawData(profileBlockLength);
805 if (!dataInfo) {
806 LOG_E(BMS_TAG_INSTALLD, "readRawData failed");
807 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
808 return false;
809 }
810 const unsigned char *profileBlock = reinterpret_cast<const unsigned char *>(dataInfo);
811 if (profileBlock == nullptr) {
812 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ERR_APPEXECFWK_PARCEL_ERROR);
813 return false;
814 }
815 ErrCode result = DeliverySignProfile(bundleName, profileBlockLength, profileBlock);
816 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
817 return true;
818 }
819
HandRemoveSignProfile(MessageParcel & data,MessageParcel & reply)820 bool InstalldHost::HandRemoveSignProfile(MessageParcel &data, MessageParcel &reply)
821 {
822 std::string bundleName = Str16ToStr8(data.ReadString16());
823
824 ErrCode result = RemoveSignProfile(bundleName);
825 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
826 return true;
827 }
828
HandleSetEncryptionDir(MessageParcel & data,MessageParcel & reply)829 bool InstalldHost::HandleSetEncryptionDir(MessageParcel &data, MessageParcel &reply)
830 {
831 int32_t uid = data.ReadInt32();
832 std::string bundleName = Str16ToStr8(data.ReadString16());
833 int32_t userId = data.ReadInt32();
834 std::string keyId = "";
835
836 ErrCode result = SetEncryptionPolicy(uid, bundleName, userId, keyId);
837 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
838 if (!reply.WriteString(keyId)) {
839 APP_LOGE("write keyId failed");
840 return false;
841 }
842 return true;
843 }
844
HandleDeleteEncryptionKeyId(MessageParcel & data,MessageParcel & reply)845 bool InstalldHost::HandleDeleteEncryptionKeyId(MessageParcel &data, MessageParcel &reply)
846 {
847 std::string bundleName = Str16ToStr8(data.ReadString16());
848 int32_t userId = data.ReadInt32();
849
850 ErrCode result = DeleteEncryptionKeyId(bundleName, userId);
851 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
852 return true;
853 }
854
HandleRemoveExtensionDir(MessageParcel & data,MessageParcel & reply)855 bool InstalldHost::HandleRemoveExtensionDir(MessageParcel &data, MessageParcel &reply)
856 {
857 int32_t userId = data.ReadInt32();
858 int32_t extensionBundleDirSize = data.ReadInt32();
859 if (extensionBundleDirSize <= 0 || extensionBundleDirSize > MAX_BATCH_QUERY_BUNDLE_SIZE) {
860 APP_LOGE("extensionBundleDirs count is error");
861 return false;
862 }
863 std::vector<std::string> extensionBundleDirs;
864 for (int32_t i = 0; i < extensionBundleDirSize; i++) {
865 std::string extensionBundleDir = data.ReadString();
866 if (extensionBundleDir.empty()) {
867 APP_LOGE("extensionBundleDirs %{public}d is empty", i);
868 return false;
869 }
870 extensionBundleDirs.push_back(extensionBundleDir);
871 }
872 ErrCode result = RemoveExtensionDir(userId, extensionBundleDirs);
873 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
874 return true;
875 }
876
HandleIsExistExtensionDir(MessageParcel & data,MessageParcel & reply)877 bool InstalldHost::HandleIsExistExtensionDir(MessageParcel &data, MessageParcel &reply)
878 {
879 int32_t userId = data.ReadInt32();
880 std::string extensionBundleDir = Str16ToStr8(data.ReadString16());
881
882 bool isExist = false;
883 ErrCode result = IsExistExtensionDir(userId, extensionBundleDir, isExist);
884 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
885 if (!reply.WriteBool(isExist)) {
886 LOG_E(BMS_TAG_INSTALLD, "fail to write bool from reply");
887 return false;
888 }
889 return true;
890 }
891
HandleGetExtensionSandboxTypeList(MessageParcel & data,MessageParcel & reply)892 bool InstalldHost::HandleGetExtensionSandboxTypeList(MessageParcel &data, MessageParcel &reply)
893 {
894 std::vector<std::string> typeList;
895 ErrCode result = GetExtensionSandboxTypeList(typeList);
896 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
897 if (result == ERR_OK) {
898 if (!reply.WriteStringVector(typeList)) {
899 APP_LOGE("write failed");
900 return false;
901 }
902 }
903 return true;
904 }
905
HandleCreateExtensionDataDir(MessageParcel & data,MessageParcel & reply)906 bool InstalldHost::HandleCreateExtensionDataDir(MessageParcel &data, MessageParcel &reply)
907 {
908 std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
909 if (info == nullptr) {
910 LOG_E(BMS_TAG_INSTALLD, "readParcelableInfo failed");
911 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
912 }
913 ErrCode result = CreateExtensionDataDir(*info);
914 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
915 return true;
916 }
917
HandleMoveHapToCodeDir(MessageParcel & data,MessageParcel & reply)918 bool InstalldHost::HandleMoveHapToCodeDir(MessageParcel &data, MessageParcel &reply)
919 {
920 std::string originPath = Str16ToStr8(data.ReadString16());
921 std::string targetPath = Str16ToStr8(data.ReadString16());
922
923 ErrCode result = MoveHapToCodeDir(originPath, targetPath);
924 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
925 return true;
926 }
927
RemoveCloseInstalldTask()928 void InstalldHost::RemoveCloseInstalldTask()
929 {
930 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
931 handler_->RemoveTask(UNLOAD_TASK_NAME);
932 }
933
AddCloseInstalldTask()934 void InstalldHost::AddCloseInstalldTask()
935 {
936 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
937 auto task = [] {
938 BundleMemoryGuard memoryGuard;
939 if (!SystemAbilityHelper::UnloadSystemAbility(INSTALLD_SERVICE_ID)) {
940 LOG_E(BMS_TAG_INSTALLD, "fail to unload to system ability manager");
941 return;
942 }
943 LOG_NOFUNC_I(BMS_TAG_INSTALLD, "unload Installd successfully");
944 };
945 handler_->PostTask(task, UNLOAD_TASK_NAME, UNLOAD_TIME);
946 LOG_D(BMS_TAG_INSTALLD, "send unload task successfully");
947 }
948 } // namespace AppExecFwk
949 } // namespace OHOS
950