From bc278948153cca54506aa5e8bcfcdd56c72932ac Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 21 Apr 2010 15:56:41 -0700 Subject: [PATCH] Add additional test for likely NAT timeout * This prevents unnecessary delays in receiving push mail * At present, there is a likely 5 minute delay on receiving new pushed mail on the network displaying the behavior we're testing for Bug: 2615293 Change-Id: Ic42e576fa683790f96434fcbad5ee873d0730f6d --- src/com/android/exchange/EasSyncService.java | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index 4399d50f6..ef89ff819 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -1477,7 +1477,7 @@ public class EasSyncService extends AbstractSyncService { } } - void pushFallback(long mailboxId) { + private void pushFallback(long mailboxId) { Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); if (mailbox == null) { return; @@ -1494,7 +1494,22 @@ public class EasSyncService extends AbstractSyncService { 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; userLog("runPingLoop"); // Do push for all sync services here @@ -1647,7 +1662,7 @@ public class EasSyncService extends AbstractSyncService { if (mPostReset) { // Nothing to do in this case; this is SyncManager telling us to try another // ping. - } else if (mPostAborted || (hasMessage && message.contains("reset by peer"))) { + } else if (mPostAborted || isLikelyNatFailure(message)) { long pingLength = SystemClock.elapsedRealtime() - pingTime; if ((pingHeartbeat > PING_MIN_HEARTBEAT) && (pingHeartbeat > mPingHighWaterMark)) { @@ -1668,7 +1683,7 @@ public class EasSyncService extends AbstractSyncService { userLog("Abort or NAT type return < 2 seconds; throwing IOException"); throw e; } else { - userLog("NAT type IOException > 2 seconds?"); + userLog("NAT type IOException"); } } else { throw e; @@ -1703,7 +1718,7 @@ public class EasSyncService extends AbstractSyncService { mPingHeartbeat = pingHeartbeat; } - void sleep(long ms, boolean runAsleep) { + private void sleep(long ms, boolean runAsleep) { if (runAsleep) { SyncManager.runAsleep(mMailboxId, ms+(5*SECONDS)); }