summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/lineageos/lineageparts/lineagestats/Utilities.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/org/lineageos/lineageparts/lineagestats/Utilities.java b/src/org/lineageos/lineageparts/lineagestats/Utilities.java
index de4bf07..511f6ed 100644
--- a/src/org/lineageos/lineageparts/lineagestats/Utilities.java
+++ b/src/org/lineageos/lineageparts/lineagestats/Utilities.java
@@ -28,6 +28,7 @@ import lineageos.providers.LineageSettings;
import java.math.BigInteger;
import java.net.NetworkInterface;
import java.security.MessageDigest;
+import java.util.Locale;
public class Utilities {
public static String getUniqueID(Context context) {
@@ -55,9 +56,14 @@ public class Utilities {
public static String getCountryCode(Context context) {
TelephonyManager tm = context.getSystemService(TelephonyManager.class);
- String countryCode = tm.getNetworkCountryIso();
- if (TextUtils.isEmpty(countryCode)) {
- countryCode = "Unknown";
+ String countryCode = tm.getNetworkCountryIso().toUpperCase();
+ if (TextUtils.isEmpty(countryCode) || isCdmaPhone(tm)) {
+ String localeCountryCode = Locale.getDefault().getCountry();
+ if (localeCountryCode.length() == 2) {
+ countryCode = localeCountryCode;
+ } else {
+ countryCode = "Unknown";
+ }
}
return countryCode;
}
@@ -99,4 +105,8 @@ public class Utilities {
LineageSettings.Secure.putInt(context.getContentResolver(),
LineageSettings.Secure.STATS_COLLECTION, enable);
}
+
+ private static boolean isCdmaPhone(TelephonyManager tm) {
+ return tm != null && tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
+ }
}