Merge "[Mainline] Migrate ProxyInfo" am: 3c3711dffd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1506616

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ic839f183b48279532dcfb484818457a5372087b2
This commit is contained in:
Serik Beketayev
2020-12-25 09:21:03 +00:00
committed by Automerger Merge Worker
8 changed files with 38 additions and 19 deletions

View File

@@ -24,6 +24,8 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.android.net.module.util.ProxyUtils;
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import java.net.URI;
@@ -251,7 +253,7 @@ public final class Proxy {
if (p != null) {
host = p.getHost();
port = Integer.toString(p.getPort());
exclList = p.getExclusionListAsString();
exclList = ProxyUtils.exclusionListAsString(p.getExclusionList());
pacFileUrl = p.getPacFileUrl();
}
setHttpProxySystemProperty(host, port, exclList, pacFileUrl);

View File

@@ -28,6 +28,7 @@ import android.os.Parcelable;
import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.net.module.util.ProxyUtils;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
@@ -285,10 +286,12 @@ public final class VpnProfile implements Cloneable, Parcelable {
String exclList = (values.length > 17) ? values[17] : "";
String pacFileUrl = (values.length > 18) ? values[18] : "";
if (!host.isEmpty() || !port.isEmpty() || !exclList.isEmpty()) {
profile.proxy = new ProxyInfo(host, port.isEmpty() ?
0 : Integer.parseInt(port), exclList);
profile.proxy =
ProxyInfo.buildDirectProxy(host, port.isEmpty() ?
0 : Integer.parseInt(port),
ProxyUtils.exclusionStringAsList(exclList));
} else if (!pacFileUrl.isEmpty()) {
profile.proxy = new ProxyInfo(Uri.parse(pacFileUrl));
profile.proxy = ProxyInfo.buildPacProxy(Uri.parse(pacFileUrl));
}
} // else profile.proxy = null
@@ -337,8 +340,8 @@ public final class VpnProfile implements Cloneable, Parcelable {
builder.append(VALUE_DELIMITER).append(proxy.getPort());
builder.append(VALUE_DELIMITER)
.append(
proxy.getExclusionListAsString() != null
? proxy.getExclusionListAsString()
ProxyUtils.exclusionListAsString(proxy.getExclusionList()) != null
? ProxyUtils.exclusionListAsString(proxy.getExclusionList())
: "");
builder.append(VALUE_DELIMITER).append(proxy.getPacFileUrl().toString());
} else {

View File

@@ -390,7 +390,7 @@ public class PacManager {
return;
}
if (!mHasSentBroadcast) {
sendPacBroadcast(new ProxyInfo(mPacUrl, mLastPort));
sendPacBroadcast(ProxyInfo.buildPacProxy(mPacUrl, mLastPort));
mHasSentBroadcast = true;
}
}

View File

@@ -38,7 +38,9 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.net.module.util.ProxyUtils;
import java.util.Collections;
import java.util.Objects;
/**
@@ -163,9 +165,10 @@ public class ProxyTracker {
if (!TextUtils.isEmpty(host) || !TextUtils.isEmpty(pacFileUrl)) {
ProxyInfo proxyProperties;
if (!TextUtils.isEmpty(pacFileUrl)) {
proxyProperties = new ProxyInfo(Uri.parse(pacFileUrl));
proxyProperties = ProxyInfo.buildPacProxy(Uri.parse(pacFileUrl));
} else {
proxyProperties = new ProxyInfo(host, port, exclList);
proxyProperties = ProxyInfo.buildDirectProxy(host, port,
ProxyUtils.exclusionStringAsList(exclList));
}
if (!proxyProperties.isValid()) {
if (DBG) Log.d(TAG, "Invalid proxy properties, ignoring: " + proxyProperties);
@@ -204,7 +207,8 @@ public class ProxyTracker {
return false;
}
}
final ProxyInfo p = new ProxyInfo(proxyHost, proxyPort, "");
final ProxyInfo p = ProxyInfo.buildDirectProxy(proxyHost, proxyPort,
Collections.emptyList());
setGlobalProxy(p);
return true;
}
@@ -219,7 +223,8 @@ public class ProxyTracker {
*/
public void sendProxyBroadcast() {
final ProxyInfo defaultProxy = getDefaultProxy();
final ProxyInfo proxyInfo = null != defaultProxy ? defaultProxy : new ProxyInfo("", 0, "");
final ProxyInfo proxyInfo = null != defaultProxy ?
defaultProxy : ProxyInfo.buildDirectProxy("", 0, Collections.emptyList());
if (mPacManager.setCurrentProxyScriptUrl(proxyInfo) == PacManager.DONT_SEND_BROADCAST) {
return;
}
@@ -261,7 +266,7 @@ public class ProxyTracker {
mGlobalProxy = new ProxyInfo(proxyInfo);
host = mGlobalProxy.getHost();
port = mGlobalProxy.getPort();
exclList = mGlobalProxy.getExclusionListAsString();
exclList = ProxyUtils.exclusionListAsString(mGlobalProxy.getExclusionList());
pacFileUrl = Uri.EMPTY.equals(proxyInfo.getPacFileUrl())
? "" : proxyInfo.getPacFileUrl().toString();
} else {

View File

@@ -30,6 +30,7 @@ import android.util.Log;
import android.util.SparseArray;
import com.android.internal.annotations.VisibleForTesting;
import com.android.net.module.util.ProxyUtils;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
@@ -123,7 +124,8 @@ public class IpConfigStore {
switch (config.proxySettings) {
case STATIC:
ProxyInfo proxyProperties = config.httpProxy;
String exclusionList = proxyProperties.getExclusionListAsString();
String exclusionList = ProxyUtils.exclusionListAsString(
proxyProperties.getExclusionList());
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
out.writeUTF(PROXY_HOST_KEY);
@@ -370,13 +372,14 @@ public class IpConfigStore {
switch (proxySettings) {
case STATIC:
ProxyInfo proxyInfo =
new ProxyInfo(proxyHost, proxyPort, exclusionList);
ProxyInfo proxyInfo = ProxyInfo.buildDirectProxy(proxyHost, proxyPort,
ProxyUtils.exclusionStringAsList(exclusionList));
config.proxySettings = proxySettings;
config.httpProxy = proxyInfo;
break;
case PAC:
ProxyInfo proxyPacProperties = new ProxyInfo(Uri.parse(pacFileUrl));
ProxyInfo proxyPacProperties =
ProxyInfo.buildPacProxy(Uri.parse(pacFileUrl));
config.proxySettings = proxySettings;
config.httpProxy = proxyPacProperties;
break;

View File

@@ -285,6 +285,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockSettingsInternal;
import com.android.internal.widget.LockscreenCredential;
import com.android.internal.widget.PasswordValidationError;
import com.android.net.module.util.ProxyUtils;
import com.android.server.LocalServices;
import com.android.server.LockGuard;
import com.android.server.PersistentDataBlockManagerInternal;
@@ -7759,7 +7760,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
exclusionList = exclusionList.trim();
ProxyInfo proxyProperties = new ProxyInfo(data[0], proxyPort, exclusionList);
ProxyInfo proxyProperties = ProxyInfo.buildDirectProxy(data[0], proxyPort,
ProxyUtils.exclusionStringAsList(exclusionList));
if (!proxyProperties.isValid()) {
Slog.e(LOG_TAG, "Invalid proxy properties, ignoring: " + proxyProperties.toString());
return;

View File

@@ -39,6 +39,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
/**
* Unit tests for {@link IpConfigStore}
@@ -82,7 +83,8 @@ public class IpConfigStoreTest {
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1));
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2));
ProxyInfo proxyInfo = new ProxyInfo("10.10.10.10", 88, "host1,host2");
ProxyInfo proxyInfo =
ProxyInfo.buildDirectProxy("10.10.10.10", 88, Arrays.asList("host1", "host2"));
IpConfiguration expectedConfig1 = new IpConfiguration(IpAssignment.STATIC,
ProxySettings.STATIC, staticIpConfiguration, proxyInfo);

View File

@@ -29,6 +29,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.net.VpnProfile;
import com.android.net.module.util.ProxyUtils;
import com.android.org.bouncycastle.x509.X509V1CertificateGenerator;
import org.junit.Before;
@@ -67,7 +68,8 @@ public class Ikev2VpnProfileTest {
return "fooPackage";
}
};
private final ProxyInfo mProxy = new ProxyInfo(SERVER_ADDR_STRING, -1, EXCL_LIST);
private final ProxyInfo mProxy = ProxyInfo.buildDirectProxy(
SERVER_ADDR_STRING, -1, ProxyUtils.exclusionStringAsList(EXCL_LIST));
private X509Certificate mUserCert;
private X509Certificate mServerRootCa;