summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-09-18 19:53:39 (GMT)
committerJeff Sharkey <jsharkey@android.com>2013-09-18 20:24:48 (GMT)
commit8ec87ea5a5c191554d6205d4c779768664b1724b (patch)
tree1652bb0c244513e65612d934c8dc0c1921aa09bf
parente00d56d349fff8a9c5dc86739448603986ba6cb5 (diff)
downloadandroid_packages_providers_DownloadProvider-8ec87ea5a5c191554d6205d4c779768664b1724b.zip
android_packages_providers_DownloadProvider-8ec87ea5a5c191554d6205d4c779768664b1724b.tar.gz
android_packages_providers_DownloadProvider-8ec87ea5a5c191554d6205d4c779768664b1724b.tar.bz2
Unified handling of errors around opening.
Handle both missing downloads and missing activities. Bug: 10799449, 10713636 Change-Id: I592b07fc5cf530526803379d7f7a99e8a6b207c4
-rw-r--r--src/com/android/providers/downloads/DownloadReceiver.java10
-rw-r--r--src/com/android/providers/downloads/OpenHelper.java36
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java8
-rw-r--r--ui/src/com/android/providers/downloads/ui/TrampolineActivity.java6
4 files changed, 36 insertions, 24 deletions
diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java
index 42f029a..f3d2376 100644
--- a/src/com/android/providers/downloads/DownloadReceiver.java
+++ b/src/com/android/providers/downloads/DownloadReceiver.java
@@ -20,7 +20,6 @@ import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMP
import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION;
import android.app.DownloadManager;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
import android.content.ContentValues;
@@ -162,13 +161,8 @@ public class DownloadReceiver extends BroadcastReceiver {
* {@link DownloadManager#COLUMN_ID}.
*/
private void openDownload(Context context, long id) {
- final Intent intent = OpenHelper.buildViewIntent(context, id);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- try {
- context.startActivity(intent);
- } catch (ActivityNotFoundException ex) {
- Log.d(Constants.TAG, "no activity for " + intent, ex);
- Toast.makeText(context, R.string.download_no_application_title, Toast.LENGTH_LONG)
+ if (!OpenHelper.startViewIntent(context, id, Intent.FLAG_ACTIVITY_NEW_TASK)) {
+ Toast.makeText(context, R.string.download_no_application_title, Toast.LENGTH_SHORT)
.show();
}
}
diff --git a/src/com/android/providers/downloads/OpenHelper.java b/src/com/android/providers/downloads/OpenHelper.java
index 0d5f5e9..af7a37f 100644
--- a/src/com/android/providers/downloads/OpenHelper.java
+++ b/src/com/android/providers/downloads/OpenHelper.java
@@ -21,23 +21,47 @@ import static android.app.DownloadManager.COLUMN_LOCAL_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);
@@ -45,7 +69,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);
@@ -121,10 +145,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)));
}
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 991d70b..107940c 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -19,7 +19,6 @@ package com.android.providers.downloads.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
-import android.content.ActivityNotFoundException;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
@@ -530,11 +529,8 @@ public class DownloadList extends Activity {
}
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID));
- final Intent intent = OpenHelper.buildViewIntent(this, id);
- try {
- startActivity(intent);
- } catch (ActivityNotFoundException ex) {
- Toast.makeText(this, R.string.download_no_application_title, Toast.LENGTH_LONG).show();
+ if (!OpenHelper.startViewIntent(this, id, 0)) {
+ Toast.makeText(this, R.string.download_no_application_title, Toast.LENGTH_SHORT).show();
}
}
diff --git a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
index e9cc17e..f96c04e 100644
--- a/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
+++ b/ui/src/com/android/providers/downloads/ui/TrampolineActivity.java
@@ -92,8 +92,10 @@ public class TrampolineActivity extends Activity {
break;
case DownloadManager.STATUS_SUCCESSFUL:
- final Intent intent = OpenHelper.buildViewIntent(this, id);
- startActivity(intent);
+ if (!OpenHelper.startViewIntent(this, id, 0)) {
+ Toast.makeText(this, R.string.download_no_application_title, Toast.LENGTH_SHORT)
+ .show();
+ }
finish();
break;