Просмотр исходного кода

Prefer getNetworkCountryIso over getSimCountryIso

Rod Hynes 3 лет назад
Родитель
Сommit
d82ff79ab9
1 измененных файлов с 12 добавлено и 5 удалено
  1. 12 5
      MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

+ 12 - 5
MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

@@ -1138,16 +1138,23 @@ public class PsiphonTunnel {
         String region = "";
         TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
         if (telephonyManager != null) {
-            region = telephonyManager.getSimCountryIso();
-            if (region == null) {
-                region = "";
-            }
-            if (region.length() == 0 && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
+            // getNetworkCountryIso, when present, is preferred over
+            // getSimCountryIso, since getNetworkCountryIso is the network
+            // the device is currently on, while getSimCountryIso is the home
+            // region of the SIM. While roaming, only getNetworkCountryIso
+            // may more accurately represent the actual device region.
+            if (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
                 region = telephonyManager.getNetworkCountryIso();
                 if (region == null) {
                     region = "";
                 }
             }
+            if (region.length() == 0) {
+                region = telephonyManager.getSimCountryIso();
+                if (region == null) {
+                    region = "";
+                }
+            }
         }
         if (region.length() == 0) {
             Locale defaultLocale = Locale.getDefault();