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