From a8d677fce88d2add418cdcc868f2a00b2e2d702e Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 7 Mar 2018 17:16:08 -0800 Subject: Support local emergency phone number check when there are multiple SIMs. Bug: 73994020 Test: PhoneNumberHelperTest PiperOrigin-RevId: 188260007 Change-Id: I23025e9b9454f487117c35e7a3b09307371ae825 --- .../dialer/oem/PhoneNumberUtilsAccessor.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java (limited to 'java/com/android/dialer/oem/PhoneNumberUtilsAccessor.java') 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); + } + } +} -- cgit v1.2.3