summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSudheer Shanka <sudheersai@google.com>2019-04-18 18:25:42 -0700
committerSudheer Shanka <sudheersai@google.com>2019-04-18 18:25:42 -0700
commit834f98ce8f26c22d69a1257a6aeaaa3fa70d0702 (patch)
treea80eb2eb19b822dbd061d9f61c5a5beee9ece5ad
parenta4ec3ecfb60abb19e2f26892368f67309883995e (diff)
downloadandroid_packages_providers_DownloadProvider-834f98ce8f26c22d69a1257a6aeaaa3fa70d0702.tar.gz
android_packages_providers_DownloadProvider-834f98ce8f26c22d69a1257a6aeaaa3fa70d0702.tar.bz2
android_packages_providers_DownloadProvider-834f98ce8f26c22d69a1257a6aeaaa3fa70d0702.zip
Remove logic of including downloads dirs in pkg sandboxes.
Bug: 130427780 Test: manual Change-Id: I3a3c98dfa769ea6e2dac1fb3d92148489c04f3a1
-rw-r--r--src/com/android/providers/downloads/DownloadStorageProvider.java78
1 files changed, 29 insertions, 49 deletions
diff --git a/src/com/android/providers/downloads/DownloadStorageProvider.java b/src/com/android/providers/downloads/DownloadStorageProvider.java
index e5963ae8..df073cdc 100644
--- a/src/com/android/providers/downloads/DownloadStorageProvider.java
+++ b/src/com/android/providers/downloads/DownloadStorageProvider.java
@@ -153,7 +153,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
// It's possible that the folder does not exist on disk, so we will create the folder if
// that is the case. If user decides to delete the folder later, then it's OK to fail on
// subsequent queries.
- getTopLevelDownloadsDirectory().mkdirs();
+ getPublicDownloadsDirectory().mkdirs();
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
final RowBuilder row = result.newRow();
@@ -483,27 +483,23 @@ public class DownloadStorageProvider extends FileSystemProvider {
private void includeSearchFilesFromSharedStorage(DownloadsCursor result,
String[] projection, Set<String> filePaths,
Bundle queryArgs) throws FileNotFoundException {
- final List<File> downloadsDirs = getDownloadsDirectories();
- final int size = downloadsDirs.size();
- for (int i = 0; i < size; ++i) {
- final File downloadDir = downloadsDirs.get(i);
- try (Cursor rawFilesCursor = super.querySearchDocuments(downloadDir,
- projection, filePaths, queryArgs)) {
-
- final boolean shouldExcludeMedia = queryArgs.getBoolean(
- DocumentsContract.QUERY_ARG_EXCLUDE_MEDIA, false /* defaultValue */);
- while (rawFilesCursor.moveToNext()) {
- final String mimeType = rawFilesCursor.getString(
- rawFilesCursor.getColumnIndexOrThrow(Document.COLUMN_MIME_TYPE));
- // When the value of shouldExcludeMedia is true, don't add media files into
- // the result to avoid duplicated files. MediaScanner will scan the files
- // into MediaStore. If the behavior is changed, we need to add the files back.
- if (!shouldExcludeMedia || !isMediaMimeType(mimeType)) {
- String docId = rawFilesCursor.getString(
- rawFilesCursor.getColumnIndexOrThrow(Document.COLUMN_DOCUMENT_ID));
- File rawFile = getFileForDocId(docId);
- includeFileFromSharedStorage(result, rawFile);
- }
+ final File downloadDir = getPublicDownloadsDirectory();
+ try (Cursor rawFilesCursor = super.querySearchDocuments(downloadDir,
+ projection, filePaths, queryArgs)) {
+
+ final boolean shouldExcludeMedia = queryArgs.getBoolean(
+ DocumentsContract.QUERY_ARG_EXCLUDE_MEDIA, false /* defaultValue */);
+ while (rawFilesCursor.moveToNext()) {
+ final String mimeType = rawFilesCursor.getString(
+ rawFilesCursor.getColumnIndexOrThrow(Document.COLUMN_MIME_TYPE));
+ // When the value of shouldExcludeMedia is true, don't add media files into
+ // the result to avoid duplicated files. MediaScanner will scan the files
+ // into MediaStore. If the behavior is changed, we need to add the files back.
+ if (!shouldExcludeMedia || !isMediaMimeType(mimeType)) {
+ String docId = rawFilesCursor.getString(
+ rawFilesCursor.getColumnIndexOrThrow(Document.COLUMN_DOCUMENT_ID));
+ File rawFile = getFileForDocId(docId);
+ includeFileFromSharedStorage(result, rawFile);
}
}
}
@@ -567,7 +563,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
}
if (DOC_ID_ROOT.equals(docId)) {
- return getTopLevelDownloadsDirectory();
+ return getPublicDownloadsDirectory();
}
final long token = Binder.clearCallingIdentity();
@@ -755,34 +751,17 @@ public class DownloadStorageProvider extends FileSystemProvider {
private void includeFilesFromSharedStorage(DownloadsCursor result,
Set<String> downloadedFilePaths, @Nullable String searchString)
throws FileNotFoundException {
- final List<File> downloadsDirs = getDownloadsDirectories();
+ final File downloadsDir = getPublicDownloadsDirectory();
// Add every file from the Downloads directory to the result cursor. Ignore files that
// were in the supplied downloaded file paths.
- final int size = downloadsDirs.size();
- for (int i = 0; i < size; ++i) {
- final File downloadsDir = downloadsDirs.get(i);
- for (File file : FileUtils.listFilesOrEmpty(downloadsDir)) {
- boolean inResultsAlready = downloadedFilePaths.contains(file.getAbsolutePath());
- boolean containsQuery = searchString == null || file.getName().contains(
- searchString);
- if (!inResultsAlready && containsQuery) {
- includeFileFromSharedStorage(result, file);
- }
- }
- }
- }
-
- private static List<File> getDownloadsDirectories() {
- final List<File> downloadsDirectories = new ArrayList<>();
- downloadsDirectories.add(getTopLevelDownloadsDirectory());
- final File sandboxDir = Environment.buildExternalStorageAndroidSandboxDirs()[0];
- for (File file : FileUtils.listFilesOrEmpty(sandboxDir)) {
- final File downloadDir = new File(file, Environment.DIRECTORY_DOWNLOADS);
- if (downloadDir.exists()) {
- downloadsDirectories.add(downloadDir);
+ for (File file : FileUtils.listFilesOrEmpty(downloadsDir)) {
+ boolean inResultsAlready = downloadedFilePaths.contains(file.getAbsolutePath());
+ boolean containsQuery = searchString == null || file.getName().contains(
+ searchString);
+ if (!inResultsAlready && containsQuery) {
+ includeFileFromSharedStorage(result, file);
}
}
- return downloadsDirectories;
}
/**
@@ -798,7 +777,7 @@ public class DownloadStorageProvider extends FileSystemProvider {
includeFile(result, null, file);
}
- private static File getTopLevelDownloadsDirectory() {
+ private static File getPublicDownloadsDirectory() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
}
@@ -1091,7 +1070,8 @@ public class DownloadStorageProvider extends FileSystemProvider {
void start() {
synchronized (mLock) {
if (mOpenCursorCount++ == 0) {
- mFileWatcher = new ContentChangedRelay(mResolver, getDownloadsDirectories());
+ mFileWatcher = new ContentChangedRelay(mResolver,
+ Arrays.asList(getPublicDownloadsDirectory()));
mFileWatcher.startWatching();
}
}