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 | |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 22 | import android.os.Handler; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 23 | |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 24 | import java.lang.String; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 25 | import java.util.ArrayList; |
| 26 | import java.util.Collections; |
| 27 | import java.util.List; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 28 | import java.util.Map; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 29 | import java.util.Objects; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 30 | import java.util.concurrent.CopyOnWriteArrayList; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Represents an ongoing phone call that the in-call app should present to the user. |
| 34 | */ |
| 35 | public final class Call { |
| 36 | /** |
| 37 | * The state of a {@code Call} when newly created. |
| 38 | */ |
| 39 | public static final int STATE_NEW = 0; |
| 40 | |
| 41 | /** |
| 42 | * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected. |
| 43 | */ |
| 44 | public static final int STATE_DIALING = 1; |
| 45 | |
| 46 | /** |
| 47 | * The state of an incoming {@code Call} when ringing locally, but not yet connected. |
| 48 | */ |
| 49 | public static final int STATE_RINGING = 2; |
| 50 | |
| 51 | /** |
| 52 | * The state of a {@code Call} when in a holding state. |
| 53 | */ |
| 54 | public static final int STATE_HOLDING = 3; |
| 55 | |
| 56 | /** |
| 57 | * The state of a {@code Call} when actively supporting conversation. |
| 58 | */ |
| 59 | public static final int STATE_ACTIVE = 4; |
| 60 | |
| 61 | /** |
| 62 | * The state of a {@code Call} when no further voice or other communication is being |
| 63 | * transmitted, the remote side has been or will inevitably be informed that the {@code Call} |
| 64 | * is no longer active, and the local data transport has or inevitably will release resources |
| 65 | * associated with this {@code Call}. |
| 66 | */ |
| 67 | public static final int STATE_DISCONNECTED = 7; |
| 68 | |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 69 | /** |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 70 | * The state of an outgoing {@code Call} when waiting on user to select a |
| 71 | * {@link PhoneAccount} through which to place the call. |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 72 | */ |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 73 | public static final int STATE_SELECT_PHONE_ACCOUNT = 8; |
| 74 | |
| 75 | /** |
| 76 | * @hide |
| 77 | * @deprecated use STATE_SELECT_PHONE_ACCOUNT. |
| 78 | */ |
| 79 | @Deprecated |
| 80 | @SystemApi |
| 81 | public static final int STATE_PRE_DIAL_WAIT = STATE_SELECT_PHONE_ACCOUNT; |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 82 | |
Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 83 | /** |
Nancy Chen | e9b7a8e | 2014-08-08 14:26:27 -0700 | [diff] [blame] | 84 | * The initial state of an outgoing {@code Call}. |
| 85 | * Common transitions are to {@link #STATE_DIALING} state for a successful call or |
| 86 | * {@link #STATE_DISCONNECTED} if it failed. |
Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 87 | */ |
| 88 | public static final int STATE_CONNECTING = 9; |
| 89 | |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 90 | /** |
Tyler Gunn | 4afc6af | 2014-10-07 10:14:55 -0700 | [diff] [blame] | 91 | * The state of a {@code Call} when the user has initiated a disconnection of the call, but the |
| 92 | * call has not yet been disconnected by the underlying {@code ConnectionService}. The next |
| 93 | * state of the call is (potentially) {@link #STATE_DISCONNECTED}. |
| 94 | */ |
| 95 | public static final int STATE_DISCONNECTING = 10; |
| 96 | |
| 97 | /** |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 98 | * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call |
| 99 | * extras. Used to pass the phone accounts to display on the front end to the user in order to |
| 100 | * select phone accounts to (for example) place a call. |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 101 | */ |
| 102 | public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts"; |
| 103 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 104 | public static class Details { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 105 | |
| 106 | /** Call can currently be put on hold or unheld. */ |
| 107 | public static final int CAPABILITY_HOLD = 0x00000001; |
| 108 | |
| 109 | /** Call supports the hold feature. */ |
| 110 | public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002; |
| 111 | |
| 112 | /** |
| 113 | * Calls within a conference can be merged. A {@link ConnectionService} has the option to |
| 114 | * add a {@link Conference} call before the child {@link Connection}s are merged. This is how |
| 115 | * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this |
| 116 | * capability allows a merge button to be shown while the conference call is in the foreground |
| 117 | * of the in-call UI. |
| 118 | * <p> |
| 119 | * This is only intended for use by a {@link Conference}. |
| 120 | */ |
| 121 | public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004; |
| 122 | |
| 123 | /** |
| 124 | * Calls within a conference can be swapped between foreground and background. |
| 125 | * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information. |
| 126 | * <p> |
| 127 | * This is only intended for use by a {@link Conference}. |
| 128 | */ |
| 129 | public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008; |
| 130 | |
| 131 | /** |
| 132 | * @hide |
| 133 | */ |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 134 | public static final int CAPABILITY_UNUSED_1 = 0x00000010; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 135 | |
| 136 | /** Call supports responding via text option. */ |
| 137 | public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020; |
| 138 | |
| 139 | /** Call can be muted. */ |
| 140 | public static final int CAPABILITY_MUTE = 0x00000040; |
| 141 | |
| 142 | /** |
| 143 | * Call supports conference call management. This capability only applies to {@link Conference} |
| 144 | * calls which can have {@link Connection}s as children. |
| 145 | */ |
| 146 | public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080; |
| 147 | |
| 148 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 149 | * Local device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 150 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 151 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 154 | * Local device supports transmitting video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 155 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 156 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 157 | |
| 158 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 159 | * Local device supports bidirectional video calling. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 160 | */ |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 161 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL = |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 162 | CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 163 | |
| 164 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 165 | * Remote device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 166 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 167 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400; |
| 168 | |
| 169 | /** |
| 170 | * Remote device supports transmitting video. |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 171 | */ |
| 172 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800; |
| 173 | |
| 174 | /** |
| 175 | * Remote device supports bidirectional video calling. |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 176 | */ |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 177 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL = |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 178 | CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Call is able to be separated from its parent {@code Conference}, if any. |
| 182 | */ |
| 183 | public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000; |
| 184 | |
| 185 | /** |
| 186 | * Call is able to be individually disconnected when in a {@code Conference}. |
| 187 | */ |
| 188 | public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000; |
| 189 | |
| 190 | /** |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 191 | * Speed up audio setup for MT call. |
| 192 | * @hide |
| 193 | */ |
Tyler Gunn | 96d6c40 | 2015-03-18 12:39:23 -0700 | [diff] [blame] | 194 | public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000; |
| 195 | |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Call can be upgraded to a video call. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 198 | * @hide |
| 199 | */ |
| 200 | public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000; |
| 201 | |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 202 | /** |
| 203 | * 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] | 204 | * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState. |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 205 | */ |
| 206 | public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000; |
| 207 | |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 208 | /** |
| 209 | * Call sends responses through connection. |
| 210 | * @hide |
| 211 | */ |
Tyler Gunn | f97a009 | 2016-01-19 15:59:34 -0800 | [diff] [blame] | 212 | public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000; |
| 213 | |
| 214 | /** |
| 215 | * When set, prevents a video {@code Call} from being downgraded to an audio-only call. |
| 216 | * <p> |
| 217 | * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or |
| 218 | * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be |
| 219 | * downgraded from a video call back to a VideoState of |
| 220 | * {@link VideoProfile#STATE_AUDIO_ONLY}. |
| 221 | * <p> |
| 222 | * Intuitively, a call which can be downgraded to audio should also have local and remote |
| 223 | * video |
| 224 | * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and |
| 225 | * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}). |
| 226 | */ |
| 227 | public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000; |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 228 | |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 229 | //****************************************************************************************** |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 230 | // Next CAPABILITY value: 0x00800000 |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 231 | //****************************************************************************************** |
| 232 | |
| 233 | /** |
| 234 | * Whether the call is currently a conference. |
| 235 | */ |
| 236 | public static final int PROPERTY_CONFERENCE = 0x00000001; |
| 237 | |
| 238 | /** |
| 239 | * Whether the call is a generic conference, where we do not know the precise state of |
| 240 | * participants in the conference (eg. on CDMA). |
| 241 | */ |
| 242 | public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002; |
| 243 | |
| 244 | /** |
| 245 | * Whether the call is made while the device is in emergency callback mode. |
| 246 | */ |
| 247 | public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004; |
| 248 | |
| 249 | /** |
| 250 | * Connection is using WIFI. |
| 251 | */ |
| 252 | public static final int PROPERTY_WIFI = 0x00000008; |
| 253 | |
| 254 | /** |
| 255 | * Call is using high definition audio. |
| 256 | */ |
| 257 | public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010; |
| 258 | |
Tony Mak | a68dcce | 2015-12-17 09:31:18 +0000 | [diff] [blame] | 259 | /** |
| 260 | * Whether the call is associated with the work profile. |
| 261 | */ |
| 262 | public static final int PROPERTY_WORK_CALL = 0x00000020; |
| 263 | |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 264 | //****************************************************************************************** |
Tony Mak | a68dcce | 2015-12-17 09:31:18 +0000 | [diff] [blame] | 265 | // Next PROPERTY value: 0x00000040 |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 266 | //****************************************************************************************** |
Tyler Gunn | 068085b | 2015-02-06 13:56:52 -0800 | [diff] [blame] | 267 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 268 | private final String mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 269 | private final Uri mHandle; |
| 270 | private final int mHandlePresentation; |
| 271 | private final String mCallerDisplayName; |
| 272 | private final int mCallerDisplayNamePresentation; |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 273 | private final PhoneAccountHandle mAccountHandle; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 274 | private final int mCallCapabilities; |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 275 | private final int mCallProperties; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 276 | private final DisconnectCause mDisconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 277 | private final long mConnectTimeMillis; |
| 278 | private final GatewayInfo mGatewayInfo; |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 279 | private final int mVideoState; |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 280 | private final StatusHints mStatusHints; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 281 | private final Bundle mExtras; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 282 | private final Bundle mIntentExtras; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 283 | |
| 284 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 285 | * Whether the supplied capabilities supports the specified capability. |
| 286 | * |
| 287 | * @param capabilities A bit field of capabilities. |
| 288 | * @param capability The capability to check capabilities for. |
| 289 | * @return Whether the specified capability is supported. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 290 | */ |
| 291 | public static boolean can(int capabilities, int capability) { |
Tyler Gunn | 014c711 | 2015-12-18 14:33:57 -0800 | [diff] [blame] | 292 | return (capabilities & capability) == capability; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Whether the capabilities of this {@code Details} supports the specified capability. |
| 297 | * |
| 298 | * @param capability The capability to check capabilities for. |
| 299 | * @return Whether the specified capability is supported. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 300 | */ |
| 301 | public boolean can(int capability) { |
| 302 | return can(mCallCapabilities, capability); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string. |
| 307 | * |
| 308 | * @param capabilities A capability bit field. |
| 309 | * @return A human readable string representation. |
| 310 | */ |
| 311 | public static String capabilitiesToString(int capabilities) { |
| 312 | StringBuilder builder = new StringBuilder(); |
| 313 | builder.append("[Capabilities:"); |
| 314 | if (can(capabilities, CAPABILITY_HOLD)) { |
| 315 | builder.append(" CAPABILITY_HOLD"); |
| 316 | } |
| 317 | if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) { |
| 318 | builder.append(" CAPABILITY_SUPPORT_HOLD"); |
| 319 | } |
| 320 | if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) { |
| 321 | builder.append(" CAPABILITY_MERGE_CONFERENCE"); |
| 322 | } |
| 323 | if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) { |
| 324 | builder.append(" CAPABILITY_SWAP_CONFERENCE"); |
| 325 | } |
| 326 | if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) { |
| 327 | builder.append(" CAPABILITY_RESPOND_VIA_TEXT"); |
| 328 | } |
| 329 | if (can(capabilities, CAPABILITY_MUTE)) { |
| 330 | builder.append(" CAPABILITY_MUTE"); |
| 331 | } |
| 332 | if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) { |
| 333 | builder.append(" CAPABILITY_MANAGE_CONFERENCE"); |
| 334 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 335 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) { |
| 336 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX"); |
| 337 | } |
| 338 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) { |
| 339 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX"); |
| 340 | } |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 341 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) { |
| 342 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 343 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame] | 344 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) { |
| 345 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX"); |
| 346 | } |
| 347 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) { |
| 348 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX"); |
| 349 | } |
Tyler Gunn | f97a009 | 2016-01-19 15:59:34 -0800 | [diff] [blame] | 350 | if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) { |
| 351 | builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO"); |
| 352 | } |
Andrew Lee | 9a8f9ce | 2015-04-10 18:09:46 -0700 | [diff] [blame] | 353 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) { |
| 354 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 355 | } |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 356 | if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) { |
Tyler Gunn | d11a315 | 2015-03-18 13:09:14 -0700 | [diff] [blame] | 357 | builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO"); |
Dong Zhou | 89f41eb | 2015-03-15 11:59:49 -0500 | [diff] [blame] | 358 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 359 | if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) { |
| 360 | builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO"); |
| 361 | } |
Tyler Gunn | b5e0cfb | 2015-04-07 16:10:51 -0700 | [diff] [blame] | 362 | if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) { |
| 363 | builder.append(" CAPABILITY_CAN_PAUSE_VIDEO"); |
| 364 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 365 | builder.append("]"); |
| 366 | return builder.toString(); |
| 367 | } |
| 368 | |
| 369 | /** |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 370 | * Whether the supplied properties includes the specified property. |
| 371 | * |
| 372 | * @param properties A bit field of properties. |
| 373 | * @param property The property to check properties for. |
| 374 | * @return Whether the specified property is supported. |
| 375 | */ |
| 376 | public static boolean hasProperty(int properties, int property) { |
Tyler Gunn | 014c711 | 2015-12-18 14:33:57 -0800 | [diff] [blame] | 377 | return (properties & property) == property; |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Whether the properties of this {@code Details} includes the specified property. |
| 382 | * |
| 383 | * @param property The property to check properties for. |
| 384 | * @return Whether the specified property is supported. |
| 385 | */ |
| 386 | public boolean hasProperty(int property) { |
| 387 | return hasProperty(mCallProperties, property); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Render a set of property bits ({@code PROPERTY_*}) as a human readable string. |
| 392 | * |
| 393 | * @param properties A property bit field. |
| 394 | * @return A human readable string representation. |
| 395 | */ |
| 396 | public static String propertiesToString(int properties) { |
| 397 | StringBuilder builder = new StringBuilder(); |
| 398 | builder.append("[Properties:"); |
| 399 | if (hasProperty(properties, PROPERTY_CONFERENCE)) { |
| 400 | builder.append(" PROPERTY_CONFERENCE"); |
| 401 | } |
| 402 | if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) { |
| 403 | builder.append(" PROPERTY_GENERIC_CONFERENCE"); |
| 404 | } |
| 405 | if (hasProperty(properties, PROPERTY_WIFI)) { |
| 406 | builder.append(" PROPERTY_WIFI"); |
| 407 | } |
| 408 | if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) { |
| 409 | builder.append(" PROPERTY_HIGH_DEF_AUDIO"); |
| 410 | } |
| 411 | if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) { |
Yorke Lee | be2a4a2 | 2015-06-12 10:10:55 -0700 | [diff] [blame] | 412 | builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE"); |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 413 | } |
| 414 | builder.append("]"); |
| 415 | return builder.toString(); |
| 416 | } |
| 417 | |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 418 | /** {@hide} */ |
| 419 | public String getTelecomCallId() { |
| 420 | return mTelecomCallId; |
| 421 | } |
| 422 | |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 423 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 424 | * @return The handle (e.g., phone number) to which the {@code Call} is currently |
| 425 | * connected. |
| 426 | */ |
| 427 | public Uri getHandle() { |
| 428 | return mHandle; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * @return The presentation requirements for the handle. See |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 433 | * {@link TelecomManager} for valid values. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 434 | */ |
| 435 | public int getHandlePresentation() { |
| 436 | return mHandlePresentation; |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * @return The display name for the caller. |
| 441 | */ |
| 442 | public String getCallerDisplayName() { |
| 443 | return mCallerDisplayName; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * @return The presentation requirements for the caller display name. See |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 448 | * {@link TelecomManager} for valid values. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 449 | */ |
| 450 | public int getCallerDisplayNamePresentation() { |
| 451 | return mCallerDisplayNamePresentation; |
| 452 | } |
| 453 | |
| 454 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 455 | * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being |
| 456 | * routed. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 457 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 458 | public PhoneAccountHandle getAccountHandle() { |
| 459 | return mAccountHandle; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 463 | * @return A bitmask of the capabilities of the {@code Call}, as defined by the various |
| 464 | * {@code CAPABILITY_*} constants in this class. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 465 | */ |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 466 | public int getCallCapabilities() { |
| 467 | return mCallCapabilities; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /** |
Andrew Lee | 2378ea7 | 2015-04-29 14:38:11 -0700 | [diff] [blame] | 471 | * @return A bitmask of the properties of the {@code Call}, as defined by the various |
| 472 | * {@code PROPERTY_*} constants in this class. |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 473 | */ |
| 474 | public int getCallProperties() { |
| 475 | return mCallProperties; |
| 476 | } |
| 477 | |
| 478 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 479 | * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed |
Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame] | 480 | * by {@link android.telecom.DisconnectCause}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 481 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 482 | public DisconnectCause getDisconnectCause() { |
| 483 | return mDisconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * @return The time the {@code Call} has been connected. This information is updated |
| 488 | * periodically, but user interfaces should not rely on this to display any "call time |
| 489 | * clock". |
| 490 | */ |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 491 | public final long getConnectTimeMillis() { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 492 | return mConnectTimeMillis; |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * @return Information about any calling gateway the {@code Call} may be using. |
| 497 | */ |
| 498 | public GatewayInfo getGatewayInfo() { |
| 499 | return mGatewayInfo; |
| 500 | } |
| 501 | |
Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 502 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 503 | * @return The video state of the {@code Call}. |
Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 504 | */ |
| 505 | public int getVideoState() { |
| 506 | return mVideoState; |
| 507 | } |
| 508 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 509 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 510 | * @return The current {@link android.telecom.StatusHints}, or {@code null} if none |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 511 | * have been set. |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 512 | */ |
| 513 | public StatusHints getStatusHints() { |
| 514 | return mStatusHints; |
| 515 | } |
| 516 | |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 517 | /** |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 518 | * @return The extras associated with this call. |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 519 | */ |
| 520 | public Bundle getExtras() { |
| 521 | return mExtras; |
| 522 | } |
| 523 | |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 524 | /** |
| 525 | * @return The extras used with the original intent to place this call. |
| 526 | */ |
| 527 | public Bundle getIntentExtras() { |
| 528 | return mIntentExtras; |
| 529 | } |
| 530 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 531 | @Override |
| 532 | public boolean equals(Object o) { |
| 533 | if (o instanceof Details) { |
| 534 | Details d = (Details) o; |
| 535 | return |
| 536 | Objects.equals(mHandle, d.mHandle) && |
| 537 | Objects.equals(mHandlePresentation, d.mHandlePresentation) && |
| 538 | Objects.equals(mCallerDisplayName, d.mCallerDisplayName) && |
| 539 | Objects.equals(mCallerDisplayNamePresentation, |
| 540 | d.mCallerDisplayNamePresentation) && |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 541 | Objects.equals(mAccountHandle, d.mAccountHandle) && |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 542 | Objects.equals(mCallCapabilities, d.mCallCapabilities) && |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 543 | Objects.equals(mCallProperties, d.mCallProperties) && |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 544 | Objects.equals(mDisconnectCause, d.mDisconnectCause) && |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 545 | Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) && |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 546 | Objects.equals(mGatewayInfo, d.mGatewayInfo) && |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 547 | Objects.equals(mVideoState, d.mVideoState) && |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 548 | Objects.equals(mStatusHints, d.mStatusHints) && |
Tyler Gunn | 1e9bfc6 | 2015-08-19 11:18:58 -0700 | [diff] [blame] | 549 | areBundlesEqual(mExtras, d.mExtras) && |
| 550 | areBundlesEqual(mIntentExtras, d.mIntentExtras); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 551 | } |
| 552 | return false; |
| 553 | } |
| 554 | |
| 555 | @Override |
| 556 | public int hashCode() { |
| 557 | return |
| 558 | Objects.hashCode(mHandle) + |
| 559 | Objects.hashCode(mHandlePresentation) + |
| 560 | Objects.hashCode(mCallerDisplayName) + |
| 561 | Objects.hashCode(mCallerDisplayNamePresentation) + |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 562 | Objects.hashCode(mAccountHandle) + |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 563 | Objects.hashCode(mCallCapabilities) + |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 564 | Objects.hashCode(mCallProperties) + |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 565 | Objects.hashCode(mDisconnectCause) + |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 566 | Objects.hashCode(mConnectTimeMillis) + |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 567 | Objects.hashCode(mGatewayInfo) + |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 568 | Objects.hashCode(mVideoState) + |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 569 | Objects.hashCode(mStatusHints) + |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 570 | Objects.hashCode(mExtras) + |
| 571 | Objects.hashCode(mIntentExtras); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** {@hide} */ |
| 575 | public Details( |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 576 | String telecomCallId, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 577 | Uri handle, |
| 578 | int handlePresentation, |
| 579 | String callerDisplayName, |
| 580 | int callerDisplayNamePresentation, |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 581 | PhoneAccountHandle accountHandle, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 582 | int capabilities, |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 583 | int properties, |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 584 | DisconnectCause disconnectCause, |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 585 | long connectTimeMillis, |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 586 | GatewayInfo gatewayInfo, |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 587 | int videoState, |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 588 | StatusHints statusHints, |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 589 | Bundle extras, |
| 590 | Bundle intentExtras) { |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 591 | mTelecomCallId = telecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 592 | mHandle = handle; |
| 593 | mHandlePresentation = handlePresentation; |
| 594 | mCallerDisplayName = callerDisplayName; |
| 595 | mCallerDisplayNamePresentation = callerDisplayNamePresentation; |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 596 | mAccountHandle = accountHandle; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 597 | mCallCapabilities = capabilities; |
Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 598 | mCallProperties = properties; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 599 | mDisconnectCause = disconnectCause; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 600 | mConnectTimeMillis = connectTimeMillis; |
| 601 | mGatewayInfo = gatewayInfo; |
Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 602 | mVideoState = videoState; |
Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 603 | mStatusHints = statusHints; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 604 | mExtras = extras; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 605 | mIntentExtras = intentExtras; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 606 | } |
Sailesh Nepal | 1bef339 | 2016-01-24 18:21:53 -0800 | [diff] [blame] | 607 | |
| 608 | /** {@hide} */ |
| 609 | public static Details createFromParcelableCall(ParcelableCall parcelableCall) { |
| 610 | return new Details( |
| 611 | parcelableCall.getId(), |
| 612 | parcelableCall.getHandle(), |
| 613 | parcelableCall.getHandlePresentation(), |
| 614 | parcelableCall.getCallerDisplayName(), |
| 615 | parcelableCall.getCallerDisplayNamePresentation(), |
| 616 | parcelableCall.getAccountHandle(), |
| 617 | parcelableCall.getCapabilities(), |
| 618 | parcelableCall.getProperties(), |
| 619 | parcelableCall.getDisconnectCause(), |
| 620 | parcelableCall.getConnectTimeMillis(), |
| 621 | parcelableCall.getGatewayInfo(), |
| 622 | parcelableCall.getVideoState(), |
| 623 | parcelableCall.getStatusHints(), |
| 624 | parcelableCall.getExtras(), |
| 625 | parcelableCall.getIntentExtras()); |
| 626 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 629 | public static abstract class Callback { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 630 | /** |
| 631 | * Invoked when the state of this {@code Call} has changed. See {@link #getState()}. |
| 632 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 633 | * @param call The {@code Call} invoking this method. |
| 634 | * @param state The new state of the {@code Call}. |
| 635 | */ |
| 636 | public void onStateChanged(Call call, int state) {} |
| 637 | |
| 638 | /** |
| 639 | * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}. |
| 640 | * |
| 641 | * @param call The {@code Call} invoking this method. |
| 642 | * @param parent The new parent of the {@code Call}. |
| 643 | */ |
| 644 | public void onParentChanged(Call call, Call parent) {} |
| 645 | |
| 646 | /** |
| 647 | * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}. |
| 648 | * |
| 649 | * @param call The {@code Call} invoking this method. |
| 650 | * @param children The new children of the {@code Call}. |
| 651 | */ |
| 652 | public void onChildrenChanged(Call call, List<Call> children) {} |
| 653 | |
| 654 | /** |
| 655 | * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}. |
| 656 | * |
| 657 | * @param call The {@code Call} invoking this method. |
| 658 | * @param details A {@code Details} object describing the {@code Call}. |
| 659 | */ |
| 660 | public void onDetailsChanged(Call call, Details details) {} |
| 661 | |
| 662 | /** |
| 663 | * Invoked when the text messages that can be used as responses to the incoming |
| 664 | * {@code Call} are loaded from the relevant database. |
| 665 | * See {@link #getCannedTextResponses()}. |
| 666 | * |
| 667 | * @param call The {@code Call} invoking this method. |
| 668 | * @param cannedTextResponses The text messages useable as responses. |
| 669 | */ |
| 670 | public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {} |
| 671 | |
| 672 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 673 | * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause |
| 674 | * character. This causes the post-dial signals to stop pending user confirmation. An |
| 675 | * implementation should present this choice to the user and invoke |
| 676 | * {@link #postDialContinue(boolean)} when the user makes the choice. |
| 677 | * |
| 678 | * @param call The {@code Call} invoking this method. |
| 679 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 680 | */ |
| 681 | public void onPostDialWait(Call call, String remainingPostDialSequence) {} |
| 682 | |
| 683 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 684 | * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 685 | * |
| 686 | * @param call The {@code Call} invoking this method. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 687 | * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 688 | */ |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 689 | public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {} |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 690 | |
| 691 | /** |
| 692 | * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning |
| 693 | * up their UI for the {@code Call} in response to state transitions. Specifically, |
| 694 | * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of |
| 695 | * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather, |
| 696 | * clients should wait for this method to be invoked. |
| 697 | * |
| 698 | * @param call The {@code Call} being destroyed. |
| 699 | */ |
| 700 | public void onCallDestroyed(Call call) {} |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 701 | |
| 702 | /** |
| 703 | * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be |
| 704 | * conferenced. |
| 705 | * |
| 706 | * @param call The {@code Call} being updated. |
| 707 | * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be |
| 708 | * conferenced. |
| 709 | */ |
| 710 | public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {} |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 713 | /** |
| 714 | * @deprecated Use {@code Call.Callback} instead. |
| 715 | * @hide |
| 716 | */ |
| 717 | @Deprecated |
| 718 | @SystemApi |
| 719 | public static abstract class Listener extends Callback { } |
| 720 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 721 | private final Phone mPhone; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 722 | private final String mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 723 | private final InCallAdapter mInCallAdapter; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 724 | private final List<String> mChildrenIds = new ArrayList<>(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 725 | private final List<Call> mChildren = new ArrayList<>(); |
| 726 | private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren); |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 727 | private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>(); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 728 | private final List<Call> mConferenceableCalls = new ArrayList<>(); |
| 729 | private final List<Call> mUnmodifiableConferenceableCalls = |
| 730 | Collections.unmodifiableList(mConferenceableCalls); |
| 731 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 732 | private boolean mChildrenCached; |
| 733 | private String mParentId = null; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 734 | private int mState; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 735 | private List<String> mCannedTextResponses = null; |
| 736 | private String mRemainingPostDialSequence; |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 737 | private VideoCallImpl mVideoCallImpl; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 738 | private Details mDetails; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 739 | |
| 740 | /** |
| 741 | * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any. |
| 742 | * |
| 743 | * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence |
| 744 | * remaining or this {@code Call} is not in a post-dial state. |
| 745 | */ |
| 746 | public String getRemainingPostDialSequence() { |
| 747 | return mRemainingPostDialSequence; |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * Instructs this {@link #STATE_RINGING} {@code Call} to answer. |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 752 | * @param videoState The video state in which to answer the call. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 753 | */ |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 754 | public void answer(int videoState) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 755 | mInCallAdapter.answerCall(mTelecomCallId, videoState); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Instructs this {@link #STATE_RINGING} {@code Call} to reject. |
| 760 | * |
| 761 | * @param rejectWithMessage Whether to reject with a text message. |
| 762 | * @param textMessage An optional text message with which to respond. |
| 763 | */ |
| 764 | public void reject(boolean rejectWithMessage, String textMessage) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 765 | mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Instructs this {@code Call} to disconnect. |
| 770 | */ |
| 771 | public void disconnect() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 772 | mInCallAdapter.disconnectCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Instructs this {@code Call} to go on hold. |
| 777 | */ |
| 778 | public void hold() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 779 | mInCallAdapter.holdCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Instructs this {@link #STATE_HOLDING} call to release from hold. |
| 784 | */ |
| 785 | public void unhold() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 786 | mInCallAdapter.unholdCall(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone. |
| 791 | * |
| 792 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 793 | * |
| 794 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 795 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 796 | */ |
| 797 | public void playDtmfTone(char digit) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 798 | mInCallAdapter.playDtmfTone(mTelecomCallId, digit); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
| 802 | * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone |
| 803 | * currently playing. |
| 804 | * |
| 805 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 806 | * currently playing, this method will do nothing. |
| 807 | */ |
| 808 | public void stopDtmfTone() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 809 | mInCallAdapter.stopDtmfTone(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Instructs this {@code Call} to continue playing a post-dial DTMF string. |
| 814 | * |
| 815 | * A post-dial DTMF string is a string of digits entered after a phone number, when dialed, |
| 816 | * 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] | 817 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 818 | * 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] | 819 | * {@code Call} will temporarily pause playing the tones for a pre-defined period of time. |
| 820 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 821 | * 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] | 822 | * {@code Call} will pause playing the tones and notify callbacks via |
| 823 | * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 824 | * should display to the user an indication of this state and an affordance to continue |
| 825 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 826 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 827 | * |
| 828 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 829 | */ |
| 830 | public void postDialContinue(boolean proceed) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 831 | mInCallAdapter.postDialContinue(mTelecomCallId, proceed); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 835 | * 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] | 836 | * an outgoing call. Optionally sets this account as the default account. |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 837 | */ |
Nancy Chen | 36c62f3 | 2014-10-21 18:36:39 -0700 | [diff] [blame] | 838 | public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) { |
| 839 | mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault); |
Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 840 | |
| 841 | } |
| 842 | |
| 843 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 844 | * Instructs this {@code Call} to enter a conference. |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 845 | * |
| 846 | * @param callToConferenceWith The other call with which to conference. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 847 | */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 848 | public void conference(Call callToConferenceWith) { |
| 849 | if (callToConferenceWith != null) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 850 | mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 851 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /** |
| 855 | * Instructs this {@code Call} to split from any conference call with which it may be |
| 856 | * connected. |
| 857 | */ |
| 858 | public void splitFromConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 859 | mInCallAdapter.splitFromConference(mTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 863 | * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 864 | */ |
| 865 | public void mergeConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 866 | mInCallAdapter.mergeConference(mTelecomCallId); |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 870 | * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 871 | */ |
| 872 | public void swapConference() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 873 | mInCallAdapter.swapConference(mTelecomCallId); |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 877 | * Obtains the parent of this {@code Call} in a conference, if any. |
| 878 | * |
| 879 | * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a |
| 880 | * child of any conference {@code Call}s. |
| 881 | */ |
| 882 | public Call getParent() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 883 | if (mParentId != null) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 884 | return mPhone.internalGetCallByTelecomId(mParentId); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 885 | } |
| 886 | return null; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Obtains the children of this conference {@code Call}, if any. |
| 891 | * |
| 892 | * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty |
| 893 | * {@code List} otherwise. |
| 894 | */ |
| 895 | public List<Call> getChildren() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 896 | if (!mChildrenCached) { |
| 897 | mChildrenCached = true; |
| 898 | mChildren.clear(); |
| 899 | |
| 900 | for(String id : mChildrenIds) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 901 | Call call = mPhone.internalGetCallByTelecomId(id); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 902 | if (call == null) { |
| 903 | // At least one child was still not found, so do not save true for "cached" |
| 904 | mChildrenCached = false; |
| 905 | } else { |
| 906 | mChildren.add(call); |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 911 | return mUnmodifiableChildren; |
| 912 | } |
| 913 | |
| 914 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 915 | * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference. |
| 916 | * |
| 917 | * @return The list of conferenceable {@code Call}s. |
| 918 | */ |
| 919 | public List<Call> getConferenceableCalls() { |
| 920 | return mUnmodifiableConferenceableCalls; |
| 921 | } |
| 922 | |
| 923 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 924 | * Obtains the state of this {@code Call}. |
| 925 | * |
| 926 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 927 | */ |
| 928 | public int getState() { |
| 929 | return mState; |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * Obtains a list of canned, pre-configured message responses to present to the user as |
| 934 | * ways of rejecting this {@code Call} using via a text message. |
| 935 | * |
| 936 | * @see #reject(boolean, String) |
| 937 | * |
| 938 | * @return A list of canned text message responses. |
| 939 | */ |
| 940 | public List<String> getCannedTextResponses() { |
| 941 | return mCannedTextResponses; |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * Obtains an object that can be used to display video from this {@code Call}. |
| 946 | * |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 947 | * @return An {@code Call.VideoCall}. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 948 | */ |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 949 | public InCallService.VideoCall getVideoCall() { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 950 | return mVideoCallImpl; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | /** |
| 954 | * Obtains an object containing call details. |
| 955 | * |
| 956 | * @return A {@link Details} object. Depending on the state of the {@code Call}, the |
| 957 | * result may be {@code null}. |
| 958 | */ |
| 959 | public Details getDetails() { |
| 960 | return mDetails; |
| 961 | } |
| 962 | |
| 963 | /** |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 964 | * Registers a callback to this {@code Call}. |
| 965 | * |
| 966 | * @param callback A {@code Callback}. |
| 967 | */ |
| 968 | public void registerCallback(Callback callback) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 969 | registerCallback(callback, new Handler()); |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * Registers a callback to this {@code Call}. |
| 974 | * |
| 975 | * @param callback A {@code Callback}. |
| 976 | * @param handler A handler which command and status changes will be delivered to. |
| 977 | */ |
| 978 | public void registerCallback(Callback callback, Handler handler) { |
| 979 | unregisterCallback(callback); |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 980 | // Don't allow new callback registration if the call is already being destroyed. |
| 981 | if (callback != null && handler != null && mState != STATE_DISCONNECTED) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 982 | mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler)); |
| 983 | } |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Unregisters a callback from this {@code Call}. |
| 988 | * |
| 989 | * @param callback A {@code Callback}. |
| 990 | */ |
| 991 | public void unregisterCallback(Callback callback) { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 992 | // Don't allow callback deregistration if the call is already being destroyed. |
| 993 | if (callback != null && mState != STATE_DISCONNECTED) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 994 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 995 | if (record.getCallback() == callback) { |
| 996 | mCallbackRecords.remove(record); |
| 997 | break; |
| 998 | } |
| 999 | } |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1004 | * Adds a listener to this {@code Call}. |
| 1005 | * |
| 1006 | * @param listener A {@code Listener}. |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1007 | * @deprecated Use {@link #registerCallback} instead. |
| 1008 | * @hide |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1009 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1010 | @Deprecated |
| 1011 | @SystemApi |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1012 | public void addListener(Listener listener) { |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1013 | registerCallback(listener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Removes a listener from this {@code Call}. |
| 1018 | * |
| 1019 | * @param listener A {@code Listener}. |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1020 | * @deprecated Use {@link #unregisterCallback} instead. |
| 1021 | * @hide |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1022 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1023 | @Deprecated |
| 1024 | @SystemApi |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1025 | public void removeListener(Listener listener) { |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 1026 | unregisterCallback(listener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /** {@hide} */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1030 | Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1031 | mPhone = phone; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1032 | mTelecomCallId = telecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1033 | mInCallAdapter = inCallAdapter; |
| 1034 | mState = STATE_NEW; |
| 1035 | } |
| 1036 | |
| 1037 | /** {@hide} */ |
Shriram Ganesh | ddf570e | 2015-05-31 09:18:48 -0700 | [diff] [blame] | 1038 | Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state) { |
| 1039 | mPhone = phone; |
| 1040 | mTelecomCallId = telecomCallId; |
| 1041 | mInCallAdapter = inCallAdapter; |
| 1042 | mState = state; |
| 1043 | } |
| 1044 | |
| 1045 | /** {@hide} */ |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1046 | final String internalGetCallId() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1047 | return mTelecomCallId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /** {@hide} */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1051 | final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1052 | // 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] | 1053 | Details details = Details.createFromParcelableCall(parcelableCall); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1054 | boolean detailsChanged = !Objects.equals(mDetails, details); |
| 1055 | if (detailsChanged) { |
| 1056 | mDetails = details; |
| 1057 | } |
| 1058 | |
| 1059 | boolean cannedTextResponsesChanged = false; |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 1060 | if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null |
| 1061 | && !parcelableCall.getCannedSmsResponses().isEmpty()) { |
| 1062 | mCannedTextResponses = |
| 1063 | Collections.unmodifiableList(parcelableCall.getCannedSmsResponses()); |
Yorke Lee | e886f63 | 2015-08-04 13:43:31 -0700 | [diff] [blame] | 1064 | cannedTextResponsesChanged = true; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1067 | VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 1068 | boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() && |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1069 | !Objects.equals(mVideoCallImpl, newVideoCallImpl); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1070 | if (videoCallChanged) { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1071 | mVideoCallImpl = newVideoCallImpl; |
| 1072 | } |
| 1073 | if (mVideoCallImpl != null) { |
| 1074 | mVideoCallImpl.setVideoState(getDetails().getVideoState()); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Santos Cordon | e3c507b | 2015-04-23 14:44:19 -0700 | [diff] [blame] | 1077 | int state = parcelableCall.getState(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1078 | boolean stateChanged = mState != state; |
| 1079 | if (stateChanged) { |
| 1080 | mState = state; |
| 1081 | } |
| 1082 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1083 | String parentId = parcelableCall.getParentCallId(); |
| 1084 | boolean parentChanged = !Objects.equals(mParentId, parentId); |
| 1085 | if (parentChanged) { |
| 1086 | mParentId = parentId; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1089 | List<String> childCallIds = parcelableCall.getChildCallIds(); |
| 1090 | boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds); |
| 1091 | if (childrenChanged) { |
| 1092 | mChildrenIds.clear(); |
| 1093 | mChildrenIds.addAll(parcelableCall.getChildCallIds()); |
| 1094 | mChildrenCached = false; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1097 | List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds(); |
| 1098 | List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size()); |
| 1099 | for (String otherId : conferenceableCallIds) { |
| 1100 | if (callIdMap.containsKey(otherId)) { |
| 1101 | conferenceableCalls.add(callIdMap.get(otherId)); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) { |
| 1106 | mConferenceableCalls.clear(); |
| 1107 | mConferenceableCalls.addAll(conferenceableCalls); |
| 1108 | fireConferenceableCallsChanged(); |
| 1109 | } |
| 1110 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1111 | // Now we fire updates, ensuring that any client who listens to any of these notifications |
| 1112 | // gets the most up-to-date state. |
| 1113 | |
| 1114 | if (stateChanged) { |
| 1115 | fireStateChanged(mState); |
| 1116 | } |
| 1117 | if (detailsChanged) { |
| 1118 | fireDetailsChanged(mDetails); |
| 1119 | } |
| 1120 | if (cannedTextResponsesChanged) { |
| 1121 | fireCannedTextResponsesLoaded(mCannedTextResponses); |
| 1122 | } |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 1123 | if (videoCallChanged) { |
Tyler Gunn | 584ba6c | 2015-12-08 10:53:41 -0800 | [diff] [blame] | 1124 | fireVideoCallChanged(mVideoCallImpl); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1125 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1126 | if (parentChanged) { |
| 1127 | fireParentChanged(getParent()); |
| 1128 | } |
| 1129 | if (childrenChanged) { |
| 1130 | fireChildrenChanged(getChildren()); |
| 1131 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1132 | |
| 1133 | // If we have transitioned to DISCONNECTED, that means we need to notify clients and |
| 1134 | // remove ourselves from the Phone. Note that we do this after completing all state updates |
| 1135 | // so a client can cleanly transition all their UI to the state appropriate for a |
| 1136 | // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list. |
| 1137 | if (mState == STATE_DISCONNECTED) { |
| 1138 | fireCallDestroyed(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | /** {@hide} */ |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1143 | final void internalSetPostDialWait(String remaining) { |
| 1144 | mRemainingPostDialSequence = remaining; |
| 1145 | firePostDialWait(mRemainingPostDialSequence); |
| 1146 | } |
| 1147 | |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 1148 | /** {@hide} */ |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 1149 | final void internalSetDisconnected() { |
| 1150 | if (mState != Call.STATE_DISCONNECTED) { |
| 1151 | mState = Call.STATE_DISCONNECTED; |
| 1152 | fireStateChanged(mState); |
| 1153 | fireCallDestroyed(); |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1157 | private void fireStateChanged(final int newState) { |
| 1158 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1159 | final Call call = this; |
| 1160 | final Callback callback = record.getCallback(); |
| 1161 | record.getHandler().post(new Runnable() { |
| 1162 | @Override |
| 1163 | public void run() { |
| 1164 | callback.onStateChanged(call, newState); |
| 1165 | } |
| 1166 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1170 | private void fireParentChanged(final Call newParent) { |
| 1171 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1172 | final Call call = this; |
| 1173 | final Callback callback = record.getCallback(); |
| 1174 | record.getHandler().post(new Runnable() { |
| 1175 | @Override |
| 1176 | public void run() { |
| 1177 | callback.onParentChanged(call, newParent); |
| 1178 | } |
| 1179 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1183 | private void fireChildrenChanged(final List<Call> children) { |
| 1184 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1185 | final Call call = this; |
| 1186 | final Callback callback = record.getCallback(); |
| 1187 | record.getHandler().post(new Runnable() { |
| 1188 | @Override |
| 1189 | public void run() { |
| 1190 | callback.onChildrenChanged(call, children); |
| 1191 | } |
| 1192 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1196 | private void fireDetailsChanged(final Details details) { |
| 1197 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1198 | final Call call = this; |
| 1199 | final Callback callback = record.getCallback(); |
| 1200 | record.getHandler().post(new Runnable() { |
| 1201 | @Override |
| 1202 | public void run() { |
| 1203 | callback.onDetailsChanged(call, details); |
| 1204 | } |
| 1205 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1209 | private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) { |
| 1210 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1211 | final Call call = this; |
| 1212 | final Callback callback = record.getCallback(); |
| 1213 | record.getHandler().post(new Runnable() { |
| 1214 | @Override |
| 1215 | public void run() { |
| 1216 | callback.onCannedTextResponsesLoaded(call, cannedTextResponses); |
| 1217 | } |
| 1218 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1222 | private void fireVideoCallChanged(final InCallService.VideoCall videoCall) { |
| 1223 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1224 | final Call call = this; |
| 1225 | final Callback callback = record.getCallback(); |
| 1226 | record.getHandler().post(new Runnable() { |
| 1227 | @Override |
| 1228 | public void run() { |
| 1229 | callback.onVideoCallChanged(call, videoCall); |
| 1230 | } |
| 1231 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1235 | private void firePostDialWait(final String remainingPostDialSequence) { |
| 1236 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1237 | final Call call = this; |
| 1238 | final Callback callback = record.getCallback(); |
| 1239 | record.getHandler().post(new Runnable() { |
| 1240 | @Override |
| 1241 | public void run() { |
| 1242 | callback.onPostDialWait(call, remainingPostDialSequence); |
| 1243 | } |
| 1244 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | private void fireCallDestroyed() { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 1249 | /** |
| 1250 | * To preserve the ordering of the Call's onCallDestroyed callback and Phone's |
| 1251 | * onCallRemoved callback, we remove this call from the Phone's record |
| 1252 | * only once all of the registered onCallDestroyed callbacks are executed. |
| 1253 | * All the callbacks get removed from our records as a part of this operation |
| 1254 | * since onCallDestroyed is the final callback. |
| 1255 | */ |
| 1256 | final Call call = this; |
| 1257 | if (mCallbackRecords.isEmpty()) { |
| 1258 | // No callbacks registered, remove the call from Phone's record. |
| 1259 | mPhone.internalRemoveCall(call); |
| 1260 | } |
| 1261 | for (final CallbackRecord<Callback> record : mCallbackRecords) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1262 | final Callback callback = record.getCallback(); |
| 1263 | record.getHandler().post(new Runnable() { |
| 1264 | @Override |
| 1265 | public void run() { |
Roshan Pius | 1ca6207 | 2015-07-07 17:34:51 -0700 | [diff] [blame] | 1266 | boolean isFinalRemoval = false; |
| 1267 | RuntimeException toThrow = null; |
| 1268 | try { |
| 1269 | callback.onCallDestroyed(call); |
| 1270 | } catch (RuntimeException e) { |
| 1271 | toThrow = e; |
| 1272 | } |
| 1273 | synchronized(Call.this) { |
| 1274 | mCallbackRecords.remove(record); |
| 1275 | if (mCallbackRecords.isEmpty()) { |
| 1276 | isFinalRemoval = true; |
| 1277 | } |
| 1278 | } |
| 1279 | if (isFinalRemoval) { |
| 1280 | mPhone.internalRemoveCall(call); |
| 1281 | } |
| 1282 | if (toThrow != null) { |
| 1283 | throw toThrow; |
| 1284 | } |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1285 | } |
| 1286 | }); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1290 | private void fireConferenceableCallsChanged() { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1291 | for (CallbackRecord<Callback> record : mCallbackRecords) { |
| 1292 | final Call call = this; |
| 1293 | final Callback callback = record.getCallback(); |
| 1294 | record.getHandler().post(new Runnable() { |
| 1295 | @Override |
| 1296 | public void run() { |
| 1297 | callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls); |
| 1298 | } |
| 1299 | }); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1300 | } |
| 1301 | } |
Tyler Gunn | 1e9bfc6 | 2015-08-19 11:18:58 -0700 | [diff] [blame] | 1302 | |
| 1303 | /** |
| 1304 | * Determines if two bundles are equal. |
| 1305 | * |
| 1306 | * @param bundle The original bundle. |
| 1307 | * @param newBundle The bundle to compare with. |
| 1308 | * @retrun {@code true} if the bundles are equal, {@code false} otherwise. |
| 1309 | */ |
| 1310 | private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) { |
| 1311 | if (bundle == null || newBundle == null) { |
| 1312 | return bundle == newBundle; |
| 1313 | } |
| 1314 | |
| 1315 | if (bundle.size() != newBundle.size()) { |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
| 1319 | for(String key : bundle.keySet()) { |
| 1320 | if (key != null) { |
| 1321 | final Object value = bundle.get(key); |
| 1322 | final Object newValue = newBundle.get(key); |
| 1323 | if (!Objects.equals(value, newValue)) { |
| 1324 | return false; |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | return true; |
| 1329 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1330 | } |