blob: 1a6c52f7cd9cddf191250c7d2c6f20b4248754da [file] [log] [blame]
Ihab Awade63fadb2014-07-09 21:52:04 -07001/*
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 Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awade63fadb2014-07-09 21:52:04 -070018
Gabriel Pealb95f1692014-08-19 14:24:18 -070019import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070020import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070021import android.os.Bundle;
Ihab Awade63fadb2014-07-09 21:52:04 -070022
Andrew Lee50aca232014-07-22 16:41:54 -070023import java.lang.String;
Ihab Awade63fadb2014-07-09 21:52:04 -070024import java.util.ArrayList;
25import java.util.Collections;
26import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070027import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070028import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070029import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070030
31/**
32 * Represents an ongoing phone call that the in-call app should present to the user.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033 *
34 * {@hide}
Ihab Awade63fadb2014-07-09 21:52:04 -070035 */
Gabriel Pealb95f1692014-08-19 14:24:18 -070036@SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -070037public 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 Chen5da0fd52014-07-08 14:16:17 -070071 /**
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 Chene20930f2014-08-07 16:17:21 -070076 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070077 * 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 Chene20930f2014-08-07 16:17:21 -070080 */
81 public static final int STATE_CONNECTING = 9;
82
Ihab Awade63fadb2014-07-09 21:52:04 -070083 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 Charlton8c8a0622014-07-20 12:31:00 -070088 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -070089 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -070090 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070091 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -070092 private final long mConnectTimeMillis;
93 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -070094 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -070095 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -070096 private final Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -070097
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 Gunnef9f6f92014-09-12 22:16:17 -0700108 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700109 */
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 Gunnef9f6f92014-09-12 22:16:17 -0700123 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700124 */
125 public int getCallerDisplayNamePresentation() {
126 return mCallerDisplayNamePresentation;
127 }
128
129 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700130 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
131 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700132 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700133 public PhoneAccountHandle getAccountHandle() {
134 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700135 }
136
137 /**
138 * @return A bitmask of the capabilities of the {@code Call}, as defined in
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 * {@link PhoneCapabilities}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700140 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700141 public int getCallCapabilities() {
142 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700143 }
144
145 /**
Andrew Lee223ad142014-08-27 16:33:08 -0700146 * @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 Awade63fadb2014-07-09 21:52:04 -0700154 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700155 * by {@link android.telecomm.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700156 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700157 public DisconnectCause getDisconnectCause() {
158 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700159 }
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 Lee7a341382014-07-15 17:05:08 -0700177 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700178 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700179 */
180 public int getVideoState() {
181 return mVideoState;
182 }
183
Ihab Awad5d0410f2014-07-30 10:07:40 -0700184 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700185 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700186 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700187 */
188 public StatusHints getStatusHints() {
189 return mStatusHints;
190 }
191
Nancy Chen10798dc2014-08-08 14:00:25 -0700192 /**
193 * @return A bundle extras to pass with the call
194 */
195 public Bundle getExtras() {
196 return mExtras;
197 }
198
Ihab Awade63fadb2014-07-09 21:52:04 -0700199 @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 Charlton8c8a0622014-07-20 12:31:00 -0700209 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700210 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700211 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700212 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700213 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700214 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700215 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700216 Objects.equals(mStatusHints, d.mStatusHints) &&
217 Objects.equals(mExtras, d.mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700218 }
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 Charlton8c8a0622014-07-20 12:31:00 -0700229 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700230 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700231 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700232 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700233 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700234 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700235 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700236 Objects.hashCode(mStatusHints) +
237 Objects.hashCode(mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700238 }
239
240 /** {@hide} */
241 public Details(
242 Uri handle,
243 int handlePresentation,
244 String callerDisplayName,
245 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700246 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700247 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700248 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700249 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700250 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700251 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700252 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700253 StatusHints statusHints,
254 Bundle extras) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700255 mHandle = handle;
256 mHandlePresentation = handlePresentation;
257 mCallerDisplayName = callerDisplayName;
258 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700259 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700260 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700261 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700262 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700263 mConnectTimeMillis = connectTimeMillis;
264 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700265 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700266 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700267 mExtras = extras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700268 }
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 Awade63fadb2014-07-09 21:52:04 -0700275 * @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 Awade63fadb2014-07-09 21:52:04 -0700315 * 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 Lee50aca232014-07-22 16:41:54 -0700326 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700327 *
328 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700329 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700330 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700331 */
Andrew Lee50aca232014-07-22 16:41:54 -0700332 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700333
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 Cordon7c7bc7f2014-07-28 18:15:48 -0700344
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 Awade63fadb2014-07-09 21:52:04 -0700354 }
355
356 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700357 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700358 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700359 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700360 private final List<Call> mChildren = new ArrayList<>();
361 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Jay Shrauner229e3822014-08-15 09:23:07 -0700362 private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700363 private final List<Call> mConferenceableCalls = new ArrayList<>();
364 private final List<Call> mUnmodifiableConferenceableCalls =
365 Collections.unmodifiableList(mConferenceableCalls);
366
Santos Cordon823fd3c2014-08-07 18:35:18 -0700367 private boolean mChildrenCached;
368 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700369 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700370 private List<String> mCannedTextResponses = null;
371 private String mRemainingPostDialSequence;
Andrew Lee50aca232014-07-22 16:41:54 -0700372 private InCallService.VideoCall mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700373 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700374
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 Lee8da4c3c2014-07-16 10:11:42 -0700387 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700388 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700389 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700390 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700391 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700400 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700401 }
402
403 /**
404 * Instructs this {@code Call} to disconnect.
405 */
406 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700407 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700408 }
409
410 /**
411 * Instructs this {@code Call} to go on hold.
412 */
413 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700414 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700415 }
416
417 /**
418 * Instructs this {@link #STATE_HOLDING} call to release from hold.
419 */
420 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700421 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700422 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700433 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700434 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700444 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700445 }
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 Awade63fadb2014-07-09 21:52:04 -0700452 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700453 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700454 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
455 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700456 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700457 * {@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 Gunnef9f6f92014-09-12 22:16:17 -0700466 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700467 }
468
469 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700470 * Notifies this {@code Call} that an account has been selected and to proceed with placing
471 * an outgoing call.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700472 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700473 public void phoneAccountSelected(PhoneAccountHandle accountHandle) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700474 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700475
476 }
477
478 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700479 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700480 *
481 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700482 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700483 public void conference(Call callToConferenceWith) {
484 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700485 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700486 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700487 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700494 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700495 }
496
497 /**
Santos Cordona4868042014-09-04 17:39:22 -0700498 * Merges the calls within this conference. See {@link PhoneCapabilities#MERGE_CONFERENCE}.
499 */
500 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700501 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700502 }
503
504 /**
505 * Swaps the calls within this conference. See {@link PhoneCapabilities#SWAP_CONFERENCE}.
506 */
507 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700508 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700509 }
510
511 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700512 * 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 Cordon823fd3c2014-08-07 18:35:18 -0700518 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700519 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700520 }
521 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700522 }
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 Cordon823fd3c2014-08-07 18:35:18 -0700531 if (!mChildrenCached) {
532 mChildrenCached = true;
533 mChildren.clear();
534
535 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700536 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700537 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 Awade63fadb2014-07-09 21:52:04 -0700546 return mUnmodifiableChildren;
547 }
548
549 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700550 * 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 Awade63fadb2014-07-09 21:52:04 -0700559 * 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 Lee50aca232014-07-22 16:41:54 -0700582 * @return An {@code Call.VideoCall}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700583 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700584 */
Andrew Lee50aca232014-07-22 16:41:54 -0700585 public InCallService.VideoCall getVideoCall() {
586 return mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700587 }
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 Shrauner229e3822014-08-15 09:23:07 -0700614 if (listener != null) {
615 mListeners.remove(listener);
616 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700617 }
618
619 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700620 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700621 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700622 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700623 mInCallAdapter = inCallAdapter;
624 mState = STATE_NEW;
625 }
626
627 /** {@hide} */
628 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 }
631
632 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700633 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700634 // First, we update the internal state as far as possible before firing any updates.
Ihab Awade63fadb2014-07-09 21:52:04 -0700635 Details details = new Details(
Santos Cordon88b771d2014-07-19 13:10:40 -0700636 parcelableCall.getHandle(),
637 parcelableCall.getHandlePresentation(),
638 parcelableCall.getCallerDisplayName(),
639 parcelableCall.getCallerDisplayNamePresentation(),
640 parcelableCall.getAccountHandle(),
641 parcelableCall.getCapabilities(),
Andrew Lee223ad142014-08-27 16:33:08 -0700642 parcelableCall.getProperties(),
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700643 parcelableCall.getDisconnectCause(),
Santos Cordon88b771d2014-07-19 13:10:40 -0700644 parcelableCall.getConnectTimeMillis(),
645 parcelableCall.getGatewayInfo(),
646 parcelableCall.getVideoState(),
Nancy Chen10798dc2014-08-08 14:00:25 -0700647 parcelableCall.getStatusHints(),
648 parcelableCall.getExtras());
Ihab Awade63fadb2014-07-09 21:52:04 -0700649 boolean detailsChanged = !Objects.equals(mDetails, details);
650 if (detailsChanged) {
651 mDetails = details;
652 }
653
654 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -0700655 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
656 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
657 mCannedTextResponses =
658 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Ihab Awade63fadb2014-07-09 21:52:04 -0700659 }
660
Andrew Lee50aca232014-07-22 16:41:54 -0700661 boolean videoCallChanged = !Objects.equals(mVideoCall, parcelableCall.getVideoCall());
662 if (videoCallChanged) {
663 mVideoCall = parcelableCall.getVideoCall();
Ihab Awade63fadb2014-07-09 21:52:04 -0700664 }
665
Santos Cordon88b771d2014-07-19 13:10:40 -0700666 int state = stateFromParcelableCallState(parcelableCall.getState());
Ihab Awade63fadb2014-07-09 21:52:04 -0700667 boolean stateChanged = mState != state;
668 if (stateChanged) {
669 mState = state;
670 }
671
Santos Cordon823fd3c2014-08-07 18:35:18 -0700672 String parentId = parcelableCall.getParentCallId();
673 boolean parentChanged = !Objects.equals(mParentId, parentId);
674 if (parentChanged) {
675 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700676 }
677
Santos Cordon823fd3c2014-08-07 18:35:18 -0700678 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 Awade63fadb2014-07-09 21:52:04 -0700684 }
685
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700686 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 Awade63fadb2014-07-09 21:52:04 -0700700 // 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 Lee50aca232014-07-22 16:41:54 -0700712 if (videoCallChanged) {
713 fireVideoCallChanged(mVideoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -0700714 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700715 if (parentChanged) {
716 fireParentChanged(getParent());
717 }
718 if (childrenChanged) {
719 fireChildrenChanged(getChildren());
720 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700721
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 Awade63fadb2014-07-09 21:52:04 -0700733 final void internalSetPostDialWait(String remaining) {
734 mRemainingPostDialSequence = remaining;
735 firePostDialWait(mRemainingPostDialSequence);
736 }
737
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700738 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -0700739 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 Awade63fadb2014-07-09 21:52:04 -0700748 private void fireStateChanged(int newState) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700749 for (Listener listener : mListeners) {
750 listener.onStateChanged(this, newState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700751 }
752 }
753
754 private void fireParentChanged(Call newParent) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700755 for (Listener listener : mListeners) {
756 listener.onParentChanged(this, newParent);
Ihab Awade63fadb2014-07-09 21:52:04 -0700757 }
758 }
759
760 private void fireChildrenChanged(List<Call> children) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700761 for (Listener listener : mListeners) {
762 listener.onChildrenChanged(this, children);
Ihab Awade63fadb2014-07-09 21:52:04 -0700763 }
764 }
765
766 private void fireDetailsChanged(Details details) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700767 for (Listener listener : mListeners) {
768 listener.onDetailsChanged(this, details);
Ihab Awade63fadb2014-07-09 21:52:04 -0700769 }
770 }
771
772 private void fireCannedTextResponsesLoaded(List<String> cannedTextResponses) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700773 for (Listener listener : mListeners) {
774 listener.onCannedTextResponsesLoaded(this, cannedTextResponses);
Ihab Awade63fadb2014-07-09 21:52:04 -0700775 }
776 }
777
Andrew Lee50aca232014-07-22 16:41:54 -0700778 private void fireVideoCallChanged(InCallService.VideoCall videoCall) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700779 for (Listener listener : mListeners) {
780 listener.onVideoCallChanged(this, videoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -0700781 }
782 }
783
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 private void firePostDialWait(String remainingPostDialSequence) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700785 for (Listener listener : mListeners) {
786 listener.onPostDialWait(this, remainingPostDialSequence);
Ihab Awade63fadb2014-07-09 21:52:04 -0700787 }
788 }
789
790 private void fireCallDestroyed() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700791 for (Listener listener : mListeners) {
792 listener.onCallDestroyed(this);
Ihab Awade63fadb2014-07-09 21:52:04 -0700793 }
794 }
795
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700796 private void fireConferenceableCallsChanged() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700797 for (Listener listener : mListeners) {
798 listener.onConferenceableCallsChanged(this, mUnmodifiableConferenceableCalls);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700799 }
800 }
801
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700802 private int stateFromParcelableCallState(int parcelableCallState) {
Santos Cordon88b771d2014-07-19 13:10:40 -0700803 switch (parcelableCallState) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700804 case CallState.NEW:
Ihab Awade63fadb2014-07-09 21:52:04 -0700805 return STATE_NEW;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 case CallState.CONNECTING:
Nancy Chene20930f2014-08-07 16:17:21 -0700807 return STATE_CONNECTING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 case CallState.PRE_DIAL_WAIT:
Nancy Chen5da0fd52014-07-08 14:16:17 -0700809 return STATE_PRE_DIAL_WAIT;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700810 case CallState.DIALING:
Ihab Awade63fadb2014-07-09 21:52:04 -0700811 return STATE_DIALING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 case CallState.RINGING:
Ihab Awade63fadb2014-07-09 21:52:04 -0700813 return STATE_RINGING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 case CallState.ACTIVE:
Ihab Awade63fadb2014-07-09 21:52:04 -0700815 return STATE_ACTIVE;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 case CallState.ON_HOLD:
Ihab Awade63fadb2014-07-09 21:52:04 -0700817 return STATE_HOLDING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700818 case CallState.DISCONNECTED:
Ihab Awade63fadb2014-07-09 21:52:04 -0700819 return STATE_DISCONNECTED;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 case CallState.ABORTED:
Ihab Awade63fadb2014-07-09 21:52:04 -0700821 return STATE_DISCONNECTED;
822 default:
Santos Cordon88b771d2014-07-19 13:10:40 -0700823 Log.wtf(this, "Unrecognized CallState %s", parcelableCallState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 return STATE_NEW;
825 }
826 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700827}