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
This commit is contained in:
Danny Baumann 2015-06-17 12:58:26 +02:00 committed by Steve Kondik
parent 99c6d7b40a
commit a73579b5b3

View File

@ -111,8 +111,6 @@ public class ImapService extends Service {
// Kick idle connection every ~25 minutes (in a window between 25 and 28 minutes) // 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_TIMEOUT = 25 * 60 * 1000;
private static final int KICK_IDLE_CONNECTION_MAX_DELAY = 3 * 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 // Restart idle connection between 30 seconds and 1 minute after re-gaining connectivity
private static final int RESTART_IDLE_DELAY_MIN = 30 * 1000; private static final int RESTART_IDLE_DELAY_MIN = 30 * 1000;
@ -292,12 +290,11 @@ public class ImapService extends Service {
} }
private PendingIntent getIdleRefreshIntent() { private PendingIntent getIdleRefreshIntent() {
int requestCode = ALARM_REQUEST_REFRESH_IDLE_CODE + (int) mMailbox.mId;
Intent i = new Intent(mContext, ImapService.class); Intent i = new Intent(mContext, ImapService.class);
i.setAction(ACTION_RESTART_IDLE_CONNECTION); i.setAction(ACTION_RESTART_IDLE_CONNECTION);
i.putExtra(EXTRA_MAILBOX, (int) mMailbox.mId); i.putExtra(EXTRA_MAILBOX, mMailbox.mId);
return PendingIntent.getService(mContext, requestCode, i, return PendingIntent.getService(mContext, (int) mMailbox.mId, i,
PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT);
} }
private void scheduleKickIdleConnection() { private void scheduleKickIdleConnection() {
@ -314,12 +311,11 @@ public class ImapService extends Service {
} }
private PendingIntent getKickIdleConnectionPendingIntent() { private PendingIntent getKickIdleConnectionPendingIntent() {
int requestCode = ALARM_REQUEST_KICK_IDLE_CODE + (int) mMailbox.mId;
Intent i = new Intent(mContext, ImapService.class); Intent i = new Intent(mContext, ImapService.class);
i.setAction(ACTION_KICK_IDLE_CONNECTION); i.setAction(ACTION_KICK_IDLE_CONNECTION);
i.putExtra(EXTRA_MAILBOX, mMailbox.mId); i.putExtra(EXTRA_MAILBOX, mMailbox.mId);
return PendingIntent.getService(mContext, requestCode, return PendingIntent.getService(mContext, (int) mMailbox.mId,
i, PendingIntent.FLAG_CANCEL_CURRENT); i, PendingIntent.FLAG_UPDATE_CURRENT);
} }
} }
@ -592,7 +588,7 @@ public class ImapService extends Service {
private PendingIntent getIdleConnectionRestartIntent() { private PendingIntent getIdleConnectionRestartIntent() {
Intent i = new Intent(mContext, ImapService.class); Intent i = new Intent(mContext, ImapService.class);
i.setAction(ACTION_RESTART_ALL_IDLE_CONNECTIONS); i.setAction(ACTION_RESTART_ALL_IDLE_CONNECTIONS);
return PendingIntent.getService(mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); return PendingIntent.getService(mContext, 0, i, 0);
} }
} }