blob: ef314f3d139e445731d562e019f4ad2ea18e2cd6 [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;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
43/**
Santos Cordon895d4b82015-06-25 16:41:48 -070044 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
45 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070046 * <p>
47 * Implementations create a custom subclass of {@code Connection} and return it to the framework
48 * as the return value of
49 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
50 * or
51 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
52 * Implementations are then responsible for updating the state of the {@code Connection}, and
53 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
54 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070055 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070056public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070057
Santos Cordon895d4b82015-06-25 16:41:48 -070058 /**
59 * The connection is initializing. This is generally the first state for a {@code Connection}
60 * returned by a {@link ConnectionService}.
61 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 public static final int STATE_INITIALIZING = 0;
63
Santos Cordon895d4b82015-06-25 16:41:48 -070064 /**
65 * The connection is new and not connected.
66 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070067 public static final int STATE_NEW = 1;
68
Santos Cordon895d4b82015-06-25 16:41:48 -070069 /**
70 * An incoming connection is in the ringing state. During this state, the user's ringer or
71 * vibration feature will be activated.
72 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070073 public static final int STATE_RINGING = 2;
74
Santos Cordon895d4b82015-06-25 16:41:48 -070075 /**
76 * An outgoing connection is in the dialing state. In this state the other party has not yet
77 * answered the call and the user traditionally hears a ringback tone.
78 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 public static final int STATE_DIALING = 3;
80
Santos Cordon895d4b82015-06-25 16:41:48 -070081 /**
82 * A connection is active. Both parties are connected to the call and can actively communicate.
83 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 public static final int STATE_ACTIVE = 4;
85
Santos Cordon895d4b82015-06-25 16:41:48 -070086 /**
87 * A connection is on hold.
88 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 public static final int STATE_HOLDING = 5;
90
Santos Cordon895d4b82015-06-25 16:41:48 -070091 /**
92 * A connection has been disconnected. This is the final state once the user has been
93 * disconnected from a call either locally, remotely or by an error in the service.
94 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070095 public static final int STATE_DISCONNECTED = 6;
96
Santos Cordon895d4b82015-06-25 16:41:48 -070097 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070098 * The state of an external connection which is in the process of being pulled from a remote
99 * device to the local device.
100 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700101 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700102 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700103 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700104 */
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.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700287 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -0700288 */
289 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
290
291 //**********************************************************************************************
292 // Next CAPABILITY value: 0x02000000
293 //**********************************************************************************************
294
295 /**
296 * Indicates that the current device callback number should be shown.
297 *
298 * @hide
299 */
300 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
301
302 /**
303 * Whether the call is a generic conference, where we do not know the precise state of
304 * participants in the conference (eg. on CDMA).
305 *
306 * @hide
307 */
308 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
309
310 /**
311 * Connection is using high definition audio.
312 * @hide
313 */
314 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
315
316 /**
317 * Connection is using WIFI.
318 * @hide
319 */
320 public static final int PROPERTY_WIFI = 1<<3;
321
322 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700323 * When set, indicates that the {@code Connection} does not actually exist locally for the
324 * {@link ConnectionService}.
325 * <p>
326 * Consider, for example, a scenario where a user has two devices with the same phone number.
327 * When a user places a call on one devices, the telephony stack can represent that call on the
328 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700329 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700330 * <p>
331 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
332 * external connections. Only those {@link InCallService}s which have the
333 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
334 * manifest will see external connections.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700335 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700337 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700338
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700339
Tyler Gunn96d6c402015-03-18 12:39:23 -0700340 //**********************************************************************************************
Tyler Gunn720c6642016-03-22 09:02:47 -0700341 // Next PROPERTY value: 1<<5
Tyler Gunn96d6c402015-03-18 12:39:23 -0700342 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800343
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700344 /**
345 * Connection extra key used to store the last forwarded number associated with the current
346 * connection. Used to communicate to the user interface that the connection was forwarded via
347 * the specified number.
348 */
349 public static final String EXTRA_LAST_FORWARDED_NUMBER =
350 "android.telecom.extra.LAST_FORWARDED_NUMBER";
351
352 /**
353 * Connection extra key used to store a child number associated with the current connection.
354 * Used to communicate to the user interface that the connection was received via
355 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
356 * address.
357 */
358 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
359
360 /**
361 * Connection extra key used to store the subject for an incoming call. The user interface can
362 * query this extra and display its contents for incoming calls. Will only be used if the
363 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
364 */
365 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
366
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800367 /**
368 * Connection event used to inform Telecom that it should play the on hold tone. This is used
369 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
370 * {@link #sendConnectionEvent(String)}.
371 * @hide
372 */
373 public static final String EVENT_ON_HOLD_TONE_START =
374 "android.telecom.event.ON_HOLD_TONE_START";
375
376 /**
377 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
378 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
379 * {@link #sendConnectionEvent(String)}.
380 * @hide
381 */
382 public static final String EVENT_ON_HOLD_TONE_END =
383 "android.telecom.event.ON_HOLD_TONE_END";
384
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700385 /**
386 * Connection event used to inform {@link InCallService}s when pulling of an external call has
387 * failed. The user interface should inform the user of the error.
388 * <p>
389 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
390 * API is called on a {@link Call} with the properties
391 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
392 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
393 * pull the external call due to an error condition.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700394 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700395 */
396 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
397
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700398 // Flag controlling whether PII is emitted into the logs
399 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
400
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800401 /**
402 * Whether the given capabilities support the specified capability.
403 *
404 * @param capabilities A capability bit field.
405 * @param capability The capability to check capabilities for.
406 * @return Whether the specified capability is supported.
407 * @hide
408 */
409 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800410 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800411 }
412
413 /**
414 * Whether the capabilities of this {@code Connection} supports the specified capability.
415 *
416 * @param capability The capability to check capabilities for.
417 * @return Whether the specified capability is supported.
418 * @hide
419 */
420 public boolean can(int capability) {
421 return can(mConnectionCapabilities, capability);
422 }
423
424 /**
425 * Removes the specified capability from the set of capabilities of this {@code Connection}.
426 *
427 * @param capability The capability to remove from the set.
428 * @hide
429 */
430 public void removeCapability(int capability) {
431 mConnectionCapabilities &= ~capability;
432 }
433
434 /**
435 * Adds the specified capability to the set of capabilities of this {@code Connection}.
436 *
437 * @param capability The capability to add to the set.
438 * @hide
439 */
440 public void addCapability(int capability) {
441 mConnectionCapabilities |= capability;
442 }
443
444
445 public static String capabilitiesToString(int capabilities) {
446 StringBuilder builder = new StringBuilder();
447 builder.append("[Capabilities:");
448 if (can(capabilities, CAPABILITY_HOLD)) {
449 builder.append(" CAPABILITY_HOLD");
450 }
451 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
452 builder.append(" CAPABILITY_SUPPORT_HOLD");
453 }
454 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
455 builder.append(" CAPABILITY_MERGE_CONFERENCE");
456 }
457 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
458 builder.append(" CAPABILITY_SWAP_CONFERENCE");
459 }
460 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
461 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
462 }
463 if (can(capabilities, CAPABILITY_MUTE)) {
464 builder.append(" CAPABILITY_MUTE");
465 }
466 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
467 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
468 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700469 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
470 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
471 }
472 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
473 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
474 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700475 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
476 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800477 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700478 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
479 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
480 }
481 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
482 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
483 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700484 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
485 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800486 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800487 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
488 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
489 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500490 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700491 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500492 }
Rekha Kumar07366812015-03-24 16:42:31 -0700493 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
494 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
495 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700496 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
497 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
498 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700499 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
500 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
501 }
Bryce Lee81901682015-08-28 16:38:02 -0700502 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
503 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
504 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700505 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
506 builder.append(" CAPABILITY_CAN_PULL_CALL");
507 }
Bryce Lee81901682015-08-28 16:38:02 -0700508
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800509 builder.append("]");
510 return builder.toString();
511 }
512
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700513 /**
514 * Builds a string representation of a properties bit-mask.
515 *
516 * @param properties The properties bit-mask.
517 * @return String representation.
518 * @hide
519 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700520 public static String propertiesToString(int properties) {
521 StringBuilder builder = new StringBuilder();
522 builder.append("[Properties:");
523
524 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
525 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
526 }
527
528 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
529 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
530 }
531
532 if (can(properties, PROPERTY_WIFI)) {
533 builder.append(" PROPERTY_WIFI");
534 }
535
536 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
537 builder.append(" PROPERTY_GENERIC_CONFERENCE");
538 }
539
540 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
541 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
542 }
543
544 builder.append("]");
545 return builder.toString();
546 }
547
Sailesh Nepal091768c2014-06-30 15:15:23 -0700548 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700549 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700550 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700551 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700552 public void onCallerDisplayNameChanged(
553 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700554 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700555 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700556 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800557 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700558 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700559 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800560 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700561 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 public void onVideoProviderChanged(
563 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700564 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
565 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800566 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700567 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700568 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700569 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800570 public void onConferenceParticipantsChanged(Connection c,
571 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800572 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700573 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700574 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700575 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700576 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700577 }
578
Tyler Gunnb702ef82015-05-29 11:51:53 -0700579 /**
580 * Provides a means of controlling the video session associated with a {@link Connection}.
581 * <p>
582 * Implementations create a custom subclass of {@link VideoProvider} and the
583 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
584 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
585 * should set the {@link VideoProvider}.
586 * <p>
587 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
588 * {@link InCallService} implementations to issue requests related to the video session;
589 * it provides a means for the {@link ConnectionService} to report events and information
590 * related to the video session to Telecom and the {@link InCallService} implementations.
591 * <p>
592 * {@link InCallService} implementations interact with the {@link VideoProvider} via
593 * {@link android.telecom.InCallService.VideoCall}.
594 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700596
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 /**
598 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700599 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 */
601 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700602
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700603 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700604 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
605 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700606 */
607 public static final int SESSION_EVENT_RX_RESUME = 2;
608
609 /**
610 * Video transmission has begun. This occurs after a negotiated start of video transmission
611 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700612 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 */
614 public static final int SESSION_EVENT_TX_START = 3;
615
616 /**
617 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
618 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700619 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 */
621 public static final int SESSION_EVENT_TX_STOP = 4;
622
623 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700624 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
625 * this as a cue to inform the user the camera is not available.
626 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 */
628 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
629
630 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700631 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
632 * for operation. The {@link InCallService} can use this as a cue to inform the user that
633 * the camera has become available again.
634 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700635 */
636 public static final int SESSION_EVENT_CAMERA_READY = 6;
637
638 /**
639 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700640 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700641 */
642 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
643
644 /**
645 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700646 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 */
648 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
649
650 /**
651 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700652 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 */
654 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
655
Rekha Kumar07366812015-03-24 16:42:31 -0700656 /**
657 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700658 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700659 */
660 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
661
662 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700663 * Session modify request rejected by remote user.
664 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700665 */
666 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
667
Tyler Gunn75958422015-04-15 14:23:42 -0700668 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669 private static final int MSG_SET_CAMERA = 2;
670 private static final int MSG_SET_PREVIEW_SURFACE = 3;
671 private static final int MSG_SET_DISPLAY_SURFACE = 4;
672 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
673 private static final int MSG_SET_ZOOM = 6;
674 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
675 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
676 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700678 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700679 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700681 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700683
684 /**
685 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700686 *
687 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
688 * load factor before resizing, 1 means we only expect a single thread to
689 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700690 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700691 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
692 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700693
694 /**
695 * Default handler used to consolidate binder method calls onto a single thread.
696 */
697 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700698 public VideoProviderHandler() {
699 super();
700 }
701
702 public VideoProviderHandler(Looper looper) {
703 super(looper);
704 }
705
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 @Override
707 public void handleMessage(Message msg) {
708 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700709 case MSG_ADD_VIDEO_CALLBACK: {
710 IBinder binder = (IBinder) msg.obj;
711 IVideoCallback callback = IVideoCallback.Stub
712 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700713 if (callback == null) {
714 Log.w(this, "addVideoProvider - skipped; callback is null.");
715 break;
716 }
717
Tyler Gunn75958422015-04-15 14:23:42 -0700718 if (mVideoCallbacks.containsKey(binder)) {
719 Log.i(this, "addVideoProvider - skipped; already present.");
720 break;
721 }
722 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700724 }
725 case MSG_REMOVE_VIDEO_CALLBACK: {
726 IBinder binder = (IBinder) msg.obj;
727 IVideoCallback callback = IVideoCallback.Stub
728 .asInterface((IBinder) msg.obj);
729 if (!mVideoCallbacks.containsKey(binder)) {
730 Log.i(this, "removeVideoProvider - skipped; not present.");
731 break;
732 }
733 mVideoCallbacks.remove(binder);
734 break;
735 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700736 case MSG_SET_CAMERA:
737 onSetCamera((String) msg.obj);
738 break;
739 case MSG_SET_PREVIEW_SURFACE:
740 onSetPreviewSurface((Surface) msg.obj);
741 break;
742 case MSG_SET_DISPLAY_SURFACE:
743 onSetDisplaySurface((Surface) msg.obj);
744 break;
745 case MSG_SET_DEVICE_ORIENTATION:
746 onSetDeviceOrientation(msg.arg1);
747 break;
748 case MSG_SET_ZOOM:
749 onSetZoom((Float) msg.obj);
750 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700751 case MSG_SEND_SESSION_MODIFY_REQUEST: {
752 SomeArgs args = (SomeArgs) msg.obj;
753 try {
754 onSendSessionModifyRequest((VideoProfile) args.arg1,
755 (VideoProfile) args.arg2);
756 } finally {
757 args.recycle();
758 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700760 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 case MSG_SEND_SESSION_MODIFY_RESPONSE:
762 onSendSessionModifyResponse((VideoProfile) msg.obj);
763 break;
764 case MSG_REQUEST_CAMERA_CAPABILITIES:
765 onRequestCameraCapabilities();
766 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800767 case MSG_REQUEST_CONNECTION_DATA_USAGE:
768 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769 break;
770 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700771 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 break;
773 default:
774 break;
775 }
776 }
777 }
778
779 /**
780 * IVideoProvider stub implementation.
781 */
782 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700783 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700784 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700785 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
786 }
787
788 public void removeVideoCallback(IBinder videoCallbackBinder) {
789 mMessageHandler.obtainMessage(
790 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700791 }
792
793 public void setCamera(String cameraId) {
794 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
795 }
796
797 public void setPreviewSurface(Surface surface) {
798 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
799 }
800
801 public void setDisplaySurface(Surface surface) {
802 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
803 }
804
805 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700806 mMessageHandler.obtainMessage(
807 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 }
809
810 public void setZoom(float value) {
811 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
812 }
813
Tyler Gunn45382162015-05-06 08:52:27 -0700814 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
815 SomeArgs args = SomeArgs.obtain();
816 args.arg1 = fromProfile;
817 args.arg2 = toProfile;
818 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819 }
820
821 public void sendSessionModifyResponse(VideoProfile responseProfile) {
822 mMessageHandler.obtainMessage(
823 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
824 }
825
826 public void requestCameraCapabilities() {
827 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
828 }
829
830 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800831 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700832 }
833
Yorke Lee32f24732015-05-12 16:18:03 -0700834 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700835 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
836 }
837 }
838
839 public VideoProvider() {
840 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700841 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700842 }
843
844 /**
845 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
846 *
847 * @param looper The looper.
848 * @hide
849 */
850 public VideoProvider(Looper looper) {
851 mBinder = new VideoProvider.VideoProviderBinder();
852 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853 }
854
855 /**
856 * Returns binder object which can be used across IPC methods.
857 * @hide
858 */
859 public final IVideoProvider getInterface() {
860 return mBinder;
861 }
862
863 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700864 * Sets the camera to be used for the outgoing video.
865 * <p>
866 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
867 * camera via
868 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
869 * <p>
870 * Sent from the {@link InCallService} via
871 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700873 * @param cameraId The id of the camera (use ids as reported by
874 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 */
876 public abstract void onSetCamera(String cameraId);
877
878 /**
879 * Sets the surface to be used for displaying a preview of what the user's camera is
880 * currently capturing. When video transmission is enabled, this is the video signal which
881 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700882 * <p>
883 * Sent from the {@link InCallService} via
884 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700886 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887 */
888 public abstract void onSetPreviewSurface(Surface surface);
889
890 /**
891 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700892 * <p>
893 * Sent from the {@link InCallService} via
894 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 */
898 public abstract void onSetDisplaySurface(Surface surface);
899
900 /**
901 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
902 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700903 * <p>
904 * Sent from the {@link InCallService} via
905 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 *
907 * @param rotation The device orientation, in degrees.
908 */
909 public abstract void onSetDeviceOrientation(int rotation);
910
911 /**
912 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700913 * <p>
914 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 *
916 * @param value The camera zoom ratio.
917 */
918 public abstract void onSetZoom(float value);
919
920 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700921 * Issues a request to modify the properties of the current video session.
922 * <p>
923 * Example scenarios include: requesting an audio-only call to be upgraded to a
924 * bi-directional video call, turning on or off the user's camera, sending a pause signal
925 * when the {@link InCallService} is no longer the foreground application.
926 * <p>
927 * If the {@link VideoProvider} determines a request to be invalid, it should call
928 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
929 * invalid request back to the {@link InCallService}.
930 * <p>
931 * Where a request requires confirmation from the user of the peer device, the
932 * {@link VideoProvider} must communicate the request to the peer device and handle the
933 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
934 * is used to inform the {@link InCallService} of the result of the request.
935 * <p>
936 * Sent from the {@link InCallService} via
937 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700939 * @param fromProfile The video profile prior to the request.
940 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941 */
Tyler Gunn45382162015-05-06 08:52:27 -0700942 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
943 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700944
Tyler Gunnb702ef82015-05-29 11:51:53 -0700945 /**
946 * Provides a response to a request to change the current video session properties.
947 * <p>
948 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
949 * video call, could decline the request and keep the call as audio-only.
950 * In such a scenario, the {@code responseProfile} would have a video state of
951 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
952 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
953 * <p>
954 * Sent from the {@link InCallService} via
955 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
956 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
957 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 */
961 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
962
963 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700964 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
965 * <p>
966 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
967 * camera via
968 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
969 * <p>
970 * Sent from the {@link InCallService} via
971 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 */
973 public abstract void onRequestCameraCapabilities();
974
975 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700976 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
977 * video component of the current {@link Connection}.
978 * <p>
979 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
980 * via {@link VideoProvider#setCallDataUsage(long)}.
981 * <p>
982 * Sent from the {@link InCallService} via
983 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986
987 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
989 * the peer device when the video signal is paused.
990 * <p>
991 * Sent from the {@link InCallService} via
992 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 *
994 * @param uri URI of image to display.
995 */
Yorke Lee32f24732015-05-12 16:18:03 -0700996 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997
998 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * Used to inform listening {@link InCallService} implementations when the
1000 * {@link VideoProvider} receives a session modification request.
1001 * <p>
1002 * Received by the {@link InCallService} via
1003 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001005 * @param videoProfile The requested video profile.
1006 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 */
1008 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001009 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001010 for (IVideoCallback callback : mVideoCallbacks.values()) {
1011 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001012 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001013 } catch (RemoteException ignored) {
1014 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001015 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 }
1017 }
1018 }
1019
1020 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * Used to inform listening {@link InCallService} implementations when the
1022 * {@link VideoProvider} receives a response to a session modification request.
1023 * <p>
1024 * Received by the {@link InCallService} via
1025 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1026 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 *
1028 * @param status Status of the session modify request. Valid values are
1029 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1030 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001031 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1032 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1033 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1034 * @param requestedProfile The original request which was sent to the peer device.
1035 * @param responseProfile The actual profile changes agreed to by the peer device.
1036 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001037 */
1038 public void receiveSessionModifyResponse(int status,
1039 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001040 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001041 for (IVideoCallback callback : mVideoCallbacks.values()) {
1042 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001043 callback.receiveSessionModifyResponse(status, requestedProfile,
1044 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001045 } catch (RemoteException ignored) {
1046 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001047 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 }
1049 }
1050 }
1051
1052 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001053 * Used to inform listening {@link InCallService} implementations when the
1054 * {@link VideoProvider} reports a call session event.
1055 * <p>
1056 * Received by the {@link InCallService} via
1057 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001058 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001059 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1060 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1061 * {@link VideoProvider#SESSION_EVENT_TX_START},
1062 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1063 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1064 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001065 */
1066 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001067 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001068 for (IVideoCallback callback : mVideoCallbacks.values()) {
1069 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001070 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001071 } catch (RemoteException ignored) {
1072 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001073 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 }
1075 }
1076 }
1077
1078 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001079 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1080 * peer's video have changed.
1081 * <p>
1082 * This could occur if, for example, the peer rotates their device, changing the aspect
1083 * ratio of the video, or if the user switches between the back and front cameras.
1084 * <p>
1085 * Received by the {@link InCallService} via
1086 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001087 *
1088 * @param width The updated peer video width.
1089 * @param height The updated peer video height.
1090 */
1091 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001092 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001093 for (IVideoCallback callback : mVideoCallbacks.values()) {
1094 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001095 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001096 } catch (RemoteException ignored) {
1097 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001098 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001099 }
1100 }
1101 }
1102
1103 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001104 * Used to inform listening {@link InCallService} implementations when the data usage of the
1105 * video associated with the current {@link Connection} has changed.
1106 * <p>
1107 * This could be in response to a preview request via
1108 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001109 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1110 * 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 -07001111 * <p>
1112 * Received by the {@link InCallService} via
1113 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001115 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1116 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001117 */
Yorke Lee32f24732015-05-12 16:18:03 -07001118 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001119 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001120 for (IVideoCallback callback : mVideoCallbacks.values()) {
1121 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001122 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001123 } catch (RemoteException ignored) {
1124 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001125 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 }
1127 }
1128 }
1129
1130 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001131 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001133 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001134 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1135 * @hide
1136 */
1137 public void changeCallDataUsage(long dataUsage) {
1138 setCallDataUsage(dataUsage);
1139 }
1140
1141 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001142 * Used to inform listening {@link InCallService} implementations when the capabilities of
1143 * the current camera have changed.
1144 * <p>
1145 * The {@link VideoProvider} should call this in response to
1146 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1147 * changed via {@link VideoProvider#onSetCamera(String)}.
1148 * <p>
1149 * Received by the {@link InCallService} via
1150 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1151 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001152 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001153 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 */
Yorke Lee400470f2015-05-12 13:31:25 -07001155 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001156 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001157 for (IVideoCallback callback : mVideoCallbacks.values()) {
1158 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001159 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001160 } catch (RemoteException ignored) {
1161 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001162 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 }
1164 }
1165 }
Rekha Kumar07366812015-03-24 16:42:31 -07001166
1167 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001168 * Used to inform listening {@link InCallService} implementations when the video quality
1169 * of the call has changed.
1170 * <p>
1171 * Received by the {@link InCallService} via
1172 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001173 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001174 * @param videoQuality The updated video quality. Valid values:
1175 * {@link VideoProfile#QUALITY_HIGH},
1176 * {@link VideoProfile#QUALITY_MEDIUM},
1177 * {@link VideoProfile#QUALITY_LOW},
1178 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001179 */
1180 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001181 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001182 for (IVideoCallback callback : mVideoCallbacks.values()) {
1183 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001184 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001185 } catch (RemoteException ignored) {
1186 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001187 }
Rekha Kumar07366812015-03-24 16:42:31 -07001188 }
1189 }
1190 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001191 }
1192
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001193 private final Listener mConnectionDeathListener = new Listener() {
1194 @Override
1195 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001196 if (mConferenceables.remove(c)) {
1197 fireOnConferenceableConnectionsChanged();
1198 }
1199 }
1200 };
1201
1202 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1203 @Override
1204 public void onDestroyed(Conference c) {
1205 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001206 fireOnConferenceableConnectionsChanged();
1207 }
1208 }
1209 };
1210
Jay Shrauner229e3822014-08-15 09:23:07 -07001211 /**
1212 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1213 * load factor before resizing, 1 means we only expect a single thread to
1214 * access the map so make only a single shard
1215 */
1216 private final Set<Listener> mListeners = Collections.newSetFromMap(
1217 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001218 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1219 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001220 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001221
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001222 // The internal telecom call ID associated with this connection.
1223 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001225 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001226 private Uri mAddress;
1227 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001228 private String mCallerDisplayName;
1229 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001230 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001231 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001232 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001234 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001235 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001236 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001237 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001238 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001239 private Conference mConference;
1240 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001241 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001242
1243 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001244 * Tracks the key set for the extras bundle provided on the last invocation of
1245 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1246 * keys which were set previously but are no longer present in the replacement Bundle.
1247 */
1248 private Set<String> mPreviousExtraKeys;
1249
1250 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001251 * Create a new Connection.
1252 */
Santos Cordonf2951102014-07-20 19:06:29 -07001253 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001254
1255 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001256 * Returns the Telecom internal call ID associated with this connection. Should only be used
1257 * for debugging and tracing purposes.
1258 *
1259 * @return The Telecom call ID.
1260 * @hide
1261 */
1262 public final String getTelecomCallId() {
1263 return mTelecomCallId;
1264 }
1265
1266 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001267 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001268 */
Andrew Lee100e2932014-09-08 15:34:24 -07001269 public final Uri getAddress() {
1270 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001271 }
1272
1273 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001274 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001275 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001276 */
Andrew Lee100e2932014-09-08 15:34:24 -07001277 public final int getAddressPresentation() {
1278 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001279 }
1280
1281 /**
1282 * @return The caller display name (CNAP).
1283 */
1284 public final String getCallerDisplayName() {
1285 return mCallerDisplayName;
1286 }
1287
1288 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001289 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001290 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001291 */
1292 public final int getCallerDisplayNamePresentation() {
1293 return mCallerDisplayNamePresentation;
1294 }
1295
1296 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001297 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001298 */
1299 public final int getState() {
1300 return mState;
1301 }
1302
1303 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001304 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001305 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1306 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1307 * {@link VideoProfile#STATE_TX_ENABLED},
1308 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001309 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001311 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001312 */
1313 public final int getVideoState() {
1314 return mVideoState;
1315 }
1316
1317 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001318 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319 * being routed by the system. This is {@code null} if this Connection
1320 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001321 * @deprecated Use {@link #getCallAudioState()} instead.
1322 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001323 */
Yorke Lee4af59352015-05-13 14:14:54 -07001324 @SystemApi
1325 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001327 if (mCallAudioState == null) {
1328 return null;
1329 }
Yorke Lee4af59352015-05-13 14:14:54 -07001330 return new AudioState(mCallAudioState);
1331 }
1332
1333 /**
1334 * @return The audio state of the connection, describing how its audio is currently
1335 * being routed by the system. This is {@code null} if this Connection
1336 * does not directly know about its audio state.
1337 */
1338 public final CallAudioState getCallAudioState() {
1339 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001340 }
1341
1342 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001343 * @return The conference that this connection is a part of. Null if it is not part of any
1344 * conference.
1345 */
1346 public final Conference getConference() {
1347 return mConference;
1348 }
1349
1350 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001351 * Returns whether this connection is requesting that the system play a ringback tone
1352 * on its behalf.
1353 */
Andrew Lee100e2932014-09-08 15:34:24 -07001354 public final boolean isRingbackRequested() {
1355 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001356 }
1357
1358 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001359 * @return True if the connection's audio mode is VOIP.
1360 */
1361 public final boolean getAudioModeIsVoip() {
1362 return mAudioModeIsVoip;
1363 }
1364
1365 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001366 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1367 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1368 * start time of the conference.
1369 *
1370 * @return The time at which the {@code Connnection} was connected.
1371 *
1372 * @hide
1373 */
1374 public final long getConnectTimeMillis() {
1375 return mConnectTimeMillis;
1376 }
1377
1378 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001379 * @return The status hints for this connection.
1380 */
1381 public final StatusHints getStatusHints() {
1382 return mStatusHints;
1383 }
1384
1385 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001386 * Returns the extras associated with this connection.
Tyler Gunndee56a82016-03-23 16:06:34 -07001387 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001388 * @return The extras associated with this connection.
1389 */
1390 public final Bundle getExtras() {
1391 return mExtras;
1392 }
1393
1394 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001395 * Assign a listener to be notified of state changes.
1396 *
1397 * @param l A listener.
1398 * @return This Connection.
1399 *
1400 * @hide
1401 */
1402 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001403 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001404 return this;
1405 }
1406
1407 /**
1408 * Remove a previously assigned listener that was being notified of state changes.
1409 *
1410 * @param l A Listener.
1411 * @return This Connection.
1412 *
1413 * @hide
1414 */
1415 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001416 if (l != null) {
1417 mListeners.remove(l);
1418 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001419 return this;
1420 }
1421
1422 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001423 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001424 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001425 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001426 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001427 }
1428
1429 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001430 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1431 * ONLY for debugging purposes.
1432 *
1433 * @param callId The telecom call ID.
1434 * @hide
1435 */
1436 public void setTelecomCallId(String callId) {
1437 mTelecomCallId = callId;
1438 }
1439
1440 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001441 * Inform this Connection that the state of its audio output has been changed externally.
1442 *
1443 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001444 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001445 */
Yorke Lee4af59352015-05-13 14:14:54 -07001446 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001447 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001448 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001449 mCallAudioState = state;
1450 onAudioStateChanged(getAudioState());
1451 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001452 }
1453
1454 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001455 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001456 * @return A string representation of the value.
1457 */
1458 public static String stateToString(int state) {
1459 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001461 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001463 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001465 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001467 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001469 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001471 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001473 return "DISCONNECTED";
1474 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001475 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001476 return "UNKNOWN";
1477 }
1478 }
1479
1480 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001481 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001482 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001483 public final int getConnectionCapabilities() {
1484 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001485 }
1486
1487 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001488 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001489 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -07001490 */
1491 public final int getConnectionProperties() {
1492 return mConnectionProperties;
1493 }
1494
1495 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001496 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001497 *
Andrew Lee100e2932014-09-08 15:34:24 -07001498 * @param address The new address.
1499 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001500 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001501 */
Andrew Lee100e2932014-09-08 15:34:24 -07001502 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001503 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001504 Log.d(this, "setAddress %s", address);
1505 mAddress = address;
1506 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001507 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001508 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001509 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001510 }
1511
1512 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001513 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001514 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001515 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001516 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001517 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001518 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001519 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001520 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001521 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001522 mCallerDisplayName = callerDisplayName;
1523 mCallerDisplayNamePresentation = presentation;
1524 for (Listener l : mListeners) {
1525 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1526 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001527 }
1528
1529 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001530 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001531 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1532 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1533 * {@link VideoProfile#STATE_TX_ENABLED},
1534 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001535 *
1536 * @param videoState The new video state.
1537 */
1538 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001540 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001541 mVideoState = videoState;
1542 for (Listener l : mListeners) {
1543 l.onVideoStateChanged(this, mVideoState);
1544 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001545 }
1546
1547 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001548 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001549 * communicate).
1550 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001551 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001552 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001553 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001554 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001555 }
1556
1557 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001558 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001559 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001560 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001561 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001563 }
1564
1565 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001566 * Sets state to initializing (this Connection is not yet ready to be used).
1567 */
1568 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001569 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001571 }
1572
1573 /**
1574 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1575 */
1576 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001578 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001579 }
1580
1581 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001582 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001583 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001584 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001585 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001586 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001587 }
1588
1589 /**
1590 * Sets state to be on hold.
1591 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001592 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001593 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001594 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001595 }
1596
1597 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001598 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001600 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001601 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001602 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001604 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001606 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001607 }
1608
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 public final VideoProvider getVideoProvider() {
1610 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001611 }
1612
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001613 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001614 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001615 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001616 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001617 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001618 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001619 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001620 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001621 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001622 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001623 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001624 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001625 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001626 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001627 }
1628
1629 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001630 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1631 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1632 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1633 * to send an {@link #onPostDialContinue(boolean)} signal.
1634 *
1635 * @param remaining The DTMF character sequence remaining to be emitted once the
1636 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1637 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001638 */
1639 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001640 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001641 for (Listener l : mListeners) {
1642 l.onPostDialWait(this, remaining);
1643 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001644 }
1645
1646 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001647 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1648 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001649 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001650 *
1651 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001652 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001653 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001654 checkImmutable();
1655 for (Listener l : mListeners) {
1656 l.onPostDialChar(this, nextChar);
1657 }
1658 }
1659
1660 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001661 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001662 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001663 *
1664 * @param ringback Whether the ringback tone is to be played.
1665 */
Andrew Lee100e2932014-09-08 15:34:24 -07001666 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001667 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001668 if (mRingbackRequested != ringback) {
1669 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001670 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001671 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001672 }
1673 }
Ihab Awadf8358972014-05-28 16:46:42 -07001674 }
1675
1676 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001678 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001679 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001680 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001681 public final void setConnectionCapabilities(int connectionCapabilities) {
1682 checkImmutable();
1683 if (mConnectionCapabilities != connectionCapabilities) {
1684 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001685 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001686 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001687 }
1688 }
Santos Cordonb6939982014-06-04 20:20:58 -07001689 }
1690
1691 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001692 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1693 *
1694 * @param connectionProperties The new connection properties.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001695 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -07001696 */
1697 public final void setConnectionProperties(int connectionProperties) {
1698 checkImmutable();
1699 if (mConnectionProperties != connectionProperties) {
1700 mConnectionProperties = connectionProperties;
1701 for (Listener l : mListeners) {
1702 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1703 }
1704 }
1705 }
1706
1707 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001708 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001709 */
Evan Charlton36a71342014-07-19 16:31:02 -07001710 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001711 for (Listener l : mListeners) {
1712 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001713 }
Santos Cordonb6939982014-06-04 20:20:58 -07001714 }
1715
1716 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001717 * Requests that the framework use VOIP audio mode for this connection.
1718 *
1719 * @param isVoip True if the audio mode is VOIP.
1720 */
1721 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001722 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001723 mAudioModeIsVoip = isVoip;
1724 for (Listener l : mListeners) {
1725 l.onAudioModeIsVoipChanged(this, isVoip);
1726 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001727 }
1728
1729 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001730 * Sets the time at which a call became active on this Connection. This is set only
1731 * when a conference call becomes active on this connection.
1732 *
1733 * @param connectionTimeMillis The connection time, in milliseconds.
1734 *
1735 * @hide
1736 */
1737 public final void setConnectTimeMillis(long connectTimeMillis) {
1738 mConnectTimeMillis = connectTimeMillis;
1739 }
1740
1741 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001742 * Sets the label and icon status to display in the in-call UI.
1743 *
1744 * @param statusHints The status label and icon to set.
1745 */
1746 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001747 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001748 mStatusHints = statusHints;
1749 for (Listener l : mListeners) {
1750 l.onStatusHintsChanged(this, statusHints);
1751 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001752 }
1753
1754 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001755 * Sets the connections with which this connection can be conferenced.
1756 *
1757 * @param conferenceableConnections The set of connections this connection can conference with.
1758 */
1759 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001760 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001761 clearConferenceableList();
1762 for (Connection c : conferenceableConnections) {
1763 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1764 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001765 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001766 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001767 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001768 }
1769 }
1770 fireOnConferenceableConnectionsChanged();
1771 }
1772
1773 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001774 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1775 * or conferences with which this connection can be conferenced.
1776 *
1777 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001778 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001779 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001780 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001781 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001782 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1783 // small amount of items here.
1784 if (!mConferenceables.contains(c)) {
1785 if (c instanceof Connection) {
1786 Connection connection = (Connection) c;
1787 connection.addConnectionListener(mConnectionDeathListener);
1788 } else if (c instanceof Conference) {
1789 Conference conference = (Conference) c;
1790 conference.addListener(mConferenceDeathListener);
1791 }
1792 mConferenceables.add(c);
1793 }
1794 }
1795 fireOnConferenceableConnectionsChanged();
1796 }
1797
1798 /**
1799 * Returns the connections or conferences with which this connection can be conferenced.
1800 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001801 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001802 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001803 }
1804
Yorke Lee53463962015-08-04 16:07:19 -07001805 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001806 * @hide
1807 */
1808 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001809 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001810 if (mConnectionService != null) {
1811 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1812 "which is already associated with another ConnectionService.");
1813 } else {
1814 mConnectionService = connectionService;
1815 }
1816 }
1817
1818 /**
1819 * @hide
1820 */
1821 public final void unsetConnectionService(ConnectionService connectionService) {
1822 if (mConnectionService != connectionService) {
1823 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1824 "that does not belong to the ConnectionService.");
1825 } else {
1826 mConnectionService = null;
1827 }
1828 }
1829
1830 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001831 * @hide
1832 */
1833 public final ConnectionService getConnectionService() {
1834 return mConnectionService;
1835 }
1836
1837 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001838 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001839 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001840 *
1841 * @param conference The conference.
1842 * @return {@code true} if the conference was successfully set.
1843 * @hide
1844 */
1845 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001846 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001847 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001848 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001849 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001850 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1851 fireConferenceChanged();
1852 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001853 return true;
1854 }
1855 return false;
1856 }
1857
1858 /**
1859 * Resets the conference that this connection is a part of.
1860 * @hide
1861 */
1862 public final void resetConference() {
1863 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001864 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001865 mConference = null;
1866 fireConferenceChanged();
1867 }
1868 }
1869
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001870 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001871 * Set some extras that can be associated with this {@code Connection}.
1872 * <p>
1873 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1874 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1875 * <p>
1876 * 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 -07001877 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1878 *
1879 * @param extras The extras associated with this {@code Connection}.
1880 */
1881 public final void setExtras(@Nullable Bundle extras) {
1882 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001883
1884 // Add/replace any new or changed extras values.
1885 putExtras(extras);
1886
1887 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1888 // the current one and remove any keys that went away.
1889 if (mPreviousExtraKeys != null) {
1890 List<String> toRemove = new ArrayList<String>();
1891 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001892 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001893 toRemove.add(oldKey);
1894 }
1895 }
1896 if (!toRemove.isEmpty()) {
1897 removeExtras(toRemove);
1898 }
1899 }
1900
1901 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1902 // called we can see if the caller has removed any extras values.
1903 if (mPreviousExtraKeys == null) {
1904 mPreviousExtraKeys = new ArraySet<String>();
1905 }
1906 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001907 if (extras != null) {
1908 mPreviousExtraKeys.addAll(extras.keySet());
1909 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001910 }
1911
1912 /**
1913 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1914 * added.
1915 * <p>
1916 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1917 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1918 *
1919 * @param extras The extras to add.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001920 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -07001921 */
1922 public final void putExtras(@NonNull Bundle extras) {
1923 checkImmutable();
1924 if (extras == null) {
1925 return;
1926 }
1927
1928 if (mExtras == null) {
1929 mExtras = new Bundle();
1930 }
1931 mExtras.putAll(extras);
1932
Santos Cordon6b7f9552015-05-27 17:21:45 -07001933 for (Listener l : mListeners) {
1934 l.onExtrasChanged(this, extras);
1935 }
1936 }
1937
1938 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001939 * Adds a boolean extra to this {@code Connection}.
1940 *
1941 * @param key The extra key.
1942 * @param value The value.
1943 * @hide
1944 */
1945 public final void putExtra(String key, boolean value) {
1946 Bundle newExtras = new Bundle();
1947 newExtras.putBoolean(key, value);
1948 putExtras(newExtras);
1949 }
1950
1951 /**
1952 * Adds an integer extra to this {@code Connection}.
1953 *
1954 * @param key The extra key.
1955 * @param value The value.
1956 * @hide
1957 */
1958 public final void putExtra(String key, int value) {
1959 Bundle newExtras = new Bundle();
1960 newExtras.putInt(key, value);
1961 putExtras(newExtras);
1962 }
1963
1964 /**
1965 * Adds a string extra to this {@code Connection}.
1966 *
1967 * @param key The extra key.
1968 * @param value The value.
1969 * @hide
1970 */
1971 public final void putExtra(String key, String value) {
1972 Bundle newExtras = new Bundle();
1973 newExtras.putString(key, value);
1974 putExtras(newExtras);
1975 }
1976
1977 /**
1978 * Removes an extra from this {@code Connection}.
1979 *
1980 * @param keys The key of the extra key to remove.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07001981 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -07001982 */
1983 public final void removeExtras(List<String> keys) {
1984 if (mExtras != null) {
1985 for (String key : keys) {
1986 mExtras.remove(key);
1987 }
1988
1989 if (mExtras.size() == 0) {
1990 mExtras = null;
1991 }
1992 }
1993
1994 for (Listener l : mListeners) {
1995 l.onExtrasRemoved(this, keys);
1996 }
1997 }
1998
1999 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002000 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002001 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002002 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002003 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2004 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002005 */
Yorke Lee4af59352015-05-13 14:14:54 -07002006 @SystemApi
2007 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002008 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002009
2010 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002011 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2012 *
2013 * @param state The new connection audio state.
2014 */
2015 public void onCallAudioStateChanged(CallAudioState state) {}
2016
2017 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002018 * Notifies this Connection of an internal state change. This method is called after the
2019 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002020 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002021 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002022 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002023 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002024
2025 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002026 * Notifies this Connection of a request to play a DTMF tone.
2027 *
2028 * @param c A DTMF character.
2029 */
Santos Cordonf2951102014-07-20 19:06:29 -07002030 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002031
2032 /**
2033 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2034 */
Santos Cordonf2951102014-07-20 19:06:29 -07002035 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002036
2037 /**
2038 * Notifies this Connection of a request to disconnect.
2039 */
Santos Cordonf2951102014-07-20 19:06:29 -07002040 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002041
2042 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002043 * Notifies this Connection of a request to disconnect a participant of the conference managed
2044 * by the connection.
2045 *
2046 * @param endpoint the {@link Uri} of the participant to disconnect.
2047 * @hide
2048 */
2049 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2050
2051 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002052 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002053 */
Santos Cordonf2951102014-07-20 19:06:29 -07002054 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002055
2056 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002057 * Notifies this Connection of a request to abort.
2058 */
Santos Cordonf2951102014-07-20 19:06:29 -07002059 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002060
2061 /**
2062 * Notifies this Connection of a request to hold.
2063 */
Santos Cordonf2951102014-07-20 19:06:29 -07002064 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065
2066 /**
2067 * Notifies this Connection of a request to exit a hold state.
2068 */
Santos Cordonf2951102014-07-20 19:06:29 -07002069 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070
2071 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002072 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002073 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002074 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002075 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 */
Santos Cordonf2951102014-07-20 19:06:29 -07002077 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002078
2079 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002080 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002081 * a request to accept.
2082 */
2083 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002084 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002085 }
2086
2087 /**
2088 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002089 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 */
Santos Cordonf2951102014-07-20 19:06:29 -07002091 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002093 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002094 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2095 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002096 */
2097 public void onReject(String replyMessage) {}
2098
2099 /**
Bryce Leecac50772015-11-17 15:13:29 -08002100 * Notifies the Connection of a request to silence the ringer.
2101 *
2102 * @hide
2103 */
2104 public void onSilence() {}
2105
2106 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002107 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2108 */
Santos Cordonf2951102014-07-20 19:06:29 -07002109 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002110
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002111 /**
2112 * Notifies this Connection of a request to pull an external call to the local device.
2113 * <p>
2114 * The {@link InCallService} issues a request to pull an external call to the local device via
2115 * {@link Call#pullExternalCall()}.
2116 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002117 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2118 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002119 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002120 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07002121 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002122 */
2123 public void onPullExternalCall() {}
2124
2125 /**
2126 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2127 * <p>
2128 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2129 * <p>
2130 * See also {@link Call#sendCallEvent(String, Bundle)}.
2131 *
2132 * @param event The call event.
2133 * @param extras Extras associated with the call event.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07002134 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002135 */
2136 public void onCallEvent(String event, Bundle extras) {}
2137
Tyler Gunndee56a82016-03-23 16:06:34 -07002138 /**
2139 * Notifies this {@link Connection} of a change to the extras made outside the
2140 * {@link ConnectionService}.
2141 * <p>
2142 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2143 * the {@link android.telecom.Call#putExtras(Bundle)} and
2144 * {@link Call#removeExtras(List)}.
2145 *
2146 * @param extras The new extras bundle.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07002147 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -07002148 */
2149 public void onExtrasChanged(Bundle extras) {}
2150
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002151 static String toLogSafePhoneNumber(String number) {
2152 // For unknown number, log empty string.
2153 if (number == null) {
2154 return "";
2155 }
2156
2157 if (PII_DEBUG) {
2158 // When PII_DEBUG is true we emit PII.
2159 return number;
2160 }
2161
2162 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2163 // sanitized phone numbers.
2164 StringBuilder builder = new StringBuilder();
2165 for (int i = 0; i < number.length(); i++) {
2166 char c = number.charAt(i);
2167 if (c == '-' || c == '@' || c == '.') {
2168 builder.append(c);
2169 } else {
2170 builder.append('x');
2171 }
2172 }
2173 return builder.toString();
2174 }
2175
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002178 if (mState == STATE_DISCONNECTED && mState != state) {
2179 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002180 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002181 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002182 if (mState != state) {
2183 Log.d(this, "setState: %s", stateToString(state));
2184 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002185 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002186 for (Listener l : mListeners) {
2187 l.onStateChanged(this, state);
2188 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002189 }
2190 }
2191
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002192 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002193 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002194 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2195 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002196 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002197 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002198
2199 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002200 if (mImmutable) {
2201 throw new UnsupportedOperationException("Connection is immutable");
2202 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002203 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002204 }
2205
Evan Charltonbf11f982014-07-20 22:06:28 -07002206 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002207 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002208 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2209 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002210 * <p>
2211 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2212 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002213 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002214 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002215 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002216 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002217 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2218 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002219 }
2220
Evan Charltonbf11f982014-07-20 22:06:28 -07002221 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002222 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2223 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2224 * this should never be un-@hide-den.
2225 *
2226 * @hide
2227 */
2228 public void checkImmutable() {}
2229
2230 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002231 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2232 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2233 * that state. This connection should not be used for anything, and no other
2234 * {@code Connection}s should be attempted.
2235 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002236 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002237 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002238 * @return A {@code Connection} which indicates that the underlying connection should
2239 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002240 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002241 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002242 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002243 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002244
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002245 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002246 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002247 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002248 }
2249 }
2250
Santos Cordon823fd3c2014-08-07 18:35:18 -07002251 private final void fireConferenceChanged() {
2252 for (Listener l : mListeners) {
2253 l.onConferenceChanged(this, mConference);
2254 }
2255 }
2256
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002257 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002258 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002259 if (c instanceof Connection) {
2260 Connection connection = (Connection) c;
2261 connection.removeConnectionListener(mConnectionDeathListener);
2262 } else if (c instanceof Conference) {
2263 Conference conference = (Conference) c;
2264 conference.removeListener(mConferenceDeathListener);
2265 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002266 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002267 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002268 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002269
2270 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002271 * Handles a change to extras received from Telecom.
2272 *
2273 * @param extras The new extras.
2274 * @hide
2275 */
2276 final void handleExtrasChanged(Bundle extras) {
2277 mExtras = extras;
2278 onExtrasChanged(mExtras);
2279 }
2280
2281 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002282 * Notifies listeners that the merge request failed.
2283 *
2284 * @hide
2285 */
2286 protected final void notifyConferenceMergeFailed() {
2287 for (Listener l : mListeners) {
2288 l.onConferenceMergeFailed(this);
2289 }
2290 }
2291
2292 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002293 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002294 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002295 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002296 * @hide
2297 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002298 protected final void updateConferenceParticipants(
2299 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002300 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002301 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002302 }
2303 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002304
2305 /**
2306 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002307 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002308 */
2309 protected void notifyConferenceStarted() {
2310 for (Listener l : mListeners) {
2311 l.onConferenceStarted();
2312 }
2313 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002314
2315 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002316 * Sends an event associated with this {@code Connection}, with associated event extras.
2317 *
2318 * Events are exposed to {@link InCallService} implementations via the
2319 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2320 *
2321 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2322 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002323 *
2324 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002325 * @param extras Bundle containing extra information associated with the event.
Tyler Gunn1bf206b2016-04-15 11:28:44 -07002326 * @hide
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002327 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002328 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002329 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002330 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002331 }
2332 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002333}