mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2025-02-17 06:28:19 +00:00
!7512 GetDirByBundleNameAndAppIndex 修复
Merge pull request !7512 from liumingyue/fix-getDir-1120
This commit is contained in:
commit
c32a35b1e7
@ -59,6 +59,8 @@ const std::string FUNCATION_BATCH_BUNDLE_INFO = "BundleMgrHostImpl::BatchGetBund
|
||||
const std::string FUNCATION_GET_BUNDLE_INFO = "BundleMgrHostImpl::GetBundleInfo";
|
||||
const std::string FUNCATION_GET_BUNDLE_INFO_V9 = "BundleMgrHostImpl::GetBundleInfoV9";
|
||||
const std::string FUNCATION_GET_BUNDLE_INFO_FOR_SELF = "BundleMgrHostImpl::GetBundleInfoForSelf";
|
||||
const std::string CLONE_APP_DIR_PREFIX = "+clone-";
|
||||
const std::string PLUS = "+";
|
||||
}
|
||||
|
||||
bool BundleMgrHostImpl::GetApplicationInfo(
|
||||
@ -4593,23 +4595,40 @@ std::string BundleMgrHostImpl::GetCallerName()
|
||||
return callerName;
|
||||
}
|
||||
|
||||
ErrCode GetDirForApp(const std::string &bundleName, const int32_t appIndex, std::string &dataDir)
|
||||
{
|
||||
APP_LOGD("start GetDirForApp");
|
||||
if (appIndex < 0) {
|
||||
return ERR_BUNDLE_MANAGER_GET_DIR_INVALID_APP_INDEX;
|
||||
} else if (appIndex == 0) {
|
||||
dataDir = bundleName;
|
||||
} else {
|
||||
dataDir = CLONE_APP_DIR_PREFIX + std::to_string(appIndex) + PLUS + bundleName;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode BundleMgrHostImpl::GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex,
|
||||
std::string &dataDir)
|
||||
{
|
||||
APP_LOGD("start GetDirByBundleNameAndAppIndex");
|
||||
if (!BundlePermissionMgr::IsSystemApp()) {
|
||||
APP_LOGE("non-system app calling system api");
|
||||
return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED;
|
||||
}
|
||||
if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)) {
|
||||
APP_LOGE("Verify permission failed");
|
||||
return ERR_BUNDLE_MANAGER_PERMISSION_DENIED;
|
||||
}
|
||||
auto dataMgr = GetDataMgrFromService();
|
||||
if (dataMgr == nullptr) {
|
||||
APP_LOGE("DataMgr is nullptr");
|
||||
return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
BundleType type;
|
||||
dataMgr->GetBundleType(bundleName, type);
|
||||
if (type != BundleType::ATOMIC_SERVICE) {
|
||||
return GetDirForApp(bundleName, appIndex, dataDir);
|
||||
}
|
||||
|
||||
if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED)
|
||||
&& !BundlePermissionMgr::IsBundleSelfCalling(bundleName)) {
|
||||
APP_LOGE("Verify permission failed");
|
||||
return ERR_BUNDLE_MANAGER_PERMISSION_DENIED;
|
||||
}
|
||||
return dataMgr->GetDirByBundleNameAndAppIndex(bundleName, appIndex, dataDir);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user