Merge "Add additional test for likely NAT timeout" into froyo

This commit is contained in:
Marc Blank 2010-04-23 12:42:30 -07:00 committed by Android (Google) Code Review
commit de3ae17246

View File

@ -1477,7 +1477,7 @@ public class EasSyncService extends AbstractSyncService {
} }
} }
void pushFallback(long mailboxId) { private void pushFallback(long mailboxId) {
Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId);
if (mailbox == null) { if (mailbox == null) {
return; return;
@ -1494,7 +1494,22 @@ public class EasSyncService extends AbstractSyncService {
SyncManager.kick("push fallback"); SyncManager.kick("push fallback");
} }
void runPingLoop() throws IOException, StaleFolderListException { /**
* Simplistic attempt to determine a NAT timeout, based on experience with various carriers
* and networks. The strings "reset by peer" and "broken pipe" are very common in these
* situations, so we look for them specifically (sans the b in broken, in case it's lowercase)
* @param message
* @return whether this message is likely associated with a NAT failure
*/
private boolean isLikelyNatFailure(String message) {
if (message == null) return false;
if (message.contains("reset by peer") || message.contains("roken pipe")) {
return true;
}
return false;
}
private void runPingLoop() throws IOException, StaleFolderListException {
int pingHeartbeat = mPingHeartbeat; int pingHeartbeat = mPingHeartbeat;
userLog("runPingLoop"); userLog("runPingLoop");
// Do push for all sync services here // Do push for all sync services here
@ -1647,7 +1662,7 @@ public class EasSyncService extends AbstractSyncService {
if (mPostReset) { if (mPostReset) {
// Nothing to do in this case; this is SyncManager telling us to try another // Nothing to do in this case; this is SyncManager telling us to try another
// ping. // ping.
} else if (mPostAborted || (hasMessage && message.contains("reset by peer"))) { } else if (mPostAborted || isLikelyNatFailure(message)) {
long pingLength = SystemClock.elapsedRealtime() - pingTime; long pingLength = SystemClock.elapsedRealtime() - pingTime;
if ((pingHeartbeat > PING_MIN_HEARTBEAT) && if ((pingHeartbeat > PING_MIN_HEARTBEAT) &&
(pingHeartbeat > mPingHighWaterMark)) { (pingHeartbeat > mPingHighWaterMark)) {
@ -1668,7 +1683,7 @@ public class EasSyncService extends AbstractSyncService {
userLog("Abort or NAT type return < 2 seconds; throwing IOException"); userLog("Abort or NAT type return < 2 seconds; throwing IOException");
throw e; throw e;
} else { } else {
userLog("NAT type IOException > 2 seconds?"); userLog("NAT type IOException");
} }
} else { } else {
throw e; throw e;
@ -1703,7 +1718,7 @@ public class EasSyncService extends AbstractSyncService {
mPingHeartbeat = pingHeartbeat; mPingHeartbeat = pingHeartbeat;
} }
void sleep(long ms, boolean runAsleep) { private void sleep(long ms, boolean runAsleep) {
if (runAsleep) { if (runAsleep) {
SyncManager.runAsleep(mMailboxId, ms+(5*SECONDS)); SyncManager.runAsleep(mMailboxId, ms+(5*SECONDS));
} }