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

Commit 4f4d7c5c authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Android (Google) Code Review
Browse files

Merge "Add test case for notifyDisplayInfoChanged on wrong subId." into rvc-dev

parents 03d293cf 14113826
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTI
import static android.telephony.PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE;
import static android.telephony.PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED;
import static android.telephony.PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED;
import static android.telephony.SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED;
import static android.telephony.TelephonyManager.RADIO_POWER_OFF;
import static android.telephony.TelephonyManager.RADIO_POWER_ON;
@@ -39,6 +41,8 @@ import android.telephony.PhoneCapability;
import android.telephony.PhoneStateListener;
import android.telephony.PreciseDataConnectionState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.test.suitebuilder.annotation.SmallTest;
@@ -65,6 +69,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
    private TelephonyRegistry mTelephonyRegistry;
    private PhoneCapability mPhoneCapability;
    private int mActiveSubId;
    private TelephonyDisplayInfo mTelephonyDisplayInfo;
    private int mSrvccState = -1;
    private int mRadioPowerState = RADIO_POWER_UNAVAILABLE;
    // All events contribute to TelephonyRegistry.ENFORCE_PHONE_STATE_PERMISSION_MASK
@@ -142,6 +147,10 @@ public class TelephonyRegistryTest extends TelephonyTest {
        public void onPreciseDataConnectionStateChanged(PreciseDataConnectionState preciseState) {
            invocationCount.incrementAndGet();
        }
        @Override
        public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfo) {
            mTelephonyDisplayInfo = displayInfo;
        }
    }

    private void addTelephonyRegistryService() {
@@ -418,6 +427,28 @@ public class TelephonyRegistryTest extends TelephonyTest {
        }
    }

    @Test
    public void testNotifyDisplayInfoChanged() {
        mContext.sendBroadcast(new Intent(ACTION_DEFAULT_SUBSCRIPTION_CHANGED)
                .putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, 12)
                .putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, 0));
        processAllMessages();
        mTelephonyRegistry.listenForSubscriber(2, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mPhoneStateListener.callback,
                PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED, false);

        // 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);

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

    private void assertSecurityExceptionThrown(int event, String eventDesc) {
        try {
            mTelephonyRegistry.listen(mContext.getOpPackageName(),