diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index a06934ab2bdbd99cfa82fa54d5ca250af98c319f..4fc002fadae0b552e5a9a7626811cd856abf09b5 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -32,6 +32,7 @@ namespace OHOS { namespace AppFileService { namespace ModuleFileUri { const std::string PATH_SHARE = "/data/storage/el2/share"; +const std::string MEDIA_FUSE_PATH_HEAD = "/data/storage/el2/"; const std::string MODE_RW = "/rw/"; const std::string MODE_R = "/r/"; const std::string FILE_SCHEME_PREFIX = "file://"; @@ -94,6 +95,10 @@ string FileUri::GetRealPath() (access(realPath.c_str(), F_OK) == 0 || CheckFileManagerFullMountEnable())) { return realPath; } + if (bundleName == MEDIA_AUTHORITY) { + realPath = MEDIA_FUSE_PATH_HEAD + bundleName + sandboxPath; + return realPath; + } { std::lock_guard lock(g_globalMutex); if (BUNDLE_NAME.empty()) { diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp index 8e84576ff4722215074b5dfe9a1e711cf7dcf6b0..d52248fd4da307c7a765a2a9420b8317f0e90df6 100644 --- a/test/unittest/file_uri_native/file_uri_test.cpp +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -255,6 +255,23 @@ namespace OHOS::AppFileService::ModuleFileUri { GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0004"; } + /** + * @tc.name: file_uri_test_0005 + * @tc.desc: Test function of GetPath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7LW57 + */ + HWTEST_F(FileUriTest, File_uri_GetPath_0005, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0005"; + string fileStr = "/data/storage/el2/media/Photo/12/IMG_12345_999999/test.jpg"; + string uri = "file://media/Photo/12/IMG_12345_999999/test.jpg"; + FileUri fileUri(uri); + EXPECT_EQ(fileUri.GetRealPath(), fileStr); + GTEST_LOG_(INFO) << "FileUriTest-begin File_uri_GetPath_0005"; + } /** * @tc.name: file_uri_test_0007 * @tc.desc: Test function of GetFullDirectoryUri() interface for SUCCESS.