Loading services/core/java/com/android/server/connectivity/ProxyTracker.java +26 −28 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.server.connectivity; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_HOST; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PAC; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PORT; import static android.provider.Settings.Global.HTTP_PROXY; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ContentResolver; Loading Loading @@ -47,16 +53,14 @@ public class ProxyTracker { @NonNull private final Context mContext; // TODO : make this private and import as much managing logic from ConnectivityService as // possible @NonNull public final Object mProxyLock = new Object(); private final Object mProxyLock = new Object(); // The global proxy is the proxy that is set device-wide, overriding any network-specific // proxy. Note however that proxies are hints ; the system does not enforce their use. Hence // this value is only for querying. @Nullable @GuardedBy("mProxyLock") public ProxyInfo mGlobalProxy = null; private ProxyInfo mGlobalProxy = null; // The default proxy is the proxy that applies to no particular network if the global proxy // is not set. Individual networks have their own settings that override this. This member // is set through setDefaultProxy, which is called when the default network changes proxies Loading @@ -64,10 +68,10 @@ public class ProxyTracker { // when PacManager resolves the proxy. @Nullable @GuardedBy("mProxyLock") public volatile ProxyInfo mDefaultProxy = null; // Whether the default proxy is disabled. TODO : make this mDefaultProxyEnabled private volatile ProxyInfo mDefaultProxy = null; // Whether the default proxy is enabled. @GuardedBy("mProxyLock") public boolean mDefaultProxyDisabled = false; private boolean mDefaultProxyEnabled = true; // The object responsible for Proxy Auto Configuration (PAC). @NonNull Loading @@ -85,7 +89,7 @@ public class ProxyTracker { @Nullable private static ProxyInfo canonicalizeProxyInfo(@Nullable final ProxyInfo proxy) { if (proxy != null && TextUtils.isEmpty(proxy.getHost()) && (proxy.getPacFileUrl() == null || Uri.EMPTY.equals(proxy.getPacFileUrl()))) { && Uri.EMPTY.equals(proxy.getPacFileUrl())) { return null; } return proxy; Loading Loading @@ -123,7 +127,7 @@ public class ProxyTracker { // This information is already available as a world read/writable jvm property. synchronized (mProxyLock) { final ProxyInfo ret = mGlobalProxy; if ((ret == null) && !mDefaultProxyDisabled) return mDefaultProxy; if ((ret == null) && mDefaultProxyEnabled) return mDefaultProxy; return ret; } } Loading @@ -146,11 +150,10 @@ public class ProxyTracker { */ public void loadGlobalProxy() { ContentResolver res = mContext.getContentResolver(); String host = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST); int port = Settings.Global.getInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, 0); String exclList = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST); String pacFileUrl = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC); String host = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_HOST); int port = Settings.Global.getInt(res, GLOBAL_HTTP_PROXY_PORT, 0); String exclList = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_EXCLUSION_LIST); String pacFileUrl = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_PAC); if (!TextUtils.isEmpty(host) || !TextUtils.isEmpty(pacFileUrl)) { ProxyInfo proxyProperties; if (!TextUtils.isEmpty(pacFileUrl)) { Loading @@ -175,8 +178,7 @@ public class ProxyTracker { * Read the global proxy from the deprecated Settings.Global.HTTP_PROXY setting and apply it. */ public void loadDeprecatedGlobalHttpProxy() { final String proxy = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.HTTP_PROXY); final String proxy = Settings.Global.getString(mContext.getContentResolver(), HTTP_PROXY); if (!TextUtils.isEmpty(proxy)) { String data[] = proxy.split(":"); if (data.length == 0) { Loading Loading @@ -259,11 +261,10 @@ public class ProxyTracker { final ContentResolver res = mContext.getContentResolver(); final long token = Binder.clearCallingIdentity(); try { Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host); Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port); Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList); Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_HOST, host); Settings.Global.putInt(res, GLOBAL_HTTP_PROXY_PORT, port); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_PAC, pacFileUrl); } finally { Binder.restoreCallingIdentity(token); } Loading @@ -280,10 +281,7 @@ public class ProxyTracker { */ public void setDefaultProxy(@Nullable ProxyInfo proxyInfo) { synchronized (mProxyLock) { if (mDefaultProxy != null && mDefaultProxy.equals(proxyInfo)) { return; } if (mDefaultProxy == proxyInfo) return; // catches repeated nulls if (Objects.equals(mDefaultProxy, proxyInfo)) return; if (proxyInfo != null && !proxyInfo.isValid()) { if (DBG) Slog.d(TAG, "Invalid proxy properties, ignoring: " + proxyInfo); return; Loading @@ -304,7 +302,7 @@ public class ProxyTracker { mDefaultProxy = proxyInfo; if (mGlobalProxy != null) return; if (!mDefaultProxyDisabled) { if (mDefaultProxyEnabled) { sendProxyBroadcast(proxyInfo); } } Loading @@ -319,8 +317,8 @@ public class ProxyTracker { */ public void setDefaultProxyEnabled(final boolean enabled) { synchronized (mProxyLock) { if (mDefaultProxyDisabled == enabled) { mDefaultProxyDisabled = !enabled; if (mDefaultProxyEnabled != enabled) { mDefaultProxyEnabled = enabled; if (mGlobalProxy == null && mDefaultProxy != null) { sendProxyBroadcast(enabled ? mDefaultProxy : null); } Loading Loading
services/core/java/com/android/server/connectivity/ProxyTracker.java +26 −28 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.server.connectivity; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_HOST; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PAC; import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PORT; import static android.provider.Settings.Global.HTTP_PROXY; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ContentResolver; Loading Loading @@ -47,16 +53,14 @@ public class ProxyTracker { @NonNull private final Context mContext; // TODO : make this private and import as much managing logic from ConnectivityService as // possible @NonNull public final Object mProxyLock = new Object(); private final Object mProxyLock = new Object(); // The global proxy is the proxy that is set device-wide, overriding any network-specific // proxy. Note however that proxies are hints ; the system does not enforce their use. Hence // this value is only for querying. @Nullable @GuardedBy("mProxyLock") public ProxyInfo mGlobalProxy = null; private ProxyInfo mGlobalProxy = null; // The default proxy is the proxy that applies to no particular network if the global proxy // is not set. Individual networks have their own settings that override this. This member // is set through setDefaultProxy, which is called when the default network changes proxies Loading @@ -64,10 +68,10 @@ public class ProxyTracker { // when PacManager resolves the proxy. @Nullable @GuardedBy("mProxyLock") public volatile ProxyInfo mDefaultProxy = null; // Whether the default proxy is disabled. TODO : make this mDefaultProxyEnabled private volatile ProxyInfo mDefaultProxy = null; // Whether the default proxy is enabled. @GuardedBy("mProxyLock") public boolean mDefaultProxyDisabled = false; private boolean mDefaultProxyEnabled = true; // The object responsible for Proxy Auto Configuration (PAC). @NonNull Loading @@ -85,7 +89,7 @@ public class ProxyTracker { @Nullable private static ProxyInfo canonicalizeProxyInfo(@Nullable final ProxyInfo proxy) { if (proxy != null && TextUtils.isEmpty(proxy.getHost()) && (proxy.getPacFileUrl() == null || Uri.EMPTY.equals(proxy.getPacFileUrl()))) { && Uri.EMPTY.equals(proxy.getPacFileUrl())) { return null; } return proxy; Loading Loading @@ -123,7 +127,7 @@ public class ProxyTracker { // This information is already available as a world read/writable jvm property. synchronized (mProxyLock) { final ProxyInfo ret = mGlobalProxy; if ((ret == null) && !mDefaultProxyDisabled) return mDefaultProxy; if ((ret == null) && mDefaultProxyEnabled) return mDefaultProxy; return ret; } } Loading @@ -146,11 +150,10 @@ public class ProxyTracker { */ public void loadGlobalProxy() { ContentResolver res = mContext.getContentResolver(); String host = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST); int port = Settings.Global.getInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, 0); String exclList = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST); String pacFileUrl = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC); String host = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_HOST); int port = Settings.Global.getInt(res, GLOBAL_HTTP_PROXY_PORT, 0); String exclList = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_EXCLUSION_LIST); String pacFileUrl = Settings.Global.getString(res, GLOBAL_HTTP_PROXY_PAC); if (!TextUtils.isEmpty(host) || !TextUtils.isEmpty(pacFileUrl)) { ProxyInfo proxyProperties; if (!TextUtils.isEmpty(pacFileUrl)) { Loading @@ -175,8 +178,7 @@ public class ProxyTracker { * Read the global proxy from the deprecated Settings.Global.HTTP_PROXY setting and apply it. */ public void loadDeprecatedGlobalHttpProxy() { final String proxy = Settings.Global.getString(mContext.getContentResolver(), Settings.Global.HTTP_PROXY); final String proxy = Settings.Global.getString(mContext.getContentResolver(), HTTP_PROXY); if (!TextUtils.isEmpty(proxy)) { String data[] = proxy.split(":"); if (data.length == 0) { Loading Loading @@ -259,11 +261,10 @@ public class ProxyTracker { final ContentResolver res = mContext.getContentResolver(); final long token = Binder.clearCallingIdentity(); try { Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host); Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port); Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList); Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_HOST, host); Settings.Global.putInt(res, GLOBAL_HTTP_PROXY_PORT, port); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList); Settings.Global.putString(res, GLOBAL_HTTP_PROXY_PAC, pacFileUrl); } finally { Binder.restoreCallingIdentity(token); } Loading @@ -280,10 +281,7 @@ public class ProxyTracker { */ public void setDefaultProxy(@Nullable ProxyInfo proxyInfo) { synchronized (mProxyLock) { if (mDefaultProxy != null && mDefaultProxy.equals(proxyInfo)) { return; } if (mDefaultProxy == proxyInfo) return; // catches repeated nulls if (Objects.equals(mDefaultProxy, proxyInfo)) return; if (proxyInfo != null && !proxyInfo.isValid()) { if (DBG) Slog.d(TAG, "Invalid proxy properties, ignoring: " + proxyInfo); return; Loading @@ -304,7 +302,7 @@ public class ProxyTracker { mDefaultProxy = proxyInfo; if (mGlobalProxy != null) return; if (!mDefaultProxyDisabled) { if (mDefaultProxyEnabled) { sendProxyBroadcast(proxyInfo); } } Loading @@ -319,8 +317,8 @@ public class ProxyTracker { */ public void setDefaultProxyEnabled(final boolean enabled) { synchronized (mProxyLock) { if (mDefaultProxyDisabled == enabled) { mDefaultProxyDisabled = !enabled; if (mDefaultProxyEnabled != enabled) { mDefaultProxyEnabled = enabled; if (mGlobalProxy == null && mDefaultProxy != null) { sendProxyBroadcast(enabled ? mDefaultProxy : null); } Loading