Merge "Remove hidden API usage of Proxy.validate"
This commit is contained in:
@@ -85,6 +85,7 @@ import android.security.keystore.StrongBoxUnavailableException;
|
|||||||
import android.service.restrictions.RestrictionsReceiver;
|
import android.service.restrictions.RestrictionsReceiver;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.telephony.data.ApnSetting;
|
import android.telephony.data.ApnSetting;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
@@ -4548,29 +4549,23 @@ public class DevicePolicyManager {
|
|||||||
InetSocketAddress sa = (InetSocketAddress) proxySpec.address();
|
InetSocketAddress sa = (InetSocketAddress) proxySpec.address();
|
||||||
String hostName = sa.getHostName();
|
String hostName = sa.getHostName();
|
||||||
int port = sa.getPort();
|
int port = sa.getPort();
|
||||||
StringBuilder hostBuilder = new StringBuilder();
|
final List<String> trimmedExclList;
|
||||||
final String hostSpec = hostBuilder.append(hostName)
|
|
||||||
.append(":").append(Integer.toString(port)).toString();
|
|
||||||
final String exclSpec;
|
|
||||||
if (exclusionList == null) {
|
if (exclusionList == null) {
|
||||||
exclSpec = "";
|
trimmedExclList = Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
StringBuilder listBuilder = new StringBuilder();
|
trimmedExclList = new ArrayList<>(exclusionList.size());
|
||||||
boolean firstDomain = true;
|
|
||||||
for (String exclDomain : exclusionList) {
|
for (String exclDomain : exclusionList) {
|
||||||
if (!firstDomain) {
|
trimmedExclList.add(exclDomain.trim());
|
||||||
listBuilder = listBuilder.append(",");
|
|
||||||
} else {
|
|
||||||
firstDomain = false;
|
|
||||||
}
|
}
|
||||||
listBuilder = listBuilder.append(exclDomain.trim());
|
|
||||||
}
|
}
|
||||||
exclSpec = listBuilder.toString();
|
final ProxyInfo info = ProxyInfo.buildDirectProxy(hostName, port, trimmedExclList);
|
||||||
|
// The hostSpec is built assuming that there is a specified port and hostname,
|
||||||
|
// but ProxyInfo.isValid() accepts 0 / empty as unspecified: also reject them.
|
||||||
|
if (port == 0 || TextUtils.isEmpty(hostName) || !info.isValid()) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
|
|
||||||
!= android.net.Proxy.PROXY_VALID) throw new IllegalArgumentException();
|
|
||||||
|
|
||||||
return new Pair<>(hostSpec, exclSpec);
|
return new Pair<>(hostName + ":" + port, TextUtils.join(",", trimmedExclList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user