summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Hibdon <mhibdon@google.com>2014-10-06 11:56:34 -0700
committerMartin Hibdon <mhibdon@google.com>2014-10-07 16:03:41 -0700
commit1e2a913eb7bd5b30ad4098582c31ba9c6b40efb5 (patch)
tree08b9e63d4f23c551456f3110ee445272a26f2f83 /src
parent9b2db3efa01353044e7dffd349c769dda5ee2ecf (diff)
downloadandroid_packages_apps_Exchange-1e2a913eb7bd5b30ad4098582c31ba9c6b40efb5.tar.gz
android_packages_apps_Exchange-1e2a913eb7bd5b30ad4098582c31ba9c6b40efb5.tar.bz2
android_packages_apps_Exchange-1e2a913eb7bd5b30ad4098582c31ba9c6b40efb5.zip
Fix ping upon account creation
b/17708011 Change-Id: I46643a6c15f85b93bcc6aeb5c0d90a0f0bd2cd4b
Diffstat (limited to 'src')
-rw-r--r--src/com/android/exchange/service/EasService.java17
-rw-r--r--src/com/android/exchange/service/PingSyncSynchronizer.java53
2 files changed, 47 insertions, 23 deletions
diff --git a/src/com/android/exchange/service/EasService.java b/src/com/android/exchange/service/EasService.java
index 95c7b0b0..07a46b5e 100644
--- a/src/com/android/exchange/service/EasService.java
+++ b/src/com/android/exchange/service/EasService.java
@@ -125,7 +125,7 @@ public class EasService extends Service {
public void pushModify(final long accountId) {
LogUtils.d(TAG, "IEmailService.pushModify: %d", accountId);
final Account account = Account.restoreAccountWithId(EasService.this, accountId);
- if (pingNeededForAccount(account)) {
+ if (pingNeededForAccount(EasService.this, account)) {
mSynchronizer.pushModify(account);
} else {
mSynchronizer.pushStop(accountId);
@@ -261,15 +261,16 @@ public class EasService extends Service {
@Override
protected Void doInBackground(Void... params) {
+ LogUtils.i(TAG, "RestartPingTask");
final Cursor c = EasService.this.getContentResolver().query(Account.CONTENT_URI,
Account.CONTENT_PROJECTION, PUSH_ACCOUNTS_SELECTION, null, null);
if (c != null) {
try {
while (c.moveToNext()) {
final Account account = new Account();
- LogUtils.d(TAG, "RestartPingsTask starting ping for %s", account);
account.restore(c);
- if (EasService.this.pingNeededForAccount(account)) {
+ LogUtils.i(TAG, "RestartPingsTask starting ping for %d", account.getId());
+ if (pingNeededForAccount(EasService.this, account)) {
mHasRestartedPing = true;
EasService.this.mSynchronizer.pushModify(account);
}
@@ -284,7 +285,7 @@ public class EasService extends Service {
@Override
protected void onPostExecute(Void result) {
if (!mHasRestartedPing) {
- LogUtils.d(TAG, "RestartPingsTask did not start any pings.");
+ LogUtils.i(TAG, "RestartPingsTask did not start any pings.");
EasService.this.mSynchronizer.stopServiceIfIdle();
}
}
@@ -297,7 +298,7 @@ public class EasService extends Service {
@Override
public void onCreate() {
- LogUtils.d(TAG, "EasService.onCreate");
+ LogUtils.i(TAG, "EasService.onCreate");
super.onCreate();
TempDirectory.setTempDirectory(this);
EmailContent.init(this);
@@ -319,6 +320,7 @@ public class EasService extends Service {
@Override
public void onDestroy() {
+ LogUtils.i(TAG, "onDestroy");
mSynchronizer.stopAllPings();
}
@@ -374,9 +376,10 @@ public class EasService extends Service {
* Determine whether this account is configured with folders that are ready for push
* notifications.
* @param account The {@link Account} that we're interested in.
+ * @param context The context
* @return Whether this account needs to ping.
*/
- public boolean pingNeededForAccount(final Account account) {
+ public static boolean pingNeededForAccount(final Context context, final Account account) {
// Check account existence.
if (account == null || account.mId == Account.NO_ACCOUNT) {
LogUtils.d(TAG, "Do not ping: Account not found or not valid");
@@ -410,7 +413,7 @@ public class EasService extends Service {
final Set<String> authsToSync = getAuthoritiesToSync(amAccount, AUTHORITIES_TO_SYNC);
// If we have at least one sync-enabled content type, check for syncing mailboxes.
if (!authsToSync.isEmpty()) {
- final Cursor c = Mailbox.getMailboxesForPush(getContentResolver(), account.mId);
+ final Cursor c = Mailbox.getMailboxesForPush(context.getContentResolver(), account.mId);
if (c != null) {
try {
while (c.moveToNext()) {
diff --git a/src/com/android/exchange/service/PingSyncSynchronizer.java b/src/com/android/exchange/service/PingSyncSynchronizer.java
index 1f2f72d3..3a1f24c9 100644
--- a/src/com/android/exchange/service/PingSyncSynchronizer.java
+++ b/src/com/android/exchange/service/PingSyncSynchronizer.java
@@ -95,15 +95,20 @@ public class PingSyncSynchronizer {
/**
* This class handles bookkeeping for a single account.
*/
- private static class AccountSyncState {
+ private class AccountSyncState {
/** The currently running {@link PingTask}, or null if we aren't in the middle of a Ping. */
private PingTask mPingTask;
+ // Values for mPushEnabled.
+ public static final int PUSH_UNKNOWN = 0;
+ public static final int PUSH_ENABLED = 1;
+ public static final int PUSH_DISABLED = 2;
+
/**
* Tracks whether this account wants to get push notifications, based on calls to
* {@link #pushModify} and {@link #pushStop} (i.e. it tracks the last requested push state).
*/
- private boolean mPushEnabled;
+ private int mPushEnabled;
/**
* The number of syncs that are blocked waiting for the current operation to complete.
@@ -115,9 +120,12 @@ public class PingSyncSynchronizer {
/** The condition on which to block syncs that need to wait. */
private Condition mCondition;
- public AccountSyncState(final Lock lock ) {
+ public AccountSyncState(final Lock lock) {
mPingTask = null;
- mPushEnabled = false;
+ // We don't yet have enough information to know whether or not push should be enabled.
+ // We need to look up the account and it's folders, which won't yet exist for a newly
+ // created account.
+ mPushEnabled = PUSH_UNKNOWN;
mSyncCount = 0;
mCondition = lock.newCondition();
}
@@ -155,17 +163,22 @@ public class PingSyncSynchronizer {
final PingSyncSynchronizer synchronizer) {
--mSyncCount;
if (mSyncCount > 0) {
- LogUtils.d(TAG, "PSS Signalling a pending sync to proceed.");
+ LogUtils.i(TAG, "PSS Signalling a pending sync to proceed.");
mCondition.signal();
return false;
} else {
- if (mPushEnabled) {
+ if (mPushEnabled == PUSH_UNKNOWN) {
+ LogUtils.i(TAG, "PSS push enabled is unknown");
+ mPushEnabled = (EasService.pingNeededForAccount(mService, account) ?
+ PUSH_ENABLED : PUSH_DISABLED);
+ }
+ if (mPushEnabled == PUSH_ENABLED) {
if (lastSyncHadError) {
- LogUtils.d(TAG, "PSS last sync had error.");
+ LogUtils.i(TAG, "PSS last sync had error.");
scheduleDelayedPing(synchronizer.getContext(), account);
return true;
} else {
- LogUtils.d(TAG, "PSS last sync succeeded.");
+ LogUtils.i(TAG, "PSS last sync succeeded.");
final android.accounts.Account amAccount =
new android.accounts.Account(account.mEmailAddress,
Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE);
@@ -176,7 +189,7 @@ public class PingSyncSynchronizer {
}
}
}
- LogUtils.d(TAG, "PSS no push enabled.");
+ LogUtils.i(TAG, "PSS no push enabled.");
return true;
}
@@ -191,8 +204,16 @@ public class PingSyncSynchronizer {
mCondition.signal();
return false;
} else {
- if (mPushEnabled) {
- LogUtils.d(TAG, "PSS pingEnd, starting new ping.");
+ if (mPushEnabled == PUSH_ENABLED || mPushEnabled == PUSH_UNKNOWN) {
+ if (mPushEnabled == PUSH_UNKNOWN) {
+ // This should not occur. If mPushEnabled is unknown, we should not
+ // have started a ping. Still, we'd rather err on the side of restarting
+ // the ping, so log an error and request a new ping. Eventually we should
+ // do a sync, and then we'll correctly initialize mPushEnabled in
+ // syncEnd().
+ LogUtils.e(TAG, "PSS pingEnd, with mPushEnabled UNKNOWN?");
+ }
+ LogUtils.i(TAG, "PSS pingEnd, starting new ping.");
/**
* This situation only arises if we encountered some sort of error that
* stopped our ping but not due to a sync interruption. In this scenario
@@ -208,7 +229,7 @@ public class PingSyncSynchronizer {
private void scheduleDelayedPing(final Context context,
final Account account) {
- LogUtils.d(TAG, "PSS Scheduling a delayed ping.");
+ LogUtils.i(TAG, "PSS Scheduling a delayed ping.");
final Intent intent = new Intent(context, EasService.class);
intent.setAction(Eas.EXCHANGE_SERVICE_INTENT_ACTION);
intent.putExtra(EasService.EXTRA_START_PING, true);
@@ -226,8 +247,8 @@ public class PingSyncSynchronizer {
* Modifies or starts a ping for this account if no syncs are running.
*/
public void pushModify(final Account account, final PingSyncSynchronizer synchronizer) {
- LogUtils.d(LogUtils.TAG, "PSS pushModify");
- mPushEnabled = true;
+ LogUtils.i(LogUtils.TAG, "PSS pushModify");
+ mPushEnabled = PUSH_ENABLED;
final android.accounts.Account amAccount =
new android.accounts.Account(account.mEmailAddress,
Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE);
@@ -254,8 +275,8 @@ public class PingSyncSynchronizer {
* Stop the currently running ping.
*/
public void pushStop() {
- LogUtils.d(LogUtils.TAG, "PSS pushStop");
- mPushEnabled = false;
+ LogUtils.i(LogUtils.TAG, "PSS pushStop");
+ mPushEnabled = PUSH_DISABLED;
if (mPingTask != null) {
mPingTask.stop();
}