summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java14
-rw-r--r--src/com/android/providers/downloads/RealSystemFacade.java8
-rw-r--r--src/com/android/providers/downloads/SystemFacade.java3
-rw-r--r--tests/src/com/android/providers/downloads/FakeSystemFacade.java7
4 files changed, 31 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 65142db..f6b0be6 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -45,6 +45,7 @@ import android.drm.DrmManagerClient;
import android.drm.DrmOutputStream;
import android.net.ConnectivityManager;
import android.net.INetworkPolicyListener;
+import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkPolicyManager;
import android.net.TrafficStats;
@@ -351,6 +352,15 @@ public class DownloadThread implements Runnable {
throw new StopRequestException(STATUS_BAD_REQUEST, e);
}
+ // Use the caller's default network to make this connection, since they might be subject to
+ // restrictions that we shouldn't let them circumvent.
+ final Network network = mSystemFacade.getActiveNetwork(mInfo.mUid);
+ if (network == null) {
+ throw new StopRequestException(Downloads.Impl.STATUS_WAITING_FOR_NETWORK,
+ "no network associated with requesting UID");
+ }
+ logDebug("Using network: " + network);
+
boolean cleartextTrafficPermitted = mSystemFacade.isCleartextTrafficPermitted(mInfo.mUid);
int redirectionCount = 0;
while (redirectionCount++ < Constants.MAX_REDIRECTS) {
@@ -366,8 +376,10 @@ public class DownloadThread implements Runnable {
// response with body.
HttpURLConnection conn = null;
try {
+ // Check that the caller is allowed to make network connections. If so, make one on
+ // their behalf to open the url.
checkConnectivity();
- conn = (HttpURLConnection) url.openConnection();
+ conn = (HttpURLConnection) network.openConnection(url);
conn.setInstanceFollowRedirects(false);
conn.setConnectTimeout(DEFAULT_TIMEOUT);
conn.setReadTimeout(DEFAULT_TIMEOUT);
diff --git a/src/com/android/providers/downloads/RealSystemFacade.java b/src/com/android/providers/downloads/RealSystemFacade.java
index b3f170f..48df2a0 100644
--- a/src/com/android/providers/downloads/RealSystemFacade.java
+++ b/src/com/android/providers/downloads/RealSystemFacade.java
@@ -26,6 +26,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -59,6 +60,13 @@ class RealSystemFacade implements SystemFacade {
}
@Override
+ public Network getActiveNetwork(int uid) {
+ ConnectivityManager connectivity =
+ (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ return connectivity.getActiveNetworkForUid(uid);
+ }
+
+ @Override
public boolean isActiveNetworkMetered() {
final ConnectivityManager conn = ConnectivityManager.from(mContext);
return conn.isActiveNetworkMetered();
diff --git a/src/com/android/providers/downloads/SystemFacade.java b/src/com/android/providers/downloads/SystemFacade.java
index 83fc7a6..7f97b91 100644
--- a/src/com/android/providers/downloads/SystemFacade.java
+++ b/src/com/android/providers/downloads/SystemFacade.java
@@ -18,6 +18,7 @@ package com.android.providers.downloads;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Network;
import android.net.NetworkInfo;
interface SystemFacade {
@@ -32,6 +33,8 @@ interface SystemFacade {
*/
public NetworkInfo getActiveNetworkInfo(int uid);
+ public Network getActiveNetwork(int uid);
+
public boolean isActiveNetworkMetered();
/**
diff --git a/tests/src/com/android/providers/downloads/FakeSystemFacade.java b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
index 7581e6f..af5482e 100644
--- a/tests/src/com/android/providers/downloads/FakeSystemFacade.java
+++ b/tests/src/com/android/providers/downloads/FakeSystemFacade.java
@@ -3,6 +3,7 @@ package com.android.providers.downloads;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
+import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
@@ -10,6 +11,7 @@ import java.util.ArrayList;
import java.util.List;
public class FakeSystemFacade implements SystemFacade {
long mTimeMillis = 0;
+ Network mActiveNetwork = null;
Integer mActiveNetworkType = ConnectivityManager.TYPE_WIFI;
boolean mIsRoaming = false;
boolean mIsMetered = false;
@@ -43,6 +45,11 @@ public class FakeSystemFacade implements SystemFacade {
}
@Override
+ public Network getActiveNetwork(int uid) {
+ return mActiveNetwork;
+ }
+
+ @Override
public NetworkInfo getActiveNetworkInfo(int uid) {
if (mActiveNetworkType == null) {
return null;