diff options
author | Philip P. Moltmann <moltmann@google.com> | 2017-04-05 16:46:50 -0700 |
---|---|---|
committer | Philip P. Moltmann <moltmann@google.com> | 2017-04-05 16:46:50 -0700 |
commit | d37be36a56f13419e947c9f8b9af3b0f5ee9c71e (patch) | |
tree | 54ce500fbe07e04d292632f48bf5db1e6ae07fda | |
parent | 399dba4ab0328c0c83015398e949ec40a673e978 (diff) |
Make print failure notifications important
Before failures and progress was similar important. Both were not shown.
Now both are shown and the failures alert.
Removed the notification grouping as autogrouping is good enough.
Test: Created failed and running print jobs
Change-Id: I6dfca583d69aa9713d45a2bc52d05e95f06b376f
-rw-r--r-- | packages/PrintSpooler/res/values/strings.xml | 6 | ||||
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java | 84 |
2 files changed, 38 insertions, 52 deletions
diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml index 2e6ed69b4892..63850aea59e6 100644 --- a/packages/PrintSpooler/res/values/strings.xml +++ b/packages/PrintSpooler/res/values/strings.xml @@ -149,6 +149,12 @@ <!-- Description of printer info icon. [CHAR LIMIT=50] --> <string name="printer_info_desc">More information about this printer</string> + <!-- Label for the notification channel that contains print jobs without problems. [CHAR LIMIT=40] --> + <string name="notification_channel_progress">Running print jobs</string> + + <!-- Label for the notification channel that contains print jobs with problems. [CHAR LIMIT=40] --> + <string name="notification_channel_failure">Failed print jobs</string> + <!-- Notification that we could not create a file name for the printed PDF. [CHAR LIMIT=50] --> <string name="could_not_create_file">Could not create file</string> diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java b/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java index cd1d540d922b..9d737e0cd9d5 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/NotificationController.java @@ -20,13 +20,12 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Notification; import android.app.Notification.Action; -import android.app.Notification.InboxStyle; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.AsyncTask; @@ -57,14 +56,14 @@ final class NotificationController { public static final String LOG_TAG = "NotificationController"; + private static final String NOTIFICATION_CHANNEL_PROGRESS = "PRINT_PROGRESS"; + private static final String NOTIFICATION_CHANNEL_FAILURES = "PRINT_FAILURES"; + private static final String INTENT_ACTION_CANCEL_PRINTJOB = "INTENT_ACTION_CANCEL_PRINTJOB"; private static final String INTENT_ACTION_RESTART_PRINTJOB = "INTENT_ACTION_RESTART_PRINTJOB"; private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID"; - private static final String PRINT_JOB_NOTIFICATION_GROUP_KEY = "PRINT_JOB_NOTIFICATIONS"; - private static final String PRINT_JOB_NOTIFICATION_SUMMARY = "PRINT_JOB_NOTIFICATIONS_SUMMARY"; - private final Context mContext; private final NotificationManager mNotificationManager; @@ -78,6 +77,15 @@ final class NotificationController { mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); mNotifications = new ArraySet<>(0); + + mNotificationManager.createNotificationChannel( + new NotificationChannel(NOTIFICATION_CHANNEL_PROGRESS, + context.getString(R.string.notification_channel_progress), + NotificationManager.IMPORTANCE_LOW)); + mNotificationManager.createNotificationChannel( + new NotificationChannel(NOTIFICATION_CHANNEL_FAILURES, + context.getString(R.string.notification_channel_failure), + NotificationManager.IMPORTANCE_DEFAULT)); } public void onUpdateNotifications(List<PrintJobInfo> printJobs) { @@ -104,13 +112,6 @@ final class NotificationController { final int numPrintJobs = printJobs.size(); - // Create summary notification - if (numPrintJobs > 1) { - createStackedNotification(printJobs); - } else { - mNotificationManager.cancel(PRINT_JOB_NOTIFICATION_SUMMARY, 0); - } - // Create per print job notification for (int i = 0; i < numPrintJobs; i++) { PrintJobInfo printJob = printJobs.get(i); @@ -178,16 +179,16 @@ final class NotificationController { */ private void createNotification(@NonNull PrintJobInfo printJob, @Nullable Action firstAction, @Nullable Action secondAction) { - Notification.Builder builder = new Notification.Builder(mContext) + Notification.Builder builder = new Notification.Builder(mContext, computeChannel(printJob)) .setContentIntent(createContentIntent(printJob.getId())) .setSmallIcon(computeNotificationIcon(printJob)) .setContentTitle(computeNotificationTitle(printJob)) .setWhen(System.currentTimeMillis()) .setOngoing(true) .setShowWhen(true) + .setOnlyAlertOnce(true) .setColor(mContext.getColor( - com.android.internal.R.color.system_notification_accent_color)) - .setGroup(PRINT_JOB_NOTIFICATION_GROUP_KEY); + com.android.internal.R.color.system_notification_accent_color)); if (firstAction != null) { builder.addAction(firstAction); @@ -238,43 +239,6 @@ final class NotificationController { createNotification(printJob, null, null); } - private void createStackedNotification(List<PrintJobInfo> printJobs) { - Notification.Builder builder = new Notification.Builder(mContext) - .setContentIntent(createContentIntent(null)) - .setWhen(System.currentTimeMillis()) - .setOngoing(true) - .setShowWhen(true) - .setGroup(PRINT_JOB_NOTIFICATION_GROUP_KEY) - .setGroupSummary(true); - - final int printJobCount = printJobs.size(); - - InboxStyle inboxStyle = new InboxStyle(); - - int icon = com.android.internal.R.drawable.ic_print; - for (int i = printJobCount - 1; i>= 0; i--) { - PrintJobInfo printJob = printJobs.get(i); - - inboxStyle.addLine(computeNotificationTitle(printJob)); - - // if any print job is in an error state show an error icon for the summary - if (printJob.getState() == PrintJobInfo.STATE_FAILED - || printJob.getState() == PrintJobInfo.STATE_BLOCKED) { - icon = com.android.internal.R.drawable.ic_print_error; - } - } - - builder.setSmallIcon(icon); - builder.setLargeIcon( - ((BitmapDrawable) mContext.getResources().getDrawable(icon, null)).getBitmap()); - builder.setNumber(printJobCount); - builder.setStyle(inboxStyle); - builder.setColor(mContext.getColor( - com.android.internal.R.color.system_notification_accent_color)); - - mNotificationManager.notify(PRINT_JOB_NOTIFICATION_SUMMARY, 0, builder.build()); - } - private String computeNotificationTitle(PrintJobInfo printJob) { switch (printJob.getState()) { case PrintJobInfo.STATE_FAILED: { @@ -359,6 +323,22 @@ final class NotificationController { } } + private static String computeChannel(PrintJobInfo printJob) { + if (printJob.isCancelling()) { + return NOTIFICATION_CHANNEL_PROGRESS; + } + + switch (printJob.getState()) { + case PrintJobInfo.STATE_FAILED: + case PrintJobInfo.STATE_BLOCKED: { + return NOTIFICATION_CHANNEL_FAILURES; + } + default: { + return NOTIFICATION_CHANNEL_PROGRESS; + } + } + } + public static final class NotificationBroadcastReceiver extends BroadcastReceiver { @SuppressWarnings("hiding") private static final String LOG_TAG = "NotificationBroadcastReceiver"; |