From 1112824b50cb59bc914b947b19ca1170f975e9cc Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Thu, 17 Oct 2024 09:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8C=85=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=88=86=E8=BA=AB=E5=BA=94=E7=94=A8=E5=8C=85?= =?UTF-8?q?=E5=90=8D=E7=BA=A7=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuiruibin --- interfaces/common/include/common_func.h | 1 + interfaces/common/src/common_func.cpp | 22 ++++++++++++++++++- .../native/file_share/src/file_share.cpp | 10 +++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/interfaces/common/include/common_func.h b/interfaces/common/include/common_func.h index 9603016e6..dffcc8668 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 8cc7572b0..89e1bf399 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 0a4acae55..0c954afab 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; } -- Gitee