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

Commit 0a1b7c2b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Improves service state changed notification"

parents 04d8d2ff b60225e8
Loading
Loading
Loading
Loading
+21 −1
Original line number Original line Diff line number Diff line
@@ -211,6 +211,7 @@ public class ServiceStateTracker extends Handler {
    protected static final int EVENT_PHONE_TYPE_SWITCHED               = 50;
    protected static final int EVENT_PHONE_TYPE_SWITCHED               = 50;
    protected static final int EVENT_RADIO_POWER_FROM_CARRIER          = 51;
    protected static final int EVENT_RADIO_POWER_FROM_CARRIER          = 51;
    protected static final int EVENT_SIM_NOT_INSERTED                  = 52;
    protected static final int EVENT_SIM_NOT_INSERTED                  = 52;
    protected static final int EVENT_IMS_SERVICE_STATE_CHANGED         = 53;


    protected static final String TIMEZONE_PROPERTY = "persist.sys.timezone";
    protected static final String TIMEZONE_PROPERTY = "persist.sys.timezone";


@@ -1346,6 +1347,15 @@ public class ServiceStateTracker extends Handler {
                updateSpnDisplay();
                updateSpnDisplay();
                break;
                break;


            case EVENT_IMS_SERVICE_STATE_CHANGED:
                if (DBG) log("EVENT_IMS_SERVICE_STATE_CHANGED");
                // IMS state will only affect the merged service state if the service state of
                // GsmCdma phone is not STATE_IN_SERVICE.
                if (mSS.getState() != ServiceState.STATE_IN_SERVICE) {
                    mPhone.notifyServiceStateChanged(mPhone.getServiceState());
                }
                break;

            //CDMA
            //CDMA
            case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
            case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
                handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource());
                handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource());
@@ -2536,6 +2546,11 @@ public class ServiceStateTracker extends Handler {
        }
        }
    }
    }


    /** Called when the service state of ImsPhone is changed. */
    public void onImsServiceStateChanged() {
        sendMessage(obtainMessage(EVENT_IMS_SERVICE_STATE_CHANGED));
    }

    public void setImsRegistrationState(boolean registered) {
    public void setImsRegistrationState(boolean registered) {
        log("ImsRegistrationState - registered : " + registered);
        log("ImsRegistrationState - registered : " + registered);


@@ -2798,6 +2813,8 @@ public class ServiceStateTracker extends Handler {
            mRejectCode = mNewRejectCode;
            mRejectCode = mNewRejectCode;
        }
        }


        ServiceState oldMergedSS = mPhone.getServiceState();

        // swap mSS and mNewSS to put new state in mSS
        // swap mSS and mNewSS to put new state in mSS
        ServiceState tss = mSS;
        ServiceState tss = mSS;
        mSS = mNewSS;
        mSS = mNewSS;
@@ -2909,7 +2926,10 @@ public class ServiceStateTracker extends Handler {
            setRoamingType(mSS);
            setRoamingType(mSS);
            log("Broadcasting ServiceState : " + mSS);
            log("Broadcasting ServiceState : " + mSS);
            // notify using PhoneStateListener and the legacy intent ACTION_SERVICE_STATE_CHANGED
            // notify using PhoneStateListener and the legacy intent ACTION_SERVICE_STATE_CHANGED
            mPhone.notifyServiceStateChanged(mSS);
            // notify service state changed only if the merged service state is changed.
            if (!oldMergedSS.equals(mPhone.getServiceState())) {
                mPhone.notifyServiceStateChanged(mPhone.getServiceState());
            }


            // insert into ServiceStateProvider. This will trigger apps to wake through JobScheduler
            // insert into ServiceStateProvider. This will trigger apps to wake through JobScheduler
            mPhone.getContext().getContentResolver()
            mPhone.getContext().getContentResolver()
+14 −2
Original line number Original line Diff line number Diff line
@@ -258,9 +258,21 @@ public class ImsPhone extends ImsPhoneBase {
        return mSS;
        return mSS;
    }
    }


    /* package */ void setServiceState(int state) {
    @VisibleForTesting
    public void setServiceState(int state) {
        boolean isVoiceRegStateChanged = false;

        synchronized (this) {
            isVoiceRegStateChanged = mSS.getVoiceRegState() != state;
            mSS.setVoiceRegState(state);
            mSS.setVoiceRegState(state);
        }
        updateDataServiceState();
        updateDataServiceState();

        if (isVoiceRegStateChanged) {
            if (mDefaultPhone.getServiceStateTracker() != null) {
                mDefaultPhone.getServiceStateTracker().onImsServiceStateChanged();
            }
        }
    }
    }


    @Override
    @Override
+25 −0
Original line number Original line Diff line number Diff line
@@ -331,6 +331,31 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertFalse(sst.isImsRegistered());
        assertFalse(sst.isImsRegistered());
    }
    }


    @Test
    public void testOnImsServiceStateChanged() {
        // The service state of GsmCdmaPhone is STATE_OUT_OF_SERVICE, and IMS is unregistered.
        ServiceState ss = new ServiceState();
        ss.setVoiceRegState(ServiceState.STATE_OUT_OF_SERVICE);
        sst.mSS = ss;

        sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_IMS_SERVICE_STATE_CHANGED));
        waitForMs(200);

        // The listener will be notified that the service state was changed.
        verify(mPhone).notifyServiceStateChanged(any(ServiceState.class));

        // The service state of GsmCdmaPhone is STATE_IN_SERVICE, and IMS is registered.
        ss = new ServiceState();
        ss.setVoiceRegState(ServiceState.STATE_IN_SERVICE);
        sst.mSS = ss;

        sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_IMS_SERVICE_STATE_CHANGED));
        waitForMs(200);

        // Nothing happened because the IMS service state was not affected the merged service state.
        verify(mPhone, times(1)).notifyServiceStateChanged(any(ServiceState.class));
    }

    @Test
    @Test
    @MediumTest
    @MediumTest
    public void testSignalStrength() {
    public void testSignalStrength() {
+21 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,8 @@ import static org.mockito.Matchers.nullable;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


@@ -47,6 +49,7 @@ import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.support.test.filters.FlakyTest;
import android.support.test.filters.FlakyTest;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import com.android.ims.ImsCallProfile;
import com.android.ims.ImsCallProfile;
@@ -484,6 +487,24 @@ public class ImsPhoneTest extends TelephonyTest {
        assertEquals(msg, messageArgumentCaptor.getValue().obj);
        assertEquals(msg, messageArgumentCaptor.getValue().obj);
    }
    }


    @Test
    public void testShouldSendNotificationWhenServiceStateIsChanged() {
        mImsPhoneUT.setServiceState(ServiceState.STATE_IN_SERVICE);
        reset(mSST);

        mImsPhoneUT.setServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        verify(mSST).onImsServiceStateChanged();
    }

    @Test
    public void testShouldNotSendNotificationWhenServiceStateIsNotChanged() {
        mImsPhoneUT.setServiceState(ServiceState.STATE_IN_SERVICE);
        reset(mSST);

        mImsPhoneUT.setServiceState(ServiceState.STATE_IN_SERVICE);
        verify(mSST, never()).onImsServiceStateChanged();
    }

    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testCellBarring() throws Exception {
    public void testCellBarring() throws Exception {