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