Merge "Assign the bit calculation as long to prevent overflow"
This commit is contained in:
@@ -592,8 +592,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
// TODO: Consider adding unwanted capabilities to the public API and mention this
|
// TODO: Consider adding unwanted capabilities to the public API and mention this
|
||||||
// in the documentation.
|
// in the documentation.
|
||||||
checkValidCapability(capability);
|
checkValidCapability(capability);
|
||||||
mNetworkCapabilities |= 1 << capability;
|
mNetworkCapabilities |= 1L << capability;
|
||||||
mUnwantedNetworkCapabilities &= ~(1 << capability); // remove from unwanted capability list
|
// remove from unwanted capability list
|
||||||
|
mUnwantedNetworkCapabilities &= ~(1L << capability);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,8 +613,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public void addUnwantedCapability(@NetCapability int capability) {
|
public void addUnwantedCapability(@NetCapability int capability) {
|
||||||
checkValidCapability(capability);
|
checkValidCapability(capability);
|
||||||
mUnwantedNetworkCapabilities |= 1 << capability;
|
mUnwantedNetworkCapabilities |= 1L << capability;
|
||||||
mNetworkCapabilities &= ~(1 << capability); // remove from requested capabilities
|
mNetworkCapabilities &= ~(1L << capability); // remove from requested capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -626,7 +627,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public @NonNull NetworkCapabilities removeCapability(@NetCapability int capability) {
|
public @NonNull NetworkCapabilities removeCapability(@NetCapability int capability) {
|
||||||
checkValidCapability(capability);
|
checkValidCapability(capability);
|
||||||
final long mask = ~(1 << capability);
|
final long mask = ~(1L << capability);
|
||||||
mNetworkCapabilities &= mask;
|
mNetworkCapabilities &= mask;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -641,7 +642,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public @NonNull NetworkCapabilities removeUnwantedCapability(@NetCapability int capability) {
|
public @NonNull NetworkCapabilities removeUnwantedCapability(@NetCapability int capability) {
|
||||||
checkValidCapability(capability);
|
checkValidCapability(capability);
|
||||||
mUnwantedNetworkCapabilities &= ~(1 << capability);
|
mUnwantedNetworkCapabilities &= ~(1L << capability);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,14 +710,14 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public boolean hasCapability(@NetCapability int capability) {
|
public boolean hasCapability(@NetCapability int capability) {
|
||||||
return isValidCapability(capability)
|
return isValidCapability(capability)
|
||||||
&& ((mNetworkCapabilities & (1 << capability)) != 0);
|
&& ((mNetworkCapabilities & (1L << capability)) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public boolean hasUnwantedCapability(@NetCapability int capability) {
|
public boolean hasUnwantedCapability(@NetCapability int capability) {
|
||||||
return isValidCapability(capability)
|
return isValidCapability(capability)
|
||||||
&& ((mUnwantedNetworkCapabilities & (1 << capability)) != 0);
|
&& ((mUnwantedNetworkCapabilities & (1L << capability)) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
|
|||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
||||||
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_BIP;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
|
||||||
@@ -89,6 +90,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_SUPL;
|
|||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||||
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_VSIM;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_WIFI_P2P;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_WIFI_P2P;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_XCAP;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_XCAP;
|
||||||
import static android.net.NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION;
|
import static android.net.NetworkCapabilities.REDACT_FOR_ACCESS_FINE_LOCATION;
|
||||||
@@ -3042,10 +3044,11 @@ public class ConnectivityServiceTest {
|
|||||||
// Verify NOT_RESTRICTED is set appropriately
|
// Verify NOT_RESTRICTED is set appropriately
|
||||||
final NetworkCapabilities nc = new NetworkRequest.Builder().addCapability(capability)
|
final NetworkCapabilities nc = new NetworkRequest.Builder().addCapability(capability)
|
||||||
.build().networkCapabilities;
|
.build().networkCapabilities;
|
||||||
if (capability == NET_CAPABILITY_CBS || capability == NET_CAPABILITY_DUN ||
|
if (capability == NET_CAPABILITY_CBS || capability == NET_CAPABILITY_DUN
|
||||||
capability == NET_CAPABILITY_EIMS || capability == NET_CAPABILITY_FOTA ||
|
|| capability == NET_CAPABILITY_EIMS || capability == NET_CAPABILITY_FOTA
|
||||||
capability == NET_CAPABILITY_IA || capability == NET_CAPABILITY_IMS ||
|
|| capability == NET_CAPABILITY_IA || capability == NET_CAPABILITY_IMS
|
||||||
capability == NET_CAPABILITY_RCS || capability == NET_CAPABILITY_XCAP
|
|| capability == NET_CAPABILITY_RCS || capability == NET_CAPABILITY_XCAP
|
||||||
|
|| capability == NET_CAPABILITY_VSIM || capability == NET_CAPABILITY_BIP
|
||||||
|| capability == NET_CAPABILITY_ENTERPRISE) {
|
|| capability == NET_CAPABILITY_ENTERPRISE) {
|
||||||
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
|
assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
|
||||||
} else {
|
} else {
|
||||||
@@ -3155,6 +3158,8 @@ public class ConnectivityServiceTest {
|
|||||||
tryNetworkFactoryRequests(NET_CAPABILITY_INTERNET);
|
tryNetworkFactoryRequests(NET_CAPABILITY_INTERNET);
|
||||||
tryNetworkFactoryRequests(NET_CAPABILITY_TRUSTED);
|
tryNetworkFactoryRequests(NET_CAPABILITY_TRUSTED);
|
||||||
tryNetworkFactoryRequests(NET_CAPABILITY_NOT_VPN);
|
tryNetworkFactoryRequests(NET_CAPABILITY_NOT_VPN);
|
||||||
|
tryNetworkFactoryRequests(NET_CAPABILITY_VSIM);
|
||||||
|
tryNetworkFactoryRequests(NET_CAPABILITY_BIP);
|
||||||
// Skipping VALIDATED and CAPTIVE_PORTAL as they're disallowed.
|
// Skipping VALIDATED and CAPTIVE_PORTAL as they're disallowed.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user