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