Don't send device info in OPTIONS command
Bug: <need to find>
Change-Id: Ic7b8299fad70aeaff05485e675ac1882dcfbc9d1
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index 266a05f..18955a5 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -196,8 +196,12 @@
public String mProtocolVersion = Eas.DEFAULT_PROTOCOL_VERSION;
public Double mProtocolVersionDouble;
protected String mDeviceId = null;
- /*package*/ String mAuthString = null;
- /*package*/ String mCmdString = null;
+ @VisibleForTesting
+ String mAuthString = null;
+ @VisibleForTesting
+ String mUserString = null;
+ @VisibleForTesting
+ String mBaseUriString = null;
public String mHostAddress;
public String mUserName;
public String mPassword;
@@ -638,7 +642,7 @@
// Try again using the bare user name
int atSignIndex = mUserName.indexOf('@');
mUserName = mUserName.substring(0, atSignIndex);
- cacheAuthAndCmdString();
+ cacheAuthUserAndBaseUriStrings();
userLog("401 received; trying username: ", mUserName);
// Recreate the basic authentication string and reset the header
post.removeHeaders("Authorization");
@@ -690,7 +694,7 @@
mUserName = userName;
mPassword = password;
// Make sure the authentication string is recreated and cached
- cacheAuthAndCmdString();
+ cacheAuthUserAndBaseUriStrings();
// Split out the domain name
int amp = userName.indexOf('@');
@@ -1147,28 +1151,29 @@
}
/**
- * Using mUserName and mPassword, create and cache mAuthString and mCacheString, which are used
- * in all HttpPost commands. This should be called if these strings are null, or if mUserName
- * and/or mPassword are changed
+ * Using mUserName and mPassword, lazily create the strings that are commonly used in our HTTP
+ * POSTs, including the authentication header string, the base URI we use to communicate with
+ * EAS, and the user information string (user, deviceId, and deviceType)
*/
- private void cacheAuthAndCmdString() {
- String safeUserName = Uri.encode(mUserName);
- String cs = mUserName + ':' + mPassword;
- mAuthString = "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP);
- mCmdString = "&User=" + safeUserName + "&DeviceId=" + mDeviceId +
- "&DeviceType=" + DEVICE_TYPE;
+ private void cacheAuthUserAndBaseUriStrings() {
+ if (mAuthString == null || mUserString == null || mBaseUriString == null) {
+ String safeUserName = Uri.encode(mUserName);
+ String cs = mUserName + ':' + mPassword;
+ mAuthString = "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP);
+ mUserString = "&User=" + safeUserName + "&DeviceId=" + mDeviceId +
+ "&DeviceType=" + DEVICE_TYPE;
+ String scheme =
+ EmailClientConnectionManager.makeScheme(mSsl, mTrustSsl, mClientCertAlias);
+ mBaseUriString = scheme + "://" + mHostAddress + "/Microsoft-Server-ActiveSync";
+ }
}
@VisibleForTesting
String makeUriString(String cmd, String extra) {
- // Cache the authentication string and the command string
- if (mAuthString == null || mCmdString == null) {
- cacheAuthAndCmdString();
- }
- String scheme = EmailClientConnectionManager.makeScheme(mSsl, mTrustSsl, mClientCertAlias);
- String uriString = scheme + "://" + mHostAddress + "/Microsoft-Server-ActiveSync";
+ cacheAuthUserAndBaseUriStrings();
+ String uriString = mBaseUriString;
if (cmd != null) {
- uriString += "?Cmd=" + cmd + mCmdString;
+ uriString += "?Cmd=" + cmd + mUserString;
}
if (extra != null) {
uriString += extra;
@@ -1324,10 +1329,12 @@
}
protected EasResponse sendHttpClientOptions() throws IOException {
- HttpClient client = getHttpClient(COMMAND_TIMEOUT);
- String us = makeUriString("OPTIONS", null);
- HttpOptions method = new HttpOptions(URI.create(us));
+ cacheAuthUserAndBaseUriStrings();
+ // We only send user name with the OPTIONS command
+ String uriString = mBaseUriString + "&Cmd=OPTIONS&User=" + Uri.encode(mUserName);
+ HttpOptions method = new HttpOptions(URI.create(uriString));
setHeaders(method, false);
+ HttpClient client = getHttpClient(COMMAND_TIMEOUT);
return EasResponse.fromHttpRequest(getClientConnectionManager(), client, method);
}
diff --git a/tests/src/com/android/exchange/EasSyncServiceTests.java b/tests/src/com/android/exchange/EasSyncServiceTests.java
index 8b0b410..d1a5b1e 100644
--- a/tests/src/com/android/exchange/EasSyncServiceTests.java
+++ b/tests/src/com/android/exchange/EasSyncServiceTests.java
@@ -17,17 +17,17 @@
package com.android.exchange;
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Base64;
+
import com.android.emailcommon.provider.Account;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Base64;
-
import java.io.IOException;
/**
@@ -109,13 +109,13 @@
String uriString = svc.makeUriString("OPTIONS", null);
// These next two should now be cached
assertNotNull(svc.mAuthString);
- assertNotNull(svc.mCmdString);
+ assertNotNull(svc.mUserString);
assertEquals("Basic " + Base64.encodeToString((USER+":"+PASSWORD).getBytes(),
Base64.NO_WRAP), svc.mAuthString);
assertEquals("&User=" + USER + "&DeviceId=" + ID + "&DeviceType=" +
- EasSyncService.DEVICE_TYPE, svc.mCmdString);
- assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=OPTIONS" +
- svc.mCmdString, uriString);
+ EasSyncService.DEVICE_TYPE, svc.mUserString);
+ assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync", svc.mBaseUriString);
+ assertEquals(svc.mBaseUriString + "?Cmd=OPTIONS" + svc.mUserString, uriString);
// User name that requires encoding
String user = "name_with_underscore@foo%bar.com";
svc = setupService(user);
@@ -124,9 +124,9 @@
Base64.NO_WRAP), svc.mAuthString);
String safeUserName = "name_with_underscore%40foo%25bar.com";
assertEquals("&User=" + safeUserName + "&DeviceId=" + ID + "&DeviceType=" +
- EasSyncService.DEVICE_TYPE, svc.mCmdString);
+ EasSyncService.DEVICE_TYPE, svc.mUserString);
assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=OPTIONS" +
- svc.mCmdString, uriString);
+ svc.mUserString, uriString);
}
public void testResetHeartbeats() {