am 719610ab: am 42e5dca4: Add sanity checks in SyncManager and EasSyncService

Merge commit '719610ab8faee6a0c0ed4ff748cd1eeec3459fa6'

* commit '719610ab8faee6a0c0ed4ff748cd1eeec3459fa6':
  Add sanity checks in SyncManager and EasSyncService
This commit is contained in:
Marc Blank 2009-12-18 16:50:58 -08:00 committed by Android Git Automerger
commit 320a065b6b
2 changed files with 19 additions and 5 deletions

View File

@ -141,12 +141,22 @@ public class EasSyncService extends AbstractSyncService {
// Whether we've ever lowered the heartbeat
private boolean mPingHeartbeatDropped = false;
// Whether a POST was aborted due to watchdog timeout
private boolean mAborted = false;
private boolean mPostAborted = false;
// Whether or not the sync service is valid (usable)
public boolean mIsValid = true;
public EasSyncService(Context _context, Mailbox _mailbox) {
super(_context, _mailbox);
mContentResolver = _context.getContentResolver();
if (mAccount == null) {
mIsValid = false;
return;
}
HostAuth ha = HostAuth.restoreHostAuthWithId(_context, mAccount.mHostAuthKeyRecv);
if (ha == null) {
mIsValid = false;
return;
}
mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0;
mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES) != 0;
}
@ -165,7 +175,7 @@ public class EasSyncService extends AbstractSyncService {
synchronized(getSynchronizer()) {
if (mPendingPost != null) {
userLog("Aborting pending POST!");
mAborted = true;
mPostAborted = true;
mPendingPost.abort();
}
}
@ -816,7 +826,7 @@ public class EasSyncService extends AbstractSyncService {
// haven't yet "fixed" the timeout, back off by two minutes and "fix" it
boolean hasMessage = message != null;
userLog("IOException runPingLoop: " + (hasMessage ? message : "[no message]"));
if (mAborted || (hasMessage && message.contains("reset by peer"))) {
if (mPostAborted || (hasMessage && message.contains("reset by peer"))) {
long pingLength = SystemClock.elapsedRealtime() - pingTime;
if ((pingHeartbeat > PING_MIN_HEARTBEAT) &&
(pingHeartbeat > mPingHighWaterMark)) {
@ -826,7 +836,7 @@ public class EasSyncService extends AbstractSyncService {
pingHeartbeat = PING_MIN_HEARTBEAT;
}
userLog("Decreased ping heartbeat to ", pingHeartbeat, "s");
} else if (mAborted || (pingLength < 2000)) {
} else if (mPostAborted || (pingLength < 2000)) {
userLog("Abort or NAT type return < 2 seconds; throwing IOException");
throw e;
} else {

View File

@ -1336,6 +1336,7 @@ public class SyncManager extends Service implements Runnable {
AbstractSyncService service = mServiceMap.get(m.mId);
if (service == null) {
service = new EasSyncService(this, m);
if (!((EasSyncService)service).mIsValid) return;
service.mSyncReason = reason;
if (req != null) {
service.addPartRequest(req);
@ -1534,7 +1535,10 @@ public class SyncManager extends Service implements Runnable {
// If so, stop them or remove them from the map
for (Long mailboxId: deletedMailboxes) {
AbstractSyncService svc = mServiceMap.get(mailboxId);
if (svc != null) {
if (svc == null || svc.mThread == null) {
releaseMailbox(mailboxId);
continue;
} else {
boolean alive = svc.mThread.isAlive();
log("Deleted mailbox: " + svc.mMailboxName);
if (alive) {