Commit a956143e authored by Naoki Fukino's avatar Naoki Fukino Committed by Commit Bot

Convert URLs of Android files to ArcUrls.

Android container now supports content urls with /external_files to access all
files on emulated external storage.
We need to convert URLs under /run/arc/sdcard/write/emulated/0 on Chrome OS side
to the content URLs.
To share the path to Android files, the definition of kAndroidFilesPath is moved
from volume_manager to path_util.

Bug: 855982
Test: Manually tested on Kevin and Eve with a patch ag/4411504 on Android.
Change-Id: Idb6fbd9aa697c306d953b0bcb7cf332ec9a26c19
Reviewed-on: https://chromium-review.googlesource.com/1113169
Commit-Queue: Naoki Fukino <fukino@chromium.org>
Reviewed-by: default avatarShuhei Takahashi <nya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570001}
parent cb2bfe69
...@@ -36,6 +36,8 @@ constexpr char kArcFileProviderUrl[] = ...@@ -36,6 +36,8 @@ constexpr char kArcFileProviderUrl[] =
// Sync with the root name defined with the file provider in ARC++ side. // Sync with the root name defined with the file provider in ARC++ side.
constexpr base::FilePath::CharType kArcDownloadRoot[] = constexpr base::FilePath::CharType kArcDownloadRoot[] =
FILE_PATH_LITERAL("/download"); FILE_PATH_LITERAL("/download");
constexpr base::FilePath::CharType kArcExternalFilesRoot[] =
FILE_PATH_LITERAL("/external_files");
// Sync with the removable media provider in ARC++ side. // Sync with the removable media provider in ARC++ side.
constexpr char kArcRemovableMediaProviderUrl[] = constexpr char kArcRemovableMediaProviderUrl[] =
"content://org.chromium.arc.removablemediaprovider/"; "content://org.chromium.arc.removablemediaprovider/";
...@@ -69,6 +71,9 @@ void OnAllContentUrlsResolved(ConvertToContentUrlsCallback callback, ...@@ -69,6 +71,9 @@ void OnAllContentUrlsResolved(ConvertToContentUrlsCallback callback,
const base::FilePath::CharType kRemovableMediaPath[] = const base::FilePath::CharType kRemovableMediaPath[] =
FILE_PATH_LITERAL("/media/removable"); FILE_PATH_LITERAL("/media/removable");
const base::FilePath::CharType kAndroidFilesPath[] =
FILE_PATH_LITERAL("/run/arc/sdcard/write/emulated/0");
base::FilePath GetDownloadsFolderForProfile(Profile* profile) { base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
// On non-ChromeOS system (test+development), the primary profile uses // On non-ChromeOS system (test+development), the primary profile uses
// $HOME/Downloads for ease for accessing local files for debugging. // $HOME/Downloads for ease for accessing local files for debugging.
...@@ -146,6 +151,15 @@ bool ConvertPathToArcUrl(const base::FilePath& path, GURL* arc_url_out) { ...@@ -146,6 +151,15 @@ bool ConvertPathToArcUrl(const base::FilePath& path, GURL* arc_url_out) {
return true; return true;
} }
// Convert paths under Android files root (/run/arc/sdcard/write/emulated/0).
result_path = base::FilePath(kArcExternalFilesRoot);
if (base::FilePath(kAndroidFilesPath)
.AppendRelativePath(path, &result_path)) {
*arc_url_out = GURL(kArcFileProviderUrl)
.Resolve(net::EscapePath(result_path.AsUTF8Unsafe()));
return true;
}
// Convert paths under /media/removable. // Convert paths under /media/removable.
base::FilePath relative_path; base::FilePath relative_path;
if (base::FilePath(kRemovableMediaPath) if (base::FilePath(kRemovableMediaPath)
......
...@@ -20,6 +20,9 @@ namespace util { ...@@ -20,6 +20,9 @@ namespace util {
// be used by tests. // be used by tests.
extern const base::FilePath::CharType kRemovableMediaPath[]; extern const base::FilePath::CharType kRemovableMediaPath[];
// Absolute path for the folder containing Android files.
extern const base::FilePath::CharType kAndroidFilesPath[];
// Gets the absolute path for the 'Downloads' folder for the |profile|. // Gets the absolute path for the 'Downloads' folder for the |profile|.
base::FilePath GetDownloadsFolderForProfile(Profile* profile); base::FilePath GetDownloadsFolderForProfile(Profile* profile);
......
...@@ -364,7 +364,41 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ...@@ -364,7 +364,41 @@ TEST_F(FileManagerPathUtilConvertUrlTest,
run_loop.Run(); run_loop.Run();
} }
TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipeUrls) { TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_AndroidFiles) {
base::RunLoop run_loop;
ConvertToContentUrls(
std::vector<FileSystemURL>{
CreateExternalURL(base::FilePath::FromUTF8Unsafe(
"/run/arc/sdcard/write/emulated/0/Pictures/a/b.jpg"))},
base::BindOnce(
[](base::RunLoop* run_loop, const std::vector<GURL>& urls) {
run_loop->Quit();
ASSERT_EQ(1U, urls.size());
EXPECT_EQ(
GURL("content://org.chromium.arc.intent_helper.fileprovider/"
"external_files/Pictures/a/b.jpg"),
urls[0]);
},
&run_loop));
}
TEST_F(FileManagerPathUtilConvertUrlTest,
ConvertToContentUrls_InvalidAndroidFiles) {
base::RunLoop run_loop;
ConvertToContentUrls(
std::vector<FileSystemURL>{
CreateExternalURL(base::FilePath::FromUTF8Unsafe(
"/run/arc/sdcard/read/emulated/0/a/b/c"))},
base::BindOnce(
[](base::RunLoop* run_loop, const std::vector<GURL>& urls) {
run_loop->Quit();
ASSERT_EQ(1U, urls.size());
EXPECT_EQ(GURL(), urls[0]); // Invalid URL.
},
&run_loop));
}
TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipleUrls) {
base::RunLoop run_loop; base::RunLoop run_loop;
ConvertToContentUrls( ConvertToContentUrls(
std::vector<FileSystemURL>{ std::vector<FileSystemURL>{
...@@ -372,11 +406,12 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipeUrls) { ...@@ -372,11 +406,12 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipeUrls) {
CreateExternalURL( CreateExternalURL(
base::FilePath::FromUTF8Unsafe("/media/removable/a/b/c")), base::FilePath::FromUTF8Unsafe("/media/removable/a/b/c")),
CreateExternalURL(drive_mount_point_.AppendASCII("a/b/c")), CreateExternalURL(drive_mount_point_.AppendASCII("a/b/c")),
}, CreateExternalURL(base::FilePath::FromUTF8Unsafe(
"/run/arc/sdcard/write/emulated/0/a/b/c"))},
base::BindOnce( base::BindOnce(
[](base::RunLoop* run_loop, const std::vector<GURL>& urls) { [](base::RunLoop* run_loop, const std::vector<GURL>& urls) {
run_loop->Quit(); run_loop->Quit();
ASSERT_EQ(3U, urls.size()); ASSERT_EQ(4U, urls.size());
EXPECT_EQ(GURL(), urls[0]); // Invalid URL. EXPECT_EQ(GURL(), urls[0]); // Invalid URL.
EXPECT_EQ( EXPECT_EQ(
GURL("content://org.chromium.arc.removablemediaprovider/a/b/c"), GURL("content://org.chromium.arc.removablemediaprovider/a/b/c"),
...@@ -386,6 +421,10 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipeUrls) { ...@@ -386,6 +421,10 @@ TEST_F(FileManagerPathUtilConvertUrlTest, ConvertToContentUrls_MultipeUrls) {
"content://org.chromium.arc.chromecontentprovider/" "content://org.chromium.arc.chromecontentprovider/"
"externalfile%3Adrive-user%2540gmail.com-hash%2Fa%2Fb%2Fc"), "externalfile%3Adrive-user%2540gmail.com-hash%2Fa%2Fb%2Fc"),
urls[2]); urls[2]);
EXPECT_EQ(
GURL("content://org.chromium.arc.intent_helper.fileprovider/"
"external_files/a/b/c"),
urls[3]);
}, },
&run_loop)); &run_loop));
run_loop.Run(); run_loop.Run();
......
...@@ -54,8 +54,6 @@ const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; ...@@ -54,8 +54,6 @@ const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-";
const char kMtpVolumeIdPrefix[] = "mtp:"; const char kMtpVolumeIdPrefix[] = "mtp:";
const char kRootPath[] = "/"; const char kRootPath[] = "/";
const char kAndroidFilesMountPointName[] = "android_files"; const char kAndroidFilesMountPointName[] = "android_files";
const base::FilePath::CharType kAndroidFilesPath[] =
FILE_PATH_LITERAL("/run/arc/sdcard/write/emulated/0");
// Registers |path| as the "Downloads" folder to the FileSystem API backend. // Registers |path| as the "Downloads" folder to the FileSystem API backend.
// If another folder is already mounted. It revokes and overrides the old one. // If another folder is already mounted. It revokes and overrides the old one.
...@@ -89,10 +87,10 @@ bool IsShowAndroidFilesEnabled() { ...@@ -89,10 +87,10 @@ bool IsShowAndroidFilesEnabled() {
bool RegisterAndroidFilesMountPoint() { bool RegisterAndroidFilesMountPoint() {
storage::ExternalMountPoints* const mount_points = storage::ExternalMountPoints* const mount_points =
storage::ExternalMountPoints::GetSystemInstance(); storage::ExternalMountPoints::GetSystemInstance();
return mount_points->RegisterFileSystem(kAndroidFilesMountPointName, return mount_points->RegisterFileSystem(
storage::kFileSystemTypeNativeLocal, kAndroidFilesMountPointName, storage::kFileSystemTypeNativeLocal,
storage::FileSystemMountOption(), storage::FileSystemMountOption(),
base::FilePath(kAndroidFilesPath)); base::FilePath(util::kAndroidFilesPath));
} }
// Finds the path register as the "Downloads" folder to FileSystem API backend. // Finds the path register as the "Downloads" folder to FileSystem API backend.
...@@ -349,7 +347,7 @@ std::unique_ptr<Volume> Volume::CreateForAndroidFiles() { ...@@ -349,7 +347,7 @@ std::unique_ptr<Volume> Volume::CreateForAndroidFiles() {
volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
// Keep source_path empty. // Keep source_path empty.
volume->source_ = SOURCE_SYSTEM; volume->source_ = SOURCE_SYSTEM;
volume->mount_path_ = base::FilePath(kAndroidFilesPath); volume->mount_path_ = base::FilePath(util::kAndroidFilesPath);
volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
volume->volume_id_ = GenerateVolumeId(*volume); volume->volume_id_ = GenerateVolumeId(*volume);
volume->watchable_ = true; volume->watchable_ = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment