summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorOren Blasberg <orenb@google.com>2015-06-19 11:31:38 -0700
committerOren Blasberg <orenb@google.com>2015-06-25 15:50:58 -0700
commit6971133998ddc8c8c6b37b2fdaaec1d3ed152e90 (patch)
tree0f8b878bed85ec64b384fd34db87079368d78d3a /src/com
parent8b2db225a6ccef9dff906ffed1e9c3193622f91d (diff)
downloadandroid_packages_providers_DownloadProvider-6971133998ddc8c8c6b37b2fdaaec1d3ed152e90.tar.gz
android_packages_providers_DownloadProvider-6971133998ddc8c8c6b37b2fdaaec1d3ed152e90.tar.bz2
android_packages_providers_DownloadProvider-6971133998ddc8c8c6b37b2fdaaec1d3ed152e90.zip
Add "Cancel" action to downloads in notification.
Add a "Cancel" action to in-progress downloads shown in notification pane. We add a new action type for a new "cancel" intent sent by DownloadNotifier to DownloadReceiver, which in turn cancels the download by way of DownloadManager. BUG=19972464 Change-Id: I83cd2f40e1442c327f756027b99f9eac913a0e70
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/providers/downloads/Constants.java3
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java31
-rw-r--r--src/com/android/providers/downloads/DownloadReceiver.java28
3 files changed, 61 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/Constants.java b/src/com/android/providers/downloads/Constants.java
index 7b8fcd24..6cea8086 100644
--- a/src/com/android/providers/downloads/Constants.java
+++ b/src/com/android/providers/downloads/Constants.java
@@ -54,6 +54,9 @@ public class Constants {
/** the intent that gets sent when clicking an incomplete/failed download */
public static final String ACTION_LIST = "android.intent.action.DOWNLOAD_LIST";
+ /** the intent that gets sent when canceling a download */
+ public static final String ACTION_CANCEL = "android.intent.action.DOWNLOAD_CANCEL";
+
/** the intent that gets sent when deleting the notification of a completed download */
public static final String ACTION_HIDE = "android.intent.action.DOWNLOAD_HIDE";
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index 60c249f9..2ff8b634 100644
--- a/src/com/android/providers/downloads/DownloadNotifier.java
+++ b/src/com/android/providers/downloads/DownloadNotifier.java
@@ -122,6 +122,15 @@ public class DownloadNotifier {
}
}
+ private static boolean isClusterDeleted(Collection<DownloadInfo> cluster) {
+ boolean wasDeleted = true;
+ for (DownloadInfo info : cluster) {
+ wasDeleted = wasDeleted && info.mDeleted;
+ }
+
+ return wasDeleted;
+ }
+
private void updateWithLocked(Collection<DownloadInfo> downloads) {
final Resources res = mContext.getResources();
@@ -139,6 +148,11 @@ public class DownloadNotifier {
final int type = getNotificationTagType(tag);
final Collection<DownloadInfo> cluster = clustered.get(tag);
+ // If each of the downloads was canceled, don't show notification for the cluster
+ if (isClusterDeleted(cluster)) {
+ continue;
+ }
+
final Notification.Builder builder = new Notification.Builder(mContext);
builder.setColor(res.getColor(
com.android.internal.R.color.system_notification_accent_color));
@@ -164,16 +178,31 @@ public class DownloadNotifier {
// Build action intents
if (type == TYPE_ACTIVE || type == TYPE_WAITING) {
+ long[] downloadIds = getDownloadIds(cluster);
+
// build a synthetic uri for intent identification purposes
final Uri uri = new Uri.Builder().scheme("active-dl").appendPath(tag).build();
final Intent intent = new Intent(Constants.ACTION_LIST,
uri, mContext, DownloadReceiver.class);
intent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
- getDownloadIds(cluster));
+ downloadIds);
builder.setContentIntent(PendingIntent.getBroadcast(mContext,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
builder.setOngoing(true);
+ // Add a Cancel action
+ final Uri cancelUri = new Uri.Builder().scheme("cancel-dl").appendPath(tag).build();
+ final Intent cancelIntent = new Intent(Constants.ACTION_CANCEL,
+ cancelUri, mContext, DownloadReceiver.class);
+ cancelIntent.putExtra(DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_IDS, downloadIds);
+ cancelIntent.putExtra(DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_NOTIFICATION_TAG, tag);
+
+ builder.addAction(
+ android.R.drawable.ic_menu_close_clear_cancel,
+ res.getString(R.string.button_cancel_download),
+ PendingIntent.getBroadcast(mContext,
+ 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+
} else if (type == TYPE_COMPLETE) {
final DownloadInfo info = cluster.iterator().next();
final Uri uri = ContentUris.withAppendedId(
diff --git a/src/com/android/providers/downloads/DownloadReceiver.java b/src/com/android/providers/downloads/DownloadReceiver.java
index 28e2a673..2f50dcf6 100644
--- a/src/com/android/providers/downloads/DownloadReceiver.java
+++ b/src/com/android/providers/downloads/DownloadReceiver.java
@@ -21,6 +21,7 @@ import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY
import static com.android.providers.downloads.Constants.TAG;
import android.app.DownloadManager;
+import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentUris;
@@ -45,6 +46,21 @@ import com.google.common.annotations.VisibleForTesting;
* Receives system broadcasts (boot, network connectivity)
*/
public class DownloadReceiver extends BroadcastReceiver {
+ /**
+ * Intent extra included with {@link #ACTION_CANCEL} intents, indicating the IDs (as array of
+ * long) of the downloads that were canceled.
+ */
+ public static final String EXTRA_CANCELED_DOWNLOAD_IDS =
+ "com.android.providers.downloads.extra.CANCELED_DOWNLOAD_IDS";
+
+ /**
+ * Intent extra included with {@link #ACTION_CANCEL} intents, indicating the tag of the
+ * notification corresponding to the download(s) that were canceled; this notification must be
+ * canceled.
+ */
+ public static final String EXTRA_CANCELED_DOWNLOAD_NOTIFICATION_TAG =
+ "com.android.providers.downloads.extra.CANCELED_DOWNLOAD_NOTIFICATION_TAG";
+
private static Handler sAsyncHandler;
static {
@@ -107,6 +123,18 @@ public class DownloadReceiver extends BroadcastReceiver {
}
});
}
+ } else if (Constants.ACTION_CANCEL.equals(action)) {
+ long[] downloadIds = intent.getLongArrayExtra(
+ DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_IDS);
+ DownloadManager manager = (DownloadManager) context.getSystemService(
+ Context.DOWNLOAD_SERVICE);
+ manager.remove(downloadIds);
+
+ String notifTag = intent.getStringExtra(
+ DownloadReceiver.EXTRA_CANCELED_DOWNLOAD_NOTIFICATION_TAG);
+ NotificationManager notifManager = (NotificationManager) context.getSystemService(
+ Context.NOTIFICATION_SERVICE);
+ notifManager.cancel(notifTag, 0);
}
}