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 package com.android.contacts.common.compat.telecom; 17 18 import android.support.annotation.Nullable; 19 import android.telecom.PhoneAccountHandle; 20 import android.telecom.TelecomManager; 21 import java.lang.reflect.Field; 22 23 /** Compatibility class for {@link android.telecom.TelecomManager}. */ 24 public class TelecomManagerCompat { 25 26 // Constants from http://cs/android/frameworks/base/telecomm/java/android/telecom/Call.java. 27 public static final String EVENT_REQUEST_HANDOVER = "android.telecom.event.REQUEST_HANDOVER"; 28 public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE = 29 "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE"; 30 public static final String EXTRA_HANDOVER_VIDEO_STATE = 31 "android.telecom.extra.HANDOVER_VIDEO_STATE"; 32 33 // This is a hidden constant in android.telecom.DisconnectCause. Telecom sets this as a disconnect 34 // reason if it wants us to prompt the user that the video call is not available. 35 // TODO(wangqi): Reference it to constant in android.telecom.DisconnectCause. 36 public static final String REASON_IMS_ACCESS_BLOCKED = "REASON_IMS_ACCESS_BLOCKED"; 37 38 /** 39 * Returns the current SIM call manager. Apps must be prepared for this method to return null, 40 * indicating that there currently exists no registered SIM call manager. 41 * 42 * @param telecomManager the {@link TelecomManager} to use to fetch the SIM call manager. 43 * @return The phone account handle of the current sim call manager. 44 */ 45 @Nullable getSimCallManager(TelecomManager telecomManager)46 public static PhoneAccountHandle getSimCallManager(TelecomManager telecomManager) { 47 if (telecomManager != null) { 48 return telecomManager.getSimCallManager(); 49 } 50 return null; 51 } 52 53 /** 54 * Handovers are supported from Android O-DR onward. Since there is no API bump from O to O-DR, we 55 * need to use reflection to check the existence of TelecomManager.EXTRA_IS_HANDOVER in 56 * http://cs/android/frameworks/base/telecomm/java/android/telecom/TelecomManager.java. 57 */ supportsHandover()58 public static boolean supportsHandover() { 59 // 60 try { 61 Field field = TelecomManager.class.getDeclaredField("EXTRA_IS_HANDOVER"); 62 return "android.telecom.extra.IS_HANDOVER".equals(field.get(null /* obj (static field) */)); 63 } catch (Exception e) { 64 // Do nothing 65 } 66 return false; 67 } 68 } 69