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

Commit 8aeca63b authored by joonhunshin's avatar joonhunshin Committed by Joonhun Shin
Browse files

Fix to update wfc mode in roaming network

CarrierConfigManager may be null while device is booting, so ImsManager.setWfcMode() will not be called. However, the last cached roaming state is still changed. Even if ImsPhone receives the roaming state update again and CarrierConfigManager becomes available, ImsManager.setWfcMode() will not be called again because the cached roaming state already reflects the change.

Bug: 317298331
Test: atest ImsPhoneTest
Test: manul test (Panther, AT&T SIM)
      changed carrier config editable_wfc_roaming_mode_bool as true
      enabled screen PIN lock
      changed WFC prefered mode
      Checked text based log after device reboot
Change-Id: I632b195d4f8a25d4aeb5322b20fcafa6980ae60c
parent b7e2699c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -55,3 +55,10 @@ flag {
    description: "For DSDA devices, controls whether the existing call will be dropped when an incoming call on a different sub is answered, when either sub does not support hold capability."
    bug:"315993953"
}

flag {
    name: "update_roaming_state_to_set_wfc_mode"
    namespace: "telephony"
    description: "This flag updates roaming state to set wfc mode"
    bug:"317298331"
}
+6 −1
Original line number Diff line number Diff line
@@ -2436,7 +2436,9 @@ public class ImsPhone extends ImsPhoneBase {

        if (mCT.getState() == PhoneConstants.State.IDLE) {
            if (DBG) logd("updateRoamingState now: " + newRoamingState);
            if (!mFeatureFlags.updateRoamingStateToSetWfcMode()) {
                mLastKnownRoamingState = newRoamingState;
            }
            CarrierConfigManager configManager = (CarrierConfigManager)
                    getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
            // Don't set wfc mode if carrierconfig has not loaded. It will be set by GsmCdmaPhone
@@ -2445,6 +2447,9 @@ public class ImsPhone extends ImsPhoneBase {
                    configManager.getConfigForSubId(getSubId()))) {
                ImsManager imsManager = mImsManagerFactory.create(mContext, mPhoneId);
                imsManager.setWfcMode(imsManager.getWfcMode(newRoamingState), newRoamingState);
                if (mFeatureFlags.updateRoamingStateToSetWfcMode()) {
                    mLastKnownRoamingState = newRoamingState;
                }
            }
        } else {
            if (DBG) logd("updateRoamingState postponed: " + newRoamingState);
+32 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.verify;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
@@ -818,6 +819,37 @@ public class ImsPhoneTest extends TelephonyTest {
        verify(mImsManager, times(1)).setWfcMode(anyInt(), anyBoolean());
    }

    @Test
    @SmallTest
    public void testSetWfcModeInRoaming() throws Exception {
        doReturn(true).when(mFeatureFlags).updateRoamingStateToSetWfcMode();
        doReturn(PhoneConstants.State.IDLE).when(mImsCT).getState();
        doReturn(true).when(mPhone).isRadioOn();

        // Set CarrierConfigManager to be invalid
        doReturn(null).when(mContext).getSystemService(Context.CARRIER_CONFIG_SERVICE);

        //Roaming - data registration only on LTE
        Message m = getServiceStateChangedMessage(getServiceStateDataOnly(
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE, ServiceState.STATE_IN_SERVICE, true));
        // Inject the message synchronously instead of waiting for the thread to do it.
        mImsPhoneUT.handleMessage(m);
        m.recycle();

        verify(mImsManager, never()).setWfcMode(anyInt(), eq(true));

        // Set CarrierConfigManager to be valid
        doReturn(mCarrierConfigManager).when(mContext)
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);

        m = getServiceStateChangedMessage(getServiceStateDataOnly(
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE, ServiceState.STATE_IN_SERVICE, true));
        mImsPhoneUT.handleMessage(m);
        m.recycle();

        verify(mImsManager, times(1)).setWfcMode(anyInt(), eq(true));
    }

    @Test
    public void testNonNullTrackersInImsPhone() throws Exception {
        assertNotNull(mImsPhoneUT.getEmergencyNumberTracker());