Merge "Revert "ConnectivityManager: allow usage of TYPE_NONE"" am: a4fcd1a2b7 am: 8ad104e62c

am: bdcebe39e6

Change-Id: I428cb473221a403e3c78cbc5d1224d46747ec315
This commit is contained in:
Roland Levillain 2017-07-04 11:46:56 +00:00 • committed by android-build-merger
commit 93caca72db
3 changed files with 38 additions and 156 deletions

View file

@ -582,8 +582,6 @@ 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.
@ -642,7 +640,7 @@ public class ConnectivityManager {
*/
@Deprecated
public static boolean isNetworkTypeValid(int networkType) {
return MIN_NETWORK_TYPE <= networkType && networkType <= MAX_NETWORK_TYPE;
return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
}
/**
@ -655,8 +653,6 @@ 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,7 +21,6 @@ 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;
@ -430,11 +429,6 @@ public final class NetworkCapabilities implements Parcelable {
/** @hide */
public static final int MAX_TRANSPORT = TRANSPORT_LOWPAN;
/** @hide */
public static boolean isValidTransport(int transportType) {
return (MIN_TRANSPORT <= transportType) && (transportType <= MAX_TRANSPORT);
}
private static final String[] TRANSPORT_NAMES = {
"CELLULAR",
"WIFI",
@ -459,7 +453,9 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public NetworkCapabilities addTransportType(int transportType) {
checkValidTransportType(transportType);
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
mTransportTypes |= 1 << transportType;
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
@ -473,7 +469,9 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public NetworkCapabilities removeTransportType(int transportType) {
checkValidTransportType(transportType);
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
mTransportTypes &= ~(1 << transportType);
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
@ -497,7 +495,10 @@ public final class NetworkCapabilities implements Parcelable {
* @return {@code true} if set on this instance.
*/
public boolean hasTransport(int transportType) {
return isValidTransport(transportType) && ((mTransportTypes & (1 << transportType)) != 0);
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
return false;
}
return ((mTransportTypes & (1 << transportType)) != 0);
}
private void combineTransportTypes(NetworkCapabilities nc) {
@ -905,14 +906,9 @@ public final class NetworkCapabilities implements Parcelable {
* @hide
*/
public static String transportNameOf(int transport) {
if (!isValidTransport(transport)) {
if (transport < 0 || TRANSPORT_NAMES.length <= transport) {
return "UNKNOWN";
}
return TRANSPORT_NAMES[transport];
}
private static void checkValidTransportType(int transport) {
Preconditions.checkArgument(
isValidTransport(transport), "Invalid TransportType " + transport);
}
}

View file

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