From d9b2a8f237492951f71abeb8f2ce359311862f21 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 28 Jul 2011 13:55:10 -0700 Subject: [PATCH] Make "security required" notification ongoing * While investigating the referenced bug, it was discovered that canceling the "security required" notification (with "X", rather than the "cancel" option in the dialog) causes the notification to be unavailable until a reboot * This puts the account needing a security update in the position of being unsyncable, and might explain the referenced bug (we have no confirmation of that step; on the other hand, the tester can't now reproduce the problem, so an unusual action like this is to be expected) * The fix consists of making this particular notification "ongoing", which prevents the user from dismissing it; arguably, this should always have been the case anyway... * Consider this fix for backport into LTE and MR2 branches Bug: 5072343 Change-Id: Ia7419236cf9389380d1e079b1a9a6f425015c487 --- .../android/email/NotificationController.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/android/email/NotificationController.java b/src/com/android/email/NotificationController.java index ea56fb911..737580db2 100644 --- a/src/com/android/email/NotificationController.java +++ b/src/com/android/email/NotificationController.java @@ -133,6 +133,17 @@ public class NotificationController { return sInstance; } + /** + * Return whether or not a notification, based on the passed-in id, needs to be "ongoing" + * @param notificationId the notification id to check + * @return whether or not the notification must be "ongoing" + */ + private boolean needsOngoingNotification(int notificationId) { + // "Security needed" must be ongoing so that the user doesn't close it; otherwise, sync will + // be prevented until a reboot. Consider also doing this for password expired. + return notificationId == NOTIFICATION_ID_SECURITY_NEEDED; + } + /** * Returns a {@link Notification} for an event with the given account. The account contains * specific rules on ring tone usage and these will be used to modify the notification @@ -152,7 +163,7 @@ public class NotificationController { */ private Notification createAccountNotification(Account account, String ticker, CharSequence title, String contentText, Intent intent, Bitmap largeIcon, - Integer number, boolean enableAudio) { + Integer number, boolean enableAudio, boolean ongoing) { // Pending Intent PendingIntent pending = null; if (intent != null) { @@ -169,7 +180,8 @@ public class NotificationController { .setNumber(number == null ? 0 : number) .setSmallIcon(R.drawable.stat_notify_email_generic) .setWhen(mClock.getTime()) - .setTicker(ticker); + .setTicker(ticker) + .setOngoing(ongoing); if (enableAudio) { setupSoundAndVibration(builder, account); @@ -192,7 +204,7 @@ public class NotificationController { private void showAccountNotification(Account account, String ticker, String title, String contentText, Intent intent, int notificationId) { Notification notification = createAccountNotification(account, ticker, title, contentText, - intent, null, null, true); + intent, null, null, true, needsOngoingNotification(notificationId)); mNotificationManager.notify(notificationId, notification); } @@ -431,7 +443,7 @@ public class NotificationController { boolean enableAudio = (now - mLastMessageNotifyTime) > MIN_SOUND_INTERVAL_MS; Notification notification = createAccountNotification( account, title.toString(), title, text, - intent, largeIcon, number, enableAudio); + intent, largeIcon, number, enableAudio, false); mLastMessageNotifyTime = now; return notification; }