Extract PLMN from Voice CellIdentity for Locale

The locale tracker needs to know what MCCs are seen,
and it doesn't matter whether the device registers
successfully on a network, simply camping on a tower
(even for emergency services only) is a strong indicator
of the current country. This change tries to use a
registered network operator from the IRadio::getOperator
command, but if that fails, it falls back to using the
PLMN from the voice operator which is reported even when
the device only camps for emergency services.

Bug: 136036974
Test: atest LocaleTrackerTest
Change-Id: I634aeb9fb95cc361b21b79f209a90dddf18f5896
diff --git a/src/java/com/android/internal/telephony/ServiceStateTracker.java b/src/java/com/android/internal/telephony/ServiceStateTracker.java
index 61690a4..ae0f327 100755
--- a/src/java/com/android/internal/telephony/ServiceStateTracker.java
+++ b/src/java/com/android/internal/telephony/ServiceStateTracker.java
@@ -3328,8 +3328,17 @@
 
             tm.setNetworkOperatorNumericForPhone(mPhone.getPhoneId(), operatorNumeric);
 
-            if (isInvalidOperatorNumeric(operatorNumeric)) {
-                if (DBG) log("operatorNumeric " + operatorNumeric + " is invalid");
+            // If the OPERATOR command hasn't returned a valid operator, but if the device has
+            // camped on a cell either to attempt registration or for emergency services, then
+            // for purposes of setting the locale, we don't care if registration fails or is
+            // incomplete.
+            String localeOperator = isInvalidOperatorNumeric(operatorNumeric)
+                    && (mCellIdentity != null)
+                    ? mCellIdentity.getMccString() + mCellIdentity.getMncString()
+                    : operatorNumeric;
+
+            if (isInvalidOperatorNumeric(localeOperator)) {
+                if (DBG) log("localeOperator " + localeOperator + " is invalid");
                 // Passing empty string is important for the first update. The initial value of
                 // operator numeric in locale tracker is null. The async update will allow getting
                 // cell info from the modem instead of using the cached one.
@@ -3341,10 +3350,10 @@
 
                 // Update IDD.
                 if (!mPhone.isPhoneTypeGsm()) {
-                    setOperatorIdd(operatorNumeric);
+                    setOperatorIdd(localeOperator);
                 }
 
-                mLocaleTracker.updateOperatorNumeric(operatorNumeric);
+                mLocaleTracker.updateOperatorNumeric(localeOperator);
             }
 
             tm.setNetworkRoamingForPhone(mPhone.getPhoneId(),