1 /*
2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "verify_manager_host_impl.h"
17
18 #include <sys/wait.h>
19 #include <unistd.h>
20
21 #include "bundle_mgr_service.h"
22 #include "bundle_permission_mgr.h"
23 #include "installd_client.h"
24 #include "ipc_skeleton.h"
25 #include "verify_util.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 constexpr const char* SEPARATOR = "/";
31 constexpr const char* ABCS_DIR = "abcs";
32 constexpr const char* ABCS_TEMP_DIR = "temp/";
33 constexpr const char* DATA_STORAGE_BUNDLE = "/data/storage/el1/bundle/";
34 constexpr const char* DATA_STORAGE_EL1_BASE = "/data/storage/el1/base/";
35 constexpr const char* DATA_STORAGE_EL1_DATABASE = "/data/storage/el1/database/";
36 constexpr const char* DATA_STORAGE_EL2_BASE = "/data/storage/el2/base/";
37 constexpr const char* DATA_STORAGE_EL2_DATABASE = "/data/storage/el2/database/";
38 constexpr const char* DATA_STORAGE_EL3_BASE = "/data/storage/el3/base/";
39 constexpr const char* DATA_STORAGE_EL3_DATABASE = "/data/storage/el3/database/";
40 constexpr const char* DATA_STORAGE_EL4_BASE = "/data/storage/el4/base/";
41 constexpr const char* DATA_STORAGE_EL4_DATABASE = "/data/storage/el4/database/";
42 constexpr const char* ABC_FILE_SUFFIX = ".abc";
43
IsValidPath(const std::string & path)44 bool IsValidPath(const std::string &path)
45 {
46 if (path.empty()) {
47 return false;
48 }
49 if (path.find("..") != std::string::npos) {
50 return false;
51 }
52 return true;
53 }
54
GetRootDir(const std::string & bundleName)55 std::string GetRootDir(const std::string &bundleName)
56 {
57 std::string rootDir;
58 rootDir.append(Constants::BUNDLE_CODE_DIR).append(ServiceConstants::PATH_SEPARATOR)
59 .append(bundleName).append(ServiceConstants::PATH_SEPARATOR)
60 .append(ABCS_DIR).append(ServiceConstants::PATH_SEPARATOR);
61 return rootDir;
62 }
63
GetTempRootDir(const std::string & bundleName)64 std::string GetTempRootDir(const std::string &bundleName)
65 {
66 std::string tempRootDir;
67 tempRootDir.append(Constants::BUNDLE_CODE_DIR).append(ServiceConstants::PATH_SEPARATOR)
68 .append(bundleName).append(ServiceConstants::PATH_SEPARATOR).append(ABCS_DIR)
69 .append(ServiceConstants::PATH_SEPARATOR).append(ABCS_TEMP_DIR);
70 return tempRootDir;
71 }
72
GetDataDir(const std::string & path,std::string & suffix,std::string & el,std::string & baseType)73 bool GetDataDir(const std::string &path, std::string &suffix, std::string &el, std::string &baseType)
74 {
75 if (BundleUtil::StartWith(path, DATA_STORAGE_EL1_BASE)) {
76 suffix = path.substr(strlen(DATA_STORAGE_EL1_BASE));
77 el = ServiceConstants::DIR_EL1;
78 baseType = ServiceConstants::BASE;
79 return true;
80 }
81
82 if (BundleUtil::StartWith(path, DATA_STORAGE_EL1_DATABASE)) {
83 suffix = path.substr(strlen(DATA_STORAGE_EL1_DATABASE));
84 el = ServiceConstants::DIR_EL1;
85 baseType = ServiceConstants::DATABASE;
86 return true;
87 }
88
89 if (BundleUtil::StartWith(path, DATA_STORAGE_EL2_BASE)) {
90 suffix = path.substr(strlen(DATA_STORAGE_EL2_BASE));
91 el = ServiceConstants::DIR_EL2;
92 baseType = ServiceConstants::BASE;
93 return true;
94 }
95
96 if (BundleUtil::StartWith(path, DATA_STORAGE_EL2_DATABASE)) {
97 suffix = path.substr(strlen(DATA_STORAGE_EL2_DATABASE));
98 el = ServiceConstants::DIR_EL2;
99 baseType = ServiceConstants::DATABASE;
100 return true;
101 }
102
103 if (BundleUtil::StartWith(path, DATA_STORAGE_EL3_BASE)) {
104 suffix = path.substr(strlen(DATA_STORAGE_EL3_BASE));
105 el = ServiceConstants::DIR_EL3;
106 baseType = ServiceConstants::BASE;
107 return true;
108 }
109
110 if (BundleUtil::StartWith(path, DATA_STORAGE_EL3_DATABASE)) {
111 suffix = path.substr(strlen(DATA_STORAGE_EL3_DATABASE));
112 el = ServiceConstants::DIR_EL3;
113 baseType = ServiceConstants::DATABASE;
114 return true;
115 }
116
117 if (BundleUtil::StartWith(path, DATA_STORAGE_EL4_BASE)) {
118 suffix = path.substr(strlen(DATA_STORAGE_EL4_BASE));
119 el = ServiceConstants::DIR_EL4;
120 baseType = ServiceConstants::BASE;
121 return true;
122 }
123
124 if (BundleUtil::StartWith(path, DATA_STORAGE_EL4_DATABASE)) {
125 suffix = path.substr(strlen(DATA_STORAGE_EL4_DATABASE));
126 el = ServiceConstants::DIR_EL4;
127 baseType = ServiceConstants::DATABASE;
128 return true;
129 }
130
131 return false;
132 }
133 }
134
VerifyManagerHostImpl()135 VerifyManagerHostImpl::VerifyManagerHostImpl()
136 {
137 APP_LOGI("create VerifyManagerHostImpl");
138 }
139
~VerifyManagerHostImpl()140 VerifyManagerHostImpl::~VerifyManagerHostImpl()
141 {
142 APP_LOGI("destroy VerifyManagerHostImpl");
143 }
144
CallbackEnter(uint32_t code)145 int32_t VerifyManagerHostImpl::CallbackEnter([[maybe_unused]] uint32_t code)
146 {
147 BundleMemoryGuard::SetBundleMemoryGuard();
148 return ERR_NONE;
149 }
150
CallbackExit(uint32_t code,int32_t result)151 int32_t VerifyManagerHostImpl::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
152 {
153 BundleMemoryGuard::ClearBundleMemoryGuard();
154 return ERR_NONE;
155 }
156
Verify(const std::vector<std::string> & abcPaths,int32_t & funcResult)157 ErrCode VerifyManagerHostImpl::Verify(const std::vector<std::string> &abcPaths, int32_t &funcResult)
158 {
159 if (!BundlePermissionMgr::IsSystemApp() &&
160 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_TWELVE)) {
161 APP_LOGE("non-system app calling system api");
162 funcResult = ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
163 return ERR_OK;
164 }
165
166 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_RUN_DYN_CODE)) {
167 APP_LOGE("verify permission failed");
168 funcResult = ERR_BUNDLE_MANAGER_VERIFY_PERMISSION_DENIED;
169 return ERR_OK;
170 }
171
172 std::string bundleName;
173 int32_t userId = BundleUtil::GetUserIdByCallingUid();
174 if (!GetCallingBundleName(bundleName) || bundleName.empty()) {
175 APP_LOGE("GetCallingBundleName failed");
176 funcResult = ERR_BUNDLE_MANAGER_VERIFY_PARAM_ERROR;
177 return ERR_OK;
178 }
179
180 auto &mtx = GetBundleMutex(bundleName);
181 std::lock_guard lock {mtx};
182 if (!CheckFileParam(abcPaths)) {
183 APP_LOGE("CheckFile failed");
184 funcResult = ERR_BUNDLE_MANAGER_VERIFY_PARAM_ERROR;
185 return ERR_OK;
186 }
187
188 if (!CopyFilesToTempDir(bundleName, userId, abcPaths)) {
189 APP_LOGE("Copy failed");
190 RemoveTempFiles(bundleName);
191 funcResult = ERR_BUNDLE_MANAGER_VERIFY_PARAM_ERROR;
192 return ERR_OK;
193 }
194
195 ErrCode ret = InnerVerify(bundleName, abcPaths);
196 RemoveTempFiles(bundleName);
197 funcResult = ret;
198 return ERR_OK;
199 }
200
GetCallingBundleName(std::string & bundleName)201 bool VerifyManagerHostImpl::GetCallingBundleName(std::string &bundleName)
202 {
203 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
204 if (dataMgr == nullptr) {
205 APP_LOGE("verify failed, dataMgr is null");
206 return false;
207 }
208
209 int32_t callingUid = IPCSkeleton::GetCallingUid();
210 InnerBundleInfo innerBundleInfo;
211 if (dataMgr->GetInnerBundleInfoByUid(callingUid, innerBundleInfo) != ERR_OK) {
212 APP_LOGE("verify failed, callingUid is %{public}d", callingUid);
213 return false;
214 }
215
216 bundleName = innerBundleInfo.GetBundleName();
217 return true;
218 }
219
CopyFilesToTempDir(const std::string & bundleName,int32_t userId,const std::vector<std::string> & abcPaths)220 bool VerifyManagerHostImpl::CopyFilesToTempDir(
221 const std::string &bundleName,
222 int32_t userId,
223 const std::vector<std::string> &abcPaths)
224 {
225 std::string tempRootDir = GetTempRootDir(bundleName);
226 ErrCode result = MkdirIfNotExist(tempRootDir);
227 if (result != ERR_OK) {
228 APP_LOGE("mkdir tempRootDir %{public}s faild %{public}d", tempRootDir.c_str(), result);
229 return false;
230 }
231
232 for (size_t i = 0; i < abcPaths.size(); ++i) {
233 std::string tempCopyPath = tempRootDir + abcPaths[i];
234 std::string realPath = GetRealPath(bundleName, userId, abcPaths[i]);
235 if (realPath.empty()) {
236 APP_LOGE("abcPath %{public}s is illegal", abcPaths[i].c_str());
237 return false;
238 }
239
240 APP_LOGD("realPath is %{public}s", realPath.c_str());
241 std::string fileDir;
242 if (!GetFileDir(tempCopyPath, fileDir)) {
243 APP_LOGE("GetFileDir failed %{public}s", realPath.c_str());
244 return false;
245 }
246
247 result = MkdirIfNotExist(fileDir);
248 if (result != ERR_OK) {
249 APP_LOGE("mkdir fileDir %{public}s faild %{public}d", fileDir.c_str(), result);
250 return false;
251 }
252
253 result = InstalldClient::GetInstance()->CopyFile(realPath, tempCopyPath, "");
254 if (result != ERR_OK) {
255 APP_LOGE("CopyFile tempDir %{public}s faild %{public}d", realPath.c_str(), result);
256 return false;
257 }
258 }
259
260 return true;
261 }
262
GetRealPath(const std::string & bundleName,int32_t userId,const std::string & relativePath)263 std::string VerifyManagerHostImpl::GetRealPath(
264 const std::string &bundleName, int32_t userId, const std::string &relativePath)
265 {
266 auto path = relativePath;
267 if (!BundleUtil::StartWith(path, ServiceConstants::PATH_SEPARATOR)) {
268 path = ServiceConstants::PATH_SEPARATOR + path;
269 }
270
271 std::string filePath;
272 if (BundleUtil::StartWith(path, DATA_STORAGE_BUNDLE)) {
273 auto suffix = path.substr(strlen(DATA_STORAGE_BUNDLE));
274 filePath.append(Constants::BUNDLE_CODE_DIR).append(ServiceConstants::PATH_SEPARATOR)
275 .append(bundleName).append(ServiceConstants::PATH_SEPARATOR).append(suffix);
276 return filePath;
277 }
278
279 std::string suffix;
280 std::string el;
281 std::string baseType;
282 if (!GetDataDir(path, suffix, el, baseType)) {
283 APP_LOGW("The path %{public}s is illegal", path.c_str());
284 return filePath;
285 }
286
287 filePath.append(ServiceConstants::BUNDLE_APP_DATA_BASE_DIR).append(el)
288 .append(ServiceConstants::PATH_SEPARATOR).append(std::to_string(userId)).append(baseType)
289 .append(bundleName).append(ServiceConstants::PATH_SEPARATOR).append(suffix);
290 return filePath;
291 }
292
InnerVerify(const std::string & bundleName,const std::vector<std::string> & abcPaths)293 ErrCode VerifyManagerHostImpl::InnerVerify(
294 const std::string &bundleName,
295 const std::vector<std::string> &abcPaths)
296 {
297 if (!VerifyAbc(GetTempRootDir(bundleName), abcPaths)) {
298 APP_LOGE("verify abc failed");
299 return ERR_BUNDLE_MANAGER_VERIFY_VERIFY_ABC_FAILED;
300 }
301
302 if (!MoveAbc(bundleName, abcPaths)) {
303 APP_LOGE("move abc failed");
304 return ERR_BUNDLE_MANAGER_VERIFY_VERIFY_ABC_FAILED;
305 }
306
307 APP_LOGI("verify abc success");
308 return ERR_OK;
309 }
310
CheckFileParam(const std::vector<std::string> & abcPaths)311 bool VerifyManagerHostImpl::CheckFileParam(const std::vector<std::string> &abcPaths)
312 {
313 if (abcPaths.empty()) {
314 APP_LOGE("CheckFile abcPath failed due to abcPaths is empty");
315 return false;
316 }
317
318 for (const auto &abcPath : abcPaths) {
319 if (!IsValidPath(abcPath)) {
320 APP_LOGE("CheckFile abcPath(%{public}s) failed due to invalid path", abcPath.c_str());
321 return false;
322 }
323 if (!BundleUtil::CheckFileType(abcPath, ABC_FILE_SUFFIX)) {
324 APP_LOGE("CheckFile abcPath(%{public}s) failed due to not abc suffix", abcPath.c_str());
325 return false;
326 }
327 }
328
329 return true;
330 }
331
VerifyAbc(const std::string & rootDir,const std::vector<std::string> & names)332 bool VerifyManagerHostImpl::VerifyAbc(
333 const std::string &rootDir, const std::vector<std::string> &names)
334 {
335 std::vector<std::string> paths;
336 paths.reserve(names.size());
337 for (const auto &name : names) {
338 paths.emplace_back(rootDir + name);
339 }
340
341 return VerifyAbc(paths);
342 }
343
VerifyAbc(const std::vector<std::string> & abcPaths)344 bool VerifyManagerHostImpl::VerifyAbc(const std::vector<std::string> &abcPaths)
345 {
346 APP_LOGD("current process pid: %{public}d, ppid: %{public}d", getpid(), getppid());
347 pid_t pid = fork();
348 if (pid < 0) {
349 APP_LOGE("fork child process failed");
350 return false;
351 } else if (pid == 0) {
352 APP_LOGD("child process pid: %{public}d, ppid: %{public}d", getpid(), getppid());
353 for (const auto &abcPath : abcPaths) {
354 if (!BundleUtil::IsExistFile(abcPath)) {
355 APP_LOGE("abcPath is not exist: %{public}s", abcPath.c_str());
356 _exit(1);
357 }
358
359 if (!VerifyUtil::VerifyAbc(abcPath)) {
360 APP_LOGE("verify abc failed");
361 _exit(1);
362 }
363 }
364 APP_LOGI("verify abc successfully");
365 _exit(0);
366 } else {
367 int status;
368 pid_t childPid = waitpid(pid, &status, 0);
369 if (childPid == -1) {
370 APP_LOGE("waitpid failed");
371 return false;
372 }
373 if (WIFEXITED(status)) {
374 int exitStatus = WEXITSTATUS(status);
375 if (exitStatus != 0) {
376 APP_LOGE("verify abc failed");
377 return false;
378 }
379 } else {
380 APP_LOGE("child process did not exit normally");
381 return false;
382 }
383 }
384 APP_LOGD("end process pid: %{public}d, ppid: %{public}d", getpid(), getppid());
385 return true;
386 }
387
RemoveTempFiles(const std::string & bundleName)388 void VerifyManagerHostImpl::RemoveTempFiles(const std::string &bundleName)
389 {
390 APP_LOGI("RemoveTempFiles");
391 auto tempRootDir = GetTempRootDir(bundleName);
392 InstalldClient::GetInstance()->RemoveDir(tempRootDir);
393 }
394
RemoveTempFiles(const std::vector<std::string> & paths)395 void VerifyManagerHostImpl::RemoveTempFiles(const std::vector<std::string> &paths)
396 {
397 APP_LOGI("RemoveTempFiles");
398 for (const auto &path : paths) {
399 if (!BundleUtil::DeleteDir(path)) {
400 APP_LOGW("RemoveFile %{private}s failed", path.c_str());
401 }
402 }
403 }
404
GetFileName(const std::string & sourcePath,std::string & fileName)405 bool VerifyManagerHostImpl::GetFileName(const std::string &sourcePath, std::string &fileName)
406 {
407 size_t pos = sourcePath.find_last_of(SEPARATOR);
408 if (pos == std::string::npos) {
409 APP_LOGE("invalid sourcePath");
410 return false;
411 }
412
413 fileName = sourcePath.substr(pos + 1);
414 return !fileName.empty();
415 }
416
GetFileDir(const std::string & sourcePath,std::string & fileDir)417 bool VerifyManagerHostImpl::GetFileDir(const std::string &sourcePath, std::string &fileDir)
418 {
419 size_t pos = sourcePath.find_last_of(SEPARATOR);
420 if (pos == std::string::npos) {
421 APP_LOGE("invalid sourcePath");
422 return false;
423 }
424
425 fileDir = sourcePath.substr(0, pos);
426 return !fileDir.empty();
427 }
428
MkdirIfNotExist(const std::string & dir)429 ErrCode VerifyManagerHostImpl::MkdirIfNotExist(const std::string &dir)
430 {
431 bool isDirExist = false;
432 ErrCode result = InstalldClient::GetInstance()->IsExistDir(dir, isDirExist);
433 if (result != ERR_OK) {
434 APP_LOGE("Check if dir exist failed %{public}d", result);
435 return result;
436 }
437
438 if (!isDirExist) {
439 result = InstalldClient::GetInstance()->CreateBundleDir(dir);
440 if (result != ERR_OK) {
441 APP_LOGE("Create dir failed %{public}d", result);
442 return result;
443 }
444 }
445 return result;
446 }
447
MoveAbc(const std::string & bundleName,const std::vector<std::string> & abcPaths)448 bool VerifyManagerHostImpl::MoveAbc(
449 const std::string &bundleName,
450 const std::vector<std::string> &abcPaths)
451 {
452 auto rootDir = GetRootDir(bundleName);
453 auto tempRootDir = GetTempRootDir(bundleName);
454 std::vector<std::string> hasMovePaths;
455 ErrCode result = ERR_OK;
456 for (size_t i = 0; i < abcPaths.size(); ++i) {
457 std::string tempPath = tempRootDir + abcPaths[i];
458 std::string targetPath = rootDir + abcPaths[i];
459 std::string fileDir;
460 if (!GetFileDir(targetPath, fileDir)) {
461 APP_LOGE("GetFileDir failed %{public}s", targetPath.c_str());
462 Rollback(hasMovePaths);
463 return false;
464 }
465
466 result = MkdirIfNotExist(fileDir);
467 if (result != ERR_OK) {
468 APP_LOGE("mkdir fileDir %{public}s faild %{public}d", fileDir.c_str(), result);
469 Rollback(hasMovePaths);
470 return false;
471 }
472
473 result = InstalldClient::GetInstance()->MoveFile(tempPath, targetPath);
474 if (result != ERR_OK) {
475 APP_LOGE("move file to real path failed %{public}d", result);
476 Rollback(hasMovePaths);
477 return false;
478 }
479
480 hasMovePaths.emplace_back(targetPath);
481 }
482
483 return true;
484 }
485
Rollback(const std::string & rootDir,const std::vector<std::string> & names)486 void VerifyManagerHostImpl::Rollback(
487 const std::string &rootDir, const std::vector<std::string> &names)
488 {
489 std::vector<std::string> paths;
490 for (const auto &name : names) {
491 paths.emplace_back(rootDir + name);
492 }
493
494 Rollback(paths);
495 }
496
Rollback(const std::vector<std::string> & paths)497 void VerifyManagerHostImpl::Rollback(const std::vector<std::string> &paths)
498 {
499 for (const auto &abcPath : paths) {
500 auto result = BundleUtil::DeleteDir(abcPath);
501 if (result != ERR_OK) {
502 APP_LOGE("move file to real path failed %{public}d", result);
503 }
504 }
505 }
506
VerifyDeleteAbcPermission(const std::string & path)507 ErrCode VerifyManagerHostImpl::VerifyDeleteAbcPermission(const std::string &path)
508 {
509 if (!BundlePermissionMgr::IsSystemApp() &&
510 !BundlePermissionMgr::VerifyCallingBundleSdkVersion(ServiceConstants::API_VERSION_TWELVE)) {
511 APP_LOGE("non-system app calling system api");
512 return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
513 }
514 if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_RUN_DYN_CODE)) {
515 APP_LOGE("DeleteAbc failed due to permission denied");
516 return ERR_BUNDLE_MANAGER_VERIFY_PERMISSION_DENIED;
517 }
518 if (!IsValidPath(path)) {
519 APP_LOGE("DeleteAbc failed due to invalid path");
520 return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
521 }
522 if (!BundleUtil::CheckFileType(path, ABC_FILE_SUFFIX)) {
523 APP_LOGE("DeleteAbc failed due to not abc file");
524 return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
525 }
526 return ERR_OK;
527 }
528
DeleteAbc(const std::string & path,int32_t & funcResult)529 ErrCode VerifyManagerHostImpl::DeleteAbc(const std::string &path, int32_t &funcResult)
530 {
531 funcResult = VerifyDeleteAbcPermission(path);
532 if (funcResult != ERR_OK) {
533 return ERR_OK;
534 }
535 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
536 if (dataMgr == nullptr) {
537 APP_LOGE("DeleteAbc failed due to dataMgr is null");
538 funcResult = ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
539 return ERR_OK;
540 }
541 int32_t callingUid = IPCSkeleton::GetCallingUid();
542 InnerBundleInfo innerBundleInfo;
543 if (dataMgr->GetInnerBundleInfoByUid(callingUid, innerBundleInfo) != ERR_OK) {
544 APP_LOGE("DeleteAbc failed due to get callingUid failed");
545 funcResult = ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
546 return ERR_OK;
547 }
548
549 auto &mtx = GetBundleMutex(innerBundleInfo.GetBundleName());
550 std::lock_guard lock {mtx};
551 std::string realPath;
552 realPath.append(Constants::BUNDLE_CODE_DIR).append(ServiceConstants::PATH_SEPARATOR)
553 .append(innerBundleInfo.GetBundleName()).append(ServiceConstants::PATH_SEPARATOR)
554 .append(ABCS_DIR).append(ServiceConstants::PATH_SEPARATOR).append(path);
555 bool isExist = false;
556 auto result = InstalldClient::GetInstance()->IsExistFile(realPath, isExist);
557 if (result != ERR_OK) {
558 APP_LOGE("DeleteAbc %{public}s failed due to call IsExistFile failed %{public}d",
559 realPath.c_str(), result);
560 funcResult = ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
561 return ERR_OK;
562 }
563 if (!isExist) {
564 APP_LOGE("DeleteAbc failed due to path %{public}s is not exist", realPath.c_str());
565 funcResult = ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
566 return ERR_OK;
567 }
568 result = InstalldClient::GetInstance()->RemoveDir(realPath);
569 if (result != ERR_OK) {
570 APP_LOGE("DeleteAbc failed due to remove path %{public}s failed %{public}d",
571 realPath.c_str(), result);
572 funcResult = ERR_BUNDLE_MANAGER_DELETE_ABC_FAILED;
573 return ERR_OK;
574 }
575 funcResult = ERR_OK;
576 return ERR_OK;
577 }
578
GetBundleMutex(const std::string & bundleName)579 std::mutex &VerifyManagerHostImpl::GetBundleMutex(const std::string &bundleName)
580 {
581 bundleMutex_.lock_shared();
582 auto it = bundleMutexMap_.find(bundleName);
583 if (it == bundleMutexMap_.end()) {
584 bundleMutex_.unlock_shared();
585 std::unique_lock lock {bundleMutex_};
586 return bundleMutexMap_[bundleName];
587 }
588 bundleMutex_.unlock_shared();
589 return it->second;
590 }
591 } // AppExecFwk
592 } // namespace OHOS
593