From 100df0a66c28bfae8f4e3c2dd6c4c7b21294456d Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 15 May 2018 23:11:45 +0900 Subject: [PATCH] Fix: ConnectivityManager is initialized with a wrong context ActivityThread#setHttpProxy uses a system context to get a ConnectivityManager instance. If it's not already cached, the system service registry will cache this instance initialized with the system context, and subsequent calls to get this service will return the bad instance. This patch uses the application context instead, unless it's not available for some unlikely reason. A possible symptom of this issue is to have Bluetooth tethering failing with a security exception, because it's requested by the "android" package without system uid. Bug: 73572062 Test: manual Change-Id: I745707e4ffe564f6d201ec259fa6b5ee32fbeda6 --- core/java/android/app/ActivityThread.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 0ae4b7d3df663..37453fef30a44 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -937,7 +937,8 @@ public final class ActivityThread extends ClientTransactionHandler { } public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { - final ConnectivityManager cm = ConnectivityManager.from(getSystemContext()); + final ConnectivityManager cm = ConnectivityManager.from( + getApplication() != null ? getApplication() : getSystemContext()); final Network network = cm.getBoundNetworkForProcess(); if (network != null) { Proxy.setHttpProxySystemProperty(cm.getDefaultProxy());