summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/oem
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/oem
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/oem')
-rw-r--r--java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java b/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java
new file mode 100644
index 000000000..178a7b21d
--- /dev/null
+++ b/java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dialer.oem;
+
+import android.content.Context;
+import android.telephony.PhoneNumberUtils;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/** Provides access to hidden APIs in {@link android.telephony.PhoneNumberUtils}. */
+public final class PhoneNumberUtilsAccessor {
+
+ /**
+ * Checks if a given number is an emergency number for the country that the user is in.
+ *
+ * @param subId the subscription ID of the SIM
+ * @param number the number to check
+ * @param context the specific context which the number should be checked against
+ * @return true if the specified number is an emergency number for the country the user is
+ * currently in.
+ */
+ public static boolean isLocalEmergencyNumber(Context context, int subId, String number) {
+ try {
+ Method method =
+ PhoneNumberUtils.class.getMethod(
+ "isLocalEmergencyNumber", Context.class, int.class, String.class);
+ return (boolean) method.invoke(null, context, subId, number);
+
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}