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

Commit 17c79855 authored by Sewook Seo's avatar Sewook Seo Committed by Android (Google) Code Review
Browse files

Merge "Unit test code for onCallStates change crash issue" into main

parents a5078a87 e3c7cb28
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -71,3 +71,14 @@ flag {
    bug:"359064059"
    is_exported: true
}

# OWNER=sewookseo TARGET=25Q2
flag {
    name: "pass_copied_call_state_list"
    namespace: "telephony"
    description: "To prevent passing the TelephonyRegistry's original instance to listeners in the same process"
    bug:"379126049"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+42 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.platform.test.flag.junit.SetFlagsRule;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation;
import android.telephony.BarringInfo;
import android.telephony.CallState;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityGsm;
import android.telephony.CellIdentityLte;
@@ -141,6 +142,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
    private int[] mCarrierRoamingNtnAvailableServices;
    private NtnSignalStrength mCarrierRoamingNtnSignalStrength;
    private boolean mIsSatelliteEnabled;
    private final List<List<CallState>> mCallStateList = new ArrayList<>();

    // All events contribute to TelephonyRegistry#isPhoneStatePermissionRequired
    private static final Set<Integer> READ_PHONE_STATE_EVENTS;
@@ -224,7 +226,8 @@ public class TelephonyRegistryTest extends TelephonyTest {
            TelephonyCallback.EmergencyCallbackModeListener,
            TelephonyCallback.CarrierRoamingNtnModeListener,
            TelephonyCallback.SecurityAlgorithmsListener,
            TelephonyCallback.CellularIdentifierDisclosedListener {
            TelephonyCallback.CellularIdentifierDisclosedListener,
            TelephonyCallback.CallAttributesListener {
        // This class isn't mockable to get invocation counts because the IBinder is null and
        // crashes the TelephonyRegistry. Make a cheesy verify(times()) alternative.
        public AtomicInteger invocationCount = new AtomicInteger(0);
@@ -374,6 +377,12 @@ public class TelephonyRegistryTest extends TelephonyTest {
        public void onCellularIdentifierDisclosedChanged(CellularIdentifierDisclosure disclosure) {
            invocationCount.incrementAndGet();
        }

        @Override
        public void onCallStatesChanged(List<CallState> callStateList) {
            invocationCount.incrementAndGet();
            mCallStateList.add(callStateList);
        }
    }

    public class MySatelliteStateChangeListener implements ISatelliteStateChangeListener {
@@ -448,6 +457,7 @@ public class TelephonyRegistryTest extends TelephonyTest {
            mPhysicalChannelConfigs = null;
        }
        mCellLocation = null;
        mCallStateList.clear();
        super.tearDown();
    }

@@ -1771,6 +1781,37 @@ public class TelephonyRegistryTest extends TelephonyTest {
        assertTrue(Arrays.equals(mCarrierRoamingNtnAvailableServices, services));
    }

    @Test
    @EnableFlags(Flags.FLAG_PASS_COPIED_CALL_STATE_LIST)
    public void testNotifyPreciseCallStateChangedInProcess() {
        doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
        doReturn(0/*slotIndex*/).when(mMockSubInfo).getSimSlotIndex();

        final int subId = 1;
        int[] events = {TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED};

        mTelephonyRegistry.listenWithEventList(false, false, subId, mContext.getOpPackageName(),
                mContext.getAttributionTag(), mTelephonyCallback.callback, events, false);
        processAllMessages();

        int[] callState = {0, 5, 0};
        String[] imsCallId = {"0", "1", "0"};
        int[] imsServiceType = {0, 1, 0};
        int[] imsCallType = {0, 1, 0};
        int[] callState2 = {0, 1, 0};
        mTelephonyRegistry.notifyPreciseCallState(
                /*phoneId*/ 0, subId, callState, imsCallId, imsServiceType, imsCallType);
        mTelephonyRegistry.notifyPreciseCallState(
                /*phoneId*/ 0, subId, callState2, imsCallId, imsServiceType, imsCallType);
        processAllMessages();

        assertEquals(2, mCallStateList.size());
        //make sure the call state is from the first report(callState).
        assertEquals(5, mCallStateList.get(0).getFirst().getCallState());
        //make sure the call state is from the second report(callState2).
        assertEquals(1, mCallStateList.get(1).getFirst().getCallState());
    }

    @Test
    @EnableFlags(Flags.FLAG_CARRIER_ROAMING_NB_IOT_NTN)
    public void testNotifyCarrierRoamingNtnSignalStrengthChanged() {