blob: fa7a59d76f09c995368070f95f72b7b8ddbf207e [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -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 Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Santos Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.os.Handler;
29import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070030import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Message;
32import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
Santos Cordonb6939982014-06-04 20:20:58 -070035import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070038import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070039import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040
41/**
Santos Cordon895d4b82015-06-25 16:41:48 -070042 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
43 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070044 * <p>
45 * Implementations create a custom subclass of {@code Connection} and return it to the framework
46 * as the return value of
47 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
48 * or
49 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
50 * Implementations are then responsible for updating the state of the {@code Connection}, and
51 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
52 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070053 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070054public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
Santos Cordon895d4b82015-06-25 16:41:48 -070056 /**
57 * The connection is initializing. This is generally the first state for a {@code Connection}
58 * returned by a {@link ConnectionService}.
59 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 public static final int STATE_INITIALIZING = 0;
61
Santos Cordon895d4b82015-06-25 16:41:48 -070062 /**
63 * The connection is new and not connected.
64 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 public static final int STATE_NEW = 1;
66
Santos Cordon895d4b82015-06-25 16:41:48 -070067 /**
68 * An incoming connection is in the ringing state. During this state, the user's ringer or
69 * vibration feature will be activated.
70 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public static final int STATE_RINGING = 2;
72
Santos Cordon895d4b82015-06-25 16:41:48 -070073 /**
74 * An outgoing connection is in the dialing state. In this state the other party has not yet
75 * answered the call and the user traditionally hears a ringback tone.
76 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 public static final int STATE_DIALING = 3;
78
Santos Cordon895d4b82015-06-25 16:41:48 -070079 /**
80 * A connection is active. Both parties are connected to the call and can actively communicate.
81 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 public static final int STATE_ACTIVE = 4;
83
Santos Cordon895d4b82015-06-25 16:41:48 -070084 /**
85 * A connection is on hold.
86 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070087 public static final int STATE_HOLDING = 5;
88
Santos Cordon895d4b82015-06-25 16:41:48 -070089 /**
90 * A connection has been disconnected. This is the final state once the user has been
91 * disconnected from a call either locally, remotely or by an error in the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 public static final int STATE_DISCONNECTED = 6;
94
Santos Cordon895d4b82015-06-25 16:41:48 -070095 /**
96 * Connection can currently be put on hold or unheld. This is distinct from
97 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
98 * it does not at the moment support the function. This can be true while the call is in the
99 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
100 * display a disabled 'hold' button.
101 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800102 public static final int CAPABILITY_HOLD = 0x00000001;
103
104 /** Connection supports the hold feature. */
105 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
106
107 /**
108 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
109 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
110 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
111 * capability allows a merge button to be shown while the conference is in the foreground
112 * of the in-call UI.
113 * <p>
114 * This is only intended for use by a {@link Conference}.
115 */
116 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
117
118 /**
119 * Connections within a conference can be swapped between foreground and background.
120 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
121 * <p>
122 * This is only intended for use by a {@link Conference}.
123 */
124 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
125
126 /**
127 * @hide
128 */
129 public static final int CAPABILITY_UNUSED = 0x00000010;
130
131 /** Connection supports responding via text option. */
132 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
133
134 /** Connection can be muted. */
135 public static final int CAPABILITY_MUTE = 0x00000040;
136
137 /**
138 * Connection supports conference management. This capability only applies to
139 * {@link Conference}s which can have {@link Connection}s as children.
140 */
141 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
142
143 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700144 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700146 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800147
148 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700149 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700151 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152
153 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700154 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700156 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
163
164 /**
165 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 */
167 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
168
169 /**
170 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700172 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174
175 /**
176 * Connection is able to be separated from its parent {@code Conference}, if any.
177 */
178 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
179
180 /**
181 * Connection is able to be individually disconnected when in a {@code Conference}.
182 */
183 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
184
185 /**
186 * Whether the call is a generic conference, where we do not know the precise state of
187 * participants in the conference (eg. on CDMA).
188 *
189 * @hide
190 */
191 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
192
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700193 /**
194 * Connection is using high definition audio.
195 * @hide
196 */
197 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
198
199 /**
200 * Connection is using WIFI.
201 * @hide
202 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700203 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204
Tyler Gunn068085b2015-02-06 13:56:52 -0800205 /**
206 * Indicates that the current device callback number should be shown.
207 *
208 * @hide
209 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700210 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800211
Tyler Gunn96d6c402015-03-18 12:39:23 -0700212 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500213 * Speed up audio setup for MT call.
214 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700215 */
216 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800217
Rekha Kumar07366812015-03-24 16:42:31 -0700218 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700220 */
221 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
222
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700223 /**
224 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700225 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700226 */
227 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
228
Tyler Gunnd4091732015-06-29 09:15:37 -0700229 /**
230 * For a conference, indicates the conference will not have child connections.
231 * <p>
232 * An example of a conference with child connections is a GSM conference call, where the radio
233 * retains connections to the individual participants of the conference. Another example is an
234 * IMS conference call where conference event package functionality is supported; in this case
235 * the conference server ensures the radio is aware of the participants in the conference, which
236 * are represented by child connections.
237 * <p>
238 * An example of a conference with no child connections is an IMS conference call with no
239 * conference event package support. Such a conference is represented by the radio as a single
240 * connection to the IMS conference server.
241 * <p>
242 * Indicating whether a conference has children or not is important to help user interfaces
243 * visually represent a conference. A conference with no children, for example, will have the
244 * conference connection shown in the list of calls on a Bluetooth device, where if the
245 * conference has children, only the children will be shown in the list of calls on a Bluetooth
246 * device.
247 * @hide
248 */
249 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
250
Bryce Lee81901682015-08-28 16:38:02 -0700251 /**
252 * Indicates that the connection itself wants to handle any sort of reply response, rather than
253 * relying on SMS.
254 * @hide
255 */
256 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
257
Tyler Gunnf97a0092016-01-19 15:59:34 -0800258 /**
259 * When set, prevents a video call from being downgraded to an audio-only call.
260 * <p>
261 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
262 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
263 * downgraded from a video call back to a VideoState of
264 * {@link VideoProfile#STATE_AUDIO_ONLY}.
265 * <p>
266 * Intuitively, a call which can be downgraded to audio should also have local and remote
267 * video
268 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
269 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
270 */
271 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
272
Tyler Gunn96d6c402015-03-18 12:39:23 -0700273 //**********************************************************************************************
Tyler Gunnf97a0092016-01-19 15:59:34 -0800274 // Next CAPABILITY value: 0x01000000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700275 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800276
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700277 /**
278 * Connection extra key used to store the last forwarded number associated with the current
279 * connection. Used to communicate to the user interface that the connection was forwarded via
280 * the specified number.
281 */
282 public static final String EXTRA_LAST_FORWARDED_NUMBER =
283 "android.telecom.extra.LAST_FORWARDED_NUMBER";
284
285 /**
286 * Connection extra key used to store a child number associated with the current connection.
287 * Used to communicate to the user interface that the connection was received via
288 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
289 * address.
290 */
291 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
292
293 /**
294 * Connection extra key used to store the subject for an incoming call. The user interface can
295 * query this extra and display its contents for incoming calls. Will only be used if the
296 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
297 */
298 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
299
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700300 // Flag controlling whether PII is emitted into the logs
301 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
302
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800303 /**
304 * Whether the given capabilities support the specified capability.
305 *
306 * @param capabilities A capability bit field.
307 * @param capability The capability to check capabilities for.
308 * @return Whether the specified capability is supported.
309 * @hide
310 */
311 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800312 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800313 }
314
315 /**
316 * Whether the capabilities of this {@code Connection} supports the specified capability.
317 *
318 * @param capability The capability to check capabilities for.
319 * @return Whether the specified capability is supported.
320 * @hide
321 */
322 public boolean can(int capability) {
323 return can(mConnectionCapabilities, capability);
324 }
325
326 /**
327 * Removes the specified capability from the set of capabilities of this {@code Connection}.
328 *
329 * @param capability The capability to remove from the set.
330 * @hide
331 */
332 public void removeCapability(int capability) {
333 mConnectionCapabilities &= ~capability;
334 }
335
336 /**
337 * Adds the specified capability to the set of capabilities of this {@code Connection}.
338 *
339 * @param capability The capability to add to the set.
340 * @hide
341 */
342 public void addCapability(int capability) {
343 mConnectionCapabilities |= capability;
344 }
345
346
347 public static String capabilitiesToString(int capabilities) {
348 StringBuilder builder = new StringBuilder();
349 builder.append("[Capabilities:");
350 if (can(capabilities, CAPABILITY_HOLD)) {
351 builder.append(" CAPABILITY_HOLD");
352 }
353 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
354 builder.append(" CAPABILITY_SUPPORT_HOLD");
355 }
356 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
357 builder.append(" CAPABILITY_MERGE_CONFERENCE");
358 }
359 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
360 builder.append(" CAPABILITY_SWAP_CONFERENCE");
361 }
362 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
363 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
364 }
365 if (can(capabilities, CAPABILITY_MUTE)) {
366 builder.append(" CAPABILITY_MUTE");
367 }
368 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
369 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
370 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700371 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
372 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
373 }
374 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
375 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
376 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700377 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
378 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800379 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700380 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
381 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
382 }
383 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
384 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
385 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700386 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
387 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800388 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800389 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
390 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
391 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800392 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
393 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800394 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800395 if (can(capabilities, CAPABILITY_WIFI)) {
396 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800397 }
398 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
399 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
400 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800401 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
402 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
403 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500404 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700405 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500406 }
Rekha Kumar07366812015-03-24 16:42:31 -0700407 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
408 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
409 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700410 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
411 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
412 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700413 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
414 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
415 }
Bryce Lee81901682015-08-28 16:38:02 -0700416 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
417 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
418 }
419
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 builder.append("]");
421 return builder.toString();
422 }
423
Sailesh Nepal091768c2014-06-30 15:15:23 -0700424 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700425 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700426 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700427 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700428 public void onCallerDisplayNameChanged(
429 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700430 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700431 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700432 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800433 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700434 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700435 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800436 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700437 public void onVideoProviderChanged(
438 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700439 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
440 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800441 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700442 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700443 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700444 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800445 public void onConferenceParticipantsChanged(Connection c,
446 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800447 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700448 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700449 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700450 }
451
Tyler Gunnb702ef82015-05-29 11:51:53 -0700452 /**
453 * Provides a means of controlling the video session associated with a {@link Connection}.
454 * <p>
455 * Implementations create a custom subclass of {@link VideoProvider} and the
456 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
457 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
458 * should set the {@link VideoProvider}.
459 * <p>
460 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
461 * {@link InCallService} implementations to issue requests related to the video session;
462 * it provides a means for the {@link ConnectionService} to report events and information
463 * related to the video session to Telecom and the {@link InCallService} implementations.
464 * <p>
465 * {@link InCallService} implementations interact with the {@link VideoProvider} via
466 * {@link android.telecom.InCallService.VideoCall}.
467 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700468 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700469
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700470 /**
471 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700472 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700473 */
474 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700475
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700476 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700477 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
478 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700479 */
480 public static final int SESSION_EVENT_RX_RESUME = 2;
481
482 /**
483 * Video transmission has begun. This occurs after a negotiated start of video transmission
484 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700485 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700486 */
487 public static final int SESSION_EVENT_TX_START = 3;
488
489 /**
490 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
491 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700492 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700493 */
494 public static final int SESSION_EVENT_TX_STOP = 4;
495
496 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700497 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
498 * this as a cue to inform the user the camera is not available.
499 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700500 */
501 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
502
503 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700504 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
505 * for operation. The {@link InCallService} can use this as a cue to inform the user that
506 * the camera has become available again.
507 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700508 */
509 public static final int SESSION_EVENT_CAMERA_READY = 6;
510
511 /**
512 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700513 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700514 */
515 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
516
517 /**
518 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700519 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 */
521 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
522
523 /**
524 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700525 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 */
527 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
528
Rekha Kumar07366812015-03-24 16:42:31 -0700529 /**
530 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700531 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700532 */
533 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
534
535 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700536 * Session modify request rejected by remote user.
537 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700538 */
539 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
540
Tyler Gunn75958422015-04-15 14:23:42 -0700541 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700542 private static final int MSG_SET_CAMERA = 2;
543 private static final int MSG_SET_PREVIEW_SURFACE = 3;
544 private static final int MSG_SET_DISPLAY_SURFACE = 4;
545 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
546 private static final int MSG_SET_ZOOM = 6;
547 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
548 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
549 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700552 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700553
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700554 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700556
557 /**
558 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700559 *
560 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
561 * load factor before resizing, 1 means we only expect a single thread to
562 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700563 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700564 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
565 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566
567 /**
568 * Default handler used to consolidate binder method calls onto a single thread.
569 */
570 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700571 public VideoProviderHandler() {
572 super();
573 }
574
575 public VideoProviderHandler(Looper looper) {
576 super(looper);
577 }
578
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700579 @Override
580 public void handleMessage(Message msg) {
581 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700582 case MSG_ADD_VIDEO_CALLBACK: {
583 IBinder binder = (IBinder) msg.obj;
584 IVideoCallback callback = IVideoCallback.Stub
585 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700586 if (callback == null) {
587 Log.w(this, "addVideoProvider - skipped; callback is null.");
588 break;
589 }
590
Tyler Gunn75958422015-04-15 14:23:42 -0700591 if (mVideoCallbacks.containsKey(binder)) {
592 Log.i(this, "addVideoProvider - skipped; already present.");
593 break;
594 }
595 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700596 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700597 }
598 case MSG_REMOVE_VIDEO_CALLBACK: {
599 IBinder binder = (IBinder) msg.obj;
600 IVideoCallback callback = IVideoCallback.Stub
601 .asInterface((IBinder) msg.obj);
602 if (!mVideoCallbacks.containsKey(binder)) {
603 Log.i(this, "removeVideoProvider - skipped; not present.");
604 break;
605 }
606 mVideoCallbacks.remove(binder);
607 break;
608 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 case MSG_SET_CAMERA:
610 onSetCamera((String) msg.obj);
611 break;
612 case MSG_SET_PREVIEW_SURFACE:
613 onSetPreviewSurface((Surface) msg.obj);
614 break;
615 case MSG_SET_DISPLAY_SURFACE:
616 onSetDisplaySurface((Surface) msg.obj);
617 break;
618 case MSG_SET_DEVICE_ORIENTATION:
619 onSetDeviceOrientation(msg.arg1);
620 break;
621 case MSG_SET_ZOOM:
622 onSetZoom((Float) msg.obj);
623 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700624 case MSG_SEND_SESSION_MODIFY_REQUEST: {
625 SomeArgs args = (SomeArgs) msg.obj;
626 try {
627 onSendSessionModifyRequest((VideoProfile) args.arg1,
628 (VideoProfile) args.arg2);
629 } finally {
630 args.recycle();
631 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700633 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 case MSG_SEND_SESSION_MODIFY_RESPONSE:
635 onSendSessionModifyResponse((VideoProfile) msg.obj);
636 break;
637 case MSG_REQUEST_CAMERA_CAPABILITIES:
638 onRequestCameraCapabilities();
639 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 case MSG_REQUEST_CONNECTION_DATA_USAGE:
641 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 break;
643 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700644 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700645 break;
646 default:
647 break;
648 }
649 }
650 }
651
652 /**
653 * IVideoProvider stub implementation.
654 */
655 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700656 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700658 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
659 }
660
661 public void removeVideoCallback(IBinder videoCallbackBinder) {
662 mMessageHandler.obtainMessage(
663 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 }
665
666 public void setCamera(String cameraId) {
667 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
668 }
669
670 public void setPreviewSurface(Surface surface) {
671 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
672 }
673
674 public void setDisplaySurface(Surface surface) {
675 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
676 }
677
678 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700679 mMessageHandler.obtainMessage(
680 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700681 }
682
683 public void setZoom(float value) {
684 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
685 }
686
Tyler Gunn45382162015-05-06 08:52:27 -0700687 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
688 SomeArgs args = SomeArgs.obtain();
689 args.arg1 = fromProfile;
690 args.arg2 = toProfile;
691 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692 }
693
694 public void sendSessionModifyResponse(VideoProfile responseProfile) {
695 mMessageHandler.obtainMessage(
696 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
697 }
698
699 public void requestCameraCapabilities() {
700 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
701 }
702
703 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800704 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 }
706
Yorke Lee32f24732015-05-12 16:18:03 -0700707 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700708 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
709 }
710 }
711
712 public VideoProvider() {
713 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700714 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700715 }
716
717 /**
718 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
719 *
720 * @param looper The looper.
721 * @hide
722 */
723 public VideoProvider(Looper looper) {
724 mBinder = new VideoProvider.VideoProviderBinder();
725 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 }
727
728 /**
729 * Returns binder object which can be used across IPC methods.
730 * @hide
731 */
732 public final IVideoProvider getInterface() {
733 return mBinder;
734 }
735
736 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700737 * Sets the camera to be used for the outgoing video.
738 * <p>
739 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
740 * camera via
741 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
742 * <p>
743 * Sent from the {@link InCallService} via
744 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700745 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700746 * @param cameraId The id of the camera (use ids as reported by
747 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 */
749 public abstract void onSetCamera(String cameraId);
750
751 /**
752 * Sets the surface to be used for displaying a preview of what the user's camera is
753 * currently capturing. When video transmission is enabled, this is the video signal which
754 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700755 * <p>
756 * Sent from the {@link InCallService} via
757 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700759 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700760 */
761 public abstract void onSetPreviewSurface(Surface surface);
762
763 /**
764 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700765 * <p>
766 * Sent from the {@link InCallService} via
767 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700768 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700769 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 */
771 public abstract void onSetDisplaySurface(Surface surface);
772
773 /**
774 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
775 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700776 * <p>
777 * Sent from the {@link InCallService} via
778 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700779 *
780 * @param rotation The device orientation, in degrees.
781 */
782 public abstract void onSetDeviceOrientation(int rotation);
783
784 /**
785 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700786 * <p>
787 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788 *
789 * @param value The camera zoom ratio.
790 */
791 public abstract void onSetZoom(float value);
792
793 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700794 * Issues a request to modify the properties of the current video session.
795 * <p>
796 * Example scenarios include: requesting an audio-only call to be upgraded to a
797 * bi-directional video call, turning on or off the user's camera, sending a pause signal
798 * when the {@link InCallService} is no longer the foreground application.
799 * <p>
800 * If the {@link VideoProvider} determines a request to be invalid, it should call
801 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
802 * invalid request back to the {@link InCallService}.
803 * <p>
804 * Where a request requires confirmation from the user of the peer device, the
805 * {@link VideoProvider} must communicate the request to the peer device and handle the
806 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
807 * is used to inform the {@link InCallService} of the result of the request.
808 * <p>
809 * Sent from the {@link InCallService} via
810 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700811 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700812 * @param fromProfile The video profile prior to the request.
813 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 */
Tyler Gunn45382162015-05-06 08:52:27 -0700815 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
816 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700817
Tyler Gunnb702ef82015-05-29 11:51:53 -0700818 /**
819 * Provides a response to a request to change the current video session properties.
820 * <p>
821 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
822 * video call, could decline the request and keep the call as audio-only.
823 * In such a scenario, the {@code responseProfile} would have a video state of
824 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
825 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
826 * <p>
827 * Sent from the {@link InCallService} via
828 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
829 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
830 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 */
834 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
835
836 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700837 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
838 * <p>
839 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
840 * camera via
841 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
842 * <p>
843 * Sent from the {@link InCallService} via
844 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700845 */
846 public abstract void onRequestCameraCapabilities();
847
848 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700849 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
850 * video component of the current {@link Connection}.
851 * <p>
852 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
853 * via {@link VideoProvider#setCallDataUsage(long)}.
854 * <p>
855 * Sent from the {@link InCallService} via
856 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700857 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800858 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700859
860 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700861 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
862 * the peer device when the video signal is paused.
863 * <p>
864 * Sent from the {@link InCallService} via
865 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700866 *
867 * @param uri URI of image to display.
868 */
Yorke Lee32f24732015-05-12 16:18:03 -0700869 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870
871 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700872 * Used to inform listening {@link InCallService} implementations when the
873 * {@link VideoProvider} receives a session modification request.
874 * <p>
875 * Received by the {@link InCallService} via
876 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700878 * @param videoProfile The requested video profile.
879 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700880 */
881 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700882 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700883 for (IVideoCallback callback : mVideoCallbacks.values()) {
884 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700885 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700886 } catch (RemoteException ignored) {
887 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700888 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 }
890 }
891 }
892
893 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700894 * Used to inform listening {@link InCallService} implementations when the
895 * {@link VideoProvider} receives a response to a session modification request.
896 * <p>
897 * Received by the {@link InCallService} via
898 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
899 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700900 *
901 * @param status Status of the session modify request. Valid values are
902 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
903 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
905 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
906 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
907 * @param requestedProfile The original request which was sent to the peer device.
908 * @param responseProfile The actual profile changes agreed to by the peer device.
909 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700910 */
911 public void receiveSessionModifyResponse(int status,
912 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700913 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700914 for (IVideoCallback callback : mVideoCallbacks.values()) {
915 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700916 callback.receiveSessionModifyResponse(status, requestedProfile,
917 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700918 } catch (RemoteException ignored) {
919 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700920 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700921 }
922 }
923 }
924
925 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700926 * Used to inform listening {@link InCallService} implementations when the
927 * {@link VideoProvider} reports a call session event.
928 * <p>
929 * Received by the {@link InCallService} via
930 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700932 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
933 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
934 * {@link VideoProvider#SESSION_EVENT_TX_START},
935 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
936 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
937 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938 */
939 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700940 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700941 for (IVideoCallback callback : mVideoCallbacks.values()) {
942 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700943 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700944 } catch (RemoteException ignored) {
945 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700946 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 }
948 }
949 }
950
951 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * Used to inform listening {@link InCallService} implementations when the dimensions of the
953 * peer's video have changed.
954 * <p>
955 * This could occur if, for example, the peer rotates their device, changing the aspect
956 * ratio of the video, or if the user switches between the back and front cameras.
957 * <p>
958 * Received by the {@link InCallService} via
959 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 *
961 * @param width The updated peer video width.
962 * @param height The updated peer video height.
963 */
964 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700965 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700966 for (IVideoCallback callback : mVideoCallbacks.values()) {
967 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700968 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700969 } catch (RemoteException ignored) {
970 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700971 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 }
973 }
974 }
975
976 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * Used to inform listening {@link InCallService} implementations when the data usage of the
978 * video associated with the current {@link Connection} has changed.
979 * <p>
980 * This could be in response to a preview request via
981 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700982 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
983 * provided at most for every 1 MB of data transferred and no more than once every 10 sec.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700984 * <p>
985 * Received by the {@link InCallService} via
986 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
989 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 */
Yorke Lee32f24732015-05-12 16:18:03 -0700991 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700992 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700993 for (IVideoCallback callback : mVideoCallbacks.values()) {
994 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700995 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700996 } catch (RemoteException ignored) {
997 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700998 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700999 }
1000 }
1001 }
1002
1003 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001004 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001007 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1008 * @hide
1009 */
1010 public void changeCallDataUsage(long dataUsage) {
1011 setCallDataUsage(dataUsage);
1012 }
1013
1014 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * Used to inform listening {@link InCallService} implementations when the capabilities of
1016 * the current camera have changed.
1017 * <p>
1018 * The {@link VideoProvider} should call this in response to
1019 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1020 * changed via {@link VideoProvider#onSetCamera(String)}.
1021 * <p>
1022 * Received by the {@link InCallService} via
1023 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1024 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001025 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001026 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 */
Yorke Lee400470f2015-05-12 13:31:25 -07001028 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001029 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001030 for (IVideoCallback callback : mVideoCallbacks.values()) {
1031 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001032 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001033 } catch (RemoteException ignored) {
1034 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001035 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 }
1037 }
1038 }
Rekha Kumar07366812015-03-24 16:42:31 -07001039
1040 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001041 * Used to inform listening {@link InCallService} implementations when the video quality
1042 * of the call has changed.
1043 * <p>
1044 * Received by the {@link InCallService} via
1045 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001046 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001047 * @param videoQuality The updated video quality. Valid values:
1048 * {@link VideoProfile#QUALITY_HIGH},
1049 * {@link VideoProfile#QUALITY_MEDIUM},
1050 * {@link VideoProfile#QUALITY_LOW},
1051 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001052 */
1053 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001054 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001055 for (IVideoCallback callback : mVideoCallbacks.values()) {
1056 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001057 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001058 } catch (RemoteException ignored) {
1059 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001060 }
Rekha Kumar07366812015-03-24 16:42:31 -07001061 }
1062 }
1063 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001064 }
1065
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001066 private final Listener mConnectionDeathListener = new Listener() {
1067 @Override
1068 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001069 if (mConferenceables.remove(c)) {
1070 fireOnConferenceableConnectionsChanged();
1071 }
1072 }
1073 };
1074
1075 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1076 @Override
1077 public void onDestroyed(Conference c) {
1078 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001079 fireOnConferenceableConnectionsChanged();
1080 }
1081 }
1082 };
1083
Jay Shrauner229e3822014-08-15 09:23:07 -07001084 /**
1085 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1086 * load factor before resizing, 1 means we only expect a single thread to
1087 * access the map so make only a single shard
1088 */
1089 private final Set<Listener> mListeners = Collections.newSetFromMap(
1090 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001091 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1092 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001093 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001094
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001095 // The internal telecom call ID associated with this connection.
1096 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001098 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001099 private Uri mAddress;
1100 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001101 private String mCallerDisplayName;
1102 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001103 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001104 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001106 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001107 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001108 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001109 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001110 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001111 private Conference mConference;
1112 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001113 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001114
1115 /**
1116 * Create a new Connection.
1117 */
Santos Cordonf2951102014-07-20 19:06:29 -07001118 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001119
1120 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001121 * Returns the Telecom internal call ID associated with this connection. Should only be used
1122 * for debugging and tracing purposes.
1123 *
1124 * @return The Telecom call ID.
1125 * @hide
1126 */
1127 public final String getTelecomCallId() {
1128 return mTelecomCallId;
1129 }
1130
1131 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001132 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001133 */
Andrew Lee100e2932014-09-08 15:34:24 -07001134 public final Uri getAddress() {
1135 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001136 }
1137
1138 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001139 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001140 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001141 */
Andrew Lee100e2932014-09-08 15:34:24 -07001142 public final int getAddressPresentation() {
1143 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001144 }
1145
1146 /**
1147 * @return The caller display name (CNAP).
1148 */
1149 public final String getCallerDisplayName() {
1150 return mCallerDisplayName;
1151 }
1152
1153 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001154 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001155 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001156 */
1157 public final int getCallerDisplayNamePresentation() {
1158 return mCallerDisplayNamePresentation;
1159 }
1160
1161 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001162 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001163 */
1164 public final int getState() {
1165 return mState;
1166 }
1167
1168 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001169 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001170 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1171 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1172 * {@link VideoProfile#STATE_TX_ENABLED},
1173 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001174 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001175 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001176 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001177 */
1178 public final int getVideoState() {
1179 return mVideoState;
1180 }
1181
1182 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001183 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001184 * being routed by the system. This is {@code null} if this Connection
1185 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001186 * @deprecated Use {@link #getCallAudioState()} instead.
1187 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001188 */
Yorke Lee4af59352015-05-13 14:14:54 -07001189 @SystemApi
1190 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001191 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001192 if (mCallAudioState == null) {
1193 return null;
1194 }
Yorke Lee4af59352015-05-13 14:14:54 -07001195 return new AudioState(mCallAudioState);
1196 }
1197
1198 /**
1199 * @return The audio state of the connection, describing how its audio is currently
1200 * being routed by the system. This is {@code null} if this Connection
1201 * does not directly know about its audio state.
1202 */
1203 public final CallAudioState getCallAudioState() {
1204 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001205 }
1206
1207 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001208 * @return The conference that this connection is a part of. Null if it is not part of any
1209 * conference.
1210 */
1211 public final Conference getConference() {
1212 return mConference;
1213 }
1214
1215 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001216 * Returns whether this connection is requesting that the system play a ringback tone
1217 * on its behalf.
1218 */
Andrew Lee100e2932014-09-08 15:34:24 -07001219 public final boolean isRingbackRequested() {
1220 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001221 }
1222
1223 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001224 * @return True if the connection's audio mode is VOIP.
1225 */
1226 public final boolean getAudioModeIsVoip() {
1227 return mAudioModeIsVoip;
1228 }
1229
1230 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001231 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1232 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1233 * start time of the conference.
1234 *
1235 * @return The time at which the {@code Connnection} was connected.
1236 *
1237 * @hide
1238 */
1239 public final long getConnectTimeMillis() {
1240 return mConnectTimeMillis;
1241 }
1242
1243 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001244 * @return The status hints for this connection.
1245 */
1246 public final StatusHints getStatusHints() {
1247 return mStatusHints;
1248 }
1249
1250 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001251 * @return The extras associated with this connection.
1252 */
1253 public final Bundle getExtras() {
1254 return mExtras;
1255 }
1256
1257 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001258 * Assign a listener to be notified of state changes.
1259 *
1260 * @param l A listener.
1261 * @return This Connection.
1262 *
1263 * @hide
1264 */
1265 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001266 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001267 return this;
1268 }
1269
1270 /**
1271 * Remove a previously assigned listener that was being notified of state changes.
1272 *
1273 * @param l A Listener.
1274 * @return This Connection.
1275 *
1276 * @hide
1277 */
1278 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001279 if (l != null) {
1280 mListeners.remove(l);
1281 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001282 return this;
1283 }
1284
1285 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001286 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001287 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001288 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001289 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001290 }
1291
1292 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001293 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1294 * ONLY for debugging purposes.
1295 *
1296 * @param callId The telecom call ID.
1297 * @hide
1298 */
1299 public void setTelecomCallId(String callId) {
1300 mTelecomCallId = callId;
1301 }
1302
1303 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 * Inform this Connection that the state of its audio output has been changed externally.
1305 *
1306 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001307 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308 */
Yorke Lee4af59352015-05-13 14:14:54 -07001309 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001311 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001312 mCallAudioState = state;
1313 onAudioStateChanged(getAudioState());
1314 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001315 }
1316
1317 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319 * @return A string representation of the value.
1320 */
1321 public static String stateToString(int state) {
1322 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001323 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001324 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001326 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001328 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001329 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001330 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001332 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001334 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001336 return "DISCONNECTED";
1337 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001338 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001339 return "UNKNOWN";
1340 }
1341 }
1342
1343 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001344 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001345 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001346 public final int getConnectionCapabilities() {
1347 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001348 }
1349
1350 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001351 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001352 *
Andrew Lee100e2932014-09-08 15:34:24 -07001353 * @param address The new address.
1354 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001355 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001356 */
Andrew Lee100e2932014-09-08 15:34:24 -07001357 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001358 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001359 Log.d(this, "setAddress %s", address);
1360 mAddress = address;
1361 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001362 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001363 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001364 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001365 }
1366
1367 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001368 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001369 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001370 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001371 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001372 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001373 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001374 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001375 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001376 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001377 mCallerDisplayName = callerDisplayName;
1378 mCallerDisplayNamePresentation = presentation;
1379 for (Listener l : mListeners) {
1380 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1381 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001382 }
1383
1384 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001385 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001386 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1387 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1388 * {@link VideoProfile#STATE_TX_ENABLED},
1389 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001390 *
1391 * @param videoState The new video state.
1392 */
1393 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001394 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001395 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001396 mVideoState = videoState;
1397 for (Listener l : mListeners) {
1398 l.onVideoStateChanged(this, mVideoState);
1399 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001400 }
1401
1402 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001403 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001404 * communicate).
1405 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001406 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001407 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001408 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001410 }
1411
1412 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001413 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001414 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001415 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001416 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001417 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001418 }
1419
1420 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001421 * Sets state to initializing (this Connection is not yet ready to be used).
1422 */
1423 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001424 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001425 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001426 }
1427
1428 /**
1429 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1430 */
1431 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001432 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001434 }
1435
1436 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001437 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001438 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001439 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001440 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442 }
1443
1444 /**
1445 * Sets state to be on hold.
1446 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001447 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001448 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001450 }
1451
1452 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001453 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001455 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001457 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001459 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001461 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001462 }
1463
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 public final VideoProvider getVideoProvider() {
1465 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001466 }
1467
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001468 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001469 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001470 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001471 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001473 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001474 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001475 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001476 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001478 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001479 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001480 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001481 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001482 }
1483
1484 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001485 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1486 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1487 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1488 * to send an {@link #onPostDialContinue(boolean)} signal.
1489 *
1490 * @param remaining The DTMF character sequence remaining to be emitted once the
1491 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1492 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001493 */
1494 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001495 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001496 for (Listener l : mListeners) {
1497 l.onPostDialWait(this, remaining);
1498 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001499 }
1500
1501 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001502 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1503 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001504 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001505 *
1506 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001507 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001508 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001509 checkImmutable();
1510 for (Listener l : mListeners) {
1511 l.onPostDialChar(this, nextChar);
1512 }
1513 }
1514
1515 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001516 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001517 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001518 *
1519 * @param ringback Whether the ringback tone is to be played.
1520 */
Andrew Lee100e2932014-09-08 15:34:24 -07001521 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001522 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001523 if (mRingbackRequested != ringback) {
1524 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001525 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001526 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001527 }
1528 }
Ihab Awadf8358972014-05-28 16:46:42 -07001529 }
1530
1531 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001532 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001533 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001534 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001535 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001536 public final void setConnectionCapabilities(int connectionCapabilities) {
1537 checkImmutable();
1538 if (mConnectionCapabilities != connectionCapabilities) {
1539 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001540 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001541 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001542 }
1543 }
Santos Cordonb6939982014-06-04 20:20:58 -07001544 }
1545
1546 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001547 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001548 */
Evan Charlton36a71342014-07-19 16:31:02 -07001549 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001550 for (Listener l : mListeners) {
1551 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001552 }
Santos Cordonb6939982014-06-04 20:20:58 -07001553 }
1554
1555 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001556 * Requests that the framework use VOIP audio mode for this connection.
1557 *
1558 * @param isVoip True if the audio mode is VOIP.
1559 */
1560 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001561 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001562 mAudioModeIsVoip = isVoip;
1563 for (Listener l : mListeners) {
1564 l.onAudioModeIsVoipChanged(this, isVoip);
1565 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001566 }
1567
1568 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001569 * Sets the time at which a call became active on this Connection. This is set only
1570 * when a conference call becomes active on this connection.
1571 *
1572 * @param connectionTimeMillis The connection time, in milliseconds.
1573 *
1574 * @hide
1575 */
1576 public final void setConnectTimeMillis(long connectTimeMillis) {
1577 mConnectTimeMillis = connectTimeMillis;
1578 }
1579
1580 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001581 * Sets the label and icon status to display in the in-call UI.
1582 *
1583 * @param statusHints The status label and icon to set.
1584 */
1585 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001586 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001587 mStatusHints = statusHints;
1588 for (Listener l : mListeners) {
1589 l.onStatusHintsChanged(this, statusHints);
1590 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001591 }
1592
1593 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001594 * Sets the connections with which this connection can be conferenced.
1595 *
1596 * @param conferenceableConnections The set of connections this connection can conference with.
1597 */
1598 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001599 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001600 clearConferenceableList();
1601 for (Connection c : conferenceableConnections) {
1602 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1603 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001604 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001605 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001606 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001607 }
1608 }
1609 fireOnConferenceableConnectionsChanged();
1610 }
1611
1612 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001613 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1614 * or conferences with which this connection can be conferenced.
1615 *
1616 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001617 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001618 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001619 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001620 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001621 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1622 // small amount of items here.
1623 if (!mConferenceables.contains(c)) {
1624 if (c instanceof Connection) {
1625 Connection connection = (Connection) c;
1626 connection.addConnectionListener(mConnectionDeathListener);
1627 } else if (c instanceof Conference) {
1628 Conference conference = (Conference) c;
1629 conference.addListener(mConferenceDeathListener);
1630 }
1631 mConferenceables.add(c);
1632 }
1633 }
1634 fireOnConferenceableConnectionsChanged();
1635 }
1636
1637 /**
1638 * Returns the connections or conferences with which this connection can be conferenced.
1639 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001640 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001641 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001642 }
1643
Yorke Lee53463962015-08-04 16:07:19 -07001644 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001645 * @hide
1646 */
1647 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001648 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001649 if (mConnectionService != null) {
1650 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1651 "which is already associated with another ConnectionService.");
1652 } else {
1653 mConnectionService = connectionService;
1654 }
1655 }
1656
1657 /**
1658 * @hide
1659 */
1660 public final void unsetConnectionService(ConnectionService connectionService) {
1661 if (mConnectionService != connectionService) {
1662 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1663 "that does not belong to the ConnectionService.");
1664 } else {
1665 mConnectionService = null;
1666 }
1667 }
1668
1669 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001670 * @hide
1671 */
1672 public final ConnectionService getConnectionService() {
1673 return mConnectionService;
1674 }
1675
1676 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001677 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001678 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001679 *
1680 * @param conference The conference.
1681 * @return {@code true} if the conference was successfully set.
1682 * @hide
1683 */
1684 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001685 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001686 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001687 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001688 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001689 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1690 fireConferenceChanged();
1691 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001692 return true;
1693 }
1694 return false;
1695 }
1696
1697 /**
1698 * Resets the conference that this connection is a part of.
1699 * @hide
1700 */
1701 public final void resetConference() {
1702 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001703 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001704 mConference = null;
1705 fireConferenceChanged();
1706 }
1707 }
1708
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001709 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001710 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1711 * be made as to how an In-Call UI or service will handle these extras.
1712 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1713 *
1714 * @param extras The extras associated with this {@code Connection}.
1715 */
1716 public final void setExtras(@Nullable Bundle extras) {
1717 checkImmutable();
1718 mExtras = extras;
1719 for (Listener l : mListeners) {
1720 l.onExtrasChanged(this, extras);
1721 }
1722 }
1723
1724 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001725 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001726 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001727 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001728 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1729 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001730 */
Yorke Lee4af59352015-05-13 14:14:54 -07001731 @SystemApi
1732 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001733 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001734
1735 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001736 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1737 *
1738 * @param state The new connection audio state.
1739 */
1740 public void onCallAudioStateChanged(CallAudioState state) {}
1741
1742 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001743 * Notifies this Connection of an internal state change. This method is called after the
1744 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001745 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001746 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001747 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001748 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001749
1750 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001751 * Notifies this Connection of a request to play a DTMF tone.
1752 *
1753 * @param c A DTMF character.
1754 */
Santos Cordonf2951102014-07-20 19:06:29 -07001755 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001756
1757 /**
1758 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1759 */
Santos Cordonf2951102014-07-20 19:06:29 -07001760 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001761
1762 /**
1763 * Notifies this Connection of a request to disconnect.
1764 */
Santos Cordonf2951102014-07-20 19:06:29 -07001765 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001766
1767 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001768 * Notifies this Connection of a request to disconnect a participant of the conference managed
1769 * by the connection.
1770 *
1771 * @param endpoint the {@link Uri} of the participant to disconnect.
1772 * @hide
1773 */
1774 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1775
1776 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001777 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001778 */
Santos Cordonf2951102014-07-20 19:06:29 -07001779 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001780
1781 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001782 * Notifies this Connection of a request to abort.
1783 */
Santos Cordonf2951102014-07-20 19:06:29 -07001784 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001785
1786 /**
1787 * Notifies this Connection of a request to hold.
1788 */
Santos Cordonf2951102014-07-20 19:06:29 -07001789 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001790
1791 /**
1792 * Notifies this Connection of a request to exit a hold state.
1793 */
Santos Cordonf2951102014-07-20 19:06:29 -07001794 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795
1796 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001797 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001798 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001799 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001800 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001801 */
Santos Cordonf2951102014-07-20 19:06:29 -07001802 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001803
1804 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001805 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001806 * a request to accept.
1807 */
1808 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001809 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001810 }
1811
1812 /**
1813 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001814 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815 */
Santos Cordonf2951102014-07-20 19:06:29 -07001816 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001817
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001818 /**
Bryce Lee81901682015-08-28 16:38:02 -07001819 * Notifies ths Connection of a request reject with a message.
1820 *
1821 * @hide
1822 */
1823 public void onReject(String replyMessage) {}
1824
1825 /**
Bryce Leecac50772015-11-17 15:13:29 -08001826 * Notifies the Connection of a request to silence the ringer.
1827 *
1828 * @hide
1829 */
1830 public void onSilence() {}
1831
1832 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001833 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1834 */
Santos Cordonf2951102014-07-20 19:06:29 -07001835 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001836
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001837 static String toLogSafePhoneNumber(String number) {
1838 // For unknown number, log empty string.
1839 if (number == null) {
1840 return "";
1841 }
1842
1843 if (PII_DEBUG) {
1844 // When PII_DEBUG is true we emit PII.
1845 return number;
1846 }
1847
1848 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1849 // sanitized phone numbers.
1850 StringBuilder builder = new StringBuilder();
1851 for (int i = 0; i < number.length(); i++) {
1852 char c = number.charAt(i);
1853 if (c == '-' || c == '@' || c == '.') {
1854 builder.append(c);
1855 } else {
1856 builder.append('x');
1857 }
1858 }
1859 return builder.toString();
1860 }
1861
Ihab Awad542e0ea2014-05-16 10:22:16 -07001862 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001863 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001864 if (mState == STATE_DISCONNECTED && mState != state) {
1865 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001866 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001867 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001868 if (mState != state) {
1869 Log.d(this, "setState: %s", stateToString(state));
1870 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001871 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001872 for (Listener l : mListeners) {
1873 l.onStateChanged(this, state);
1874 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001875 }
1876 }
1877
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001878 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001879 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001880 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1881 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001882 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001883 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001884
1885 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001886 if (mImmutable) {
1887 throw new UnsupportedOperationException("Connection is immutable");
1888 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001889 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001890 }
1891
Evan Charltonbf11f982014-07-20 22:06:28 -07001892 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001893 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001894 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1895 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001896 * <p>
1897 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1898 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001899 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001900 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001901 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001902 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001903 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1904 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001905 }
1906
Evan Charltonbf11f982014-07-20 22:06:28 -07001907 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001908 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1909 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1910 * this should never be un-@hide-den.
1911 *
1912 * @hide
1913 */
1914 public void checkImmutable() {}
1915
1916 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001917 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1918 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1919 * that state. This connection should not be used for anything, and no other
1920 * {@code Connection}s should be attempted.
1921 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001922 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001923 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001924 * @return A {@code Connection} which indicates that the underlying connection should
1925 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001926 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001927 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001928 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001929 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001930
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001931 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001932 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001933 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001934 }
1935 }
1936
Santos Cordon823fd3c2014-08-07 18:35:18 -07001937 private final void fireConferenceChanged() {
1938 for (Listener l : mListeners) {
1939 l.onConferenceChanged(this, mConference);
1940 }
1941 }
1942
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001943 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001944 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001945 if (c instanceof Connection) {
1946 Connection connection = (Connection) c;
1947 connection.removeConnectionListener(mConnectionDeathListener);
1948 } else if (c instanceof Conference) {
1949 Conference conference = (Conference) c;
1950 conference.removeListener(mConferenceDeathListener);
1951 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001952 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001953 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001954 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001955
1956 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001957 * Notifies listeners that the merge request failed.
1958 *
1959 * @hide
1960 */
1961 protected final void notifyConferenceMergeFailed() {
1962 for (Listener l : mListeners) {
1963 l.onConferenceMergeFailed(this);
1964 }
1965 }
1966
1967 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001968 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001969 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001970 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001971 * @hide
1972 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001973 protected final void updateConferenceParticipants(
1974 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001975 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001976 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001977 }
1978 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001979
1980 /**
1981 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001982 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001983 */
1984 protected void notifyConferenceStarted() {
1985 for (Listener l : mListeners) {
1986 l.onConferenceStarted();
1987 }
1988 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001989}