summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2014-10-09 19:11:11 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-10-09 19:11:11 +0000
commitd25b996a7ab2589f258d0006dda6589f53d98366 (patch)
treee6d66ab7b804b6b1fc5e9247c51950705be2ffa7 /media
parentf857b272c27ca6836b5cec51a9f3714603aa2ad0 (diff)
parenta6ae8ba4a59f3f893fe8893335e7517388123c10 (diff)
downloadframeworks_base-d25b996a7ab2589f258d0006dda6589f53d98366.zip
frameworks_base-d25b996a7ab2589f258d0006dda6589f53d98366.tar.gz
frameworks_base-d25b996a7ab2589f258d0006dda6589f53d98366.tar.bz2
am a6ae8ba4: MediaHTTPConnection: do not use proxy for localhost
* commit 'a6ae8ba4a59f3f893fe8893335e7517388123c10': MediaHTTPConnection: do not use proxy for localhost
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/MediaHTTPConnection.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/media/java/android/media/MediaHTTPConnection.java b/media/java/android/media/MediaHTTPConnection.java
index 05acf90..d0f3334 100644
--- a/media/java/android/media/MediaHTTPConnection.java
+++ b/media/java/android/media/MediaHTTPConnection.java
@@ -16,6 +16,7 @@
package android.media;
+import android.net.NetworkUtils;
import android.os.IBinder;
import android.os.StrictMode;
import android.util.Log;
@@ -25,6 +26,7 @@ import java.io.InputStream;
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
+import java.net.Proxy;
import java.net.URL;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@@ -137,6 +139,29 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
}
}
+ private static final boolean isLocalHost(URL url) {
+ if (url == null) {
+ return false;
+ }
+
+ String host = url.getHost();
+
+ if (host == null) {
+ return false;
+ }
+
+ try {
+ if (host.equalsIgnoreCase("localhost")) {
+ return true;
+ }
+ if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
+ return true;
+ }
+ } catch (IllegalArgumentException iex) {
+ }
+ return false;
+ }
+
private void seekTo(long offset) throws IOException {
teardownConnection();
@@ -145,8 +170,17 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
int redirectCount = 0;
URL url = mURL;
+
+ // do not use any proxy for localhost (127.0.0.1)
+ boolean noProxy = isLocalHost(url);
+
while (true) {
- mConnection = (HttpURLConnection)url.openConnection();
+ if (noProxy) {
+ mConnection = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
+ } else {
+ mConnection = (HttpURLConnection)url.openConnection();
+ }
+
// handle redirects ourselves if we do not allow cross-domain redirect
mConnection.setInstanceFollowRedirects(mAllowCrossDomainRedirect);