Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f86f0e18 authored by Tsuwei Chen's avatar Tsuwei Chen
Browse files

Set user agent for XTRA download according to carrier specification.

Bug: 17056380
Change-Id: Iacb90d4780f35fa6875702889d4a5f02610768b7
parent 08ff5c14
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -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 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
    private static final String DEFAULT_USER_AGENT = "Android";

    private Context mContext;
    private String[] mXtraServers;
    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;
@@ -61,8 +64,17 @@ public class GpsXtraDownloader {
        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];
@@ -104,13 +116,14 @@ public class GpsXtraDownloader {
        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) {