summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Ping Hu <yph@google.com>2014-02-20 17:19:16 -0800
committerYu Ping Hu <yph@google.com>2014-03-04 18:27:14 +0000
commit68489d7184f6e008364b4ebb6130e3e2e703a433 (patch)
treec41be3f0a6a039efc5177d91de4834b4b4ee530a
parentd1a58bafb5b5e2920bb3c5a88a9539883f7eb786 (diff)
downloadExchange-68489d7184f6e008364b4ebb6130e3e2e703a433.tar.gz
EasService fixes & improvements.
- Make sure to call EmailContent.init. - Add function to determine if an account needs to ping. This is currently unused but will be necessary later. - Track the last ping/not ping status in PingSyncSynchronizer. This is used to know whether to restart a ping, rather than expecting the EasService to pass this in. (NOTE: This CP was missed from exchange branch initially, but some of the diffs got applied in another way.) Change-Id: Ibb0aa45cf5174ea5dd3ba6210104a25e9060dcf8
-rw-r--r--src/com/android/exchange/service/EasService.java3
-rw-r--r--src/com/android/exchange/service/PingSyncSynchronizer.java27
-rw-r--r--src/com/android/exchange/service/PingTask.java6
3 files changed, 20 insertions, 16 deletions
diff --git a/src/com/android/exchange/service/EasService.java b/src/com/android/exchange/service/EasService.java
index 45c93f28..41aa48c5 100644
--- a/src/com/android/exchange/service/EasService.java
+++ b/src/com/android/exchange/service/EasService.java
@@ -242,8 +242,7 @@ public class EasService extends Service {
try {
return operation.performOperation();
} finally {
- // TODO: Fix pushEnabled param
- mSynchronizer.syncEnd(accountId, false);
+ mSynchronizer.syncEnd(accountId);
}
}
diff --git a/src/com/android/exchange/service/PingSyncSynchronizer.java b/src/com/android/exchange/service/PingSyncSynchronizer.java
index 461e05e9..7871f0f2 100644
--- a/src/com/android/exchange/service/PingSyncSynchronizer.java
+++ b/src/com/android/exchange/service/PingSyncSynchronizer.java
@@ -79,6 +79,12 @@ public class PingSyncSynchronizer {
private PingTask mPingTask;
/**
+ * 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;
+
+ /**
* The number of syncs that are blocked waiting for the current operation to complete.
* Unlike Pings, sync operations do not start their own tasks and are assumed to run in
* whatever thread calls into this class.
@@ -94,6 +100,7 @@ public class PingSyncSynchronizer {
*/
public AccountSyncState(final Lock lock) {
mPingTask = null;
+ mPushEnabled = false;
mSyncCount = 0;
mCondition = lock.newCondition();
}
@@ -125,17 +132,16 @@ public class PingSyncSynchronizer {
/**
* Update bookkeeping when a sync completes. This includes signaling pending ops to
* go ahead, or starting the ping if appropriate and there are no waiting ops.
- * @param pushEnabled Whether this account is configured for push.
* @return Whether this account is now idle.
*/
- public boolean syncEnd(final boolean pushEnabled) {
+ public boolean syncEnd() {
--mSyncCount;
if (mSyncCount > 0) {
LogUtils.d(TAG, "Signalling a pending sync to proceed.");
mCondition.signal();
return false;
} else {
- if (pushEnabled) {
+ if (mPushEnabled) {
// TODO: Start the ping task
return false;
}
@@ -145,16 +151,15 @@ public class PingSyncSynchronizer {
/**
* Update bookkeeping when the ping task terminates, including signaling any waiting ops.
- * @param pushEnabled Whether this account is configured for push.
* @return Whether this account is now idle.
*/
- public boolean pingEnd(final boolean pushEnabled) {
+ public boolean pingEnd() {
mPingTask = null;
if (mSyncCount > 0) {
mCondition.signal();
return false;
} else {
- if (pushEnabled) {
+ if (mPushEnabled) {
// TODO: request a push-only sync.
return false;
}
@@ -166,6 +171,7 @@ public class PingSyncSynchronizer {
* Modifies or starts a ping for this account if no syncs are running.
*/
public void pushModify() {
+ mPushEnabled = true;
if (mSyncCount == 0) {
if (mPingTask == null) {
// No ping, no running syncs -- start a new ping.
@@ -183,6 +189,7 @@ public class PingSyncSynchronizer {
* Stop the currently running ping.
*/
public void pushStop() {
+ mPushEnabled = false;
if (mPingTask != null) {
mPingTask.stop();
}
@@ -263,7 +270,7 @@ public class PingSyncSynchronizer {
}
}
- public void syncEnd(final long accountId, final boolean pushEnabled) {
+ public void syncEnd(final long accountId) {
mLock.lock();
try {
LogUtils.d(TAG, "PSS syncEnd for account %d", accountId);
@@ -272,7 +279,7 @@ public class PingSyncSynchronizer {
LogUtils.w(TAG, "PSS syncEnd for account %d but no state found", accountId);
return;
}
- if (accountState.syncEnd(pushEnabled)) {
+ if (accountState.syncEnd()) {
removeAccount(accountId);
}
} finally {
@@ -280,7 +287,7 @@ public class PingSyncSynchronizer {
}
}
- public void pingEnd(final long accountId, final boolean pushEnabled) {
+ public void pingEnd(final long accountId) {
mLock.lock();
try {
LogUtils.d(TAG, "PSS pingEnd for account %d", accountId);
@@ -289,7 +296,7 @@ public class PingSyncSynchronizer {
LogUtils.w(TAG, "PSS pingEnd for account %d but no state found", accountId);
return;
}
- if (accountState.pingEnd(pushEnabled)) {
+ if (accountState.pingEnd()) {
removeAccount(accountId);
}
} finally {
diff --git a/src/com/android/exchange/service/PingTask.java b/src/com/android/exchange/service/PingTask.java
index a016556b..98b71f43 100644
--- a/src/com/android/exchange/service/PingTask.java
+++ b/src/com/android/exchange/service/PingTask.java
@@ -91,8 +91,7 @@ public class PingTask extends AsyncTask<Void, Void, Void> {
mSyncHandlerMap.pingComplete(mOperation.getAmAccount(), mOperation.getAccountId(),
pingStatus);
} else {
- // TODO: Fix the pushEnabled param.
- mPingSyncSynchronizer.pingEnd(mOperation.getAccountId(), false);
+ mPingSyncSynchronizer.pingEnd(mOperation.getAccountId());
}
return null;
}
@@ -106,8 +105,7 @@ public class PingTask extends AsyncTask<Void, Void, Void> {
mSyncHandlerMap.pingComplete(mOperation.getAmAccount(), mOperation.getAccountId(),
EasOperation.RESULT_REQUEST_FAILURE);
} else {
- // TODO: Fix the pushEnabled param.
- mPingSyncSynchronizer.pingEnd(mOperation.getAccountId(), false);
+ mPingSyncSynchronizer.pingEnd(mOperation.getAccountId());
}
}
}