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