diff --git a/bundle.json b/bundle.json index 24ea4291b6ae8bf5f8b4c1ba24fd39f9f37a0c4c..6a2953b34b269ae815c344424e942c836527d411 100644 --- a/bundle.json +++ b/bundle.json @@ -27,6 +27,7 @@ "common_event_service", "c_utils", "data_share", + "device_manager", "faultloggerd", "file_api", "hitrace", diff --git a/interfaces/common/file_share_sandbox.json b/interfaces/common/file_share_sandbox.json index 8a5b059014e6aad932984962484b24e996330a9a..d5bba1777b1c885cc881f9a7cd0591816cb299c0 100644 --- a/interfaces/common/file_share_sandbox.json +++ b/interfaces/common/file_share_sandbox.json @@ -22,22 +22,22 @@ "src-path" : "/data/local/ark-profile///" }, { "sandbox-path" : "/data/storage/el2/distributedfiles/", - "src-path" : "/mnt/hmdfs//account/merge_view/data//" + "src-path" : "/mnt/hmdfs//account/device_view//data//" }, { "sandbox-path" : "/mnt/data/fuse/", "src-path" : "/mnt/data//fuse/" }, { "sandbox-path" : "/storage/Users/currentUser/Documents/", - "src-path" : "/mnt/hmdfs//account/merge_view/files/Documents/" + "src-path" : "/mnt/hmdfs//account/device_view//files/Documents/" }, { "sandbox-path" : "/storage/Users/currentUser/Download/", - "src-path" : "/mnt/hmdfs//account/merge_view/files/Download/" + "src-path" : "/mnt/hmdfs//account/device_view//files/Download/" }, { "sandbox-path" : "/storage/Users/currentUser/Desktop/", - "src-path" : "/mnt/hmdfs//account/merge_view/files/Desktop/" + "src-path" : "/mnt/hmdfs//account/device_view//files/Desktop/" }, { "sandbox-path" : "/storage/Users/currentUser/", - "src-path" : "/mnt/hmdfs//account/merge_view/files/Docs/" + "src-path" : "/mnt/hmdfs//account/device_view//files/Docs/" }, { "sandbox-path" : "/storage/External/", "src-path" : "/mnt/data/external/" diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index 470b941aff921dade20199fbff57f4ce89b96882..d46a71231bd096d58f6a777d181db17b68fba925 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -43,6 +43,8 @@ namespace { const string FUSE_URI_HEAD = "/mnt/data/fuse"; const string BACKFLASH = "/"; const string MEDIA = "media"; + const string NETWORK_ID_FLAG = ""; + const string LOCAL = "local"; const int ASSET_IN_BUCKET_NUM_MAX = 1000; const int ASSET_DIR_START_NUM = 16; } @@ -103,7 +105,8 @@ string SandboxHelper::Decode(const string &uri) } static string GetLowerPath(string &lowerPathHead, const string &lowerPathTail, - const string &userId, const string &bundleName) + const string &userId, const string &bundleName, + const string &networkId) { if (lowerPathHead.find(CURRENT_USER_ID_FLAG) != string::npos) { lowerPathHead = lowerPathHead.replace(lowerPathHead.find(CURRENT_USER_ID_FLAG), @@ -115,6 +118,11 @@ static string GetLowerPath(string &lowerPathHead, const string &lowerPathTail, PACKAGE_NAME_FLAG.length(), bundleName); } + if (lowerPathHead.find(NETWORK_ID_FLAG) != string::npos) { + lowerPathHead = lowerPathHead.replace(lowerPathHead.find(NETWORK_ID_FLAG), + NETWORK_ID_FLAG.length(), networkId); + } + return lowerPathHead + lowerPathTail; } @@ -231,6 +239,21 @@ static int32_t GetMediaPhysicalPath(const std::string &sandboxPath, const std::s return 0; } +static void GetNetworkIdFromUri(const std::string &fileUri, string &networkId) +{ + Uri uri(fileUri); + std::string networkIdInfo = uri.GetQuery(); + if (networkIdInfo.empty()) { + return; + } + + size_t posIndex = networkIdInfo.find('='); + if (posIndex == string::npos || posIndex == (networkIdInfo.size() - 1)) { + return; + } + networkId = networkIdInfo.substr(posIndex + 1); +} + int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::string &userId, std::string &physicalPath) { @@ -270,10 +293,13 @@ int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::st if (lowerPathHead == "") { return -EINVAL; - } else { - physicalPath = GetLowerPath(lowerPathHead, lowerPathTail, userId, bundleName); - return 0; } + + string networkId = LOCAL; + GetNetworkIdFromUri(fileUri, networkId); + + physicalPath = GetLowerPath(lowerPathHead, lowerPathTail, userId, bundleName, networkId); + return 0; } bool SandboxHelper::CheckValidPath(const std::string &filePath) diff --git a/interfaces/innerkits/native/BUILD.gn b/interfaces/innerkits/native/BUILD.gn index fed5cfc188acd13f41c4ac83dc02645ceba70d73..67c3c077e568597edeaf97bd3d29dbce1868d2d9 100644 --- a/interfaces/innerkits/native/BUILD.gn +++ b/interfaces/innerkits/native/BUILD.gn @@ -110,6 +110,7 @@ ohos_shared_library("remote_file_share_native") { external_deps = [ "ability_base:zuri", "c_utils:utils", + "device_manager:devicemanagersdk", "hilog:libhilog", ] diff --git a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp index a7f7321a467caec50d1639be27eb09ab80f38f6a..d49b0ac97079a832c98a827f8f7d4c6e2be1c75f 100644 --- a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp +++ b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp @@ -24,6 +24,8 @@ #include #include "log.h" +#include "device_manager.h" +#include "device_manager_callback.h" #include "sandbox_helper.h" #include "securec.h" #include "uri.h" @@ -31,6 +33,7 @@ namespace OHOS { namespace AppFileService { namespace ModuleRemoteFileShare { +using namespace OHOS::DistributedHardware; namespace { const int HMDFS_CID_SIZE = 64; const int USER_ID_INIT = 100; @@ -47,6 +50,8 @@ namespace { const std::string REMOTE_SHARE_PATH_DIR = "/.remote_share"; const std::string MEDIA_AUTHORITY = "media"; const std::string FILE_MANAGER_AUTHORITY = "docs"; + const std::string PACKAGE_NAME = "get_dfs_uri_from_local"; + const std::string NETWORK_PARA = "?networkid="; } #define HMDFS_IOC_SET_SHARE_PATH _IOW(HMDFS_IOC, 1, struct HmdfsShareControl) @@ -67,6 +72,13 @@ struct HmdfsDstInfo { uint64_t size; }; +class InitDMCallback : public DmInitCallback { +public: + InitDMCallback() = default; + ~InitDMCallback() override = default; + void OnRemoteDied() override {}; +}; + static std::string GetProcessName() { char pthreadName[PATH_MAX]; @@ -297,13 +309,32 @@ static void InitHmdfsInfo(struct HmdfsDstInfo &hdi, const std::string &physicalP hdi.size = reinterpret_cast(&hdi.size); } +static std::string GetLocalNetworkId() +{ + auto callback = std::make_shared(); + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(PACKAGE_NAME, callback); + if (ret != 0) { + return ""; + } + + DmDeviceInfo info; + ret = DeviceManager::GetInstance().GetLocalDeviceInfo(PACKAGE_NAME, info); + auto networkId = std::string(info.networkId); + LOGD("GetLocalNetworkId :%{private}s", networkId.c_str()); + if (ret != 0 || networkId.empty()) { + return ""; + } + return networkId; +} + static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, Uri &uri, uint64_t fileSize) { std::string bundleName = uri.GetAuthority(); std::string path = uri.GetPath(); + std::string networkId = NETWORK_PARA + GetLocalNetworkId(); hui.uriStr = SandboxHelper::Encode(FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + - REMOTE_SHARE_PATH_DIR + path); + REMOTE_SHARE_PATH_DIR + path + networkId); hui.fileSize = fileSize; return; } @@ -311,7 +342,7 @@ static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, Uri &uri, uint64_t fileSiz static int32_t SetPublicDirHmdfsInfo(const std::string &physicalPath, const std::string &uriStr, struct HmdfsUriInfo &hui) { - hui.uriStr = uriStr; + hui.uriStr = uriStr + NETWORK_PARA + GetLocalNetworkId(); struct stat buf = {}; if (stat(physicalPath.c_str(), &buf) != 0) { LOGE("Failed to get physical path stat with %{public}d", -errno); @@ -336,6 +367,7 @@ int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int if (bundleName == MEDIA_AUTHORITY || bundleName == FILE_MANAGER_AUTHORITY) { (void)SetPublicDirHmdfsInfo(physicalPath, uriStr, hui); + LOGD("GetDfsUriFromLocal successfully with %{private}s", hui.uriStr.c_str()); return 0; }