diff --git a/interfaces/common/include/common_func.h b/interfaces/common/include/common_func.h index 9603016e65d103075af0ac2ffaa468adf876b341..dffcc8668b43a2f72841fcd7187231bc01a2578d 100644 --- a/interfaces/common/include/common_func.h +++ b/interfaces/common/include/common_func.h @@ -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 diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp index 8cc7572b09084ea78df95321207b8a3a1eb9f26d..89e1bf39932625d466cba24729e001c4702d1fd1 100644 --- a/interfaces/common/src/common_func.cpp +++ b/interfaces/common/src/common_func.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include "bundle_mgr_client.h" #include "bundle_mgr_proxy.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -57,6 +59,21 @@ static sptr GetBundleMgrProxy() return iface_cast(remoteObject); } +bool CommonFunc::GetDirByBundleNameAndAppIndex(const std::string &bundleName, int32_t appIndex, std::string &dirName) +{ + auto bmsClient = DelayedSingleton::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 = 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; } diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 0a4acae55153929b4448f0711e18673ad0649f9e..0c954afab138b08e587e71fc7134a8fa4b4c3ca9 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -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; }