From 89ab89dd83764a5dadc4725c92759fa6cc7244d2 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 7 Jan 2010 11:58:03 -0800 Subject: [PATCH] Make sure protocol version is always set in sync services * A recent change caused an issue in which protocolVersion could be null, resulting in an NPE * Ensure that protocolVersion is always set to a valid version, defaulting to 2.5 Bug: 2353859 Change-Id: I6e07ba3df5362c988658e401bebc1776a6780876 --- src/com/android/exchange/EasSyncService.java | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java index cd255ee21..418b1ea68 100644 --- a/src/com/android/exchange/EasSyncService.java +++ b/src/com/android/exchange/EasSyncService.java @@ -91,6 +91,9 @@ public class EasSyncService extends AbstractSyncService { static private final String PING_COMMAND = "Ping"; static private final int COMMAND_TIMEOUT = 20*SECONDS; + // Define our default protocol version as 2.5 (Exchange 2003) + static private final String DEFAULT_PROTOCOL_VERSION = "2.5"; + /** * We start with an 8 minute timeout, and increase/decrease by 3 minutes at a time. There's * no point having a timeout shorter than 5 minutes, I think; at that point, we can just let @@ -119,7 +122,7 @@ public class EasSyncService extends AbstractSyncService { static private final int PING_FALLBACK_PIM = 25; // Reasonable default - String mProtocolVersion = "2.5"; + public String mProtocolVersion = DEFAULT_PROTOCOL_VERSION; public Double mProtocolVersionDouble; protected String mDeviceId = null; private String mDeviceType = "Android"; @@ -557,7 +560,7 @@ public class EasSyncService extends AbstractSyncService { SyncManager.kick("change ping boxes to push"); } - // Determine our protocol version, if we haven't already + // Determine our protocol version, if we haven't already and save it in the Account if (mAccount.mProtocolVersion == null) { userLog("Determine EAS protocol version"); HttpResponse resp = sendHttpClientOptions(); @@ -574,6 +577,10 @@ public class EasSyncService extends AbstractSyncService { } mProtocolVersionDouble = Double.parseDouble(mProtocolVersion); mAccount.mProtocolVersion = mProtocolVersion; + // Save the protocol version + cv.clear(); + cv.put(Account.PROTOCOL_VERSION, mProtocolVersion); + mAccount.update(mContext, cv); userLog(versions); userLog("Using version ", mProtocolVersion); } else { @@ -588,7 +595,7 @@ public class EasSyncService extends AbstractSyncService { // Change all pushable boxes to push when we start the account mailbox if (mAccount.mSyncInterval == Account.CHECK_INTERVAL_PUSH) { - cv = new ContentValues(); + cv.clear(); cv.put(Mailbox.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PUSH); if (mContentResolver.update(Mailbox.CONTENT_URI, cv, SyncManager.WHERE_IN_ACCOUNT_AND_PUSHABLE, @@ -623,7 +630,7 @@ public class EasSyncService extends AbstractSyncService { } // Change all push/hold boxes to push - cv = new ContentValues(); + cv.clear(); cv.put(Mailbox.SYNC_INTERVAL, Account.CHECK_INTERVAL_PUSH); if (mContentResolver.update(Mailbox.CONTENT_URI, cv, WHERE_PUSH_HOLD_NOT_ACCOUNT_MAILBOX, @@ -1101,11 +1108,13 @@ public class EasSyncService extends AbstractSyncService { mUserName = ha.mLogin; mPassword = ha.mPassword; - // Set up our protocol version + // Set up our protocol version from the Account mProtocolVersion = mAccount.mProtocolVersion; - if (mProtocolVersion != null) { - mProtocolVersionDouble = Double.parseDouble(mProtocolVersion); + // If it hasn't been set up, start with default version + if (mProtocolVersion == null) { + mProtocolVersion = DEFAULT_PROTOCOL_VERSION; } + mProtocolVersionDouble = Double.parseDouble(mProtocolVersion); return true; }