summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/Helpers.java
diff options
context:
space:
mode:
authorSudheer Shanka <sudheersai@google.com>2019-08-15 15:11:04 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-15 15:11:04 -0700
commit158d1fa8a1d2017e778819082e50b424785dd145 (patch)
tree6ee493750854a9b556fb8db3fa879d49590f51f2 /src/com/android/providers/downloads/Helpers.java
parent454cf9bf59c12f370e2c7bd6cebec417fa0b7a9f (diff)
parentb02bbf988e4e7e0c2cdba7bad6ad518e82df1f33 (diff)
downloadandroid_packages_providers_DownloadProvider-158d1fa8a1d2017e778819082e50b424785dd145.tar.gz
android_packages_providers_DownloadProvider-158d1fa8a1d2017e778819082e50b424785dd145.tar.bz2
android_packages_providers_DownloadProvider-158d1fa8a1d2017e778819082e50b424785dd145.zip
Ensure files get mediascanned after the download is completed.
am: b02bbf988e Change-Id: I8d37b11fb060996eb1d85528c4341d3c0eaed169
Diffstat (limited to 'src/com/android/providers/downloads/Helpers.java')
-rw-r--r--src/com/android/providers/downloads/Helpers.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 565aa52e..f75b627f 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -34,18 +34,22 @@ import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
+import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.provider.Downloads;
+import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.util.LongSparseArray;
@@ -489,6 +493,26 @@ public class Helpers {
throw new IOException("Failed to generate an available filename");
}
+ public static Uri convertToMediaStoreDownloadsUri(Uri mediaStoreUri) {
+ final String volumeName = MediaStore.getVolumeName(mediaStoreUri);
+ final long id = android.content.ContentUris.parseId(mediaStoreUri);
+ return MediaStore.Downloads.getContentUri(volumeName, id);
+ }
+
+ // TODO: Move it to MediaStore.
+ public static Uri triggerMediaScan(android.content.ContentProviderClient mediaProviderClient,
+ File file) {
+ try {
+ final Bundle in = new Bundle();
+ in.putParcelable(Intent.EXTRA_STREAM, Uri.fromFile(file));
+ final Bundle out = mediaProviderClient.call(MediaStore.SCAN_FILE_CALL, null, in);
+ return out.getParcelable(Intent.EXTRA_STREAM);
+ } catch (RemoteException e) {
+ // Should not happen
+ }
+ return null;
+ }
+
public static boolean isFileInExternalAndroidDirs(String filePath) {
return PATTERN_ANDROID_DIRS.matcher(filePath).matches();
}