Loading core/java/android/net/TelephonyNetworkSpecifier.java +4 −3 Original line number Diff line number Diff line Loading @@ -98,9 +98,10 @@ public final class TelephonyNetworkSpecifier extends NetworkSpecifier implements /** @hide */ @Override public boolean canBeSatisfiedBy(NetworkSpecifier other) { // Any generic requests should be satisfied by a specific telephony network. // For simplicity, we treat null same as MatchAllNetworkSpecifier return equals(other) || other == null || other instanceof MatchAllNetworkSpecifier; // Although the only caller, NetworkCapabilities, already handled the case of // MatchAllNetworkSpecifier, we do it again here in case the API will be used by others. // TODO(b/154959809): consider implementing bi-directional specifier instead. return equals(other) || other instanceof MatchAllNetworkSpecifier; } Loading tests/net/java/android/net/TelephonyNetworkSpecifierTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -19,7 +19,10 @@ package android.net; import static com.android.testutils.ParcelUtilsKt.assertParcelSane; 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 androidx.test.filters.SmallTest; Loading @@ -32,6 +35,7 @@ import org.junit.Test; @SmallTest public class TelephonyNetworkSpecifierTest { private static final int TEST_SUBID = 5; private static final String TEST_SSID = "Test123"; /** * Validate that IllegalArgumentException will be thrown if build TelephonyNetworkSpecifier Loading Loading @@ -79,4 +83,31 @@ public class TelephonyNetworkSpecifierTest { .build(); 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)); } } Loading
core/java/android/net/TelephonyNetworkSpecifier.java +4 −3 Original line number Diff line number Diff line Loading @@ -98,9 +98,10 @@ public final class TelephonyNetworkSpecifier extends NetworkSpecifier implements /** @hide */ @Override public boolean canBeSatisfiedBy(NetworkSpecifier other) { // Any generic requests should be satisfied by a specific telephony network. // For simplicity, we treat null same as MatchAllNetworkSpecifier return equals(other) || other == null || other instanceof MatchAllNetworkSpecifier; // Although the only caller, NetworkCapabilities, already handled the case of // MatchAllNetworkSpecifier, we do it again here in case the API will be used by others. // TODO(b/154959809): consider implementing bi-directional specifier instead. return equals(other) || other instanceof MatchAllNetworkSpecifier; } Loading
tests/net/java/android/net/TelephonyNetworkSpecifierTest.java +31 −0 Original line number Diff line number Diff line Loading @@ -19,7 +19,10 @@ package android.net; import static com.android.testutils.ParcelUtilsKt.assertParcelSane; 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 androidx.test.filters.SmallTest; Loading @@ -32,6 +35,7 @@ import org.junit.Test; @SmallTest public class TelephonyNetworkSpecifierTest { private static final int TEST_SUBID = 5; private static final String TEST_SSID = "Test123"; /** * Validate that IllegalArgumentException will be thrown if build TelephonyNetworkSpecifier Loading Loading @@ -79,4 +83,31 @@ public class TelephonyNetworkSpecifierTest { .build(); 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)); } }