From 7a952773d1b49d19c1bca4c20792f216467651bb Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Fri, 1 May 2020 00:26:14 +0100 Subject: [PATCH] Connectivity: start PAC global proxy after reboot. Previously, we read the global proxy settings from Settings.Global database after reboot. This works for manual proxies, but not for proxies based on PAC rules, as PacManager is never invoked when ConnectivityService starts up. As a consequence, services required for PAC-based proxies (PacService and ProxyService) are never started. In this CL, we make sure PacManager is called during boot, so that PAC rules will take effect. Bug: 35943997 Test: set a PAC proxy and observe it still works after reboot Change-Id: I69edb5fcd3e84663d338ff4b93c40fd5ee2c8c51 --- .../server/connectivity/ProxyTracker.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/ProxyTracker.java b/services/core/java/com/android/server/connectivity/ProxyTracker.java index e715890fb2..f812a05fd0 100644 --- a/services/core/java/com/android/server/connectivity/ProxyTracker.java +++ b/services/core/java/com/android/server/connectivity/ProxyTracker.java @@ -73,6 +73,8 @@ public class ProxyTracker { @GuardedBy("mProxyLock") private boolean mDefaultProxyEnabled = true; + private final Handler mConnectivityServiceHandler; + // The object responsible for Proxy Auto Configuration (PAC). @NonNull private final PacManager mPacManager; @@ -80,6 +82,7 @@ public class ProxyTracker { public ProxyTracker(@NonNull final Context context, @NonNull final Handler connectivityServiceInternalHandler, final int pacChangedEvent) { mContext = context; + mConnectivityServiceHandler = connectivityServiceInternalHandler; mPacManager = new PacManager(context, connectivityServiceInternalHandler, pacChangedEvent); } @@ -149,6 +152,9 @@ public class ProxyTracker { * Read the global proxy settings and cache them in memory. */ public void loadGlobalProxy() { + if (loadDeprecatedGlobalHttpProxy()) { + return; + } ContentResolver res = mContext.getContentResolver(); String host = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_HOST); int port = Settings.Global.getInt(res, GLOBAL_HTTP_PROXY_PORT, 0); @@ -169,20 +175,24 @@ public class ProxyTracker { synchronized (mProxyLock) { mGlobalProxy = proxyProperties; } + + if (!TextUtils.isEmpty(pacFileUrl)) { + mConnectivityServiceHandler.post( + () -> mPacManager.setCurrentProxyScriptUrl(proxyProperties)); + } } - loadDeprecatedGlobalHttpProxy(); - // TODO : shouldn't this function call mPacManager.setCurrentProxyScriptUrl ? } /** * Read the global proxy from the deprecated Settings.Global.HTTP_PROXY setting and apply it. + * Returns {@code true} when global proxy was set successfully from deprecated setting. */ - public void loadDeprecatedGlobalHttpProxy() { + public boolean loadDeprecatedGlobalHttpProxy() { final String proxy = Settings.Global.getString(mContext.getContentResolver(), HTTP_PROXY); if (!TextUtils.isEmpty(proxy)) { String data[] = proxy.split(":"); if (data.length == 0) { - return; + return false; } final String proxyHost = data[0]; @@ -191,12 +201,14 @@ public class ProxyTracker { try { proxyPort = Integer.parseInt(data[1]); } catch (NumberFormatException e) { - return; + return false; } } final ProxyInfo p = new ProxyInfo(proxyHost, proxyPort, ""); setGlobalProxy(p); + return true; } + return false; } /**