summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Christie <dnchrist@google.com> 2016-08-25 01:25:30 +0000
committer android-build-merger <android-build-merger@google.com> 2016-08-25 01:25:30 +0000
commitae6bd11a4bfb031a53e16e929c2e761035e18a2c (patch)
tree5145fbc12f3c224db6d6c30c6e12b8d1964e3138
parent02e54d3c6ad989e8e1463ea5fc32ed9dfa1de19d (diff)
parent36246a43e54503e5be6b52ce9dcb08c8b1388bf5 (diff)
resolve merge conflicts of 8aaffd9 to nyc-dev
am: 36246a43e5 Change-Id: Ic91baff73ef9e5ffe304d10a5a55e8476dfcfecb
-rw-r--r--services/core/java/com/android/server/location/GpsXtraDownloader.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/location/GpsXtraDownloader.java b/services/core/java/com/android/server/location/GpsXtraDownloader.java
index c464371bf16a..bf7798591c67 100644
--- a/services/core/java/com/android/server/location/GpsXtraDownloader.java
+++ b/services/core/java/com/android/server/location/GpsXtraDownloader.java
@@ -22,6 +22,10 @@ import android.util.Log;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@@ -37,6 +41,7 @@ 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 static final int CONNECTION_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(30);
@@ -124,7 +129,19 @@ public class GpsXtraDownloader {
return null;
}
- return Streams.readFully(connection.getInputStream());
+ 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();
+ }
} catch (IOException ioe) {
if (DEBUG) Log.d(TAG, "Error downloading gps XTRA: ", ioe);
} finally {
@@ -136,3 +153,4 @@ public class GpsXtraDownloader {
}
}
+