Merge "Restrict match conditions of TelephonyNetworkSpecifier#canBeSatisfied" into rvc-dev
This commit is contained in:
@@ -98,9 +98,10 @@ public final class TelephonyNetworkSpecifier extends NetworkSpecifier implements
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
public boolean canBeSatisfiedBy(NetworkSpecifier other) {
|
||||||
// Any generic requests should be satisfied by a specific telephony network.
|
// Although the only caller, NetworkCapabilities, already handled the case of
|
||||||
// For simplicity, we treat null same as MatchAllNetworkSpecifier
|
// MatchAllNetworkSpecifier, we do it again here in case the API will be used by others.
|
||||||
return equals(other) || other == null || other instanceof MatchAllNetworkSpecifier;
|
// TODO(b/154959809): consider implementing bi-directional specifier instead.
|
||||||
|
return equals(other) || other instanceof MatchAllNetworkSpecifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,10 @@ package android.net;
|
|||||||
import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
|
import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.net.wifi.WifiNetworkSpecifier;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
@@ -32,6 +35,7 @@ import org.junit.Test;
|
|||||||
@SmallTest
|
@SmallTest
|
||||||
public class TelephonyNetworkSpecifierTest {
|
public class TelephonyNetworkSpecifierTest {
|
||||||
private static final int TEST_SUBID = 5;
|
private static final int TEST_SUBID = 5;
|
||||||
|
private static final String TEST_SSID = "Test123";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that IllegalArgumentException will be thrown if build TelephonyNetworkSpecifier
|
* Validate that IllegalArgumentException will be thrown if build TelephonyNetworkSpecifier
|
||||||
@@ -79,4 +83,31 @@ public class TelephonyNetworkSpecifierTest {
|
|||||||
.build();
|
.build();
|
||||||
assertParcelSane(specifier, 1 /* fieldCount */);
|
assertParcelSane(specifier, 1 /* fieldCount */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the behavior of method canBeSatisfiedBy().
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanBeSatisfiedBy() {
|
||||||
|
final TelephonyNetworkSpecifier tns1 = new TelephonyNetworkSpecifier.Builder()
|
||||||
|
.setSubscriptionId(TEST_SUBID)
|
||||||
|
.build();
|
||||||
|
final TelephonyNetworkSpecifier tns2 = new TelephonyNetworkSpecifier.Builder()
|
||||||
|
.setSubscriptionId(TEST_SUBID)
|
||||||
|
.build();
|
||||||
|
final WifiNetworkSpecifier wns = new WifiNetworkSpecifier.Builder()
|
||||||
|
.setSsid(TEST_SSID)
|
||||||
|
.build();
|
||||||
|
final MatchAllNetworkSpecifier mans = new MatchAllNetworkSpecifier();
|
||||||
|
|
||||||
|
// Test equality
|
||||||
|
assertEquals(tns1, tns2);
|
||||||
|
assertTrue(tns1.canBeSatisfiedBy(tns1));
|
||||||
|
assertTrue(tns1.canBeSatisfiedBy(tns2));
|
||||||
|
|
||||||
|
// Test other edge cases.
|
||||||
|
assertFalse(tns1.canBeSatisfiedBy(null));
|
||||||
|
assertFalse(tns1.canBeSatisfiedBy(wns));
|
||||||
|
assertTrue(tns1.canBeSatisfiedBy(mans));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user