From a73579b5b3a61e4a69ee55e90e115a858e969570 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Wed, 17 Jun 2015 12:58:26 +0200 Subject: [PATCH] Don't cancel PendingIntents used for AlarmManager. Creating new ones (which is the implicit effect of FLAG_CANCEL_CURRENT) causes PendingIntent.equals() to return false for the new and the old instance, which in turn leads to AlarmManager failing to remove the alarm. Also remove the unneeded request code offsets. The intent actions for the various actions are already distinct, so we need to only identify between the intents that have the same actions; using the mailbox ID as request code is sufficient for that purpose. Change-Id: I9030c24a9c6b1c722b246601fde741f7027d3de7 --- .../com/android/email/service/ImapService.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/provider_src/com/android/email/service/ImapService.java b/provider_src/com/android/email/service/ImapService.java index f7fe3f894..183a36d4e 100644 --- a/provider_src/com/android/email/service/ImapService.java +++ b/provider_src/com/android/email/service/ImapService.java @@ -111,8 +111,6 @@ public class ImapService extends Service { // Kick idle connection every ~25 minutes (in a window between 25 and 28 minutes) private static final int KICK_IDLE_CONNECTION_TIMEOUT = 25 * 60 * 1000; private static final int KICK_IDLE_CONNECTION_MAX_DELAY = 3 * 60 * 1000; - private static final int ALARM_REQUEST_KICK_IDLE_CODE = 1000; - private static final int ALARM_REQUEST_REFRESH_IDLE_CODE = 1001; // Restart idle connection between 30 seconds and 1 minute after re-gaining connectivity private static final int RESTART_IDLE_DELAY_MIN = 30 * 1000; @@ -292,12 +290,11 @@ public class ImapService extends Service { } private PendingIntent getIdleRefreshIntent() { - int requestCode = ALARM_REQUEST_REFRESH_IDLE_CODE + (int) mMailbox.mId; Intent i = new Intent(mContext, ImapService.class); i.setAction(ACTION_RESTART_IDLE_CONNECTION); - i.putExtra(EXTRA_MAILBOX, (int) mMailbox.mId); - return PendingIntent.getService(mContext, requestCode, i, - PendingIntent.FLAG_CANCEL_CURRENT); + i.putExtra(EXTRA_MAILBOX, mMailbox.mId); + return PendingIntent.getService(mContext, (int) mMailbox.mId, i, + PendingIntent.FLAG_UPDATE_CURRENT); } private void scheduleKickIdleConnection() { @@ -314,12 +311,11 @@ public class ImapService extends Service { } private PendingIntent getKickIdleConnectionPendingIntent() { - int requestCode = ALARM_REQUEST_KICK_IDLE_CODE + (int) mMailbox.mId; Intent i = new Intent(mContext, ImapService.class); i.setAction(ACTION_KICK_IDLE_CONNECTION); i.putExtra(EXTRA_MAILBOX, mMailbox.mId); - return PendingIntent.getService(mContext, requestCode, - i, PendingIntent.FLAG_CANCEL_CURRENT); + return PendingIntent.getService(mContext, (int) mMailbox.mId, + i, PendingIntent.FLAG_UPDATE_CURRENT); } } @@ -592,7 +588,7 @@ public class ImapService extends Service { private PendingIntent getIdleConnectionRestartIntent() { Intent i = new Intent(mContext, ImapService.class); i.setAction(ACTION_RESTART_ALL_IDLE_CONNECTIONS); - return PendingIntent.getService(mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); + return PendingIntent.getService(mContext, 0, i, 0); } }