Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82c57776 authored by Rambo Wang's avatar Rambo Wang Committed by Automerger Merge Worker
Browse files

Merge "Restrict match conditions of TelephonyNetworkSpecifier#canBeSatisfied"...

Merge "Restrict match conditions of TelephonyNetworkSpecifier#canBeSatisfied" into rvc-dev am: 767b5871

Change-Id: If7fb76656075d1b54320902b69882a8fd64bfc12
parents d225fe54 767b5871
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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;
    }


+31 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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
@@ -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));
    }
}