[PT02] Move static methods to ProxyTracker
No logic changes. Only changes are adding nullability annotations, final modifiers, and adding an s in a comment. Test: runtests Change-Id: If4986a25bb36819de8ff459c4c0439c56d4e5a50
This commit is contained in:
@@ -3309,34 +3309,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
// Convert empty ProxyInfo's to null as null-checks are used to determine if proxies are present
|
||||
// (e.g. if mGlobalProxy==null fall back to network-specific proxy, if network-specific
|
||||
// proxy is null then there is no proxy in place).
|
||||
private ProxyInfo canonicalizeProxyInfo(ProxyInfo proxy) {
|
||||
if (proxy != null && TextUtils.isEmpty(proxy.getHost())
|
||||
&& (proxy.getPacFileUrl() == null || Uri.EMPTY.equals(proxy.getPacFileUrl()))) {
|
||||
proxy = null;
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
// ProxyInfo equality function with a couple modifications over ProxyInfo.equals() to make it
|
||||
// better for determining if a new proxy broadcast is necessary:
|
||||
// 1. Canonicalize empty ProxyInfos to null so an empty proxy compares equal to null so as to
|
||||
// avoid unnecessary broadcasts.
|
||||
// 2. Make sure all parts of the ProxyInfo's compare true, including the host when a PAC URL
|
||||
// is in place. This is important so legacy PAC resolver (see com.android.proxyhandler)
|
||||
// changes aren't missed. The legacy PAC resolver pretends to be a simple HTTP proxy but
|
||||
// actually uses the PAC to resolve; this results in ProxyInfo's with PAC URL, host and port
|
||||
// all set.
|
||||
private boolean proxyInfoEqual(ProxyInfo a, ProxyInfo b) {
|
||||
a = canonicalizeProxyInfo(a);
|
||||
b = canonicalizeProxyInfo(b);
|
||||
// ProxyInfo.equals() doesn't check hosts when PAC URLs are present, but we need to check
|
||||
// hosts even when PAC URLs are present to account for the legacy PAC resolver.
|
||||
return Objects.equals(a, b) && (a == null || Objects.equals(a.getHost(), b.getHost()));
|
||||
}
|
||||
|
||||
public void setGlobalProxy(ProxyInfo proxyProperties) {
|
||||
enforceConnectivityInternalPermission();
|
||||
|
||||
@@ -3470,7 +3442,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
ProxyInfo newProxyInfo = newLp == null ? null : newLp.getHttpProxy();
|
||||
ProxyInfo oldProxyInfo = oldLp == null ? null : oldLp.getHttpProxy();
|
||||
|
||||
if (!proxyInfoEqual(newProxyInfo, oldProxyInfo)) {
|
||||
if (!ProxyTracker.proxyInfoEqual(newProxyInfo, oldProxyInfo)) {
|
||||
sendProxyBroadcast(getDefaultProxy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,13 @@ package com.android.server.connectivity;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.net.ProxyInfo;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A class to handle proxy for ConnectivityService.
|
||||
*
|
||||
@@ -40,4 +44,33 @@ public class ProxyTracker {
|
||||
public volatile ProxyInfo mDefaultProxy = null;
|
||||
@GuardedBy("mProxyLock")
|
||||
public boolean mDefaultProxyDisabled = false;
|
||||
|
||||
// Convert empty ProxyInfo's to null as null-checks are used to determine if proxies are present
|
||||
// (e.g. if mGlobalProxy==null fall back to network-specific proxy, if network-specific
|
||||
// proxy is null then there is no proxy in place).
|
||||
@Nullable
|
||||
private static ProxyInfo canonicalizeProxyInfo(@Nullable final ProxyInfo proxy) {
|
||||
if (proxy != null && TextUtils.isEmpty(proxy.getHost())
|
||||
&& (proxy.getPacFileUrl() == null || Uri.EMPTY.equals(proxy.getPacFileUrl()))) {
|
||||
return null;
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
// ProxyInfo equality functions with a couple modifications over ProxyInfo.equals() to make it
|
||||
// better for determining if a new proxy broadcast is necessary:
|
||||
// 1. Canonicalize empty ProxyInfos to null so an empty proxy compares equal to null so as to
|
||||
// avoid unnecessary broadcasts.
|
||||
// 2. Make sure all parts of the ProxyInfo's compare true, including the host when a PAC URL
|
||||
// is in place. This is important so legacy PAC resolver (see com.android.proxyhandler)
|
||||
// changes aren't missed. The legacy PAC resolver pretends to be a simple HTTP proxy but
|
||||
// actually uses the PAC to resolve; this results in ProxyInfo's with PAC URL, host and port
|
||||
// all set.
|
||||
public static boolean proxyInfoEqual(@Nullable final ProxyInfo a, @Nullable final ProxyInfo b) {
|
||||
final ProxyInfo pa = canonicalizeProxyInfo(a);
|
||||
final ProxyInfo pb = canonicalizeProxyInfo(b);
|
||||
// ProxyInfo.equals() doesn't check hosts when PAC URLs are present, but we need to check
|
||||
// hosts even when PAC URLs are present to account for the legacy PAC resolver.
|
||||
return Objects.equals(pa, pb) && (pa == null || Objects.equals(pa.getHost(), pb.getHost()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user