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

Commit 46584ac2 authored by SongFerngWang's avatar SongFerngWang Committed by Automerger Merge Worker
Browse files

Add testcase for DisplayInfo Compatibility am: 92edb302

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/15785732

Change-Id: I46f7778a2567c880ad87a95cd5591454048559ad
parents 1f4cc5bc 92edb302
Loading
Loading
Loading
Loading
+82 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -273,7 +274,6 @@ public class TelephonyRegistryTest extends TelephonyTest {
        assertEquals(phoneCapability, mPhoneCapability);
    }


    @Test @SmallTest
    public void testActiveDataSubChanged() {
        // mTelephonyRegistry.listen with notifyNow = true should trigger callback immediately.
@@ -616,9 +616,13 @@ public class TelephonyRegistryTest extends TelephonyTest {
        int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED};
        mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported(
                anyString(), any())).thenReturn(true);
        TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED);

        // Notify with invalid subId on default phone. Should NOT trigger callback.
        TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo(0, 0);
        mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo);
        processAllMessages();
        assertEquals(null, mTelephonyDisplayInfo);
@@ -629,6 +633,82 @@ public class TelephonyRegistryTest extends TelephonyTest {
        assertEquals(displayInfo, mTelephonyDisplayInfo);
    }

    @Test
    public void testDisplayInfoCompatibility() {
        mContext.sendBroadcast(new Intent(ACTION_DEFAULT_SUBSCRIPTION_CHANGED)
                .putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 12)
                .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0));
        processAllMessages();
        int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED};
        mTelephonyRegistry.listenWithEventList(2, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported(
                anyString(), any())).thenReturn(false);
        TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED);
        TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE);

        // Notify with invalid subId on default phone. Should NOT trigger callback.
        mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo);
        processAllMessages();
        assertEquals(null, mTelephonyDisplayInfo);

        // Notify with the matching subId on default phone. Should trigger callback.
        mTelephonyRegistry.notifyDisplayInfoChanged(0, 2, displayInfo);
        processAllMessages();
        assertEquals(expectDisplayInfo, mTelephonyDisplayInfo);
    }

    @Test
    public void testDisplayInfoCompatibility_moreCallingPackages() {
        mContext.sendBroadcast(new Intent(ACTION_DEFAULT_SUBSCRIPTION_CHANGED)
                .putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 12)
                .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0));
        processAllMessages();
        int[] events = {TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED};
        TelephonyDisplayInfo displayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED);
        TelephonyDisplayInfo expectDisplayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE);
        TelephonyCallback telephonyCallback2 = new TelephonyCallbackWrapper() {
            @Override
            public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfoNotify) {
                assertEquals(displayInfo, displayInfoNotify);
            }
        };
        Executor mSimpleExecutor2 = new Executor() {
            @Override
            public void execute(Runnable r) {
                r.run();
            }
        };
        telephonyCallback2.init(mSimpleExecutor2);
        mTelephonyRegistry.listenWithEventList(2, "pkg1",
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        mTelephonyRegistry.listenWithEventList(2, "pkg2",
                mContext.getAttributionTag(), telephonyCallback2.callback, events, false);
        when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported(
                eq("pkg1"), any())).thenReturn(false);
        when(mMockConfigurationProvider.isDisplayInfoNrAdvancedSupported(
                eq("pkg2"), any())).thenReturn(true);


        // Notify with invalid subId on default phone. Should NOT trigger callback.
        mTelephonyRegistry.notifyDisplayInfoChanged(0, INVALID_SUBSCRIPTION_ID, displayInfo);
        processAllMessages();
        assertEquals(null, mTelephonyDisplayInfo);

        // Notify with the matching subId on default phone. Should trigger callback.
        mTelephonyRegistry.notifyDisplayInfoChanged(0, 2, displayInfo);
        processAllMessages();
        assertEquals(expectDisplayInfo, mTelephonyDisplayInfo);
    }

    @Test
    public void testNotifyCellLocationForSubscriberByUserSwitched() throws RemoteException {
        final int phoneId = 0;