Revert "ConnectivityManager: allow usage of TYPE_NONE"
This CL is breaking some internal builds.
This reverts commit 0b7642a820.
Change-Id: Ie79214808d84c73f54a525f515b4c90a3fb23542
This commit is contained in:
@@ -579,8 +579,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.
|
||||
@@ -638,7 +636,7 @@ public class ConnectivityManager {
|
||||
* validate a network type.
|
||||
*/
|
||||
public static boolean isNetworkTypeValid(int networkType) {
|
||||
return MIN_NETWORK_TYPE <= networkType && networkType <= MAX_NETWORK_TYPE;
|
||||
return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,8 +649,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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user