Merge "Allow test+other networks to have specifiers"

This commit is contained in:
Remi NGUYEN VAN
2022-02-14 05:31:20 +00:00
committed by Gerrit Code Review
2 changed files with 36 additions and 19 deletions

View File

@@ -1536,9 +1536,12 @@ public final class NetworkCapabilities implements Parcelable {
*/
public @NonNull NetworkCapabilities setNetworkSpecifier(
@NonNull NetworkSpecifier networkSpecifier) {
if (networkSpecifier != null && Long.bitCount(mTransportTypes) != 1) {
throw new IllegalStateException("Must have a single transport specified to use " +
"setNetworkSpecifier");
if (networkSpecifier != null
// Transport can be test, or test + a single other transport
&& mTransportTypes != (1L << TRANSPORT_TEST)
&& Long.bitCount(mTransportTypes & ~(1L << TRANSPORT_TEST)) != 1) {
throw new IllegalStateException("Must have a single non-test transport specified to "
+ "use setNetworkSpecifier");
}
mNetworkSpecifier = networkSpecifier;