summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Ping Hu <yph@google.com>2013-10-17 19:27:29 -0700
committerThe Android Automerger <android-build@google.com>2013-10-18 14:48:58 -0700
commitc46009b0605f5d84163b9ff0821091577d9815d0 (patch)
tree8c15d5fa40d31ca40b5dfd78868c1bc59f1701f9
parent64b7751d235116f29ffd2b915f9abe057e45333a (diff)
downloadExchange-c46009b0605f5d84163b9ff0821091577d9815d0.tar.gz
Handle all possible exits of the PingTask.
- If we get an exception, reschedule the ping instead of just dying. - If the task was cancelled, also reschedule. Bug: 11249423 Change-Id: I74a39e04de73659d58f1c53b238f8a40f15d6849
-rw-r--r--src/com/android/exchange/service/PingTask.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/com/android/exchange/service/PingTask.java b/src/com/android/exchange/service/PingTask.java
index 87a7b8e9..768727c8 100644
--- a/src/com/android/exchange/service/PingTask.java
+++ b/src/com/android/exchange/service/PingTask.java
@@ -18,12 +18,13 @@ package com.android.exchange.service;
import android.content.Context;
import android.os.AsyncTask;
-import android.util.Log;
import com.android.emailcommon.provider.Account;
import com.android.exchange.Eas;
import com.android.exchange.adapter.PingParser;
+import com.android.exchange.eas.EasOperation;
import com.android.exchange.eas.EasPing;
+import com.android.mail.utils.LogUtils;
/**
* Thread management class for Ping operations.
@@ -58,15 +59,32 @@ public class PingTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
- Log.i(TAG, "Ping task starting");
+ LogUtils.i(TAG, "Ping task starting for %d", mOperation.getAccountId());
int pingStatus;
- do {
- pingStatus = mOperation.doPing();
- } while (PingParser.shouldPingAgain(pingStatus));
- Log.i(TAG, "Ping task ending with status: " + pingStatus);
+ try {
+ do {
+ pingStatus = mOperation.doPing();
+ } while (PingParser.shouldPingAgain(pingStatus));
+ } catch (final Exception e) {
+ // TODO: This is hacky, try to be cleaner.
+ // If we get any sort of exception here, treat it like the ping returned a connection
+ // failure.
+ LogUtils.e(TAG, e, "Ping exception for account %d", mOperation.getAccountId());
+ pingStatus = EasOperation.RESULT_REQUEST_FAILURE;
+ }
+ LogUtils.i(TAG, "Ping task ending with status: %d", pingStatus);
mSyncHandlerMap.pingComplete(mOperation.getAmAccount(), mOperation.getAccountId(),
pingStatus);
return null;
}
+
+ @Override
+ protected void onCancelled (Void result) {
+ // TODO: This is also hacky, should have a separate result code at minimum.
+ // If the ping is cancelled, make sure it reports something to the sync adapter.
+ LogUtils.w(TAG, "Ping cancelled for %d", mOperation.getAccountId());
+ mSyncHandlerMap.pingComplete(mOperation.getAmAccount(), mOperation.getAccountId(),
+ EasOperation.RESULT_REQUEST_FAILURE);
+ }
}