适配包管理获取分身应用包名级目录

Signed-off-by: cuiruibin <cuiruibin3@huawei.com>
This commit is contained in:
cuiruibin 2024-10-17 09:22:23 +08:00
parent 146f9840a3
commit 1112824b50
3 changed files with 30 additions and 3 deletions

View File

@ -25,6 +25,7 @@ class CommonFunc {
public:
static std::string GetSelfBundleName();
static std::string GetUriFromPath(const std::string &path);
static bool GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName);
};
} // namespace AppFileService
} // namespace OHOS

View File

@ -18,6 +18,8 @@
#include <mutex>
#include <vector>
#include <singleton.h>
#include "bundle_mgr_client.h"
#include "bundle_mgr_proxy.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -57,6 +59,21 @@ static sptr<BundleMgrProxy> GetBundleMgrProxy()
return iface_cast<BundleMgrProxy>(remoteObject);
}
bool CommonFunc::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName)
{
auto bmsClient = DelayedSingleton<AppExecFwk::BundleMgrClient>::GetInstance();
if (bmsClient == nullptr) {
LOGE("bundleMgrClient is nullptr.");
return false;
}
auto bmsRet = bmsClient->GetDirByBundleNameAndAppIndex(bundleName, appIndex, dirName);
if (bmsRet != ERR_OK) {
LOGE("GetDirByBundleNameAndAppIndex failed, ret:%{public}d", bmsRet);
return false;
}
return true;
}
string CommonFunc::GetSelfBundleName()
{
sptr<BundleMgrProxy> bundleMgrProxy = GetBundleMgrProxy();
@ -71,7 +88,10 @@ string CommonFunc::GetSelfBundleName()
LOGE("GetSelfBundleName: bundleName get fail.");
return "";
}
string dirName = "" ;
if (GetDirByBundleNameAndAppIndex(bundleInfo.name, bundleInfo.appIndex, dirName)) {
return dirName;
}
return bundleInfo.name;
}

View File

@ -27,6 +27,7 @@
#include "hap_token_info.h"
#include "log.h"
#include "sandbox_helper.h"
#include "common_func.h"
#include "uri.h"
namespace OHOS {
@ -50,6 +51,7 @@ const string SHARE_RW_PATH = "/rw/";
const string SHARE_PATH = "/share/";
const string EXTERNAL_PATH = "file://docs/storage/External";
const string NETWORK_PARA = "networkid=";
const int32_t DLP_COMMON = 0;
}
struct FileShareInfo {
@ -75,10 +77,14 @@ static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string &curre
}
bundleName = hapInfo.bundleName;
currentUid = to_string(hapInfo.userID);
int index = hapInfo.instIndex;
string dirName = "" ;
if (index != 0) {
bundleName = to_string(index) + "_" + bundleName;
if (hapInfo.dlpType != DLP_COMMON) {
bundleName = to_string(index) + "_" + bundleName;
} else if (CommonFunc::GetDirByBundleNameAndAppIndex(bundleName, index, dirName)) {
bundleName = dirName;
}
}
return 0;
}