summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/phonenumberutil
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2018-03-07 17:16:08 -0800
committerCopybara-Service <copybara-piper@google.com>2018-03-07 17:18:27 -0800
commita8d677fce88d2add418cdcc868f2a00b2e2d702e (patch)
tree1756a87c6a845b9d81edb95c2e05ac60cbc53411 /java/com/android/dialer/phonenumberutil
parent0c2805ffe1f08ee163b4fe721ce086b5530e84f0 (diff)
Support local emergency phone number check when there are multiple SIMs.
Bug: 73994020 Test: PhoneNumberHelperTest PiperOrigin-RevId: 188260007 Change-Id: I23025e9b9454f487117c35e7a3b09307371ae825
Diffstat (limited to 'java/com/android/dialer/phonenumberutil')
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
index e1051951e..33a94ea74 100644
--- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
+++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
@@ -25,6 +25,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
+import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
@@ -34,10 +35,13 @@ import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.CompatUtils;
import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.oem.MotorolaUtils;
+import com.android.dialer.oem.PhoneNumberUtilsAccessor;
import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent;
import com.android.dialer.telecom.TelecomUtil;
+import com.google.common.base.Optional;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
public class PhoneNumberHelper {
@@ -138,6 +142,39 @@ public class PhoneNumberHelper {
}
/**
+ * An enhanced version of {@link PhoneNumberUtils#isLocalEmergencyNumber(Context, String)}.
+ *
+ * <p>This methods supports checking the number for all SIMs.
+ *
+ * @param context the context which the number should be checked against
+ * @param number the number to tbe checked
+ * @return true if the specified number is an emergency number for any SIM in the device.
+ */
+ @SuppressWarnings("Guava")
+ public static boolean isLocalEmergencyNumber(Context context, String number) {
+ List<PhoneAccountHandle> phoneAccountHandles =
+ TelecomUtil.getSubscriptionPhoneAccounts(context);
+
+ // If the number of phone accounts with a subscription is no greater than 1, only one SIM is
+ // installed in the device. We hand over the job to PhoneNumberUtils#isLocalEmergencyNumber.
+ if (phoneAccountHandles.size() <= 1) {
+ return PhoneNumberUtils.isLocalEmergencyNumber(context, number);
+ }
+
+ for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
+ Optional<SubscriptionInfo> subscriptionInfo =
+ TelecomUtil.getSubscriptionInfo(context, phoneAccountHandle);
+ if (subscriptionInfo.isPresent()
+ && PhoneNumberUtilsAccessor.isLocalEmergencyNumber(
+ context, subscriptionInfo.get().getSubscriptionId(), number)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Returns true if the given number is the number of the configured voicemail. To be able to
* mock-out this, it is not a static method.
*/