blob: 39302081b79ad2461541653760fae8cae9f80b74 [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
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070038import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
44/**
Santos Cordon895d4b82015-06-25 16:41:48 -070045 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
46 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070047 * <p>
48 * Implementations create a custom subclass of {@code Connection} and return it to the framework
49 * as the return value of
50 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
51 * or
52 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
53 * Implementations are then responsible for updating the state of the {@code Connection}, and
54 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
55 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070056 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070057public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
Santos Cordon895d4b82015-06-25 16:41:48 -070059 /**
60 * The connection is initializing. This is generally the first state for a {@code Connection}
61 * returned by a {@link ConnectionService}.
62 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 public static final int STATE_INITIALIZING = 0;
64
Santos Cordon895d4b82015-06-25 16:41:48 -070065 /**
66 * The connection is new and not connected.
67 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 public static final int STATE_NEW = 1;
69
Santos Cordon895d4b82015-06-25 16:41:48 -070070 /**
71 * An incoming connection is in the ringing state. During this state, the user's ringer or
72 * vibration feature will be activated.
73 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 public static final int STATE_RINGING = 2;
75
Santos Cordon895d4b82015-06-25 16:41:48 -070076 /**
77 * An outgoing connection is in the dialing state. In this state the other party has not yet
78 * answered the call and the user traditionally hears a ringback tone.
79 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 public static final int STATE_DIALING = 3;
81
Santos Cordon895d4b82015-06-25 16:41:48 -070082 /**
83 * A connection is active. Both parties are connected to the call and can actively communicate.
84 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 public static final int STATE_ACTIVE = 4;
86
Santos Cordon895d4b82015-06-25 16:41:48 -070087 /**
88 * A connection is on hold.
89 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 public static final int STATE_HOLDING = 5;
91
Santos Cordon895d4b82015-06-25 16:41:48 -070092 /**
93 * A connection has been disconnected. This is the final state once the user has been
94 * disconnected from a call either locally, remotely or by an error in the service.
95 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public static final int STATE_DISCONNECTED = 6;
97
Santos Cordon895d4b82015-06-25 16:41:48 -070098 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external connection which is in the process of being pulled from a remote
100 * device to the local device.
101 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700102 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700103 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
104 */
105 public static final int STATE_PULLING_CALL = 7;
106
107 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 * Connection can currently be put on hold or unheld. This is distinct from
109 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
110 * it does not at the moment support the function. This can be true while the call is in the
111 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
112 * display a disabled 'hold' button.
113 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 public static final int CAPABILITY_HOLD = 0x00000001;
115
116 /** Connection supports the hold feature. */
117 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
118
119 /**
120 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
121 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
122 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
123 * capability allows a merge button to be shown while the conference is in the foreground
124 * of the in-call UI.
125 * <p>
126 * This is only intended for use by a {@link Conference}.
127 */
128 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
129
130 /**
131 * Connections within a conference can be swapped between foreground and background.
132 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
133 * <p>
134 * This is only intended for use by a {@link Conference}.
135 */
136 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
137
138 /**
139 * @hide
140 */
141 public static final int CAPABILITY_UNUSED = 0x00000010;
142
143 /** Connection supports responding via text option. */
144 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
145
146 /** Connection can be muted. */
147 public static final int CAPABILITY_MUTE = 0x00000040;
148
149 /**
150 * Connection supports conference management. This capability only applies to
151 * {@link Conference}s which can have {@link Connection}s as children.
152 */
153 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
154
155 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700158 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159
160 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164
165 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700168 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
175
176 /**
177 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 */
179 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
180
181 /**
182 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
188 * Connection is able to be separated from its parent {@code Conference}, if any.
189 */
190 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
191
192 /**
193 * Connection is able to be individually disconnected when in a {@code Conference}.
194 */
195 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
196
197 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700198 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 * @hide
200 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700201 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700204 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 * @hide
206 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700207 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208
209 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700210 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * @hide
212 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700213 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214
Tyler Gunn068085b2015-02-06 13:56:52 -0800215 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700216 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800217 * @hide
218 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700219 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800220
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 */
225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Tyler Gunnd4091732015-06-29 09:15:37 -0700238 /**
239 * For a conference, indicates the conference will not have child connections.
240 * <p>
241 * An example of a conference with child connections is a GSM conference call, where the radio
242 * retains connections to the individual participants of the conference. Another example is an
243 * IMS conference call where conference event package functionality is supported; in this case
244 * the conference server ensures the radio is aware of the participants in the conference, which
245 * are represented by child connections.
246 * <p>
247 * An example of a conference with no child connections is an IMS conference call with no
248 * conference event package support. Such a conference is represented by the radio as a single
249 * connection to the IMS conference server.
250 * <p>
251 * Indicating whether a conference has children or not is important to help user interfaces
252 * visually represent a conference. A conference with no children, for example, will have the
253 * conference connection shown in the list of calls on a Bluetooth device, where if the
254 * conference has children, only the children will be shown in the list of calls on a Bluetooth
255 * device.
256 * @hide
257 */
258 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259
Bryce Lee81901682015-08-28 16:38:02 -0700260 /**
261 * Indicates that the connection itself wants to handle any sort of reply response, rather than
262 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700263 */
264 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
265
Tyler Gunnf97a0092016-01-19 15:59:34 -0800266 /**
267 * When set, prevents a video call from being downgraded to an audio-only call.
268 * <p>
269 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271 * downgraded from a video call back to a VideoState of
272 * {@link VideoProfile#STATE_AUDIO_ONLY}.
273 * <p>
274 * Intuitively, a call which can be downgraded to audio should also have local and remote
275 * video
276 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278 */
279 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700281 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 * When set for an external connection, indicates that this {@code Connection} can be pulled
283 * from a remote device to the current device.
284 * <p>
285 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
286 * is set.
287 */
288 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
289
290 //**********************************************************************************************
291 // Next CAPABILITY value: 0x02000000
292 //**********************************************************************************************
293
294 /**
295 * Indicates that the current device callback number should be shown.
296 *
297 * @hide
298 */
299 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
300
301 /**
302 * Whether the call is a generic conference, where we do not know the precise state of
303 * participants in the conference (eg. on CDMA).
304 *
305 * @hide
306 */
307 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
308
309 /**
310 * Connection is using high definition audio.
311 * @hide
312 */
313 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
314
315 /**
316 * Connection is using WIFI.
317 * @hide
318 */
319 public static final int PROPERTY_WIFI = 1<<3;
320
321 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 * When set, indicates that the {@code Connection} does not actually exist locally for the
323 * {@link ConnectionService}.
324 * <p>
325 * Consider, for example, a scenario where a user has two devices with the same phone number.
326 * When a user places a call on one devices, the telephony stack can represent that call on the
327 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700328 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700329 * <p>
330 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
331 * external connections. Only those {@link InCallService}s which have the
332 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
333 * manifest will see external connections.
334 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336
Brad Ebinger15847072016-05-18 11:08:36 -0700337 /**
338 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
339 */
340 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700341
Tyler Gunn96d6c402015-03-18 12:39:23 -0700342 //**********************************************************************************************
Brad Ebinger15847072016-05-18 11:08:36 -0700343 // Next PROPERTY value: 1<<6
Tyler Gunn96d6c402015-03-18 12:39:23 -0700344 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800345
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700346 /**
347 * Connection extra key used to store the last forwarded number associated with the current
348 * connection. Used to communicate to the user interface that the connection was forwarded via
349 * the specified number.
350 */
351 public static final String EXTRA_LAST_FORWARDED_NUMBER =
352 "android.telecom.extra.LAST_FORWARDED_NUMBER";
353
354 /**
355 * Connection extra key used to store a child number associated with the current connection.
356 * Used to communicate to the user interface that the connection was received via
357 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
358 * address.
359 */
360 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
361
362 /**
363 * Connection extra key used to store the subject for an incoming call. The user interface can
364 * query this extra and display its contents for incoming calls. Will only be used if the
365 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
366 */
367 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
368
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800369 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700370 * Boolean connection extra key set on a {@link Connection} in
371 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
372 * current active foreground call to be dropped.
373 */
374 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
375 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
376
377 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800378 * Connection event used to inform Telecom that it should play the on hold tone. This is used
379 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
380 * {@link #sendConnectionEvent(String)}.
381 * @hide
382 */
383 public static final String EVENT_ON_HOLD_TONE_START =
384 "android.telecom.event.ON_HOLD_TONE_START";
385
386 /**
387 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
388 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
389 * {@link #sendConnectionEvent(String)}.
390 * @hide
391 */
392 public static final String EVENT_ON_HOLD_TONE_END =
393 "android.telecom.event.ON_HOLD_TONE_END";
394
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700395 /**
396 * Connection event used to inform {@link InCallService}s when pulling of an external call has
397 * failed. The user interface should inform the user of the error.
398 * <p>
399 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
400 * API is called on a {@link Call} with the properties
401 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
402 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
403 * pull the external call due to an error condition.
404 */
405 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
406
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700407 /**
408 * Connection event used to inform {@link InCallService}s when the merging of two calls has
409 * failed. The User Interface should use this message to inform the user of the error.
410 */
411 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
412
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700413 // Flag controlling whether PII is emitted into the logs
414 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
415
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800416 /**
417 * Whether the given capabilities support the specified capability.
418 *
419 * @param capabilities A capability bit field.
420 * @param capability The capability to check capabilities for.
421 * @return Whether the specified capability is supported.
422 * @hide
423 */
424 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800425 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800426 }
427
428 /**
429 * Whether the capabilities of this {@code Connection} supports the specified capability.
430 *
431 * @param capability The capability to check capabilities for.
432 * @return Whether the specified capability is supported.
433 * @hide
434 */
435 public boolean can(int capability) {
436 return can(mConnectionCapabilities, capability);
437 }
438
439 /**
440 * Removes the specified capability from the set of capabilities of this {@code Connection}.
441 *
442 * @param capability The capability to remove from the set.
443 * @hide
444 */
445 public void removeCapability(int capability) {
446 mConnectionCapabilities &= ~capability;
447 }
448
449 /**
450 * Adds the specified capability to the set of capabilities of this {@code Connection}.
451 *
452 * @param capability The capability to add to the set.
453 * @hide
454 */
455 public void addCapability(int capability) {
456 mConnectionCapabilities |= capability;
457 }
458
459
460 public static String capabilitiesToString(int capabilities) {
461 StringBuilder builder = new StringBuilder();
462 builder.append("[Capabilities:");
463 if (can(capabilities, CAPABILITY_HOLD)) {
464 builder.append(" CAPABILITY_HOLD");
465 }
466 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
467 builder.append(" CAPABILITY_SUPPORT_HOLD");
468 }
469 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
470 builder.append(" CAPABILITY_MERGE_CONFERENCE");
471 }
472 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
473 builder.append(" CAPABILITY_SWAP_CONFERENCE");
474 }
475 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
476 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
477 }
478 if (can(capabilities, CAPABILITY_MUTE)) {
479 builder.append(" CAPABILITY_MUTE");
480 }
481 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
482 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
483 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700484 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
485 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
486 }
487 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
488 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
489 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700490 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
491 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800492 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700493 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
494 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
495 }
496 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
497 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
498 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700499 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
500 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800501 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800502 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
503 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
504 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500505 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700506 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500507 }
Rekha Kumar07366812015-03-24 16:42:31 -0700508 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
509 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
510 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700511 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
512 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
513 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700514 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
515 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
516 }
Bryce Lee81901682015-08-28 16:38:02 -0700517 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
518 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
519 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700520 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
521 builder.append(" CAPABILITY_CAN_PULL_CALL");
522 }
Bryce Lee81901682015-08-28 16:38:02 -0700523
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800524 builder.append("]");
525 return builder.toString();
526 }
527
Tyler Gunn720c6642016-03-22 09:02:47 -0700528 public static String propertiesToString(int properties) {
529 StringBuilder builder = new StringBuilder();
530 builder.append("[Properties:");
531
532 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
533 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
534 }
535
536 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
537 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
538 }
539
540 if (can(properties, PROPERTY_WIFI)) {
541 builder.append(" PROPERTY_WIFI");
542 }
543
544 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
545 builder.append(" PROPERTY_GENERIC_CONFERENCE");
546 }
547
548 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
549 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
550 }
551
Brad Ebinger15847072016-05-18 11:08:36 -0700552 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
553 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
554 }
555
Tyler Gunn720c6642016-03-22 09:02:47 -0700556 builder.append("]");
557 return builder.toString();
558 }
559
Sailesh Nepal091768c2014-06-30 15:15:23 -0700560 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700561 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700562 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700563 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700564 public void onCallerDisplayNameChanged(
565 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700566 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700567 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700568 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800569 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700570 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700571 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800572 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700573 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700574 public void onVideoProviderChanged(
575 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700576 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
577 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800578 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700579 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700580 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700581 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800582 public void onConferenceParticipantsChanged(Connection c,
583 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800584 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700585 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700586 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700587 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700588 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700589 }
590
Tyler Gunnb702ef82015-05-29 11:51:53 -0700591 /**
592 * Provides a means of controlling the video session associated with a {@link Connection}.
593 * <p>
594 * Implementations create a custom subclass of {@link VideoProvider} and the
595 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
596 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
597 * should set the {@link VideoProvider}.
598 * <p>
599 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
600 * {@link InCallService} implementations to issue requests related to the video session;
601 * it provides a means for the {@link ConnectionService} to report events and information
602 * related to the video session to Telecom and the {@link InCallService} implementations.
603 * <p>
604 * {@link InCallService} implementations interact with the {@link VideoProvider} via
605 * {@link android.telecom.InCallService.VideoCall}.
606 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700607 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700608
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 /**
610 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700611 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 */
613 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700614
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700616 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
617 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 */
619 public static final int SESSION_EVENT_RX_RESUME = 2;
620
621 /**
622 * Video transmission has begun. This occurs after a negotiated start of video transmission
623 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700624 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 */
626 public static final int SESSION_EVENT_TX_START = 3;
627
628 /**
629 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
630 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700631 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 */
633 public static final int SESSION_EVENT_TX_STOP = 4;
634
635 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700636 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
637 * this as a cue to inform the user the camera is not available.
638 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 */
640 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
641
642 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700643 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
644 * for operation. The {@link InCallService} can use this as a cue to inform the user that
645 * the camera has become available again.
646 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 */
648 public static final int SESSION_EVENT_CAMERA_READY = 6;
649
650 /**
651 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700652 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 */
654 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
655
656 /**
657 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700658 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700659 */
660 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
661
662 /**
663 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700664 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 */
666 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
667
Rekha Kumar07366812015-03-24 16:42:31 -0700668 /**
669 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700670 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700671 */
672 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
673
674 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700675 * Session modify request rejected by remote user.
676 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700677 */
678 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
679
Tyler Gunn75958422015-04-15 14:23:42 -0700680 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700681 private static final int MSG_SET_CAMERA = 2;
682 private static final int MSG_SET_PREVIEW_SURFACE = 3;
683 private static final int MSG_SET_DISPLAY_SURFACE = 4;
684 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
685 private static final int MSG_SET_ZOOM = 6;
686 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
687 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
688 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700691 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700693 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700695
696 /**
697 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700698 *
699 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
700 * load factor before resizing, 1 means we only expect a single thread to
701 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700702 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700703 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
704 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705
706 /**
707 * Default handler used to consolidate binder method calls onto a single thread.
708 */
709 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700710 public VideoProviderHandler() {
711 super();
712 }
713
714 public VideoProviderHandler(Looper looper) {
715 super(looper);
716 }
717
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700718 @Override
719 public void handleMessage(Message msg) {
720 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700721 case MSG_ADD_VIDEO_CALLBACK: {
722 IBinder binder = (IBinder) msg.obj;
723 IVideoCallback callback = IVideoCallback.Stub
724 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700725 if (callback == null) {
726 Log.w(this, "addVideoProvider - skipped; callback is null.");
727 break;
728 }
729
Tyler Gunn75958422015-04-15 14:23:42 -0700730 if (mVideoCallbacks.containsKey(binder)) {
731 Log.i(this, "addVideoProvider - skipped; already present.");
732 break;
733 }
734 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700735 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700736 }
737 case MSG_REMOVE_VIDEO_CALLBACK: {
738 IBinder binder = (IBinder) msg.obj;
739 IVideoCallback callback = IVideoCallback.Stub
740 .asInterface((IBinder) msg.obj);
741 if (!mVideoCallbacks.containsKey(binder)) {
742 Log.i(this, "removeVideoProvider - skipped; not present.");
743 break;
744 }
745 mVideoCallbacks.remove(binder);
746 break;
747 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 case MSG_SET_CAMERA:
749 onSetCamera((String) msg.obj);
750 break;
751 case MSG_SET_PREVIEW_SURFACE:
752 onSetPreviewSurface((Surface) msg.obj);
753 break;
754 case MSG_SET_DISPLAY_SURFACE:
755 onSetDisplaySurface((Surface) msg.obj);
756 break;
757 case MSG_SET_DEVICE_ORIENTATION:
758 onSetDeviceOrientation(msg.arg1);
759 break;
760 case MSG_SET_ZOOM:
761 onSetZoom((Float) msg.obj);
762 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700763 case MSG_SEND_SESSION_MODIFY_REQUEST: {
764 SomeArgs args = (SomeArgs) msg.obj;
765 try {
766 onSendSessionModifyRequest((VideoProfile) args.arg1,
767 (VideoProfile) args.arg2);
768 } finally {
769 args.recycle();
770 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700771 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700772 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 case MSG_SEND_SESSION_MODIFY_RESPONSE:
774 onSendSessionModifyResponse((VideoProfile) msg.obj);
775 break;
776 case MSG_REQUEST_CAMERA_CAPABILITIES:
777 onRequestCameraCapabilities();
778 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800779 case MSG_REQUEST_CONNECTION_DATA_USAGE:
780 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 break;
782 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700783 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700784 break;
785 default:
786 break;
787 }
788 }
789 }
790
791 /**
792 * IVideoProvider stub implementation.
793 */
794 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700795 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700797 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
798 }
799
800 public void removeVideoCallback(IBinder videoCallbackBinder) {
801 mMessageHandler.obtainMessage(
802 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700803 }
804
805 public void setCamera(String cameraId) {
806 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
807 }
808
809 public void setPreviewSurface(Surface surface) {
810 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
811 }
812
813 public void setDisplaySurface(Surface surface) {
814 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
815 }
816
817 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700818 mMessageHandler.obtainMessage(
819 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 }
821
822 public void setZoom(float value) {
823 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
824 }
825
Tyler Gunn45382162015-05-06 08:52:27 -0700826 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
827 SomeArgs args = SomeArgs.obtain();
828 args.arg1 = fromProfile;
829 args.arg2 = toProfile;
830 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 }
832
833 public void sendSessionModifyResponse(VideoProfile responseProfile) {
834 mMessageHandler.obtainMessage(
835 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
836 }
837
838 public void requestCameraCapabilities() {
839 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
840 }
841
842 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800843 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700844 }
845
Yorke Lee32f24732015-05-12 16:18:03 -0700846 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700847 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
848 }
849 }
850
851 public VideoProvider() {
852 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700853 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700854 }
855
856 /**
857 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
858 *
859 * @param looper The looper.
860 * @hide
861 */
862 public VideoProvider(Looper looper) {
863 mBinder = new VideoProvider.VideoProviderBinder();
864 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 }
866
867 /**
868 * Returns binder object which can be used across IPC methods.
869 * @hide
870 */
871 public final IVideoProvider getInterface() {
872 return mBinder;
873 }
874
875 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700876 * Sets the camera to be used for the outgoing video.
877 * <p>
878 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
879 * camera via
880 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
881 * <p>
882 * Sent from the {@link InCallService} via
883 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700885 * @param cameraId The id of the camera (use ids as reported by
886 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887 */
888 public abstract void onSetCamera(String cameraId);
889
890 /**
891 * Sets the surface to be used for displaying a preview of what the user's camera is
892 * currently capturing. When video transmission is enabled, this is the video signal which
893 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700894 * <p>
895 * Sent from the {@link InCallService} via
896 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700899 */
900 public abstract void onSetPreviewSurface(Surface surface);
901
902 /**
903 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * <p>
905 * Sent from the {@link InCallService} via
906 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700908 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 */
910 public abstract void onSetDisplaySurface(Surface surface);
911
912 /**
913 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
914 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700915 * <p>
916 * Sent from the {@link InCallService} via
917 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700918 *
919 * @param rotation The device orientation, in degrees.
920 */
921 public abstract void onSetDeviceOrientation(int rotation);
922
923 /**
924 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700925 * <p>
926 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 *
928 * @param value The camera zoom ratio.
929 */
930 public abstract void onSetZoom(float value);
931
932 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700933 * Issues a request to modify the properties of the current video session.
934 * <p>
935 * Example scenarios include: requesting an audio-only call to be upgraded to a
936 * bi-directional video call, turning on or off the user's camera, sending a pause signal
937 * when the {@link InCallService} is no longer the foreground application.
938 * <p>
939 * If the {@link VideoProvider} determines a request to be invalid, it should call
940 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
941 * invalid request back to the {@link InCallService}.
942 * <p>
943 * Where a request requires confirmation from the user of the peer device, the
944 * {@link VideoProvider} must communicate the request to the peer device and handle the
945 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
946 * is used to inform the {@link InCallService} of the result of the request.
947 * <p>
948 * Sent from the {@link InCallService} via
949 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700951 * @param fromProfile The video profile prior to the request.
952 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 */
Tyler Gunn45382162015-05-06 08:52:27 -0700954 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
955 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700956
Tyler Gunnb702ef82015-05-29 11:51:53 -0700957 /**
958 * Provides a response to a request to change the current video session properties.
959 * <p>
960 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
961 * video call, could decline the request and keep the call as audio-only.
962 * In such a scenario, the {@code responseProfile} would have a video state of
963 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
964 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
965 * <p>
966 * Sent from the {@link InCallService} via
967 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
968 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
969 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700971 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 */
973 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
974
975 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700976 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
977 * <p>
978 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
979 * camera via
980 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
981 * <p>
982 * Sent from the {@link InCallService} via
983 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 */
985 public abstract void onRequestCameraCapabilities();
986
987 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
989 * video component of the current {@link Connection}.
990 * <p>
991 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
992 * via {@link VideoProvider#setCallDataUsage(long)}.
993 * <p>
994 * Sent from the {@link InCallService} via
995 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700996 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998
999 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001000 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1001 * the peer device when the video signal is paused.
1002 * <p>
1003 * Sent from the {@link InCallService} via
1004 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 *
1006 * @param uri URI of image to display.
1007 */
Yorke Lee32f24732015-05-12 16:18:03 -07001008 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009
1010 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001011 * Used to inform listening {@link InCallService} implementations when the
1012 * {@link VideoProvider} receives a session modification request.
1013 * <p>
1014 * Received by the {@link InCallService} via
1015 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001017 * @param videoProfile The requested video profile.
1018 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 */
1020 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001021 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001022 for (IVideoCallback callback : mVideoCallbacks.values()) {
1023 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001024 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001025 } catch (RemoteException ignored) {
1026 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001027 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001028 }
1029 }
1030 }
1031
1032 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * Used to inform listening {@link InCallService} implementations when the
1034 * {@link VideoProvider} receives a response to a session modification request.
1035 * <p>
1036 * Received by the {@link InCallService} via
1037 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1038 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 *
1040 * @param status Status of the session modify request. Valid values are
1041 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1042 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1044 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1045 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1046 * @param requestedProfile The original request which was sent to the peer device.
1047 * @param responseProfile The actual profile changes agreed to by the peer device.
1048 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 */
1050 public void receiveSessionModifyResponse(int status,
1051 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001052 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001053 for (IVideoCallback callback : mVideoCallbacks.values()) {
1054 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001055 callback.receiveSessionModifyResponse(status, requestedProfile,
1056 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001057 } catch (RemoteException ignored) {
1058 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001059 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 }
1061 }
1062 }
1063
1064 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001065 * Used to inform listening {@link InCallService} implementations when the
1066 * {@link VideoProvider} reports a call session event.
1067 * <p>
1068 * Received by the {@link InCallService} via
1069 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001070 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001071 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1072 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1073 * {@link VideoProvider#SESSION_EVENT_TX_START},
1074 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1075 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1076 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 */
1078 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001079 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001080 for (IVideoCallback callback : mVideoCallbacks.values()) {
1081 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001082 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001083 } catch (RemoteException ignored) {
1084 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001085 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 }
1087 }
1088 }
1089
1090 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001091 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1092 * peer's video have changed.
1093 * <p>
1094 * This could occur if, for example, the peer rotates their device, changing the aspect
1095 * ratio of the video, or if the user switches between the back and front cameras.
1096 * <p>
1097 * Received by the {@link InCallService} via
1098 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001099 *
1100 * @param width The updated peer video width.
1101 * @param height The updated peer video height.
1102 */
1103 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001104 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001105 for (IVideoCallback callback : mVideoCallbacks.values()) {
1106 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001107 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001108 } catch (RemoteException ignored) {
1109 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001110 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 }
1112 }
1113 }
1114
1115 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001116 * Used to inform listening {@link InCallService} implementations when the data usage of the
1117 * video associated with the current {@link Connection} has changed.
1118 * <p>
1119 * This could be in response to a preview request via
1120 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001121 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1122 * 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 -07001123 * <p>
1124 * Received by the {@link InCallService} via
1125 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001127 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1128 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001129 */
Yorke Lee32f24732015-05-12 16:18:03 -07001130 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001131 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001132 for (IVideoCallback callback : mVideoCallbacks.values()) {
1133 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001134 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001135 } catch (RemoteException ignored) {
1136 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001137 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001138 }
1139 }
1140 }
1141
1142 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001143 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001145 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001146 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1147 * @hide
1148 */
1149 public void changeCallDataUsage(long dataUsage) {
1150 setCallDataUsage(dataUsage);
1151 }
1152
1153 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001154 * Used to inform listening {@link InCallService} implementations when the capabilities of
1155 * the current camera have changed.
1156 * <p>
1157 * The {@link VideoProvider} should call this in response to
1158 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1159 * changed via {@link VideoProvider#onSetCamera(String)}.
1160 * <p>
1161 * Received by the {@link InCallService} via
1162 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1163 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001164 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001165 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 */
Yorke Lee400470f2015-05-12 13:31:25 -07001167 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001168 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001169 for (IVideoCallback callback : mVideoCallbacks.values()) {
1170 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001171 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001172 } catch (RemoteException ignored) {
1173 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001174 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 }
1176 }
1177 }
Rekha Kumar07366812015-03-24 16:42:31 -07001178
1179 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001180 * Used to inform listening {@link InCallService} implementations when the video quality
1181 * of the call has changed.
1182 * <p>
1183 * Received by the {@link InCallService} via
1184 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001185 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001186 * @param videoQuality The updated video quality. Valid values:
1187 * {@link VideoProfile#QUALITY_HIGH},
1188 * {@link VideoProfile#QUALITY_MEDIUM},
1189 * {@link VideoProfile#QUALITY_LOW},
1190 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001191 */
1192 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001193 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001194 for (IVideoCallback callback : mVideoCallbacks.values()) {
1195 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001196 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001197 } catch (RemoteException ignored) {
1198 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001199 }
Rekha Kumar07366812015-03-24 16:42:31 -07001200 }
1201 }
1202 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001203 }
1204
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001205 private final Listener mConnectionDeathListener = new Listener() {
1206 @Override
1207 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001208 if (mConferenceables.remove(c)) {
1209 fireOnConferenceableConnectionsChanged();
1210 }
1211 }
1212 };
1213
1214 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1215 @Override
1216 public void onDestroyed(Conference c) {
1217 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001218 fireOnConferenceableConnectionsChanged();
1219 }
1220 }
1221 };
1222
Jay Shrauner229e3822014-08-15 09:23:07 -07001223 /**
1224 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1225 * load factor before resizing, 1 means we only expect a single thread to
1226 * access the map so make only a single shard
1227 */
1228 private final Set<Listener> mListeners = Collections.newSetFromMap(
1229 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001230 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1231 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001232 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001233
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001234 // The internal telecom call ID associated with this connection.
1235 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001236 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001237 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001238 private Uri mAddress;
1239 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001240 private String mCallerDisplayName;
1241 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001242 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001243 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001244 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001245 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001246 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001247 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001248 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001249 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001250 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001251 private Conference mConference;
1252 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001253 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001254 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001255
1256 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001257 * Tracks the key set for the extras bundle provided on the last invocation of
1258 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1259 * keys which were set previously but are no longer present in the replacement Bundle.
1260 */
1261 private Set<String> mPreviousExtraKeys;
1262
1263 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 * Create a new Connection.
1265 */
Santos Cordonf2951102014-07-20 19:06:29 -07001266 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001267
1268 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001269 * Returns the Telecom internal call ID associated with this connection. Should only be used
1270 * for debugging and tracing purposes.
1271 *
1272 * @return The Telecom call ID.
1273 * @hide
1274 */
1275 public final String getTelecomCallId() {
1276 return mTelecomCallId;
1277 }
1278
1279 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001280 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001281 */
Andrew Lee100e2932014-09-08 15:34:24 -07001282 public final Uri getAddress() {
1283 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001284 }
1285
1286 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001287 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001288 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001289 */
Andrew Lee100e2932014-09-08 15:34:24 -07001290 public final int getAddressPresentation() {
1291 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001292 }
1293
1294 /**
1295 * @return The caller display name (CNAP).
1296 */
1297 public final String getCallerDisplayName() {
1298 return mCallerDisplayName;
1299 }
1300
1301 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001302 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001303 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001304 */
1305 public final int getCallerDisplayNamePresentation() {
1306 return mCallerDisplayNamePresentation;
1307 }
1308
1309 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001310 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001311 */
1312 public final int getState() {
1313 return mState;
1314 }
1315
1316 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001317 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001318 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1319 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1320 * {@link VideoProfile#STATE_TX_ENABLED},
1321 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001322 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001323 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001324 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001325 */
1326 public final int getVideoState() {
1327 return mVideoState;
1328 }
1329
1330 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001331 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001332 * being routed by the system. This is {@code null} if this Connection
1333 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001334 * @deprecated Use {@link #getCallAudioState()} instead.
1335 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001336 */
Yorke Lee4af59352015-05-13 14:14:54 -07001337 @SystemApi
1338 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001340 if (mCallAudioState == null) {
1341 return null;
1342 }
Yorke Lee4af59352015-05-13 14:14:54 -07001343 return new AudioState(mCallAudioState);
1344 }
1345
1346 /**
1347 * @return The audio state of the connection, describing how its audio is currently
1348 * being routed by the system. This is {@code null} if this Connection
1349 * does not directly know about its audio state.
1350 */
1351 public final CallAudioState getCallAudioState() {
1352 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001353 }
1354
1355 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001356 * @return The conference that this connection is a part of. Null if it is not part of any
1357 * conference.
1358 */
1359 public final Conference getConference() {
1360 return mConference;
1361 }
1362
1363 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001364 * Returns whether this connection is requesting that the system play a ringback tone
1365 * on its behalf.
1366 */
Andrew Lee100e2932014-09-08 15:34:24 -07001367 public final boolean isRingbackRequested() {
1368 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001369 }
1370
1371 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001372 * @return True if the connection's audio mode is VOIP.
1373 */
1374 public final boolean getAudioModeIsVoip() {
1375 return mAudioModeIsVoip;
1376 }
1377
1378 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001379 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1380 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1381 * start time of the conference.
1382 *
1383 * @return The time at which the {@code Connnection} was connected.
1384 *
1385 * @hide
1386 */
1387 public final long getConnectTimeMillis() {
1388 return mConnectTimeMillis;
1389 }
1390
1391 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001392 * @return The status hints for this connection.
1393 */
1394 public final StatusHints getStatusHints() {
1395 return mStatusHints;
1396 }
1397
1398 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001399 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001400 * <p>
1401 * Extras should be updated using {@link #putExtras(Bundle)}.
1402 * <p>
1403 * Telecom or an {@link InCallService} can also update the extras via
1404 * {@link android.telecom.Call#putExtras(Bundle)}, and
1405 * {@link Call#removeExtras(List)}.
1406 * <p>
1407 * The connection is notified of changes to the extras made by Telecom or an
1408 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001409 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001410 * @return The extras associated with this connection.
1411 */
1412 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001413 Bundle extras = null;
1414 synchronized (mExtrasLock) {
1415 if (mExtras != null) {
1416 extras = new Bundle(mExtras);
1417 }
1418 }
1419 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001420 }
1421
1422 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001423 * Assign a listener to be notified of state changes.
1424 *
1425 * @param l A listener.
1426 * @return This Connection.
1427 *
1428 * @hide
1429 */
1430 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001431 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001432 return this;
1433 }
1434
1435 /**
1436 * Remove a previously assigned listener that was being notified of state changes.
1437 *
1438 * @param l A Listener.
1439 * @return This Connection.
1440 *
1441 * @hide
1442 */
1443 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001444 if (l != null) {
1445 mListeners.remove(l);
1446 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001447 return this;
1448 }
1449
1450 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001451 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001452 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001453 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001454 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001455 }
1456
1457 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001458 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1459 * ONLY for debugging purposes.
1460 *
1461 * @param callId The telecom call ID.
1462 * @hide
1463 */
1464 public void setTelecomCallId(String callId) {
1465 mTelecomCallId = callId;
1466 }
1467
1468 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001469 * Inform this Connection that the state of its audio output has been changed externally.
1470 *
1471 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001472 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001473 */
Yorke Lee4af59352015-05-13 14:14:54 -07001474 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001475 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001476 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001477 mCallAudioState = state;
1478 onAudioStateChanged(getAudioState());
1479 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001480 }
1481
1482 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484 * @return A string representation of the value.
1485 */
1486 public static String stateToString(int state) {
1487 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001489 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001491 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001493 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001494 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001495 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001497 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001499 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001501 return "DISCONNECTED";
1502 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001503 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001504 return "UNKNOWN";
1505 }
1506 }
1507
1508 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001509 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001510 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001511 public final int getConnectionCapabilities() {
1512 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001513 }
1514
1515 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001516 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1517 */
1518 public final int getConnectionProperties() {
1519 return mConnectionProperties;
1520 }
1521
1522 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001523 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001524 *
Andrew Lee100e2932014-09-08 15:34:24 -07001525 * @param address The new address.
1526 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001527 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001528 */
Andrew Lee100e2932014-09-08 15:34:24 -07001529 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001530 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001531 Log.d(this, "setAddress %s", address);
1532 mAddress = address;
1533 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001534 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001535 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001536 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001537 }
1538
1539 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001540 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001541 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001542 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001543 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001544 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001545 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001546 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001547 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001548 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001549 mCallerDisplayName = callerDisplayName;
1550 mCallerDisplayNamePresentation = presentation;
1551 for (Listener l : mListeners) {
1552 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1553 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001554 }
1555
1556 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001557 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001558 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1559 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1560 * {@link VideoProfile#STATE_TX_ENABLED},
1561 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001562 *
1563 * @param videoState The new video state.
1564 */
1565 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001566 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001567 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001568 mVideoState = videoState;
1569 for (Listener l : mListeners) {
1570 l.onVideoStateChanged(this, mVideoState);
1571 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001572 }
1573
1574 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001575 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001576 * communicate).
1577 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001578 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001579 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001580 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001581 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001582 }
1583
1584 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001585 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001586 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001587 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001588 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001590 }
1591
1592 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001593 * Sets state to initializing (this Connection is not yet ready to be used).
1594 */
1595 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001596 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001598 }
1599
1600 /**
1601 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1602 */
1603 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001604 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001606 }
1607
1608 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001609 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001610 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001611 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001612 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001613 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001614 }
1615
1616 /**
1617 * Sets state to be on hold.
1618 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001619 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001620 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001621 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001622 }
1623
1624 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001625 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001626 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001627 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001629 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001630 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001631 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001632 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001633 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001634 }
1635
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001636 public final VideoProvider getVideoProvider() {
1637 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001638 }
1639
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001640 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001641 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001642 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001643 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001644 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001645 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001646 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001647 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001648 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001650 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001651 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001652 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001653 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001654 }
1655
1656 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001657 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1658 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1659 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1660 * to send an {@link #onPostDialContinue(boolean)} signal.
1661 *
1662 * @param remaining The DTMF character sequence remaining to be emitted once the
1663 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1664 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001665 */
1666 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001667 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001668 for (Listener l : mListeners) {
1669 l.onPostDialWait(this, remaining);
1670 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001671 }
1672
1673 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001674 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1675 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001676 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001677 *
1678 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001679 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001680 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001681 checkImmutable();
1682 for (Listener l : mListeners) {
1683 l.onPostDialChar(this, nextChar);
1684 }
1685 }
1686
1687 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001688 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001689 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001690 *
1691 * @param ringback Whether the ringback tone is to be played.
1692 */
Andrew Lee100e2932014-09-08 15:34:24 -07001693 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001694 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001695 if (mRingbackRequested != ringback) {
1696 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001697 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001698 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001699 }
1700 }
Ihab Awadf8358972014-05-28 16:46:42 -07001701 }
1702
1703 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001704 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001705 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001706 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001707 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001708 public final void setConnectionCapabilities(int connectionCapabilities) {
1709 checkImmutable();
1710 if (mConnectionCapabilities != connectionCapabilities) {
1711 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001712 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001713 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001714 }
1715 }
Santos Cordonb6939982014-06-04 20:20:58 -07001716 }
1717
1718 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001719 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1720 *
1721 * @param connectionProperties The new connection properties.
1722 */
1723 public final void setConnectionProperties(int connectionProperties) {
1724 checkImmutable();
1725 if (mConnectionProperties != connectionProperties) {
1726 mConnectionProperties = connectionProperties;
1727 for (Listener l : mListeners) {
1728 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1729 }
1730 }
1731 }
1732
1733 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001734 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001735 */
Evan Charlton36a71342014-07-19 16:31:02 -07001736 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001737 for (Listener l : mListeners) {
1738 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001739 }
Santos Cordonb6939982014-06-04 20:20:58 -07001740 }
1741
1742 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001743 * Requests that the framework use VOIP audio mode for this connection.
1744 *
1745 * @param isVoip True if the audio mode is VOIP.
1746 */
1747 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001748 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001749 mAudioModeIsVoip = isVoip;
1750 for (Listener l : mListeners) {
1751 l.onAudioModeIsVoipChanged(this, isVoip);
1752 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001753 }
1754
1755 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001756 * Sets the time at which a call became active on this Connection. This is set only
1757 * when a conference call becomes active on this connection.
1758 *
1759 * @param connectionTimeMillis The connection time, in milliseconds.
1760 *
1761 * @hide
1762 */
1763 public final void setConnectTimeMillis(long connectTimeMillis) {
1764 mConnectTimeMillis = connectTimeMillis;
1765 }
1766
1767 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001768 * Sets the label and icon status to display in the in-call UI.
1769 *
1770 * @param statusHints The status label and icon to set.
1771 */
1772 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001773 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001774 mStatusHints = statusHints;
1775 for (Listener l : mListeners) {
1776 l.onStatusHintsChanged(this, statusHints);
1777 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001778 }
1779
1780 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001781 * Sets the connections with which this connection can be conferenced.
1782 *
1783 * @param conferenceableConnections The set of connections this connection can conference with.
1784 */
1785 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001786 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001787 clearConferenceableList();
1788 for (Connection c : conferenceableConnections) {
1789 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1790 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001791 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001792 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001793 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001794 }
1795 }
1796 fireOnConferenceableConnectionsChanged();
1797 }
1798
1799 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001800 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1801 * or conferences with which this connection can be conferenced.
1802 *
1803 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001804 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001805 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001806 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001807 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001808 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1809 // small amount of items here.
1810 if (!mConferenceables.contains(c)) {
1811 if (c instanceof Connection) {
1812 Connection connection = (Connection) c;
1813 connection.addConnectionListener(mConnectionDeathListener);
1814 } else if (c instanceof Conference) {
1815 Conference conference = (Conference) c;
1816 conference.addListener(mConferenceDeathListener);
1817 }
1818 mConferenceables.add(c);
1819 }
1820 }
1821 fireOnConferenceableConnectionsChanged();
1822 }
1823
1824 /**
1825 * Returns the connections or conferences with which this connection can be conferenced.
1826 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001827 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001828 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001829 }
1830
Yorke Lee53463962015-08-04 16:07:19 -07001831 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001832 * @hide
1833 */
1834 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001835 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001836 if (mConnectionService != null) {
1837 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1838 "which is already associated with another ConnectionService.");
1839 } else {
1840 mConnectionService = connectionService;
1841 }
1842 }
1843
1844 /**
1845 * @hide
1846 */
1847 public final void unsetConnectionService(ConnectionService connectionService) {
1848 if (mConnectionService != connectionService) {
1849 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1850 "that does not belong to the ConnectionService.");
1851 } else {
1852 mConnectionService = null;
1853 }
1854 }
1855
1856 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001857 * @hide
1858 */
1859 public final ConnectionService getConnectionService() {
1860 return mConnectionService;
1861 }
1862
1863 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001864 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001865 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001866 *
1867 * @param conference The conference.
1868 * @return {@code true} if the conference was successfully set.
1869 * @hide
1870 */
1871 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001872 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001873 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001874 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001875 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001876 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1877 fireConferenceChanged();
1878 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001879 return true;
1880 }
1881 return false;
1882 }
1883
1884 /**
1885 * Resets the conference that this connection is a part of.
1886 * @hide
1887 */
1888 public final void resetConference() {
1889 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001890 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001891 mConference = null;
1892 fireConferenceChanged();
1893 }
1894 }
1895
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001896 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001897 * Set some extras that can be associated with this {@code Connection}.
1898 * <p>
1899 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1900 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1901 * <p>
1902 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001903 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1904 *
1905 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001906 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1907 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001908 */
1909 public final void setExtras(@Nullable Bundle extras) {
1910 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001911
1912 // Add/replace any new or changed extras values.
1913 putExtras(extras);
1914
1915 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1916 // the current one and remove any keys that went away.
1917 if (mPreviousExtraKeys != null) {
1918 List<String> toRemove = new ArrayList<String>();
1919 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001920 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001921 toRemove.add(oldKey);
1922 }
1923 }
1924 if (!toRemove.isEmpty()) {
1925 removeExtras(toRemove);
1926 }
1927 }
1928
1929 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1930 // called we can see if the caller has removed any extras values.
1931 if (mPreviousExtraKeys == null) {
1932 mPreviousExtraKeys = new ArraySet<String>();
1933 }
1934 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001935 if (extras != null) {
1936 mPreviousExtraKeys.addAll(extras.keySet());
1937 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001938 }
1939
1940 /**
1941 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1942 * added.
1943 * <p>
1944 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1945 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1946 *
1947 * @param extras The extras to add.
1948 */
1949 public final void putExtras(@NonNull Bundle extras) {
1950 checkImmutable();
1951 if (extras == null) {
1952 return;
1953 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001954 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
1955 // the listeners.
1956 Bundle listenerExtras;
1957 synchronized (mExtrasLock) {
1958 if (mExtras == null) {
1959 mExtras = new Bundle();
1960 }
1961 mExtras.putAll(extras);
1962 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07001963 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001964 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001965 // Create a new clone of the extras for each listener so that they don't clobber
1966 // each other
1967 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07001968 }
1969 }
1970
1971 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001972 * Adds a boolean extra to this {@code Connection}.
1973 *
1974 * @param key The extra key.
1975 * @param value The value.
1976 * @hide
1977 */
1978 public final void putExtra(String key, boolean value) {
1979 Bundle newExtras = new Bundle();
1980 newExtras.putBoolean(key, value);
1981 putExtras(newExtras);
1982 }
1983
1984 /**
1985 * Adds an integer extra to this {@code Connection}.
1986 *
1987 * @param key The extra key.
1988 * @param value The value.
1989 * @hide
1990 */
1991 public final void putExtra(String key, int value) {
1992 Bundle newExtras = new Bundle();
1993 newExtras.putInt(key, value);
1994 putExtras(newExtras);
1995 }
1996
1997 /**
1998 * Adds a string extra to this {@code Connection}.
1999 *
2000 * @param key The extra key.
2001 * @param value The value.
2002 * @hide
2003 */
2004 public final void putExtra(String key, String value) {
2005 Bundle newExtras = new Bundle();
2006 newExtras.putString(key, value);
2007 putExtras(newExtras);
2008 }
2009
2010 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002011 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002012 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002013 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002014 */
2015 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002016 synchronized (mExtrasLock) {
2017 if (mExtras != null) {
2018 for (String key : keys) {
2019 mExtras.remove(key);
2020 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002021 }
2022 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002023 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002024 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002025 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002026 }
2027 }
2028
2029 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002030 * Removes extras from this {@code Connection}.
2031 *
2032 * @param keys The keys of the extras to remove.
2033 */
2034 public final void removeExtras(String ... keys) {
2035 removeExtras(Arrays.asList(keys));
2036 }
2037
2038 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002039 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002040 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002041 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002042 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2043 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002044 */
Yorke Lee4af59352015-05-13 14:14:54 -07002045 @SystemApi
2046 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002047 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002048
2049 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002050 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2051 *
2052 * @param state The new connection audio state.
2053 */
2054 public void onCallAudioStateChanged(CallAudioState state) {}
2055
2056 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002057 * Notifies this Connection of an internal state change. This method is called after the
2058 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002059 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002060 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002061 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002062 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002063
2064 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065 * Notifies this Connection of a request to play a DTMF tone.
2066 *
2067 * @param c A DTMF character.
2068 */
Santos Cordonf2951102014-07-20 19:06:29 -07002069 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070
2071 /**
2072 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2073 */
Santos Cordonf2951102014-07-20 19:06:29 -07002074 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002075
2076 /**
2077 * Notifies this Connection of a request to disconnect.
2078 */
Santos Cordonf2951102014-07-20 19:06:29 -07002079 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002080
2081 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002082 * Notifies this Connection of a request to disconnect a participant of the conference managed
2083 * by the connection.
2084 *
2085 * @param endpoint the {@link Uri} of the participant to disconnect.
2086 * @hide
2087 */
2088 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2089
2090 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002091 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002092 */
Santos Cordonf2951102014-07-20 19:06:29 -07002093 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002094
2095 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002096 * Notifies this Connection of a request to abort.
2097 */
Santos Cordonf2951102014-07-20 19:06:29 -07002098 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002099
2100 /**
2101 * Notifies this Connection of a request to hold.
2102 */
Santos Cordonf2951102014-07-20 19:06:29 -07002103 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002104
2105 /**
2106 * Notifies this Connection of a request to exit a hold state.
2107 */
Santos Cordonf2951102014-07-20 19:06:29 -07002108 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002109
2110 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002111 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002112 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002113 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002114 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002115 */
Santos Cordonf2951102014-07-20 19:06:29 -07002116 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002117
2118 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002119 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002120 * a request to accept.
2121 */
2122 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002123 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002124 }
2125
2126 /**
2127 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002128 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002129 */
Santos Cordonf2951102014-07-20 19:06:29 -07002130 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002132 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002133 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2134 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002135 */
2136 public void onReject(String replyMessage) {}
2137
2138 /**
Bryce Leecac50772015-11-17 15:13:29 -08002139 * Notifies the Connection of a request to silence the ringer.
2140 *
2141 * @hide
2142 */
2143 public void onSilence() {}
2144
2145 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002146 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2147 */
Santos Cordonf2951102014-07-20 19:06:29 -07002148 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002149
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002150 /**
2151 * Notifies this Connection of a request to pull an external call to the local device.
2152 * <p>
2153 * The {@link InCallService} issues a request to pull an external call to the local device via
2154 * {@link Call#pullExternalCall()}.
2155 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002156 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2157 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002158 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002159 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002160 */
2161 public void onPullExternalCall() {}
2162
2163 /**
2164 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2165 * <p>
2166 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2167 * <p>
2168 * See also {@link Call#sendCallEvent(String, Bundle)}.
2169 *
2170 * @param event The call event.
2171 * @param extras Extras associated with the call event.
2172 */
2173 public void onCallEvent(String event, Bundle extras) {}
2174
Tyler Gunndee56a82016-03-23 16:06:34 -07002175 /**
2176 * Notifies this {@link Connection} of a change to the extras made outside the
2177 * {@link ConnectionService}.
2178 * <p>
2179 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2180 * the {@link android.telecom.Call#putExtras(Bundle)} and
2181 * {@link Call#removeExtras(List)}.
2182 *
2183 * @param extras The new extras bundle.
2184 */
2185 public void onExtrasChanged(Bundle extras) {}
2186
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002187 static String toLogSafePhoneNumber(String number) {
2188 // For unknown number, log empty string.
2189 if (number == null) {
2190 return "";
2191 }
2192
2193 if (PII_DEBUG) {
2194 // When PII_DEBUG is true we emit PII.
2195 return number;
2196 }
2197
2198 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2199 // sanitized phone numbers.
2200 StringBuilder builder = new StringBuilder();
2201 for (int i = 0; i < number.length(); i++) {
2202 char c = number.charAt(i);
2203 if (c == '-' || c == '@' || c == '.') {
2204 builder.append(c);
2205 } else {
2206 builder.append('x');
2207 }
2208 }
2209 return builder.toString();
2210 }
2211
Ihab Awad542e0ea2014-05-16 10:22:16 -07002212 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002214 if (mState == STATE_DISCONNECTED && mState != state) {
2215 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002216 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002217 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002218 if (mState != state) {
2219 Log.d(this, "setState: %s", stateToString(state));
2220 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002221 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002222 for (Listener l : mListeners) {
2223 l.onStateChanged(this, state);
2224 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002225 }
2226 }
2227
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002228 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002229 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002230 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2231 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002232 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002233 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002234
2235 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002236 if (mImmutable) {
2237 throw new UnsupportedOperationException("Connection is immutable");
2238 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002239 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002240 }
2241
Evan Charltonbf11f982014-07-20 22:06:28 -07002242 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002243 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002244 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2245 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002246 * <p>
2247 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2248 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002249 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002250 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002251 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002252 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002253 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2254 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002255 }
2256
Evan Charltonbf11f982014-07-20 22:06:28 -07002257 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002258 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2259 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2260 * this should never be un-@hide-den.
2261 *
2262 * @hide
2263 */
2264 public void checkImmutable() {}
2265
2266 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002267 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2268 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2269 * that state. This connection should not be used for anything, and no other
2270 * {@code Connection}s should be attempted.
2271 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002272 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002273 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002274 * @return A {@code Connection} which indicates that the underlying connection should
2275 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002276 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002277 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002278 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002279 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002280
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002281 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002282 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002283 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002284 }
2285 }
2286
Santos Cordon823fd3c2014-08-07 18:35:18 -07002287 private final void fireConferenceChanged() {
2288 for (Listener l : mListeners) {
2289 l.onConferenceChanged(this, mConference);
2290 }
2291 }
2292
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002293 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002294 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002295 if (c instanceof Connection) {
2296 Connection connection = (Connection) c;
2297 connection.removeConnectionListener(mConnectionDeathListener);
2298 } else if (c instanceof Conference) {
2299 Conference conference = (Conference) c;
2300 conference.removeListener(mConferenceDeathListener);
2301 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002302 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002303 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002304 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002305
2306 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002307 * Handles a change to extras received from Telecom.
2308 *
2309 * @param extras The new extras.
2310 * @hide
2311 */
2312 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002313 Bundle b = null;
2314 synchronized (mExtrasLock) {
2315 mExtras = extras;
2316 if (mExtras != null) {
2317 b = new Bundle(mExtras);
2318 }
2319 }
2320 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002321 }
2322
2323 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002324 * Notifies listeners that the merge request failed.
2325 *
2326 * @hide
2327 */
2328 protected final void notifyConferenceMergeFailed() {
2329 for (Listener l : mListeners) {
2330 l.onConferenceMergeFailed(this);
2331 }
2332 }
2333
2334 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002335 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002336 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002337 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002338 * @hide
2339 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002340 protected final void updateConferenceParticipants(
2341 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002342 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002343 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002344 }
2345 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002346
2347 /**
2348 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002349 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002350 */
2351 protected void notifyConferenceStarted() {
2352 for (Listener l : mListeners) {
2353 l.onConferenceStarted();
2354 }
2355 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002356
2357 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002358 * Sends an event associated with this {@code Connection}, with associated event extras.
2359 *
2360 * Events are exposed to {@link InCallService} implementations via the
2361 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2362 *
2363 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2364 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002365 *
2366 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002367 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002368 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002369 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002370 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002371 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002372 }
2373 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002374}