diff --git a/interfaces/innerkits/native/file_share/include/file_share.h b/interfaces/innerkits/native/file_share/include/file_share.h index 5e299f6bb7b70258b98040357b957375b3796299..8f7c3430204f60e1fbbef530ccb0cacdaf013265 100644 --- a/interfaces/innerkits/native/file_share/include/file_share.h +++ b/interfaces/innerkits/native/file_share/include/file_share.h @@ -33,8 +33,6 @@ enum SHARE_FILE_TYPE { DIR_TYPE = 0, FILE_TYPE }; namespace { const string FILE_SCHEME = "file"; -const string CMD_GET_PID = "pidof "; -const string PID_FLAG = ""; const string PACKAGE_NAME_FLAG = ""; const string CURRENT_USER_ID_FLAG = ""; const string DATA_APP_EL2_PATH = "/data/service/el2/"; @@ -52,7 +50,7 @@ const vector SANDBOX_PATH = { "/data/storage/ark-cache", "/data/storage/ark-profile", "/data/storage/el2/distributedfiles", - "/data/fuse" + "/mnt/data/fuse" }; const vector LOWER_PATH = { @@ -64,7 +62,7 @@ const vector LOWER_PATH = { "/data/local/ark-cache/", "/data/local/ark-profile//", "/mnt/hmdfs//account/merge_view/data/", - "/proc//root/data/fuse" + "/mnt/sandbox//mnt/data/fuse" }; } diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 9380079c9da67b1a30a430ac92b6a7521192770c..6c9d161510131b40237fe142b50363d73b991923 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -41,6 +41,27 @@ struct FileShareInfo { SHARE_FILE_TYPE type_; }; +static void UpdateBundleNameForDlp(const string &providerPath, string &bundleName, const string &providerBundleName) +{ + if (providerBundleName == DLP_MANAGER_BUNDLE_NAME) { + size_t lastPos = providerPath.find_last_of("/"); + if (lastPos == string::npos) { + return; + } + string subStr = providerPath.substr(lastPos); + size_t firstPos = subStr.find_first_of("_"); + if (firstPos == string::npos) { + return; + } + subStr = subStr.substr(firstPos + 1); + size_t secondPos = subStr.find_first_of("_"); + if (secondPos == string::npos) { + return; + } + bundleName += "_" + subStr.substr(0, secondPos); + } +} + static int32_t GetTargetInfo(uint32_t tokenId, string &bundleName, string ¤tUid) { Security::AccessToken::HapTokenInfo hapInfo; @@ -79,24 +100,6 @@ static bool IsExistFile(const string &path) return S_ISREG(buf.st_mode); } -static string GetPidFromProcessName(const string &processName) -{ - FILE *fp; - string cmd = CMD_GET_PID + processName; - string pid = ""; - if ((fp = popen(cmd.c_str(), "r")) != NULL) { - const int32_t bufLen = 20; - char buf[bufLen] = {'\0'}; - if (fgets(buf, bufLen, fp) != NULL) { - pid = string(buf); - } - - pclose(fp); - fp = nullptr; - } - return pid; -} - static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, FileShareInfo &info) { if (lowerPathHead.empty()) { @@ -113,19 +116,6 @@ static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, PACKAGE_NAME_FLAG.length(), info.providerBundleName_); } - if (info.providerBundleName_ == DLP_MANAGER_BUNDLE_NAME) { - string pid = GetPidFromProcessName(DLP_MANAGER_BUNDLE_NAME); - if (pid.empty()) { - LOGE("Failed to get id from process name"); - return -EINVAL; - } - if (lowerPathHead.find(PID_FLAG) != string::npos) { - pid.erase(pid.size() - 1); - lowerPathHead = lowerPathHead.replace(lowerPathHead.find(PID_FLAG), - PID_FLAG.length(), pid); - } - } - info.providerLowerPath_ = lowerPathHead + lowerPathTail; return 0; } @@ -134,6 +124,7 @@ static int32_t GetProviderPath(const string &uriStr, FileShareInfo &info) { Uri uri(uriStr); string pathInProvider = uri.GetPath(); + UpdateBundleNameForDlp(pathInProvider, info.targetBundleName_, info.providerBundleName_); size_t num = SANDBOX_PATH.size(); string lowerPathTail = "", lowerPathHead = "";