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

Commit 69f0e4c2 authored by Hui Wang's avatar Hui Wang Committed by Android (Google) Code Review
Browse files

Merge "Do not register event until entering the state" into udc-dev

parents 680faec2 f61a4aac
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -115,6 +115,21 @@ public final class CellBroadcastConfigTracker extends StateMachine {
     * The default state.
     */
    private class DefaultState extends State {
        @Override
        public void enter() {
            mPhone.registerForRadioOffOrNotAvailable(getHandler(), EVENT_RADIO_OFF, null);
            mPhone.getContext().getSystemService(SubscriptionManager.class)
                    .addOnSubscriptionsChangedListener(new HandlerExecutor(getHandler()),
                            mSubChangedListener);
        }

        @Override
        public void exit() {
            mPhone.unregisterForRadioOffOrNotAvailable(getHandler());
            mPhone.getContext().getSystemService(SubscriptionManager.class)
                    .removeOnSubscriptionsChangedListener(mSubChangedListener);
        }

        @Override
        public boolean processMessage(Message msg) {
            boolean retVal = HANDLED;
@@ -384,11 +399,6 @@ public final class CellBroadcastConfigTracker extends StateMachine {
        mPhone = phone;
        mSubId = mPhone.getSubId();

        mPhone.registerForRadioOffOrNotAvailable(getHandler(), EVENT_RADIO_OFF, null);
        mPhone.getContext().getSystemService(SubscriptionManager.class)
                .addOnSubscriptionsChangedListener(new HandlerExecutor(getHandler()),
                        mSubChangedListener);

        addState(mDefaultState);
        addState(mIdleState, mDefaultState);
        addState(mGsmConfiguringState, mDefaultState);
@@ -401,11 +411,14 @@ public final class CellBroadcastConfigTracker extends StateMachine {
    /**
     * create a CellBroadcastConfigTracker instance for the phone
     */
    public static CellBroadcastConfigTracker make(Phone phone, Handler handler) {
    public static CellBroadcastConfigTracker make(Phone phone, Handler handler,
            boolean shouldStart) {
        CellBroadcastConfigTracker tracker = handler == null
                ? new CellBroadcastConfigTracker(phone)
                : new CellBroadcastConfigTracker(phone, handler);
        if (shouldStart) {
            tracker.start();
        }
        return tracker;
    }

+1 −1
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ public class GsmCdmaPhone extends Phone {

    @VisibleForTesting
    public CellBroadcastConfigTracker mCellBroadcastConfigTracker =
            CellBroadcastConfigTracker.make(this, null);
            CellBroadcastConfigTracker.make(this, null, true);

    private boolean mIsNullCipherAndIntegritySupported = false;

+27 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
@@ -66,7 +67,7 @@ public final class CellBroadcastConfigTrackerTest extends TelephonyTest {
        mSpyCi = spy(mSimulatedCommands);
        mPhone = new GsmCdmaPhone(mContext, mSpyCi, mNotifier, true, 0,
            PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory, (c, p) -> mImsManager);
        mTracker = CellBroadcastConfigTracker.make(mPhone, mPhone);
        mTracker = CellBroadcastConfigTracker.make(mPhone, mPhone, true);
        mPhone.mCellBroadcastConfigTracker = mTracker;
        processAllMessages();
    }
@@ -487,6 +488,31 @@ public final class CellBroadcastConfigTrackerTest extends TelephonyTest {
                mergeRangesAsNeeded(ranges2));
    }

    @Test
    public void testMakeCellBroadcastConfigTracker() {
        Phone phone = spy(mPhone);
        CellBroadcastConfigTracker tracker = CellBroadcastConfigTracker.make(phone, phone, false);
        processAllMessages();

        verify(phone, never()).registerForRadioOffOrNotAvailable(any(), anyInt(), any());
        verify(mSubscriptionManager, never()).addOnSubscriptionsChangedListener(
                any(), eq(tracker.mSubChangedListener));

        tracker.start();
        processAllMessages();

        verify(phone, times(1)).registerForRadioOffOrNotAvailable(any(), anyInt(), any());
        verify(mSubscriptionManager, times(1)).addOnSubscriptionsChangedListener(
                any(), eq(tracker.mSubChangedListener));

        tracker = CellBroadcastConfigTracker.make(phone, phone, true);
        processAllMessages();

        verify(phone, times(2)).registerForRadioOffOrNotAvailable(any(), anyInt(), any());
        verify(mSubscriptionManager, times(1)).addOnSubscriptionsChangedListener(
                any(), eq(tracker.mSubChangedListener));
    }

    private void mockCommandInterface() {
        doNothing().when(mSpyCi).setGsmBroadcastConfig(any(), any());
        doNothing().when(mSpyCi).setGsmBroadcastActivation(anyBoolean(), any());