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

Commit ecb8d8e8 authored by Pengquan Meng's avatar Pengquan Meng
Browse files

Notify Ims service state changed

This fixed the server state is not being notified correctly if the
voiceRegState is changed in ImsPhone.

Test: unit test
BUG: 63514380

Change-Id: I072ad0c3c33b64f1d7b028295a474c524e093765
parent 02558a9f
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 {