diff options
author | Michael W <baddaemon87@gmail.com> | 2019-09-11 13:59:30 +0200 |
---|---|---|
committer | Michael W <baddaemon87@gmail.com> | 2019-11-03 01:26:39 +0100 |
commit | 6b12b1119119f9af76c60f3a1568d15b0b9adb52 (patch) | |
tree | 71805f2756b9d2707828a90cc3b691cbd274969e | |
parent | d44cce6f84e84591e47fc08091087ca1aafac2b9 (diff) | |
download | lineage-sdk-6b12b1119119f9af76c60f3a1568d15b0b9adb52.tar.gz lineage-sdk-6b12b1119119f9af76c60f3a1568d15b0b9adb52.tar.bz2 lineage-sdk-6b12b1119119f9af76c60f3a1568d15b0b9adb52.zip |
SensitivePn: Also hide international numbers
* When calling the number with intl. prefix it is currently not hidden
* Remove the international prefix before checking th number
Test:
Before:
116006 - hidden
+49116006 - not hidden
004911606 - not hidden
After:
116006 - hidden
+49116006 - hidden
0049116006 - hidden
Change-Id: I72ec2c9a4da87ef243c59c8c4bab33585fdbd854
-rw-r--r-- | Android.bp | 10 | ||||
-rw-r--r-- | sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java | 30 |
2 files changed, 35 insertions, 5 deletions
@@ -79,7 +79,10 @@ lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES = [ java_library { name: "org.lineageos.platform", - static_libs: ["telephony-ext"] + lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES, + static_libs: [ + "libphonenumber", + "telephony-ext" + ] + lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES, libs: [ "services", @@ -106,7 +109,10 @@ java_library { java_library_static { name: "org.lineageos.platform.internal", required: ["services"], - static_libs: ["telephony-ext"] + lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES, + static_libs: [ + "libphonenumber", + "telephony-ext" + ] + lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES, libs: lineage_sdk_LOCAL_JAVA_LIBRARIES, srcs: [ diff --git a/sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java b/sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java index a87e2b09..8d917600 100644 --- a/sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java +++ b/sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java @@ -27,6 +27,11 @@ import android.text.TextUtils; import android.util.Log; import android.util.Xml; +import com.google.i18n.phonenumbers.NumberParseException; +import com.google.i18n.phonenumbers.Phonenumber; +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; + import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -37,6 +42,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; public class SensitivePhoneNumbers { private final String LOG_TAG = this.getClass().getSimpleName(); @@ -98,14 +104,15 @@ public class SensitivePhoneNumbers { } public boolean isSensitiveNumber(Context context, String numberToCheck, int subId) { - SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); + String nationalNumber = formatNumberToNational(context, numberToCheck); + SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); List<SubscriptionInfo> list = subManager.getActiveSubscriptionInfoList(); if (list != null) { // Test all subscriptions so an accidential use of a wrong sim also hides the number for (SubscriptionInfo subInfo : list) { String mcc = String.valueOf(subInfo.getMcc()); - if (isSensitiveNumber(numberToCheck, mcc)) { + if (isSensitiveNumber(nationalNumber, mcc)) { return true; } } @@ -118,7 +125,7 @@ public class SensitivePhoneNumbers { String networkUsed = telephonyManager.getNetworkOperator(subId); if (!TextUtils.isEmpty(networkUsed)) { String networkMCC = networkUsed.substring(0, 3); - return isSensitiveNumber(numberToCheck, networkMCC); + return isSensitiveNumber(nationalNumber, networkMCC); } } @@ -137,4 +144,21 @@ public class SensitivePhoneNumbers { } return false; } + + private String formatNumberToNational(Context context, String number) { + PhoneNumberUtil util = PhoneNumberUtil.getInstance(); + String countryIso = context.getResources().getConfiguration().locale.getCountry(); + + Phonenumber.PhoneNumber pn = null; + try { + pn = util.parse(number, countryIso); + } catch (NumberParseException e) { + } + + if (pn != null) { + return util.format(pn, PhoneNumberFormat.NATIONAL); + } else { + return number; + } + } } |