diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-11-05 20:08:34 +0000 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-11-05 20:08:34 +0000 |
commit | 40a32f628089f338f823b34ed832e18a164aec23 (patch) | |
tree | 301569d0a81c340425d54787155120c03c320c11 /src/com/android/providers/downloads/OpenHelper.java | |
parent | 907bcd0c7cf8a44e07b3cf426b605ca7694ee24d (diff) | |
parent | a839ee4c19bfebac961f4b0aaa8aecaba114bac9 (diff) | |
download | android_packages_providers_DownloadProvider-40a32f628089f338f823b34ed832e18a164aec23.tar.gz android_packages_providers_DownloadProvider-40a32f628089f338f823b34ed832e18a164aec23.tar.bz2 android_packages_providers_DownloadProvider-40a32f628089f338f823b34ed832e18a164aec23.zip |
Merge tag 'android-4.4_r1' into cm-11.0
Android 4.4 Release 1.0
Change-Id: I6eadeafdb9d3219bebd28325b4e290b6d5282499
Diffstat (limited to 'src/com/android/providers/downloads/OpenHelper.java')
-rw-r--r-- | src/com/android/providers/downloads/OpenHelper.java | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/com/android/providers/downloads/OpenHelper.java b/src/com/android/providers/downloads/OpenHelper.java index 184cdb3d..58c8ed69 100644 --- a/src/com/android/providers/downloads/OpenHelper.java +++ b/src/com/android/providers/downloads/OpenHelper.java @@ -22,23 +22,47 @@ import static android.app.DownloadManager.COLUMN_MEDIAPROVIDER_URI; import static android.app.DownloadManager.COLUMN_MEDIA_TYPE; import static android.app.DownloadManager.COLUMN_URI; import static android.provider.Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI; +import static com.android.providers.downloads.Constants.TAG; import android.app.DownloadManager; +import android.content.ActivityNotFoundException; import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.Downloads.Impl.RequestHeaders; +import android.util.Log; import java.io.File; public class OpenHelper { /** - * Build an {@link Intent} to view the download at current {@link Cursor} - * position, handling subtleties around installing packages. + * Build and start an {@link Intent} to view the download with given ID, + * handling subtleties around installing packages. */ - public static Intent buildViewIntent(Context context, long id) { + public static boolean startViewIntent(Context context, long id, int intentFlags) { + final Intent intent = OpenHelper.buildViewIntent(context, id); + if (intent == null) { + Log.w(TAG, "No intent built for " + id); + return false; + } + + intent.addFlags(intentFlags); + try { + context.startActivity(intent); + return true; + } catch (ActivityNotFoundException e) { + Log.w(TAG, "Failed to start " + intent + ": " + e); + return false; + } + } + + /** + * Build an {@link Intent} to view the download with given ID, handling + * subtleties around installing packages. + */ + private static Intent buildViewIntent(Context context, long id) { final DownloadManager downManager = (DownloadManager) context.getSystemService( Context.DOWNLOAD_SERVICE); downManager.setAccessAllDownloads(true); @@ -46,7 +70,7 @@ public class OpenHelper { final Cursor cursor = downManager.query(new DownloadManager.Query().setFilterById(id)); try { if (!cursor.moveToFirst()) { - throw new IllegalArgumentException("Missing download " + id); + return null; } final Uri localUri = getCursorUri(cursor, COLUMN_LOCAL_URI); @@ -55,7 +79,6 @@ public class OpenHelper { mimeType = DownloadDrmHelper.getOriginalMimeType(context, file, mimeType); final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if ("application/vnd.android.package-archive".equals(mimeType)) { // PackageInstaller doesn't like content URIs, so open file @@ -71,9 +94,12 @@ public class OpenHelper { intent.setDataAndType(mediaUri, mimeType); intent.putExtra("SingleItemOnly", true); } else if ("file".equals(localUri.getScheme())) { + 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); } @@ -130,10 +156,6 @@ public class OpenHelper { return Uri.parse(getCursorString(cursor, column)); } - private static long getCursorLong(Cursor cursor, String column) { - return cursor.getLong(cursor.getColumnIndexOrThrow(column)); - } - private static File getCursorFile(Cursor cursor, String column) { return new File(cursor.getString(cursor.getColumnIndexOrThrow(column))); } |