blob: 4547c6a6c153180cad0a6b32c6617a59873bb1ea [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
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800300 /**
301 * Connection event used to inform Telecom that it should play the on hold tone. This is used
302 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
303 * {@link #sendConnectionEvent(String)}.
304 * @hide
305 */
306 public static final String EVENT_ON_HOLD_TONE_START =
307 "android.telecom.event.ON_HOLD_TONE_START";
308
309 /**
310 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
311 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
312 * {@link #sendConnectionEvent(String)}.
313 * @hide
314 */
315 public static final String EVENT_ON_HOLD_TONE_END =
316 "android.telecom.event.ON_HOLD_TONE_END";
317
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700318 // Flag controlling whether PII is emitted into the logs
319 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
320
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800321 /**
322 * Whether the given capabilities support the specified capability.
323 *
324 * @param capabilities A capability bit field.
325 * @param capability The capability to check capabilities for.
326 * @return Whether the specified capability is supported.
327 * @hide
328 */
329 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800330 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800331 }
332
333 /**
334 * Whether the capabilities of this {@code Connection} supports the specified capability.
335 *
336 * @param capability The capability to check capabilities for.
337 * @return Whether the specified capability is supported.
338 * @hide
339 */
340 public boolean can(int capability) {
341 return can(mConnectionCapabilities, capability);
342 }
343
344 /**
345 * Removes the specified capability from the set of capabilities of this {@code Connection}.
346 *
347 * @param capability The capability to remove from the set.
348 * @hide
349 */
350 public void removeCapability(int capability) {
351 mConnectionCapabilities &= ~capability;
352 }
353
354 /**
355 * Adds the specified capability to the set of capabilities of this {@code Connection}.
356 *
357 * @param capability The capability to add to the set.
358 * @hide
359 */
360 public void addCapability(int capability) {
361 mConnectionCapabilities |= capability;
362 }
363
364
365 public static String capabilitiesToString(int capabilities) {
366 StringBuilder builder = new StringBuilder();
367 builder.append("[Capabilities:");
368 if (can(capabilities, CAPABILITY_HOLD)) {
369 builder.append(" CAPABILITY_HOLD");
370 }
371 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
372 builder.append(" CAPABILITY_SUPPORT_HOLD");
373 }
374 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
375 builder.append(" CAPABILITY_MERGE_CONFERENCE");
376 }
377 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
378 builder.append(" CAPABILITY_SWAP_CONFERENCE");
379 }
380 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
381 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
382 }
383 if (can(capabilities, CAPABILITY_MUTE)) {
384 builder.append(" CAPABILITY_MUTE");
385 }
386 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
387 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
388 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700389 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
390 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
391 }
392 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
393 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
394 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700395 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
396 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800397 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700398 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
399 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
400 }
401 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
402 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
403 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700404 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
405 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800406 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800407 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
408 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
409 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800410 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
411 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800413 if (can(capabilities, CAPABILITY_WIFI)) {
414 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800415 }
416 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
417 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
418 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800419 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
420 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
421 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500422 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700423 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500424 }
Rekha Kumar07366812015-03-24 16:42:31 -0700425 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
426 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
427 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700428 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
429 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
430 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700431 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
432 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
433 }
Bryce Lee81901682015-08-28 16:38:02 -0700434 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
435 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
436 }
437
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800438 builder.append("]");
439 return builder.toString();
440 }
441
Sailesh Nepal091768c2014-06-30 15:15:23 -0700442 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700443 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700444 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700445 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700446 public void onCallerDisplayNameChanged(
447 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700448 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700449 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700450 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800451 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700452 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700453 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800454 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700455 public void onVideoProviderChanged(
456 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700457 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
458 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800459 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700460 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700461 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700462 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800463 public void onConferenceParticipantsChanged(Connection c,
464 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800465 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700466 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700467 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800468 /** @hide */
469 public void onConnectionEvent(Connection c, String event) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700470 }
471
Tyler Gunnb702ef82015-05-29 11:51:53 -0700472 /**
473 * Provides a means of controlling the video session associated with a {@link Connection}.
474 * <p>
475 * Implementations create a custom subclass of {@link VideoProvider} and the
476 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
477 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
478 * should set the {@link VideoProvider}.
479 * <p>
480 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
481 * {@link InCallService} implementations to issue requests related to the video session;
482 * it provides a means for the {@link ConnectionService} to report events and information
483 * related to the video session to Telecom and the {@link InCallService} implementations.
484 * <p>
485 * {@link InCallService} implementations interact with the {@link VideoProvider} via
486 * {@link android.telecom.InCallService.VideoCall}.
487 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700489
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 /**
491 * Video is not being received (no protocol pause was issued).
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_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700495
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700496 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700497 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
498 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 */
500 public static final int SESSION_EVENT_RX_RESUME = 2;
501
502 /**
503 * Video transmission has begun. This occurs after a negotiated start of video transmission
504 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700505 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700506 */
507 public static final int SESSION_EVENT_TX_START = 3;
508
509 /**
510 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
511 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700512 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513 */
514 public static final int SESSION_EVENT_TX_STOP = 4;
515
516 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700517 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
518 * this as a cue to inform the user the camera is not available.
519 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 */
521 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
522
523 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700524 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
525 * for operation. The {@link InCallService} can use this as a cue to inform the user that
526 * the camera has become available again.
527 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 */
529 public static final int SESSION_EVENT_CAMERA_READY = 6;
530
531 /**
532 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700533 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700534 */
535 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
536
537 /**
538 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700539 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 */
541 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
542
543 /**
544 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700545 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700546 */
547 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
548
Rekha Kumar07366812015-03-24 16:42:31 -0700549 /**
550 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700551 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700552 */
553 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
554
555 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700556 * Session modify request rejected by remote user.
557 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700558 */
559 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
560
Tyler Gunn75958422015-04-15 14:23:42 -0700561 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 private static final int MSG_SET_CAMERA = 2;
563 private static final int MSG_SET_PREVIEW_SURFACE = 3;
564 private static final int MSG_SET_DISPLAY_SURFACE = 4;
565 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
566 private static final int MSG_SET_ZOOM = 6;
567 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
568 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
569 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800570 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700571 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700572 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700574 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700575 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700576
577 /**
578 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700579 *
580 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
581 * load factor before resizing, 1 means we only expect a single thread to
582 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700583 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700584 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
585 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700586
587 /**
588 * Default handler used to consolidate binder method calls onto a single thread.
589 */
590 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700591 public VideoProviderHandler() {
592 super();
593 }
594
595 public VideoProviderHandler(Looper looper) {
596 super(looper);
597 }
598
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 @Override
600 public void handleMessage(Message msg) {
601 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700602 case MSG_ADD_VIDEO_CALLBACK: {
603 IBinder binder = (IBinder) msg.obj;
604 IVideoCallback callback = IVideoCallback.Stub
605 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700606 if (callback == null) {
607 Log.w(this, "addVideoProvider - skipped; callback is null.");
608 break;
609 }
610
Tyler Gunn75958422015-04-15 14:23:42 -0700611 if (mVideoCallbacks.containsKey(binder)) {
612 Log.i(this, "addVideoProvider - skipped; already present.");
613 break;
614 }
615 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700616 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700617 }
618 case MSG_REMOVE_VIDEO_CALLBACK: {
619 IBinder binder = (IBinder) msg.obj;
620 IVideoCallback callback = IVideoCallback.Stub
621 .asInterface((IBinder) msg.obj);
622 if (!mVideoCallbacks.containsKey(binder)) {
623 Log.i(this, "removeVideoProvider - skipped; not present.");
624 break;
625 }
626 mVideoCallbacks.remove(binder);
627 break;
628 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700629 case MSG_SET_CAMERA:
630 onSetCamera((String) msg.obj);
631 break;
632 case MSG_SET_PREVIEW_SURFACE:
633 onSetPreviewSurface((Surface) msg.obj);
634 break;
635 case MSG_SET_DISPLAY_SURFACE:
636 onSetDisplaySurface((Surface) msg.obj);
637 break;
638 case MSG_SET_DEVICE_ORIENTATION:
639 onSetDeviceOrientation(msg.arg1);
640 break;
641 case MSG_SET_ZOOM:
642 onSetZoom((Float) msg.obj);
643 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700644 case MSG_SEND_SESSION_MODIFY_REQUEST: {
645 SomeArgs args = (SomeArgs) msg.obj;
646 try {
647 onSendSessionModifyRequest((VideoProfile) args.arg1,
648 (VideoProfile) args.arg2);
649 } finally {
650 args.recycle();
651 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700653 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700654 case MSG_SEND_SESSION_MODIFY_RESPONSE:
655 onSendSessionModifyResponse((VideoProfile) msg.obj);
656 break;
657 case MSG_REQUEST_CAMERA_CAPABILITIES:
658 onRequestCameraCapabilities();
659 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800660 case MSG_REQUEST_CONNECTION_DATA_USAGE:
661 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 break;
663 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700664 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 break;
666 default:
667 break;
668 }
669 }
670 }
671
672 /**
673 * IVideoProvider stub implementation.
674 */
675 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700676 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700678 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
679 }
680
681 public void removeVideoCallback(IBinder videoCallbackBinder) {
682 mMessageHandler.obtainMessage(
683 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700684 }
685
686 public void setCamera(String cameraId) {
687 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
688 }
689
690 public void setPreviewSurface(Surface surface) {
691 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
692 }
693
694 public void setDisplaySurface(Surface surface) {
695 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
696 }
697
698 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700699 mMessageHandler.obtainMessage(
700 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700701 }
702
703 public void setZoom(float value) {
704 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
705 }
706
Tyler Gunn45382162015-05-06 08:52:27 -0700707 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
708 SomeArgs args = SomeArgs.obtain();
709 args.arg1 = fromProfile;
710 args.arg2 = toProfile;
711 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 }
713
714 public void sendSessionModifyResponse(VideoProfile responseProfile) {
715 mMessageHandler.obtainMessage(
716 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
717 }
718
719 public void requestCameraCapabilities() {
720 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
721 }
722
723 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800724 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 }
726
Yorke Lee32f24732015-05-12 16:18:03 -0700727 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
729 }
730 }
731
732 public VideoProvider() {
733 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700734 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700735 }
736
737 /**
738 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
739 *
740 * @param looper The looper.
741 * @hide
742 */
743 public VideoProvider(Looper looper) {
744 mBinder = new VideoProvider.VideoProviderBinder();
745 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 }
747
748 /**
749 * Returns binder object which can be used across IPC methods.
750 * @hide
751 */
752 public final IVideoProvider getInterface() {
753 return mBinder;
754 }
755
756 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700757 * Sets the camera to be used for the outgoing video.
758 * <p>
759 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
760 * camera via
761 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
762 * <p>
763 * Sent from the {@link InCallService} via
764 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700766 * @param cameraId The id of the camera (use ids as reported by
767 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700768 */
769 public abstract void onSetCamera(String cameraId);
770
771 /**
772 * Sets the surface to be used for displaying a preview of what the user's camera is
773 * currently capturing. When video transmission is enabled, this is the video signal which
774 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700775 * <p>
776 * Sent from the {@link InCallService} via
777 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700779 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700780 */
781 public abstract void onSetPreviewSurface(Surface surface);
782
783 /**
784 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700785 * <p>
786 * Sent from the {@link InCallService} via
787 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700789 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700790 */
791 public abstract void onSetDisplaySurface(Surface surface);
792
793 /**
794 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
795 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700796 * <p>
797 * Sent from the {@link InCallService} via
798 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700799 *
800 * @param rotation The device orientation, in degrees.
801 */
802 public abstract void onSetDeviceOrientation(int rotation);
803
804 /**
805 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700806 * <p>
807 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 *
809 * @param value The camera zoom ratio.
810 */
811 public abstract void onSetZoom(float value);
812
813 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700814 * Issues a request to modify the properties of the current video session.
815 * <p>
816 * Example scenarios include: requesting an audio-only call to be upgraded to a
817 * bi-directional video call, turning on or off the user's camera, sending a pause signal
818 * when the {@link InCallService} is no longer the foreground application.
819 * <p>
820 * If the {@link VideoProvider} determines a request to be invalid, it should call
821 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
822 * invalid request back to the {@link InCallService}.
823 * <p>
824 * Where a request requires confirmation from the user of the peer device, the
825 * {@link VideoProvider} must communicate the request to the peer device and handle the
826 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
827 * is used to inform the {@link InCallService} of the result of the request.
828 * <p>
829 * Sent from the {@link InCallService} via
830 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * @param fromProfile The video profile prior to the request.
833 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700834 */
Tyler Gunn45382162015-05-06 08:52:27 -0700835 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
836 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837
Tyler Gunnb702ef82015-05-29 11:51:53 -0700838 /**
839 * Provides a response to a request to change the current video session properties.
840 * <p>
841 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
842 * video call, could decline the request and keep the call as audio-only.
843 * In such a scenario, the {@code responseProfile} would have a video state of
844 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
845 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
846 * <p>
847 * Sent from the {@link InCallService} via
848 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
849 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
850 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700852 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853 */
854 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
855
856 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700857 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
858 * <p>
859 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
860 * camera via
861 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
862 * <p>
863 * Sent from the {@link InCallService} via
864 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 */
866 public abstract void onRequestCameraCapabilities();
867
868 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700869 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
870 * video component of the current {@link Connection}.
871 * <p>
872 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
873 * via {@link VideoProvider#setCallDataUsage(long)}.
874 * <p>
875 * Sent from the {@link InCallService} via
876 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800878 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879
880 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
882 * the peer device when the video signal is paused.
883 * <p>
884 * Sent from the {@link InCallService} via
885 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 *
887 * @param uri URI of image to display.
888 */
Yorke Lee32f24732015-05-12 16:18:03 -0700889 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700890
891 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700892 * Used to inform listening {@link InCallService} implementations when the
893 * {@link VideoProvider} receives a session modification request.
894 * <p>
895 * Received by the {@link InCallService} via
896 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * @param videoProfile The requested video profile.
899 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700900 */
901 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700902 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700903 for (IVideoCallback callback : mVideoCallbacks.values()) {
904 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700905 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700906 } catch (RemoteException ignored) {
907 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700908 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 }
910 }
911 }
912
913 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * Used to inform listening {@link InCallService} implementations when the
915 * {@link VideoProvider} receives a response to a session modification request.
916 * <p>
917 * Received by the {@link InCallService} via
918 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
919 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920 *
921 * @param status Status of the session modify request. Valid values are
922 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
923 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700924 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
925 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
926 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
927 * @param requestedProfile The original request which was sent to the peer device.
928 * @param responseProfile The actual profile changes agreed to by the peer device.
929 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930 */
931 public void receiveSessionModifyResponse(int status,
932 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700933 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700934 for (IVideoCallback callback : mVideoCallbacks.values()) {
935 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700936 callback.receiveSessionModifyResponse(status, requestedProfile,
937 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700938 } catch (RemoteException ignored) {
939 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700940 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941 }
942 }
943 }
944
945 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700946 * Used to inform listening {@link InCallService} implementations when the
947 * {@link VideoProvider} reports a call session event.
948 * <p>
949 * Received by the {@link InCallService} via
950 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
953 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
954 * {@link VideoProvider#SESSION_EVENT_TX_START},
955 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
956 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
957 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 */
959 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700960 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700961 for (IVideoCallback callback : mVideoCallbacks.values()) {
962 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700963 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700964 } catch (RemoteException ignored) {
965 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700966 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 }
968 }
969 }
970
971 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700972 * Used to inform listening {@link InCallService} implementations when the dimensions of the
973 * peer's video have changed.
974 * <p>
975 * This could occur if, for example, the peer rotates their device, changing the aspect
976 * ratio of the video, or if the user switches between the back and front cameras.
977 * <p>
978 * Received by the {@link InCallService} via
979 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 *
981 * @param width The updated peer video width.
982 * @param height The updated peer video height.
983 */
984 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700985 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700986 for (IVideoCallback callback : mVideoCallbacks.values()) {
987 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700988 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700989 } catch (RemoteException ignored) {
990 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700991 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 }
993 }
994 }
995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Used to inform listening {@link InCallService} implementations when the data usage of the
998 * video associated with the current {@link Connection} has changed.
999 * <p>
1000 * This could be in response to a preview request via
1001 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001002 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1003 * 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 -07001004 * <p>
1005 * Received by the {@link InCallService} via
1006 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1009 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001010 */
Yorke Lee32f24732015-05-12 16:18:03 -07001011 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001012 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001013 for (IVideoCallback callback : mVideoCallbacks.values()) {
1014 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001015 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001016 } catch (RemoteException ignored) {
1017 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001018 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 }
1020 }
1021 }
1022
1023 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001024 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001025 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001026 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001027 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1028 * @hide
1029 */
1030 public void changeCallDataUsage(long dataUsage) {
1031 setCallDataUsage(dataUsage);
1032 }
1033
1034 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * Used to inform listening {@link InCallService} implementations when the capabilities of
1036 * the current camera have changed.
1037 * <p>
1038 * The {@link VideoProvider} should call this in response to
1039 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1040 * changed via {@link VideoProvider#onSetCamera(String)}.
1041 * <p>
1042 * Received by the {@link InCallService} via
1043 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1044 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001045 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001046 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001047 */
Yorke Lee400470f2015-05-12 13:31:25 -07001048 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001049 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001050 for (IVideoCallback callback : mVideoCallbacks.values()) {
1051 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001052 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001053 } catch (RemoteException ignored) {
1054 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001055 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 }
1057 }
1058 }
Rekha Kumar07366812015-03-24 16:42:31 -07001059
1060 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001061 * Used to inform listening {@link InCallService} implementations when the video quality
1062 * of the call has changed.
1063 * <p>
1064 * Received by the {@link InCallService} via
1065 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001066 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001067 * @param videoQuality The updated video quality. Valid values:
1068 * {@link VideoProfile#QUALITY_HIGH},
1069 * {@link VideoProfile#QUALITY_MEDIUM},
1070 * {@link VideoProfile#QUALITY_LOW},
1071 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001072 */
1073 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001074 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001075 for (IVideoCallback callback : mVideoCallbacks.values()) {
1076 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001077 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001078 } catch (RemoteException ignored) {
1079 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001080 }
Rekha Kumar07366812015-03-24 16:42:31 -07001081 }
1082 }
1083 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001084 }
1085
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001086 private final Listener mConnectionDeathListener = new Listener() {
1087 @Override
1088 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001089 if (mConferenceables.remove(c)) {
1090 fireOnConferenceableConnectionsChanged();
1091 }
1092 }
1093 };
1094
1095 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1096 @Override
1097 public void onDestroyed(Conference c) {
1098 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001099 fireOnConferenceableConnectionsChanged();
1100 }
1101 }
1102 };
1103
Jay Shrauner229e3822014-08-15 09:23:07 -07001104 /**
1105 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1106 * load factor before resizing, 1 means we only expect a single thread to
1107 * access the map so make only a single shard
1108 */
1109 private final Set<Listener> mListeners = Collections.newSetFromMap(
1110 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001111 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1112 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001113 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001114
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001115 // The internal telecom call ID associated with this connection.
1116 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001117 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001118 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001119 private Uri mAddress;
1120 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001121 private String mCallerDisplayName;
1122 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001123 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001124 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001126 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001127 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001128 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001129 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001130 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001131 private Conference mConference;
1132 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001133 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001134
1135 /**
1136 * Create a new Connection.
1137 */
Santos Cordonf2951102014-07-20 19:06:29 -07001138 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001139
1140 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001141 * Returns the Telecom internal call ID associated with this connection. Should only be used
1142 * for debugging and tracing purposes.
1143 *
1144 * @return The Telecom call ID.
1145 * @hide
1146 */
1147 public final String getTelecomCallId() {
1148 return mTelecomCallId;
1149 }
1150
1151 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001152 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001153 */
Andrew Lee100e2932014-09-08 15:34:24 -07001154 public final Uri getAddress() {
1155 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001156 }
1157
1158 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001159 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001160 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001161 */
Andrew Lee100e2932014-09-08 15:34:24 -07001162 public final int getAddressPresentation() {
1163 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001164 }
1165
1166 /**
1167 * @return The caller display name (CNAP).
1168 */
1169 public final String getCallerDisplayName() {
1170 return mCallerDisplayName;
1171 }
1172
1173 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001174 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001175 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001176 */
1177 public final int getCallerDisplayNamePresentation() {
1178 return mCallerDisplayNamePresentation;
1179 }
1180
1181 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001182 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001183 */
1184 public final int getState() {
1185 return mState;
1186 }
1187
1188 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001189 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001190 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1191 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1192 * {@link VideoProfile#STATE_TX_ENABLED},
1193 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001194 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001195 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001196 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001197 */
1198 public final int getVideoState() {
1199 return mVideoState;
1200 }
1201
1202 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001203 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001204 * being routed by the system. This is {@code null} if this Connection
1205 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001206 * @deprecated Use {@link #getCallAudioState()} instead.
1207 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001208 */
Yorke Lee4af59352015-05-13 14:14:54 -07001209 @SystemApi
1210 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001212 if (mCallAudioState == null) {
1213 return null;
1214 }
Yorke Lee4af59352015-05-13 14:14:54 -07001215 return new AudioState(mCallAudioState);
1216 }
1217
1218 /**
1219 * @return The audio state of the connection, describing how its audio is currently
1220 * being routed by the system. This is {@code null} if this Connection
1221 * does not directly know about its audio state.
1222 */
1223 public final CallAudioState getCallAudioState() {
1224 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001225 }
1226
1227 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001228 * @return The conference that this connection is a part of. Null if it is not part of any
1229 * conference.
1230 */
1231 public final Conference getConference() {
1232 return mConference;
1233 }
1234
1235 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001236 * Returns whether this connection is requesting that the system play a ringback tone
1237 * on its behalf.
1238 */
Andrew Lee100e2932014-09-08 15:34:24 -07001239 public final boolean isRingbackRequested() {
1240 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001241 }
1242
1243 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001244 * @return True if the connection's audio mode is VOIP.
1245 */
1246 public final boolean getAudioModeIsVoip() {
1247 return mAudioModeIsVoip;
1248 }
1249
1250 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001251 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1252 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1253 * start time of the conference.
1254 *
1255 * @return The time at which the {@code Connnection} was connected.
1256 *
1257 * @hide
1258 */
1259 public final long getConnectTimeMillis() {
1260 return mConnectTimeMillis;
1261 }
1262
1263 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001264 * @return The status hints for this connection.
1265 */
1266 public final StatusHints getStatusHints() {
1267 return mStatusHints;
1268 }
1269
1270 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001271 * @return The extras associated with this connection.
1272 */
1273 public final Bundle getExtras() {
1274 return mExtras;
1275 }
1276
1277 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001278 * Assign a listener to be notified of state changes.
1279 *
1280 * @param l A listener.
1281 * @return This Connection.
1282 *
1283 * @hide
1284 */
1285 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001286 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001287 return this;
1288 }
1289
1290 /**
1291 * Remove a previously assigned listener that was being notified of state changes.
1292 *
1293 * @param l A Listener.
1294 * @return This Connection.
1295 *
1296 * @hide
1297 */
1298 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001299 if (l != null) {
1300 mListeners.remove(l);
1301 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001302 return this;
1303 }
1304
1305 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001306 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001307 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001308 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001309 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001310 }
1311
1312 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001313 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1314 * ONLY for debugging purposes.
1315 *
1316 * @param callId The telecom call ID.
1317 * @hide
1318 */
1319 public void setTelecomCallId(String callId) {
1320 mTelecomCallId = callId;
1321 }
1322
1323 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324 * Inform this Connection that the state of its audio output has been changed externally.
1325 *
1326 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001327 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 */
Yorke Lee4af59352015-05-13 14:14:54 -07001329 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001330 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001331 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001332 mCallAudioState = state;
1333 onAudioStateChanged(getAudioState());
1334 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001335 }
1336
1337 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001339 * @return A string representation of the value.
1340 */
1341 public static String stateToString(int state) {
1342 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001343 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001344 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001345 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001346 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001348 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001350 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001351 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001352 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001354 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001356 return "DISCONNECTED";
1357 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001358 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001359 return "UNKNOWN";
1360 }
1361 }
1362
1363 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001364 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001365 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001366 public final int getConnectionCapabilities() {
1367 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001368 }
1369
1370 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001371 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001372 *
Andrew Lee100e2932014-09-08 15:34:24 -07001373 * @param address The new address.
1374 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001375 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001376 */
Andrew Lee100e2932014-09-08 15:34:24 -07001377 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001378 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001379 Log.d(this, "setAddress %s", address);
1380 mAddress = address;
1381 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001382 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001383 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001384 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001385 }
1386
1387 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001388 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001389 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001390 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001391 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001392 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001393 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001394 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001395 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001396 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001397 mCallerDisplayName = callerDisplayName;
1398 mCallerDisplayNamePresentation = presentation;
1399 for (Listener l : mListeners) {
1400 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1401 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001402 }
1403
1404 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001405 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001406 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1407 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1408 * {@link VideoProfile#STATE_TX_ENABLED},
1409 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001410 *
1411 * @param videoState The new video state.
1412 */
1413 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001414 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001415 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001416 mVideoState = videoState;
1417 for (Listener l : mListeners) {
1418 l.onVideoStateChanged(this, mVideoState);
1419 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001420 }
1421
1422 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001423 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001424 * communicate).
1425 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001426 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001427 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001428 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001429 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001430 }
1431
1432 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001433 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001434 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001435 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001436 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001437 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001438 }
1439
1440 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001441 * Sets state to initializing (this Connection is not yet ready to be used).
1442 */
1443 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001444 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001445 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001446 }
1447
1448 /**
1449 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1450 */
1451 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001452 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001454 }
1455
1456 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001457 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001458 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001459 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001460 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001462 }
1463
1464 /**
1465 * Sets state to be on hold.
1466 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001467 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001468 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001469 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001470 }
1471
1472 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001473 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001474 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001475 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001476 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001477 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001478 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001479 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001481 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001482 }
1483
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 public final VideoProvider getVideoProvider() {
1485 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001486 }
1487
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001488 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001489 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001491 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001494 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001495 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001496 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001497 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001498 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001499 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001500 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001501 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001502 }
1503
1504 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001505 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1506 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1507 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1508 * to send an {@link #onPostDialContinue(boolean)} signal.
1509 *
1510 * @param remaining The DTMF character sequence remaining to be emitted once the
1511 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1512 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001513 */
1514 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001515 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001516 for (Listener l : mListeners) {
1517 l.onPostDialWait(this, remaining);
1518 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001519 }
1520
1521 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001522 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1523 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001524 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001525 *
1526 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001527 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001528 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001529 checkImmutable();
1530 for (Listener l : mListeners) {
1531 l.onPostDialChar(this, nextChar);
1532 }
1533 }
1534
1535 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001536 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001537 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001538 *
1539 * @param ringback Whether the ringback tone is to be played.
1540 */
Andrew Lee100e2932014-09-08 15:34:24 -07001541 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001542 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001543 if (mRingbackRequested != ringback) {
1544 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001545 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001546 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001547 }
1548 }
Ihab Awadf8358972014-05-28 16:46:42 -07001549 }
1550
1551 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001552 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001553 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001554 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001555 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001556 public final void setConnectionCapabilities(int connectionCapabilities) {
1557 checkImmutable();
1558 if (mConnectionCapabilities != connectionCapabilities) {
1559 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001560 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001561 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001562 }
1563 }
Santos Cordonb6939982014-06-04 20:20:58 -07001564 }
1565
1566 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001567 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001568 */
Evan Charlton36a71342014-07-19 16:31:02 -07001569 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001570 for (Listener l : mListeners) {
1571 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001572 }
Santos Cordonb6939982014-06-04 20:20:58 -07001573 }
1574
1575 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001576 * Requests that the framework use VOIP audio mode for this connection.
1577 *
1578 * @param isVoip True if the audio mode is VOIP.
1579 */
1580 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001581 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001582 mAudioModeIsVoip = isVoip;
1583 for (Listener l : mListeners) {
1584 l.onAudioModeIsVoipChanged(this, isVoip);
1585 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001586 }
1587
1588 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001589 * Sets the time at which a call became active on this Connection. This is set only
1590 * when a conference call becomes active on this connection.
1591 *
1592 * @param connectionTimeMillis The connection time, in milliseconds.
1593 *
1594 * @hide
1595 */
1596 public final void setConnectTimeMillis(long connectTimeMillis) {
1597 mConnectTimeMillis = connectTimeMillis;
1598 }
1599
1600 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001601 * Sets the label and icon status to display in the in-call UI.
1602 *
1603 * @param statusHints The status label and icon to set.
1604 */
1605 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001606 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001607 mStatusHints = statusHints;
1608 for (Listener l : mListeners) {
1609 l.onStatusHintsChanged(this, statusHints);
1610 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001611 }
1612
1613 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001614 * Sets the connections with which this connection can be conferenced.
1615 *
1616 * @param conferenceableConnections The set of connections this connection can conference with.
1617 */
1618 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001619 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001620 clearConferenceableList();
1621 for (Connection c : conferenceableConnections) {
1622 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1623 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001624 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001625 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001626 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001627 }
1628 }
1629 fireOnConferenceableConnectionsChanged();
1630 }
1631
1632 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001633 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1634 * or conferences with which this connection can be conferenced.
1635 *
1636 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001637 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001638 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001639 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001640 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001641 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1642 // small amount of items here.
1643 if (!mConferenceables.contains(c)) {
1644 if (c instanceof Connection) {
1645 Connection connection = (Connection) c;
1646 connection.addConnectionListener(mConnectionDeathListener);
1647 } else if (c instanceof Conference) {
1648 Conference conference = (Conference) c;
1649 conference.addListener(mConferenceDeathListener);
1650 }
1651 mConferenceables.add(c);
1652 }
1653 }
1654 fireOnConferenceableConnectionsChanged();
1655 }
1656
1657 /**
1658 * Returns the connections or conferences with which this connection can be conferenced.
1659 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001660 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001661 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001662 }
1663
Yorke Lee53463962015-08-04 16:07:19 -07001664 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001665 * @hide
1666 */
1667 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001668 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001669 if (mConnectionService != null) {
1670 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1671 "which is already associated with another ConnectionService.");
1672 } else {
1673 mConnectionService = connectionService;
1674 }
1675 }
1676
1677 /**
1678 * @hide
1679 */
1680 public final void unsetConnectionService(ConnectionService connectionService) {
1681 if (mConnectionService != connectionService) {
1682 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1683 "that does not belong to the ConnectionService.");
1684 } else {
1685 mConnectionService = null;
1686 }
1687 }
1688
1689 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001690 * @hide
1691 */
1692 public final ConnectionService getConnectionService() {
1693 return mConnectionService;
1694 }
1695
1696 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001697 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001698 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001699 *
1700 * @param conference The conference.
1701 * @return {@code true} if the conference was successfully set.
1702 * @hide
1703 */
1704 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001705 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001706 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001707 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001708 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001709 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1710 fireConferenceChanged();
1711 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001712 return true;
1713 }
1714 return false;
1715 }
1716
1717 /**
1718 * Resets the conference that this connection is a part of.
1719 * @hide
1720 */
1721 public final void resetConference() {
1722 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001723 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001724 mConference = null;
1725 fireConferenceChanged();
1726 }
1727 }
1728
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001729 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001730 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1731 * be made as to how an In-Call UI or service will handle these extras.
1732 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1733 *
1734 * @param extras The extras associated with this {@code Connection}.
1735 */
1736 public final void setExtras(@Nullable Bundle extras) {
1737 checkImmutable();
1738 mExtras = extras;
1739 for (Listener l : mListeners) {
1740 l.onExtrasChanged(this, extras);
1741 }
1742 }
1743
1744 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001745 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001746 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001747 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001748 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1749 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001750 */
Yorke Lee4af59352015-05-13 14:14:54 -07001751 @SystemApi
1752 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001753 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001754
1755 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001756 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1757 *
1758 * @param state The new connection audio state.
1759 */
1760 public void onCallAudioStateChanged(CallAudioState state) {}
1761
1762 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001763 * Notifies this Connection of an internal state change. This method is called after the
1764 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001765 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001766 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001767 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001768 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001769
1770 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001771 * Notifies this Connection of a request to play a DTMF tone.
1772 *
1773 * @param c A DTMF character.
1774 */
Santos Cordonf2951102014-07-20 19:06:29 -07001775 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001776
1777 /**
1778 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1779 */
Santos Cordonf2951102014-07-20 19:06:29 -07001780 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001781
1782 /**
1783 * Notifies this Connection of a request to disconnect.
1784 */
Santos Cordonf2951102014-07-20 19:06:29 -07001785 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786
1787 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001788 * Notifies this Connection of a request to disconnect a participant of the conference managed
1789 * by the connection.
1790 *
1791 * @param endpoint the {@link Uri} of the participant to disconnect.
1792 * @hide
1793 */
1794 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1795
1796 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001797 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001798 */
Santos Cordonf2951102014-07-20 19:06:29 -07001799 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001800
1801 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 * Notifies this Connection of a request to abort.
1803 */
Santos Cordonf2951102014-07-20 19:06:29 -07001804 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805
1806 /**
1807 * Notifies this Connection of a request to hold.
1808 */
Santos Cordonf2951102014-07-20 19:06:29 -07001809 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001810
1811 /**
1812 * Notifies this Connection of a request to exit a hold state.
1813 */
Santos Cordonf2951102014-07-20 19:06:29 -07001814 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815
1816 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001818 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001819 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001820 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001821 */
Santos Cordonf2951102014-07-20 19:06:29 -07001822 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823
1824 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001825 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001826 * a request to accept.
1827 */
1828 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001829 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001830 }
1831
1832 /**
1833 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001834 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001835 */
Santos Cordonf2951102014-07-20 19:06:29 -07001836 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001837
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001838 /**
Bryce Lee81901682015-08-28 16:38:02 -07001839 * Notifies ths Connection of a request reject with a message.
1840 *
1841 * @hide
1842 */
1843 public void onReject(String replyMessage) {}
1844
1845 /**
Bryce Leecac50772015-11-17 15:13:29 -08001846 * Notifies the Connection of a request to silence the ringer.
1847 *
1848 * @hide
1849 */
1850 public void onSilence() {}
1851
1852 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001853 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1854 */
Santos Cordonf2951102014-07-20 19:06:29 -07001855 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001856
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001857 static String toLogSafePhoneNumber(String number) {
1858 // For unknown number, log empty string.
1859 if (number == null) {
1860 return "";
1861 }
1862
1863 if (PII_DEBUG) {
1864 // When PII_DEBUG is true we emit PII.
1865 return number;
1866 }
1867
1868 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1869 // sanitized phone numbers.
1870 StringBuilder builder = new StringBuilder();
1871 for (int i = 0; i < number.length(); i++) {
1872 char c = number.charAt(i);
1873 if (c == '-' || c == '@' || c == '.') {
1874 builder.append(c);
1875 } else {
1876 builder.append('x');
1877 }
1878 }
1879 return builder.toString();
1880 }
1881
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001883 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001884 if (mState == STATE_DISCONNECTED && mState != state) {
1885 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001886 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001887 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001888 if (mState != state) {
1889 Log.d(this, "setState: %s", stateToString(state));
1890 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001891 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001892 for (Listener l : mListeners) {
1893 l.onStateChanged(this, state);
1894 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001895 }
1896 }
1897
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001898 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001899 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001900 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1901 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001902 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001903 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001904
1905 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001906 if (mImmutable) {
1907 throw new UnsupportedOperationException("Connection is immutable");
1908 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001909 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001910 }
1911
Evan Charltonbf11f982014-07-20 22:06:28 -07001912 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001913 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001914 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1915 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001916 * <p>
1917 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1918 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001919 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001920 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001921 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001922 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001923 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1924 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001925 }
1926
Evan Charltonbf11f982014-07-20 22:06:28 -07001927 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001928 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1929 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1930 * this should never be un-@hide-den.
1931 *
1932 * @hide
1933 */
1934 public void checkImmutable() {}
1935
1936 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001937 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1938 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1939 * that state. This connection should not be used for anything, and no other
1940 * {@code Connection}s should be attempted.
1941 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001942 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001943 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001944 * @return A {@code Connection} which indicates that the underlying connection should
1945 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001946 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001947 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001948 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001949 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001950
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001951 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001952 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001953 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001954 }
1955 }
1956
Santos Cordon823fd3c2014-08-07 18:35:18 -07001957 private final void fireConferenceChanged() {
1958 for (Listener l : mListeners) {
1959 l.onConferenceChanged(this, mConference);
1960 }
1961 }
1962
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001963 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001964 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001965 if (c instanceof Connection) {
1966 Connection connection = (Connection) c;
1967 connection.removeConnectionListener(mConnectionDeathListener);
1968 } else if (c instanceof Conference) {
1969 Conference conference = (Conference) c;
1970 conference.removeListener(mConferenceDeathListener);
1971 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001972 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001973 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001974 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001975
1976 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001977 * Notifies listeners that the merge request failed.
1978 *
1979 * @hide
1980 */
1981 protected final void notifyConferenceMergeFailed() {
1982 for (Listener l : mListeners) {
1983 l.onConferenceMergeFailed(this);
1984 }
1985 }
1986
1987 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001988 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001989 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001990 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001991 * @hide
1992 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001993 protected final void updateConferenceParticipants(
1994 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001995 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001996 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001997 }
1998 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001999
2000 /**
2001 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002002 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002003 */
2004 protected void notifyConferenceStarted() {
2005 for (Listener l : mListeners) {
2006 l.onConferenceStarted();
2007 }
2008 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002009
2010 /**
2011 * Sends a connection event to Telecom.
2012 *
2013 * @param event The connection event.
2014 * @hide
2015 */
2016 protected void sendConnectionEvent(String event) {
2017 for (Listener l : mListeners) {
2018 l.onConnectionEvent(this, event);
2019 }
2020 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002021}