blob: a71161adda373a22bd3ef38eeeb21a7ffff20af1 [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
Nancy Chen513c8922014-09-17 14:47:20 -070083 /**
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 Awade63fadb2014-07-09 21:52:04 -070092 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 Charlton8c8a0622014-07-20 12:31:00 -070097 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -070098 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -070099 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700100 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700101 private final long mConnectTimeMillis;
102 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700103 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700104 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700105 private final Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700106
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 Gunnef9f6f92014-09-12 22:16:17 -0700117 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700118 */
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 Gunnef9f6f92014-09-12 22:16:17 -0700132 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700133 */
134 public int getCallerDisplayNamePresentation() {
135 return mCallerDisplayNamePresentation;
136 }
137
138 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700139 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
140 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700141 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700142 public PhoneAccountHandle getAccountHandle() {
143 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700144 }
145
146 /**
147 * @return A bitmask of the capabilities of the {@code Call}, as defined in
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700148 * {@link PhoneCapabilities}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700149 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700150 public int getCallCapabilities() {
151 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700152 }
153
154 /**
Andrew Lee223ad142014-08-27 16:33:08 -0700155 * @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 Awade63fadb2014-07-09 21:52:04 -0700163 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700164 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700165 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700166 public DisconnectCause getDisconnectCause() {
167 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700168 }
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 Lee7a341382014-07-15 17:05:08 -0700186 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700187 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700188 */
189 public int getVideoState() {
190 return mVideoState;
191 }
192
Ihab Awad5d0410f2014-07-30 10:07:40 -0700193 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700194 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700195 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700196 */
197 public StatusHints getStatusHints() {
198 return mStatusHints;
199 }
200
Nancy Chen10798dc2014-08-08 14:00:25 -0700201 /**
202 * @return A bundle extras to pass with the call
203 */
204 public Bundle getExtras() {
205 return mExtras;
206 }
207
Ihab Awade63fadb2014-07-09 21:52:04 -0700208 @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 Charlton8c8a0622014-07-20 12:31:00 -0700218 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700219 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700220 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700221 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700222 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700223 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700224 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700225 Objects.equals(mStatusHints, d.mStatusHints) &&
226 Objects.equals(mExtras, d.mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700227 }
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 Charlton8c8a0622014-07-20 12:31:00 -0700238 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700239 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700240 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700241 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700242 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700243 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700244 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700245 Objects.hashCode(mStatusHints) +
246 Objects.hashCode(mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700247 }
248
249 /** {@hide} */
250 public Details(
251 Uri handle,
252 int handlePresentation,
253 String callerDisplayName,
254 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700255 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700256 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700257 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700258 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700259 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700260 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700261 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700262 StatusHints statusHints,
263 Bundle extras) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700264 mHandle = handle;
265 mHandlePresentation = handlePresentation;
266 mCallerDisplayName = callerDisplayName;
267 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700268 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700269 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700270 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700271 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700272 mConnectTimeMillis = connectTimeMillis;
273 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700274 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700275 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700276 mExtras = extras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700277 }
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 Awade63fadb2014-07-09 21:52:04 -0700284 * @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 Awade63fadb2014-07-09 21:52:04 -0700324 * 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 Lee50aca232014-07-22 16:41:54 -0700335 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700336 *
337 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700338 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700339 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700340 */
Andrew Lee50aca232014-07-22 16:41:54 -0700341 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700342
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 Cordon7c7bc7f2014-07-28 18:15:48 -0700353
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 Awade63fadb2014-07-09 21:52:04 -0700363 }
364
365 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700366 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700367 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700368 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700369 private final List<Call> mChildren = new ArrayList<>();
370 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Jay Shrauner229e3822014-08-15 09:23:07 -0700371 private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700372 private final List<Call> mConferenceableCalls = new ArrayList<>();
373 private final List<Call> mUnmodifiableConferenceableCalls =
374 Collections.unmodifiableList(mConferenceableCalls);
375
Santos Cordon823fd3c2014-08-07 18:35:18 -0700376 private boolean mChildrenCached;
377 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700378 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700379 private List<String> mCannedTextResponses = null;
380 private String mRemainingPostDialSequence;
Andrew Lee50aca232014-07-22 16:41:54 -0700381 private InCallService.VideoCall mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700382 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700383
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 Lee8da4c3c2014-07-16 10:11:42 -0700396 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700397 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700398 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700399 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700400 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700409 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700410 }
411
412 /**
413 * Instructs this {@code Call} to disconnect.
414 */
415 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700416 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700417 }
418
419 /**
420 * Instructs this {@code Call} to go on hold.
421 */
422 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700423 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700424 }
425
426 /**
427 * Instructs this {@link #STATE_HOLDING} call to release from hold.
428 */
429 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700430 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700431 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700442 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700443 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700453 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700454 }
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 Awade63fadb2014-07-09 21:52:04 -0700461 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700462 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700463 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
464 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700465 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700466 * {@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 Gunnef9f6f92014-09-12 22:16:17 -0700475 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700476 }
477
478 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700479 * Notifies this {@code Call} that an account has been selected and to proceed with placing
480 * an outgoing call.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700481 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700482 public void phoneAccountSelected(PhoneAccountHandle accountHandle) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700483 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700484
485 }
486
487 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700488 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700489 *
490 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700491 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700492 public void conference(Call callToConferenceWith) {
493 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700494 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700495 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700496 }
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 Gunnef9f6f92014-09-12 22:16:17 -0700503 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700504 }
505
506 /**
Santos Cordona4868042014-09-04 17:39:22 -0700507 * Merges the calls within this conference. See {@link PhoneCapabilities#MERGE_CONFERENCE}.
508 */
509 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700510 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700511 }
512
513 /**
514 * Swaps the calls within this conference. See {@link PhoneCapabilities#SWAP_CONFERENCE}.
515 */
516 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700517 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700518 }
519
520 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700521 * 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 Cordon823fd3c2014-08-07 18:35:18 -0700527 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700528 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700529 }
530 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700531 }
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 Cordon823fd3c2014-08-07 18:35:18 -0700540 if (!mChildrenCached) {
541 mChildrenCached = true;
542 mChildren.clear();
543
544 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700545 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700546 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 Awade63fadb2014-07-09 21:52:04 -0700555 return mUnmodifiableChildren;
556 }
557
558 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700559 * 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 Awade63fadb2014-07-09 21:52:04 -0700568 * 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 Lee50aca232014-07-22 16:41:54 -0700591 * @return An {@code Call.VideoCall}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700592 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700593 */
Andrew Lee50aca232014-07-22 16:41:54 -0700594 public InCallService.VideoCall getVideoCall() {
595 return mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700596 }
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 Shrauner229e3822014-08-15 09:23:07 -0700623 if (listener != null) {
624 mListeners.remove(listener);
625 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700626 }
627
628 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700629 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700631 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700632 mInCallAdapter = inCallAdapter;
633 mState = STATE_NEW;
634 }
635
636 /** {@hide} */
637 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700638 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700639 }
640
641 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700642 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700643 // First, we update the internal state as far as possible before firing any updates.
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 Details details = new Details(
Santos Cordon88b771d2014-07-19 13:10:40 -0700645 parcelableCall.getHandle(),
646 parcelableCall.getHandlePresentation(),
647 parcelableCall.getCallerDisplayName(),
648 parcelableCall.getCallerDisplayNamePresentation(),
649 parcelableCall.getAccountHandle(),
650 parcelableCall.getCapabilities(),
Andrew Lee223ad142014-08-27 16:33:08 -0700651 parcelableCall.getProperties(),
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700652 parcelableCall.getDisconnectCause(),
Santos Cordon88b771d2014-07-19 13:10:40 -0700653 parcelableCall.getConnectTimeMillis(),
654 parcelableCall.getGatewayInfo(),
655 parcelableCall.getVideoState(),
Nancy Chen10798dc2014-08-08 14:00:25 -0700656 parcelableCall.getStatusHints(),
657 parcelableCall.getExtras());
Ihab Awade63fadb2014-07-09 21:52:04 -0700658 boolean detailsChanged = !Objects.equals(mDetails, details);
659 if (detailsChanged) {
660 mDetails = details;
661 }
662
663 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -0700664 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
665 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
666 mCannedTextResponses =
667 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Ihab Awade63fadb2014-07-09 21:52:04 -0700668 }
669
Andrew Lee50aca232014-07-22 16:41:54 -0700670 boolean videoCallChanged = !Objects.equals(mVideoCall, parcelableCall.getVideoCall());
671 if (videoCallChanged) {
672 mVideoCall = parcelableCall.getVideoCall();
Ihab Awade63fadb2014-07-09 21:52:04 -0700673 }
674
Santos Cordon88b771d2014-07-19 13:10:40 -0700675 int state = stateFromParcelableCallState(parcelableCall.getState());
Ihab Awade63fadb2014-07-09 21:52:04 -0700676 boolean stateChanged = mState != state;
677 if (stateChanged) {
678 mState = state;
679 }
680
Santos Cordon823fd3c2014-08-07 18:35:18 -0700681 String parentId = parcelableCall.getParentCallId();
682 boolean parentChanged = !Objects.equals(mParentId, parentId);
683 if (parentChanged) {
684 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 }
686
Santos Cordon823fd3c2014-08-07 18:35:18 -0700687 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 Awade63fadb2014-07-09 21:52:04 -0700693 }
694
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700695 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 Awade63fadb2014-07-09 21:52:04 -0700709 // 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 Lee50aca232014-07-22 16:41:54 -0700721 if (videoCallChanged) {
722 fireVideoCallChanged(mVideoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -0700723 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700724 if (parentChanged) {
725 fireParentChanged(getParent());
726 }
727 if (childrenChanged) {
728 fireChildrenChanged(getChildren());
729 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700730
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 Awade63fadb2014-07-09 21:52:04 -0700742 final void internalSetPostDialWait(String remaining) {
743 mRemainingPostDialSequence = remaining;
744 firePostDialWait(mRemainingPostDialSequence);
745 }
746
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700747 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -0700748 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 Awade63fadb2014-07-09 21:52:04 -0700757 private void fireStateChanged(int newState) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700758 for (Listener listener : mListeners) {
759 listener.onStateChanged(this, newState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700760 }
761 }
762
763 private void fireParentChanged(Call newParent) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700764 for (Listener listener : mListeners) {
765 listener.onParentChanged(this, newParent);
Ihab Awade63fadb2014-07-09 21:52:04 -0700766 }
767 }
768
769 private void fireChildrenChanged(List<Call> children) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700770 for (Listener listener : mListeners) {
771 listener.onChildrenChanged(this, children);
Ihab Awade63fadb2014-07-09 21:52:04 -0700772 }
773 }
774
775 private void fireDetailsChanged(Details details) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700776 for (Listener listener : mListeners) {
777 listener.onDetailsChanged(this, details);
Ihab Awade63fadb2014-07-09 21:52:04 -0700778 }
779 }
780
781 private void fireCannedTextResponsesLoaded(List<String> cannedTextResponses) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700782 for (Listener listener : mListeners) {
783 listener.onCannedTextResponsesLoaded(this, cannedTextResponses);
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 }
785 }
786
Andrew Lee50aca232014-07-22 16:41:54 -0700787 private void fireVideoCallChanged(InCallService.VideoCall videoCall) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700788 for (Listener listener : mListeners) {
789 listener.onVideoCallChanged(this, videoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -0700790 }
791 }
792
Ihab Awade63fadb2014-07-09 21:52:04 -0700793 private void firePostDialWait(String remainingPostDialSequence) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700794 for (Listener listener : mListeners) {
795 listener.onPostDialWait(this, remainingPostDialSequence);
Ihab Awade63fadb2014-07-09 21:52:04 -0700796 }
797 }
798
799 private void fireCallDestroyed() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700800 for (Listener listener : mListeners) {
801 listener.onCallDestroyed(this);
Ihab Awade63fadb2014-07-09 21:52:04 -0700802 }
803 }
804
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700805 private void fireConferenceableCallsChanged() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700806 for (Listener listener : mListeners) {
807 listener.onConferenceableCallsChanged(this, mUnmodifiableConferenceableCalls);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700808 }
809 }
810
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700811 private int stateFromParcelableCallState(int parcelableCallState) {
Santos Cordon88b771d2014-07-19 13:10:40 -0700812 switch (parcelableCallState) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700813 case CallState.NEW:
Ihab Awade63fadb2014-07-09 21:52:04 -0700814 return STATE_NEW;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700815 case CallState.CONNECTING:
Nancy Chene20930f2014-08-07 16:17:21 -0700816 return STATE_CONNECTING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700817 case CallState.PRE_DIAL_WAIT:
Nancy Chen5da0fd52014-07-08 14:16:17 -0700818 return STATE_PRE_DIAL_WAIT;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819 case CallState.DIALING:
Ihab Awade63fadb2014-07-09 21:52:04 -0700820 return STATE_DIALING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 case CallState.RINGING:
Ihab Awade63fadb2014-07-09 21:52:04 -0700822 return STATE_RINGING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700823 case CallState.ACTIVE:
Ihab Awade63fadb2014-07-09 21:52:04 -0700824 return STATE_ACTIVE;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700825 case CallState.ON_HOLD:
Ihab Awade63fadb2014-07-09 21:52:04 -0700826 return STATE_HOLDING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700827 case CallState.DISCONNECTED:
Ihab Awade63fadb2014-07-09 21:52:04 -0700828 return STATE_DISCONNECTED;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 case CallState.ABORTED:
Ihab Awade63fadb2014-07-09 21:52:04 -0700830 return STATE_DISCONNECTED;
831 default:
Santos Cordon88b771d2014-07-19 13:10:40 -0700832 Log.wtf(this, "Unrecognized CallState %s", parcelableCallState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700833 return STATE_NEW;
834 }
835 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700836}