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

Commit 250fb97f authored by Honggang Luo's avatar Honggang Luo Committed by takeshi.tanigawa
Browse files

Fix "No service" is not shown without SIM

"Emergency calls only" is shown instead of "No service" in statusbar
even if within the area specified by
"config_display_no_service_when_sim_unready" in the following cases.

1. Power on the device without SIM.
   When updateSpnDisplay() is called, the country code may not be
   updated yet. So the plmn keeps as "Emergency calls only".

2. Remove SIM card from the device which supports hot swap SIM.
   After removing the SIM, the UiccApplication becomes null.
   If UiccApplication is null, mIsSimReady is not updated to false.
   "No service" is not shown when mIsSimReady is true,
   so the problem occur.

How to fix the problem:
1. When last known country code is changed, update plmn by
   updateSpnDisplay().
2. If UiccApplication is null, update mIsSimReady to false.

Test: manual - "No service" is shown in lock screen and statusbar
without SIM.
Test: auto - Passed ServiceStateTrackerTest.
Bug: 151881495

Change-Id: I8115fdd0b4760069a309a55ddd8b579785d7ce46
parent 53811b99
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -539,6 +539,8 @@ public class ServiceStateTracker extends Handler {
    /** To identify whether EVENT_SIM_READY is received or not */
    private boolean mIsSimReady = false;

    private String mLastKnownNetworkCountry = "";

    @UnsupportedAppUsage
    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
@@ -564,6 +566,12 @@ public class ServiceStateTracker extends Handler {
            } else if (intent.getAction().equals(ACTION_RADIO_OFF)) {
                mAlarmSwitch = false;
                powerOffRadioSafely();
            } else if (intent.getAction().equals(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED)) {
                String lastKnownNetworkCountry = intent.getStringExtra(
                        TelephonyManager.EXTRA_LAST_KNOWN_NETWORK_COUNTRY);
                if (!mLastKnownNetworkCountry.equals(lastKnownNetworkCountry)) {
                    updateSpnDisplay();
                }
            }
        }
    };
@@ -685,6 +693,9 @@ public class ServiceStateTracker extends Handler {
        filter = new IntentFilter();
        filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        context.registerReceiver(mIntentReceiver, filter);
        filter = new IntentFilter();
        filter.addAction(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
        context.registerReceiver(mIntentReceiver, filter);

        mPhone.notifyOtaspChanged(TelephonyManager.OTASP_UNINITIALIZED);

@@ -1173,8 +1184,8 @@ public class ServiceStateTracker extends Handler {
                    mCdnr.updateEfFromUsim(null /* Usim */);
                }
                onUpdateIccAvailability();
                if (mUiccApplcation != null
                        && mUiccApplcation.getState() != AppState.APPSTATE_READY) {
                if (mUiccApplcation == null
                        || mUiccApplcation.getState() != AppState.APPSTATE_READY) {
                    mIsSimReady = false;
                    updateSpnDisplay();
                }
@@ -2866,9 +2877,9 @@ public class ServiceStateTracker extends Handler {
        if (ArrayUtils.isEmpty(countriesWithNoService)) {
            return false;
        }
        String currentCountry = mLocaleTracker.getCurrentCountry();
        mLastKnownNetworkCountry = mLocaleTracker.getLastKnownCountryIso();
        for (String country : countriesWithNoService) {
            if (country.equalsIgnoreCase(currentCountry)) {
            if (country.equalsIgnoreCase(mLastKnownNetworkCountry)) {
                return true;
            }
        }
+3 −3
Original line number Diff line number Diff line
@@ -2541,7 +2541,7 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    @Test
    public void testShouldForceDisplayNoService_forceBasedOnLocale() {
        // set up unaffected locale (US) and clear the resource
        doReturn("us").when(mLocaleTracker).getCurrentCountry();
        doReturn("us").when(mLocaleTracker).getLastKnownCountryIso();
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_display_no_service_when_sim_unready,
                new String[0]);
@@ -2551,11 +2551,11 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_display_no_service_when_sim_unready,
                new String[]{"de"});
        doReturn("us").when(mLocaleTracker).getCurrentCountry();
        doReturn("us").when(mLocaleTracker).getLastKnownCountryIso();
        assertFalse(sst.shouldForceDisplayNoService());

        // mock the locale to Germany
        doReturn("de").when(mLocaleTracker).getCurrentCountry();
        doReturn("de").when(mLocaleTracker).getLastKnownCountryIso();
        assertTrue(sst.shouldForceDisplayNoService());
    }