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

Commit f7c97bb7 authored by Hunsuk Choi's avatar Hunsuk Choi
Browse files

Use saved ECBM config in SIM locked state

In SIM locked state, default carrier configuration is used and ECBM is disabled.
So, use saved configuration in SIM locked state as like SIM absent state.

Bug: 333945233
Test: atest EmergencyStateTrackerTest
Change-Id: Iaddbc427cdb5708b8f6423a30434e73bd4a7226f
parent bb2c1762
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ public class EmergencyStateTracker {
    @VisibleForTesting
    public interface TelephonyManagerProxy {
        int getPhoneCount();
        int getSimState(int slotIndex);
    }

    private final TelephonyManagerProxy mTelephonyManagerProxy;
@@ -242,6 +243,11 @@ public class EmergencyStateTracker {
        public int getPhoneCount() {
            return mTelephonyManager.getActiveModemCount();
        }

        @Override
        public int getSimState(int slotIndex) {
            return mTelephonyManager.getSimState(slotIndex);
        }
    }

    /**
@@ -1072,10 +1078,10 @@ public class EmergencyStateTracker {
    @VisibleForTesting
    public boolean isEmergencyCallbackModeSupported(Phone phone) {
        int subId = phone.getSubId();
        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
        int phoneId = phone.getPhoneId();
        if (!isSimReady(phoneId, subId)) {
            // If there is no SIM, refer to the saved last carrier configuration with valid
            // subscription.
            int phoneId = phone.getPhoneId();
            Boolean savedConfig = mNoSimEcbmSupported.get(Integer.valueOf(phoneId));
            if (savedConfig == null) {
                // Exceptional case such as with poor boot performance.
@@ -1788,8 +1794,8 @@ public class EmergencyStateTracker {
                    + ", ecbmSupported=" + savedConfig);
        }

        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
            // invalid subId
        if (!isSimReady(slotIndex, subId)) {
            Rlog.i(TAG, "onCarrierConfigChanged SIM not ready");
            return;
        }

@@ -1833,6 +1839,12 @@ public class EmergencyStateTracker {
                + ", ecbmSupported=" + carrierConfig);
    }

    private boolean isSimReady(int slotIndex, int subId) {
        return SubscriptionManager.isValidSubscriptionId(subId)
                && mTelephonyManagerProxy.getSimState(slotIndex)
                        == TelephonyManager.SIM_STATE_READY;
    }

    private boolean getBroadcastEmergencyCallStateChanges(Phone phone) {
        Boolean broadcast = mBroadcastEmergencyCallStateChanges.get(
                Integer.valueOf(phone.getPhoneId()));
+33 −1
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ public class EmergencyStateTrackerTest extends TelephonyTest {
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        MockitoAnnotations.initMocks(this);

        doReturn(TelephonyManager.SIM_STATE_READY)
                .when(mTelephonyManagerProxy).getSimState(anyInt());
    }

    @After
@@ -2395,6 +2398,7 @@ public class EmergencyStateTrackerTest extends TelephonyTest {
        // Verify carrier config for valid subscription
        assertTrue(testEst.isEmergencyCallbackModeSupported(phone));

        // onCarrierConfigurationChanged is not called yet.
        // SIM removed
        when(phone.getSubId()).thenReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        setEcmSupportedConfig(phone, false);
@@ -2423,7 +2427,35 @@ public class EmergencyStateTrackerTest extends TelephonyTest {
        // Verify saved config for valid subscription
        assertTrue(testEst.isEmergencyCallbackModeSupported(phone));

        // Insert SIM again, but emergency callback mode not supported
        // Insert SIM in PIN locked again, but emergency callback mode not supported
        doReturn(TelephonyManager.SIM_STATE_PIN_REQUIRED)
                .when(mTelephonyManagerProxy).getSimState(anyInt());
        when(phone.getSubId()).thenReturn(1);
        setEcmSupportedConfig(phone, false);

        // onCarrierConfigChanged with valid subscription
        carrierConfigChangeListener.onCarrierConfigChanged(
                phone.getPhoneId(), phone.getSubId(),
                TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID);

        // Verify carrier config for valid subscription in PIN locked state, saved configuration
        assertTrue(testEst.isEmergencyCallbackModeSupported(phone));

        // SIM removed again
        when(phone.getSubId()).thenReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        setEcmSupportedConfig(phone, false);

        // onCarrierConfigChanged with invalid subscription
        carrierConfigChangeListener.onCarrierConfigChanged(
                phone.getPhoneId(), phone.getSubId(),
                TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID);

        // Verify saved config for valid subscription
        assertTrue(testEst.isEmergencyCallbackModeSupported(phone));

        // Insert SIM, PIN verified, again, but emergency callback mode not supported
        doReturn(TelephonyManager.SIM_STATE_READY)
                .when(mTelephonyManagerProxy).getSimState(anyInt());
        when(phone.getSubId()).thenReturn(1);
        setEcmSupportedConfig(phone, false);