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