diff options
| author | 2019-10-02 23:37:02 +0800 | |
|---|---|---|
| committer | 2019-11-20 20:07:05 +0800 | |
| commit | 6763aec94ccfa34eba2e6b7d6efbc17bf2ac08a0 (patch) | |
| tree | 236103444af5ef1676979916d9fea485f9171446 | |
| parent | 29146f991b6514c942a58d4569d575b7b6d81892 (diff) | |
Expose IpConfiguration and ProxyInfo APIs
Moving IpConfiguration methods to system API
for mainline support.
Public copy constructors of ProxyInfo and add
buildPacProxy(Uri, int) to create a new proxy
properties.
Bug: 139268426
Bug: 135998869
Test: atest android.net.cts
atest android.net.wifi.cts
atest FrameworksNetTests
./frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I07bcd2a34a222ea2b3cf0d8b497f051011c41c2c
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | api/system-current.txt | 27 | ||||
| -rw-r--r-- | core/java/android/net/IpConfiguration.java | 54 | ||||
| -rw-r--r-- | core/java/android/net/ProxyInfo.java | 24 |
4 files changed, 85 insertions, 23 deletions
diff --git a/api/current.txt b/api/current.txt index 19fd711f1f44..44c91f68d2a0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -28935,14 +28935,17 @@ package android.net { } public class ProxyInfo implements android.os.Parcelable { + ctor public ProxyInfo(@Nullable android.net.ProxyInfo); method public static android.net.ProxyInfo buildDirectProxy(String, int); method public static android.net.ProxyInfo buildDirectProxy(String, int, java.util.List<java.lang.String>); method public static android.net.ProxyInfo buildPacProxy(android.net.Uri); + method @NonNull public static android.net.ProxyInfo buildPacProxy(@NonNull android.net.Uri, int); method public int describeContents(); method public String[] getExclusionList(); method public String getHost(); method public android.net.Uri getPacFileUrl(); method public int getPort(); + method public boolean isValid(); method public void writeToParcel(android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.net.ProxyInfo> CREATOR; } diff --git a/api/system-current.txt b/api/system-current.txt index 2a8fb6341da3..59918caa633d 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4049,6 +4049,33 @@ package android.net { method public void onUpstreamChanged(@Nullable android.net.Network); } + public final class IpConfiguration implements android.os.Parcelable { + ctor public IpConfiguration(); + ctor public IpConfiguration(@NonNull android.net.IpConfiguration); + method @Nullable public android.net.ProxyInfo getHttpProxy(); + method @NonNull public android.net.IpConfiguration.IpAssignment getIpAssignment(); + method @NonNull public android.net.IpConfiguration.ProxySettings getProxySettings(); + method @Nullable public android.net.StaticIpConfiguration getStaticIpConfiguration(); + method public void setHttpProxy(@Nullable android.net.ProxyInfo); + method public void setIpAssignment(@NonNull android.net.IpConfiguration.IpAssignment); + method public void setProxySettings(@NonNull android.net.IpConfiguration.ProxySettings); + method public void setStaticIpConfiguration(@Nullable android.net.StaticIpConfiguration); + field @NonNull public static final android.os.Parcelable.Creator<android.net.IpConfiguration> CREATOR; + } + + public enum IpConfiguration.IpAssignment { + enum_constant public static final android.net.IpConfiguration.IpAssignment DHCP; + enum_constant public static final android.net.IpConfiguration.IpAssignment STATIC; + enum_constant public static final android.net.IpConfiguration.IpAssignment UNASSIGNED; + } + + public enum IpConfiguration.ProxySettings { + enum_constant public static final android.net.IpConfiguration.ProxySettings NONE; + enum_constant public static final android.net.IpConfiguration.ProxySettings PAC; + enum_constant public static final android.net.IpConfiguration.ProxySettings STATIC; + enum_constant public static final android.net.IpConfiguration.ProxySettings UNASSIGNED; + } + public final class IpPrefix implements android.os.Parcelable { ctor public IpPrefix(@NonNull java.net.InetAddress, @IntRange(from=0, to=128) int); ctor public IpPrefix(@NonNull String); diff --git a/core/java/android/net/IpConfiguration.java b/core/java/android/net/IpConfiguration.java index 2af82d7214bf..143467b15fe8 100644 --- a/core/java/android/net/IpConfiguration.java +++ b/core/java/android/net/IpConfiguration.java @@ -16,6 +16,10 @@ package android.net; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SuppressLint; +import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.net.StaticIpConfiguration; import android.os.Parcel; @@ -27,13 +31,17 @@ import java.util.Objects; * A class representing a configured network. * @hide */ -public class IpConfiguration implements Parcelable { +@SystemApi +public final class IpConfiguration implements Parcelable { private static final String TAG = "IpConfiguration"; + // This enum has been used by apps through reflection for many releases. + // Therefore they can't just be removed. Duplicating these constants to + // give an alternate SystemApi is a worse option than exposing them. + @SuppressLint("Enum") public enum IpAssignment { /* Use statically configured IP settings. Configuration can be accessed * with staticIpConfiguration */ - @UnsupportedAppUsage STATIC, /* Use dynamically configured IP settings */ DHCP, @@ -42,14 +50,19 @@ public class IpConfiguration implements Parcelable { UNASSIGNED } + /** @hide */ public IpAssignment ipAssignment; + /** @hide */ public StaticIpConfiguration staticIpConfiguration; + // This enum has been used by apps through reflection for many releases. + // Therefore they can't just be removed. Duplicating these constants to + // give an alternate SystemApi is a worse option than exposing them. + @SuppressLint("Enum") public enum ProxySettings { /* No proxy is to be used. Any existing proxy settings * should be cleared. */ - @UnsupportedAppUsage NONE, /* Use statically configured proxy. Configuration can be accessed * with httpProxy. */ @@ -62,8 +75,10 @@ public class IpConfiguration implements Parcelable { PAC } + /** @hide */ public ProxySettings proxySettings; + /** @hide */ @UnsupportedAppUsage public ProxyInfo httpProxy; @@ -83,6 +98,7 @@ public class IpConfiguration implements Parcelable { init(IpAssignment.UNASSIGNED, ProxySettings.UNASSIGNED, null, null); } + /** @hide */ @UnsupportedAppUsage public IpConfiguration(IpAssignment ipAssignment, ProxySettings proxySettings, @@ -91,7 +107,7 @@ public class IpConfiguration implements Parcelable { init(ipAssignment, proxySettings, staticIpConfiguration, httpProxy); } - public IpConfiguration(IpConfiguration source) { + public IpConfiguration(@NonNull IpConfiguration source) { this(); if (source != null) { init(source.ipAssignment, source.proxySettings, @@ -99,35 +115,35 @@ public class IpConfiguration implements Parcelable { } } - public IpAssignment getIpAssignment() { + public @NonNull IpAssignment getIpAssignment() { return ipAssignment; } - public void setIpAssignment(IpAssignment ipAssignment) { + public void setIpAssignment(@NonNull IpAssignment ipAssignment) { this.ipAssignment = ipAssignment; } - public StaticIpConfiguration getStaticIpConfiguration() { + public @Nullable StaticIpConfiguration getStaticIpConfiguration() { return staticIpConfiguration; } - public void setStaticIpConfiguration(StaticIpConfiguration staticIpConfiguration) { + public void setStaticIpConfiguration(@Nullable StaticIpConfiguration staticIpConfiguration) { this.staticIpConfiguration = staticIpConfiguration; } - public ProxySettings getProxySettings() { + public @NonNull ProxySettings getProxySettings() { return proxySettings; } - public void setProxySettings(ProxySettings proxySettings) { + public void setProxySettings(@NonNull ProxySettings proxySettings) { this.proxySettings = proxySettings; } - public ProxyInfo getHttpProxy() { + public @Nullable ProxyInfo getHttpProxy() { return httpProxy; } - public void setHttpProxy(ProxyInfo httpProxy) { + public void setHttpProxy(@Nullable ProxyInfo httpProxy) { this.httpProxy = httpProxy; } @@ -175,13 +191,19 @@ public class IpConfiguration implements Parcelable { 83 * httpProxy.hashCode(); } - /** Implement the Parcelable interface */ + /** + * Implement the Parcelable interface + * @hide + */ public int describeContents() { return 0; } - /** Implement the Parcelable interface */ - public void writeToParcel(Parcel dest, int flags) { + /** + * Implement the Parcelable interface + * @hide + */ + public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString(ipAssignment.name()); dest.writeString(proxySettings.name()); dest.writeParcelable(staticIpConfiguration, flags); @@ -189,7 +211,7 @@ public class IpConfiguration implements Parcelable { } /** Implement the Parcelable interface */ - public static final @android.annotation.NonNull Creator<IpConfiguration> CREATOR = + public static final @NonNull Creator<IpConfiguration> CREATOR = new Creator<IpConfiguration>() { public IpConfiguration createFromParcel(Parcel in) { IpConfiguration config = new IpConfiguration(); diff --git a/core/java/android/net/ProxyInfo.java b/core/java/android/net/ProxyInfo.java index 807c467053a6..9d92db448668 100644 --- a/core/java/android/net/ProxyInfo.java +++ b/core/java/android/net/ProxyInfo.java @@ -16,7 +16,8 @@ package android.net; - +import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -89,6 +90,15 @@ public class ProxyInfo implements Parcelable { } /** + * Construct a {@link ProxyInfo} object that will download and run the PAC script at the + * specified URL and port. + */ + @NonNull + public static ProxyInfo buildPacProxy(@NonNull Uri pacUrl, int port) { + return new ProxyInfo(pacUrl, port); + } + + /** * Create a ProxyProperties that points at a HTTP Proxy. * @hide */ @@ -105,7 +115,7 @@ public class ProxyInfo implements Parcelable { * Create a ProxyProperties that points at a PAC URL. * @hide */ - public ProxyInfo(Uri pacFileUrl) { + public ProxyInfo(@NonNull Uri pacFileUrl) { mHost = LOCAL_HOST; mPort = LOCAL_PORT; mExclusionList = LOCAL_EXCL_LIST; @@ -132,7 +142,7 @@ public class ProxyInfo implements Parcelable { * Only used in PacManager after Local Proxy is bound. * @hide */ - public ProxyInfo(Uri pacFileUrl, int localProxyPort) { + public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) { mHost = LOCAL_HOST; mPort = localProxyPort; mExclusionList = LOCAL_EXCL_LIST; @@ -159,11 +169,10 @@ public class ProxyInfo implements Parcelable { mPacFileUrl = Uri.EMPTY; } - // copy constructor instead of clone /** - * @hide + * A copy constructor to hold proxy properties. */ - public ProxyInfo(ProxyInfo source) { + public ProxyInfo(@Nullable ProxyInfo source) { if (source != null) { mHost = source.getHost(); mPort = source.getPort(); @@ -226,12 +235,13 @@ public class ProxyInfo implements Parcelable { * comma separated * @hide */ + @Nullable public String getExclusionListAsString() { return mExclusionList; } /** - * @hide + * Return true if the pattern of proxy is valid, otherwise return false. */ public boolean isValid() { if (!Uri.EMPTY.equals(mPacFileUrl)) return true; |