Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | * in compliance with the License. You may obtain a copy of the License at |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 6 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 8 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | * the License. |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 15 | package android.telecom; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 16 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 17 | import android.annotation.SystemApi; |
| 18 | import android.content.ComponentName; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 21 | import android.os.RemoteException; |
| 22 | import android.os.ServiceManager; |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 23 | import android.telephony.TelephonyManager; |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 25 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 26 | import com.android.internal.telecom.ITelecomService; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 27 | |
Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 28 | import java.util.ArrayList; |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 29 | import java.util.Collections; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 32 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 33 | * Provides access to Telecom-related functionality. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 34 | * TODO: Move this all into PhoneManager. |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 35 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 36 | public class TelecomManager { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 37 | |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 38 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 39 | * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 40 | * UI by notifying the Telecom system that an incoming call exists for a specific call service |
| 41 | * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find |
| 42 | * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 43 | * ultimately use to control and get information about the call. |
| 44 | * <p> |
| 45 | * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 46 | * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 47 | * ask the connection service for more information about the call prior to showing any UI. |
| 48 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 49 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 50 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 51 | public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 54 | * The {@link android.content.Intent} action used to configure a |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 55 | * {@link android.telecom.ConnectionService}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 56 | */ |
| 57 | public static final String ACTION_CONNECTION_SERVICE_CONFIGURE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 58 | "android.telecom.action.CONNECTION_SERVICE_CONFIGURE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Yorke Lee | 3818a89 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 61 | * The {@link android.content.Intent} action used to show the call settings page. |
| 62 | */ |
| 63 | public static final String ACTION_SHOW_CALL_SETTINGS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 64 | "android.telecom.action.SHOW_CALL_SETTINGS"; |
Yorke Lee | 3818a89 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 67 | * The {@link android.content.Intent} action used to show the settings page used to configure |
| 68 | * {@link PhoneAccount} preferences. |
| 69 | */ |
| 70 | public static final String ACTION_CHANGE_PHONE_ACCOUNTS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 71 | "android.telecom.action.CHANGE_PHONE_ACCOUNTS"; |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 74 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that |
| 75 | * determines whether the speakerphone should be automatically turned on for an outgoing call. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 76 | */ |
| 77 | public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 78 | "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 81 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that |
| 82 | * determines the desired video state for an outgoing call. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 83 | * Valid options: |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 84 | * {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 85 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 86 | * {@link VideoProfile.VideoState#RX_ENABLED}, |
| 87 | * {@link VideoProfile.VideoState#TX_ENABLED}. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 88 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 89 | */ |
| 90 | public static final String EXTRA_START_CALL_WITH_VIDEO_STATE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 91 | "android.telecom.extra.START_CALL_WITH_VIDEO_STATE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 94 | * The extra used with an {@link android.content.Intent#ACTION_CALL} and |
| 95 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a |
| 96 | * {@link PhoneAccountHandle} to use when making the call. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 97 | * <p class="note"> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 98 | * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 99 | */ |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 100 | public static final String EXTRA_PHONE_ACCOUNT_HANDLE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 101 | "android.telecom.extra.PHONE_ACCOUNT_HANDLE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 104 | * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains |
| 105 | * metadata about the call. This {@link Bundle} will be returned to the |
| 106 | * {@link ConnectionService}. |
| 107 | * |
| 108 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 109 | */ |
| 110 | public static final String EXTRA_INCOMING_CALL_EXTRAS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 111 | "android.telecom.extra.INCOMING_CALL_EXTRAS"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 114 | * Optional extra for {@link android.content.Intent#ACTION_CALL} and |
| 115 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle} |
| 116 | * which contains metadata about the call. This {@link Bundle} will be saved into |
| 117 | * {@code Call.Details}. |
| 118 | * |
| 119 | * @hide |
| 120 | */ |
| 121 | public static final String EXTRA_OUTGOING_CALL_EXTRAS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 122 | "android.telecom.extra.OUTGOING_CALL_EXTRAS"; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 125 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 126 | * containing the disconnect code. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 127 | */ |
| 128 | public static final String EXTRA_CALL_DISCONNECT_CAUSE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 129 | "android.telecom.extra.CALL_DISCONNECT_CAUSE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 132 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 133 | * containing the disconnect message. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 134 | */ |
| 135 | public static final String EXTRA_CALL_DISCONNECT_MESSAGE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 136 | "android.telecom.extra.CALL_DISCONNECT_MESSAGE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 139 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 140 | * containing the component name of the associated connection service. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 141 | */ |
| 142 | public static final String EXTRA_CONNECTION_SERVICE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 143 | "android.telecom.extra.CONNECTION_SERVICE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 146 | * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the |
| 147 | * package name of the app specifying an alternative gateway for the call. |
| 148 | * The value is a string. |
| 149 | * |
| 150 | * (The following comment corresponds to the all GATEWAY_* extras) |
| 151 | * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an |
| 152 | * alternative address to dial which is different from the one specified and displayed to |
| 153 | * the user. This alternative address is referred to as the gateway address. |
| 154 | */ |
| 155 | public static final String GATEWAY_PROVIDER_PACKAGE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 156 | "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE"; |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the |
| 160 | * original address to dial for the call. This is used when an alternative gateway address is |
| 161 | * provided to recall the original address. |
| 162 | * The value is a {@link android.net.Uri}. |
| 163 | * |
| 164 | * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details) |
| 165 | */ |
| 166 | public static final String GATEWAY_ORIGINAL_ADDRESS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 167 | "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS"; |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 170 | * The number which the party on the other side of the line will see (and use to return the |
| 171 | * call). |
| 172 | * <p> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 173 | * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate |
| 174 | * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the |
| 175 | * user's expected caller ID. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 176 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 177 | public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * The dual tone multi-frequency signaling character sent to indicate the dialing system should |
| 181 | * pause for a predefined period. |
| 182 | */ |
| 183 | public static final char DTMF_CHARACTER_PAUSE = ','; |
| 184 | |
| 185 | /** |
| 186 | * The dual-tone multi-frequency signaling character sent to indicate the dialing system should |
| 187 | * wait for user confirmation before proceeding. |
| 188 | */ |
| 189 | public static final char DTMF_CHARACTER_WAIT = ';'; |
| 190 | |
| 191 | /** |
| 192 | * TTY (teletypewriter) mode is off. |
| 193 | * |
| 194 | * @hide |
| 195 | */ |
| 196 | public static final int TTY_MODE_OFF = 0; |
| 197 | |
| 198 | /** |
| 199 | * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user |
| 200 | * will communicate with the remote party by sending and receiving text messages. |
| 201 | * |
| 202 | * @hide |
| 203 | */ |
| 204 | public static final int TTY_MODE_FULL = 1; |
| 205 | |
| 206 | /** |
| 207 | * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the |
| 208 | * speaker is on. The user will communicate with the remote party by sending text messages and |
| 209 | * hearing an audible reply. |
| 210 | * |
| 211 | * @hide |
| 212 | */ |
| 213 | public static final int TTY_MODE_HCO = 2; |
| 214 | |
| 215 | /** |
| 216 | * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the |
| 217 | * microphone is still on. User will communicate with the remote party by speaking and receiving |
| 218 | * text message replies. |
| 219 | * |
| 220 | * @hide |
| 221 | */ |
| 222 | public static final int TTY_MODE_VCO = 3; |
| 223 | |
| 224 | /** |
| 225 | * Broadcast intent action indicating that the current TTY mode has changed. An intent extra |
| 226 | * provides this state as an int. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 227 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 228 | * @see #EXTRA_CURRENT_TTY_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 229 | * @hide |
| 230 | */ |
| 231 | public static final String ACTION_CURRENT_TTY_MODE_CHANGED = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 232 | "android.telecom.action.CURRENT_TTY_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 233 | |
| 234 | /** |
| 235 | * The lookup key for an int that indicates the current TTY mode. |
| 236 | * Valid modes are: |
| 237 | * - {@link #TTY_MODE_OFF} |
| 238 | * - {@link #TTY_MODE_FULL} |
| 239 | * - {@link #TTY_MODE_HCO} |
| 240 | * - {@link #TTY_MODE_VCO} |
| 241 | * |
| 242 | * @hide |
| 243 | */ |
| 244 | public static final String EXTRA_CURRENT_TTY_MODE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 245 | "android.telecom.intent.extra.CURRENT_TTY_MODE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 246 | |
| 247 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 248 | * Broadcast intent action indicating that the TTY preferred operating mode has changed. An |
| 249 | * intent extra provides the new mode as an int. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 250 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 251 | * @see #EXTRA_TTY_PREFERRED_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 252 | * @hide |
| 253 | */ |
| 254 | public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 255 | "android.telecom.action.TTY_PREFERRED_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 258 | * The lookup key for an int that indicates preferred TTY mode. Valid modes are: - |
| 259 | * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} - |
| 260 | * {@link #TTY_MODE_VCO} |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 261 | * |
| 262 | * @hide |
| 263 | */ |
| 264 | public static final String EXTRA_TTY_PREFERRED_MODE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 265 | "android.telecom.intent.extra.TTY_PREFERRED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 266 | |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 267 | /** |
| 268 | * The following 4 constants define how properties such as phone numbers and names are |
| 269 | * displayed to the user. |
| 270 | */ |
| 271 | |
| 272 | /** Property is displayed normally. */ |
| 273 | public static final int PRESENTATION_ALLOWED = 1; |
| 274 | |
| 275 | /** Property was blocked. */ |
| 276 | public static final int PRESENTATION_RESTRICTED = 2; |
| 277 | |
| 278 | /** Presentation was not specified or is unknown. */ |
| 279 | public static final int PRESENTATION_UNKNOWN = 3; |
| 280 | |
| 281 | /** Property should be displayed as a pay phone. */ |
| 282 | public static final int PRESENTATION_PAYPHONE = 4; |
| 283 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 284 | private static final String TAG = "TelecomManager"; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 285 | |
| 286 | private final Context mContext; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 287 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 288 | /** |
| 289 | * @hide |
| 290 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 291 | public static TelecomManager from(Context context) { |
| 292 | return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 293 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * @hide |
| 297 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 298 | public TelecomManager(Context context) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 299 | Context appContext = context.getApplicationContext(); |
| 300 | if (appContext != null) { |
| 301 | mContext = appContext; |
| 302 | } else { |
| 303 | mContext = context; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 308 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 309 | * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 310 | * list which is returned from calling {@link #getCallCapablePhoneAccounts()}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 311 | * <p> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 312 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 313 | * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 314 | * phone call must either create their {@link android.content.Intent#ACTION_CALL} or |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 315 | * {@link android.content.Intent#ACTION_DIAL} {@code Intent} with no |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 316 | * {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE}, or present the user with an affordance to |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 317 | * select one of the elements of {@link #getCallCapablePhoneAccounts()}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 318 | * <p> |
| 319 | * An {@link android.content.Intent#ACTION_CALL} or {@link android.content.Intent#ACTION_DIAL} |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 320 | * {@code Intent} with no {@link TelecomManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 321 | * subsequent steps in the phone call flow are responsible for presenting the user with an |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 322 | * affordance, if necessary, to choose a {@code PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 323 | * |
| 324 | * @param uriScheme The URI scheme. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 325 | */ |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 326 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 327 | try { |
| 328 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 329 | return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 330 | } |
| 331 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 332 | Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 333 | } |
| 334 | return null; |
| 335 | } |
| 336 | |
| 337 | /** |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 338 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
| 339 | * calls. This {@code PhoneAccount} will always be a member of the list which is returned from |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 340 | * calling {@link #getCallCapablePhoneAccounts()} |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 341 | * |
| 342 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 343 | * exists no user-chosen default {@code PhoneAccount}. |
| 344 | * |
| 345 | * @return The user outgoing phone account selected by the user. |
| 346 | * @hide |
| 347 | */ |
| 348 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
| 349 | try { |
| 350 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 351 | return getTelecomService().getUserSelectedOutgoingPhoneAccount(); |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 352 | } |
| 353 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 354 | Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e); |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 355 | } |
| 356 | return null; |
| 357 | } |
| 358 | |
| 359 | /** |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 360 | * Sets the default account for making outgoing phone calls. |
| 361 | * @hide |
| 362 | */ |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 363 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 364 | try { |
| 365 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 366 | getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 367 | } |
| 368 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 369 | Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 374 | * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 375 | * calls. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 376 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 377 | * @see #EXTRA_PHONE_ACCOUNT_HANDLE |
| 378 | * @return A list of {@code PhoneAccountHandle} objects. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 379 | */ |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 380 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 381 | try { |
| 382 | if (isServiceConnected()) { |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 383 | return getTelecomService().getCallCapablePhoneAccounts(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 384 | } |
| 385 | } catch (RemoteException e) { |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 386 | Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 387 | } |
Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 388 | return new ArrayList<>(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 392 | * Returns the current SIM call manager. Apps must be prepared for this method to return |
| 393 | * {@code null}, indicating that there currently exists no user-chosen default |
| 394 | * {@code PhoneAccount}. |
| 395 | * @return The phone account handle of the current sim call manager. |
| 396 | * @hide |
| 397 | */ |
| 398 | public PhoneAccountHandle getSimCallManager() { |
| 399 | try { |
| 400 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 401 | return getTelecomService().getSimCallManager(); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 402 | } |
| 403 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 404 | Log.e(TAG, "Error calling ITelecomService#getSimCallManager"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 405 | } |
| 406 | return null; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Sets the SIM call manager to the specified phone account. |
| 411 | * @param accountHandle The phone account handle of the account to set as the sim call manager. |
| 412 | * @hide |
| 413 | */ |
| 414 | public void setSimCallManager(PhoneAccountHandle accountHandle) { |
| 415 | try { |
| 416 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 417 | getTelecomService().setSimCallManager(accountHandle); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 418 | } |
| 419 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 420 | Log.e(TAG, "Error calling ITelecomService#setSimCallManager"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Returns the list of registered SIM call managers. |
| 426 | * @return List of registered SIM call managers. |
| 427 | * @hide |
| 428 | */ |
| 429 | public List<PhoneAccountHandle> getSimCallManagers() { |
| 430 | try { |
| 431 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 432 | return getTelecomService().getSimCallManagers(); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 433 | } |
| 434 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 435 | Log.e(TAG, "Error calling ITelecomService#getSimCallManagers"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 436 | } |
| 437 | return new ArrayList<>(); |
| 438 | } |
| 439 | |
| 440 | /** |
Evan Charlton | eb0a8d5 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 441 | * Returns the current connection manager. Apps must be prepared for this method to return |
| 442 | * {@code null}, indicating that there currently exists no user-chosen default |
| 443 | * {@code PhoneAccount}. |
| 444 | * |
| 445 | * @return The phone account handle of the current connection manager. |
| 446 | */ |
| 447 | public PhoneAccountHandle getConnectionManager() { |
| 448 | return getSimCallManager(); |
| 449 | } |
| 450 | |
| 451 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 452 | * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 453 | * calls which support the specified URI scheme. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 454 | * <P> |
| 455 | * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which |
| 456 | * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with |
| 457 | * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs |
| 458 | * such as {@code sip:example@sipexample.com}). |
| 459 | * |
| 460 | * @param uriScheme The URI scheme. |
| 461 | * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. |
| 462 | */ |
| 463 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { |
| 464 | try { |
| 465 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 466 | return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 467 | } |
| 468 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 469 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 470 | } |
| 471 | return new ArrayList<>(); |
| 472 | } |
| 473 | |
| 474 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 475 | * Determine whether the device has more than one account registered that can make and receive |
| 476 | * phone calls. |
Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 477 | * |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 478 | * @return {@code true} if the device has more than one account registered and {@code false} |
| 479 | * otherwise. |
Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 480 | */ |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 481 | public boolean hasMultipleCallCapableAccounts() { |
| 482 | return getCallCapablePhoneAccounts().size() > 1; |
Nancy Chen | 6080118 | 2014-07-22 16:56:49 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 486 | * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes |
| 487 | * resources which can be used in a user interface. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 488 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 489 | * @param account The {@link PhoneAccountHandle}. |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 490 | * @return The {@link PhoneAccount} object. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 491 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 492 | public PhoneAccount getPhoneAccount(PhoneAccountHandle account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 493 | try { |
| 494 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 495 | return getTelecomService().getPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 496 | } |
| 497 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 498 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 499 | } |
| 500 | return null; |
| 501 | } |
| 502 | |
| 503 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 504 | * Returns a count of all {@link PhoneAccount}s. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 505 | * |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 506 | * @return The count of {@link PhoneAccount}s. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 507 | * @hide |
| 508 | */ |
| 509 | @SystemApi |
| 510 | public int getAllPhoneAccountsCount() { |
| 511 | try { |
| 512 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 513 | return getTelecomService().getAllPhoneAccountsCount(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 514 | } |
| 515 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 516 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 517 | } |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Returns a list of all {@link PhoneAccount}s. |
| 523 | * |
| 524 | * @return All {@link PhoneAccount}s. |
| 525 | * @hide |
| 526 | */ |
| 527 | @SystemApi |
| 528 | public List<PhoneAccount> getAllPhoneAccounts() { |
| 529 | try { |
| 530 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 531 | return getTelecomService().getAllPhoneAccounts(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 532 | } |
| 533 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 534 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 535 | } |
| 536 | return Collections.EMPTY_LIST; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Returns a list of all {@link PhoneAccountHandle}s. |
| 541 | * |
| 542 | * @return All {@link PhoneAccountHandle}s. |
| 543 | * @hide |
| 544 | */ |
| 545 | @SystemApi |
| 546 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
| 547 | try { |
| 548 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 549 | return getTelecomService().getAllPhoneAccountHandles(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 550 | } |
| 551 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 552 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 553 | } |
| 554 | return Collections.EMPTY_LIST; |
| 555 | } |
| 556 | |
| 557 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 558 | * Register a {@link PhoneAccount} for use by the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 559 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 560 | * @param account The complete {@link PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 561 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 562 | public void registerPhoneAccount(PhoneAccount account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 563 | try { |
| 564 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 565 | getTelecomService().registerPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 566 | } |
| 567 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 568 | Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 573 | * Remove a {@link PhoneAccount} registration from the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 574 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 575 | * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 576 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 577 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 578 | try { |
| 579 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 580 | getTelecomService().unregisterPhoneAccount(accountHandle); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 581 | } |
| 582 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 583 | Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
| 587 | /** |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 588 | * Remove all Accounts that belong to the calling package from the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 589 | */ |
| 590 | @SystemApi |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 591 | public void clearAccounts() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 592 | try { |
| 593 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 594 | getTelecomService().clearAccounts(mContext.getPackageName()); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 595 | } |
| 596 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 597 | Log.e(TAG, "Error calling ITelecomService#clearAccounts", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * @hide |
| 603 | */ |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 604 | @SystemApi |
| 605 | public ComponentName getDefaultPhoneApp() { |
| 606 | try { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 607 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 608 | return getTelecomService().getDefaultPhoneApp(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 609 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 610 | } catch (RemoteException e) { |
| 611 | Log.e(TAG, "RemoteException attempting to get the default phone app.", e); |
| 612 | } |
| 613 | return null; |
| 614 | } |
| 615 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 616 | /** |
| 617 | * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding |
| 618 | * states). |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 619 | * <p> |
| 620 | * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} |
| 621 | * </p> |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 622 | */ |
| 623 | @SystemApi |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 624 | public boolean isInCall() { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 625 | try { |
| 626 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 627 | return getTelecomService().isInCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 628 | } |
| 629 | } catch (RemoteException e) { |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 630 | Log.e(TAG, "RemoteException calling isInCall().", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 631 | } |
| 632 | return false; |
| 633 | } |
| 634 | |
| 635 | /** |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 636 | * Returns one of the following constants that represents the current state of Telecom: |
| 637 | * |
| 638 | * {@link TelephonyManager#CALL_STATE_RINGING} |
| 639 | * {@link TelephonyManager#CALL_STATE_OFFHOOK} |
| 640 | * {@link TelephonyManager#CALL_STATE_IDLE} |
| 641 | * |
| 642 | * <p> |
| 643 | * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} |
| 644 | * </p> |
| 645 | * @hide |
| 646 | */ |
| 647 | @SystemApi |
| 648 | public int getCallState() { |
| 649 | try { |
| 650 | if (isServiceConnected()) { |
| 651 | return getTelecomService().getCallState(); |
| 652 | } |
| 653 | } catch (RemoteException e) { |
| 654 | Log.d(TAG, "RemoteException calling getCallState().", e); |
| 655 | } |
| 656 | return TelephonyManager.CALL_STATE_IDLE; |
| 657 | } |
| 658 | |
| 659 | /** |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 660 | * Returns whether there currently exists is a ringing incoming-call. |
| 661 | * |
| 662 | * @hide |
| 663 | */ |
| 664 | @SystemApi |
| 665 | public boolean isRinging() { |
| 666 | try { |
| 667 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 668 | return getTelecomService().isRinging(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 669 | } |
| 670 | } catch (RemoteException e) { |
| 671 | Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 677 | * Ends an ongoing call. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 678 | * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 679 | * method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 680 | * @hide |
| 681 | */ |
| 682 | @SystemApi |
| 683 | public boolean endCall() { |
| 684 | try { |
| 685 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 686 | return getTelecomService().endCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 687 | } |
| 688 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 689 | Log.e(TAG, "Error calling ITelecomService#endCall", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 690 | } |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * If there is a ringing incoming call, this method accepts the call on behalf of the user. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 696 | * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 697 | * this method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 698 | * |
| 699 | * @hide |
| 700 | */ |
| 701 | @SystemApi |
| 702 | public void acceptRingingCall() { |
| 703 | try { |
| 704 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 705 | getTelecomService().acceptRingingCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 706 | } |
| 707 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 708 | Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Silences the ringer if a ringing call exists. |
| 714 | * |
| 715 | * @hide |
| 716 | */ |
| 717 | @SystemApi |
| 718 | public void silenceRinger() { |
| 719 | try { |
| 720 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 721 | getTelecomService().silenceRinger(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 722 | } |
| 723 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 724 | Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 728 | /** |
| 729 | * Returns whether TTY is supported on this device. |
| 730 | * |
| 731 | * @hide |
| 732 | */ |
| 733 | @SystemApi |
| 734 | public boolean isTtySupported() { |
| 735 | try { |
| 736 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 737 | return getTelecomService().isTtySupported(); |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 738 | } |
| 739 | } catch (RemoteException e) { |
| 740 | Log.e(TAG, "RemoteException attempting to get TTY supported state.", e); |
| 741 | } |
| 742 | return false; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns the current TTY mode of the device. For TTY to be on the user must enable it in |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 747 | * settings and have a wired headset plugged in. |
| 748 | * Valid modes are: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 749 | * - {@link TelecomManager#TTY_MODE_OFF} |
| 750 | * - {@link TelecomManager#TTY_MODE_FULL} |
| 751 | * - {@link TelecomManager#TTY_MODE_HCO} |
| 752 | * - {@link TelecomManager#TTY_MODE_VCO} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 753 | * @hide |
| 754 | */ |
| 755 | public int getCurrentTtyMode() { |
| 756 | try { |
| 757 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 758 | return getTelecomService().getCurrentTtyMode(); |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 759 | } |
| 760 | } catch (RemoteException e) { |
| 761 | Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e); |
| 762 | } |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 763 | return TTY_MODE_OFF; |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 766 | /** |
| 767 | * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it |
| 768 | * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame^] | 769 | * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind |
| 770 | * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 771 | * additional information about the call (See |
| 772 | * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI. |
| 773 | * |
| 774 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 775 | * {@link #registerPhoneAccount}. |
| 776 | * @param extras A bundle that will be passed through to |
| 777 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 778 | */ |
| 779 | public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 780 | try { |
| 781 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 782 | getTelecomService().addNewIncomingCall( |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 783 | phoneAccount, extras == null ? new Bundle() : extras); |
| 784 | } |
| 785 | } catch (RemoteException e) { |
| 786 | Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e); |
| 787 | } |
| 788 | } |
| 789 | |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 790 | /** |
| 791 | * Processes the specified dial string as an MMI code. |
| 792 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 793 | * Some of these sequences launch special behavior through handled by Telephony. |
| 794 | * <p> |
| 795 | * Requires that the method-caller be set as the system dialer app. |
| 796 | * </p> |
| 797 | * |
| 798 | * @param dialString The digits to dial. |
| 799 | * @return True if the digits were processed as an MMI code, false otherwise. |
| 800 | */ |
| 801 | public boolean handleMmi(String dialString) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 802 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 803 | if (service != null) { |
| 804 | try { |
| 805 | return service.handlePinMmi(dialString); |
| 806 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 807 | Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Removes the missed-call notification if one is present. |
| 815 | * <p> |
| 816 | * Requires that the method-caller be set as the system dialer app. |
| 817 | * </p> |
| 818 | */ |
| 819 | public void cancelMissedCallsNotification() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 820 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 821 | if (service != null) { |
| 822 | try { |
| 823 | service.cancelMissedCallsNotification(); |
| 824 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 825 | Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Brings the in-call screen to the foreground if there is an ongoing call. If there is |
| 832 | * currently no ongoing call, then this method does nothing. |
| 833 | * <p> |
| 834 | * Requires that the method-caller be set as the system dialer app or have the |
| 835 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. |
| 836 | * </p> |
| 837 | * |
| 838 | * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen. |
| 839 | */ |
| 840 | public void showInCallScreen(boolean showDialpad) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 841 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 842 | if (service != null) { |
| 843 | try { |
| 844 | service.showInCallScreen(showDialpad); |
| 845 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 846 | Log.e(TAG, "Error calling ITelecomService#showCallScreen", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 851 | private ITelecomService getTelecomService() { |
| 852 | return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 853 | } |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 854 | |
| 855 | private boolean isServiceConnected() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 856 | boolean isConnected = getTelecomService() != null; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 857 | if (!isConnected) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 858 | Log.w(TAG, "Telecom Service not found."); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 859 | } |
| 860 | return isConnected; |
| 861 | } |
Evan Charlton | 235c159 | 2014-09-05 15:41:23 +0000 | [diff] [blame] | 862 | } |