| 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 | |
| Gabriel Peal | b95f169 | 2014-08-19 14:24:18 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 22 | |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 23 | import java.lang.String; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 27 | import java.util.Map; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 28 | import java.util.Objects; |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 29 | import java.util.concurrent.CopyOnWriteArrayList; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Represents an ongoing phone call that the in-call app should present to the user. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 33 | * |
| 34 | * {@hide} |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 35 | */ |
| Gabriel Peal | b95f169 | 2014-08-19 14:24:18 -0700 | [diff] [blame] | 36 | @SystemApi |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 37 | public final class Call { |
| 38 | /** |
| 39 | * The state of a {@code Call} when newly created. |
| 40 | */ |
| 41 | public static final int STATE_NEW = 0; |
| 42 | |
| 43 | /** |
| 44 | * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected. |
| 45 | */ |
| 46 | public static final int STATE_DIALING = 1; |
| 47 | |
| 48 | /** |
| 49 | * The state of an incoming {@code Call} when ringing locally, but not yet connected. |
| 50 | */ |
| 51 | public static final int STATE_RINGING = 2; |
| 52 | |
| 53 | /** |
| 54 | * The state of a {@code Call} when in a holding state. |
| 55 | */ |
| 56 | public static final int STATE_HOLDING = 3; |
| 57 | |
| 58 | /** |
| 59 | * The state of a {@code Call} when actively supporting conversation. |
| 60 | */ |
| 61 | public static final int STATE_ACTIVE = 4; |
| 62 | |
| 63 | /** |
| 64 | * The state of a {@code Call} when no further voice or other communication is being |
| 65 | * transmitted, the remote side has been or will inevitably be informed that the {@code Call} |
| 66 | * is no longer active, and the local data transport has or inevitably will release resources |
| 67 | * associated with this {@code Call}. |
| 68 | */ |
| 69 | public static final int STATE_DISCONNECTED = 7; |
| 70 | |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 71 | /** |
| 72 | * The state of an outgoing {@code Call}, but waiting for user input before proceeding. |
| 73 | */ |
| 74 | public static final int STATE_PRE_DIAL_WAIT = 8; |
| 75 | |
| Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 76 | /** |
| Nancy Chen | e9b7a8e | 2014-08-08 14:26:27 -0700 | [diff] [blame] | 77 | * The initial state of an outgoing {@code Call}. |
| 78 | * Common transitions are to {@link #STATE_DIALING} state for a successful call or |
| 79 | * {@link #STATE_DISCONNECTED} if it failed. |
| Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 80 | */ |
| 81 | public static final int STATE_CONNECTING = 9; |
| 82 | |
| Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 83 | /** |
| 84 | * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call |
| 85 | * extras. Used to pass the phone accounts to display on the front end to the user in order to |
| 86 | * select phone accounts to (for example) place a call. |
| 87 | * |
| 88 | * @hide |
| 89 | */ |
| 90 | public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts"; |
| 91 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 92 | public static class Details { |
| 93 | private final Uri mHandle; |
| 94 | private final int mHandlePresentation; |
| 95 | private final String mCallerDisplayName; |
| 96 | private final int mCallerDisplayNamePresentation; |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 97 | private final PhoneAccountHandle mAccountHandle; |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 98 | private final int mCallCapabilities; |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 99 | private final int mCallProperties; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 100 | private final DisconnectCause mDisconnectCause; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 101 | private final long mConnectTimeMillis; |
| 102 | private final GatewayInfo mGatewayInfo; |
| Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 103 | private final int mVideoState; |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 104 | private final StatusHints mStatusHints; |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 105 | private final Bundle mExtras; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * @return The handle (e.g., phone number) to which the {@code Call} is currently |
| 109 | * connected. |
| 110 | */ |
| 111 | public Uri getHandle() { |
| 112 | return mHandle; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return The presentation requirements for the handle. See |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 117 | * {@link TelecomManager} for valid values. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 118 | */ |
| 119 | public int getHandlePresentation() { |
| 120 | return mHandlePresentation; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @return The display name for the caller. |
| 125 | */ |
| 126 | public String getCallerDisplayName() { |
| 127 | return mCallerDisplayName; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @return The presentation requirements for the caller display name. See |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 132 | * {@link TelecomManager} for valid values. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 133 | */ |
| 134 | public int getCallerDisplayNamePresentation() { |
| 135 | return mCallerDisplayNamePresentation; |
| 136 | } |
| 137 | |
| 138 | /** |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 139 | * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being |
| 140 | * routed. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 141 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 142 | public PhoneAccountHandle getAccountHandle() { |
| 143 | return mAccountHandle; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @return A bitmask of the capabilities of the {@code Call}, as defined in |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 148 | * {@link PhoneCapabilities}. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 149 | */ |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 150 | public int getCallCapabilities() { |
| 151 | return mCallCapabilities; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 155 | * @return A bitmask of the properties of the {@code Call}, as defined in |
| 156 | * {@link CallProperties}. |
| 157 | */ |
| 158 | public int getCallProperties() { |
| 159 | return mCallProperties; |
| 160 | } |
| 161 | |
| 162 | /** |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 163 | * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed |
| Nancy Chen | f4cf77c | 2014-09-19 10:53:21 -0700 | [diff] [blame^] | 164 | * by {@link android.telecom.DisconnectCause}. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 165 | */ |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 166 | public DisconnectCause getDisconnectCause() { |
| 167 | return mDisconnectCause; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @return The time the {@code Call} has been connected. This information is updated |
| 172 | * periodically, but user interfaces should not rely on this to display any "call time |
| 173 | * clock". |
| 174 | */ |
| 175 | public long getConnectTimeMillis() { |
| 176 | return mConnectTimeMillis; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @return Information about any calling gateway the {@code Call} may be using. |
| 181 | */ |
| 182 | public GatewayInfo getGatewayInfo() { |
| 183 | return mGatewayInfo; |
| 184 | } |
| 185 | |
| Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 186 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 187 | * @return The video state of the {@code Call}. |
| Andrew Lee | 7a34138 | 2014-07-15 17:05:08 -0700 | [diff] [blame] | 188 | */ |
| 189 | public int getVideoState() { |
| 190 | return mVideoState; |
| 191 | } |
| 192 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 193 | /** |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 194 | * @return The current {@link android.telecom.StatusHints}, or {@code null} if none |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 195 | * have been set. |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 196 | */ |
| 197 | public StatusHints getStatusHints() { |
| 198 | return mStatusHints; |
| 199 | } |
| 200 | |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 201 | /** |
| 202 | * @return A bundle extras to pass with the call |
| 203 | */ |
| 204 | public Bundle getExtras() { |
| 205 | return mExtras; |
| 206 | } |
| 207 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 208 | @Override |
| 209 | public boolean equals(Object o) { |
| 210 | if (o instanceof Details) { |
| 211 | Details d = (Details) o; |
| 212 | return |
| 213 | Objects.equals(mHandle, d.mHandle) && |
| 214 | Objects.equals(mHandlePresentation, d.mHandlePresentation) && |
| 215 | Objects.equals(mCallerDisplayName, d.mCallerDisplayName) && |
| 216 | Objects.equals(mCallerDisplayNamePresentation, |
| 217 | d.mCallerDisplayNamePresentation) && |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 218 | Objects.equals(mAccountHandle, d.mAccountHandle) && |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 219 | Objects.equals(mCallCapabilities, d.mCallCapabilities) && |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 220 | Objects.equals(mCallProperties, d.mCallProperties) && |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 221 | Objects.equals(mDisconnectCause, d.mDisconnectCause) && |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 222 | Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) && |
| Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 223 | Objects.equals(mGatewayInfo, d.mGatewayInfo) && |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 224 | Objects.equals(mVideoState, d.mVideoState) && |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 225 | Objects.equals(mStatusHints, d.mStatusHints) && |
| 226 | Objects.equals(mExtras, d.mExtras); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 227 | } |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public int hashCode() { |
| 233 | return |
| 234 | Objects.hashCode(mHandle) + |
| 235 | Objects.hashCode(mHandlePresentation) + |
| 236 | Objects.hashCode(mCallerDisplayName) + |
| 237 | Objects.hashCode(mCallerDisplayNamePresentation) + |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 238 | Objects.hashCode(mAccountHandle) + |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 239 | Objects.hashCode(mCallCapabilities) + |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 240 | Objects.hashCode(mCallProperties) + |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 241 | Objects.hashCode(mDisconnectCause) + |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 242 | Objects.hashCode(mConnectTimeMillis) + |
| Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 243 | Objects.hashCode(mGatewayInfo) + |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 244 | Objects.hashCode(mVideoState) + |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 245 | Objects.hashCode(mStatusHints) + |
| 246 | Objects.hashCode(mExtras); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** {@hide} */ |
| 250 | public Details( |
| 251 | Uri handle, |
| 252 | int handlePresentation, |
| 253 | String callerDisplayName, |
| 254 | int callerDisplayNamePresentation, |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 255 | PhoneAccountHandle accountHandle, |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 256 | int capabilities, |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 257 | int properties, |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 258 | DisconnectCause disconnectCause, |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 259 | long connectTimeMillis, |
| Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 260 | GatewayInfo gatewayInfo, |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 261 | int videoState, |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 262 | StatusHints statusHints, |
| 263 | Bundle extras) { |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 264 | mHandle = handle; |
| 265 | mHandlePresentation = handlePresentation; |
| 266 | mCallerDisplayName = callerDisplayName; |
| 267 | mCallerDisplayNamePresentation = callerDisplayNamePresentation; |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 268 | mAccountHandle = accountHandle; |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 269 | mCallCapabilities = capabilities; |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 270 | mCallProperties = properties; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 271 | mDisconnectCause = disconnectCause; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 272 | mConnectTimeMillis = connectTimeMillis; |
| 273 | mGatewayInfo = gatewayInfo; |
| Andrew Lee | 85f5d42 | 2014-07-11 17:22:03 -0700 | [diff] [blame] | 274 | mVideoState = videoState; |
| Evan Charlton | 5b49ade | 2014-07-15 17:03:20 -0700 | [diff] [blame] | 275 | mStatusHints = statusHints; |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 276 | mExtras = extras; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | public static abstract class Listener { |
| 281 | /** |
| 282 | * Invoked when the state of this {@code Call} has changed. See {@link #getState()}. |
| 283 | * |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 284 | * @param call The {@code Call} invoking this method. |
| 285 | * @param state The new state of the {@code Call}. |
| 286 | */ |
| 287 | public void onStateChanged(Call call, int state) {} |
| 288 | |
| 289 | /** |
| 290 | * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}. |
| 291 | * |
| 292 | * @param call The {@code Call} invoking this method. |
| 293 | * @param parent The new parent of the {@code Call}. |
| 294 | */ |
| 295 | public void onParentChanged(Call call, Call parent) {} |
| 296 | |
| 297 | /** |
| 298 | * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}. |
| 299 | * |
| 300 | * @param call The {@code Call} invoking this method. |
| 301 | * @param children The new children of the {@code Call}. |
| 302 | */ |
| 303 | public void onChildrenChanged(Call call, List<Call> children) {} |
| 304 | |
| 305 | /** |
| 306 | * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}. |
| 307 | * |
| 308 | * @param call The {@code Call} invoking this method. |
| 309 | * @param details A {@code Details} object describing the {@code Call}. |
| 310 | */ |
| 311 | public void onDetailsChanged(Call call, Details details) {} |
| 312 | |
| 313 | /** |
| 314 | * Invoked when the text messages that can be used as responses to the incoming |
| 315 | * {@code Call} are loaded from the relevant database. |
| 316 | * See {@link #getCannedTextResponses()}. |
| 317 | * |
| 318 | * @param call The {@code Call} invoking this method. |
| 319 | * @param cannedTextResponses The text messages useable as responses. |
| 320 | */ |
| 321 | public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {} |
| 322 | |
| 323 | /** |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 324 | * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause |
| 325 | * character. This causes the post-dial signals to stop pending user confirmation. An |
| 326 | * implementation should present this choice to the user and invoke |
| 327 | * {@link #postDialContinue(boolean)} when the user makes the choice. |
| 328 | * |
| 329 | * @param call The {@code Call} invoking this method. |
| 330 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 331 | */ |
| 332 | public void onPostDialWait(Call call, String remainingPostDialSequence) {} |
| 333 | |
| 334 | /** |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 335 | * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 336 | * |
| 337 | * @param call The {@code Call} invoking this method. |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 338 | * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}. |
| Tyler Gunn | 75537ae | 2014-08-22 11:33:13 -0700 | [diff] [blame] | 339 | * @hide |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 340 | */ |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 341 | public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {} |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 342 | |
| 343 | /** |
| 344 | * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning |
| 345 | * up their UI for the {@code Call} in response to state transitions. Specifically, |
| 346 | * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of |
| 347 | * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather, |
| 348 | * clients should wait for this method to be invoked. |
| 349 | * |
| 350 | * @param call The {@code Call} being destroyed. |
| 351 | */ |
| 352 | public void onCallDestroyed(Call call) {} |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 353 | |
| 354 | /** |
| 355 | * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be |
| 356 | * conferenced. |
| 357 | * |
| 358 | * @param call The {@code Call} being updated. |
| 359 | * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be |
| 360 | * conferenced. |
| 361 | */ |
| 362 | public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {} |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | private final Phone mPhone; |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 366 | private final String mTelecomCallId; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 367 | private final InCallAdapter mInCallAdapter; |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 368 | private final List<String> mChildrenIds = new ArrayList<>(); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 369 | private final List<Call> mChildren = new ArrayList<>(); |
| 370 | private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren); |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 371 | private final List<Listener> mListeners = new CopyOnWriteArrayList<>(); |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 372 | private final List<Call> mConferenceableCalls = new ArrayList<>(); |
| 373 | private final List<Call> mUnmodifiableConferenceableCalls = |
| 374 | Collections.unmodifiableList(mConferenceableCalls); |
| 375 | |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 376 | private boolean mChildrenCached; |
| 377 | private String mParentId = null; |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 378 | private int mState; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 379 | private List<String> mCannedTextResponses = null; |
| 380 | private String mRemainingPostDialSequence; |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 381 | private InCallService.VideoCall mVideoCall; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 382 | private Details mDetails; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any. |
| 386 | * |
| 387 | * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence |
| 388 | * remaining or this {@code Call} is not in a post-dial state. |
| 389 | */ |
| 390 | public String getRemainingPostDialSequence() { |
| 391 | return mRemainingPostDialSequence; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Instructs this {@link #STATE_RINGING} {@code Call} to answer. |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 396 | * @param videoState The video state in which to answer the call. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 397 | */ |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 398 | public void answer(int videoState) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 399 | mInCallAdapter.answerCall(mTelecomCallId, videoState); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Instructs this {@link #STATE_RINGING} {@code Call} to reject. |
| 404 | * |
| 405 | * @param rejectWithMessage Whether to reject with a text message. |
| 406 | * @param textMessage An optional text message with which to respond. |
| 407 | */ |
| 408 | public void reject(boolean rejectWithMessage, String textMessage) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 409 | mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Instructs this {@code Call} to disconnect. |
| 414 | */ |
| 415 | public void disconnect() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 416 | mInCallAdapter.disconnectCall(mTelecomCallId); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Instructs this {@code Call} to go on hold. |
| 421 | */ |
| 422 | public void hold() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 423 | mInCallAdapter.holdCall(mTelecomCallId); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Instructs this {@link #STATE_HOLDING} call to release from hold. |
| 428 | */ |
| 429 | public void unhold() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 430 | mInCallAdapter.unholdCall(mTelecomCallId); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone. |
| 435 | * |
| 436 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 437 | * |
| 438 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 439 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 440 | */ |
| 441 | public void playDtmfTone(char digit) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 442 | mInCallAdapter.playDtmfTone(mTelecomCallId, digit); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone |
| 447 | * currently playing. |
| 448 | * |
| 449 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 450 | * currently playing, this method will do nothing. |
| 451 | */ |
| 452 | public void stopDtmfTone() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 453 | mInCallAdapter.stopDtmfTone(mTelecomCallId); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Instructs this {@code Call} to continue playing a post-dial DTMF string. |
| 458 | * |
| 459 | * A post-dial DTMF string is a string of digits entered after a phone number, when dialed, |
| 460 | * 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] | 461 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 462 | * 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] | 463 | * {@code Call} will temporarily pause playing the tones for a pre-defined period of time. |
| 464 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 465 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 466 | * {@code Call} will pause playing the tones and notify listeners via |
| 467 | * {@link Listener#onPostDialWait(Call, String)}. At this point, the in-call app |
| 468 | * should display to the user an indication of this state and an affordance to continue |
| 469 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 470 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 471 | * |
| 472 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 473 | */ |
| 474 | public void postDialContinue(boolean proceed) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 475 | mInCallAdapter.postDialContinue(mTelecomCallId, proceed); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 479 | * Notifies this {@code Call} that an account has been selected and to proceed with placing |
| 480 | * an outgoing call. |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 481 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 482 | public void phoneAccountSelected(PhoneAccountHandle accountHandle) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 483 | mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle); |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 484 | |
| 485 | } |
| 486 | |
| 487 | /** |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 488 | * Instructs this {@code Call} to enter a conference. |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 489 | * |
| 490 | * @param callToConferenceWith The other call with which to conference. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 491 | */ |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 492 | public void conference(Call callToConferenceWith) { |
| 493 | if (callToConferenceWith != null) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 494 | mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId); |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 495 | } |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Instructs this {@code Call} to split from any conference call with which it may be |
| 500 | * connected. |
| 501 | */ |
| 502 | public void splitFromConference() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 503 | mInCallAdapter.splitFromConference(mTelecomCallId); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /** |
| Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 507 | * Merges the calls within this conference. See {@link PhoneCapabilities#MERGE_CONFERENCE}. |
| 508 | */ |
| 509 | public void mergeConference() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 510 | mInCallAdapter.mergeConference(mTelecomCallId); |
| Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Swaps the calls within this conference. See {@link PhoneCapabilities#SWAP_CONFERENCE}. |
| 515 | */ |
| 516 | public void swapConference() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 517 | mInCallAdapter.swapConference(mTelecomCallId); |
| Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 521 | * Obtains the parent of this {@code Call} in a conference, if any. |
| 522 | * |
| 523 | * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a |
| 524 | * child of any conference {@code Call}s. |
| 525 | */ |
| 526 | public Call getParent() { |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 527 | if (mParentId != null) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 528 | return mPhone.internalGetCallByTelecomId(mParentId); |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 529 | } |
| 530 | return null; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Obtains the children of this conference {@code Call}, if any. |
| 535 | * |
| 536 | * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty |
| 537 | * {@code List} otherwise. |
| 538 | */ |
| 539 | public List<Call> getChildren() { |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 540 | if (!mChildrenCached) { |
| 541 | mChildrenCached = true; |
| 542 | mChildren.clear(); |
| 543 | |
| 544 | for(String id : mChildrenIds) { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 545 | Call call = mPhone.internalGetCallByTelecomId(id); |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 546 | if (call == null) { |
| 547 | // At least one child was still not found, so do not save true for "cached" |
| 548 | mChildrenCached = false; |
| 549 | } else { |
| 550 | mChildren.add(call); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 555 | return mUnmodifiableChildren; |
| 556 | } |
| 557 | |
| 558 | /** |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 559 | * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference. |
| 560 | * |
| 561 | * @return The list of conferenceable {@code Call}s. |
| 562 | */ |
| 563 | public List<Call> getConferenceableCalls() { |
| 564 | return mUnmodifiableConferenceableCalls; |
| 565 | } |
| 566 | |
| 567 | /** |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 568 | * Obtains the state of this {@code Call}. |
| 569 | * |
| 570 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 571 | */ |
| 572 | public int getState() { |
| 573 | return mState; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Obtains a list of canned, pre-configured message responses to present to the user as |
| 578 | * ways of rejecting this {@code Call} using via a text message. |
| 579 | * |
| 580 | * @see #reject(boolean, String) |
| 581 | * |
| 582 | * @return A list of canned text message responses. |
| 583 | */ |
| 584 | public List<String> getCannedTextResponses() { |
| 585 | return mCannedTextResponses; |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Obtains an object that can be used to display video from this {@code Call}. |
| 590 | * |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 591 | * @return An {@code Call.VideoCall}. |
| Tyler Gunn | 75537ae | 2014-08-22 11:33:13 -0700 | [diff] [blame] | 592 | * @hide |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 593 | */ |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 594 | public InCallService.VideoCall getVideoCall() { |
| 595 | return mVideoCall; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /** |
| 599 | * Obtains an object containing call details. |
| 600 | * |
| 601 | * @return A {@link Details} object. Depending on the state of the {@code Call}, the |
| 602 | * result may be {@code null}. |
| 603 | */ |
| 604 | public Details getDetails() { |
| 605 | return mDetails; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Adds a listener to this {@code Call}. |
| 610 | * |
| 611 | * @param listener A {@code Listener}. |
| 612 | */ |
| 613 | public void addListener(Listener listener) { |
| 614 | mListeners.add(listener); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Removes a listener from this {@code Call}. |
| 619 | * |
| 620 | * @param listener A {@code Listener}. |
| 621 | */ |
| 622 | public void removeListener(Listener listener) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 623 | if (listener != null) { |
| 624 | mListeners.remove(listener); |
| 625 | } |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /** {@hide} */ |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 629 | Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) { |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 630 | mPhone = phone; |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 631 | mTelecomCallId = telecomCallId; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 632 | mInCallAdapter = inCallAdapter; |
| 633 | mState = STATE_NEW; |
| 634 | } |
| 635 | |
| 636 | /** {@hide} */ |
| 637 | final String internalGetCallId() { |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 638 | return mTelecomCallId; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /** {@hide} */ |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 642 | final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) { |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 643 | // First, we update the internal state as far as possible before firing any updates. |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 644 | Details details = new Details( |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 645 | parcelableCall.getHandle(), |
| 646 | parcelableCall.getHandlePresentation(), |
| 647 | parcelableCall.getCallerDisplayName(), |
| 648 | parcelableCall.getCallerDisplayNamePresentation(), |
| 649 | parcelableCall.getAccountHandle(), |
| 650 | parcelableCall.getCapabilities(), |
| Andrew Lee | 223ad14 | 2014-08-27 16:33:08 -0700 | [diff] [blame] | 651 | parcelableCall.getProperties(), |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 652 | parcelableCall.getDisconnectCause(), |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 653 | parcelableCall.getConnectTimeMillis(), |
| 654 | parcelableCall.getGatewayInfo(), |
| 655 | parcelableCall.getVideoState(), |
| Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 656 | parcelableCall.getStatusHints(), |
| 657 | parcelableCall.getExtras()); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 658 | boolean detailsChanged = !Objects.equals(mDetails, details); |
| 659 | if (detailsChanged) { |
| 660 | mDetails = details; |
| 661 | } |
| 662 | |
| 663 | boolean cannedTextResponsesChanged = false; |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 664 | if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null |
| 665 | && !parcelableCall.getCannedSmsResponses().isEmpty()) { |
| 666 | mCannedTextResponses = |
| 667 | Collections.unmodifiableList(parcelableCall.getCannedSmsResponses()); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 670 | boolean videoCallChanged = !Objects.equals(mVideoCall, parcelableCall.getVideoCall()); |
| 671 | if (videoCallChanged) { |
| 672 | mVideoCall = parcelableCall.getVideoCall(); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 675 | int state = stateFromParcelableCallState(parcelableCall.getState()); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 676 | boolean stateChanged = mState != state; |
| 677 | if (stateChanged) { |
| 678 | mState = state; |
| 679 | } |
| 680 | |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 681 | String parentId = parcelableCall.getParentCallId(); |
| 682 | boolean parentChanged = !Objects.equals(mParentId, parentId); |
| 683 | if (parentChanged) { |
| 684 | mParentId = parentId; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 687 | List<String> childCallIds = parcelableCall.getChildCallIds(); |
| 688 | boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds); |
| 689 | if (childrenChanged) { |
| 690 | mChildrenIds.clear(); |
| 691 | mChildrenIds.addAll(parcelableCall.getChildCallIds()); |
| 692 | mChildrenCached = false; |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 695 | List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds(); |
| 696 | List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size()); |
| 697 | for (String otherId : conferenceableCallIds) { |
| 698 | if (callIdMap.containsKey(otherId)) { |
| 699 | conferenceableCalls.add(callIdMap.get(otherId)); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) { |
| 704 | mConferenceableCalls.clear(); |
| 705 | mConferenceableCalls.addAll(conferenceableCalls); |
| 706 | fireConferenceableCallsChanged(); |
| 707 | } |
| 708 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 709 | // Now we fire updates, ensuring that any client who listens to any of these notifications |
| 710 | // gets the most up-to-date state. |
| 711 | |
| 712 | if (stateChanged) { |
| 713 | fireStateChanged(mState); |
| 714 | } |
| 715 | if (detailsChanged) { |
| 716 | fireDetailsChanged(mDetails); |
| 717 | } |
| 718 | if (cannedTextResponsesChanged) { |
| 719 | fireCannedTextResponsesLoaded(mCannedTextResponses); |
| 720 | } |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 721 | if (videoCallChanged) { |
| 722 | fireVideoCallChanged(mVideoCall); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 723 | } |
| Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 724 | if (parentChanged) { |
| 725 | fireParentChanged(getParent()); |
| 726 | } |
| 727 | if (childrenChanged) { |
| 728 | fireChildrenChanged(getChildren()); |
| 729 | } |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 730 | |
| 731 | // If we have transitioned to DISCONNECTED, that means we need to notify clients and |
| 732 | // remove ourselves from the Phone. Note that we do this after completing all state updates |
| 733 | // so a client can cleanly transition all their UI to the state appropriate for a |
| 734 | // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list. |
| 735 | if (mState == STATE_DISCONNECTED) { |
| 736 | fireCallDestroyed(); |
| 737 | mPhone.internalRemoveCall(this); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | /** {@hide} */ |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 742 | final void internalSetPostDialWait(String remaining) { |
| 743 | mRemainingPostDialSequence = remaining; |
| 744 | firePostDialWait(mRemainingPostDialSequence); |
| 745 | } |
| 746 | |
| Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 747 | /** {@hide} */ |
| Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 748 | final void internalSetDisconnected() { |
| 749 | if (mState != Call.STATE_DISCONNECTED) { |
| 750 | mState = Call.STATE_DISCONNECTED; |
| 751 | fireStateChanged(mState); |
| 752 | fireCallDestroyed(); |
| 753 | mPhone.internalRemoveCall(this); |
| 754 | } |
| 755 | } |
| 756 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 757 | private void fireStateChanged(int newState) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 758 | for (Listener listener : mListeners) { |
| 759 | listener.onStateChanged(this, newState); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
| 763 | private void fireParentChanged(Call newParent) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 764 | for (Listener listener : mListeners) { |
| 765 | listener.onParentChanged(this, newParent); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
| 769 | private void fireChildrenChanged(List<Call> children) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 770 | for (Listener listener : mListeners) { |
| 771 | listener.onChildrenChanged(this, children); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| 775 | private void fireDetailsChanged(Details details) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 776 | for (Listener listener : mListeners) { |
| 777 | listener.onDetailsChanged(this, details); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | |
| 781 | private void fireCannedTextResponsesLoaded(List<String> cannedTextResponses) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 782 | for (Listener listener : mListeners) { |
| 783 | listener.onCannedTextResponsesLoaded(this, cannedTextResponses); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
| Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 787 | private void fireVideoCallChanged(InCallService.VideoCall videoCall) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 788 | for (Listener listener : mListeners) { |
| 789 | listener.onVideoCallChanged(this, videoCall); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 793 | private void firePostDialWait(String remainingPostDialSequence) { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 794 | for (Listener listener : mListeners) { |
| 795 | listener.onPostDialWait(this, remainingPostDialSequence); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | private void fireCallDestroyed() { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 800 | for (Listener listener : mListeners) { |
| 801 | listener.onCallDestroyed(this); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 805 | private void fireConferenceableCallsChanged() { |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 806 | for (Listener listener : mListeners) { |
| 807 | listener.onConferenceableCallsChanged(this, mUnmodifiableConferenceableCalls); |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 811 | private int stateFromParcelableCallState(int parcelableCallState) { |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 812 | switch (parcelableCallState) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 813 | case CallState.NEW: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 814 | return STATE_NEW; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 815 | case CallState.CONNECTING: |
| Nancy Chen | e20930f | 2014-08-07 16:17:21 -0700 | [diff] [blame] | 816 | return STATE_CONNECTING; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 817 | case CallState.PRE_DIAL_WAIT: |
| Nancy Chen | 5da0fd5 | 2014-07-08 14:16:17 -0700 | [diff] [blame] | 818 | return STATE_PRE_DIAL_WAIT; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 819 | case CallState.DIALING: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 820 | return STATE_DIALING; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 821 | case CallState.RINGING: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 822 | return STATE_RINGING; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 823 | case CallState.ACTIVE: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 824 | return STATE_ACTIVE; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 825 | case CallState.ON_HOLD: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 826 | return STATE_HOLDING; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 827 | case CallState.DISCONNECTED: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 828 | return STATE_DISCONNECTED; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 829 | case CallState.ABORTED: |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 830 | return STATE_DISCONNECTED; |
| 831 | default: |
| Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 832 | Log.wtf(this, "Unrecognized CallState %s", parcelableCallState); |
| Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 833 | return STATE_NEW; |
| 834 | } |
| 835 | } |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 836 | } |