Merge "Change EAS User-Agent to a constant String"

This commit is contained in:
Marc Blank 2010-08-31 16:31:11 -07:00 committed by Android (Google) Code Review
commit 70047f73d3
2 changed files with 10 additions and 10 deletions

View File

@ -179,11 +179,14 @@ public class EasSyncService extends AbstractSyncService {
// The EAS protocol Provision status meaning "we partially implement the policies"
static private final String PROVISION_STATUS_PARTIAL = "2";
static /*package*/ final String DEVICE_TYPE = "Android";
static private final String USER_AGENT = DEVICE_TYPE + '/' + Build.VERSION.RELEASE + '-' +
Eas.CLIENT_VERSION;
// Reasonable default
public String mProtocolVersion = Eas.DEFAULT_PROTOCOL_VERSION;
public Double mProtocolVersionDouble;
protected String mDeviceId = null;
/*package*/ String mDeviceType = "Android";
/*package*/ String mAuthString = null;
/*package*/ String mCmdString = null;
public String mHostAddress;
@ -1179,7 +1182,7 @@ public class EasSyncService extends AbstractSyncService {
String cs = mUserName + ':' + mPassword;
mAuthString = "Basic " + Base64.encodeToString(cs.getBytes(), Base64.NO_WRAP);
mCmdString = "&User=" + safeUserName + "&DeviceId=" + mDeviceId +
"&DeviceType=" + mDeviceType;
"&DeviceType=" + DEVICE_TYPE;
}
/*package*/ String makeUriString(String cmd, String extra) throws IOException {
@ -1207,8 +1210,7 @@ public class EasSyncService extends AbstractSyncService {
method.setHeader("Authorization", mAuthString);
method.setHeader("MS-ASProtocolVersion", mProtocolVersion);
method.setHeader("Connection", "keep-alive");
method.setHeader("User-Agent", mDeviceType + '-' + Build.VERSION.RELEASE + '/' +
Eas.CLIENT_VERSION);
method.setHeader("User-Agent", USER_AGENT);
if (usePolicyKey) {
// If there's an account in existence, use its key; otherwise (we're creating the
// account), send "0". The server will respond with code 449 if there are policies

View File

@ -40,7 +40,6 @@ public class EasSyncServiceTests extends AndroidTestCase {
static private final String PASSWORD = "password";
static private final String HOST = "xxx.host.zzz";
static private final String ID = "id";
static private final String TYPE = "type";
Context mMockContext;
@ -97,7 +96,6 @@ public class EasSyncServiceTests extends AndroidTestCase {
EasSyncService svc = new EasSyncService();
svc.mAuthString = "auth";
svc.mProtocolVersion = "12.1";
svc.mDeviceType = "android";
svc.mAccount = null;
// With second argument false, there should be no header
svc.setHeaders(method, false);
@ -143,7 +141,6 @@ public class EasSyncServiceTests extends AndroidTestCase {
svc.mUserName = user;
svc.mPassword = PASSWORD;
svc.mDeviceId = ID;
svc.mDeviceType = TYPE;
svc.mHostAddress = HOST;
return svc;
}
@ -157,7 +154,8 @@ public class EasSyncServiceTests extends AndroidTestCase {
assertNotNull(svc.mCmdString);
assertEquals("Basic " + Base64.encodeToString((USER+":"+PASSWORD).getBytes(),
Base64.NO_WRAP), svc.mAuthString);
assertEquals("&User=" + USER + "&DeviceId=" + ID + "&DeviceType=" + TYPE, svc.mCmdString);
assertEquals("&User=" + USER + "&DeviceId=" + ID + "&DeviceType=" +
EasSyncService.DEVICE_TYPE, svc.mCmdString);
assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=OPTIONS" +
svc.mCmdString, uriString);
// User name that requires encoding
@ -167,8 +165,8 @@ public class EasSyncServiceTests extends AndroidTestCase {
assertEquals("Basic " + Base64.encodeToString((user+":"+PASSWORD).getBytes(),
Base64.NO_WRAP), svc.mAuthString);
String safeUserName = "name_with_underscore%40foo%25bar.com";
assertEquals("&User=" + safeUserName + "&DeviceId=" + ID + "&DeviceType=" + TYPE,
svc.mCmdString);
assertEquals("&User=" + safeUserName + "&DeviceId=" + ID + "&DeviceType=" +
EasSyncService.DEVICE_TYPE, svc.mCmdString);
assertEquals("https://" + HOST + "/Microsoft-Server-ActiveSync?Cmd=OPTIONS" +
svc.mCmdString, uriString);
}