1 /*
2  * Copyright (C) 2015 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.incallui.util;
18 
19 import android.net.Uri;
20 import android.telecom.Call;
21 import android.telephony.PhoneNumberUtils;
22 
23 /**
24  * Class to provide a standard interface for obtaining information from the underlying
25  * android.telecom.Call. Much of this should be obtained through the incall.Call, but on occasion we
26  * need to interact with the telecom.Call directly (eg. call blocking, before the incall.Call has
27  * been created).
28  */
29 public class TelecomCallUtil {
30 
31   // Whether the call handle is an emergency number.
isEmergencyCall(Call call)32   public static boolean isEmergencyCall(Call call) {
33     Uri handle = call.getDetails().getHandle();
34     return PhoneNumberUtils.isEmergencyNumber(handle == null ? "" : handle.getSchemeSpecificPart());
35   }
36 
getNumber(Call call)37   public static String getNumber(Call call) {
38     if (call == null) {
39       return null;
40     }
41     if (call.getDetails().getGatewayInfo() != null) {
42       return call.getDetails().getGatewayInfo().getOriginalAddress().getSchemeSpecificPart();
43     }
44     Uri handle = getHandle(call);
45     return handle == null ? null : handle.getSchemeSpecificPart();
46   }
47 
getHandle(Call call)48   public static Uri getHandle(Call call) {
49     return call == null ? null : call.getDetails().getHandle();
50   }
51 }
52