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