diff options
| author | Scott Kennedy <skennedy@google.com> | 2013-05-22 18:36:07 -0700 |
|---|---|---|
| committer | Scott Kennedy <skennedy@google.com> | 2013-05-22 18:36:07 -0700 |
| commit | d8302b01faa8fc7f175c93e90458aa84e8a663c7 (patch) | |
| tree | 8fbec2a8bd44b61b94d2b61221834f5ec32f8ceb /src | |
| parent | 3340827bde61288016aac24c4b27d2546da0309b (diff) | |
| download | android_packages_apps_Email-d8302b01faa8fc7f175c93e90458aa84e8a663c7.tar.gz android_packages_apps_Email-d8302b01faa8fc7f175c93e90458aa84e8a663c7.tar.bz2 android_packages_apps_Email-d8302b01faa8fc7f175c93e90458aa84e8a663c7.zip | |
Ensure notifications get cancelled when necessary
There were a few places calling the old notification code to cancel
notifications. These calls were completely unnecessary.
Also, when an account is removed, we now clear all notifications that
may exist for that account.
Bug: 7935576
Change-Id: I58f7e194c3f9a928e932b3b1b87475e7d3653b6a
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/android/email/NotificationController.java | 30 | ||||
| -rw-r--r-- | src/com/android/email/provider/AccountReconciler.java | 4 | ||||
| -rw-r--r-- | src/com/android/email/provider/EmailProvider.java | 13 |
3 files changed, 19 insertions, 28 deletions
diff --git a/src/com/android/email/NotificationController.java b/src/com/android/email/NotificationController.java index 7d3da0092..331697c86 100644 --- a/src/com/android/email/NotificationController.java +++ b/src/com/android/email/NotificationController.java @@ -70,7 +70,6 @@ public class NotificationController { private static final int NOTIFICATION_ID_PASSWORD_EXPIRED = 5; private static final int NOTIFICATION_ID_BASE_MASK = 0xF0000000; - private static final int NOTIFICATION_ID_BASE_NEW_MESSAGES = 0x10000000; private static final int NOTIFICATION_ID_BASE_LOGIN_WARNING = 0x20000000; private static final int NOTIFICATION_ID_BASE_SECURITY_NEEDED = 0x30000000; private static final int NOTIFICATION_ID_BASE_SECURITY_CHANGED = 0x40000000; @@ -179,14 +178,6 @@ public class NotificationController { } /** - * Returns a notification ID for new message notifications for the given account. - */ - private static int getNewMessageNotificationId(long mailboxId) { - // We assume accountId will always be less than 0x0FFFFFFF; is there a better way? - return (int) (NOTIFICATION_ID_BASE_NEW_MESSAGES + mailboxId); - } - - /** * Tells the notification controller if it should be watching for changes to the message table. * This is the main life cycle method for message notifications. When we stop observing * database changes, we save the state [e.g. message ID and count] of the most recent @@ -408,13 +399,6 @@ public class NotificationController { } /** - * Cancels the new message notification for a given mailbox - */ - public void cancelNewMessageNotification(long mailboxId) { - mNotificationManager.cancel(getNewMessageNotificationId(mailboxId)); - } - - /** * Show (or update) a notification that the user's password is expiring. The given account * is used to update the display text, but, all accounts share the same notification ID. * @@ -528,6 +512,20 @@ public class NotificationController { } /** + * Cancels all notifications for the specified account id. This includes new mail notifications, + * as well as special login/security notifications. + */ + public static void cancelNotifications(final Context context, final Account account) { + NotificationUtils.clearAccountNotifications(context, account.mEmailAddress); + + final NotificationManager notificationManager = getInstance(context).mNotificationManager; + + notificationManager.cancel((int) (NOTIFICATION_ID_BASE_LOGIN_WARNING + account.mId)); + notificationManager.cancel((int) (NOTIFICATION_ID_BASE_SECURITY_NEEDED + account.mId)); + notificationManager.cancel((int) (NOTIFICATION_ID_BASE_SECURITY_CHANGED + account.mId)); + } + + /** * Observer invoked whenever a message we're notifying the user about changes. */ private static class MessageContentObserver extends ContentObserver { diff --git a/src/com/android/email/provider/AccountReconciler.java b/src/com/android/email/provider/AccountReconciler.java index 130c8b90f..1412aaf55 100644 --- a/src/com/android/email/provider/AccountReconciler.java +++ b/src/com/android/email/provider/AccountReconciler.java @@ -24,6 +24,7 @@ import android.content.Context; import android.net.Uri; import android.util.Log; +import com.android.email.NotificationController; import com.android.emailcommon.Logging; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.EmailContent; @@ -134,6 +135,9 @@ public class AccountReconciler { providerAccountName); Uri uri = EmailProvider.uiUri("uiaccount", providerAccount.mId); context.getContentResolver().delete(uri, null, null); + + // Cancel all notifications for this account + NotificationController.cancelNotifications(context, providerAccount); } } } diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index aedd14f0e..4917e50b5 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -50,7 +50,6 @@ import android.util.Base64; import android.util.Log; import com.android.common.content.ProjectionMap; -import com.android.email.NotificationController; import com.android.email.Preferences; import com.android.email.R; import com.android.email.SecurityPolicy; @@ -3136,8 +3135,6 @@ public class EmailProvider extends ContentProvider { if (params.containsKey(setVisibilityKey)) { final boolean visible = params.getBoolean(setVisibilityKey); if (visible) { - NotificationController.getInstance(mContext).cancelNewMessageNotification( - mMailboxId); if (params.containsKey( UIProvider.ConversationCursorCommand.COMMAND_KEY_ENTERED_FOLDER)) { Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mMailboxId); @@ -3669,17 +3666,9 @@ public class EmailProvider extends ContentProvider { final String id = uri.getPathSegments().get(1); final Uri[] folders = new Uri[numFolders]; final Context context = getContext(); - final NotificationController controller = NotificationController.getInstance(context); int i = 0; - for (final String uriString: values.keySet()) { + for (final String uriString : values.keySet()) { folders[i] = Uri.parse(uriString); - try { - final String mailboxIdString = folders[i].getLastPathSegment(); - final long mailboxId = Long.parseLong(mailboxIdString); - controller.cancelNewMessageNotification(mailboxId); - } catch (NumberFormatException e) { - // Keep on going... - } } return updateTimestamp(context, id, folders); } |
