Merge changes I90c211dc,I4455f272

am: a0ff4efc8b

Change-Id: I502d978ff636a00979d2083c39381bf600d3d6da
This commit is contained in:
Hugo Benichi
2017-07-04 09:35:51 +00:00
committed by android-build-merger
5 changed files with 176 additions and 47 deletions

View File

@@ -582,6 +582,8 @@ public class ConnectivityManager {
/** {@hide} */
public static final int MAX_NETWORK_TYPE = TYPE_VPN;
private static final int MIN_NETWORK_TYPE = TYPE_MOBILE;
/**
* If you want to set the default network preference,you can directly
* change the networkAttributes array in framework's config.xml.
@@ -640,7 +642,7 @@ public class ConnectivityManager {
*/
@Deprecated
public static boolean isNetworkTypeValid(int networkType) {
return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
return MIN_NETWORK_TYPE <= networkType && networkType <= MAX_NETWORK_TYPE;
}
/**
@@ -653,6 +655,8 @@ public class ConnectivityManager {
*/
public static String getNetworkTypeName(int type) {
switch (type) {
case TYPE_NONE:
return "NONE";
case TYPE_MOBILE:
return "MOBILE";
case TYPE_WIFI:

View File

@@ -21,6 +21,7 @@ import android.os.Parcelable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.BitUtils;
import com.android.internal.util.Preconditions;
import java.util.Objects;
@@ -423,6 +424,11 @@ public final class NetworkCapabilities implements Parcelable {
/** @hide */
public static final int MAX_TRANSPORT = TRANSPORT_WIFI_AWARE;
/** @hide */
public static boolean isValidTransport(int transportType) {
return (MIN_TRANSPORT <= transportType) && (transportType <= MAX_TRANSPORT);
}
private static final String[] TRANSPORT_NAMES = {
"CELLULAR",
"WIFI",
@@ -446,9 +452,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public NetworkCapabilities addTransportType(int transportType) {
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
checkValidTransportType(transportType);
mTransportTypes |= 1 << transportType;
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
@@ -462,9 +466,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public NetworkCapabilities removeTransportType(int transportType) {
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
checkValidTransportType(transportType);
mTransportTypes &= ~(1 << transportType);
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
@@ -488,10 +490,7 @@ public final class NetworkCapabilities implements Parcelable {
* @return {@code true} if set on this instance.
*/
public boolean hasTransport(int transportType) {
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
return false;
}
return ((mTransportTypes & (1 << transportType)) != 0);
return isValidTransport(transportType) && ((mTransportTypes & (1 << transportType)) != 0);
}
private void combineTransportTypes(NetworkCapabilities nc) {
@@ -899,9 +898,14 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public static String transportNameOf(int transport) {
if (transport < 0 || TRANSPORT_NAMES.length <= transport) {
if (!isValidTransport(transport)) {
return "UNKNOWN";
}
return TRANSPORT_NAMES[transport];
}
private static void checkValidTransportType(int transport) {
Preconditions.checkArgument(
isValidTransport(transport), "Invalid TransportType " + transport);
}
}

View File

@@ -127,7 +127,8 @@ public class NetworkInfo implements Parcelable {
* @hide
*/
public NetworkInfo(int type, int subtype, String typeName, String subtypeName) {
if (!ConnectivityManager.isNetworkTypeValid(type)) {
if (!ConnectivityManager.isNetworkTypeValid(type)
&& type != ConnectivityManager.TYPE_NONE) {
throw new IllegalArgumentException("Invalid network type: " + type);
}
mNetworkType = type;