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

Commit e3131665 authored by Pengquan Meng's avatar Pengquan Meng Committed by android-build-merger
Browse files

Merge "Notify Ims service state changed" into oc-dr1-dev

am: f9704088

Change-Id: I0322788d68acaf6a20d65e04693454d32dc49846
parents f0aba61e f9704088
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -253,14 +253,24 @@ public class ImsPhone extends ImsPhoneBase {
    }

    @Override
    public ServiceState
    getServiceState() {
    public ServiceState getServiceState() {
        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);
        }
        updateDataServiceState();

        // Notifies the service state to the listeners. The service state combined from ImsPhone
        // and GsmCdmaPhone, it may be changed when the service state in ImsPhone is changed.
        if (isVoiceRegStateChanged) {
            mNotifier.notifyServiceState(mDefaultPhone);
        }
    }

    @Override
+23 −0
Original line number 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.doReturn;
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.verify;

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

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

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

        mImsPhoneUT.setServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        verify(mNotifier).notifyServiceState(mPhone);
    }

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

        mImsPhoneUT.setServiceState(ServiceState.STATE_IN_SERVICE);
        verify(mNotifier, never()).notifyServiceState(mPhone);
    }

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