OSDN Git Service

resolve merge conflicts of 1081a15 to lmp-mr1-ub-dev
authorDavid Christie <dnchrist@google.com>
Tue, 23 Aug 2016 23:19:51 +0000 (16:19 -0700)
committerDavid Christie <dnchrist@google.com>
Tue, 23 Aug 2016 23:19:51 +0000 (16:19 -0700)
Change-Id: Ic44c577ef364bf81dd1e30b50c71718d4910eb10

1  2 
services/core/java/com/android/server/location/GpsXtraDownloader.java

@@@ -20,11 -20,17 +20,12 @@@ import android.content.Context
  import android.text.TextUtils;
  import android.util.Log;
  
 -import org.apache.http.HttpEntity;
 -import org.apache.http.HttpHost;
 -import org.apache.http.HttpResponse;
 -import org.apache.http.StatusLine;
 -import org.apache.http.client.methods.HttpGet;
 -import org.apache.http.client.methods.HttpUriRequest;
 -import org.apache.http.conn.params.ConnRouteParams;
 +import java.net.HttpURLConnection;
 +import java.net.URL;
 +import libcore.io.IoUtils;
- import libcore.io.Streams;
  
 -import java.io.DataInputStream;
++import java.io.ByteArrayOutputStream;
++import java.io.InputStream;
  import java.io.IOException;
  import java.util.Properties;
  import java.util.Random;
@@@ -38,8 -44,10 +39,9 @@@ public class GpsXtraDownloader 
  
      private static final String TAG = "GpsXtraDownloader";
      private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+     private static final long MAXIMUM_CONTENT_LENGTH_BYTES = 1000000;  // 1MB.
      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;
                  return null;
              }
  
-             return Streams.readFully(connection.getInputStream());
 -            HttpEntity entity = response.getEntity();
 -            byte[] body = null;
 -            if (entity != null) {
 -                try {
 -                    long contentLength = entity.getContentLength();
 -                    if (contentLength > 0 && contentLength <= MAXIMUM_CONTENT_LENGTH_BYTES) {
 -                        body = new byte[(int) contentLength];
 -                        DataInputStream dis = new DataInputStream(entity.getContent());
 -                        try {
 -                            dis.readFully(body);
 -                        } finally {
 -                            try {
 -                                dis.close();
 -                            } catch (IOException e) {
 -                                Log.e(TAG, "Unexpected IOException.", e);
 -                            }
 -                        }
 -                    }
 -                } finally {
 -                    if (entity != null) {
 -                        entity.consumeContent();
++            try (InputStream in = connection.getInputStream()) {
++                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
++                byte[] buffer = new byte[1024];
++                int count;
++                while ((count = in.read(buffer)) != -1) {
++                    bytes.write(buffer, 0, count);
++                    if (bytes.size() > MAXIMUM_CONTENT_LENGTH_BYTES) {
++                        if (DEBUG) Log.d(TAG, "XTRA file too large");
++                        return null;
+                     }
+                 }
++                return bytes.toByteArray();
+             }
 -            return body;
 -        } catch (Exception e) {
 -            if (DEBUG) Log.d(TAG, "error " + e);
 +        } catch (IOException ioe) {
 +            if (DEBUG) Log.d(TAG, "Error downloading gps XTRA: ", ioe);
          } finally {
 -            if (client != null) {
 -                client.close();
 +            if (connection != null) {
 +                connection.disconnect();
              }
          }
          return null;
      }
  
  }
++