]> nv-tegra.nvidia Code Review - android/platform/packages/providers/DownloadProvider.git/commitdiff
Merge "Migrate the DownloadProvider's trampoline to use SAF Uris."
authorTomasz Mikolajewski <mtomasz@google.com>
Wed, 3 Feb 2016 03:58:02 +0000 (03:58 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Wed, 3 Feb 2016 03:58:02 +0000 (03:58 +0000)
src/com/android/providers/downloads/OpenHelper.java

index 8124df976ada6db324345827d195835561cad29a..7a74c88c7a8e0a2dc47196e9ef34fef743cf4b66 100644 (file)
@@ -31,6 +31,7 @@ import android.content.Intent;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.StrictMode;
+import android.provider.DocumentsContract;
 import android.provider.Downloads.Impl.RequestHeaders;
 import android.util.Log;
 
@@ -82,6 +83,9 @@ public class OpenHelper {
             String mimeType = getCursorString(cursor, COLUMN_MEDIA_TYPE);
             mimeType = DownloadDrmHelper.getOriginalMimeType(context, file, mimeType);
 
+            final Uri documentUri = DocumentsContract.buildDocumentUri(
+                    Constants.STORAGE_AUTHORITY, String.valueOf(id));
+
             final Intent intent = new Intent(Intent.ACTION_VIEW);
 
             if ("application/vnd.android.package-archive".equals(mimeType)) {
@@ -94,13 +98,12 @@ public class OpenHelper {
                 intent.putExtra(Intent.EXTRA_REFERRER, getRefererUri(context, id));
                 intent.putExtra(Intent.EXTRA_ORIGINATING_UID, getOriginatingUid(context, id));
             } else if ("file".equals(localUri.getScheme())) {
+                intent.setDataAndType(documentUri, mimeType);
                 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                         | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                intent.setDataAndType(
-                        ContentUris.withAppendedId(ALL_DOWNLOADS_CONTENT_URI, id), mimeType);
             } else {
-                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                intent.setDataAndType(localUri, mimeType);
+                throw new UnsupportedOperationException(
+                        "Unsupported scheme: " + localUri.getScheme());
             }
 
             return intent;