Commit 053674aa authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent 8286e248
......@@ -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);
}
......
......@@ -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()) {
......
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