From 520e6e45a6f11c9f97bb4c4feba07712ae27264b Mon Sep 17 00:00:00 2001 From: Michael W Date: Sun, 17 Nov 2019 17:02:38 +0100 Subject: [PATCH] SensitivePhoneNumbers: Additionally check against the sim operator * In order to also mark numbers as sensitive when calling to your home country, check the sim's operator as well * Also move the fallback mechanism out of the "else" in order to perform as many checks as possible to not miss any case of hiding Change-Id: I23b67145406793506be657df8b62f5d09b5a2a18 --- .../lib/phone/SensitivePhoneNumbers.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/src/java/org/lineageos/lib/phone/SensitivePhoneNumbers.java b/lib/src/java/org/lineageos/lib/phone/SensitivePhoneNumbers.java index b7827835..9bff6fbf 100644 --- a/lib/src/java/org/lineageos/lib/phone/SensitivePhoneNumbers.java +++ b/lib/src/java/org/lineageos/lib/phone/SensitivePhoneNumbers.java @@ -131,16 +131,30 @@ public class SensitivePhoneNumbers { return true; } } - } else { - // Fall back to check with the passed subId - TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); - if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { - subId = SubscriptionManager.getDefaultSubscriptionId(); + } + + // Fall back to check with the passed subId + TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); + if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + subId = SubscriptionManager.getDefaultSubscriptionId(); + } + telephonyManager = telephonyManager.createForSubscriptionId(subId); + String networkUsed = telephonyManager.getNetworkOperator(); + if (!TextUtils.isEmpty(networkUsed)) { + String networkMCC = networkUsed.substring(0, 3); + if (isSensitiveNumber(nationalNumber, networkMCC)) { + return true; } - String networkUsed = telephonyManager.getNetworkOperator(subId); - if (!TextUtils.isEmpty(networkUsed)) { - String networkMCC = networkUsed.substring(0, 3); - return isSensitiveNumber(nationalNumber, networkMCC); + } + + // Also try the sim's operator + if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) { + String simOperator = telephonyManager.getSimOperator(); + if (!TextUtils.isEmpty(simOperator)) { + String networkMCC = simOperator.substring(0, 3); + if (isSensitiveNumber(nationalNumber, networkMCC)) { + return true; + } } }