Merge "Clarify docs, sanity check roaming state."

This commit is contained in:
Jeff Sharkey
2017-11-27 21:19:40 +00:00
committed by Gerrit Code Review
3 changed files with 21 additions and 13 deletions

View File

@@ -31,16 +31,10 @@ import java.util.Objects;
import java.util.StringJoiner; import java.util.StringJoiner;
/** /**
* Representation of the capabilities of a network. This object serves two * Representation of the capabilities of an active network. Instances are
* purposes: * typically obtained through
* <ul>
* <li>An expression of the current capabilities of an active network, typically
* expressed through
* {@link NetworkCallback#onCapabilitiesChanged(Network, NetworkCapabilities)} * {@link NetworkCallback#onCapabilitiesChanged(Network, NetworkCapabilities)}
* or {@link ConnectivityManager#getNetworkCapabilities(Network)}. * or {@link ConnectivityManager#getNetworkCapabilities(Network)}.
* <li>An expression of the future capabilities of a desired network, typically
* expressed through {@link NetworkRequest}.
* </ul>
* <p> * <p>
* This replaces the old {@link ConnectivityManager#TYPE_MOBILE} method of * This replaces the old {@link ConnectivityManager#TYPE_MOBILE} method of
* network selection. Rather than indicate a need for Wi-Fi because an * network selection. Rather than indicate a need for Wi-Fi because an
@@ -79,7 +73,7 @@ public final class NetworkCapabilities implements Parcelable {
*/ */
public void clearAll() { public void clearAll() {
mNetworkCapabilities = mTransportTypes = 0; mNetworkCapabilities = mTransportTypes = 0;
mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0; mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = LINK_BANDWIDTH_UNSPECIFIED;
mNetworkSpecifier = null; mNetworkSpecifier = null;
mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED; mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED;
} }
@@ -359,6 +353,7 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* Sets all the capabilities set on this {@code NetworkCapability} instance. * Sets all the capabilities set on this {@code NetworkCapability} instance.
* This overwrites any existing capabilities.
* *
* @hide * @hide
*/ */
@@ -582,6 +577,7 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* Sets all the transports set on this {@code NetworkCapability} instance. * Sets all the transports set on this {@code NetworkCapability} instance.
* This overwrites any existing transports.
* *
* @hide * @hide
*/ */
@@ -780,7 +776,7 @@ public final class NetworkCapabilities implements Parcelable {
* Signal strength. This is a signed integer, and higher values indicate better signal. * Signal strength. This is a signed integer, and higher values indicate better signal.
* The exact units are bearer-dependent. For example, Wi-Fi uses RSSI. * The exact units are bearer-dependent. For example, Wi-Fi uses RSSI.
*/ */
private int mSignalStrength; private int mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED;
/** /**
* Sets the signal strength. This is a signed integer, with higher values indicating a stronger * Sets the signal strength. This is a signed integer, with higher values indicating a stronger

View File

@@ -16,6 +16,7 @@
package android.net; package android.net;
import android.annotation.NonNull;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
@@ -32,7 +33,7 @@ public class NetworkRequest implements Parcelable {
* The {@link NetworkCapabilities} that define this request. * The {@link NetworkCapabilities} that define this request.
* @hide * @hide
*/ */
public final NetworkCapabilities networkCapabilities; public final @NonNull NetworkCapabilities networkCapabilities;
/** /**
* Identifies the request. NetworkRequests should only be constructed by * Identifies the request. NetworkRequests should only be constructed by
@@ -307,7 +308,7 @@ public class NetworkRequest implements Parcelable {
return 0; return 0;
} }
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(networkCapabilities, flags); networkCapabilities.writeToParcel(dest, flags);
dest.writeInt(legacyType); dest.writeInt(legacyType);
dest.writeInt(requestId); dest.writeInt(requestId);
dest.writeString(type.name()); dest.writeString(type.name());
@@ -315,7 +316,7 @@ public class NetworkRequest implements Parcelable {
public static final Creator<NetworkRequest> CREATOR = public static final Creator<NetworkRequest> CREATOR =
new Creator<NetworkRequest>() { new Creator<NetworkRequest>() {
public NetworkRequest createFromParcel(Parcel in) { public NetworkRequest createFromParcel(Parcel in) {
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null); NetworkCapabilities nc = NetworkCapabilities.CREATOR.createFromParcel(in);
int legacyType = in.readInt(); int legacyType = in.readInt();
int requestId = in.readInt(); int requestId = in.readInt();
Type type = Type.valueOf(in.readString()); // IllegalArgumentException if invalid. Type type = Type.valueOf(in.readString()); // IllegalArgumentException if invalid.

View File

@@ -18,6 +18,7 @@ package android.net;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.Slog;
/** /**
* Snapshot of network state. * Snapshot of network state.
@@ -43,6 +44,16 @@ public class NetworkState implements Parcelable {
this.network = network; this.network = network;
this.subscriberId = subscriberId; this.subscriberId = subscriberId;
this.networkId = networkId; this.networkId = networkId;
// This object is an atomic view of a network, so the various components
// should always agree on roaming state.
if (networkInfo != null && networkCapabilities != null) {
if (networkInfo.isRoaming() == networkCapabilities
.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING)) {
Slog.wtf("NetworkState", "Roaming state disagreement between " + networkInfo
+ " and " + networkCapabilities);
}
}
} }
public NetworkState(Parcel in) { public NetworkState(Parcel in) {