Merge "Fix API in CaptivePortal, StaticIpConfiguration" am: cf0f380f4e am: fb943d00ca

am: 69528af3db

Change-Id: Icda65fe4a009a754b6a1a763d402820652d55391
This commit is contained in:
Remi NGUYEN VAN
2019-04-03 02:28:11 -07:00
committed by android-build-merger
2 changed files with 90 additions and 23 deletions

View File

@@ -137,6 +137,8 @@ public class CaptivePortal implements Parcelable {
/**
* Log a captive portal login event.
* @param eventId one of the CAPTIVE_PORTAL_LOGIN_* constants in metrics_constants.proto.
* @param packageName captive portal application package name.
* @hide
*/
@SystemApi

View File

@@ -22,6 +22,7 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.net.shared.InetAddressUtils;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -33,20 +34,19 @@ import java.util.Objects;
/**
* Class that describes static IP configuration.
*
* This class is different from LinkProperties because it represents
* <p>This class is different from {@link LinkProperties} because it represents
* configuration intent. The general contract is that if we can represent
* a configuration here, then we should be able to configure it on a network.
* The intent is that it closely match the UI we have for configuring networks.
*
* In contrast, LinkProperties represents current state. It is much more
* <p>In contrast, {@link LinkProperties} represents current state. It is much more
* expressive. For example, it supports multiple IP addresses, multiple routes,
* stacked interfaces, and so on. Because LinkProperties is so expressive,
* using it to represent configuration intent as well as current state causes
* problems. For example, we could unknowingly save a configuration that we are
* not in fact capable of applying, or we could save a configuration that the
* UI cannot display, which has the potential for malicious code to hide
* hostile or unexpected configuration from the user: see, for example,
* http://b/12663469 and http://b/16893413 .
* hostile or unexpected configuration from the user.
*
* @hide
*/
@@ -54,24 +54,24 @@ import java.util.Objects;
@TestApi
public final class StaticIpConfiguration implements Parcelable {
/** @hide */
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@Nullable
public LinkAddress ipAddress;
/** @hide */
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@Nullable
public InetAddress gateway;
/** @hide */
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@NonNull
public final ArrayList<InetAddress> dnsServers;
/** @hide */
@UnsupportedAppUsage
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
@Nullable
public String domains;
public StaticIpConfiguration() {
dnsServers = new ArrayList<InetAddress>();
dnsServers = new ArrayList<>();
}
public StaticIpConfiguration(@Nullable StaticIpConfiguration source) {
@@ -92,32 +92,96 @@ public final class StaticIpConfiguration implements Parcelable {
domains = null;
}
/**
* Get the static IP address included in the configuration.
*/
public @Nullable LinkAddress getIpAddress() {
return ipAddress;
}
public void setIpAddress(@Nullable LinkAddress ipAddress) {
this.ipAddress = ipAddress;
}
/**
* Get the gateway included in the configuration.
*/
public @Nullable InetAddress getGateway() {
return gateway;
}
public void setGateway(@Nullable InetAddress gateway) {
this.gateway = gateway;
}
/**
* Get the DNS servers included in the configuration.
*/
public @NonNull List<InetAddress> getDnsServers() {
return dnsServers;
}
/**
* Get a {@link String} listing in priority order of the comma separated domains to search when
* resolving host names on the link.
*/
public @Nullable String getDomains() {
return domains;
}
public void setDomains(@Nullable String newDomains) {
domains = newDomains;
/**
* Helper class to build a new instance of {@link StaticIpConfiguration}.
*/
public static final class Builder {
private LinkAddress mIpAddress;
private InetAddress mGateway;
private Iterable<InetAddress> mDnsServers;
private String mDomains;
/**
* Set the IP address to be included in the configuration; null by default.
* @return The {@link Builder} for chaining.
*/
public @NonNull Builder setIpAddress(@Nullable LinkAddress ipAddress) {
mIpAddress = ipAddress;
return this;
}
/**
* Set the address of the gateway to be included in the configuration; null by default.
* @return The {@link Builder} for chaining.
*/
public @NonNull Builder setGateway(@Nullable InetAddress gateway) {
mGateway = gateway;
return this;
}
/**
* Set the addresses of the DNS servers included in the configuration; empty by default.
* @return The {@link Builder} for chaining.
*/
public @NonNull Builder setDnsServers(@NonNull Iterable<InetAddress> dnsServers) {
mDnsServers = dnsServers;
return this;
}
/**
* Sets the DNS domain search path to be used on the link; null by default.
* @param newDomains A {@link String} containing the comma separated domains to search when
* resolving host names on this link, in priority order.
* @return The {@link Builder} for chaining.
*/
public @NonNull Builder setDomains(@Nullable String newDomains) {
mDomains = newDomains;
return this;
}
/**
* Create a {@link StaticIpConfiguration} from the parameters in this {@link Builder}.
* @return The newly created StaticIpConfiguration.
*/
public @NonNull StaticIpConfiguration build() {
final StaticIpConfiguration config = new StaticIpConfiguration();
config.ipAddress = mIpAddress;
config.gateway = mGateway;
for (InetAddress server : mDnsServers) {
config.dnsServers.add(server);
}
config.domains = mDomains;
return config;
}
}
/**
@@ -129,16 +193,17 @@ public final class StaticIpConfiguration implements Parcelable {
/**
* Returns the network routes specified by this object. Will typically include a
* directly-connected route for the IP address's local subnet and a default route. If the
* default gateway is not covered by the directly-connected route, it will also contain a host
* route to the gateway as well. This configuration is arguably invalid, but it used to work
* in K and earlier, and other OSes appear to accept it.
* directly-connected route for the IP address's local subnet and a default route.
* @param iface Interface to include in the routes.
*/
public @NonNull List<RouteInfo> getRoutes(@Nullable String iface) {
List<RouteInfo> routes = new ArrayList<RouteInfo>(3);
if (ipAddress != null) {
RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface);
routes.add(connectedRoute);
// If the default gateway is not covered by the directly-connected route, also add a
// host route to the gateway as well. This configuration is arguably invalid, but it
// used to work in K and earlier, and other OSes appear to accept it.
if (gateway != null && !connectedRoute.matches(gateway)) {
routes.add(RouteInfo.makeHostRoute(gateway, iface));
}