aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael W <baddaemon87@gmail.com>2019-09-11 13:59:30 +0200
committerLuca Stefani <luca.stefani.ge1@gmail.com>2019-11-02 19:04:28 +0100
commitbf0d04e4de1253057c993501301f69466d1773e2 (patch)
tree03a9b8efd0188a4a69ed94d09932eeca5d21fedb
parentb5462e365798e08e564c55e7f9db480d04c077b0 (diff)
downloadlineage-sdk-bf0d04e4de1253057c993501301f69466d1773e2.tar.gz
lineage-sdk-bf0d04e4de1253057c993501301f69466d1773e2.tar.bz2
lineage-sdk-bf0d04e4de1253057c993501301f69466d1773e2.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.bp6
-rw-r--r--sdk/src/java/org/lineageos/internal/phone/SensitivePhoneNumbers.java30
2 files changed, 31 insertions, 5 deletions
diff --git a/Android.bp b/Android.bp
index ac1e6531..84831378 100644
--- a/Android.bp
+++ b/Android.bp
@@ -78,7 +78,8 @@ java_library {
name: "org.lineageos.platform",
installable: true,
static_libs: [
- "telephony-ext"
+ "libphonenumber",
+ "telephony-ext",
] + lineage_sdk_LOCAL_STATIC_ANDROID_LIBRARIES + lineage_sdk_LOCAL_STATIC_JAVA_LIBRARIES,
libs: [
@@ -106,7 +107,8 @@ java_library {
name: "org.lineageos.platform.internal",
required: ["services"],
static_libs: [
- "telephony-ext"
+ "libphonenumber",
+ "telephony-ext",
] + lineage_sdk_LOCAL_STATIC_ANDROID_LIBRARIES + lineage_sdk_LOCAL_STATIC_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;
+ }
+ }
}