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