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 26 * on occasion we need to interact with the telecom.Call directly (eg. call blocking, 27 * before the incall.Call has 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( 35 handle == null ? "" : handle.getSchemeSpecificPart()); 36 } 37 getNumber(Call call)38 public static String getNumber(Call call) { 39 if (call == null) { 40 return null; 41 } 42 if (call.getDetails().getGatewayInfo() != null) { 43 return call.getDetails().getGatewayInfo() 44 .getOriginalAddress().getSchemeSpecificPart(); 45 } 46 Uri handle = getHandle(call); 47 return handle == null ? null : handle.getSchemeSpecificPart(); 48 } 49 getHandle(Call call)50 public static Uri getHandle(Call call) { 51 return call == null ? null : call.getDetails().getHandle(); 52 } 53 } 54