Don't ignore COLUMN_MEDIA_SCANNED values from caller.
Right now, DownloadProvider only uses the COLUMN_MEDIA_SCANNED
value if it is coming from addCompletedDownload and for the rest
of the requests, it ignores the incoming COLUMN_MEDIA_SCANNED value
and always invokes mediascanner. This is not what the documentation
says. For e.g., if the caller uses DownloadManager.setDestinationUri()
API, then unless otherwise specified, the download doesn't need to be
mediascanned.
Also, since we are inserting user visible downloads to MediaProvider,
use that info to populate the COLUMN_MEDIAPROVIDER_URI column as well
and update DownloadProvider to not invoke MediaScanner.
Bug: 123440050
Test: atest DownloadProviderTests
Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: I65ccae672eabe2efd5132d4b105c18bb591379fc
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index acc7094..fde1d29e 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -26,7 +26,6 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
-import android.content.Intent;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.net.ConnectivityManager;
@@ -37,7 +36,6 @@
import android.os.FileUtils;
import android.os.ParcelFileDescriptor;
import android.provider.Downloads;
-import android.provider.MediaStore.Images;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
@@ -399,14 +397,14 @@
/** if a file is designated as a MediaScanner scannable file, the following value is
* stored in the database column {@link Downloads.Impl#COLUMN_MEDIA_SCANNED}.
*/
- private static final int SCANNABLE_VALUE_YES = 0;
+ private static final int SCANNABLE_VALUE_YES = Downloads.Impl.MEDIA_NOT_SCANNED;
// value of 1 is stored in the above column by DownloadProvider after it is scanned by
// MediaScanner
/** if a file is designated as a file that should not be scanned by MediaScanner,
* the following value is stored in the database column
* {@link Downloads.Impl#COLUMN_MEDIA_SCANNED}.
*/
- private static final int SCANNABLE_VALUE_NO = 2;
+ private static final int SCANNABLE_VALUE_NO = Downloads.Impl.MEDIA_NOT_SCANNABLE;
/**
* This download is visible but only shows in the notifications
@@ -1264,19 +1262,6 @@
throw new IllegalStateException("Failed to rename to " + after);
}
- // Update MediaProvider if necessary
- if (mimeType.startsWith("image/")) {
- context.getContentResolver().delete(Images.Media.EXTERNAL_CONTENT_URI,
- Images.Media.DATA + "=?",
- new String[] {
- before.getAbsolutePath()
- });
-
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
- intent.setData(Uri.fromFile(after));
- context.sendBroadcast(intent);
- }
-
ContentValues values = new ContentValues();
values.put(Downloads.Impl.COLUMN_TITLE, displayName);
values.put(Downloads.Impl._DATA, after.toString());
@@ -1329,8 +1314,7 @@
* @param description the description that would appear for this file in Downloads App.
* @param isMediaScannerScannable true if the file is to be scanned by MediaScanner. Files
* scanned by MediaScanner appear in the applications used to view media (for example,
- * Gallery app). Starting from {@link android.os.Build.VERSION_CODES#Q}, this argument is
- * ignored and the file is always scanned by MediaScanner.
+ * Gallery app).
* @param mimeType mimetype of the file.
* @param path absolute pathname to the file. The file should be world-readable, so that it can
* be managed by the Downloads App and any other app that is used to read it (for example,
@@ -1359,8 +1343,7 @@
* @param description the description that would appear for this file in Downloads App.
* @param isMediaScannerScannable true if the file is to be scanned by MediaScanner. Files
* scanned by MediaScanner appear in the applications used to view media (for example,
- * Gallery app). Starting from {@link android.os.Build.VERSION_CODES#Q}, this argument is
- * ignored and the file is always scanned by MediaScanner.
+ * Gallery app).
* @param mimeType mimetype of the file.
* @param path absolute pathname to the file. The file should be world-readable, so that it can
* be managed by the Downloads App and any other app that is used to read it (for example,