1 /*
2 * Copyright (c) 2021-2023 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_wrapper.h"
19 #include "appexecfwk_errors.h"
20 #include "bundle_constants.h"
21 #include "bundle_framework_services_ipc_interface_code.h"
22 #include "bundle_memory_guard.h"
23 #include "parcel_macro.h"
24 #include "string_ex.h"
25 #include "system_ability_definition.h"
26 #include "system_ability_helper.h"
27
28 namespace OHOS {
29 namespace AppExecFwk {
30 namespace {
31 const int32_t UNLOAD_TIME = 3 * 60 * 1000; // 3 min for installd to unload
32 const std::string UNLOAD_TASK_NAME = "UnloadInstalldTask";
33 const std::string UNLOAD_QUEUE_NAME = "UnloadInstalldQueue";
34 }
35
InstalldHost()36 InstalldHost::InstalldHost()
37 {
38 Init();
39 InitEventHandler();
40 APP_LOGI("installd host instance is created");
41 }
42
~InstalldHost()43 InstalldHost::~InstalldHost()
44 {
45 APP_LOGI("installd host instance is destroyed");
46 }
47
Init()48 void InstalldHost::Init()
49 {
50 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::CREATE_BUNDLE_DIR),
51 &InstalldHost::HandleCreateBundleDir);
52 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_MODULE_FILES),
53 &InstalldHost::HandleExtractModuleFiles);
54 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::RENAME_MODULE_DIR),
55 &InstalldHost::HandleRenameModuleDir);
56 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::CREATE_BUNDLE_DATA_DIR),
57 &InstalldHost::HandleCreateBundleDataDir);
58 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_BUNDLE_DATA_DIR),
59 &InstalldHost::HandleRemoveBundleDataDir);
60 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_MODULE_DATA_DIR),
61 &InstalldHost::HandleRemoveModuleDataDir);
62 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::CLEAN_BUNDLE_DATA_DIR),
63 &InstalldHost::HandleCleanBundleDataDir);
64 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::SET_DIR_APL), &InstalldHost::HandleSetDirApl);
65 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::REMOVE_DIR), &InstalldHost::HandleRemoveDir);
66 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::GET_BUNDLE_STATS),
67 &InstalldHost::HandleGetBundleStats);
68 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::GET_BUNDLE_CACHE_PATH),
69 &InstalldHost::HandleGetBundleCachePath);
70 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::SCAN_DIR), &InstalldHost::HandleScanDir);
71 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::MOVE_FILE), &InstalldHost::HandleMoveFile);
72 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::COPY_FILE), &InstalldHost::HandleCopyFile);
73 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::MKDIR), &InstalldHost::HandleMkdir);
74 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::GET_FILE_STAT), &InstalldHost::HandleGetFileStat);
75 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_DIFF_FILES),
76 &InstalldHost::HandleExtractDiffFiles);
77 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::APPLY_DIFF_PATCH),
78 &InstalldHost::HandleApplyDiffPatch);
79 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_DIR), &InstalldHost::HandleIsExistDir);
80 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::IS_DIR_EMPTY), &InstalldHost::HandleIsDirEmpty);
81 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::OBTAIN_QUICK_FIX_DIR),
82 &InstalldHost::HandObtainQuickFixFileDir);
83 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::COPY_FILES), &InstalldHost::HandCopyFiles);
84 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::EXTRACT_FILES), &InstalldHost::HandleExtractFiles);
85 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::GET_NATIVE_LIBRARY_FILE_NAMES),
86 &InstalldHost::HandGetNativeLibraryFileNames);
87 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::EXECUTE_AOT), &InstalldHost::HandleExecuteAOT);
88 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::IS_EXIST_FILE), &InstalldHost::HandleIsExistFile);
89 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::VERIFY_CODE_SIGNATURE),
90 &InstalldHost::HandVerifyCodeSignature);
91 funcMap_.emplace(static_cast<uint32_t>(InstalldInterfaceCode::MOVE_FILES), &InstalldHost::HandMoveFiles);
92 }
93
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)94 int InstalldHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
95 {
96 BundleMemoryGuard memoryGuard;
97 APP_LOGD(
98 "installd host receives message from client, code = %{public}d, flags = %{public}d", code, option.GetFlags());
99 RemoveCloseInstalldTask();
100 std::u16string descripter = InstalldHost::GetDescriptor();
101 std::u16string remoteDescripter = data.ReadInterfaceToken();
102 if (descripter != remoteDescripter) {
103 APP_LOGE("installd host fail to write reply message due to the reply is nullptr");
104 return OHOS::ERR_APPEXECFWK_PARCEL_ERROR;
105 }
106 bool result = true;
107 APP_LOGD("funcMap_ size is %{public}d", static_cast<int32_t>(funcMap_.size()));
108 if (funcMap_.find(code) != funcMap_.end() && funcMap_[code] != nullptr) {
109 result = (this->*funcMap_[code])(data, reply);
110 } else {
111 APP_LOGW("installd host receives unknown code, code = %{public}u", code);
112 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
113 }
114 APP_LOGD("installd host finish to process message from client");
115 AddCloseInstalldTask();
116 return result ? NO_ERROR : OHOS::ERR_APPEXECFWK_PARCEL_ERROR;
117 }
118
InitEventHandler()119 void InstalldHost::InitEventHandler()
120 {
121 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
122 runner_ = EventRunner::Create(UNLOAD_QUEUE_NAME);
123 if (runner_ == nullptr) {
124 APP_LOGE("init event runner failed");
125 return;
126 }
127 handler_ = std::make_shared<EventHandler>(runner_);
128 handler_->PostTask([]() { BundleMemoryGuard memoryGuard; },
129 AppExecFwk::EventQueue::Priority::IMMEDIATE);
130 }
131
HandleCreateBundleDir(MessageParcel & data,MessageParcel & reply)132 bool InstalldHost::HandleCreateBundleDir(MessageParcel &data, MessageParcel &reply)
133 {
134 std::string bundleDir = Str16ToStr8(data.ReadString16());
135 APP_LOGI("bundleName %{public}s", bundleDir.c_str());
136 ErrCode result = CreateBundleDir(bundleDir);
137 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
138 return true;
139 }
140
HandleExtractModuleFiles(MessageParcel & data,MessageParcel & reply)141 bool InstalldHost::HandleExtractModuleFiles(MessageParcel &data, MessageParcel &reply)
142 {
143 std::string srcModulePath = Str16ToStr8(data.ReadString16());
144 std::string targetPath = Str16ToStr8(data.ReadString16());
145 std::string targetSoPath = Str16ToStr8(data.ReadString16());
146 std::string cpuAbi = Str16ToStr8(data.ReadString16());
147 APP_LOGI("extract module %{private}s", targetPath.c_str());
148 ErrCode result = ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi);
149 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
150 return true;
151 }
152
HandleExtractFiles(MessageParcel & data,MessageParcel & reply)153 bool InstalldHost::HandleExtractFiles(MessageParcel &data, MessageParcel &reply)
154 {
155 std::unique_ptr<ExtractParam> info(data.ReadParcelable<ExtractParam>());
156 if (info == nullptr) {
157 APP_LOGE("readParcelableInfo failed");
158 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
159 }
160
161 ErrCode result = ExtractFiles(*info);
162 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
163 return true;
164 }
165
HandleExecuteAOT(MessageParcel & data,MessageParcel & reply)166 bool InstalldHost::HandleExecuteAOT(MessageParcel &data, MessageParcel &reply)
167 {
168 std::unique_ptr<AOTArgs> aotArgs(data.ReadParcelable<AOTArgs>());
169 if (aotArgs == nullptr) {
170 APP_LOGE("readParcelableInfo failed");
171 return false;
172 }
173
174 ErrCode result = ExecuteAOT(*aotArgs);
175 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
176 return true;
177 }
178
HandleRenameModuleDir(MessageParcel & data,MessageParcel & reply)179 bool InstalldHost::HandleRenameModuleDir(MessageParcel &data, MessageParcel &reply)
180 {
181 std::string oldPath = Str16ToStr8(data.ReadString16());
182 std::string newPath = Str16ToStr8(data.ReadString16());
183 APP_LOGI("rename moduleDir %{private}s", oldPath.c_str());
184 ErrCode result = RenameModuleDir(oldPath, newPath);
185 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
186 return true;
187 }
188
HandleCreateBundleDataDir(MessageParcel & data,MessageParcel & reply)189 bool InstalldHost::HandleCreateBundleDataDir(MessageParcel &data, MessageParcel &reply)
190 {
191 std::unique_ptr<CreateDirParam> info(data.ReadParcelable<CreateDirParam>());
192 if (info == nullptr) {
193 APP_LOGE("readParcelableInfo failed");
194 return ERR_APPEXECFWK_INSTALL_INSTALLD_SERVICE_ERROR;
195 }
196 ErrCode result = CreateBundleDataDir(*info);
197 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
198 return true;
199 }
200
HandleRemoveBundleDataDir(MessageParcel & data,MessageParcel & reply)201 bool InstalldHost::HandleRemoveBundleDataDir(MessageParcel &data, MessageParcel &reply)
202 {
203 std::string bundleName = Str16ToStr8(data.ReadString16());
204 int userid = data.ReadInt32();
205 ErrCode result = RemoveBundleDataDir(bundleName, userid);
206 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
207 return true;
208 }
209
HandleRemoveModuleDataDir(MessageParcel & data,MessageParcel & reply)210 bool InstalldHost::HandleRemoveModuleDataDir(MessageParcel &data, MessageParcel &reply)
211 {
212 std::string moduleNmae = Str16ToStr8(data.ReadString16());
213 int userid = data.ReadInt32();
214 ErrCode result = RemoveModuleDataDir(moduleNmae, userid);
215 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
216 return true;
217 }
218
HandleRemoveDir(MessageParcel & data,MessageParcel & reply)219 bool InstalldHost::HandleRemoveDir(MessageParcel &data, MessageParcel &reply)
220 {
221 std::string removedDir = Str16ToStr8(data.ReadString16());
222 ErrCode result = RemoveDir(removedDir);
223 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
224 return true;
225 }
226
HandleCleanBundleDataDir(MessageParcel & data,MessageParcel & reply)227 bool InstalldHost::HandleCleanBundleDataDir(MessageParcel &data, MessageParcel &reply)
228 {
229 std::string bundleDir = Str16ToStr8(data.ReadString16());
230 ErrCode result = CleanBundleDataDir(bundleDir);
231 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
232 return true;
233 }
234
HandleGetBundleStats(MessageParcel & data,MessageParcel & reply)235 bool InstalldHost::HandleGetBundleStats(MessageParcel &data, MessageParcel &reply)
236 {
237 std::string bundleName = Str16ToStr8(data.ReadString16());
238 int32_t userId = data.ReadInt32();
239 std::vector<int64_t> bundleStats;
240 ErrCode result = GetBundleStats(bundleName, userId, bundleStats);
241 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
242 if (!reply.WriteInt64Vector(bundleStats)) {
243 APP_LOGE("HandleGetBundleStats write failed");
244 return false;
245 }
246 return true;
247 }
248
HandleSetDirApl(MessageParcel & data,MessageParcel & reply)249 bool InstalldHost::HandleSetDirApl(MessageParcel &data, MessageParcel &reply)
250 {
251 std::string dataDir = Str16ToStr8(data.ReadString16());
252 std::string bundleName = Str16ToStr8(data.ReadString16());
253 std::string apl = Str16ToStr8(data.ReadString16());
254 bool isPreInstallApp = data.ReadBool();
255 bool debug = data.ReadBool();
256 ErrCode result = SetDirApl(dataDir, bundleName, apl, isPreInstallApp, debug);
257 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
258 return true;
259 }
260
HandleGetBundleCachePath(MessageParcel & data,MessageParcel & reply)261 bool InstalldHost::HandleGetBundleCachePath(MessageParcel &data, MessageParcel &reply)
262 {
263 std::string dir = Str16ToStr8(data.ReadString16());
264 std::vector<std::string> cachePath;
265 ErrCode result = GetBundleCachePath(dir, cachePath);
266 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
267 if (!reply.WriteStringVector(cachePath)) {
268 APP_LOGE("fail to GetBundleCachePath from reply");
269 return false;
270 }
271 return true;
272 }
273
HandleScanDir(MessageParcel & data,MessageParcel & reply)274 bool InstalldHost::HandleScanDir(MessageParcel &data, MessageParcel &reply)
275 {
276 std::string dir = Str16ToStr8(data.ReadString16());
277 ScanMode scanMode = static_cast<ScanMode>(data.ReadInt32());
278 ResultMode resultMode = static_cast<ResultMode>(data.ReadInt32());
279 std::vector<std::string> paths;
280 ErrCode result = ScanDir(dir, scanMode, resultMode, paths);
281 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
282 if (!reply.WriteStringVector(paths)) {
283 APP_LOGE("fail to Scan from reply");
284 return false;
285 }
286
287 return true;
288 }
289
HandleMoveFile(MessageParcel & data,MessageParcel & reply)290 bool InstalldHost::HandleMoveFile(MessageParcel &data, MessageParcel &reply)
291 {
292 std::string oldPath = Str16ToStr8(data.ReadString16());
293 std::string newPath = Str16ToStr8(data.ReadString16());
294 ErrCode result = MoveFile(oldPath, newPath);
295 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
296 return true;
297 }
298
HandleCopyFile(MessageParcel & data,MessageParcel & reply)299 bool InstalldHost::HandleCopyFile(MessageParcel &data, MessageParcel &reply)
300 {
301 std::string oldPath = Str16ToStr8(data.ReadString16());
302 std::string newPath = Str16ToStr8(data.ReadString16());
303 std::string signatureFilePath = Str16ToStr8(data.ReadString16());
304
305 ErrCode result = CopyFile(oldPath, newPath, signatureFilePath);
306 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
307 return true;
308 }
309
HandleMkdir(MessageParcel & data,MessageParcel & reply)310 bool InstalldHost::HandleMkdir(MessageParcel &data, MessageParcel &reply)
311 {
312 std::string dir = Str16ToStr8(data.ReadString16());
313 int32_t mode = data.ReadInt32();
314 int32_t uid = data.ReadInt32();
315 int32_t gid = data.ReadInt32();
316 ErrCode result = Mkdir(dir, mode, uid, gid);
317 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
318 return true;
319 }
320
HandleGetFileStat(MessageParcel & data,MessageParcel & reply)321 bool InstalldHost::HandleGetFileStat(MessageParcel &data, MessageParcel &reply)
322 {
323 std::string file = Str16ToStr8(data.ReadString16());
324 FileStat fileStat;
325 ErrCode result = GetFileStat(file, fileStat);
326 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
327 if (!reply.WriteParcelable(&fileStat)) {
328 APP_LOGE("fail to GetFileStat from reply");
329 return false;
330 }
331
332 return true;
333 }
334
HandleExtractDiffFiles(MessageParcel & data,MessageParcel & reply)335 bool InstalldHost::HandleExtractDiffFiles(MessageParcel &data, MessageParcel &reply)
336 {
337 std::string filePath = Str16ToStr8(data.ReadString16());
338 std::string targetPath = Str16ToStr8(data.ReadString16());
339 std::string cpuAbi = Str16ToStr8(data.ReadString16());
340 ErrCode result = ExtractDiffFiles(filePath, targetPath, cpuAbi);
341 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
342 return true;
343 }
344
HandleApplyDiffPatch(MessageParcel & data,MessageParcel & reply)345 bool InstalldHost::HandleApplyDiffPatch(MessageParcel &data, MessageParcel &reply)
346 {
347 std::string oldSoPath = Str16ToStr8(data.ReadString16());
348 std::string diffFilePath = Str16ToStr8(data.ReadString16());
349 std::string newSoPath = Str16ToStr8(data.ReadString16());
350 ErrCode result = ApplyDiffPatch(oldSoPath, diffFilePath, newSoPath);
351 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
352 return true;
353 }
354
HandleIsExistDir(MessageParcel & data,MessageParcel & reply)355 bool InstalldHost::HandleIsExistDir(MessageParcel &data, MessageParcel &reply)
356 {
357 std::string path = Str16ToStr8(data.ReadString16());
358 bool isExist = false;
359 ErrCode result = IsExistDir(path, isExist);
360 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
361 if (!reply.WriteBool(isExist)) {
362 APP_LOGE("fail to IsExistDir from reply");
363 return false;
364 }
365 return true;
366 }
367
HandleIsExistFile(MessageParcel & data,MessageParcel & reply)368 bool InstalldHost::HandleIsExistFile(MessageParcel &data, MessageParcel &reply)
369 {
370 std::string path = Str16ToStr8(data.ReadString16());
371 bool isExist = false;
372 ErrCode result = IsExistFile(path, isExist);
373 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
374 if (!reply.WriteBool(isExist)) {
375 APP_LOGE("fail to IsExistFile from reply");
376 return false;
377 }
378 return true;
379 }
380
HandleIsDirEmpty(MessageParcel & data,MessageParcel & reply)381 bool InstalldHost::HandleIsDirEmpty(MessageParcel &data, MessageParcel &reply)
382 {
383 std::string dir = Str16ToStr8(data.ReadString16());
384 bool isDirEmpty = false;
385 ErrCode result = IsDirEmpty(dir, isDirEmpty);
386 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
387 if (!reply.WriteBool(isDirEmpty)) {
388 APP_LOGE("write isDirEmpty failed");
389 return false;
390 }
391 return true;
392 }
393
HandObtainQuickFixFileDir(MessageParcel & data,MessageParcel & reply)394 bool InstalldHost::HandObtainQuickFixFileDir(MessageParcel &data, MessageParcel &reply)
395 {
396 std::string dir = Str16ToStr8(data.ReadString16());
397 std::vector<std::string> dirVec;
398 ErrCode result = ObtainQuickFixFileDir(dir, dirVec);
399 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
400 if ((result == ERR_OK) && !reply.WriteStringVector(dirVec)) {
401 APP_LOGE("fail to obtain quick fix file dir from reply");
402 return false;
403 }
404 return true;
405 }
406
HandCopyFiles(MessageParcel & data,MessageParcel & reply)407 bool InstalldHost::HandCopyFiles(MessageParcel &data, MessageParcel &reply)
408 {
409 std::string sourceDir = Str16ToStr8(data.ReadString16());
410 std::string destinationDir = Str16ToStr8(data.ReadString16());
411
412 ErrCode result = CopyFiles(sourceDir, destinationDir);
413 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
414 return true;
415 }
416
HandGetNativeLibraryFileNames(MessageParcel & data,MessageParcel & reply)417 bool InstalldHost::HandGetNativeLibraryFileNames(MessageParcel &data, MessageParcel &reply)
418 {
419 std::string filePath = Str16ToStr8(data.ReadString16());
420 std::string cupAbi = Str16ToStr8(data.ReadString16());
421 std::vector<std::string> fileNames;
422 ErrCode result = GetNativeLibraryFileNames(filePath, cupAbi, fileNames);
423 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
424 if ((result == ERR_OK) && !reply.WriteStringVector(fileNames)) {
425 APP_LOGE("fail to obtain fileNames from reply");
426 return false;
427 }
428 return true;
429 }
430
HandVerifyCodeSignature(MessageParcel & data,MessageParcel & reply)431 bool InstalldHost::HandVerifyCodeSignature(MessageParcel &data, MessageParcel &reply)
432 {
433 std::string modulePath = Str16ToStr8(data.ReadString16());
434 std::string cpuAbi = Str16ToStr8(data.ReadString16());
435 std::string targetSoPath = Str16ToStr8(data.ReadString16());
436 std::string signatureFileDir = Str16ToStr8(data.ReadString16());
437
438 ErrCode result = VerifyCodeSignature(modulePath, cpuAbi, targetSoPath, signatureFileDir);
439 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
440 return true;
441 }
442
HandMoveFiles(MessageParcel & data,MessageParcel & reply)443 bool InstalldHost::HandMoveFiles(MessageParcel &data, MessageParcel &reply)
444 {
445 std::string srcDir = Str16ToStr8(data.ReadString16());
446 std::string desDir = Str16ToStr8(data.ReadString16());
447
448 ErrCode result = MoveFiles(srcDir, desDir);
449 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, result);
450 return true;
451 }
452
RemoveCloseInstalldTask()453 void InstalldHost::RemoveCloseInstalldTask()
454 {
455 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
456 handler_->RemoveTask(UNLOAD_TASK_NAME);
457 }
458
AddCloseInstalldTask()459 void InstalldHost::AddCloseInstalldTask()
460 {
461 std::lock_guard<std::mutex> lock(unloadTaskMutex_);
462 auto task = [] {
463 BundleMemoryGuard memoryGuard;
464 if (!SystemAbilityHelper::UnloadSystemAbility(INSTALLD_SERVICE_ID)) {
465 APP_LOGE("fail to unload to system ability manager");
466 return;
467 }
468 APP_LOGI("unload Installd successfully");
469 };
470 handler_->PostTask(task, UNLOAD_TASK_NAME, UNLOAD_TIME);
471 APP_LOGD("send unload task successfully");
472 }
473 } // namespace AppExecFwk
474 } // namespace OHOS
475