Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 18 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.Nullable; |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 25 | import android.os.ParcelFileDescriptor; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 26 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 27 | import java.io.IOException; |
| 28 | import java.io.InputStreamReader; |
| 29 | import java.io.OutputStreamWriter; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 30 | import java.lang.String; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 31 | import java.lang.annotation.Retention; |
| 32 | import java.lang.annotation.RetentionPolicy; |
| 33 | import java.nio.charset.StandardCharsets; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 34 | import java.util.ArrayList; |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 35 | import java.util.Arrays; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 36 | import java.util.Collections; |
| 37 | import java.util.List; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 38 | import java.util.Map; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 39 | import java.util.Objects; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 40 | import java.util.concurrent.CopyOnWriteArrayList; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Represents an ongoing phone call that the in-call app should present to the user. |
| 44 | */ |
| 45 | public final class Call { |
| 46 | /** |
| 47 | * The state of a {@code Call} when newly created. |
| 48 | */ |
| 49 | public static final int STATE_NEW = 0; |
| 50 | |
| 51 | /** |
| 52 | * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected. |
| 53 | */ |
| 54 | public static final int STATE_DIALING = 1; |
| 55 | |
| 56 | /** |
| 57 | * The state of an incoming {@code Call} when ringing locally, but not yet connected. |
| 58 | */ |
| 59 | public static final int STATE_RINGING = 2; |
| 60 | |
| 61 | /** |
| 62 | * The state of a {@code Call} when in a holding state. |
| 63 | */ |
| 64 | public static final int STATE_HOLDING = 3; |
| 65 | |
| 66 | /** |
| 67 | * The state of a {@code Call} when actively supporting conversation. |
| 68 | */ |
| 69 | public static final int STATE_ACTIVE = 4; |
| 70 | |
| 71 | /** |
| 72 | * The state of a {@code Call} when no further voice or other communication is being |
| 73 | * transmitted, the remote side has been or will inevitably be informed that the {@code Call} |
| 74 | * is no longer active, and the local data transport has or inevitably will release resources |
| 75 | * associated with this {@code Call}. |
| 76 | */ |
| 77 | public static final int STATE_DISCONNECTED = 7; |
| 78 | |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 79 | /** |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 80 | * The state of an outgoing {@code Call} when waiting on user to select a |
| 81 | * {@link PhoneAccount} through which to place the call. |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 82 | */ |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 83 | public static final int STATE_SELECT_PHONE_ACCOUNT = 8; |
| 84 | |
| 85 | /** |
| 86 | * @hide |
| 87 | * @deprecated use STATE_SELECT_PHONE_ACCOUNT. |
| 88 | */ |
| 89 | @Deprecated |
| 90 | @SystemApi |
| 91 | public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT; |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 92 | |
Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 93 | /** |
Nancy Chen | e9b7a8e | 2014-08-08 14:26:27 -0700 | [diff] [blame] | 94 | * The initial state of an outgoing {@code Call}. |
| 95 | * Common transitions are to {@link #STATE_DIALING} state for a successful call or |
| 96 | * {@link #STATE_DISCONNECTED} if it failed. |
Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 97 | */ |
| 98 | public static final int STATE_CONNECTING = 9; |
| 99 | |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 100 | /** |
Tyler Gunn | 4afc6af | 2014-10-07 10:14:55 -0700 | [diff] [blame] | 101 | * The state of a {@code Call} when the user has initiated a disconnection of the call, but the |
| 102 | * call has not yet been disconnected by the underlying {@code ConnectionService}. The next |
| 103 | * state of the call is (potentially) {@link #STATE_DISCONNECTED}. |
| 104 | */ |
| 105 | public static final int STATE_DISCONNECTING = 10; |
| 106 | |
| 107 | /** |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 108 | * The state of an external call which is in the process of being pulled from a remote device to |
| 109 | * the local device. |
| 110 | * <p> |
| 111 | * A call can only be in this state if the {@link Details#PROPERTY_IS_EXTERNAL_CALL} property |
| 112 | * and {@link Details#CAPABILITY_CAN_PULL_CALL} capability are set on the call. |
| 113 | * <p> |
| 114 | * An {@link InCallService} will only see this state if it has the |
| 115 | * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its |
| 116 | * manifest. |
| 117 | */ |
| 118 | public static final int STATE_PULLING_CALL = 11; |
| 119 | |
| 120 | /** |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 121 | * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call |
| 122 | * extras. Used to pass the phone accounts to display on the front end to the user in order to |
| 123 | * select phone accounts to (for example) place a call. |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 124 | */ |
| 125 | public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts"; |
| 126 | |
mike dooley | 4af561f | 2016-12-20 08:55:17 -0800 | [diff] [blame] | 127 | /** |
mike dooley | 9121742 | 2017-03-09 12:58:42 -0800 | [diff] [blame] | 128 | * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC) |
| 129 | * when the last outgoing emergency call was made. This is used to identify potential emergency |
| 130 | * callbacks. |
mike dooley | 4af561f | 2016-12-20 08:55:17 -0800 | [diff] [blame] | 131 | */ |
| 132 | public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS = |
| 133 | "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS"; |
| 134 | |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 135 | /** |
| 136 | * Call event sent from a {@link Call} via {@link #sendCallEvent(String, Bundle)} to inform |
| 137 | * Telecom that the user has requested that the current {@link Call} should be handed over |
| 138 | * to another {@link ConnectionService}. |
| 139 | * <p> |
| 140 | * The caller must specify the {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE} to indicate to |
| 141 | * Telecom which {@link PhoneAccountHandle} the {@link Call} should be handed over to. |
| 142 | * @hide |
| 143 | */ |
| 144 | public static final String EVENT_REQUEST_HANDOVER = |
| 145 | "android.telecom.event.REQUEST_HANDOVER"; |
| 146 | |
| 147 | /** |
| 148 | * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the |
| 149 | * {@link PhoneAccountHandle} to which a call should be handed over to. |
| 150 | * @hide |
| 151 | */ |
| 152 | public static final String EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE = |
| 153 | "android.telecom.extra.HANDOVER_PHONE_ACCOUNT_HANDLE"; |
| 154 | |
| 155 | /** |
| 156 | * Integer extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Specifies the |
| 157 | * video state of the call when it is handed over to the new {@link PhoneAccount}. |
| 158 | * <p> |
| 159 | * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY}, |
| 160 | * {@link VideoProfile#STATE_BIDIRECTIONAL}, {@link VideoProfile#STATE_RX_ENABLED}, and |
| 161 | * {@link VideoProfile#STATE_TX_ENABLED}. |
| 162 | * @hide |
| 163 | */ |
| 164 | public static final String EXTRA_HANDOVER_VIDEO_STATE = |
| 165 | "android.telecom.extra.HANDOVER_VIDEO_STATE"; |
| 166 | |
| 167 | /** |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 168 | * Extra key used with the {@link #EVENT_REQUEST_HANDOVER} call event. Used by the |
| 169 | * {@link InCallService} initiating a handover to provide a {@link Bundle} with extra |
| 170 | * information to the handover {@link ConnectionService} specified by |
| 171 | * {@link #EXTRA_HANDOVER_PHONE_ACCOUNT_HANDLE}. |
| 172 | * <p> |
| 173 | * This {@link Bundle} is not interpreted by Telecom, but passed as-is to the |
| 174 | * {@link ConnectionService} via the request extras when |
| 175 | * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} |
| 176 | * is called to initate the handover. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 177 | * @hide |
| 178 | */ |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 179 | public static final String EXTRA_HANDOVER_EXTRAS = "android.telecom.extra.HANDOVER_EXTRAS"; |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 180 | |
| 181 | /** |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 182 | * Call event sent from Telecom to the handover {@link ConnectionService} via |
| 183 | * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover |
| 184 | * to the {@link ConnectionService} has completed successfully. |
| 185 | * <p> |
| 186 | * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 187 | * @hide |
| 188 | */ |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 189 | public static final String EVENT_HANDOVER_COMPLETE = |
| 190 | "android.telecom.event.HANDOVER_COMPLETE"; |
Tyler Gunn | 34a2b31 | 2017-06-23 08:32:00 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Call event sent from Telecom to the handover destination {@link ConnectionService} via |
| 194 | * {@link Connection#onCallEvent(String, Bundle)} to inform the handover destination that the |
| 195 | * source connection has disconnected. The {@link Bundle} parameter for the call event will be |
| 196 | * {@code null}. |
| 197 | * <p> |
| 198 | * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event. |
| 199 | * @hide |
| 200 | */ |
| 201 | public static final String EVENT_HANDOVER_SOURCE_DISCONNECTED = |
| 202 | "android.telecom.event.HANDOVER_SOURCE_DISCONNECTED"; |
| 203 | |
Tyler Gunn | 9f6f047 | 2017-04-17 18:25:22 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Call event sent from Telecom to the handover {@link ConnectionService} via |
| 206 | * {@link Connection#onCallEvent(String, Bundle)} to inform a {@link Connection} that a handover |
| 207 | * to the {@link ConnectionService} has failed. |
| 208 | * <p> |
| 209 | * A handover is initiated with the {@link #EVENT_REQUEST_HANDOVER} call event. |
| 210 | * @hide |
| 211 | */ |
| 212 | public static final String EVENT_HANDOVER_FAILED = |
| 213 | "android.telecom.event.HANDOVER_FAILED"; |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 214 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 215 | public static class Details { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 216 | |
| 217 | /** Call can currently be put on hold or unheld. */ |
| 218 | public static final int CAPABILITY_HOLD = 0x00000001; |
| 219 | |
| 220 | /** Call supports the hold feature. */ |
| 221 | public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002; |
| 222 | |
| 223 | /** |
| 224 | * Calls within a conference can be merged. A {@link ConnectionService} has the option to |
| 225 | * add a {@link Conference} call before the child {@link Connection}s are merged. This is how |
| 226 | * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this |
| 227 | * capability allows a merge button to be shown while the conference call is in the foreground |
| 228 | * of the in-call UI. |
| 229 | * <p> |
| 230 | * This is only intended for use by a {@link Conference}. |
| 231 | */ |
| 232 | public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004; |
| 233 | |
| 234 | /** |
| 235 | * Calls within a conference can be swapped between foreground and background. |
| 236 | * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information. |
| 237 | * <p> |
| 238 | * This is only intended for use by a {@link Conference}. |
| 239 | */ |
| 240 | public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008; |
| 241 | |
| 242 | /** |
| 243 | * @hide |
| 244 | */ |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 245 | public static final int CAPABILITY_UNUSED_1 = 0x00000010; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 246 | |
| 247 | /** Call supports responding via text option. */ |
| 248 | public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020; |
| 249 | |
| 250 | /** Call can be muted. */ |
| 251 | public static final int CAPABILITY_MUTE = 0x00000040; |
| 252 | |
| 253 | /** |
| 254 | * Call supports conference call management. This capability only applies to {@link Conference} |
| 255 | * calls which can have {@link Connection}s as children. |
| 256 | */ |
| 257 | public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080; |
| 258 | |
| 259 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 260 | * Local device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 261 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 262 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 263 | |
| 264 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 265 | * Local device supports transmitting video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 266 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 267 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 268 | |
| 269 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 270 | * Local device supports bidirectional video calling. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 271 | */ |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 272 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL = |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 273 | CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 274 | |
| 275 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 276 | * Remote device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 277 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 278 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400; |
| 279 | |
| 280 | /** |
| 281 | * Remote device supports transmitting video. |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 282 | */ |
| 283 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800; |
| 284 | |
| 285 | /** |
| 286 | * Remote device supports bidirectional video calling. |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 287 | */ |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 288 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL = |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 289 | CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 290 | |
| 291 | /** |
| 292 | * Call is able to be separated from its parent {@code Conference}, if any. |
| 293 | */ |
| 294 | public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000; |
| 295 | |
| 296 | /** |
| 297 | * Call is able to be individually disconnected when in a {@code Conference}. |
| 298 | */ |
| 299 | public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000; |
| 300 | |
| 301 | /** |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 302 | * Speed up audio setup for MT call. |
| 303 | * @hide |
| 304 | */ |
Tyler Gunn | 96d6c40 | 2015-03-18 12:39:23 -0700 | [diff] [blame] | 305 | public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000; |
| 306 | |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Call can be upgraded to a video call. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 309 | * @hide |
| 310 | */ |
| 311 | public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000; |
| 312 | |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 313 | /** |
| 314 | * For video calls, indicates whether the outgoing video for the call can be paused using |
Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 315 | * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState. |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 316 | */ |
| 317 | public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000; |
| 318 | |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Call sends responses through connection. |
| 321 | * @hide |
| 322 | */ |
Tyler Gunn | f97a009 | 2016-01-19 15:59:34 -0800 | [diff] [blame] | 323 | public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000; |
| 324 | |
| 325 | /** |
| 326 | * When set, prevents a video {@code Call} from being downgraded to an audio-only call. |
| 327 | * <p> |
| 328 | * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or |
| 329 | * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be |
| 330 | * downgraded from a video call back to a VideoState of |
| 331 | * {@link VideoProfile#STATE_AUDIO_ONLY}. |
| 332 | * <p> |
| 333 | * Intuitively, a call which can be downgraded to audio should also have local and remote |
| 334 | * video |
| 335 | * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and |
| 336 | * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}). |
| 337 | */ |
| 338 | public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000; |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 339 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 340 | /** |
| 341 | * When set for an external call, indicates that this {@code Call} can be pulled from a |
| 342 | * remote device to the current device. |
| 343 | * <p> |
| 344 | * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set. |
| 345 | * <p> |
| 346 | * An {@link InCallService} will only see calls with this capability if it has the |
| 347 | * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} |
| 348 | * in its manifest. |
| 349 | * <p> |
| 350 | * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 351 | * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 352 | */ |
| 353 | public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000; |
| 354 | |
Pooja Jain | d34698d | 2017-12-28 14:15:31 +0530 | [diff] [blame] | 355 | /** Call supports the deflect feature. */ |
| 356 | public static final int CAPABILITY_SUPPORT_DEFLECT = 0x01000000; |
| 357 | |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 358 | //****************************************************************************************** |
Pooja Jain | d34698d | 2017-12-28 14:15:31 +0530 | [diff] [blame] | 359 | // Next CAPABILITY value: 0x02000000 |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 360 | //****************************************************************************************** |
| 361 | |
| 362 | /** |
| 363 | * Whether the call is currently a conference. |
| 364 | */ |
| 365 | public static final int PROPERTY_CONFERENCE = 0x00000001; |
| 366 | |
| 367 | /** |
| 368 | * Whether the call is a generic conference, where we do not know the precise state of |
| 369 | * participants in the conference (eg. on CDMA). |
| 370 | */ |
| 371 | public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002; |
| 372 | |
| 373 | /** |
| 374 | * Whether the call is made while the device is in emergency callback mode. |
| 375 | */ |
| 376 | public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004; |
| 377 | |
| 378 | /** |
| 379 | * Connection is using WIFI. |
| 380 | */ |
| 381 | public static final int PROPERTY_WIFI = 0x00000008; |
| 382 | |
| 383 | /** |
| 384 | * Call is using high definition audio. |
| 385 | */ |
| 386 | public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010; |
| 387 | |
Tony Mak | a68dcce | 2015-12-17 09:31:18 +0000 | [diff] [blame] | 388 | /** |
Tony Mak | 53b5df4 | 2016-05-19 13:40:38 +0100 | [diff] [blame] | 389 | * Whether the call is associated with the work profile. |
| 390 | */ |
| 391 | public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020; |
| 392 | |
| 393 | /** |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 394 | * When set, indicates that this {@code Call} does not actually exist locally for the |
| 395 | * {@link ConnectionService}. |
| 396 | * <p> |
| 397 | * Consider, for example, a scenario where a user has two phones with the same phone number. |
| 398 | * When a user places a call on one device, the telephony stack can represent that call on |
| 399 | * the other device by adding it to the {@link ConnectionService} with the |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 400 | * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 401 | * <p> |
| 402 | * An {@link InCallService} will only see calls with this property if it has the |
| 403 | * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} |
| 404 | * in its manifest. |
| 405 | * <p> |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 406 | * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 407 | */ |
| 408 | public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040; |
| 409 | |
Brad Ebinger | 1584707 | 2016-05-18 11:08:36 -0700 | [diff] [blame] | 410 | /** |
| 411 | * Indicates that the call has CDMA Enhanced Voice Privacy enabled. |
| 412 | */ |
| 413 | public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080; |
| 414 | |
Tyler Gunn | 24e1833 | 2017-02-10 09:42:49 -0800 | [diff] [blame] | 415 | /** |
| 416 | * Indicates that the call is from a self-managed {@link ConnectionService}. |
| 417 | * <p> |
| 418 | * See also {@link Connection#PROPERTY_SELF_MANAGED} |
| 419 | */ |
| 420 | public static final int PROPERTY_SELF_MANAGED = 0x00000100; |
| 421 | |
Eric Erfanian | ec88187 | 2017-12-06 16:27:53 -0800 | [diff] [blame] | 422 | /** |
| 423 | * Indicates the call used Assisted Dialing. |
| 424 | * See also {@link Connection#PROPERTY_ASSISTED_DIALING_USED} |
| 425 | * @hide |
| 426 | */ |
| 427 | public static final int PROPERTY_ASSISTED_DIALING_USED = 0x00000200; |
| 428 | |
Hall Liu | e904124 | 2018-02-09 16:40:03 -0800 | [diff] [blame^] | 429 | /** |
| 430 | * Indicates that the call is an RTT call. Use {@link #getRttCall()} to get the |
| 431 | * {@link RttCall} object that is used to send and receive text. |
| 432 | */ |
| 433 | public static final int PROPERTY_RTT = 0x00000400; |
| 434 | |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 435 | //****************************************************************************************** |
Hall Liu | e904124 | 2018-02-09 16:40:03 -0800 | [diff] [blame^] | 436 | // Next PROPERTY value: 0x00000800 |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 437 | //****************************************************************************************** |
Tyler Gunn | 068085b | 2015-02-06 13:56:52 -0800 | [diff] [blame] | 438 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 439 | private final String mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 440 | private final Uri mHandle; |
| 441 | private final int mHandlePresentation; |
| 442 | private final String mCallerDisplayName; |
| 443 | private final int mCallerDisplayNamePresentation; |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 444 | private final PhoneAccountHandle mAccountHandle; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 445 | private final int mCallCapabilities; |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 446 | private final int mCallProperties; |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 447 | private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 448 | private final DisconnectCause mDisconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 449 | private final long mConnectTimeMillis; |
| 450 | private final GatewayInfo mGatewayInfo; |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 451 | private final int mVideoState; |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 452 | private final StatusHints mStatusHints; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 453 | private final Bundle mExtras; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 454 | private final Bundle mIntentExtras; |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 455 | private final long mCreationTimeMillis; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 456 | |
| 457 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 458 | * Whether the supplied capabilities supports the specified capability. |
| 459 | * |
| 460 | * @param capabilities A bit field of capabilities. |
| 461 | * @param capability The capability to check capabilities for. |
| 462 | * @return Whether the specified capability is supported. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 463 | */ |
| 464 | public static boolean can(int capabilities, int capability) { |
Tyler Gunn | 014c711 | 2015-12-18 14:33:57 -0800 | [diff] [blame] | 465 | return (capabilities & capability) == capability; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Whether the capabilities of this {@code Details} supports the specified capability. |
| 470 | * |
| 471 | * @param capability The capability to check capabilities for. |
| 472 | * @return Whether the specified capability is supported. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 473 | */ |
| 474 | public boolean can(int capability) { |
| 475 | return can(mCallCapabilities, capability); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string. |
| 480 | * |
| 481 | * @param capabilities A capability bit field. |
| 482 | * @return A human readable string representation. |
| 483 | */ |
| 484 | public static String capabilitiesToString(int capabilities) { |
| 485 | StringBuilder builder = new StringBuilder(); |
| 486 | builder.append("[Capabilities:"); |
| 487 | if (can(capabilities, CAPABILITY_HOLD)) { |
| 488 | builder.append(" CAPABILITY_HOLD"); |
| 489 | } |
| 490 | if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) { |
| 491 | builder.append(" CAPABILITY_SUPPORT_HOLD"); |
| 492 | } |
| 493 | if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) { |
| 494 | builder.append(" CAPABILITY_MERGE_CONFERENCE"); |
| 495 | } |
| 496 | if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) { |
| 497 | builder.append(" CAPABILITY_SWAP_CONFERENCE"); |
| 498 | } |
| 499 | if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) { |
| 500 | builder.append(" CAPABILITY_RESPOND_VIA_TEXT"); |
| 501 | } |
| 502 | if (can(capabilities, CAPABILITY_MUTE)) { |
| 503 | builder.append(" CAPABILITY_MUTE"); |
| 504 | } |
| 505 | if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) { |
| 506 | builder.append(" CAPABILITY_MANAGE_CONFERENCE"); |
| 507 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 508 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) { |
| 509 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX"); |
| 510 | } |
| 511 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) { |
| 512 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX"); |
| 513 | } |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 514 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) { |
| 515 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 516 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 517 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) { |
| 518 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX"); |
| 519 | } |
| 520 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) { |
| 521 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX"); |
| 522 | } |
Tyler Gunn | f97a009 | 2016-01-19 15:59:34 -0800 | [diff] [blame] | 523 | if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) { |
| 524 | builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO"); |
| 525 | } |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 526 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) { |
| 527 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 528 | } |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 529 | if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) { |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 530 | builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO"); |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 531 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 532 | if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) { |
| 533 | builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO"); |
| 534 | } |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 535 | if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) { |
| 536 | builder.append(" CAPABILITY_CAN_PAUSE_VIDEO"); |
| 537 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 538 | if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) { |
| 539 | builder.append(" CAPABILITY_CAN_PULL_CALL"); |
| 540 | } |
Pooja Jain | d34698d | 2017-12-28 14:15:31 +0530 | [diff] [blame] | 541 | if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) { |
| 542 | builder.append(" CAPABILITY_SUPPORT_DEFLECT"); |
| 543 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 544 | builder.append("]"); |
| 545 | return builder.toString(); |
| 546 | } |
| 547 | |
| 548 | /** |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 549 | * Whether the supplied properties includes the specified property. |
| 550 | * |
| 551 | * @param properties A bit field of properties. |
| 552 | * @param property The property to check properties for. |
| 553 | * @return Whether the specified property is supported. |
| 554 | */ |
| 555 | public static boolean hasProperty(int properties, int property) { |
Tyler Gunn | 014c711 | 2015-12-18 14:33:57 -0800 | [diff] [blame] | 556 | return (properties & property) == property; |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Whether the properties of this {@code Details} includes the specified property. |
| 561 | * |
| 562 | * @param property The property to check properties for. |
| 563 | * @return Whether the specified property is supported. |
| 564 | */ |
| 565 | public boolean hasProperty(int property) { |
| 566 | return hasProperty(mCallProperties, property); |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Render a set of property bits ({@code PROPERTY_*}) as a human readable string. |
| 571 | * |
| 572 | * @param properties A property bit field. |
| 573 | * @return A human readable string representation. |
| 574 | */ |
| 575 | public static String propertiesToString(int properties) { |
| 576 | StringBuilder builder = new StringBuilder(); |
| 577 | builder.append("[Properties:"); |
| 578 | if (hasProperty(properties, PROPERTY_CONFERENCE)) { |
| 579 | builder.append(" PROPERTY_CONFERENCE"); |
| 580 | } |
| 581 | if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) { |
| 582 | builder.append(" PROPERTY_GENERIC_CONFERENCE"); |
| 583 | } |
| 584 | if (hasProperty(properties, PROPERTY_WIFI)) { |
| 585 | builder.append(" PROPERTY_WIFI"); |
| 586 | } |
| 587 | if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) { |
| 588 | builder.append(" PROPERTY_HIGH_DEF_AUDIO"); |
| 589 | } |
| 590 | if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) { |
Yorke Lee | be2a4a2 | 2015-06-12 10:10:55 -0700 | [diff] [blame] | 591 | builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE"); |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 592 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 593 | if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) { |
| 594 | builder.append(" PROPERTY_IS_EXTERNAL_CALL"); |
| 595 | } |
Brad Ebinger | 1584707 | 2016-05-18 11:08:36 -0700 | [diff] [blame] | 596 | if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) { |
| 597 | builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY"); |
| 598 | } |
Eric Erfanian | ec88187 | 2017-12-06 16:27:53 -0800 | [diff] [blame] | 599 | if(hasProperty(properties, PROPERTY_ASSISTED_DIALING_USED)) { |
| 600 | builder.append(" PROPERTY_ASSISTED_DIALING_USED"); |
| 601 | } |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 602 | builder.append("]"); |
| 603 | return builder.toString(); |
| 604 | } |
| 605 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 606 | /** {@hide} */ |
| 607 | public String getTelecomCallId() { |
| 608 | return mTelecomCallId; |
| 609 | } |
| 610 | |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 611 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 612 | * @return The handle (e.g., phone number) to which the {@code Call} is currently |
| 613 | * connected. |
| 614 | */ |
| 615 | public Uri getHandle() { |
| 616 | return mHandle; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * @return The presentation requirements for the handle. See |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 621 | * {@link TelecomManager} for valid values. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 622 | */ |
| 623 | public int getHandlePresentation() { |
| 624 | return mHandlePresentation; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * @return The display name for the caller. |
| 629 | */ |
| 630 | public String getCallerDisplayName() { |
| 631 | return mCallerDisplayName; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * @return The presentation requirements for the caller display name. See |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 636 | * {@link TelecomManager} for valid values. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 637 | */ |
| 638 | public int getCallerDisplayNamePresentation() { |
| 639 | return mCallerDisplayNamePresentation; |
| 640 | } |
| 641 | |
| 642 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 643 | * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being |
| 644 | * routed. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 645 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 646 | public PhoneAccountHandle getAccountHandle() { |
| 647 | return mAccountHandle; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 651 | * @return A bitmask of the capabilities of the {@code Call}, as defined by the various |
| 652 | * {@code CAPABILITY_*} constants in this class. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 653 | */ |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 654 | public int getCallCapabilities() { |
| 655 | return mCallCapabilities; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 659 | * @return A bitmask of the properties of the {@code Call}, as defined by the various |
| 660 | * {@code PROPERTY_*} constants in this class. |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 661 | */ |
| 662 | public int getCallProperties() { |
| 663 | return mCallProperties; |
| 664 | } |
| 665 | |
| 666 | /** |
Christine Hallstrom | 4e22d6d | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 667 | * @return a bitmask of the audio routes available for the call. |
| 668 | * |
| 669 | * @hide |
| 670 | */ |
| 671 | public int getSupportedAudioRoutes() { |
| 672 | return mSupportedAudioRoutes; |
| 673 | } |
| 674 | |
| 675 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 676 | * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 677 | * by {@link android.telecom.DisconnectCause}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 678 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 679 | public DisconnectCause getDisconnectCause() { |
| 680 | return mDisconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 684 | * Returns the time the {@link Call} connected (i.e. became active). This information is |
| 685 | * updated periodically, but user interfaces should not rely on this to display the "call |
| 686 | * time clock". For the time when the call was first added to Telecom, see |
| 687 | * {@link #getCreationTimeMillis()}. |
| 688 | * |
| 689 | * @return The time the {@link Call} connected in milliseconds since the epoch. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 690 | */ |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 691 | public final long getConnectTimeMillis() { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 692 | return mConnectTimeMillis; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * @return Information about any calling gateway the {@code Call} may be using. |
| 697 | */ |
| 698 | public GatewayInfo getGatewayInfo() { |
| 699 | return mGatewayInfo; |
| 700 | } |
| 701 | |
Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 702 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 703 | * @return The video state of the {@code Call}. |
Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 704 | */ |
| 705 | public int getVideoState() { |
| 706 | return mVideoState; |
| 707 | } |
| 708 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 709 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 710 | * @return The current {@link android.telecom.StatusHints}, or {@code null} if none |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 711 | * have been set. |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 712 | */ |
| 713 | public StatusHints getStatusHints() { |
| 714 | return mStatusHints; |
| 715 | } |
| 716 | |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 717 | /** |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 718 | * @return The extras associated with this call. |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 719 | */ |
| 720 | public Bundle getExtras() { |
| 721 | return mExtras; |
| 722 | } |
| 723 | |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 724 | /** |
| 725 | * @return The extras used with the original intent to place this call. |
| 726 | */ |
| 727 | public Bundle getIntentExtras() { |
| 728 | return mIntentExtras; |
| 729 | } |
| 730 | |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 731 | /** |
| 732 | * Returns the time when the call was first created and added to Telecom. This is the same |
| 733 | * time that is logged as the start time in the Call Log (see |
| 734 | * {@link android.provider.CallLog.Calls#DATE}). To determine when the call was connected |
| 735 | * (became active), see {@link #getConnectTimeMillis()}. |
| 736 | * |
| 737 | * @return The creation time of the call, in millis since the epoch. |
| 738 | */ |
| 739 | public long getCreationTimeMillis() { |
| 740 | return mCreationTimeMillis; |
| 741 | } |
| 742 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 743 | @Override |
| 744 | public boolean equals(Object o) { |
| 745 | if (o instanceof Details) { |
| 746 | Details d = (Details) o; |
| 747 | return |
| 748 | Objects.equals(mHandle, d.mHandle) && |
| 749 | Objects.equals(mHandlePresentation, d.mHandlePresentation) && |
| 750 | Objects.equals(mCallerDisplayName, d.mCallerDisplayName) && |
| 751 | Objects.equals(mCallerDisplayNamePresentation, |
| 752 | d.mCallerDisplayNamePresentation) && |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 753 | Objects.equals(mAccountHandle, d.mAccountHandle) && |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 754 | Objects.equals(mCallCapabilities, d.mCallCapabilities) && |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 755 | Objects.equals(mCallProperties, d.mCallProperties) && |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 756 | Objects.equals(mDisconnectCause, d.mDisconnectCause) && |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 757 | Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) && |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 758 | Objects.equals(mGatewayInfo, d.mGatewayInfo) && |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 759 | Objects.equals(mVideoState, d.mVideoState) && |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 760 | Objects.equals(mStatusHints, d.mStatusHints) && |
Tyler Gunn | 1e9bfc6 | 2015-08-19 11:18:58 -0700 | [diff] [blame] | 761 | areBundlesEqual(mExtras, d.mExtras) && |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 762 | areBundlesEqual(mIntentExtras, d.mIntentExtras) && |
| 763 | Objects.equals(mCreationTimeMillis, d.mCreationTimeMillis); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 764 | } |
| 765 | return false; |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public int hashCode() { |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 770 | return Objects.hash(mHandle, |
| 771 | mHandlePresentation, |
| 772 | mCallerDisplayName, |
| 773 | mCallerDisplayNamePresentation, |
| 774 | mAccountHandle, |
| 775 | mCallCapabilities, |
| 776 | mCallProperties, |
| 777 | mDisconnectCause, |
| 778 | mConnectTimeMillis, |
| 779 | mGatewayInfo, |
| 780 | mVideoState, |
| 781 | mStatusHints, |
| 782 | mExtras, |
| 783 | mIntentExtras, |
| 784 | mCreationTimeMillis); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /** {@hide} */ |
| 788 | public Details( |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 789 | String telecomCallId, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 790 | Uri handle, |
| 791 | int handlePresentation, |
| 792 | String callerDisplayName, |
| 793 | int callerDisplayNamePresentation, |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 794 | PhoneAccountHandle accountHandle, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 795 | int capabilities, |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 796 | int properties, |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 797 | DisconnectCause disconnectCause, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 798 | long connectTimeMillis, |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 799 | GatewayInfo gatewayInfo, |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 800 | int videoState, |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 801 | StatusHints statusHints, |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 802 | Bundle extras, |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 803 | Bundle intentExtras, |
| 804 | long creationTimeMillis) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 805 | mTelecomCallId = telecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 806 | mHandle = handle; |
| 807 | mHandlePresentation = handlePresentation; |
| 808 | mCallerDisplayName = callerDisplayName; |
| 809 | mCallerDisplayNamePresentation = callerDisplayNamePresentation; |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 810 | mAccountHandle = accountHandle; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 811 | mCallCapabilities = capabilities; |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 812 | mCallProperties = properties; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 813 | mDisconnectCause = disconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 814 | mConnectTimeMillis = connectTimeMillis; |
| 815 | mGatewayInfo = gatewayInfo; |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 816 | mVideoState = videoState; |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 817 | mStatusHints = statusHints; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 818 | mExtras = extras; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 819 | mIntentExtras = intentExtras; |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 820 | mCreationTimeMillis = creationTimeMillis; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 821 | } |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 822 | |
| 823 | /** {@hide} */ |
| 824 | public static Details createFromParcelableCall(ParcelableCall parcelableCall) { |
| 825 | return new Details( |
| 826 | parcelableCall.getId(), |
| 827 | parcelableCall.getHandle(), |
| 828 | parcelableCall.getHandlePresentation(), |
| 829 | parcelableCall.getCallerDisplayName(), |
| 830 | parcelableCall.getCallerDisplayNamePresentation(), |
| 831 | parcelableCall.getAccountHandle(), |
| 832 | parcelableCall.getCapabilities(), |
| 833 | parcelableCall.getProperties(), |
| 834 | parcelableCall.getDisconnectCause(), |
| 835 | parcelableCall.getConnectTimeMillis(), |
| 836 | parcelableCall.getGatewayInfo(), |
| 837 | parcelableCall.getVideoState(), |
| 838 | parcelableCall.getStatusHints(), |
| 839 | parcelableCall.getExtras(), |
Tyler Gunn | c0bf6de | 2017-03-17 11:27:09 -0700 | [diff] [blame] | 840 | parcelableCall.getIntentExtras(), |
| 841 | parcelableCall.getCreationTimeMillis()); |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 842 | } |
Santos Cordon | 3c20d63 | 2016-02-25 16:12:35 -0800 | [diff] [blame] | 843 | |
| 844 | @Override |
| 845 | public String toString() { |
| 846 | StringBuilder sb = new StringBuilder(); |
| 847 | sb.append("[pa: "); |
| 848 | sb.append(mAccountHandle); |
| 849 | sb.append(", hdl: "); |
| 850 | sb.append(Log.pii(mHandle)); |
| 851 | sb.append(", caps: "); |
| 852 | sb.append(capabilitiesToString(mCallCapabilities)); |
| 853 | sb.append(", props: "); |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 854 | sb.append(propertiesToString(mCallProperties)); |
Santos Cordon | 3c20d63 | 2016-02-25 16:12:35 -0800 | [diff] [blame] | 855 | sb.append("]"); |
| 856 | return sb.toString(); |
| 857 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 860 | /** |
| 861 | * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}. |
| 862 | * These callbacks can originate from the Telecom framework, or a {@link ConnectionService} |
| 863 | * implementation. |
| 864 | * <p> |
| 865 | * You can handle these callbacks by extending the {@link Callback} class and overriding the |
| 866 | * callbacks that your {@link InCallService} is interested in. The callback methods include the |
| 867 | * {@link Call} for which the callback applies, allowing reuse of a single instance of your |
| 868 | * {@link Callback} implementation, if desired. |
| 869 | * <p> |
| 870 | * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure |
| 871 | * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks |
| 872 | * (typically in {@link InCallService#onCallRemoved(Call)}). |
| 873 | * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not |
| 874 | * reach your implementation of {@link Callback}, so it is important to register your callback |
| 875 | * as soon as your {@link InCallService} is notified of a new call via |
| 876 | * {@link InCallService#onCallAdded(Call)}. |
| 877 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 878 | public static abstract class Callback { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 879 | /** |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 880 | * @hide |
| 881 | */ |
| 882 | @IntDef({HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_DEST_NOT_SUPPORTED, |
Sanket Padawe | 85291f6 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 883 | HANDOVER_FAILURE_DEST_INVALID_PERM, HANDOVER_FAILURE_DEST_USER_REJECTED, |
| 884 | HANDOVER_FAILURE_ONGOING_EMERG_CALL}) |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 885 | @Retention(RetentionPolicy.SOURCE) |
| 886 | public @interface HandoverFailureErrors {} |
| 887 | |
| 888 | /** |
| 889 | * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app |
| 890 | * to handover the call rejects handover. |
| 891 | */ |
| 892 | public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1; |
| 893 | |
| 894 | /** |
| 895 | * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there is |
| 896 | * an error associated with unsupported handover. |
| 897 | */ |
| 898 | public static final int HANDOVER_FAILURE_DEST_NOT_SUPPORTED = 2; |
| 899 | |
| 900 | /** |
| 901 | * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there |
| 902 | * are some permission errors associated with APIs doing handover. |
| 903 | */ |
| 904 | public static final int HANDOVER_FAILURE_DEST_INVALID_PERM = 3; |
| 905 | |
| 906 | /** |
| 907 | * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when user |
| 908 | * rejects handover. |
| 909 | */ |
| 910 | public static final int HANDOVER_FAILURE_DEST_USER_REJECTED = 4; |
| 911 | |
Sanket Padawe | 85291f6 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 912 | /** |
| 913 | * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there |
| 914 | * is ongoing emergency call. |
| 915 | */ |
| 916 | public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 5; |
| 917 | |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 918 | |
| 919 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 920 | * Invoked when the state of this {@code Call} has changed. See {@link #getState()}. |
| 921 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 922 | * @param call The {@code Call} invoking this method. |
| 923 | * @param state The new state of the {@code Call}. |
| 924 | */ |
| 925 | public void onStateChanged(Call call, int state) {} |
| 926 | |
| 927 | /** |
| 928 | * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}. |
| 929 | * |
| 930 | * @param call The {@code Call} invoking this method. |
| 931 | * @param parent The new parent of the {@code Call}. |
| 932 | */ |
| 933 | public void onParentChanged(Call call, Call parent) {} |
| 934 | |
| 935 | /** |
| 936 | * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}. |
| 937 | * |
| 938 | * @param call The {@code Call} invoking this method. |
| 939 | * @param children The new children of the {@code Call}. |
| 940 | */ |
| 941 | public void onChildrenChanged(Call call, List<Call> children) {} |
| 942 | |
| 943 | /** |
| 944 | * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}. |
| 945 | * |
| 946 | * @param call The {@code Call} invoking this method. |
| 947 | * @param details A {@code Details} object describing the {@code Call}. |
| 948 | */ |
| 949 | public void onDetailsChanged(Call call, Details details) {} |
| 950 | |
| 951 | /** |
| 952 | * Invoked when the text messages that can be used as responses to the incoming |
| 953 | * {@code Call} are loaded from the relevant database. |
| 954 | * See {@link #getCannedTextResponses()}. |
| 955 | * |
| 956 | * @param call The {@code Call} invoking this method. |
| 957 | * @param cannedTextResponses The text messages useable as responses. |
| 958 | */ |
| 959 | public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {} |
| 960 | |
| 961 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 962 | * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause |
| 963 | * character. This causes the post-dial signals to stop pending user confirmation. An |
| 964 | * implementation should present this choice to the user and invoke |
| 965 | * {@link #postDialContinue(boolean)} when the user makes the choice. |
| 966 | * |
| 967 | * @param call The {@code Call} invoking this method. |
| 968 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 969 | */ |
| 970 | public void onPostDialWait(Call call, String remainingPostDialSequence) {} |
| 971 | |
| 972 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 973 | * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 974 | * |
| 975 | * @param call The {@code Call} invoking this method. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 976 | * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 977 | */ |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 978 | public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {} |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 979 | |
| 980 | /** |
| 981 | * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning |
| 982 | * up their UI for the {@code Call} in response to state transitions. Specifically, |
| 983 | * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of |
| 984 | * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather, |
| 985 | * clients should wait for this method to be invoked. |
| 986 | * |
| 987 | * @param call The {@code Call} being destroyed. |
| 988 | */ |
| 989 | public void onCallDestroyed(Call call) {} |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 990 | |
| 991 | /** |
| 992 | * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be |
| 993 | * conferenced. |
| 994 | * |
| 995 | * @param call The {@code Call} being updated. |
| 996 | * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be |
| 997 | * conferenced. |
| 998 | */ |
| 999 | public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {} |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1000 | |
| 1001 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 1002 | * Invoked when a {@link Call} receives an event from its associated {@link Connection}. |
| 1003 | * <p> |
| 1004 | * Where possible, the Call should make an attempt to handle {@link Connection} events which |
| 1005 | * are part of the {@code android.telecom.*} namespace. The Call should ignore any events |
| 1006 | * it does not wish to handle. Unexpected events should be handled gracefully, as it is |
| 1007 | * possible that a {@link ConnectionService} has defined its own Connection events which a |
| 1008 | * Call is not aware of. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1009 | * <p> |
| 1010 | * See {@link Connection#sendConnectionEvent(String, Bundle)}. |
| 1011 | * |
| 1012 | * @param call The {@code Call} receiving the event. |
| 1013 | * @param event The event. |
| 1014 | * @param extras Extras associated with the connection event. |
| 1015 | */ |
| 1016 | public void onConnectionEvent(Call call, String event, Bundle extras) {} |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1017 | |
| 1018 | /** |
| 1019 | * Invoked when the RTT mode changes for this call. |
| 1020 | * @param call The call whose RTT mode has changed. |
| 1021 | * @param mode the new RTT mode, one of |
| 1022 | * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO}, |
| 1023 | * or {@link RttCall#RTT_MODE_VCO} |
| 1024 | */ |
| 1025 | public void onRttModeChanged(Call call, int mode) {} |
| 1026 | |
| 1027 | /** |
| 1028 | * Invoked when the call's RTT status changes, either from off to on or from on to off. |
| 1029 | * @param call The call whose RTT status has changed. |
| 1030 | * @param enabled whether RTT is now enabled or disabled |
| 1031 | * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now |
| 1032 | * on, null otherwise. |
| 1033 | */ |
| 1034 | public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {} |
| 1035 | |
| 1036 | /** |
| 1037 | * Invoked when the remote end of the connection has requested that an RTT communication |
| 1038 | * channel be opened. A response to this should be sent via {@link #respondToRttRequest} |
| 1039 | * with the same ID that this method is invoked with. |
| 1040 | * @param call The call which the RTT request was placed on |
| 1041 | * @param id The ID of the request. |
| 1042 | */ |
| 1043 | public void onRttRequest(Call call, int id) {} |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1044 | |
| 1045 | /** |
| 1046 | * Invoked when the RTT session failed to initiate for some reason, including rejection |
| 1047 | * by the remote party. |
| 1048 | * @param call The call which the RTT initiation failure occurred on. |
| 1049 | * @param reason One of the status codes defined in |
| 1050 | * {@link android.telecom.Connection.RttModifyStatus}, with the exception of |
| 1051 | * {@link android.telecom.Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}. |
| 1052 | */ |
| 1053 | public void onRttInitiationFailure(Call call, int reason) {} |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 1054 | |
| 1055 | /** |
| 1056 | * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount} |
| 1057 | * has completed successfully. |
| 1058 | * @param call The call which had initiated handover. |
| 1059 | */ |
| 1060 | public void onHandoverComplete(Call call) {} |
| 1061 | |
| 1062 | /** |
| 1063 | * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount} |
| 1064 | * has failed. |
| 1065 | * @param call The call which had initiated handover. |
| 1066 | * @param failureReason Error reason for failure |
| 1067 | */ |
| 1068 | public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {} |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * A class that holds the state that describes the state of the RTT channel to the remote |
| 1073 | * party, if it is active. |
| 1074 | */ |
| 1075 | public static final class RttCall { |
Hall Liu | 07094df | 2017-02-28 15:17:44 -0800 | [diff] [blame] | 1076 | /** @hide */ |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1077 | @Retention(RetentionPolicy.SOURCE) |
| 1078 | @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO}) |
| 1079 | public @interface RttAudioMode {} |
| 1080 | |
| 1081 | /** |
| 1082 | * For metrics use. Default value in the proto. |
| 1083 | * @hide |
| 1084 | */ |
| 1085 | public static final int RTT_MODE_INVALID = 0; |
| 1086 | |
| 1087 | /** |
| 1088 | * Indicates that there should be a bidirectional audio stream between the two parties |
| 1089 | * on the call. |
| 1090 | */ |
| 1091 | public static final int RTT_MODE_FULL = 1; |
| 1092 | |
| 1093 | /** |
| 1094 | * Indicates that the local user should be able to hear the audio stream from the remote |
| 1095 | * user, but not vice versa. Equivalent to muting the microphone. |
| 1096 | */ |
| 1097 | public static final int RTT_MODE_HCO = 2; |
| 1098 | |
| 1099 | /** |
| 1100 | * Indicates that the remote user should be able to hear the audio stream from the local |
| 1101 | * user, but not vice versa. Equivalent to setting the volume to zero. |
| 1102 | */ |
| 1103 | public static final int RTT_MODE_VCO = 3; |
| 1104 | |
| 1105 | private static final int READ_BUFFER_SIZE = 1000; |
| 1106 | |
| 1107 | private InputStreamReader mReceiveStream; |
| 1108 | private OutputStreamWriter mTransmitStream; |
| 1109 | private int mRttMode; |
| 1110 | private final InCallAdapter mInCallAdapter; |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1111 | private final String mTelecomCallId; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1112 | private char[] mReadBuffer = new char[READ_BUFFER_SIZE]; |
| 1113 | |
| 1114 | /** |
| 1115 | * @hide |
| 1116 | */ |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1117 | public RttCall(String telecomCallId, InputStreamReader receiveStream, |
| 1118 | OutputStreamWriter transmitStream, int mode, InCallAdapter inCallAdapter) { |
| 1119 | mTelecomCallId = telecomCallId; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1120 | mReceiveStream = receiveStream; |
| 1121 | mTransmitStream = transmitStream; |
| 1122 | mRttMode = mode; |
| 1123 | mInCallAdapter = inCallAdapter; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Returns the current RTT audio mode. |
| 1128 | * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or |
| 1129 | * {@link #RTT_MODE_HCO}. |
| 1130 | */ |
| 1131 | public int getRttAudioMode() { |
| 1132 | return mRttMode; |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * Sets the RTT audio mode. The requested mode change will be communicated through |
| 1137 | * {@link Callback#onRttModeChanged(Call, int)}. |
| 1138 | * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL}, |
| 1139 | * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}. |
| 1140 | */ |
| 1141 | public void setRttMode(@RttAudioMode int mode) { |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1142 | mInCallAdapter.setRttMode(mTelecomCallId, mode); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Writes the string {@param input} into the outgoing text stream for this RTT call. Since |
| 1147 | * RTT transmits text in real-time, this method should be called once for each character |
| 1148 | * the user enters into the device. |
| 1149 | * |
| 1150 | * This method is not thread-safe -- calling it from multiple threads simultaneously may |
| 1151 | * lead to interleaved text. |
| 1152 | * @param input The message to send to the remote user. |
| 1153 | */ |
| 1154 | public void write(String input) throws IOException { |
| 1155 | mTransmitStream.write(input); |
| 1156 | mTransmitStream.flush(); |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Reads a string from the remote user, blocking if there is no data available. Returns |
| 1161 | * {@code null} if the RTT conversation has been terminated and there is no further data |
| 1162 | * to read. |
| 1163 | * |
| 1164 | * This method is not thread-safe -- calling it from multiple threads simultaneously may |
| 1165 | * lead to interleaved text. |
| 1166 | * @return A string containing text sent by the remote user, or {@code null} if the |
| 1167 | * conversation has been terminated or if there was an error while reading. |
| 1168 | */ |
Hall Liu | b1c8a77 | 2017-07-17 17:04:41 -0700 | [diff] [blame] | 1169 | public String read() { |
| 1170 | try { |
| 1171 | int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE); |
| 1172 | if (numRead < 0) { |
| 1173 | return null; |
| 1174 | } |
| 1175 | return new String(mReadBuffer, 0, numRead); |
| 1176 | } catch (IOException e) { |
| 1177 | Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e); |
Jeff Sharkey | 9039636 | 2017-06-12 16:26:53 -0600 | [diff] [blame] | 1178 | return null; |
Hall Liu | ffa4a81 | 2017-03-02 16:11:00 -0800 | [diff] [blame] | 1179 | } |
Hall Liu | ffa4a81 | 2017-03-02 16:11:00 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to |
| 1184 | * be read. |
| 1185 | * @return A string containing text entered by the user, or {@code null} if the user has |
| 1186 | * not entered any new text yet. |
| 1187 | */ |
| 1188 | public String readImmediately() throws IOException { |
| 1189 | if (mReceiveStream.ready()) { |
Hall Liu | b1c8a77 | 2017-07-17 17:04:41 -0700 | [diff] [blame] | 1190 | int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE); |
| 1191 | if (numRead < 0) { |
| 1192 | return null; |
| 1193 | } |
| 1194 | return new String(mReadBuffer, 0, numRead); |
Hall Liu | ffa4a81 | 2017-03-02 16:11:00 -0800 | [diff] [blame] | 1195 | } else { |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1196 | return null; |
| 1197 | } |
| 1198 | } |
Hall Liu | e904124 | 2018-02-09 16:40:03 -0800 | [diff] [blame^] | 1199 | |
| 1200 | /** |
| 1201 | * Closes the underlying file descriptors |
| 1202 | * @hide |
| 1203 | */ |
| 1204 | public void close() { |
| 1205 | try { |
| 1206 | mReceiveStream.close(); |
| 1207 | } catch (IOException e) { |
| 1208 | // ignore |
| 1209 | } |
| 1210 | try { |
| 1211 | mTransmitStream.close(); |
| 1212 | } catch (IOException e) { |
| 1213 | // ignore |
| 1214 | } |
| 1215 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1218 | /** |
| 1219 | * @deprecated Use {@code Call.Callback} instead. |
| 1220 | * @hide |
| 1221 | */ |
| 1222 | @Deprecated |
| 1223 | @SystemApi |
| 1224 | public static abstract class Listener extends Callback { } |
| 1225 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1226 | private final Phone mPhone; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1227 | private final String mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1228 | private final InCallAdapter mInCallAdapter; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1229 | private final List<String> mChildrenIds = new ArrayList<>(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1230 | private final List<Call> mChildren = new ArrayList<>(); |
| 1231 | private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren); |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1232 | private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>(); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1233 | private final List<Call> mConferenceableCalls = new ArrayList<>(); |
| 1234 | private final List<Call> mUnmodifiableConferenceableCalls = |
| 1235 | Collections.unmodifiableList(mConferenceableCalls); |
| 1236 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1237 | private boolean mChildrenCached; |
| 1238 | private String mParentId = null; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1239 | private int mState; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1240 | private List<String> mCannedTextResponses = null; |
Tyler Gunn | b88b311 | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 1241 | private String mCallingPackage; |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1242 | private int mTargetSdkVersion; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1243 | private String mRemainingPostDialSequence; |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1244 | private VideoCallImpl mVideoCallImpl; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1245 | private RttCall mRttCall; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1246 | private Details mDetails; |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1247 | private Bundle mExtras; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1248 | |
| 1249 | /** |
| 1250 | * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any. |
| 1251 | * |
| 1252 | * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence |
| 1253 | * remaining or this {@code Call} is not in a post-dial state. |
| 1254 | */ |
| 1255 | public String getRemainingPostDialSequence() { |
| 1256 | return mRemainingPostDialSequence; |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * Instructs this {@link #STATE_RINGING} {@code Call} to answer. |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 1261 | * @param videoState The video state in which to answer the call. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1262 | */ |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 1263 | public void answer(int videoState) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1264 | mInCallAdapter.answerCall(mTelecomCallId, videoState); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
Pooja Jain | d34698d | 2017-12-28 14:15:31 +0530 | [diff] [blame] | 1268 | * Instructs this {@link #STATE_RINGING} {@code Call} to deflect. |
| 1269 | * |
| 1270 | * @param address The address to which the call will be deflected. |
| 1271 | */ |
| 1272 | public void deflect(Uri address) { |
| 1273 | mInCallAdapter.deflectCall(mTelecomCallId, address); |
| 1274 | } |
| 1275 | |
| 1276 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1277 | * Instructs this {@link #STATE_RINGING} {@code Call} to reject. |
| 1278 | * |
| 1279 | * @param rejectWithMessage Whether to reject with a text message. |
| 1280 | * @param textMessage An optional text message with which to respond. |
| 1281 | */ |
| 1282 | public void reject(boolean rejectWithMessage, String textMessage) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1283 | mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * Instructs this {@code Call} to disconnect. |
| 1288 | */ |
| 1289 | public void disconnect() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1290 | mInCallAdapter.disconnectCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * Instructs this {@code Call} to go on hold. |
| 1295 | */ |
| 1296 | public void hold() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1297 | mInCallAdapter.holdCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /** |
| 1301 | * Instructs this {@link #STATE_HOLDING} call to release from hold. |
| 1302 | */ |
| 1303 | public void unhold() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1304 | mInCallAdapter.unholdCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone. |
| 1309 | * |
| 1310 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 1311 | * |
| 1312 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 1313 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 1314 | */ |
| 1315 | public void playDtmfTone(char digit) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1316 | mInCallAdapter.playDtmfTone(mTelecomCallId, digit); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone |
| 1321 | * currently playing. |
| 1322 | * |
| 1323 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 1324 | * currently playing, this method will do nothing. |
| 1325 | */ |
| 1326 | public void stopDtmfTone() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1327 | mInCallAdapter.stopDtmfTone(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | /** |
| 1331 | * Instructs this {@code Call} to continue playing a post-dial DTMF string. |
| 1332 | * |
| 1333 | * A post-dial DTMF string is a string of digits entered after a phone number, when dialed, |
| 1334 | * that are immediately sent as DTMF tones to the recipient as soon as the connection is made. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1335 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1336 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1337 | * {@code Call} will temporarily pause playing the tones for a pre-defined period of time. |
| 1338 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1339 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1340 | * {@code Call} will pause playing the tones and notify callbacks via |
| 1341 | * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1342 | * should display to the user an indication of this state and an affordance to continue |
| 1343 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 1344 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 1345 | * |
| 1346 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 1347 | */ |
| 1348 | public void postDialContinue(boolean proceed) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1349 | mInCallAdapter.postDialContinue(mTelecomCallId, proceed); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 1353 | * Notifies this {@code Call} that an account has been selected and to proceed with placing |
Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 1354 | * an outgoing call. Optionally sets this account as the default account. |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 1355 | */ |
Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 1356 | public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) { |
| 1357 | mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault); |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 1358 | |
| 1359 | } |
| 1360 | |
| 1361 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1362 | * Instructs this {@code Call} to enter a conference. |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1363 | * |
| 1364 | * @param callToConferenceWith The other call with which to conference. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1365 | */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1366 | public void conference(Call callToConferenceWith) { |
| 1367 | if (callToConferenceWith != null) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1368 | mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1369 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Instructs this {@code Call} to split from any conference call with which it may be |
| 1374 | * connected. |
| 1375 | */ |
| 1376 | public void splitFromConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1377 | mInCallAdapter.splitFromConference(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1381 | * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 1382 | */ |
| 1383 | public void mergeConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1384 | mInCallAdapter.mergeConference(mTelecomCallId); |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1388 | * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 1389 | */ |
| 1390 | public void swapConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1391 | mInCallAdapter.swapConference(mTelecomCallId); |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1395 | * Initiates a request to the {@link ConnectionService} to pull an external call to the local |
| 1396 | * device. |
| 1397 | * <p> |
| 1398 | * Calls to this method are ignored if the call does not have the |
| 1399 | * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set. |
| 1400 | * <p> |
| 1401 | * An {@link InCallService} will only see calls which support this method if it has the |
| 1402 | * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} |
| 1403 | * in its manifest. |
| 1404 | */ |
| 1405 | public void pullExternalCall() { |
| 1406 | // If this isn't an external call, ignore the request. |
| 1407 | if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) { |
| 1408 | return; |
| 1409 | } |
| 1410 | |
| 1411 | mInCallAdapter.pullExternalCall(mTelecomCallId); |
| 1412 | } |
| 1413 | |
| 1414 | /** |
| 1415 | * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in |
| 1416 | * the {@link ConnectionService}. |
| 1417 | * <p> |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 1418 | * Call events are used to communicate point in time information from an {@link InCallService} |
| 1419 | * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define |
| 1420 | * events which enable the {@link InCallService}, for example, toggle a unique feature of the |
| 1421 | * {@link ConnectionService}. |
| 1422 | * <p> |
| 1423 | * A {@link ConnectionService} can communicate to the {@link InCallService} using |
| 1424 | * {@link Connection#sendConnectionEvent(String, Bundle)}. |
| 1425 | * <p> |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1426 | * Events are exposed to {@link ConnectionService} implementations via |
| 1427 | * {@link android.telecom.Connection#onCallEvent(String, Bundle)}. |
| 1428 | * <p> |
| 1429 | * No assumptions should be made as to how a {@link ConnectionService} will handle these events. |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 1430 | * The {@link InCallService} must assume that the {@link ConnectionService} could chose to |
| 1431 | * ignore some events altogether. |
| 1432 | * <p> |
| 1433 | * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid |
| 1434 | * conflicts between {@link InCallService} implementations. Further, {@link InCallService} |
| 1435 | * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall |
| 1436 | * they define their own event types in this namespace. When defining a custom event type, |
| 1437 | * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this |
| 1438 | * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}). |
| 1439 | * <p> |
| 1440 | * When defining events and the associated extras, it is important to keep their behavior |
| 1441 | * consistent when the associated {@link InCallService} is updated. Support for deprecated |
| 1442 | * events/extras should me maintained to ensure backwards compatibility with older |
| 1443 | * {@link ConnectionService} implementations which were built to support the older behavior. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1444 | * |
| 1445 | * @param event The connection event. |
| 1446 | * @param extras Bundle containing extra information associated with the event. |
| 1447 | */ |
| 1448 | public void sendCallEvent(String event, Bundle extras) { |
Sanket Padawe | f6a9e5b | 2018-01-05 14:26:16 -0800 | [diff] [blame] | 1449 | mInCallAdapter.sendCallEvent(mTelecomCallId, event, mTargetSdkVersion, extras); |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1453 | * Sends an RTT upgrade request to the remote end of the connection. Success is not |
| 1454 | * guaranteed, and notification of success will be via the |
| 1455 | * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback. |
| 1456 | */ |
| 1457 | public void sendRttRequest() { |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1458 | mInCallAdapter.sendRttRequest(mTelecomCallId); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )} |
| 1463 | * callback. |
| 1464 | * The ID used here should be the same as the ID that was received via the callback. |
| 1465 | * @param id The request ID received via {@link Callback#onRttRequest(Call, int)} |
| 1466 | * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise. |
| 1467 | */ |
| 1468 | public void respondToRttRequest(int id, boolean accept) { |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1469 | mInCallAdapter.respondToRttRequest(mTelecomCallId, id, accept); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /** |
Sanket Padawe | a8eddd4 | 2017-11-03 11:07:35 -0700 | [diff] [blame] | 1473 | * Initiates a handover of this {@link Call} to the {@link ConnectionService} identified |
| 1474 | * by {@code toHandle}. The videoState specified indicates the desired video state after the |
| 1475 | * handover. |
| 1476 | * <p> |
| 1477 | * A handover request is initiated by the user from one app to indicate a desire |
| 1478 | * to handover a call to another. |
| 1479 | * |
| 1480 | * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover |
| 1481 | * this call to. |
| 1482 | * @param videoState Indicates the video state desired after the handover. |
| 1483 | * @param extras Bundle containing extra information to be passed to the |
| 1484 | * {@link ConnectionService} |
| 1485 | */ |
| 1486 | public void handoverTo(PhoneAccountHandle toHandle, int videoState, Bundle extras) { |
| 1487 | mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras); |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1491 | * Terminate the RTT session on this call. The resulting state change will be notified via |
| 1492 | * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback. |
| 1493 | */ |
| 1494 | public void stopRtt() { |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1495 | mInCallAdapter.stopRtt(mTelecomCallId); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1499 | * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are |
| 1500 | * added. |
| 1501 | * <p> |
| 1502 | * No assumptions should be made as to how an In-Call UI or service will handle these |
| 1503 | * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts. |
| 1504 | * |
| 1505 | * @param extras The extras to add. |
| 1506 | */ |
| 1507 | public final void putExtras(Bundle extras) { |
| 1508 | if (extras == null) { |
| 1509 | return; |
| 1510 | } |
| 1511 | |
| 1512 | if (mExtras == null) { |
| 1513 | mExtras = new Bundle(); |
| 1514 | } |
| 1515 | mExtras.putAll(extras); |
| 1516 | mInCallAdapter.putExtras(mTelecomCallId, extras); |
| 1517 | } |
| 1518 | |
| 1519 | /** |
| 1520 | * Adds a boolean extra to this {@link Call}. |
| 1521 | * |
| 1522 | * @param key The extra key. |
| 1523 | * @param value The value. |
| 1524 | * @hide |
| 1525 | */ |
| 1526 | public final void putExtra(String key, boolean value) { |
| 1527 | if (mExtras == null) { |
| 1528 | mExtras = new Bundle(); |
| 1529 | } |
| 1530 | mExtras.putBoolean(key, value); |
| 1531 | mInCallAdapter.putExtra(mTelecomCallId, key, value); |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 1535 | * Adds an integer extra to this {@link Call}. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1536 | * |
| 1537 | * @param key The extra key. |
| 1538 | * @param value The value. |
| 1539 | * @hide |
| 1540 | */ |
| 1541 | public final void putExtra(String key, int value) { |
| 1542 | if (mExtras == null) { |
| 1543 | mExtras = new Bundle(); |
| 1544 | } |
| 1545 | mExtras.putInt(key, value); |
| 1546 | mInCallAdapter.putExtra(mTelecomCallId, key, value); |
| 1547 | } |
| 1548 | |
| 1549 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 1550 | * Adds a string extra to this {@link Call}. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1551 | * |
| 1552 | * @param key The extra key. |
| 1553 | * @param value The value. |
| 1554 | * @hide |
| 1555 | */ |
| 1556 | public final void putExtra(String key, String value) { |
| 1557 | if (mExtras == null) { |
| 1558 | mExtras = new Bundle(); |
| 1559 | } |
| 1560 | mExtras.putString(key, value); |
| 1561 | mInCallAdapter.putExtra(mTelecomCallId, key, value); |
| 1562 | } |
| 1563 | |
| 1564 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 1565 | * Removes extras from this {@link Call}. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1566 | * |
| 1567 | * @param keys The keys of the extras to remove. |
| 1568 | */ |
| 1569 | public final void removeExtras(List<String> keys) { |
| 1570 | if (mExtras != null) { |
| 1571 | for (String key : keys) { |
| 1572 | mExtras.remove(key); |
| 1573 | } |
| 1574 | if (mExtras.size() == 0) { |
| 1575 | mExtras = null; |
| 1576 | } |
| 1577 | } |
| 1578 | mInCallAdapter.removeExtras(mTelecomCallId, keys); |
| 1579 | } |
| 1580 | |
| 1581 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 1582 | * Removes extras from this {@link Call}. |
| 1583 | * |
| 1584 | * @param keys The keys of the extras to remove. |
| 1585 | */ |
| 1586 | public final void removeExtras(String ... keys) { |
| 1587 | removeExtras(Arrays.asList(keys)); |
| 1588 | } |
| 1589 | |
| 1590 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1591 | * Obtains the parent of this {@code Call} in a conference, if any. |
| 1592 | * |
| 1593 | * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a |
| 1594 | * child of any conference {@code Call}s. |
| 1595 | */ |
| 1596 | public Call getParent() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1597 | if (mParentId != null) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1598 | return mPhone.internalGetCallByTelecomId(mParentId); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1599 | } |
| 1600 | return null; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Obtains the children of this conference {@code Call}, if any. |
| 1605 | * |
| 1606 | * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty |
| 1607 | * {@code List} otherwise. |
| 1608 | */ |
| 1609 | public List<Call> getChildren() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1610 | if (!mChildrenCached) { |
| 1611 | mChildrenCached = true; |
| 1612 | mChildren.clear(); |
| 1613 | |
| 1614 | for(String id : mChildrenIds) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1615 | Call call = mPhone.internalGetCallByTelecomId(id); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1616 | if (call == null) { |
| 1617 | // At least one child was still not found, so do not save true for "cached" |
| 1618 | mChildrenCached = false; |
| 1619 | } else { |
| 1620 | mChildren.add(call); |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1625 | return mUnmodifiableChildren; |
| 1626 | } |
| 1627 | |
| 1628 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1629 | * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference. |
| 1630 | * |
| 1631 | * @return The list of conferenceable {@code Call}s. |
| 1632 | */ |
| 1633 | public List<Call> getConferenceableCalls() { |
| 1634 | return mUnmodifiableConferenceableCalls; |
| 1635 | } |
| 1636 | |
| 1637 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1638 | * Obtains the state of this {@code Call}. |
| 1639 | * |
| 1640 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 1641 | */ |
| 1642 | public int getState() { |
| 1643 | return mState; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
| 1647 | * Obtains a list of canned, pre-configured message responses to present to the user as |
| 1648 | * ways of rejecting this {@code Call} using via a text message. |
| 1649 | * |
| 1650 | * @see #reject(boolean, String) |
| 1651 | * |
| 1652 | * @return A list of canned text message responses. |
| 1653 | */ |
| 1654 | public List<String> getCannedTextResponses() { |
| 1655 | return mCannedTextResponses; |
| 1656 | } |
| 1657 | |
| 1658 | /** |
| 1659 | * Obtains an object that can be used to display video from this {@code Call}. |
| 1660 | * |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1661 | * @return An {@code Call.VideoCall}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1662 | */ |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1663 | public InCallService.VideoCall getVideoCall() { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1664 | return mVideoCallImpl; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * Obtains an object containing call details. |
| 1669 | * |
| 1670 | * @return A {@link Details} object. Depending on the state of the {@code Call}, the |
| 1671 | * result may be {@code null}. |
| 1672 | */ |
| 1673 | public Details getDetails() { |
| 1674 | return mDetails; |
| 1675 | } |
| 1676 | |
| 1677 | /** |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1678 | * Returns this call's RttCall object. The {@link RttCall} instance is used to send and |
| 1679 | * receive RTT text data, as well as to change the RTT mode. |
| 1680 | * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection. |
| 1681 | */ |
| 1682 | public @Nullable RttCall getRttCall() { |
| 1683 | return mRttCall; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Returns whether this call has an active RTT connection. |
| 1688 | * @return true if there is a connection, false otherwise. |
| 1689 | */ |
| 1690 | public boolean isRttActive() { |
Hall Liu | e904124 | 2018-02-09 16:40:03 -0800 | [diff] [blame^] | 1691 | return mRttCall != null && mDetails.hasProperty(Details.PROPERTY_RTT); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | /** |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1695 | * Registers a callback to this {@code Call}. |
| 1696 | * |
| 1697 | * @param callback A {@code Callback}. |
| 1698 | */ |
| 1699 | public void registerCallback(Callback callback) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1700 | registerCallback(callback, new Handler()); |
| 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * Registers a callback to this {@code Call}. |
| 1705 | * |
| 1706 | * @param callback A {@code Callback}. |
| 1707 | * @param handler A handler which command and status changes will be delivered to. |
| 1708 | */ |
| 1709 | public void registerCallback(Callback callback, Handler handler) { |
| 1710 | unregisterCallback(callback); |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 1711 | // Don't allow new callback registration if the call is already being destroyed. |
| 1712 | if (callback != null && handler != null && mState != STATE_DISCONNECTED) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1713 | mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler)); |
| 1714 | } |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /** |
| 1718 | * Unregisters a callback from this {@code Call}. |
| 1719 | * |
| 1720 | * @param callback A {@code Callback}. |
| 1721 | */ |
| 1722 | public void unregisterCallback(Callback callback) { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 1723 | // Don't allow callback deregistration if the call is already being destroyed. |
| 1724 | if (callback != null && mState != STATE_DISCONNECTED) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1725 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1726 | if (record.getCallback() == callback) { |
| 1727 | mCallbackRecords.remove(record); |
| 1728 | break; |
| 1729 | } |
| 1730 | } |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
Santos Cordon | 3c20d63 | 2016-02-25 16:12:35 -0800 | [diff] [blame] | 1734 | @Override |
| 1735 | public String toString() { |
| 1736 | return new StringBuilder(). |
| 1737 | append("Call [id: "). |
| 1738 | append(mTelecomCallId). |
| 1739 | append(", state: "). |
| 1740 | append(stateToString(mState)). |
| 1741 | append(", details: "). |
| 1742 | append(mDetails). |
| 1743 | append("]").toString(); |
| 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * @param state An integer value of a {@code STATE_*} constant. |
| 1748 | * @return A string representation of the value. |
| 1749 | */ |
| 1750 | private static String stateToString(int state) { |
| 1751 | switch (state) { |
| 1752 | case STATE_NEW: |
| 1753 | return "NEW"; |
| 1754 | case STATE_RINGING: |
| 1755 | return "RINGING"; |
| 1756 | case STATE_DIALING: |
| 1757 | return "DIALING"; |
| 1758 | case STATE_ACTIVE: |
| 1759 | return "ACTIVE"; |
| 1760 | case STATE_HOLDING: |
| 1761 | return "HOLDING"; |
| 1762 | case STATE_DISCONNECTED: |
| 1763 | return "DISCONNECTED"; |
| 1764 | case STATE_CONNECTING: |
| 1765 | return "CONNECTING"; |
| 1766 | case STATE_DISCONNECTING: |
| 1767 | return "DISCONNECTING"; |
| 1768 | case STATE_SELECT_PHONE_ACCOUNT: |
| 1769 | return "SELECT_PHONE_ACCOUNT"; |
| 1770 | default: |
| 1771 | Log.w(Call.class, "Unknown state %d", state); |
| 1772 | return "UNKNOWN"; |
| 1773 | } |
| 1774 | } |
| 1775 | |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1776 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1777 | * Adds a listener to this {@code Call}. |
| 1778 | * |
| 1779 | * @param listener A {@code Listener}. |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1780 | * @deprecated Use {@link #registerCallback} instead. |
| 1781 | * @hide |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1782 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1783 | @Deprecated |
| 1784 | @SystemApi |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1785 | public void addListener(Listener listener) { |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1786 | registerCallback(listener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * Removes a listener from this {@code Call}. |
| 1791 | * |
| 1792 | * @param listener A {@code Listener}. |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1793 | * @deprecated Use {@link #unregisterCallback} instead. |
| 1794 | * @hide |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1795 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1796 | @Deprecated |
| 1797 | @SystemApi |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1798 | public void removeListener(Listener listener) { |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1799 | unregisterCallback(listener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /** {@hide} */ |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1803 | Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage, |
| 1804 | int targetSdkVersion) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1805 | mPhone = phone; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1806 | mTelecomCallId = telecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1807 | mInCallAdapter = inCallAdapter; |
| 1808 | mState = STATE_NEW; |
Tyler Gunn | b88b311 | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 1809 | mCallingPackage = callingPackage; |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1810 | mTargetSdkVersion = targetSdkVersion; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** {@hide} */ |
Tyler Gunn | b88b311 | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 1814 | Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1815 | String callingPackage, int targetSdkVersion) { |
Shriram Ganesh | ddf570e | 2015-05-31 09:18:48 -0700 | [diff] [blame] | 1816 | mPhone = phone; |
| 1817 | mTelecomCallId = telecomCallId; |
| 1818 | mInCallAdapter = inCallAdapter; |
| 1819 | mState = state; |
Tyler Gunn | b88b311 | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 1820 | mCallingPackage = callingPackage; |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1821 | mTargetSdkVersion = targetSdkVersion; |
Shriram Ganesh | ddf570e | 2015-05-31 09:18:48 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | /** {@hide} */ |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1825 | final String internalGetCallId() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1826 | return mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | /** {@hide} */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1830 | final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) { |
Tyler Gunn | b88b311 | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 1831 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1832 | // First, we update the internal state as far as possible before firing any updates. |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 1833 | Details details = Details.createFromParcelableCall(parcelableCall); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1834 | boolean detailsChanged = !Objects.equals(mDetails, details); |
| 1835 | if (detailsChanged) { |
| 1836 | mDetails = details; |
| 1837 | } |
| 1838 | |
| 1839 | boolean cannedTextResponsesChanged = false; |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 1840 | if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null |
| 1841 | && !parcelableCall.getCannedSmsResponses().isEmpty()) { |
| 1842 | mCannedTextResponses = |
| 1843 | Collections.unmodifiableList(parcelableCall.getCannedSmsResponses()); |
Yorke Lee | e886f63 | 2015-08-04 13:43:31 -0700 | [diff] [blame] | 1844 | cannedTextResponsesChanged = true; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1847 | VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage, |
| 1848 | mTargetSdkVersion); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 1849 | boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() && |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1850 | !Objects.equals(mVideoCallImpl, newVideoCallImpl); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1851 | if (videoCallChanged) { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1852 | mVideoCallImpl = newVideoCallImpl; |
| 1853 | } |
| 1854 | if (mVideoCallImpl != null) { |
| 1855 | mVideoCallImpl.setVideoState(getDetails().getVideoState()); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 1858 | int state = parcelableCall.getState(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1859 | boolean stateChanged = mState != state; |
| 1860 | if (stateChanged) { |
| 1861 | mState = state; |
| 1862 | } |
| 1863 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1864 | String parentId = parcelableCall.getParentCallId(); |
| 1865 | boolean parentChanged = !Objects.equals(mParentId, parentId); |
| 1866 | if (parentChanged) { |
| 1867 | mParentId = parentId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1870 | List<String> childCallIds = parcelableCall.getChildCallIds(); |
| 1871 | boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds); |
| 1872 | if (childrenChanged) { |
| 1873 | mChildrenIds.clear(); |
| 1874 | mChildrenIds.addAll(parcelableCall.getChildCallIds()); |
| 1875 | mChildrenCached = false; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1878 | List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds(); |
| 1879 | List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size()); |
| 1880 | for (String otherId : conferenceableCallIds) { |
| 1881 | if (callIdMap.containsKey(otherId)) { |
| 1882 | conferenceableCalls.add(callIdMap.get(otherId)); |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) { |
| 1887 | mConferenceableCalls.clear(); |
| 1888 | mConferenceableCalls.addAll(conferenceableCalls); |
| 1889 | fireConferenceableCallsChanged(); |
| 1890 | } |
| 1891 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1892 | boolean isRttChanged = false; |
| 1893 | boolean rttModeChanged = false; |
Hall Liu | e904124 | 2018-02-09 16:40:03 -0800 | [diff] [blame^] | 1894 | if (parcelableCall.getIsRttCallChanged() |
| 1895 | && mDetails.hasProperty(Details.PROPERTY_RTT)) { |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1896 | ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall(); |
| 1897 | InputStreamReader receiveStream = new InputStreamReader( |
| 1898 | new ParcelFileDescriptor.AutoCloseInputStream( |
| 1899 | parcelableRttCall.getReceiveStream()), |
| 1900 | StandardCharsets.UTF_8); |
| 1901 | OutputStreamWriter transmitStream = new OutputStreamWriter( |
| 1902 | new ParcelFileDescriptor.AutoCloseOutputStream( |
| 1903 | parcelableRttCall.getTransmitStream()), |
| 1904 | StandardCharsets.UTF_8); |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1905 | RttCall newRttCall = new Call.RttCall(mTelecomCallId, |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1906 | receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter); |
| 1907 | if (mRttCall == null) { |
| 1908 | isRttChanged = true; |
| 1909 | } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) { |
| 1910 | rttModeChanged = true; |
| 1911 | } |
| 1912 | mRttCall = newRttCall; |
| 1913 | } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null |
| 1914 | && parcelableCall.getIsRttCallChanged()) { |
| 1915 | isRttChanged = true; |
| 1916 | mRttCall = null; |
| 1917 | } |
| 1918 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1919 | // Now we fire updates, ensuring that any client who listens to any of these notifications |
| 1920 | // gets the most up-to-date state. |
| 1921 | |
| 1922 | if (stateChanged) { |
| 1923 | fireStateChanged(mState); |
| 1924 | } |
| 1925 | if (detailsChanged) { |
| 1926 | fireDetailsChanged(mDetails); |
| 1927 | } |
| 1928 | if (cannedTextResponsesChanged) { |
| 1929 | fireCannedTextResponsesLoaded(mCannedTextResponses); |
| 1930 | } |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1931 | if (videoCallChanged) { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1932 | fireVideoCallChanged(mVideoCallImpl); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1933 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1934 | if (parentChanged) { |
| 1935 | fireParentChanged(getParent()); |
| 1936 | } |
| 1937 | if (childrenChanged) { |
| 1938 | fireChildrenChanged(getChildren()); |
| 1939 | } |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1940 | if (isRttChanged) { |
| 1941 | fireOnIsRttChanged(mRttCall != null, mRttCall); |
| 1942 | } |
| 1943 | if (rttModeChanged) { |
| 1944 | fireOnRttModeChanged(mRttCall.getRttAudioMode()); |
| 1945 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1946 | |
| 1947 | // If we have transitioned to DISCONNECTED, that means we need to notify clients and |
| 1948 | // remove ourselves from the Phone. Note that we do this after completing all state updates |
| 1949 | // so a client can cleanly transition all their UI to the state appropriate for a |
| 1950 | // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list. |
| 1951 | if (mState == STATE_DISCONNECTED) { |
| 1952 | fireCallDestroyed(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | /** {@hide} */ |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1957 | final void internalSetPostDialWait(String remaining) { |
| 1958 | mRemainingPostDialSequence = remaining; |
| 1959 | firePostDialWait(mRemainingPostDialSequence); |
| 1960 | } |
| 1961 | |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 1962 | /** {@hide} */ |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 1963 | final void internalSetDisconnected() { |
| 1964 | if (mState != Call.STATE_DISCONNECTED) { |
| 1965 | mState = Call.STATE_DISCONNECTED; |
| 1966 | fireStateChanged(mState); |
| 1967 | fireCallDestroyed(); |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1971 | /** {@hide} */ |
| 1972 | final void internalOnConnectionEvent(String event, Bundle extras) { |
| 1973 | fireOnConnectionEvent(event, extras); |
| 1974 | } |
| 1975 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 1976 | /** {@hide} */ |
| 1977 | final void internalOnRttUpgradeRequest(final int requestId) { |
| 1978 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1979 | final Call call = this; |
| 1980 | final Callback callback = record.getCallback(); |
| 1981 | record.getHandler().post(() -> callback.onRttRequest(call, requestId)); |
| 1982 | } |
| 1983 | } |
| 1984 | |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1985 | /** @hide */ |
| 1986 | final void internalOnRttInitiationFailure(int reason) { |
| 1987 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1988 | final Call call = this; |
| 1989 | final Callback callback = record.getCallback(); |
| 1990 | record.getHandler().post(() -> callback.onRttInitiationFailure(call, reason)); |
| 1991 | } |
| 1992 | } |
| 1993 | |
Sanket Padawe | 85291f6 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 1994 | /** {@hide} */ |
| 1995 | final void internalOnHandoverFailed(int error) { |
| 1996 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1997 | final Call call = this; |
| 1998 | final Callback callback = record.getCallback(); |
| 1999 | record.getHandler().post(() -> callback.onHandoverFailed(call, error)); |
| 2000 | } |
| 2001 | } |
| 2002 | |
Tyler Gunn | 858bfaf | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 2003 | /** {@hide} */ |
| 2004 | final void internalOnHandoverComplete() { |
| 2005 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2006 | final Call call = this; |
| 2007 | final Callback callback = record.getCallback(); |
| 2008 | record.getHandler().post(() -> callback.onHandoverComplete(call)); |
| 2009 | } |
| 2010 | } |
| 2011 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2012 | private void fireStateChanged(final int newState) { |
| 2013 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2014 | final Call call = this; |
| 2015 | final Callback callback = record.getCallback(); |
| 2016 | record.getHandler().post(new Runnable() { |
| 2017 | @Override |
| 2018 | public void run() { |
| 2019 | callback.onStateChanged(call, newState); |
| 2020 | } |
| 2021 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2025 | private void fireParentChanged(final Call newParent) { |
| 2026 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2027 | final Call call = this; |
| 2028 | final Callback callback = record.getCallback(); |
| 2029 | record.getHandler().post(new Runnable() { |
| 2030 | @Override |
| 2031 | public void run() { |
| 2032 | callback.onParentChanged(call, newParent); |
| 2033 | } |
| 2034 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2038 | private void fireChildrenChanged(final List<Call> children) { |
| 2039 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2040 | final Call call = this; |
| 2041 | final Callback callback = record.getCallback(); |
| 2042 | record.getHandler().post(new Runnable() { |
| 2043 | @Override |
| 2044 | public void run() { |
| 2045 | callback.onChildrenChanged(call, children); |
| 2046 | } |
| 2047 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2051 | private void fireDetailsChanged(final Details details) { |
| 2052 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2053 | final Call call = this; |
| 2054 | final Callback callback = record.getCallback(); |
| 2055 | record.getHandler().post(new Runnable() { |
| 2056 | @Override |
| 2057 | public void run() { |
| 2058 | callback.onDetailsChanged(call, details); |
| 2059 | } |
| 2060 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2064 | private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) { |
| 2065 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2066 | final Call call = this; |
| 2067 | final Callback callback = record.getCallback(); |
| 2068 | record.getHandler().post(new Runnable() { |
| 2069 | @Override |
| 2070 | public void run() { |
| 2071 | callback.onCannedTextResponsesLoaded(call, cannedTextResponses); |
| 2072 | } |
| 2073 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2074 | } |
| 2075 | } |
| 2076 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2077 | private void fireVideoCallChanged(final InCallService.VideoCall videoCall) { |
| 2078 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2079 | final Call call = this; |
| 2080 | final Callback callback = record.getCallback(); |
| 2081 | record.getHandler().post(new Runnable() { |
| 2082 | @Override |
| 2083 | public void run() { |
| 2084 | callback.onVideoCallChanged(call, videoCall); |
| 2085 | } |
| 2086 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2090 | private void firePostDialWait(final String remainingPostDialSequence) { |
| 2091 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2092 | final Call call = this; |
| 2093 | final Callback callback = record.getCallback(); |
| 2094 | record.getHandler().post(new Runnable() { |
| 2095 | @Override |
| 2096 | public void run() { |
| 2097 | callback.onPostDialWait(call, remainingPostDialSequence); |
| 2098 | } |
| 2099 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | private void fireCallDestroyed() { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 2104 | /** |
| 2105 | * To preserve the ordering of the Call's onCallDestroyed callback and Phone's |
| 2106 | * onCallRemoved callback, we remove this call from the Phone's record |
| 2107 | * only once all of the registered onCallDestroyed callbacks are executed. |
| 2108 | * All the callbacks get removed from our records as a part of this operation |
| 2109 | * since onCallDestroyed is the final callback. |
| 2110 | */ |
| 2111 | final Call call = this; |
| 2112 | if (mCallbackRecords.isEmpty()) { |
| 2113 | // No callbacks registered, remove the call from Phone's record. |
| 2114 | mPhone.internalRemoveCall(call); |
| 2115 | } |
| 2116 | for (final CallbackRecord<Callback> record : mCallbackRecords) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2117 | final Callback callback = record.getCallback(); |
| 2118 | record.getHandler().post(new Runnable() { |
| 2119 | @Override |
| 2120 | public void run() { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 2121 | boolean isFinalRemoval = false; |
| 2122 | RuntimeException toThrow = null; |
| 2123 | try { |
| 2124 | callback.onCallDestroyed(call); |
| 2125 | } catch (RuntimeException e) { |
| 2126 | toThrow = e; |
| 2127 | } |
| 2128 | synchronized(Call.this) { |
| 2129 | mCallbackRecords.remove(record); |
| 2130 | if (mCallbackRecords.isEmpty()) { |
| 2131 | isFinalRemoval = true; |
| 2132 | } |
| 2133 | } |
| 2134 | if (isFinalRemoval) { |
| 2135 | mPhone.internalRemoveCall(call); |
| 2136 | } |
| 2137 | if (toThrow != null) { |
| 2138 | throw toThrow; |
| 2139 | } |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2140 | } |
| 2141 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 2145 | private void fireConferenceableCallsChanged() { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 2146 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2147 | final Call call = this; |
| 2148 | final Callback callback = record.getCallback(); |
| 2149 | record.getHandler().post(new Runnable() { |
| 2150 | @Override |
| 2151 | public void run() { |
| 2152 | callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls); |
| 2153 | } |
| 2154 | }); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 2155 | } |
| 2156 | } |
Tyler Gunn | 1e9bfc6 | 2015-08-19 11:18:58 -0700 | [diff] [blame] | 2157 | |
| 2158 | /** |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 2159 | * Notifies listeners of an incoming connection event. |
| 2160 | * <p> |
| 2161 | * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}. |
| 2162 | * |
| 2163 | * @param event |
| 2164 | * @param extras |
| 2165 | */ |
| 2166 | private void fireOnConnectionEvent(final String event, final Bundle extras) { |
| 2167 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2168 | final Call call = this; |
| 2169 | final Callback callback = record.getCallback(); |
| 2170 | record.getHandler().post(new Runnable() { |
| 2171 | @Override |
| 2172 | public void run() { |
| 2173 | callback.onConnectionEvent(call, event, extras); |
| 2174 | } |
| 2175 | }); |
| 2176 | } |
| 2177 | } |
| 2178 | |
| 2179 | /** |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 2180 | * Notifies listeners of an RTT on/off change |
| 2181 | * |
| 2182 | * @param enabled True if RTT is now enabled, false otherwise |
| 2183 | */ |
| 2184 | private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) { |
| 2185 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2186 | final Call call = this; |
| 2187 | final Callback callback = record.getCallback(); |
| 2188 | record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall)); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | /** |
| 2193 | * Notifies listeners of a RTT mode change |
| 2194 | * |
| 2195 | * @param mode The new RTT mode |
| 2196 | */ |
| 2197 | private void fireOnRttModeChanged(final int mode) { |
| 2198 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 2199 | final Call call = this; |
| 2200 | final Callback callback = record.getCallback(); |
| 2201 | record.getHandler().post(() -> callback.onRttModeChanged(call, mode)); |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | /** |
Tyler Gunn | 1e9bfc6 | 2015-08-19 11:18:58 -0700 | [diff] [blame] | 2206 | * Determines if two bundles are equal. |
| 2207 | * |
| 2208 | * @param bundle The original bundle. |
| 2209 | * @param newBundle The bundle to compare with. |
| 2210 | * @retrun {@code true} if the bundles are equal, {@code false} otherwise. |
| 2211 | */ |
| 2212 | private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) { |
| 2213 | if (bundle == null || newBundle == null) { |
| 2214 | return bundle == newBundle; |
| 2215 | } |
| 2216 | |
| 2217 | if (bundle.size() != newBundle.size()) { |
| 2218 | return false; |
| 2219 | } |
| 2220 | |
| 2221 | for(String key : bundle.keySet()) { |
| 2222 | if (key != null) { |
| 2223 | final Object value = bundle.get(key); |
| 2224 | final Object newValue = newBundle.get(key); |
| 2225 | if (!Objects.equals(value, newValue)) { |
| 2226 | return false; |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | return true; |
| 2231 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 2232 | } |