diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp index 11fb261c6e7149035d616d5cccae4802df690925..6033524326b85726653f888c95640928dcdb7497 100644 --- a/interfaces/innerkits/native/file_uri/src/file_uri.cpp +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -31,6 +31,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://"; @@ -91,6 +92,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; + } if (((bundleName != "") && (bundleName != CommonFunc::GetSelfBundleName())) || uri_.ToString().find(NETWORK_PARA) != string::npos) { diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp index d02975a69b832afa24b4a19ca48117819f8c57f8..6c2804c44beb039a9b91d806f871aed74d23e43d 100644 --- a/test/unittest/file_uri_native/file_uri_test.cpp +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -246,6 +246,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.