Have DownloadManager pass file URIs for legacy external downloads
DownloadManager was set up to return file URIs for public API
downloads to external, but to return content URIs for all others.
This included browser downloads, which are on external but don't go
through the public API. Since the new downloads UI uses
DownloadManager, it was affected by this change when the user opened a
file from the UI. Apparently numerous things don't handle content
URIs well, including music preview (clicking on downloaded mp3) and
package installer (clicking on downloaded APK), so this change makes
it generate file URIs for legacy external downloads.
Change-Id: I5c34d8ba188cc8b0d11865262cb451208be78eae
diff --git a/core/java/android/net/DownloadManager.java b/core/java/android/net/DownloadManager.java
index 836223e..18e62b0 100644
--- a/core/java/android/net/DownloadManager.java
+++ b/core/java/android/net/DownloadManager.java
@@ -247,6 +247,7 @@
Downloads.COLUMN_LAST_MODIFICATION,
Downloads.COLUMN_DESTINATION,
Downloads.Impl.COLUMN_FILE_NAME_HINT,
+ Downloads.Impl._DATA,
};
private static final Set<String> LONG_COLUMNS = new HashSet<String>(
@@ -881,6 +882,11 @@
return getUnderlyingString(Downloads.Impl.COLUMN_FILE_NAME_HINT);
}
+ if (destinationType == Downloads.Impl.DESTINATION_EXTERNAL) {
+ // return stored destination for legacy external download
+ return Uri.fromFile(new File(getUnderlyingString(Downloads.Impl._DATA))).toString();
+ }
+
// return content URI for cache download
long downloadId = getUnderlyingLong(Downloads.Impl._ID);
return ContentUris.withAppendedId(mBaseUri, downloadId).toString();