1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Fixes Issue 1059

Only reschedule polling and setup pushing when necessary due to
particular setting changes.  Makes the K-9 Mail UI much more
responsive to setting changes that do not affect polling and pushing.

The poll schedule is deliberately only rescheduled when the period is
decreased.  An increase in period will still allow the next scheduled
check to happen as originally scheduled.
This commit is contained in:
Daniel Applebaum 2010-02-07 21:23:33 +00:00
parent 2f8f52fb0b
commit 164ee7cbfd
10 changed files with 174 additions and 92 deletions

View File

@ -732,9 +732,21 @@ public class Account implements Serializable
/** /**
* @param automaticCheckIntervalMinutes or -1 for never. * @param automaticCheckIntervalMinutes or -1 for never.
*/ */
public void setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes) public boolean setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes)
{ {
int oldInterval = this.mAutomaticCheckIntervalMinutes;
int newInterval = automaticCheckIntervalMinutes;
this.mAutomaticCheckIntervalMinutes = automaticCheckIntervalMinutes; this.mAutomaticCheckIntervalMinutes = automaticCheckIntervalMinutes;
if (oldInterval == -1 && newInterval != -1)
{
return true;
}
if (newInterval < oldInterval)
{
return true;
}
return false;
} }
/** /**
@ -863,9 +875,11 @@ public class Account implements Serializable
return mFolderDisplayMode; return mFolderDisplayMode;
} }
public void setFolderDisplayMode(FolderMode displayMode) public boolean setFolderDisplayMode(FolderMode displayMode)
{ {
FolderMode oldDisplayMode = mFolderDisplayMode;
mFolderDisplayMode = displayMode; mFolderDisplayMode = displayMode;
return oldDisplayMode != displayMode;
} }
public FolderMode getFolderSyncMode() public FolderMode getFolderSyncMode()
@ -873,9 +887,20 @@ public class Account implements Serializable
return mFolderSyncMode; return mFolderSyncMode;
} }
public void setFolderSyncMode(FolderMode syncMode) public boolean setFolderSyncMode(FolderMode syncMode)
{ {
FolderMode oldSyncMode = mFolderSyncMode;
mFolderSyncMode = syncMode; mFolderSyncMode = syncMode;
if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE)
{
return true;
}
if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE)
{
return true;
}
return false;
} }
public FolderMode getFolderPushMode() public FolderMode getFolderPushMode()
@ -883,9 +908,12 @@ public class Account implements Serializable
return mFolderPushMode; return mFolderPushMode;
} }
public void setFolderPushMode(FolderMode syncMode) public boolean setFolderPushMode(FolderMode pushMode)
{ {
mFolderPushMode = syncMode; FolderMode oldPushMode = mFolderPushMode;
mFolderPushMode = pushMode;
return pushMode != oldPushMode;
} }
public boolean isShowOngoing() public boolean isShowOngoing()
@ -953,9 +981,11 @@ public class Account implements Serializable
return mMaxPushFolders; return mMaxPushFolders;
} }
public void setMaxPushFolders(int maxPushFolders) public boolean setMaxPushFolders(int maxPushFolders)
{ {
int oldMaxPushFolders = mMaxPushFolders;
mMaxPushFolders = maxPushFolders; mMaxPushFolders = maxPushFolders;
return oldMaxPushFolders != maxPushFolders;
} }
public boolean isRing() public boolean isRing()

View File

@ -246,7 +246,6 @@ public class K9 extends Application
*/ */
public static void setServicesEnabled(Context context) public static void setServicesEnabled(Context context)
{ {
int acctLength = Preferences.getPreferences(context).getAccounts().length; int acctLength = Preferences.getPreferences(context).getAccounts().length;
setServicesEnabled(context, acctLength > 0, null); setServicesEnabled(context, acctLength > 0, null);
@ -270,7 +269,7 @@ public class K9 extends Application
* If no accounts now exist but the service is still enabled we're about to disable it * If no accounts now exist but the service is still enabled we're about to disable it
* so we'll reschedule to kill off any existing alarms. * so we'll reschedule to kill off any existing alarms.
*/ */
MailService.actionReschedule(context, wakeLockId); MailService.actionReset(context, wakeLockId);
} }
Class[] classes = { MessageCompose.class, BootReceiver.class, MailService.class }; Class[] classes = { MessageCompose.class, BootReceiver.class, MailService.class };
@ -297,7 +296,7 @@ public class K9 extends Application
* And now if accounts do exist then we've just enabled the service and we want to * And now if accounts do exist then we've just enabled the service and we want to
* schedule alarms for the new accounts. * schedule alarms for the new accounts.
*/ */
MailService.actionReschedule(context, wakeLockId); MailService.actionReset(context, wakeLockId);
} }
} }
@ -427,14 +426,16 @@ public class K9 extends Application
return backgroundOps; return backgroundOps;
} }
public static void setBackgroundOps(BACKGROUND_OPS backgroundOps) public static boolean setBackgroundOps(BACKGROUND_OPS backgroundOps)
{ {
BACKGROUND_OPS oldBackgroundOps = K9.backgroundOps;
K9.backgroundOps = backgroundOps; K9.backgroundOps = backgroundOps;
return backgroundOps != oldBackgroundOps;
} }
public static void setBackgroundOps(String nbackgroundOps) public static boolean setBackgroundOps(String nbackgroundOps)
{ {
K9.backgroundOps = BACKGROUND_OPS.valueOf(nbackgroundOps); return setBackgroundOps(BACKGROUND_OPS.valueOf(nbackgroundOps));
} }
public static boolean isAnimations() public static boolean isAnimations()

View File

@ -413,7 +413,10 @@ public class FolderList extends K9ListActivity
{ {
mAccount.setFolderDisplayMode(newMode); mAccount.setFolderDisplayMode(newMode);
mAccount.save(Preferences.getPreferences(this)); mAccount.save(Preferences.getPreferences(this));
MailService.actionReschedule(this, null); // TODO: really should just refresh pushers if (mAccount.getFolderPushMode() != FolderMode.NONE)
{
MailService.actionRestartPushers(this, null);
}
onRefresh(false); onRefresh(false);
} }

View File

@ -12,10 +12,12 @@ import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.widget.Toast; import android.widget.Toast;
import com.fsck.k9.*; import com.fsck.k9.*;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.activity.ChooseFolder; import com.fsck.k9.activity.ChooseFolder;
import com.fsck.k9.activity.ChooseIdentity; import com.fsck.k9.activity.ChooseIdentity;
import com.fsck.k9.activity.ManageIdentities; import com.fsck.k9.activity.ManageIdentities;
import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Store;
import com.fsck.k9.service.MailService;
public class AccountSettings extends K9PreferenceActivity public class AccountSettings extends K9PreferenceActivity
{ {
@ -72,6 +74,7 @@ public class AccountSettings extends K9PreferenceActivity
private ListPreference mExpungePolicy; private ListPreference mExpungePolicy;
private Preference mAutoExpandFolder; private Preference mAutoExpandFolder;
private CheckBoxPreference mStoreAttachmentsOnSdCard; private CheckBoxPreference mStoreAttachmentsOnSdCard;
private boolean mIncomingChanged = false;
public static void actionSettings(Context context, Account account) public static void actionSettings(Context context, Account account)
@ -87,7 +90,7 @@ public class AccountSettings extends K9PreferenceActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
mAccount.refresh(Preferences.getPreferences(this)); mAccount.refresh(Preferences.getPreferences(this));
boolean isPushCapable = false; boolean isPushCapable = false;
boolean isExpungeCapable = false; boolean isExpungeCapable = false;
@ -341,6 +344,7 @@ public class AccountSettings extends K9PreferenceActivity
{ {
public boolean onPreferenceClick(Preference preference) public boolean onPreferenceClick(Preference preference)
{ {
mIncomingChanged = true;
onIncomingSettings(); onIncomingSettings();
return true; return true;
} }
@ -392,22 +396,29 @@ public class AccountSettings extends K9PreferenceActivity
{ {
Preferences.getPreferences(this).setDefaultAccount(mAccount); Preferences.getPreferences(this).setDefaultAccount(mAccount);
} }
mAccount.setDescription(mAccountDescription.getText()); mAccount.setDescription(mAccountDescription.getText());
mAccount.setNotifyNewMail(mAccountNotify.isChecked()); mAccount.setNotifyNewMail(mAccountNotify.isChecked());
mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked()); mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked());
mAccount.setShowOngoing(mAccountNotifySync.isChecked()); mAccount.setShowOngoing(mAccountNotifySync.isChecked());
mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue()));
mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue())); mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue()));
mAccount.setVibrate(mAccountVibrate.isChecked()); mAccount.setVibrate(mAccountVibrate.isChecked());
mAccount.setFolderDisplayMode(Account.FolderMode.valueOf(mDisplayMode.getValue()));
mAccount.setFolderSyncMode(Account.FolderMode.valueOf(mSyncMode.getValue()));
mAccount.setFolderPushMode(Account.FolderMode.valueOf(mPushMode.getValue()));
mAccount.setMaxPushFolders(Integer.parseInt(mPushLimit.getValue()));
mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue())); mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue()));
mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue())); mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue()));
mAccount.setExpungePolicy(mExpungePolicy.getValue()); mAccount.setExpungePolicy(mExpungePolicy.getValue());
mAccount.setStoreAttachmentOnSdCard(mStoreAttachmentsOnSdCard.isChecked()); mAccount.setStoreAttachmentOnSdCard(mStoreAttachmentsOnSdCard.isChecked());
boolean needsRefresh = mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue()));
needsRefresh |= mAccount.setFolderSyncMode(Account.FolderMode.valueOf(mSyncMode.getValue()));
boolean needsPushRestart = mAccount.setFolderPushMode(Account.FolderMode.valueOf(mPushMode.getValue()));
if (mAccount.getFolderPushMode() != FolderMode.NONE)
{
needsPushRestart |= mAccount.setFolderDisplayMode(Account.FolderMode.valueOf(mDisplayMode.getValue()));
needsPushRestart |= mAccount.setMaxPushFolders(Integer.parseInt(mPushLimit.getValue()));
needsPushRestart |= mIncomingChanged;
}
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null); String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null);
if (newRingtone != null) if (newRingtone != null)
@ -426,7 +437,18 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setHideMessageViewButtons(Account.HideButtons.valueOf(mAccountHideButtons.getValue())); mAccount.setHideMessageViewButtons(Account.HideButtons.valueOf(mAccountHideButtons.getValue()));
mAccount.setAutoExpandFolderName(reverseTranslateFolder(mAutoExpandFolder.getSummary().toString())); mAccount.setAutoExpandFolderName(reverseTranslateFolder(mAutoExpandFolder.getSummary().toString()));
mAccount.save(Preferences.getPreferences(this)); mAccount.save(Preferences.getPreferences(this));
K9.setServicesEnabled(this); if (needsRefresh && needsPushRestart)
{
MailService.actionReset(this, null);
}
else if (needsRefresh)
{
MailService.actionReschedulePoll(this, null);
}
else if (needsPushRestart)
{
MailService.actionRestartPushers(this, null);
}
// TODO: refresh folder list here // TODO: refresh folder list here
} }

View File

@ -13,6 +13,7 @@ import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.service.MailService;
public class FolderSettings extends K9PreferenceActivity public class FolderSettings extends K9PreferenceActivity
{ {
@ -140,14 +141,24 @@ public class FolderSettings extends K9PreferenceActivity
private void saveSettings() private void saveSettings()
{ {
// We call getPushClass() because display class changes can affect push class when push class is set to inherit
FolderClass oldPushClass = mFolder.getPushClass();
FolderClass oldDisplayClass = mFolder.getDisplayClass();
mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue())); mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue())); mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue())); mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));
FolderClass newPushClass = mFolder.getPushClass();
FolderClass newDisplayClass = mFolder.getDisplayClass();
try try
{ {
mFolder.save(Preferences.getPreferences(this)); mFolder.save(Preferences.getPreferences(this));
K9.setServicesEnabled(this); if (oldPushClass != newPushClass
|| (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass))
{
MailService.actionRestartPushers(getApplication(), null);
}
} }
catch (MessagingException me) catch (MessagingException me)
{ {

View File

@ -148,8 +148,7 @@ public class Prefs extends K9PreferenceActivity
K9.setK9Theme(mTheme.getValue().equals("dark") ? android.R.style.Theme : android.R.style.Theme_Light); K9.setK9Theme(mTheme.getValue().equals("dark") ? android.R.style.Theme : android.R.style.Theme_Light);
K9.DEBUG = mDebugLogging.isChecked(); K9.DEBUG = mDebugLogging.isChecked();
K9.DEBUG_SENSITIVE = mSensitiveLogging.isChecked(); K9.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
String newBackgroundOps = mBackgroundOps.getValue(); boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
K9.setBackgroundOps(newBackgroundOps);
K9.setAnimations(mAnimations.isChecked()); K9.setAnimations(mAnimations.isChecked());
K9.setMessageListStars(mStars.isChecked()); K9.setMessageListStars(mStars.isChecked());
@ -161,9 +160,9 @@ public class Prefs extends K9PreferenceActivity
K9.save(editor); K9.save(editor);
DateFormatter.setDateFormat(editor, mDateFormat.getValue()); DateFormatter.setDateFormat(editor, mDateFormat.getValue());
editor.commit(); editor.commit();
if (newBackgroundOps.equals(initBackgroundOps) == false) if (needsRefresh)
{ {
MailService.backgroundDataChanged(this, null); MailService.actionRestartPushers(this, null);
} }
} }

View File

@ -40,7 +40,7 @@ public class BootReceiver extends CoreReceiver
} }
else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction()))
{ {
MailService.actionReschedule(context, tmpWakeLockId); MailService.actionReset(context, tmpWakeLockId);
tmpWakeLockId = null; tmpWakeLockId = null;
} }
else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()))
@ -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.backgroundDataChanged(context, tmpWakeLockId); MailService.actionRestartPushers(context, tmpWakeLockId);
tmpWakeLockId = null; tmpWakeLockId = null;
} }
else if (FIRE_INTENT.equals(intent.getAction())) else if (FIRE_INTENT.equals(intent.getAction()))

View File

@ -1,6 +1,9 @@
package com.fsck.k9.service; package com.fsck.k9.service;
import java.util.Collection;
import java.util.Date;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -10,40 +13,36 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkInfo.State; import android.net.NetworkInfo.State;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Config;
import android.util.Log; import android.util.Log;
import com.fsck.k9.*;
import com.fsck.k9.mail.Pusher;
import java.util.Collection; import com.fsck.k9.Account;
import java.util.Date; import com.fsck.k9.K9;
import java.util.concurrent.ExecutorService; import com.fsck.k9.MessagingController;
import java.util.concurrent.Executors; import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.mail.Pusher;
/** /**
*/ */
public class MailService extends CoreService public class MailService extends CoreService
{ {
private static final String ACTION_CHECK_MAIL = "com.fsck.k9.intent.action.MAIL_SERVICE_WAKEUP"; private static final String ACTION_CHECK_MAIL = "com.fsck.k9.intent.action.MAIL_SERVICE_WAKEUP";
private static final String ACTION_RESCHEDULE = "com.fsck.k9.intent.action.MAIL_SERVICE_RESCHEDULE"; private static final String ACTION_RESET = "com.fsck.k9.intent.action.MAIL_SERVICE_RESET";
private static final String ACTION_RESCHEDULE_CHECK = "com.fsck.k9.intent.action.MAIL_SERVICE_RESCHEDULE_CHECK"; private static final String ACTION_RESCHEDULE_POLL = "com.fsck.k9.intent.action.MAIL_SERVICE_RESCHEDULE_POLL";
private static final String ACTION_CANCEL = "com.fsck.k9.intent.action.MAIL_SERVICE_CANCEL"; private static final String ACTION_CANCEL = "com.fsck.k9.intent.action.MAIL_SERVICE_CANCEL";
private static final String ACTION_REFRESH_PUSHERS = "com.fsck.k9.intent.action.MAIL_SERVICE_REFRESH_PUSHERS"; private static final String ACTION_REFRESH_PUSHERS = "com.fsck.k9.intent.action.MAIL_SERVICE_REFRESH_PUSHERS";
private static final String ACTION_RESTART_PUSHERS = "com.fsck.k9.intent.action.MAIL_SERVICE_RESTART_PUSHERS";
private static final String CONNECTIVITY_CHANGE = "com.fsck.k9.intent.action.MAIL_SERVICE_CONNECTIVITY_CHANGE"; private static final String CONNECTIVITY_CHANGE = "com.fsck.k9.intent.action.MAIL_SERVICE_CONNECTIVITY_CHANGE";
private static final String BACKGROUND_DATA_CHANGED = "com.fsck.k9.intent.action.MAIL_SERVICE_BACKGROUND_DATA_CHANGED";
private static final String CANCEL_CONNECTIVITY_NOTICE = "com.fsck.k9.intent.action.MAIL_SERVICE_CANCEL_CONNECTIVITY_NOTICE"; 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 final String HAS_CONNECTIVITY = "com.fsck.k9.intent.action.MAIL_SERVICE_HAS_CONNECTIVITY";
public static void actionReset(Context context, Integer wakeLockId)
public static void actionReschedule(Context context, Integer wakeLockId)
{ {
Intent i = new Intent(); Intent i = new Intent();
i.setClass(context, MailService.class); i.setClass(context, MailService.class);
i.setAction(MailService.ACTION_RESCHEDULE); i.setAction(MailService.ACTION_RESET);
addWakeLockId(i, wakeLockId); addWakeLockId(i, wakeLockId);
if (wakeLockId == null) if (wakeLockId == null)
{ {
@ -51,13 +50,30 @@ public class MailService extends CoreService
} }
context.startService(i); context.startService(i);
} }
public static void rescheduleCheck(Context context, Integer wakeLockId) public static void actionRestartPushers(Context context, Integer wakeLockId)
{ {
Intent i = new Intent(); Intent i = new Intent();
i.setClass(context, MailService.class); i.setClass(context, MailService.class);
i.setAction(MailService.ACTION_RESCHEDULE_CHECK); i.setAction(MailService.ACTION_RESTART_PUSHERS);
addWakeLockId(i, wakeLockId); addWakeLockId(i, wakeLockId);
if (wakeLockId == null)
{
addWakeLock(context, i);
}
context.startService(i);
}
public static void actionReschedulePoll(Context context, Integer wakeLockId)
{
Intent i = new Intent();
i.setClass(context, MailService.class);
i.setAction(MailService.ACTION_RESCHEDULE_POLL);
addWakeLockId(i, wakeLockId);
if (wakeLockId == null)
{
addWakeLock(context, i);
}
context.startService(i); context.startService(i);
} }
@ -80,15 +96,6 @@ public class MailService extends CoreService
context.startService(i); context.startService(i);
} }
public static void backgroundDataChanged(Context context, Integer wakeLockId)
{
Intent i = new Intent();
i.setClass(context, MailService.class);
i.setAction(MailService.BACKGROUND_DATA_CHANGED);
addWakeLockId(i, wakeLockId);
context.startService(i);
}
@Override @Override
public void onCreate() public void onCreate()
{ {
@ -149,7 +156,7 @@ public class MailService extends CoreService
cancel(); cancel();
} }
else if (ACTION_RESCHEDULE.equals(intent.getAction())) else if (ACTION_RESET.equals(intent.getAction()))
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: reschedule"); Log.v(K9.LOG_TAG, "***** MailService *****: reschedule");
@ -158,11 +165,18 @@ public class MailService extends CoreService
startIdObj = null; startIdObj = null;
} }
else if (ACTION_RESCHEDULE_CHECK.equals(intent.getAction())) else if (ACTION_RESTART_PUSHERS.equals(intent.getAction()))
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: reschedule check"); Log.v(K9.LOG_TAG, "***** MailService *****: restarting pushers");
reschedulePushers(hasConnectivity, doBackground, startIdObj);
startIdObj = null;
}
else if (ACTION_RESCHEDULE_POLL.equals(intent.getAction()))
{
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: rescheduling poll");
reschedule(startIdObj); reschedule(startIdObj);
startIdObj = null; startIdObj = null;
@ -176,8 +190,7 @@ public class MailService extends CoreService
startIdObj = null; startIdObj = null;
} }
} }
else if (CONNECTIVITY_CHANGE.equals(intent.getAction()) || else if (CONNECTIVITY_CHANGE.equals(intent.getAction()) )
BACKGROUND_DATA_CHANGED.equals(intent.getAction()))
{ {
notifyConnectionStatus(hasConnectivity); notifyConnectionStatus(hasConnectivity);
rescheduleAll(hasConnectivity, doBackground, startIdObj); rescheduleAll(hasConnectivity, doBackground, startIdObj);
@ -206,12 +219,9 @@ public class MailService extends CoreService
if (hasConnectivity && doBackground) if (hasConnectivity && doBackground)
{ {
reschedule(null); reschedule(null);
reschedulePushers(startId);
}
else
{
stopPushers(startId);
} }
reschedulePushers(hasConnectivity, doBackground, startId);
} }
private void notifyConnectionStatus(boolean hasConnectivity) private void notifyConnectionStatus(boolean hasConnectivity)
@ -273,6 +283,7 @@ public class MailService extends CoreService
for (Account account : Preferences.getPreferences(MailService.this).getAccounts()) for (Account account : Preferences.getPreferences(MailService.this).getAccounts())
{ {
if (account.getAutomaticCheckIntervalMinutes() != -1 if (account.getAutomaticCheckIntervalMinutes() != -1
&& account.getFolderSyncMode() != FolderMode.NONE
&& (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) && (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1))
{ {
shortestInterval = account.getAutomaticCheckIntervalMinutes(); shortestInterval = account.getAutomaticCheckIntervalMinutes();
@ -282,7 +293,7 @@ public class MailService extends CoreService
if (shortestInterval == -1) if (shortestInterval == -1)
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(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();
} }
else else
@ -325,7 +336,7 @@ public class MailService extends CoreService
, K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT, startId); , K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT, startId);
} }
private void reschedulePushers(final Integer startId) private void reschedulePushers(final boolean hasConnectivity, final boolean doBackground, final Integer startId)
{ {
execute(getApplication(), new Runnable() execute(getApplication(), new Runnable()
{ {
@ -335,8 +346,11 @@ public class MailService extends CoreService
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Rescheduling pushers"); Log.i(K9.LOG_TAG, "Rescheduling pushers");
stopPushers(null); stopPushers(null);
setupPushers(null); if (hasConnectivity && doBackground)
schedulePushers(startId); {
setupPushers(null);
schedulePushers(startId);
}
} }
} }

View File

@ -142,7 +142,7 @@ public class PollService extends CoreService
{ {
MessagingController controller = MessagingController.getInstance(getApplication()); MessagingController controller = MessagingController.getInstance(getApplication());
controller.setCheckMailListener(null); controller.setCheckMailListener(null);
MailService.rescheduleCheck(PollService.this, null); MailService.actionReschedulePoll(PollService.this, null);
wakeLockRelease(); wakeLockRelease();
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId); Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId);

View File

@ -20,6 +20,7 @@ import android.widget.Toast;
public class RemoteControlService extends CoreService public class RemoteControlService extends CoreService
{ {
private final static String RESCHEDULE_ACTION = "com.fsck.k9.service.RemoteControlService.RESCHEDULE_ACTION"; private final static String RESCHEDULE_ACTION = "com.fsck.k9.service.RemoteControlService.RESCHEDULE_ACTION";
private final static String PUSH_RESTART_ACTION = "com.fsck.k9.service.RemoteControlService.PUSH_RESTART_ACTION";
private final static String SET_ACTION = "com.fsck.k9.service.RemoteControlService.SET_ACTION"; private final static String SET_ACTION = "com.fsck.k9.service.RemoteControlService.SET_ACTION";
@ -48,8 +49,14 @@ public class RemoteControlService extends CoreService
if (RESCHEDULE_ACTION.equals(intent.getAction())) if (RESCHEDULE_ACTION.equals(intent.getAction()))
{ {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "RemoteControlService requesting MailService reschedule"); Log.i(K9.LOG_TAG, "RemoteControlService requesting MailService poll reschedule");
MailService.actionReschedule(this, null); MailService.actionReschedulePoll(this, null);
}
if (PUSH_RESTART_ACTION.equals(intent.getAction()))
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "RemoteControlService requesting MailService push restart");
MailService.actionRestartPushers(this, null);
} }
else if (RemoteControlService.SET_ACTION.equals(intent.getAction())) else if (RemoteControlService.SET_ACTION.equals(intent.getAction()))
{ {
@ -62,6 +69,7 @@ public class RemoteControlService extends CoreService
try try
{ {
boolean needsReschedule = false; boolean needsReschedule = false;
boolean needsPushRestart = false;
String uuid = intent.getStringExtra(K9_ACCOUNT_UUID); String uuid = intent.getStringExtra(K9_ACCOUNT_UUID);
boolean allAccounts = intent.getBooleanExtra(K9_ALL_ACCOUNTS, false); boolean allAccounts = intent.getBooleanExtra(K9_ALL_ACCOUNTS, false);
if (K9.DEBUG) if (K9.DEBUG)
@ -105,17 +113,11 @@ public class RemoteControlService extends CoreService
} }
if (pushClasses != null) if (pushClasses != null)
{ {
FolderMode newClasses = FolderMode.valueOf(pushClasses); needsPushRestart |= account.setFolderPushMode(FolderMode.valueOf(pushClasses));
if (newClasses.equals(account.getFolderPushMode()) == false)
{
account.setFolderPushMode(newClasses);
needsReschedule = true;
}
} }
if (pollClasses != null) if (pollClasses != null)
{ {
account.setFolderSyncMode(FolderMode.valueOf(pollClasses)); needsReschedule |= account.setFolderSyncMode(FolderMode.valueOf(pollClasses));
} }
if (pollFrequency != null) if (pollFrequency != null)
{ {
@ -125,11 +127,7 @@ public class RemoteControlService extends CoreService
if (allowedFrequency.equals(pollFrequency)) if (allowedFrequency.equals(pollFrequency))
{ {
Integer newInterval = Integer.parseInt(allowedFrequency); Integer newInterval = Integer.parseInt(allowedFrequency);
if (newInterval.equals(account.getAutomaticCheckIntervalMinutes()) == false) needsReschedule |= account.setAutomaticCheckIntervalMinutes(newInterval);
{
account.setAutomaticCheckIntervalMinutes(newInterval);
needsReschedule = true;
}
} }
} }
} }
@ -145,11 +143,7 @@ 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);
if (K9.getBackgroundOps().equals(newBackgroundOps) == false) needsPushRestart |= K9.setBackgroundOps(newBackgroundOps);
{
K9.setBackgroundOps(newBackgroundOps);
needsReschedule = true;
}
} }
String theme = intent.getStringExtra(K9_THEME); String theme = intent.getStringExtra(K9_THEME);
@ -172,6 +166,14 @@ public class RemoteControlService extends CoreService
long nextTime = System.currentTimeMillis() + 10000; long nextTime = System.currentTimeMillis() + 10000;
BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i); BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
} }
if (needsPushRestart)
{
Intent i = new Intent();
i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.RemoteControlService");
i.setAction(PUSH_RESTART_ACTION);
long nextTime = System.currentTimeMillis() + 10000;
BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
}
} }
catch (Exception e) catch (Exception e)
{ {