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