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();
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.
* 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_ALL = "ALL";

View File

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

View File

@ -37,6 +37,8 @@ public class MailService extends CoreService
private static final String CANCEL_CONNECTIVITY_NOTICE = "com.fsck.k9.intent.action.MAIL_SERVICE_CANCEL_CONNECTIVITY_NOTICE";
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)
{
@ -146,7 +148,7 @@ public class MailService extends CoreService
PollService.startService(this);
}
reschedule(startIdObj);
reschedule(hasConnectivity, doBackground, startIdObj);
startIdObj = null;
}
else if (ACTION_CANCEL.equals(intent.getAction()))
@ -177,7 +179,7 @@ public class MailService extends CoreService
{
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll");
reschedule(startIdObj);
reschedule(hasConnectivity, doBackground, startIdObj);
startIdObj = null;
}
@ -216,10 +218,7 @@ public class MailService extends CoreService
private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId)
{
if (hasConnectivity && doBackground)
{
reschedule(null);
}
reschedule(hasConnectivity, doBackground, null);
reschedulePushers(hasConnectivity, doBackground, startId);
}
@ -272,55 +271,67 @@ public class MailService extends CoreService
BootReceiver.cancelIntent(this, i);
}
private void reschedule(Integer startId)
private void reschedule(final boolean hasConnectivity, final boolean doBackground, Integer startId)
{
execute(getApplication(), new Runnable()
if (hasConnectivity && doBackground)
{
public void run()
execute(getApplication(), new Runnable()
{
int shortestInterval = -1;
for (Account account : Preferences.getPreferences(MailService.this).getAccounts())
public void run()
{
if (account.getAutomaticCheckIntervalMinutes() != -1
&& account.getFolderSyncMode() != FolderMode.NONE
&& (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1))
int shortestInterval = -1;
for (Account account : Preferences.getPreferences(MailService.this).getAccounts())
{
shortestInterval = account.getAutomaticCheckIntervalMinutes();
if (account.getAutomaticCheckIntervalMinutes() != -1
&& account.getFolderSyncMode() != FolderMode.NONE
&& (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1))
{
shortestInterval = account.getAutomaticCheckIntervalMinutes();
}
}
}
if (shortestInterval == -1)
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName());
cancel();
}
else
{
long delay = (shortestInterval * (60 * 1000));
long nextTime = System.currentTimeMillis() + delay;
try
if (shortestInterval == -1)
{
nextCheck = -1;
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime));
Log.i(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName());
cancel();
}
catch (Exception e)
else
{
// I once got a NullPointerException deep in new Date();
Log.e(K9.LOG_TAG, "Exception while logging", e);
long delay = (shortestInterval * (60 * 1000));
long nextTime = System.currentTimeMillis() + delay;
nextCheck = nextTime;
try
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime));
}
catch (Exception e)
{
// I once got a NullPointerException deep in new Date();
Log.e(K9.LOG_TAG, "Exception while logging", e);
}
Intent i = new Intent();
i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService");
i.setAction(ACTION_CHECK_MAIL);
BootReceiver.scheduleIntent(MailService.this, nextTime, i);
}
Intent i = new Intent();
i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService");
i.setAction(ACTION_CHECK_MAIL);
BootReceiver.scheduleIntent(MailService.this, nextTime, i);
}
}
, 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();
}
, K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT, startId);
}
private void stopPushers(final Integer startId)
@ -446,5 +457,10 @@ public class MailService extends CoreService
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))
{
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);