[Mainline] Migrate ProxyInfo

Bug: 173455434
Test: atest FrameworksNetTests
Change-Id: I924aed710b62a0c91b888a9e04ac2c90cdfd88d0
This commit is contained in:
Serik Beketayev
2020-12-06 23:08:08 -08:00
parent e0d9d5d7ce
commit a9dc6770b2
2 changed files with 13 additions and 6 deletions

View File

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

View File

@@ -29,6 +29,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.internal.net.VpnProfile; import com.android.internal.net.VpnProfile;
import com.android.net.module.util.ProxyUtils;
import com.android.org.bouncycastle.x509.X509V1CertificateGenerator; import com.android.org.bouncycastle.x509.X509V1CertificateGenerator;
import org.junit.Before; import org.junit.Before;
@@ -67,7 +68,8 @@ public class Ikev2VpnProfileTest {
return "fooPackage"; 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 mUserCert;
private X509Certificate mServerRootCa; private X509Certificate mServerRootCa;