Add timeout for XTRA data connection.
b/22540683
The timeout in the XTRA data connection prevents it from keeping a
wake-lock held indefinitely if the connection is dropped.
Change-Id: Id14c780ddbcb42f764ae0565765e222013f56ab3
diff --git a/services/core/java/com/android/server/location/GpsXtraDownloader.java b/services/core/java/com/android/server/location/GpsXtraDownloader.java
index 3585049..c464371 100644
--- a/services/core/java/com/android/server/location/GpsXtraDownloader.java
+++ b/services/core/java/com/android/server/location/GpsXtraDownloader.java
@@ -19,13 +19,14 @@
import android.text.TextUtils;
import android.util.Log;
+import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
-import libcore.io.Streams;
-
-import java.io.IOException;
import java.util.Properties;
import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+import libcore.io.Streams;
/**
* A class for downloading GPS XTRA data.
@@ -37,6 +38,7 @@
private static final String TAG = "GpsXtraDownloader";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private static final String DEFAULT_USER_AGENT = "Android";
+ private static final int CONNECTION_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(30);
private final String[] mXtraServers;
// to load balance our server requests
@@ -113,6 +115,7 @@
connection.setRequestProperty(
"x-wap-profile",
"http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#");
+ connection.setConnectTimeout(CONNECTION_TIMEOUT_MS);
connection.connect();
int statusCode = connection.getResponseCode();