summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2021-01-25 04:04:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-01-25 04:04:40 +0000
commita4a9e9bbc83c6097d31a3d5f3b1c7cb6a4848d67 (patch)
treeb72e7a05f24f7dec2901201aa24de7de61b0dd25 /core/java
parent68dcdfa29bf7c5ab2d381a4dc3a8e89959a20b71 (diff)
parentad78bf1f22e6b2fa973efae91ad4f9eb23976cdd (diff)
Merge "Remove hidden API usage of Proxy.validate"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java29
1 files changed, 12 insertions, 17 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index c7fa7fa31403..69d387994568 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -85,6 +85,7 @@ import android.security.keystore.StrongBoxUnavailableException;
import android.service.restrictions.RestrictionsReceiver;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
+import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
@@ -4548,29 +4549,23 @@ public class DevicePolicyManager {
InetSocketAddress sa = (InetSocketAddress) proxySpec.address();
String hostName = sa.getHostName();
int port = sa.getPort();
- StringBuilder hostBuilder = new StringBuilder();
- final String hostSpec = hostBuilder.append(hostName)
- .append(":").append(Integer.toString(port)).toString();
- final String exclSpec;
+ final List<String> trimmedExclList;
if (exclusionList == null) {
- exclSpec = "";
+ trimmedExclList = Collections.emptyList();
} else {
- StringBuilder listBuilder = new StringBuilder();
- boolean firstDomain = true;
+ trimmedExclList = new ArrayList<>(exclusionList.size());
for (String exclDomain : exclusionList) {
- if (!firstDomain) {
- listBuilder = listBuilder.append(",");
- } else {
- firstDomain = false;
- }
- listBuilder = listBuilder.append(exclDomain.trim());
+ trimmedExclList.add(exclDomain.trim());
}
- exclSpec = listBuilder.toString();
}
- if (android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec)
- != android.net.Proxy.PROXY_VALID) throw new IllegalArgumentException();
+ 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();
+ }
- return new Pair<>(hostSpec, exclSpec);
+ return new Pair<>(hostName + ":" + port, TextUtils.join(",", trimmedExclList));
}
/**