Merge "Expose IpConfiguration and ProxyInfo APIs"
am: c2df0b68c4
Change-Id: I7fa9b282ca87f0c442e267acb8424f6aeed5d3a0
This commit is contained in:
@@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
package android.net;
|
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.annotation.UnsupportedAppUsage;
|
||||||
import android.net.StaticIpConfiguration;
|
import android.net.StaticIpConfiguration;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@@ -27,13 +31,17 @@ import java.util.Objects;
|
|||||||
* A class representing a configured network.
|
* A class representing a configured network.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class IpConfiguration implements Parcelable {
|
@SystemApi
|
||||||
|
public final class IpConfiguration implements Parcelable {
|
||||||
private static final String TAG = "IpConfiguration";
|
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 {
|
public enum IpAssignment {
|
||||||
/* Use statically configured IP settings. Configuration can be accessed
|
/* Use statically configured IP settings. Configuration can be accessed
|
||||||
* with staticIpConfiguration */
|
* with staticIpConfiguration */
|
||||||
@UnsupportedAppUsage
|
|
||||||
STATIC,
|
STATIC,
|
||||||
/* Use dynamically configured IP settings */
|
/* Use dynamically configured IP settings */
|
||||||
DHCP,
|
DHCP,
|
||||||
@@ -42,14 +50,19 @@ public class IpConfiguration implements Parcelable {
|
|||||||
UNASSIGNED
|
UNASSIGNED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
public IpAssignment ipAssignment;
|
public IpAssignment ipAssignment;
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
public StaticIpConfiguration staticIpConfiguration;
|
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 {
|
public enum ProxySettings {
|
||||||
/* No proxy is to be used. Any existing proxy settings
|
/* No proxy is to be used. Any existing proxy settings
|
||||||
* should be cleared. */
|
* should be cleared. */
|
||||||
@UnsupportedAppUsage
|
|
||||||
NONE,
|
NONE,
|
||||||
/* Use statically configured proxy. Configuration can be accessed
|
/* Use statically configured proxy. Configuration can be accessed
|
||||||
* with httpProxy. */
|
* with httpProxy. */
|
||||||
@@ -62,8 +75,10 @@ public class IpConfiguration implements Parcelable {
|
|||||||
PAC
|
PAC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
public ProxySettings proxySettings;
|
public ProxySettings proxySettings;
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public ProxyInfo httpProxy;
|
public ProxyInfo httpProxy;
|
||||||
|
|
||||||
@@ -83,6 +98,7 @@ public class IpConfiguration implements Parcelable {
|
|||||||
init(IpAssignment.UNASSIGNED, ProxySettings.UNASSIGNED, null, null);
|
init(IpAssignment.UNASSIGNED, ProxySettings.UNASSIGNED, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public IpConfiguration(IpAssignment ipAssignment,
|
public IpConfiguration(IpAssignment ipAssignment,
|
||||||
ProxySettings proxySettings,
|
ProxySettings proxySettings,
|
||||||
@@ -91,7 +107,7 @@ public class IpConfiguration implements Parcelable {
|
|||||||
init(ipAssignment, proxySettings, staticIpConfiguration, httpProxy);
|
init(ipAssignment, proxySettings, staticIpConfiguration, httpProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IpConfiguration(IpConfiguration source) {
|
public IpConfiguration(@NonNull IpConfiguration source) {
|
||||||
this();
|
this();
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
init(source.ipAssignment, source.proxySettings,
|
init(source.ipAssignment, source.proxySettings,
|
||||||
@@ -99,35 +115,35 @@ public class IpConfiguration implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IpAssignment getIpAssignment() {
|
public @NonNull IpAssignment getIpAssignment() {
|
||||||
return ipAssignment;
|
return ipAssignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIpAssignment(IpAssignment ipAssignment) {
|
public void setIpAssignment(@NonNull IpAssignment ipAssignment) {
|
||||||
this.ipAssignment = ipAssignment;
|
this.ipAssignment = ipAssignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StaticIpConfiguration getStaticIpConfiguration() {
|
public @Nullable StaticIpConfiguration getStaticIpConfiguration() {
|
||||||
return staticIpConfiguration;
|
return staticIpConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStaticIpConfiguration(StaticIpConfiguration staticIpConfiguration) {
|
public void setStaticIpConfiguration(@Nullable StaticIpConfiguration staticIpConfiguration) {
|
||||||
this.staticIpConfiguration = staticIpConfiguration;
|
this.staticIpConfiguration = staticIpConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxySettings getProxySettings() {
|
public @NonNull ProxySettings getProxySettings() {
|
||||||
return proxySettings;
|
return proxySettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxySettings(ProxySettings proxySettings) {
|
public void setProxySettings(@NonNull ProxySettings proxySettings) {
|
||||||
this.proxySettings = proxySettings;
|
this.proxySettings = proxySettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyInfo getHttpProxy() {
|
public @Nullable ProxyInfo getHttpProxy() {
|
||||||
return httpProxy;
|
return httpProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHttpProxy(ProxyInfo httpProxy) {
|
public void setHttpProxy(@Nullable ProxyInfo httpProxy) {
|
||||||
this.httpProxy = httpProxy;
|
this.httpProxy = httpProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,13 +191,19 @@ public class IpConfiguration implements Parcelable {
|
|||||||
83 * httpProxy.hashCode();
|
83 * httpProxy.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the Parcelable interface */
|
/**
|
||||||
|
* Implement the Parcelable interface
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
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(ipAssignment.name());
|
||||||
dest.writeString(proxySettings.name());
|
dest.writeString(proxySettings.name());
|
||||||
dest.writeParcelable(staticIpConfiguration, flags);
|
dest.writeParcelable(staticIpConfiguration, flags);
|
||||||
@@ -189,7 +211,7 @@ public class IpConfiguration implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Implement the Parcelable interface */
|
/** Implement the Parcelable interface */
|
||||||
public static final @android.annotation.NonNull Creator<IpConfiguration> CREATOR =
|
public static final @NonNull Creator<IpConfiguration> CREATOR =
|
||||||
new Creator<IpConfiguration>() {
|
new Creator<IpConfiguration>() {
|
||||||
public IpConfiguration createFromParcel(Parcel in) {
|
public IpConfiguration createFromParcel(Parcel in) {
|
||||||
IpConfiguration config = new IpConfiguration();
|
IpConfiguration config = new IpConfiguration();
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.annotation.UnsupportedAppUsage;
|
import android.annotation.UnsupportedAppUsage;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -88,6 +89,15 @@ public class ProxyInfo implements Parcelable {
|
|||||||
return new ProxyInfo(pacUri);
|
return new ProxyInfo(pacUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Create a ProxyProperties that points at a HTTP Proxy.
|
||||||
* @hide
|
* @hide
|
||||||
@@ -105,7 +115,7 @@ public class ProxyInfo implements Parcelable {
|
|||||||
* Create a ProxyProperties that points at a PAC URL.
|
* Create a ProxyProperties that points at a PAC URL.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public ProxyInfo(Uri pacFileUrl) {
|
public ProxyInfo(@NonNull Uri pacFileUrl) {
|
||||||
mHost = LOCAL_HOST;
|
mHost = LOCAL_HOST;
|
||||||
mPort = LOCAL_PORT;
|
mPort = LOCAL_PORT;
|
||||||
mExclusionList = LOCAL_EXCL_LIST;
|
mExclusionList = LOCAL_EXCL_LIST;
|
||||||
@@ -132,7 +142,7 @@ public class ProxyInfo implements Parcelable {
|
|||||||
* Only used in PacManager after Local Proxy is bound.
|
* Only used in PacManager after Local Proxy is bound.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public ProxyInfo(Uri pacFileUrl, int localProxyPort) {
|
public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) {
|
||||||
mHost = LOCAL_HOST;
|
mHost = LOCAL_HOST;
|
||||||
mPort = localProxyPort;
|
mPort = localProxyPort;
|
||||||
mExclusionList = LOCAL_EXCL_LIST;
|
mExclusionList = LOCAL_EXCL_LIST;
|
||||||
@@ -159,11 +169,10 @@ public class ProxyInfo implements Parcelable {
|
|||||||
mPacFileUrl = Uri.EMPTY;
|
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) {
|
if (source != null) {
|
||||||
mHost = source.getHost();
|
mHost = source.getHost();
|
||||||
mPort = source.getPort();
|
mPort = source.getPort();
|
||||||
@@ -226,12 +235,13 @@ public class ProxyInfo implements Parcelable {
|
|||||||
* comma separated
|
* comma separated
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getExclusionListAsString() {
|
public String getExclusionListAsString() {
|
||||||
return mExclusionList;
|
return mExclusionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* Return true if the pattern of proxy is valid, otherwise return false.
|
||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
if (!Uri.EMPTY.equals(mPacFileUrl)) return true;
|
if (!Uri.EMPTY.equals(mPacFileUrl)) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user