summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2016-05-09 14:51:23 -0600
committerThe Android Automerger <android-build@google.com>2016-05-09 16:44:44 -0700
commit01c7b5df1286ad904e6a98b8f61109c5b914dbf2 (patch)
tree6969eebd6afe4abd20cdee1c9cbf481d0b537678
parent31c4ea78b1cb824ba95b941cc195d22ebfe7a28d (diff)
downloadandroid_packages_providers_DownloadProvider-01c7b5df1286ad904e6a98b8f61109c5b914dbf2.zip
android_packages_providers_DownloadProvider-01c7b5df1286ad904e6a98b8f61109c5b914dbf2.tar.gz
android_packages_providers_DownloadProvider-01c7b5df1286ad904e6a98b8f61109c5b914dbf2.tar.bz2
Scan completed downloads when requested.
The recent JobScheduler rewrite means we no longer spin up a service when insterting an already-completed download. However, the calling app may have requested the download to be scanned, so kick off a scan request for them. Bug: 28659693 Change-Id: I497e10995ba04f1522fe8d7e547ebea6e305f6e9
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java10
-rw-r--r--src/com/android/providers/downloads/DownloadScanner.java11
2 files changed, 17 insertions, 4 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 00ed043..4b83cac 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -17,7 +17,11 @@
package com.android.providers.downloads;
import static android.provider.BaseColumns._ID;
+import static android.provider.Downloads.Impl.COLUMN_DESTINATION;
import static android.provider.Downloads.Impl.COLUMN_MEDIAPROVIDER_URI;
+import static android.provider.Downloads.Impl.COLUMN_MEDIA_SCANNED;
+import static android.provider.Downloads.Impl.COLUMN_MIME_TYPE;
+import static android.provider.Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD;
import static android.provider.Downloads.Impl._DATA;
import android.app.AppOpsManager;
@@ -695,6 +699,12 @@ public final class DownloadProvider extends ContentProvider {
Binder.restoreCallingIdentity(token);
}
+ if (values.getAsInteger(COLUMN_DESTINATION) == DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD
+ && values.getAsInteger(COLUMN_MEDIA_SCANNED) == 0) {
+ DownloadScanner.requestScanBlocking(getContext(), rowID, values.getAsString(_DATA),
+ values.getAsString(COLUMN_MIME_TYPE));
+ }
+
return ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, rowID);
}
diff --git a/src/com/android/providers/downloads/DownloadScanner.java b/src/com/android/providers/downloads/DownloadScanner.java
index 37f5114..4a5ba87 100644
--- a/src/com/android/providers/downloads/DownloadScanner.java
+++ b/src/com/android/providers/downloads/DownloadScanner.java
@@ -76,9 +76,13 @@ public class DownloadScanner implements MediaScannerConnectionClient {
}
public static void requestScanBlocking(Context context, DownloadInfo info) {
+ requestScanBlocking(context, info.mId, info.mFileName, info.mMimeType);
+ }
+
+ public static void requestScanBlocking(Context context, long id, String path, String mimeType) {
final DownloadScanner scanner = new DownloadScanner(context);
scanner.mLatch = new CountDownLatch(1);
- scanner.requestScan(info);
+ scanner.requestScan(new ScanRequest(id, path, mimeType));
try {
scanner.mLatch.await(SCAN_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
@@ -115,10 +119,9 @@ public class DownloadScanner implements MediaScannerConnectionClient {
*
* @see #hasPendingScans()
*/
- public void requestScan(DownloadInfo info) {
- if (LOGV) Log.v(TAG, "requestScan() for " + info.mFileName);
+ public void requestScan(ScanRequest req) {
+ if (LOGV) Log.v(TAG, "requestScan() for " + req.path);
synchronized (mConnection) {
- final ScanRequest req = new ScanRequest(info.mId, info.mFileName, info.mMimeType);
mPending.put(req.path, req);
if (mConnection.isConnected()) {