blob: 2a0a9a640c6d7510fc6a6b3aa967a56372f1245e [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) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700589 /** @hide */
590 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700591 }
592
Tyler Gunnb702ef82015-05-29 11:51:53 -0700593 /**
594 * Provides a means of controlling the video session associated with a {@link Connection}.
595 * <p>
596 * Implementations create a custom subclass of {@link VideoProvider} and the
597 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
598 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
599 * should set the {@link VideoProvider}.
600 * <p>
601 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
602 * {@link InCallService} implementations to issue requests related to the video session;
603 * it provides a means for the {@link ConnectionService} to report events and information
604 * related to the video session to Telecom and the {@link InCallService} implementations.
605 * <p>
606 * {@link InCallService} implementations interact with the {@link VideoProvider} via
607 * {@link android.telecom.InCallService.VideoCall}.
608 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700610
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 /**
612 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700613 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700614 */
615 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700616
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700618 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
619 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 */
621 public static final int SESSION_EVENT_RX_RESUME = 2;
622
623 /**
624 * Video transmission has begun. This occurs after a negotiated start of video transmission
625 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700626 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 */
628 public static final int SESSION_EVENT_TX_START = 3;
629
630 /**
631 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
632 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700633 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 */
635 public static final int SESSION_EVENT_TX_STOP = 4;
636
637 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700638 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
639 * this as a cue to inform the user the camera is not available.
640 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700641 */
642 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
643
644 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700645 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
646 * for operation. The {@link InCallService} can use this as a cue to inform the user that
647 * the camera has become available again.
648 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 */
650 public static final int SESSION_EVENT_CAMERA_READY = 6;
651
652 /**
653 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700654 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700655 */
656 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
657
658 /**
659 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700660 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 */
662 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
663
664 /**
665 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700666 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 */
668 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
669
Rekha Kumar07366812015-03-24 16:42:31 -0700670 /**
671 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700672 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700673 */
674 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
675
676 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700677 * Session modify request rejected by remote user.
678 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700679 */
680 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
681
Tyler Gunn75958422015-04-15 14:23:42 -0700682 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683 private static final int MSG_SET_CAMERA = 2;
684 private static final int MSG_SET_PREVIEW_SURFACE = 3;
685 private static final int MSG_SET_DISPLAY_SURFACE = 4;
686 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
687 private static final int MSG_SET_ZOOM = 6;
688 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
689 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
690 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700693 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700695 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700697
698 /**
699 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700700 *
701 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
702 * load factor before resizing, 1 means we only expect a single thread to
703 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700704 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700705 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
706 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707
708 /**
709 * Default handler used to consolidate binder method calls onto a single thread.
710 */
711 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700712 public VideoProviderHandler() {
713 super();
714 }
715
716 public VideoProviderHandler(Looper looper) {
717 super(looper);
718 }
719
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 @Override
721 public void handleMessage(Message msg) {
722 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700723 case MSG_ADD_VIDEO_CALLBACK: {
724 IBinder binder = (IBinder) msg.obj;
725 IVideoCallback callback = IVideoCallback.Stub
726 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700727 if (callback == null) {
728 Log.w(this, "addVideoProvider - skipped; callback is null.");
729 break;
730 }
731
Tyler Gunn75958422015-04-15 14:23:42 -0700732 if (mVideoCallbacks.containsKey(binder)) {
733 Log.i(this, "addVideoProvider - skipped; already present.");
734 break;
735 }
736 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700738 }
739 case MSG_REMOVE_VIDEO_CALLBACK: {
740 IBinder binder = (IBinder) msg.obj;
741 IVideoCallback callback = IVideoCallback.Stub
742 .asInterface((IBinder) msg.obj);
743 if (!mVideoCallbacks.containsKey(binder)) {
744 Log.i(this, "removeVideoProvider - skipped; not present.");
745 break;
746 }
747 mVideoCallbacks.remove(binder);
748 break;
749 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 case MSG_SET_CAMERA:
751 onSetCamera((String) msg.obj);
752 break;
753 case MSG_SET_PREVIEW_SURFACE:
754 onSetPreviewSurface((Surface) msg.obj);
755 break;
756 case MSG_SET_DISPLAY_SURFACE:
757 onSetDisplaySurface((Surface) msg.obj);
758 break;
759 case MSG_SET_DEVICE_ORIENTATION:
760 onSetDeviceOrientation(msg.arg1);
761 break;
762 case MSG_SET_ZOOM:
763 onSetZoom((Float) msg.obj);
764 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700765 case MSG_SEND_SESSION_MODIFY_REQUEST: {
766 SomeArgs args = (SomeArgs) msg.obj;
767 try {
768 onSendSessionModifyRequest((VideoProfile) args.arg1,
769 (VideoProfile) args.arg2);
770 } finally {
771 args.recycle();
772 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700774 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700775 case MSG_SEND_SESSION_MODIFY_RESPONSE:
776 onSendSessionModifyResponse((VideoProfile) msg.obj);
777 break;
778 case MSG_REQUEST_CAMERA_CAPABILITIES:
779 onRequestCameraCapabilities();
780 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800781 case MSG_REQUEST_CONNECTION_DATA_USAGE:
782 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700783 break;
784 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700785 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700786 break;
787 default:
788 break;
789 }
790 }
791 }
792
793 /**
794 * IVideoProvider stub implementation.
795 */
796 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700797 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700798 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700799 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
800 }
801
802 public void removeVideoCallback(IBinder videoCallbackBinder) {
803 mMessageHandler.obtainMessage(
804 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 }
806
807 public void setCamera(String cameraId) {
808 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
809 }
810
811 public void setPreviewSurface(Surface surface) {
812 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
813 }
814
815 public void setDisplaySurface(Surface surface) {
816 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
817 }
818
819 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700820 mMessageHandler.obtainMessage(
821 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700822 }
823
824 public void setZoom(float value) {
825 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
826 }
827
Tyler Gunn45382162015-05-06 08:52:27 -0700828 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
829 SomeArgs args = SomeArgs.obtain();
830 args.arg1 = fromProfile;
831 args.arg2 = toProfile;
832 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 }
834
835 public void sendSessionModifyResponse(VideoProfile responseProfile) {
836 mMessageHandler.obtainMessage(
837 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
838 }
839
840 public void requestCameraCapabilities() {
841 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
842 }
843
844 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800845 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700846 }
847
Yorke Lee32f24732015-05-12 16:18:03 -0700848 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700849 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
850 }
851 }
852
853 public VideoProvider() {
854 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700855 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700856 }
857
858 /**
859 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
860 *
861 * @param looper The looper.
862 * @hide
863 */
864 public VideoProvider(Looper looper) {
865 mBinder = new VideoProvider.VideoProviderBinder();
866 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700867 }
868
869 /**
870 * Returns binder object which can be used across IPC methods.
871 * @hide
872 */
873 public final IVideoProvider getInterface() {
874 return mBinder;
875 }
876
877 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700878 * Sets the camera to be used for the outgoing video.
879 * <p>
880 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
881 * camera via
882 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
883 * <p>
884 * Sent from the {@link InCallService} via
885 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700887 * @param cameraId The id of the camera (use ids as reported by
888 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 */
890 public abstract void onSetCamera(String cameraId);
891
892 /**
893 * Sets the surface to be used for displaying a preview of what the user's camera is
894 * currently capturing. When video transmission is enabled, this is the video signal which
895 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * <p>
897 * Sent from the {@link InCallService} via
898 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700899 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700900 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700901 */
902 public abstract void onSetPreviewSurface(Surface surface);
903
904 /**
905 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 * <p>
907 * Sent from the {@link InCallService} via
908 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700910 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700911 */
912 public abstract void onSetDisplaySurface(Surface surface);
913
914 /**
915 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
916 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700917 * <p>
918 * Sent from the {@link InCallService} via
919 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920 *
921 * @param rotation The device orientation, in degrees.
922 */
923 public abstract void onSetDeviceOrientation(int rotation);
924
925 /**
926 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700927 * <p>
928 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700929 *
930 * @param value The camera zoom ratio.
931 */
932 public abstract void onSetZoom(float value);
933
934 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 * Issues a request to modify the properties of the current video session.
936 * <p>
937 * Example scenarios include: requesting an audio-only call to be upgraded to a
938 * bi-directional video call, turning on or off the user's camera, sending a pause signal
939 * when the {@link InCallService} is no longer the foreground application.
940 * <p>
941 * If the {@link VideoProvider} determines a request to be invalid, it should call
942 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
943 * invalid request back to the {@link InCallService}.
944 * <p>
945 * Where a request requires confirmation from the user of the peer device, the
946 * {@link VideoProvider} must communicate the request to the peer device and handle the
947 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
948 * is used to inform the {@link InCallService} of the result of the request.
949 * <p>
950 * Sent from the {@link InCallService} via
951 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700952 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700953 * @param fromProfile The video profile prior to the request.
954 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 */
Tyler Gunn45382162015-05-06 08:52:27 -0700956 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
957 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 /**
960 * Provides a response to a request to change the current video session properties.
961 * <p>
962 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
963 * video call, could decline the request and keep the call as audio-only.
964 * In such a scenario, the {@code responseProfile} would have a video state of
965 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
966 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
967 * <p>
968 * Sent from the {@link InCallService} via
969 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
970 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
971 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700973 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 */
975 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
976
977 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700978 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
979 * <p>
980 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
981 * camera via
982 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
983 * <p>
984 * Sent from the {@link InCallService} via
985 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 */
987 public abstract void onRequestCameraCapabilities();
988
989 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700990 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
991 * video component of the current {@link Connection}.
992 * <p>
993 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
994 * via {@link VideoProvider#setCallDataUsage(long)}.
995 * <p>
996 * Sent from the {@link InCallService} via
997 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800999 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000
1001 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001002 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1003 * the peer device when the video signal is paused.
1004 * <p>
1005 * Sent from the {@link InCallService} via
1006 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 *
1008 * @param uri URI of image to display.
1009 */
Yorke Lee32f24732015-05-12 16:18:03 -07001010 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011
1012 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001013 * Used to inform listening {@link InCallService} implementations when the
1014 * {@link VideoProvider} receives a session modification request.
1015 * <p>
1016 * Received by the {@link InCallService} via
1017 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001018 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001019 * @param videoProfile The requested video profile.
1020 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001021 */
1022 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001023 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001024 for (IVideoCallback callback : mVideoCallbacks.values()) {
1025 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001026 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001027 } catch (RemoteException ignored) {
1028 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001029 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001030 }
1031 }
1032 }
1033
1034 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * Used to inform listening {@link InCallService} implementations when the
1036 * {@link VideoProvider} receives a response to a session modification request.
1037 * <p>
1038 * Received by the {@link InCallService} via
1039 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1040 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001041 *
1042 * @param status Status of the session modify request. Valid values are
1043 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1044 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001045 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1046 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1047 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1048 * @param requestedProfile The original request which was sent to the peer device.
1049 * @param responseProfile The actual profile changes agreed to by the peer device.
1050 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 */
1052 public void receiveSessionModifyResponse(int status,
1053 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001054 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001055 for (IVideoCallback callback : mVideoCallbacks.values()) {
1056 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001057 callback.receiveSessionModifyResponse(status, requestedProfile,
1058 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001059 } catch (RemoteException ignored) {
1060 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001061 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062 }
1063 }
1064 }
1065
1066 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001067 * Used to inform listening {@link InCallService} implementations when the
1068 * {@link VideoProvider} reports a call session event.
1069 * <p>
1070 * Received by the {@link InCallService} via
1071 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001073 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1074 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1075 * {@link VideoProvider#SESSION_EVENT_TX_START},
1076 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1077 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1078 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001079 */
1080 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001081 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001082 for (IVideoCallback callback : mVideoCallbacks.values()) {
1083 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001084 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001085 } catch (RemoteException ignored) {
1086 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001087 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 }
1089 }
1090 }
1091
1092 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001093 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1094 * peer's video have changed.
1095 * <p>
1096 * This could occur if, for example, the peer rotates their device, changing the aspect
1097 * ratio of the video, or if the user switches between the back and front cameras.
1098 * <p>
1099 * Received by the {@link InCallService} via
1100 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 *
1102 * @param width The updated peer video width.
1103 * @param height The updated peer video height.
1104 */
1105 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001106 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001107 for (IVideoCallback callback : mVideoCallbacks.values()) {
1108 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001109 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001110 } catch (RemoteException ignored) {
1111 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001112 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 }
1114 }
1115 }
1116
1117 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001118 * Used to inform listening {@link InCallService} implementations when the data usage of the
1119 * video associated with the current {@link Connection} has changed.
1120 * <p>
1121 * This could be in response to a preview request via
1122 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001123 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1124 * 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 -07001125 * <p>
1126 * Received by the {@link InCallService} via
1127 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1130 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 */
Yorke Lee32f24732015-05-12 16:18:03 -07001132 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001133 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001134 for (IVideoCallback callback : mVideoCallbacks.values()) {
1135 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001136 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001137 } catch (RemoteException ignored) {
1138 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001139 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 }
1141 }
1142 }
1143
1144 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001145 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001147 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001148 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1149 * @hide
1150 */
1151 public void changeCallDataUsage(long dataUsage) {
1152 setCallDataUsage(dataUsage);
1153 }
1154
1155 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001156 * Used to inform listening {@link InCallService} implementations when the capabilities of
1157 * the current camera have changed.
1158 * <p>
1159 * The {@link VideoProvider} should call this in response to
1160 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1161 * changed via {@link VideoProvider#onSetCamera(String)}.
1162 * <p>
1163 * Received by the {@link InCallService} via
1164 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1165 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001166 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001167 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001168 */
Yorke Lee400470f2015-05-12 13:31:25 -07001169 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001170 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001171 for (IVideoCallback callback : mVideoCallbacks.values()) {
1172 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001173 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001174 } catch (RemoteException ignored) {
1175 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001176 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 }
1178 }
1179 }
Rekha Kumar07366812015-03-24 16:42:31 -07001180
1181 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001182 * Used to inform listening {@link InCallService} implementations when the video quality
1183 * of the call has changed.
1184 * <p>
1185 * Received by the {@link InCallService} via
1186 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001187 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001188 * @param videoQuality The updated video quality. Valid values:
1189 * {@link VideoProfile#QUALITY_HIGH},
1190 * {@link VideoProfile#QUALITY_MEDIUM},
1191 * {@link VideoProfile#QUALITY_LOW},
1192 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001193 */
1194 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001195 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001196 for (IVideoCallback callback : mVideoCallbacks.values()) {
1197 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001198 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001199 } catch (RemoteException ignored) {
1200 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001201 }
Rekha Kumar07366812015-03-24 16:42:31 -07001202 }
1203 }
1204 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001205 }
1206
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001207 private final Listener mConnectionDeathListener = new Listener() {
1208 @Override
1209 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001210 if (mConferenceables.remove(c)) {
1211 fireOnConferenceableConnectionsChanged();
1212 }
1213 }
1214 };
1215
1216 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1217 @Override
1218 public void onDestroyed(Conference c) {
1219 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001220 fireOnConferenceableConnectionsChanged();
1221 }
1222 }
1223 };
1224
Jay Shrauner229e3822014-08-15 09:23:07 -07001225 /**
1226 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1227 * load factor before resizing, 1 means we only expect a single thread to
1228 * access the map so make only a single shard
1229 */
1230 private final Set<Listener> mListeners = Collections.newSetFromMap(
1231 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001232 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1233 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001234 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001235
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001236 // The internal telecom call ID associated with this connection.
1237 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001238 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001239 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001240 private Uri mAddress;
1241 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001242 private String mCallerDisplayName;
1243 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001244 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001245 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001246 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001248 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001249 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001250 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001251 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001252 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001253 private Conference mConference;
1254 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001255 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001256 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001257
1258 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001259 * Tracks the key set for the extras bundle provided on the last invocation of
1260 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1261 * keys which were set previously but are no longer present in the replacement Bundle.
1262 */
1263 private Set<String> mPreviousExtraKeys;
1264
1265 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001266 * Create a new Connection.
1267 */
Santos Cordonf2951102014-07-20 19:06:29 -07001268 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269
1270 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001271 * Returns the Telecom internal call ID associated with this connection. Should only be used
1272 * for debugging and tracing purposes.
1273 *
1274 * @return The Telecom call ID.
1275 * @hide
1276 */
1277 public final String getTelecomCallId() {
1278 return mTelecomCallId;
1279 }
1280
1281 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001282 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001283 */
Andrew Lee100e2932014-09-08 15:34:24 -07001284 public final Uri getAddress() {
1285 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001286 }
1287
1288 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001289 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001290 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001291 */
Andrew Lee100e2932014-09-08 15:34:24 -07001292 public final int getAddressPresentation() {
1293 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001294 }
1295
1296 /**
1297 * @return The caller display name (CNAP).
1298 */
1299 public final String getCallerDisplayName() {
1300 return mCallerDisplayName;
1301 }
1302
1303 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001304 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001305 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001306 */
1307 public final int getCallerDisplayNamePresentation() {
1308 return mCallerDisplayNamePresentation;
1309 }
1310
1311 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001312 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001313 */
1314 public final int getState() {
1315 return mState;
1316 }
1317
1318 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001319 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001320 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1321 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1322 * {@link VideoProfile#STATE_TX_ENABLED},
1323 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001324 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001325 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001326 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001327 */
1328 public final int getVideoState() {
1329 return mVideoState;
1330 }
1331
1332 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001333 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001334 * being routed by the system. This is {@code null} if this Connection
1335 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001336 * @deprecated Use {@link #getCallAudioState()} instead.
1337 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001338 */
Yorke Lee4af59352015-05-13 14:14:54 -07001339 @SystemApi
1340 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001342 if (mCallAudioState == null) {
1343 return null;
1344 }
Yorke Lee4af59352015-05-13 14:14:54 -07001345 return new AudioState(mCallAudioState);
1346 }
1347
1348 /**
1349 * @return The audio state of the connection, describing how its audio is currently
1350 * being routed by the system. This is {@code null} if this Connection
1351 * does not directly know about its audio state.
1352 */
1353 public final CallAudioState getCallAudioState() {
1354 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001355 }
1356
1357 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001358 * @return The conference that this connection is a part of. Null if it is not part of any
1359 * conference.
1360 */
1361 public final Conference getConference() {
1362 return mConference;
1363 }
1364
1365 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001366 * Returns whether this connection is requesting that the system play a ringback tone
1367 * on its behalf.
1368 */
Andrew Lee100e2932014-09-08 15:34:24 -07001369 public final boolean isRingbackRequested() {
1370 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001371 }
1372
1373 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001374 * @return True if the connection's audio mode is VOIP.
1375 */
1376 public final boolean getAudioModeIsVoip() {
1377 return mAudioModeIsVoip;
1378 }
1379
1380 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001381 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1382 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1383 * start time of the conference.
1384 *
1385 * @return The time at which the {@code Connnection} was connected.
1386 *
1387 * @hide
1388 */
1389 public final long getConnectTimeMillis() {
1390 return mConnectTimeMillis;
1391 }
1392
1393 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001394 * @return The status hints for this connection.
1395 */
1396 public final StatusHints getStatusHints() {
1397 return mStatusHints;
1398 }
1399
1400 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001401 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001402 * <p>
1403 * Extras should be updated using {@link #putExtras(Bundle)}.
1404 * <p>
1405 * Telecom or an {@link InCallService} can also update the extras via
1406 * {@link android.telecom.Call#putExtras(Bundle)}, and
1407 * {@link Call#removeExtras(List)}.
1408 * <p>
1409 * The connection is notified of changes to the extras made by Telecom or an
1410 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001411 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001412 * @return The extras associated with this connection.
1413 */
1414 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001415 Bundle extras = null;
1416 synchronized (mExtrasLock) {
1417 if (mExtras != null) {
1418 extras = new Bundle(mExtras);
1419 }
1420 }
1421 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001422 }
1423
1424 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001425 * Assign a listener to be notified of state changes.
1426 *
1427 * @param l A listener.
1428 * @return This Connection.
1429 *
1430 * @hide
1431 */
1432 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001433 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001434 return this;
1435 }
1436
1437 /**
1438 * Remove a previously assigned listener that was being notified of state changes.
1439 *
1440 * @param l A Listener.
1441 * @return This Connection.
1442 *
1443 * @hide
1444 */
1445 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001446 if (l != null) {
1447 mListeners.remove(l);
1448 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001449 return this;
1450 }
1451
1452 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001453 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001454 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001455 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001456 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001457 }
1458
1459 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001460 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1461 * ONLY for debugging purposes.
1462 *
1463 * @param callId The telecom call ID.
1464 * @hide
1465 */
1466 public void setTelecomCallId(String callId) {
1467 mTelecomCallId = callId;
1468 }
1469
1470 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001471 * Inform this Connection that the state of its audio output has been changed externally.
1472 *
1473 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001474 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 */
Yorke Lee4af59352015-05-13 14:14:54 -07001476 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001477 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001478 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001479 mCallAudioState = state;
1480 onAudioStateChanged(getAudioState());
1481 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001482 }
1483
1484 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001485 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001486 * @return A string representation of the value.
1487 */
1488 public static String stateToString(int state) {
1489 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001491 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001493 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001494 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001495 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001497 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001499 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001501 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001503 return "DISCONNECTED";
1504 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001505 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001506 return "UNKNOWN";
1507 }
1508 }
1509
1510 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001511 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001512 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001513 public final int getConnectionCapabilities() {
1514 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001515 }
1516
1517 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001518 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1519 */
1520 public final int getConnectionProperties() {
1521 return mConnectionProperties;
1522 }
1523
1524 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001525 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001526 *
Andrew Lee100e2932014-09-08 15:34:24 -07001527 * @param address The new address.
1528 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001529 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001530 */
Andrew Lee100e2932014-09-08 15:34:24 -07001531 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001532 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001533 Log.d(this, "setAddress %s", address);
1534 mAddress = address;
1535 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001536 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001537 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001538 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001539 }
1540
1541 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001542 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001543 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001544 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001545 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001546 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001547 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001548 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001549 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001550 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001551 mCallerDisplayName = callerDisplayName;
1552 mCallerDisplayNamePresentation = presentation;
1553 for (Listener l : mListeners) {
1554 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1555 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001556 }
1557
1558 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001559 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001560 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1561 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1562 * {@link VideoProfile#STATE_TX_ENABLED},
1563 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001564 *
1565 * @param videoState The new video state.
1566 */
1567 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001568 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001569 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001570 mVideoState = videoState;
1571 for (Listener l : mListeners) {
1572 l.onVideoStateChanged(this, mVideoState);
1573 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001574 }
1575
1576 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001578 * communicate).
1579 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001580 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001581 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001582 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001583 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 }
1585
1586 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001587 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001588 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001589 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001590 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001592 }
1593
1594 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001595 * Sets state to initializing (this Connection is not yet ready to be used).
1596 */
1597 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001598 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001600 }
1601
1602 /**
1603 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1604 */
1605 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001606 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001608 }
1609
1610 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001611 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001612 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001613 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001614 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001616 }
1617
1618 /**
1619 * Sets state to be on hold.
1620 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001621 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001622 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 }
1625
1626 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001627 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001629 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001630 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001631 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001632 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001633 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001634 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001635 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001636 }
1637
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001638 public final VideoProvider getVideoProvider() {
1639 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001640 }
1641
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001642 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001643 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001644 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001645 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001647 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001648 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001649 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001650 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001651 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001652 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001653 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001654 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001655 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001656 }
1657
1658 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001659 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1660 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1661 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1662 * to send an {@link #onPostDialContinue(boolean)} signal.
1663 *
1664 * @param remaining The DTMF character sequence remaining to be emitted once the
1665 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1666 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001667 */
1668 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001669 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001670 for (Listener l : mListeners) {
1671 l.onPostDialWait(this, remaining);
1672 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001673 }
1674
1675 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001676 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1677 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001678 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001679 *
1680 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001681 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001682 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001683 checkImmutable();
1684 for (Listener l : mListeners) {
1685 l.onPostDialChar(this, nextChar);
1686 }
1687 }
1688
1689 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001690 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001691 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001692 *
1693 * @param ringback Whether the ringback tone is to be played.
1694 */
Andrew Lee100e2932014-09-08 15:34:24 -07001695 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001696 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001697 if (mRingbackRequested != ringback) {
1698 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001699 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001700 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001701 }
1702 }
Ihab Awadf8358972014-05-28 16:46:42 -07001703 }
1704
1705 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001706 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001707 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001708 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001709 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001710 public final void setConnectionCapabilities(int connectionCapabilities) {
1711 checkImmutable();
1712 if (mConnectionCapabilities != connectionCapabilities) {
1713 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001714 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001715 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001716 }
1717 }
Santos Cordonb6939982014-06-04 20:20:58 -07001718 }
1719
1720 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001721 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1722 *
1723 * @param connectionProperties The new connection properties.
1724 */
1725 public final void setConnectionProperties(int connectionProperties) {
1726 checkImmutable();
1727 if (mConnectionProperties != connectionProperties) {
1728 mConnectionProperties = connectionProperties;
1729 for (Listener l : mListeners) {
1730 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1731 }
1732 }
1733 }
1734
1735 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001736 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001737 */
Evan Charlton36a71342014-07-19 16:31:02 -07001738 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001739 for (Listener l : mListeners) {
1740 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001741 }
Santos Cordonb6939982014-06-04 20:20:58 -07001742 }
1743
1744 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001745 * Requests that the framework use VOIP audio mode for this connection.
1746 *
1747 * @param isVoip True if the audio mode is VOIP.
1748 */
1749 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001750 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001751 mAudioModeIsVoip = isVoip;
1752 for (Listener l : mListeners) {
1753 l.onAudioModeIsVoipChanged(this, isVoip);
1754 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001755 }
1756
1757 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001758 * Sets the time at which a call became active on this Connection. This is set only
1759 * when a conference call becomes active on this connection.
1760 *
1761 * @param connectionTimeMillis The connection time, in milliseconds.
1762 *
1763 * @hide
1764 */
1765 public final void setConnectTimeMillis(long connectTimeMillis) {
1766 mConnectTimeMillis = connectTimeMillis;
1767 }
1768
1769 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001770 * Sets the label and icon status to display in the in-call UI.
1771 *
1772 * @param statusHints The status label and icon to set.
1773 */
1774 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001775 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001776 mStatusHints = statusHints;
1777 for (Listener l : mListeners) {
1778 l.onStatusHintsChanged(this, statusHints);
1779 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001780 }
1781
1782 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001783 * Sets the connections with which this connection can be conferenced.
1784 *
1785 * @param conferenceableConnections The set of connections this connection can conference with.
1786 */
1787 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001788 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001789 clearConferenceableList();
1790 for (Connection c : conferenceableConnections) {
1791 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1792 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001793 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001794 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001795 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001796 }
1797 }
1798 fireOnConferenceableConnectionsChanged();
1799 }
1800
1801 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001802 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1803 * or conferences with which this connection can be conferenced.
1804 *
1805 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001806 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001807 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001808 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001809 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001810 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1811 // small amount of items here.
1812 if (!mConferenceables.contains(c)) {
1813 if (c instanceof Connection) {
1814 Connection connection = (Connection) c;
1815 connection.addConnectionListener(mConnectionDeathListener);
1816 } else if (c instanceof Conference) {
1817 Conference conference = (Conference) c;
1818 conference.addListener(mConferenceDeathListener);
1819 }
1820 mConferenceables.add(c);
1821 }
1822 }
1823 fireOnConferenceableConnectionsChanged();
1824 }
1825
1826 /**
1827 * Returns the connections or conferences with which this connection can be conferenced.
1828 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001829 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001830 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001831 }
1832
Yorke Lee53463962015-08-04 16:07:19 -07001833 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001834 * @hide
1835 */
1836 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001837 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001838 if (mConnectionService != null) {
1839 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1840 "which is already associated with another ConnectionService.");
1841 } else {
1842 mConnectionService = connectionService;
1843 }
1844 }
1845
1846 /**
1847 * @hide
1848 */
1849 public final void unsetConnectionService(ConnectionService connectionService) {
1850 if (mConnectionService != connectionService) {
1851 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1852 "that does not belong to the ConnectionService.");
1853 } else {
1854 mConnectionService = null;
1855 }
1856 }
1857
1858 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001859 * @hide
1860 */
1861 public final ConnectionService getConnectionService() {
1862 return mConnectionService;
1863 }
1864
1865 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001866 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001867 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001868 *
1869 * @param conference The conference.
1870 * @return {@code true} if the conference was successfully set.
1871 * @hide
1872 */
1873 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001874 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001875 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001876 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001877 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001878 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1879 fireConferenceChanged();
1880 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001881 return true;
1882 }
1883 return false;
1884 }
1885
1886 /**
1887 * Resets the conference that this connection is a part of.
1888 * @hide
1889 */
1890 public final void resetConference() {
1891 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001892 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001893 mConference = null;
1894 fireConferenceChanged();
1895 }
1896 }
1897
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001898 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001899 * Set some extras that can be associated with this {@code Connection}.
1900 * <p>
1901 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1902 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1903 * <p>
1904 * 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 -07001905 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1906 *
1907 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001908 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1909 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001910 */
1911 public final void setExtras(@Nullable Bundle extras) {
1912 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001913
1914 // Add/replace any new or changed extras values.
1915 putExtras(extras);
1916
1917 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1918 // the current one and remove any keys that went away.
1919 if (mPreviousExtraKeys != null) {
1920 List<String> toRemove = new ArrayList<String>();
1921 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001922 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001923 toRemove.add(oldKey);
1924 }
1925 }
1926 if (!toRemove.isEmpty()) {
1927 removeExtras(toRemove);
1928 }
1929 }
1930
1931 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1932 // called we can see if the caller has removed any extras values.
1933 if (mPreviousExtraKeys == null) {
1934 mPreviousExtraKeys = new ArraySet<String>();
1935 }
1936 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001937 if (extras != null) {
1938 mPreviousExtraKeys.addAll(extras.keySet());
1939 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001940 }
1941
1942 /**
1943 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1944 * added.
1945 * <p>
1946 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1947 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1948 *
1949 * @param extras The extras to add.
1950 */
1951 public final void putExtras(@NonNull Bundle extras) {
1952 checkImmutable();
1953 if (extras == null) {
1954 return;
1955 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001956 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
1957 // the listeners.
1958 Bundle listenerExtras;
1959 synchronized (mExtrasLock) {
1960 if (mExtras == null) {
1961 mExtras = new Bundle();
1962 }
1963 mExtras.putAll(extras);
1964 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07001965 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001966 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001967 // Create a new clone of the extras for each listener so that they don't clobber
1968 // each other
1969 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07001970 }
1971 }
1972
1973 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001974 * Adds a boolean extra to this {@code Connection}.
1975 *
1976 * @param key The extra key.
1977 * @param value The value.
1978 * @hide
1979 */
1980 public final void putExtra(String key, boolean value) {
1981 Bundle newExtras = new Bundle();
1982 newExtras.putBoolean(key, value);
1983 putExtras(newExtras);
1984 }
1985
1986 /**
1987 * Adds an integer extra to this {@code Connection}.
1988 *
1989 * @param key The extra key.
1990 * @param value The value.
1991 * @hide
1992 */
1993 public final void putExtra(String key, int value) {
1994 Bundle newExtras = new Bundle();
1995 newExtras.putInt(key, value);
1996 putExtras(newExtras);
1997 }
1998
1999 /**
2000 * Adds a string extra to this {@code Connection}.
2001 *
2002 * @param key The extra key.
2003 * @param value The value.
2004 * @hide
2005 */
2006 public final void putExtra(String key, String value) {
2007 Bundle newExtras = new Bundle();
2008 newExtras.putString(key, value);
2009 putExtras(newExtras);
2010 }
2011
2012 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002013 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002014 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002015 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002016 */
2017 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002018 synchronized (mExtrasLock) {
2019 if (mExtras != null) {
2020 for (String key : keys) {
2021 mExtras.remove(key);
2022 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002023 }
2024 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002025 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002026 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002027 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002028 }
2029 }
2030
2031 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002032 * Removes extras from this {@code Connection}.
2033 *
2034 * @param keys The keys of the extras to remove.
2035 */
2036 public final void removeExtras(String ... keys) {
2037 removeExtras(Arrays.asList(keys));
2038 }
2039
2040 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002041 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002042 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002043 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002044 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2045 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002046 */
Yorke Lee4af59352015-05-13 14:14:54 -07002047 @SystemApi
2048 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002049 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002050
2051 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002052 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2053 *
2054 * @param state The new connection audio state.
2055 */
2056 public void onCallAudioStateChanged(CallAudioState state) {}
2057
2058 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002059 * Notifies this Connection of an internal state change. This method is called after the
2060 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002061 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002062 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002063 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002064 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002065
2066 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002067 * Notifies this Connection of a request to play a DTMF tone.
2068 *
2069 * @param c A DTMF character.
2070 */
Santos Cordonf2951102014-07-20 19:06:29 -07002071 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072
2073 /**
2074 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2075 */
Santos Cordonf2951102014-07-20 19:06:29 -07002076 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002077
2078 /**
2079 * Notifies this Connection of a request to disconnect.
2080 */
Santos Cordonf2951102014-07-20 19:06:29 -07002081 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002082
2083 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002084 * Notifies this Connection of a request to disconnect a participant of the conference managed
2085 * by the connection.
2086 *
2087 * @param endpoint the {@link Uri} of the participant to disconnect.
2088 * @hide
2089 */
2090 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2091
2092 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002093 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002094 */
Santos Cordonf2951102014-07-20 19:06:29 -07002095 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002096
2097 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098 * Notifies this Connection of a request to abort.
2099 */
Santos Cordonf2951102014-07-20 19:06:29 -07002100 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002101
2102 /**
2103 * Notifies this Connection of a request to hold.
2104 */
Santos Cordonf2951102014-07-20 19:06:29 -07002105 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002106
2107 /**
2108 * Notifies this Connection of a request to exit a hold state.
2109 */
Santos Cordonf2951102014-07-20 19:06:29 -07002110 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111
2112 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002113 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002114 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002115 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002117 */
Santos Cordonf2951102014-07-20 19:06:29 -07002118 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002119
2120 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002121 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002122 * a request to accept.
2123 */
2124 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002125 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002126 }
2127
2128 /**
2129 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002130 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131 */
Santos Cordonf2951102014-07-20 19:06:29 -07002132 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002133
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002134 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002135 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2136 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002137 */
2138 public void onReject(String replyMessage) {}
2139
2140 /**
Bryce Leecac50772015-11-17 15:13:29 -08002141 * Notifies the Connection of a request to silence the ringer.
2142 *
2143 * @hide
2144 */
2145 public void onSilence() {}
2146
2147 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002148 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2149 */
Santos Cordonf2951102014-07-20 19:06:29 -07002150 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002151
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002152 /**
2153 * Notifies this Connection of a request to pull an external call to the local device.
2154 * <p>
2155 * The {@link InCallService} issues a request to pull an external call to the local device via
2156 * {@link Call#pullExternalCall()}.
2157 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002158 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2159 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002160 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002161 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002162 */
2163 public void onPullExternalCall() {}
2164
2165 /**
2166 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2167 * <p>
2168 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2169 * <p>
2170 * See also {@link Call#sendCallEvent(String, Bundle)}.
2171 *
2172 * @param event The call event.
2173 * @param extras Extras associated with the call event.
2174 */
2175 public void onCallEvent(String event, Bundle extras) {}
2176
Tyler Gunndee56a82016-03-23 16:06:34 -07002177 /**
2178 * Notifies this {@link Connection} of a change to the extras made outside the
2179 * {@link ConnectionService}.
2180 * <p>
2181 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2182 * the {@link android.telecom.Call#putExtras(Bundle)} and
2183 * {@link Call#removeExtras(List)}.
2184 *
2185 * @param extras The new extras bundle.
2186 */
2187 public void onExtrasChanged(Bundle extras) {}
2188
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002189 static String toLogSafePhoneNumber(String number) {
2190 // For unknown number, log empty string.
2191 if (number == null) {
2192 return "";
2193 }
2194
2195 if (PII_DEBUG) {
2196 // When PII_DEBUG is true we emit PII.
2197 return number;
2198 }
2199
2200 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2201 // sanitized phone numbers.
2202 StringBuilder builder = new StringBuilder();
2203 for (int i = 0; i < number.length(); i++) {
2204 char c = number.charAt(i);
2205 if (c == '-' || c == '@' || c == '.') {
2206 builder.append(c);
2207 } else {
2208 builder.append('x');
2209 }
2210 }
2211 return builder.toString();
2212 }
2213
Ihab Awad542e0ea2014-05-16 10:22:16 -07002214 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002215 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002216 if (mState == STATE_DISCONNECTED && mState != state) {
2217 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002218 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002219 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002220 if (mState != state) {
2221 Log.d(this, "setState: %s", stateToString(state));
2222 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002223 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002224 for (Listener l : mListeners) {
2225 l.onStateChanged(this, state);
2226 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002227 }
2228 }
2229
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002230 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002231 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002232 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2233 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002234 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002235 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002236
2237 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002238 if (mImmutable) {
2239 throw new UnsupportedOperationException("Connection is immutable");
2240 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002241 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002242 }
2243
Evan Charltonbf11f982014-07-20 22:06:28 -07002244 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002245 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002246 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2247 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002248 * <p>
2249 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2250 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002251 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002252 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002253 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002254 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002255 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2256 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002257 }
2258
Evan Charltonbf11f982014-07-20 22:06:28 -07002259 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002260 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2261 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2262 * this should never be un-@hide-den.
2263 *
2264 * @hide
2265 */
2266 public void checkImmutable() {}
2267
2268 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002269 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2270 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2271 * that state. This connection should not be used for anything, and no other
2272 * {@code Connection}s should be attempted.
2273 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002274 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002275 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002276 * @return A {@code Connection} which indicates that the underlying connection should
2277 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002278 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002279 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002280 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002281 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002282
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002283 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002284 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002285 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002286 }
2287 }
2288
Santos Cordon823fd3c2014-08-07 18:35:18 -07002289 private final void fireConferenceChanged() {
2290 for (Listener l : mListeners) {
2291 l.onConferenceChanged(this, mConference);
2292 }
2293 }
2294
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002295 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002296 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002297 if (c instanceof Connection) {
2298 Connection connection = (Connection) c;
2299 connection.removeConnectionListener(mConnectionDeathListener);
2300 } else if (c instanceof Conference) {
2301 Conference conference = (Conference) c;
2302 conference.removeListener(mConferenceDeathListener);
2303 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002304 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002305 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002306 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002307
2308 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002309 * Handles a change to extras received from Telecom.
2310 *
2311 * @param extras The new extras.
2312 * @hide
2313 */
2314 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002315 Bundle b = null;
2316 synchronized (mExtrasLock) {
2317 mExtras = extras;
2318 if (mExtras != null) {
2319 b = new Bundle(mExtras);
2320 }
2321 }
2322 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002323 }
2324
2325 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002326 * Notifies listeners that the merge request failed.
2327 *
2328 * @hide
2329 */
2330 protected final void notifyConferenceMergeFailed() {
2331 for (Listener l : mListeners) {
2332 l.onConferenceMergeFailed(this);
2333 }
2334 }
2335
2336 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002337 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002338 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002339 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002340 * @hide
2341 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002342 protected final void updateConferenceParticipants(
2343 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002344 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002345 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002346 }
2347 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002348
2349 /**
2350 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002351 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002352 */
2353 protected void notifyConferenceStarted() {
2354 for (Listener l : mListeners) {
2355 l.onConferenceStarted();
2356 }
2357 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002358
2359 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002360 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2361 * be a part of a conference call.
2362 * @param isConferenceSupported {@code true} if the connection supports being part of a
2363 * conference call, {@code false} otherwise.
2364 * @hide
2365 */
2366 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2367 for (Listener l : mListeners) {
2368 l.onConferenceSupportedChanged(this, isConferenceSupported);
2369 }
2370 }
2371
2372 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002373 * Sends an event associated with this {@code Connection}, with associated event extras.
2374 *
2375 * Events are exposed to {@link InCallService} implementations via the
2376 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2377 *
2378 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2379 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002380 *
2381 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002382 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002383 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002384 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002385 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002386 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002387 }
2388 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002389}