Merge "[PT13] Simple cleanup of ProxyTracker."
am: db2eff0874
Change-Id: I6a30f78e517716ca3ff14a3601374fddc65e4aec
This commit is contained in:
@@ -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;
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -304,7 +302,7 @@ public class ProxyTracker {
|
||||
mDefaultProxy = proxyInfo;
|
||||
|
||||
if (mGlobalProxy != null) return;
|
||||
if (!mDefaultProxyDisabled) {
|
||||
if (mDefaultProxyEnabled) {
|
||||
sendProxyBroadcast(proxyInfo);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user