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
This commit is contained in:
@@ -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: [
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user