• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.dialer.oem;
18 
19 import android.content.Context;
20 import android.telephony.PhoneNumberUtils;
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23 
24 /** Provides access to hidden APIs in {@link android.telephony.PhoneNumberUtils}. */
25 public final class PhoneNumberUtilsAccessor {
26 
27   /**
28    * Checks if a given number is an emergency number for the country that the user is in.
29    *
30    * @param subId the subscription ID of the SIM
31    * @param number the number to check
32    * @param context the specific context which the number should be checked against
33    * @return true if the specified number is an emergency number for the country the user is
34    *     currently in.
35    */
isLocalEmergencyNumber(Context context, int subId, String number)36   public static boolean isLocalEmergencyNumber(Context context, int subId, String number) {
37     try {
38       Method method =
39           PhoneNumberUtils.class.getMethod(
40               "isLocalEmergencyNumber", Context.class, int.class, String.class);
41       return (boolean) method.invoke(null, context, subId, number);
42 
43     } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
44       throw new RuntimeException(e);
45     }
46   }
47 }
48