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