Use locale to decide out-of-service message

Instead of using the resource with mcc/mnc overlay (which doesn't work
when no SIM is inserted), we use LocaleTracker and a new resource which
is a list of the countries where the out-of-service message is
no-service. (e.g. Germany does not allow emergency calls without a SIM).

Bug: 126651774
Test: atest ServiceStateTrackerTest
Merged-In: I1887f3c72a594b61f45867332e1c4bce62b41612
Change-Id: I1887f3c72a594b61f45867332e1c4bce62b41612
(cherry picked from commit e8aab0f2bda68b5a3258e16251ed22f3aa078ee3)
diff --git a/src/java/com/android/internal/telephony/LocaleTracker.java b/src/java/com/android/internal/telephony/LocaleTracker.java
index fbbcb3b..dc8ad32 100755
--- a/src/java/com/android/internal/telephony/LocaleTracker.java
+++ b/src/java/com/android/internal/telephony/LocaleTracker.java
@@ -106,7 +106,7 @@
     /** 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;
 
diff --git a/src/java/com/android/internal/telephony/ServiceStateTracker.java b/src/java/com/android/internal/telephony/ServiceStateTracker.java
index 4e6bdda..69de7a2 100755
--- a/src/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -2626,9 +2626,7 @@
                 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().
@@ -2739,6 +2737,28 @@
         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 +
diff --git a/src/java/com/android/internal/telephony/cdnr/CarrierDisplayNameResolver.java b/src/java/com/android/internal/telephony/cdnr/CarrierDisplayNameResolver.java
index 6b85792..87ee39d 100644
--- a/src/java/com/android/internal/telephony/cdnr/CarrierDisplayNameResolver.java
+++ b/src/java/com/android/internal/telephony/cdnr/CarrierDisplayNameResolver.java
@@ -377,9 +377,8 @@
         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()) {
diff --git a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
index e4c7c11..8f03425 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java
@@ -299,9 +299,10 @@
         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 @@
         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);