diff options
author | Serik Beketayev <serikb@google.com> | 2020-12-25 09:45:54 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-25 09:45:54 +0000 |
commit | 40e7949c5f64676ffe6a992fdaddd04a64e549d4 (patch) | |
tree | 8cfd43477a884ccdd980ce49164706e54ad0e136 | |
parent | 0b39593d11e1346e9ef216a625bf1745eeafe090 (diff) | |
parent | 5565118666481fcb6da80efb4c5eec03368ff70f (diff) |
Merge "[Mainline] Migrate ProxyInfo" am: 3c3711dffd am: 5565118666
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1506616
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ica0e0965296e3bf843fa73fc6d687da6a9ae721d
8 files changed, 38 insertions, 19 deletions
diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java index 20ccc07b18dd..03b07e080add 100644 --- a/core/java/android/net/Proxy.java +++ b/core/java/android/net/Proxy.java @@ -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); diff --git a/core/java/com/android/internal/net/VpnProfile.java b/core/java/com/android/internal/net/VpnProfile.java index a17f5f5f8910..b7170d857da9 100644 --- a/core/java/com/android/internal/net/VpnProfile.java +++ b/core/java/com/android/internal/net/VpnProfile.java @@ -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 { diff --git a/services/core/java/com/android/server/connectivity/PacManager.java b/services/core/java/com/android/server/connectivity/PacManager.java index 198de78ecfa6..06721aea5540 100644 --- a/services/core/java/com/android/server/connectivity/PacManager.java +++ b/services/core/java/com/android/server/connectivity/PacManager.java @@ -390,7 +390,7 @@ public class PacManager { return; } if (!mHasSentBroadcast) { - sendPacBroadcast(new ProxyInfo(mPacUrl, mLastPort)); + sendPacBroadcast(ProxyInfo.buildPacProxy(mPacUrl, mLastPort)); mHasSentBroadcast = true; } } diff --git a/services/core/java/com/android/server/connectivity/ProxyTracker.java b/services/core/java/com/android/server/connectivity/ProxyTracker.java index 5cb3d94a929f..f6ca1523fe2d 100644 --- a/services/core/java/com/android/server/connectivity/ProxyTracker.java +++ b/services/core/java/com/android/server/connectivity/ProxyTracker.java @@ -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 { diff --git a/services/core/java/com/android/server/net/IpConfigStore.java b/services/core/java/com/android/server/net/IpConfigStore.java index 9c5abd4706a3..cc3a002adc84 100644 --- a/services/core/java/com/android/server/net/IpConfigStore.java +++ b/services/core/java/com/android/server/net/IpConfigStore.java @@ -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; diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index dd48ac80f0be..f390d06c8ab5 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -286,6 +286,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; @@ -7774,7 +7775,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; diff --git a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java b/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java index 9d300a611374..401d6e30df13 100644 --- a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java +++ b/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java @@ -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); diff --git a/tests/net/java/android/net/Ikev2VpnProfileTest.java b/tests/net/java/android/net/Ikev2VpnProfileTest.java index ada5494efd60..076e41d33a8d 100644 --- a/tests/net/java/android/net/Ikev2VpnProfileTest.java +++ b/tests/net/java/android/net/Ikev2VpnProfileTest.java @@ -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; |