diff --git a/interfaces/innerkits/native/BUILD.gn b/interfaces/innerkits/native/BUILD.gn index 67c3c077e568597edeaf97bd3d29dbce1868d2d9..840439d9d7c3c9f37ca12c09e0d885b0d9c13d26 100644 --- a/interfaces/innerkits/native/BUILD.gn +++ b/interfaces/innerkits/native/BUILD.gn @@ -72,6 +72,8 @@ ohos_shared_library("fileuri_native") { "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", + "init:libbegetutil", + "file_api:remote_uri_native", ] part_name = "app_file_service" diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index f027c842c8f5872f955462669ec2991ab1b61d69..18cc9b5bd64c76d09f5584d89004ee79db5a5a0a 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -24,6 +24,8 @@ #include "common_func.h" #include "log.h" #include "sandbox_helper.h" +#include "parameter.h" +#include "remote_uri.h" using namespace std; namespace OHOS { @@ -36,6 +38,23 @@ const std::string FILE_SCHEME_PREFIX = "file://"; const std::string FILE_MANAGER_AUTHORITY = "docs"; const std::string MEDIA_AUTHORITY = "media"; const std::string NETWORK_PARA = "?networkid="; +const int32_t FULL_MOUT_ENABLE_SIZE = 6; +const char* g_filemanagerFullMoutEnableParameter = "const.filemanager.full_mout.enable"; + +namespace { + bool CheckFilemanagerFullMoutEnable() + { + char value[FULL_MOUT_ENABLE_SIZE] = "false"; + int retSystem = GetParameter(g_filemanagerFullMoutEnableParameter, "false", value, FULL_MOUT_ENABLE_SIZE); + if (retSystem > 0 && !std::strcmp(value, "true")) { + LOGD("this is a pc"); + return true; + } + LOGD("this is not a pc"); + return false; + } +} + string FileUri::GetName() { string sandboxPath = SandboxHelper::Decode(uri_.GetPath()); @@ -69,6 +88,24 @@ string FileUri::GetRealPath() string realPath = sandboxPath; string bundleName = uri_.GetAuthority(); LOGD("GetRealPath decode path is %{private}s", sandboxPath.c_str()); + + if (!CheckFilemanagerFullMoutEnable()) { + LOGD("Device is not PC"); + return ""; + } + + if (OHOS::DistributedFS::ModuleRemoteUri::RemoteUri::IsMediaUri(realPath)) { + LOGD("Is Media Uri"); + return ""; + } + LOGD("Is not Media Uri"); + int fd = -1; + if (OHOS::DistributedFS::ModuleRemoteUri::RemoteUri::IsRemoteUri(realPath,fd)) { + LOGD("Is Remote Uri"); + return ""; + } + LOGD("Is not Remote Uri"); + if (bundleName == FILE_MANAGER_AUTHORITY && uri_.ToString().find(NETWORK_PARA) == string::npos && access(realPath.c_str(), F_OK) == 0) {