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

Commit 92afdae9 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Merge "Restrict match conditions of...

Merge "Merge "Restrict match conditions of TelephonyNetworkSpecifier#canBeSatisfied" into rvc-dev am: 767b5871 am: 82c57776" into rvc-d1-dev-plus-aosp am: cb4807f1

Change-Id: I5c6757694e0a53f49043992a9da1da35739ea1b8
parents 6d73d2e8 cb4807f1
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));
    }
}