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

Commit f7a27e50 authored by Pengquan Meng's avatar Pengquan Meng Committed by Android (Google) Code Review
Browse files

Merge "Use locale to decide out-of-service message" into qt-r1-dev

parents 0a84e5c7 ab2abcb5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class LocaleTracker extends Handler {
    /** Count of invalid cell info we've got so far. Will reset once we get a successful one */
    private int mFailCellInfoCount;

    /** The ISO-3166 code of device's current country */
    /** The ISO-3166 two-letter code of device's current country */
    @Nullable
    private String mCurrentCountryIso;

+23 −3
Original line number Diff line number Diff line
@@ -2631,9 +2631,7 @@ public class ServiceStateTracker extends Handler {
                showPlmn = true;

                // Force display no service
                final boolean forceDisplayNoService = mPhone.getContext().getResources().getBoolean(
                        com.android.internal.R.bool.config_display_no_service_when_sim_unready)
                        && !mIsSimReady;
                final boolean forceDisplayNoService = shouldForceDisplayNoService() && !mIsSimReady;
                if (!forceDisplayNoService && Phone.isEmergencyCallOnly()) {
                    // No service but emergency call allowed
                    plmn = Resources.getSystem().
@@ -2744,6 +2742,28 @@ public class ServiceStateTracker extends Handler {
        log("updateSpnDisplayLegacy-");
    }

    /**
     * Checks whether force to display "no service" to the user based on the current country.
     *
     * This method should only be used when SIM is unready.
     *
     * @return {@code True} if "no service" should be displayed.
     */
    public boolean shouldForceDisplayNoService() {
        String[] countriesWithNoService = mPhone.getContext().getResources().getStringArray(
                com.android.internal.R.array.config_display_no_service_when_sim_unready);
        if (ArrayUtils.isEmpty(countriesWithNoService)) {
            return false;
        }
        String currentCountry = mLocaleTracker.getCurrentCountry();
        for (String country : countriesWithNoService) {
            if (country.equalsIgnoreCase(currentCountry)) {
                return true;
            }
        }
        return false;
    }

    protected void setPowerStateToDesired() {
        if (DBG) {
            String tmpLog = "mDeviceShuttingDown=" + mDeviceShuttingDown +
+2 −3
Original line number Diff line number Diff line
@@ -377,9 +377,8 @@ public class CarrierDisplayNameResolver {
        String plmn = null;
        boolean isSimReady = mPhone.getUiccCardApplication() != null
                && mPhone.getUiccCardApplication().getState() == AppState.APPSTATE_READY;
        boolean forceDisplayNoService = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_display_no_service_when_sim_unready)
                && !isSimReady;
        boolean forceDisplayNoService =
                mPhone.getServiceStateTracker().shouldForceDisplayNoService() && !isSimReady;
        ServiceState ss = getServiceState();
        if (ss.getVoiceRegState() == ServiceState.STATE_POWER_OFF
                || forceDisplayNoService || !Phone.isEmergencyCallOnly()) {
+25 −3
Original line number Diff line number Diff line
@@ -299,9 +299,10 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        mBundle.putStringArray(CarrierConfigManager.KEY_PNN_OVERRIDE_STRING_ARRAY,
                CARRIER_CONFIG_PNN);

        // Do not force display "No service" when sim is not ready
        mContextFixture.putBooleanResource(
                com.android.internal.R.bool.config_display_no_service_when_sim_unready, false);
        // Do not force display "No service" when sim is not ready in any locales
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_display_no_service_when_sim_unready,
                new String[0]);

        logd("ServiceStateTrackerTest -Setup!");
    }
@@ -2279,6 +2280,27 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertThat(b.getBoolean(TelephonyIntents.EXTRA_SHOW_PLMN)).isTrue();
    }

    @Test
    public void testShouldForceDisplayNoService_forceBasedOnLocale() {
        // set up unaffected locale (US) and clear the resource
        doReturn("us").when(mLocaleTracker).getCurrentCountry();
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_display_no_service_when_sim_unready,
                new String[0]);
        assertFalse(sst.shouldForceDisplayNoService());

        // set up the resource to include Germany
        mContextFixture.putStringArrayResource(
                com.android.internal.R.array.config_display_no_service_when_sim_unready,
                new String[]{"de"});
        doReturn("us").when(mLocaleTracker).getCurrentCountry();
        assertFalse(sst.shouldForceDisplayNoService());

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

    private Bundle getExtrasFromLastSpnUpdateIntent() {
        // Verify the spn update notification was sent
        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);