diff options
author | Tsuwei Chen <tsuwei@google.com> | 2014-09-16 09:12:59 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-09-16 09:12:59 +0000 |
commit | c695e6c289ef9389d3aef2080246b2c9b97ec242 (patch) | |
tree | dceb4cc3c1bb58a4d6d1c1f3b75144ac55c8a8a0 | |
parent | f52b71ad9e86a60ab64b3751865c186698ea8975 (diff) | |
parent | 108dee2b373b37d543a40ea0cd813ac48bee30a8 (diff) | |
download | frameworks_base-c695e6c289ef9389d3aef2080246b2c9b97ec242.zip frameworks_base-c695e6c289ef9389d3aef2080246b2c9b97ec242.tar.gz frameworks_base-c695e6c289ef9389d3aef2080246b2c9b97ec242.tar.bz2 |
am 3a85ae0b: am 85e7eafb: am 86f1d252: Merge "Set user agent for XTRA download according to carrier specification. Bug: 17056380 Change-Id: Iacb90d4780f35fa6875702889d4a5f02610768b7" into lmp-dev
* commit '3a85ae0b6a79f2ac591991c745322914f8f7376e':
Set user agent for XTRA download according to carrier specification. Bug: 17056380 Change-Id: Iacb90d4780f35fa6875702889d4a5f02610768b7
-rw-r--r-- | services/core/java/com/android/server/location/GpsXtraDownloader.java | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/location/GpsXtraDownloader.java b/services/core/java/com/android/server/location/GpsXtraDownloader.java index 9dedb35..a5eef6a 100644 --- a/services/core/java/com/android/server/location/GpsXtraDownloader.java +++ b/services/core/java/com/android/server/location/GpsXtraDownloader.java @@ -19,6 +19,7 @@ package com.android.server.location; import android.content.Context; import android.net.Proxy; import android.net.http.AndroidHttpClient; +import android.text.TextUtils; import android.util.Log; import org.apache.http.HttpEntity; @@ -42,12 +43,14 @@ import java.util.Random; public class GpsXtraDownloader { private static final String TAG = "GpsXtraDownloader"; - static final boolean DEBUG = false; - - private Context mContext; - private String[] mXtraServers; + private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); + private static final String DEFAULT_USER_AGENT = "Android"; + + private final Context mContext; + private final String[] mXtraServers; // to load balance our server requests private int mNextServerIndex; + private final String mUserAgent; GpsXtraDownloader(Context context, Properties properties) { mContext = context; @@ -60,9 +63,18 @@ public class GpsXtraDownloader { if (server1 != null) count++; if (server2 != null) count++; if (server3 != null) count++; - + + // Set User Agent from properties, if possible. + String agent = properties.getProperty("XTRA_USER_AGENT"); + if (TextUtils.isEmpty(agent)) { + mUserAgent = DEFAULT_USER_AGENT; + } else { + mUserAgent = agent; + } + if (count == 0) { Log.e(TAG, "No XTRA servers were specified in the GPS configuration"); + mXtraServers = null; return; } else { mXtraServers = new String[count]; @@ -74,7 +86,7 @@ public class GpsXtraDownloader { // randomize first server Random random = new Random(); mNextServerIndex = random.nextInt(count); - } + } } byte[] downloadXtraData() { @@ -91,7 +103,7 @@ public class GpsXtraDownloader { // load balance our requests among the available servers while (result == null) { result = doDownload(mXtraServers[mNextServerIndex], useProxy, proxyHost, proxyPort); - + // increment mNextServerIndex and wrap around if necessary mNextServerIndex++; if (mNextServerIndex == mXtraServers.length) { @@ -100,17 +112,18 @@ public class GpsXtraDownloader { // break if we have tried all the servers if (mNextServerIndex == startIndex) break; } - + return result; } - protected static byte[] doDownload(String url, boolean isProxySet, + protected byte[] doDownload(String url, boolean isProxySet, String proxyHost, int proxyPort) { if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url); AndroidHttpClient client = null; try { - client = AndroidHttpClient.newInstance("Android"); + if (DEBUG) Log.d(TAG, "XTRA user agent: " + mUserAgent); + client = AndroidHttpClient.newInstance(mUserAgent); HttpUriRequest req = new HttpGet(url); if (isProxySet) { |