1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 21:22:26 -05:00

Fixes Issue 1194

Do both a poll and push reset when connectivity or background data
status changes.
This commit is contained in:
Daniel Applebaum 2010-02-09 01:14:55 +00:00
parent 7cafc8547b
commit 790ae2e25c
5 changed files with 63 additions and 45 deletions

View File

@ -162,7 +162,7 @@ public class Prefs extends K9PreferenceActivity
editor.commit(); editor.commit();
if (needsRefresh) if (needsRefresh)
{ {
MailService.actionRestartPushers(this, null); MailService.actionReset(this, null);
} }
} }

View File

@ -74,7 +74,7 @@ public class K9RemoteControl
* Key for the {@link Intent} Extra for controlling whether K-9 will activate the vibrator for new unread mail. * Key for the {@link Intent} Extra for controlling whether K-9 will activate the vibrator for new unread mail.
* Acceptable values are K9_ENABLED and K9_DISABLED * Acceptable values are K9_ENABLED and K9_DISABLED
*/ */
public final static String K9_VIBRATE_ENABLED = "com.fsck.k9.K9RemoteControl.notificationEnabled"; public final static String K9_VIBRATE_ENABLED = "com.fsck.k9.K9RemoteControl.vibrateEnabled";
public final static String K9_FOLDERS_NONE = "NONE"; public final static String K9_FOLDERS_NONE = "NONE";
public final static String K9_FOLDERS_ALL = "ALL"; public final static String K9_FOLDERS_ALL = "ALL";

View File

@ -51,7 +51,7 @@ public class BootReceiver extends CoreReceiver
} }
else if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(intent.getAction())) else if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(intent.getAction()))
{ {
MailService.actionRestartPushers(context, tmpWakeLockId); MailService.actionReset(context, tmpWakeLockId);
tmpWakeLockId = null; tmpWakeLockId = null;
} }
else if (FIRE_INTENT.equals(intent.getAction())) else if (FIRE_INTENT.equals(intent.getAction()))

View File

@ -38,6 +38,8 @@ public class MailService extends CoreService
private static final String HAS_CONNECTIVITY = "com.fsck.k9.intent.action.MAIL_SERVICE_HAS_CONNECTIVITY"; private static final String HAS_CONNECTIVITY = "com.fsck.k9.intent.action.MAIL_SERVICE_HAS_CONNECTIVITY";
private static long nextCheck = -1;
public static void actionReset(Context context, Integer wakeLockId) public static void actionReset(Context context, Integer wakeLockId)
{ {
Intent i = new Intent(); Intent i = new Intent();
@ -146,7 +148,7 @@ public class MailService extends CoreService
PollService.startService(this); PollService.startService(this);
} }
reschedule(startIdObj); reschedule(hasConnectivity, doBackground, startIdObj);
startIdObj = null; startIdObj = null;
} }
else if (ACTION_CANCEL.equals(intent.getAction())) else if (ACTION_CANCEL.equals(intent.getAction()))
@ -177,7 +179,7 @@ public class MailService extends CoreService
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll"); Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll");
reschedule(startIdObj); reschedule(hasConnectivity, doBackground, startIdObj);
startIdObj = null; startIdObj = null;
} }
@ -216,10 +218,7 @@ public class MailService extends CoreService
private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId) private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId)
{ {
if (hasConnectivity && doBackground) reschedule(hasConnectivity, doBackground, null);
{
reschedule(null);
}
reschedulePushers(hasConnectivity, doBackground, startId); reschedulePushers(hasConnectivity, doBackground, startId);
} }
@ -272,7 +271,9 @@ public class MailService extends CoreService
BootReceiver.cancelIntent(this, i); BootReceiver.cancelIntent(this, i);
} }
private void reschedule(Integer startId) private void reschedule(final boolean hasConnectivity, final boolean doBackground, Integer startId)
{
if (hasConnectivity && doBackground)
{ {
execute(getApplication(), new Runnable() execute(getApplication(), new Runnable()
{ {
@ -292,6 +293,7 @@ public class MailService extends CoreService
if (shortestInterval == -1) if (shortestInterval == -1)
{ {
nextCheck = -1;
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName()); Log.i(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName());
cancel(); cancel();
@ -301,6 +303,7 @@ public class MailService extends CoreService
long delay = (shortestInterval * (60 * 1000)); long delay = (shortestInterval * (60 * 1000));
long nextTime = System.currentTimeMillis() + delay; long nextTime = System.currentTimeMillis() + delay;
nextCheck = nextTime;
try try
{ {
if (K9.DEBUG) if (K9.DEBUG)
@ -322,6 +325,14 @@ public class MailService extends CoreService
} }
, K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT, startId); , K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT, startId);
} }
else
{
nextCheck = -1;
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "No connectivity, canceling check for " + getApplication().getPackageName());
cancel();
}
}
private void stopPushers(final Integer startId) private void stopPushers(final Integer startId)
{ {
@ -446,5 +457,10 @@ public class MailService extends CoreService
return null; return null;
} }
public static long getNextPollTime()
{
return nextCheck;
}
} }

View File

@ -143,7 +143,9 @@ public class RemoteControlService extends CoreService
|| K9RemoteControl.K9_BACKGROUND_OPERATIONS_WHEN_CHECKED.equals(backgroundOps)) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_WHEN_CHECKED.equals(backgroundOps))
{ {
BACKGROUND_OPS newBackgroundOps = BACKGROUND_OPS.valueOf(backgroundOps); BACKGROUND_OPS newBackgroundOps = BACKGROUND_OPS.valueOf(backgroundOps);
needsPushRestart |= K9.setBackgroundOps(newBackgroundOps); boolean needsReset = K9.setBackgroundOps(newBackgroundOps);
needsPushRestart |= needsReset;
needsReschedule |= needsReset;
} }
String theme = intent.getStringExtra(K9_THEME); String theme = intent.getStringExtra(K9_THEME);