Set country code even when device is not registered on network

Extends the functionality of getNetworkCountryIso to support
no SIM/no service case. When no SIM/no service, it returns
the country code of nearby network (unregistered but cell info
is available to the device).

Test: Manual
Bug: 64335394
Merged-In: If7fc06d5a7430262b2e3ab13a7377eb829595113
Change-Id: If7fc06d5a7430262b2e3ab13a7377eb829595113
(cherry picked from commit a7c7c98321ff22166c5aa311002cbcdbba5e4263)
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 678ab99..1219185 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -91,6 +91,7 @@
 import com.android.internal.telephony.DefaultPhoneNotifier;
 import com.android.internal.telephony.ITelephony;
 import com.android.internal.telephony.IccCard;
+import com.android.internal.telephony.LocaleTracker;
 import com.android.internal.telephony.MccTable;
 import com.android.internal.telephony.NetworkScanRequestTracker;
 import com.android.internal.telephony.OperatorInfo;
@@ -101,9 +102,9 @@
 import com.android.internal.telephony.ProxyController;
 import com.android.internal.telephony.RIL;
 import com.android.internal.telephony.RILConstants;
+import com.android.internal.telephony.ServiceStateTracker;
 import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.TelephonyPermissions;
-import com.android.internal.telephony.TelephonyProperties;
 import com.android.internal.telephony.euicc.EuiccConnector;
 import com.android.internal.telephony.uicc.IccIoResult;
 import com.android.internal.telephony.uicc.IccUtils;
@@ -1703,6 +1704,8 @@
         final long identity = Binder.clearCallingIdentity();
         try {
             final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
+            // Todo: fix this when we can get the actual cellular network info when the device
+            // is on IWLAN.
             if (TelephonyManager.NETWORK_TYPE_IWLAN
                     == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
                 return "";
@@ -1710,8 +1713,18 @@
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
-        return TelephonyManager.getTelephonyProperty(
-                phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
+
+        Phone phone = PhoneFactory.getPhone(phoneId);
+        if (phone != null) {
+            ServiceStateTracker sst = phone.getServiceStateTracker();
+            if (sst != null) {
+                LocaleTracker lt = sst.getLocaleTracker();
+                if (lt != null) {
+                    return lt.getCurrentCountry();
+                }
+            }
+        }
+        return "";
     }
 
     @Override