diff options
author | Oren Blasberg <orenb@google.com> | 2015-06-19 11:31:38 -0700 |
---|---|---|
committer | Oren Blasberg <orenb@google.com> | 2015-06-25 15:50:58 -0700 |
commit | 6971133998ddc8c8c6b37b2fdaaec1d3ed152e90 (patch) | |
tree | 0f8b878bed85ec64b384fd34db87079368d78d3a /src/com/android/providers/downloads/DownloadNotifier.java | |
parent | 8b2db225a6ccef9dff906ffed1e9c3193622f91d (diff) | |
download | android_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/android/providers/downloads/DownloadNotifier.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadNotifier.java | 31 |
1 files changed, 30 insertions, 1 deletions
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( |