blob: 5843fbbe75326336ddce5d5665ddd5a73c9b53d9 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070038import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
44/**
Santos Cordon895d4b82015-06-25 16:41:48 -070045 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
46 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070047 * <p>
48 * Implementations create a custom subclass of {@code Connection} and return it to the framework
49 * as the return value of
50 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
51 * or
52 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
53 * Implementations are then responsible for updating the state of the {@code Connection}, and
54 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
55 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070056 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070057public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
Santos Cordon895d4b82015-06-25 16:41:48 -070059 /**
60 * The connection is initializing. This is generally the first state for a {@code Connection}
61 * returned by a {@link ConnectionService}.
62 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 public static final int STATE_INITIALIZING = 0;
64
Santos Cordon895d4b82015-06-25 16:41:48 -070065 /**
66 * The connection is new and not connected.
67 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 public static final int STATE_NEW = 1;
69
Santos Cordon895d4b82015-06-25 16:41:48 -070070 /**
71 * An incoming connection is in the ringing state. During this state, the user's ringer or
72 * vibration feature will be activated.
73 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 public static final int STATE_RINGING = 2;
75
Santos Cordon895d4b82015-06-25 16:41:48 -070076 /**
77 * An outgoing connection is in the dialing state. In this state the other party has not yet
78 * answered the call and the user traditionally hears a ringback tone.
79 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 public static final int STATE_DIALING = 3;
81
Santos Cordon895d4b82015-06-25 16:41:48 -070082 /**
83 * A connection is active. Both parties are connected to the call and can actively communicate.
84 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 public static final int STATE_ACTIVE = 4;
86
Santos Cordon895d4b82015-06-25 16:41:48 -070087 /**
88 * A connection is on hold.
89 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 public static final int STATE_HOLDING = 5;
91
Santos Cordon895d4b82015-06-25 16:41:48 -070092 /**
93 * A connection has been disconnected. This is the final state once the user has been
94 * disconnected from a call either locally, remotely or by an error in the service.
95 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public static final int STATE_DISCONNECTED = 6;
97
Santos Cordon895d4b82015-06-25 16:41:48 -070098 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external connection which is in the process of being pulled from a remote
100 * device to the local device.
101 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700102 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700103 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
104 */
105 public static final int STATE_PULLING_CALL = 7;
106
107 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 * Connection can currently be put on hold or unheld. This is distinct from
109 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
110 * it does not at the moment support the function. This can be true while the call is in the
111 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
112 * display a disabled 'hold' button.
113 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 public static final int CAPABILITY_HOLD = 0x00000001;
115
116 /** Connection supports the hold feature. */
117 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
118
119 /**
120 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
121 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
122 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
123 * capability allows a merge button to be shown while the conference is in the foreground
124 * of the in-call UI.
125 * <p>
126 * This is only intended for use by a {@link Conference}.
127 */
128 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
129
130 /**
131 * Connections within a conference can be swapped between foreground and background.
132 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
133 * <p>
134 * This is only intended for use by a {@link Conference}.
135 */
136 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
137
138 /**
139 * @hide
140 */
141 public static final int CAPABILITY_UNUSED = 0x00000010;
142
143 /** Connection supports responding via text option. */
144 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
145
146 /** Connection can be muted. */
147 public static final int CAPABILITY_MUTE = 0x00000040;
148
149 /**
150 * Connection supports conference management. This capability only applies to
151 * {@link Conference}s which can have {@link Connection}s as children.
152 */
153 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
154
155 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700158 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159
160 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164
165 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700168 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
175
176 /**
177 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 */
179 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
180
181 /**
182 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
188 * Connection is able to be separated from its parent {@code Conference}, if any.
189 */
190 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
191
192 /**
193 * Connection is able to be individually disconnected when in a {@code Conference}.
194 */
195 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
196
197 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700198 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 * @hide
200 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700201 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700204 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 * @hide
206 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700207 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208
209 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700210 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * @hide
212 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700213 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214
Tyler Gunn068085b2015-02-06 13:56:52 -0800215 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700216 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800217 * @hide
218 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700219 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800220
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 */
225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Tyler Gunnd4091732015-06-29 09:15:37 -0700238 /**
239 * For a conference, indicates the conference will not have child connections.
240 * <p>
241 * An example of a conference with child connections is a GSM conference call, where the radio
242 * retains connections to the individual participants of the conference. Another example is an
243 * IMS conference call where conference event package functionality is supported; in this case
244 * the conference server ensures the radio is aware of the participants in the conference, which
245 * are represented by child connections.
246 * <p>
247 * An example of a conference with no child connections is an IMS conference call with no
248 * conference event package support. Such a conference is represented by the radio as a single
249 * connection to the IMS conference server.
250 * <p>
251 * Indicating whether a conference has children or not is important to help user interfaces
252 * visually represent a conference. A conference with no children, for example, will have the
253 * conference connection shown in the list of calls on a Bluetooth device, where if the
254 * conference has children, only the children will be shown in the list of calls on a Bluetooth
255 * device.
256 * @hide
257 */
258 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259
Bryce Lee81901682015-08-28 16:38:02 -0700260 /**
261 * Indicates that the connection itself wants to handle any sort of reply response, rather than
262 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700263 */
264 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
265
Tyler Gunnf97a0092016-01-19 15:59:34 -0800266 /**
267 * When set, prevents a video call from being downgraded to an audio-only call.
268 * <p>
269 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271 * downgraded from a video call back to a VideoState of
272 * {@link VideoProfile#STATE_AUDIO_ONLY}.
273 * <p>
274 * Intuitively, a call which can be downgraded to audio should also have local and remote
275 * video
276 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278 */
279 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700281 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 * When set for an external connection, indicates that this {@code Connection} can be pulled
283 * from a remote device to the current device.
284 * <p>
285 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
286 * is set.
287 */
288 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
289
290 //**********************************************************************************************
291 // Next CAPABILITY value: 0x02000000
292 //**********************************************************************************************
293
294 /**
295 * Indicates that the current device callback number should be shown.
296 *
297 * @hide
298 */
299 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
300
301 /**
302 * Whether the call is a generic conference, where we do not know the precise state of
303 * participants in the conference (eg. on CDMA).
304 *
305 * @hide
306 */
307 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
308
309 /**
310 * Connection is using high definition audio.
311 * @hide
312 */
313 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
314
315 /**
316 * Connection is using WIFI.
317 * @hide
318 */
319 public static final int PROPERTY_WIFI = 1<<3;
320
321 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 * When set, indicates that the {@code Connection} does not actually exist locally for the
323 * {@link ConnectionService}.
324 * <p>
325 * Consider, for example, a scenario where a user has two devices with the same phone number.
326 * When a user places a call on one devices, the telephony stack can represent that call on the
327 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700328 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700329 * <p>
330 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
331 * external connections. Only those {@link InCallService}s which have the
332 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
333 * manifest will see external connections.
334 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336
Brad Ebinger15847072016-05-18 11:08:36 -0700337 /**
338 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
339 */
340 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700341
Tyler Gunn96d6c402015-03-18 12:39:23 -0700342 //**********************************************************************************************
Brad Ebinger15847072016-05-18 11:08:36 -0700343 // Next PROPERTY value: 1<<6
Tyler Gunn96d6c402015-03-18 12:39:23 -0700344 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800345
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700346 /**
347 * Connection extra key used to store the last forwarded number associated with the current
348 * connection. Used to communicate to the user interface that the connection was forwarded via
349 * the specified number.
350 */
351 public static final String EXTRA_LAST_FORWARDED_NUMBER =
352 "android.telecom.extra.LAST_FORWARDED_NUMBER";
353
354 /**
355 * Connection extra key used to store a child number associated with the current connection.
356 * Used to communicate to the user interface that the connection was received via
357 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
358 * address.
359 */
360 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
361
362 /**
363 * Connection extra key used to store the subject for an incoming call. The user interface can
364 * query this extra and display its contents for incoming calls. Will only be used if the
365 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
366 */
367 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
368
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800369 /**
370 * Connection event used to inform Telecom that it should play the on hold tone. This is used
371 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
372 * {@link #sendConnectionEvent(String)}.
373 * @hide
374 */
375 public static final String EVENT_ON_HOLD_TONE_START =
376 "android.telecom.event.ON_HOLD_TONE_START";
377
378 /**
379 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
380 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
381 * {@link #sendConnectionEvent(String)}.
382 * @hide
383 */
384 public static final String EVENT_ON_HOLD_TONE_END =
385 "android.telecom.event.ON_HOLD_TONE_END";
386
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700387 /**
388 * Connection event used to inform {@link InCallService}s when pulling of an external call has
389 * failed. The user interface should inform the user of the error.
390 * <p>
391 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
392 * API is called on a {@link Call} with the properties
393 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
394 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
395 * pull the external call due to an error condition.
396 */
397 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
398
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700399 /**
400 * Connection event used to inform {@link InCallService}s when the merging of two calls has
401 * failed. The User Interface should use this message to inform the user of the error.
402 */
403 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
404
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700405 // Flag controlling whether PII is emitted into the logs
406 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
407
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800408 /**
409 * Whether the given capabilities support the specified capability.
410 *
411 * @param capabilities A capability bit field.
412 * @param capability The capability to check capabilities for.
413 * @return Whether the specified capability is supported.
414 * @hide
415 */
416 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800417 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 }
419
420 /**
421 * Whether the capabilities of this {@code Connection} supports the specified capability.
422 *
423 * @param capability The capability to check capabilities for.
424 * @return Whether the specified capability is supported.
425 * @hide
426 */
427 public boolean can(int capability) {
428 return can(mConnectionCapabilities, capability);
429 }
430
431 /**
432 * Removes the specified capability from the set of capabilities of this {@code Connection}.
433 *
434 * @param capability The capability to remove from the set.
435 * @hide
436 */
437 public void removeCapability(int capability) {
438 mConnectionCapabilities &= ~capability;
439 }
440
441 /**
442 * Adds the specified capability to the set of capabilities of this {@code Connection}.
443 *
444 * @param capability The capability to add to the set.
445 * @hide
446 */
447 public void addCapability(int capability) {
448 mConnectionCapabilities |= capability;
449 }
450
451
452 public static String capabilitiesToString(int capabilities) {
453 StringBuilder builder = new StringBuilder();
454 builder.append("[Capabilities:");
455 if (can(capabilities, CAPABILITY_HOLD)) {
456 builder.append(" CAPABILITY_HOLD");
457 }
458 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
459 builder.append(" CAPABILITY_SUPPORT_HOLD");
460 }
461 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
462 builder.append(" CAPABILITY_MERGE_CONFERENCE");
463 }
464 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
465 builder.append(" CAPABILITY_SWAP_CONFERENCE");
466 }
467 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
468 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
469 }
470 if (can(capabilities, CAPABILITY_MUTE)) {
471 builder.append(" CAPABILITY_MUTE");
472 }
473 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
474 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
475 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700476 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
477 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
478 }
479 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
480 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
481 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700482 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
483 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800484 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700485 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
486 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
487 }
488 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
489 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
490 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700491 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
492 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800494 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
495 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
496 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500497 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700498 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500499 }
Rekha Kumar07366812015-03-24 16:42:31 -0700500 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
501 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
502 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700503 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
504 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
505 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700506 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
507 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
508 }
Bryce Lee81901682015-08-28 16:38:02 -0700509 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
510 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
511 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700512 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
513 builder.append(" CAPABILITY_CAN_PULL_CALL");
514 }
Bryce Lee81901682015-08-28 16:38:02 -0700515
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800516 builder.append("]");
517 return builder.toString();
518 }
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
Brad Ebinger15847072016-05-18 11:08:36 -0700544 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
545 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
546 }
547
Tyler Gunn720c6642016-03-22 09:02:47 -0700548 builder.append("]");
549 return builder.toString();
550 }
551
Sailesh Nepal091768c2014-06-30 15:15:23 -0700552 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700553 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700554 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700555 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700556 public void onCallerDisplayNameChanged(
557 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700558 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700559 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700560 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800561 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700562 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700563 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800564 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700565 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566 public void onVideoProviderChanged(
567 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700568 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
569 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800570 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700571 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700572 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700573 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800574 public void onConferenceParticipantsChanged(Connection c,
575 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800576 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700577 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700578 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700579 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700580 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700581 }
582
Tyler Gunnb702ef82015-05-29 11:51:53 -0700583 /**
584 * Provides a means of controlling the video session associated with a {@link Connection}.
585 * <p>
586 * Implementations create a custom subclass of {@link VideoProvider} and the
587 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
588 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
589 * should set the {@link VideoProvider}.
590 * <p>
591 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
592 * {@link InCallService} implementations to issue requests related to the video session;
593 * it provides a means for the {@link ConnectionService} to report events and information
594 * related to the video session to Telecom and the {@link InCallService} implementations.
595 * <p>
596 * {@link InCallService} implementations interact with the {@link VideoProvider} via
597 * {@link android.telecom.InCallService.VideoCall}.
598 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700600
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700601 /**
602 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700603 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700604 */
605 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700606
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700607 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700608 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
609 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700610 */
611 public static final int SESSION_EVENT_RX_RESUME = 2;
612
613 /**
614 * Video transmission has begun. This occurs after a negotiated start of video transmission
615 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700616 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 */
618 public static final int SESSION_EVENT_TX_START = 3;
619
620 /**
621 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
622 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700623 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 */
625 public static final int SESSION_EVENT_TX_STOP = 4;
626
627 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700628 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
629 * this as a cue to inform the user the camera is not available.
630 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 */
632 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
633
634 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700635 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
636 * for operation. The {@link InCallService} can use this as a cue to inform the user that
637 * the camera has become available again.
638 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 */
640 public static final int SESSION_EVENT_CAMERA_READY = 6;
641
642 /**
643 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700644 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700645 */
646 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
647
648 /**
649 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700650 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 */
652 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
653
654 /**
655 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700656 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 */
658 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
659
Rekha Kumar07366812015-03-24 16:42:31 -0700660 /**
661 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700662 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700663 */
664 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
665
666 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700667 * Session modify request rejected by remote user.
668 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700669 */
670 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
671
Tyler Gunn75958422015-04-15 14:23:42 -0700672 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700673 private static final int MSG_SET_CAMERA = 2;
674 private static final int MSG_SET_PREVIEW_SURFACE = 3;
675 private static final int MSG_SET_DISPLAY_SURFACE = 4;
676 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
677 private static final int MSG_SET_ZOOM = 6;
678 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
679 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
680 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800681 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700683 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700684
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700685 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700686 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700687
688 /**
689 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700690 *
691 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
692 * load factor before resizing, 1 means we only expect a single thread to
693 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700694 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700695 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
696 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697
698 /**
699 * Default handler used to consolidate binder method calls onto a single thread.
700 */
701 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700702 public VideoProviderHandler() {
703 super();
704 }
705
706 public VideoProviderHandler(Looper looper) {
707 super(looper);
708 }
709
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700710 @Override
711 public void handleMessage(Message msg) {
712 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700713 case MSG_ADD_VIDEO_CALLBACK: {
714 IBinder binder = (IBinder) msg.obj;
715 IVideoCallback callback = IVideoCallback.Stub
716 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700717 if (callback == null) {
718 Log.w(this, "addVideoProvider - skipped; callback is null.");
719 break;
720 }
721
Tyler Gunn75958422015-04-15 14:23:42 -0700722 if (mVideoCallbacks.containsKey(binder)) {
723 Log.i(this, "addVideoProvider - skipped; already present.");
724 break;
725 }
726 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700728 }
729 case MSG_REMOVE_VIDEO_CALLBACK: {
730 IBinder binder = (IBinder) msg.obj;
731 IVideoCallback callback = IVideoCallback.Stub
732 .asInterface((IBinder) msg.obj);
733 if (!mVideoCallbacks.containsKey(binder)) {
734 Log.i(this, "removeVideoProvider - skipped; not present.");
735 break;
736 }
737 mVideoCallbacks.remove(binder);
738 break;
739 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 case MSG_SET_CAMERA:
741 onSetCamera((String) msg.obj);
742 break;
743 case MSG_SET_PREVIEW_SURFACE:
744 onSetPreviewSurface((Surface) msg.obj);
745 break;
746 case MSG_SET_DISPLAY_SURFACE:
747 onSetDisplaySurface((Surface) msg.obj);
748 break;
749 case MSG_SET_DEVICE_ORIENTATION:
750 onSetDeviceOrientation(msg.arg1);
751 break;
752 case MSG_SET_ZOOM:
753 onSetZoom((Float) msg.obj);
754 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700755 case MSG_SEND_SESSION_MODIFY_REQUEST: {
756 SomeArgs args = (SomeArgs) msg.obj;
757 try {
758 onSendSessionModifyRequest((VideoProfile) args.arg1,
759 (VideoProfile) args.arg2);
760 } finally {
761 args.recycle();
762 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700763 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700764 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 case MSG_SEND_SESSION_MODIFY_RESPONSE:
766 onSendSessionModifyResponse((VideoProfile) msg.obj);
767 break;
768 case MSG_REQUEST_CAMERA_CAPABILITIES:
769 onRequestCameraCapabilities();
770 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800771 case MSG_REQUEST_CONNECTION_DATA_USAGE:
772 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 break;
774 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700775 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 break;
777 default:
778 break;
779 }
780 }
781 }
782
783 /**
784 * IVideoProvider stub implementation.
785 */
786 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700787 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700789 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
790 }
791
792 public void removeVideoCallback(IBinder videoCallbackBinder) {
793 mMessageHandler.obtainMessage(
794 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700795 }
796
797 public void setCamera(String cameraId) {
798 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
799 }
800
801 public void setPreviewSurface(Surface surface) {
802 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
803 }
804
805 public void setDisplaySurface(Surface surface) {
806 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
807 }
808
809 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700810 mMessageHandler.obtainMessage(
811 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 }
813
814 public void setZoom(float value) {
815 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
816 }
817
Tyler Gunn45382162015-05-06 08:52:27 -0700818 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
819 SomeArgs args = SomeArgs.obtain();
820 args.arg1 = fromProfile;
821 args.arg2 = toProfile;
822 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700823 }
824
825 public void sendSessionModifyResponse(VideoProfile responseProfile) {
826 mMessageHandler.obtainMessage(
827 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
828 }
829
830 public void requestCameraCapabilities() {
831 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
832 }
833
834 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800835 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700836 }
837
Yorke Lee32f24732015-05-12 16:18:03 -0700838 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
840 }
841 }
842
843 public VideoProvider() {
844 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700845 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700846 }
847
848 /**
849 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
850 *
851 * @param looper The looper.
852 * @hide
853 */
854 public VideoProvider(Looper looper) {
855 mBinder = new VideoProvider.VideoProviderBinder();
856 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700857 }
858
859 /**
860 * Returns binder object which can be used across IPC methods.
861 * @hide
862 */
863 public final IVideoProvider getInterface() {
864 return mBinder;
865 }
866
867 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700868 * Sets the camera to be used for the outgoing video.
869 * <p>
870 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
871 * camera via
872 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
873 * <p>
874 * Sent from the {@link InCallService} via
875 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700877 * @param cameraId The id of the camera (use ids as reported by
878 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879 */
880 public abstract void onSetCamera(String cameraId);
881
882 /**
883 * Sets the surface to be used for displaying a preview of what the user's camera is
884 * currently capturing. When video transmission is enabled, this is the video signal which
885 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700886 * <p>
887 * Sent from the {@link InCallService} via
888 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700890 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700891 */
892 public abstract void onSetPreviewSurface(Surface surface);
893
894 /**
895 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 * <p>
897 * Sent from the {@link InCallService} via
898 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700899 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700900 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700901 */
902 public abstract void onSetDisplaySurface(Surface surface);
903
904 /**
905 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
906 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700907 * <p>
908 * Sent from the {@link InCallService} via
909 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700910 *
911 * @param rotation The device orientation, in degrees.
912 */
913 public abstract void onSetDeviceOrientation(int rotation);
914
915 /**
916 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700917 * <p>
918 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700919 *
920 * @param value The camera zoom ratio.
921 */
922 public abstract void onSetZoom(float value);
923
924 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700925 * Issues a request to modify the properties of the current video session.
926 * <p>
927 * Example scenarios include: requesting an audio-only call to be upgraded to a
928 * bi-directional video call, turning on or off the user's camera, sending a pause signal
929 * when the {@link InCallService} is no longer the foreground application.
930 * <p>
931 * If the {@link VideoProvider} determines a request to be invalid, it should call
932 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
933 * invalid request back to the {@link InCallService}.
934 * <p>
935 * Where a request requires confirmation from the user of the peer device, the
936 * {@link VideoProvider} must communicate the request to the peer device and handle the
937 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
938 * is used to inform the {@link InCallService} of the result of the request.
939 * <p>
940 * Sent from the {@link InCallService} via
941 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * @param fromProfile The video profile prior to the request.
944 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 */
Tyler Gunn45382162015-05-06 08:52:27 -0700946 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
947 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 /**
950 * Provides a response to a request to change the current video session properties.
951 * <p>
952 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
953 * video call, could decline the request and keep the call as audio-only.
954 * In such a scenario, the {@code responseProfile} would have a video state of
955 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
956 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
957 * <p>
958 * Sent from the {@link InCallService} via
959 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
960 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
961 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700963 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 */
965 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
966
967 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700968 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
969 * <p>
970 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
971 * camera via
972 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
973 * <p>
974 * Sent from the {@link InCallService} via
975 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 */
977 public abstract void onRequestCameraCapabilities();
978
979 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700980 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
981 * video component of the current {@link Connection}.
982 * <p>
983 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
984 * via {@link VideoProvider#setCallDataUsage(long)}.
985 * <p>
986 * Sent from the {@link InCallService} via
987 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700988 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800989 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990
991 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700992 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
993 * the peer device when the video signal is paused.
994 * <p>
995 * Sent from the {@link InCallService} via
996 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997 *
998 * @param uri URI of image to display.
999 */
Yorke Lee32f24732015-05-12 16:18:03 -07001000 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001
1002 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001003 * Used to inform listening {@link InCallService} implementations when the
1004 * {@link VideoProvider} receives a session modification request.
1005 * <p>
1006 * Received by the {@link InCallService} via
1007 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001009 * @param videoProfile The requested video profile.
1010 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
1012 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001013 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001014 for (IVideoCallback callback : mVideoCallbacks.values()) {
1015 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001016 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001017 } catch (RemoteException ignored) {
1018 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001019 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 }
1021 }
1022 }
1023
1024 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001025 * Used to inform listening {@link InCallService} implementations when the
1026 * {@link VideoProvider} receives a response to a session modification request.
1027 * <p>
1028 * Received by the {@link InCallService} via
1029 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1030 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 *
1032 * @param status Status of the session modify request. Valid values are
1033 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1034 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1036 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1037 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1038 * @param requestedProfile The original request which was sent to the peer device.
1039 * @param responseProfile The actual profile changes agreed to by the peer device.
1040 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001041 */
1042 public void receiveSessionModifyResponse(int status,
1043 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001044 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001045 for (IVideoCallback callback : mVideoCallbacks.values()) {
1046 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001047 callback.receiveSessionModifyResponse(status, requestedProfile,
1048 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001049 } catch (RemoteException ignored) {
1050 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001051 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 }
1053 }
1054 }
1055
1056 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001057 * Used to inform listening {@link InCallService} implementations when the
1058 * {@link VideoProvider} reports a call session event.
1059 * <p>
1060 * Received by the {@link InCallService} via
1061 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001063 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1064 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1065 * {@link VideoProvider#SESSION_EVENT_TX_START},
1066 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1067 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1068 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 */
1070 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001071 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001072 for (IVideoCallback callback : mVideoCallbacks.values()) {
1073 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001074 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001075 } catch (RemoteException ignored) {
1076 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001077 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078 }
1079 }
1080 }
1081
1082 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001083 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1084 * peer's video have changed.
1085 * <p>
1086 * This could occur if, for example, the peer rotates their device, changing the aspect
1087 * ratio of the video, or if the user switches between the back and front cameras.
1088 * <p>
1089 * Received by the {@link InCallService} via
1090 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001091 *
1092 * @param width The updated peer video width.
1093 * @param height The updated peer video height.
1094 */
1095 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001096 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001097 for (IVideoCallback callback : mVideoCallbacks.values()) {
1098 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001099 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001100 } catch (RemoteException ignored) {
1101 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001102 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 }
1104 }
1105 }
1106
1107 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001108 * Used to inform listening {@link InCallService} implementations when the data usage of the
1109 * video associated with the current {@link Connection} has changed.
1110 * <p>
1111 * This could be in response to a preview request via
1112 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001113 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1114 * 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 -07001115 * <p>
1116 * Received by the {@link InCallService} via
1117 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001119 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1120 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 */
Yorke Lee32f24732015-05-12 16:18:03 -07001122 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001123 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001124 for (IVideoCallback callback : mVideoCallbacks.values()) {
1125 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001126 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001127 } catch (RemoteException ignored) {
1128 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001129 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 }
1131 }
1132 }
1133
1134 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001135 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001137 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001138 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1139 * @hide
1140 */
1141 public void changeCallDataUsage(long dataUsage) {
1142 setCallDataUsage(dataUsage);
1143 }
1144
1145 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001146 * Used to inform listening {@link InCallService} implementations when the capabilities of
1147 * the current camera have changed.
1148 * <p>
1149 * The {@link VideoProvider} should call this in response to
1150 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1151 * changed via {@link VideoProvider#onSetCamera(String)}.
1152 * <p>
1153 * Received by the {@link InCallService} via
1154 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1155 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001156 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001157 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001158 */
Yorke Lee400470f2015-05-12 13:31:25 -07001159 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001160 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001161 for (IVideoCallback callback : mVideoCallbacks.values()) {
1162 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001163 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001164 } catch (RemoteException ignored) {
1165 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001166 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167 }
1168 }
1169 }
Rekha Kumar07366812015-03-24 16:42:31 -07001170
1171 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001172 * Used to inform listening {@link InCallService} implementations when the video quality
1173 * of the call has changed.
1174 * <p>
1175 * Received by the {@link InCallService} via
1176 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001177 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001178 * @param videoQuality The updated video quality. Valid values:
1179 * {@link VideoProfile#QUALITY_HIGH},
1180 * {@link VideoProfile#QUALITY_MEDIUM},
1181 * {@link VideoProfile#QUALITY_LOW},
1182 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001183 */
1184 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001185 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001186 for (IVideoCallback callback : mVideoCallbacks.values()) {
1187 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001188 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001189 } catch (RemoteException ignored) {
1190 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001191 }
Rekha Kumar07366812015-03-24 16:42:31 -07001192 }
1193 }
1194 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001195 }
1196
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001197 private final Listener mConnectionDeathListener = new Listener() {
1198 @Override
1199 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001200 if (mConferenceables.remove(c)) {
1201 fireOnConferenceableConnectionsChanged();
1202 }
1203 }
1204 };
1205
1206 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1207 @Override
1208 public void onDestroyed(Conference c) {
1209 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001210 fireOnConferenceableConnectionsChanged();
1211 }
1212 }
1213 };
1214
Jay Shrauner229e3822014-08-15 09:23:07 -07001215 /**
1216 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1217 * load factor before resizing, 1 means we only expect a single thread to
1218 * access the map so make only a single shard
1219 */
1220 private final Set<Listener> mListeners = Collections.newSetFromMap(
1221 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001222 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1223 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001224 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001225
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001226 // The internal telecom call ID associated with this connection.
1227 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001229 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001230 private Uri mAddress;
1231 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001232 private String mCallerDisplayName;
1233 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001234 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001235 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001236 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001237 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001238 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001239 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001240 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001241 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001242 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001243 private Conference mConference;
1244 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001245 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001246 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001247
1248 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001249 * Tracks the key set for the extras bundle provided on the last invocation of
1250 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1251 * keys which were set previously but are no longer present in the replacement Bundle.
1252 */
1253 private Set<String> mPreviousExtraKeys;
1254
1255 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001256 * Create a new Connection.
1257 */
Santos Cordonf2951102014-07-20 19:06:29 -07001258 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001259
1260 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001261 * Returns the Telecom internal call ID associated with this connection. Should only be used
1262 * for debugging and tracing purposes.
1263 *
1264 * @return The Telecom call ID.
1265 * @hide
1266 */
1267 public final String getTelecomCallId() {
1268 return mTelecomCallId;
1269 }
1270
1271 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001272 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001273 */
Andrew Lee100e2932014-09-08 15:34:24 -07001274 public final Uri getAddress() {
1275 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001276 }
1277
1278 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001279 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001281 */
Andrew Lee100e2932014-09-08 15:34:24 -07001282 public final int getAddressPresentation() {
1283 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001284 }
1285
1286 /**
1287 * @return The caller display name (CNAP).
1288 */
1289 public final String getCallerDisplayName() {
1290 return mCallerDisplayName;
1291 }
1292
1293 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001294 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001295 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001296 */
1297 public final int getCallerDisplayNamePresentation() {
1298 return mCallerDisplayNamePresentation;
1299 }
1300
1301 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001302 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001303 */
1304 public final int getState() {
1305 return mState;
1306 }
1307
1308 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001309 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001310 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1311 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1312 * {@link VideoProfile#STATE_TX_ENABLED},
1313 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001314 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001315 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001316 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001317 */
1318 public final int getVideoState() {
1319 return mVideoState;
1320 }
1321
1322 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001323 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324 * being routed by the system. This is {@code null} if this Connection
1325 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001326 * @deprecated Use {@link #getCallAudioState()} instead.
1327 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 */
Yorke Lee4af59352015-05-13 14:14:54 -07001329 @SystemApi
1330 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001332 if (mCallAudioState == null) {
1333 return null;
1334 }
Yorke Lee4af59352015-05-13 14:14:54 -07001335 return new AudioState(mCallAudioState);
1336 }
1337
1338 /**
1339 * @return The audio state of the connection, describing how its audio is currently
1340 * being routed by the system. This is {@code null} if this Connection
1341 * does not directly know about its audio state.
1342 */
1343 public final CallAudioState getCallAudioState() {
1344 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001345 }
1346
1347 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001348 * @return The conference that this connection is a part of. Null if it is not part of any
1349 * conference.
1350 */
1351 public final Conference getConference() {
1352 return mConference;
1353 }
1354
1355 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001356 * Returns whether this connection is requesting that the system play a ringback tone
1357 * on its behalf.
1358 */
Andrew Lee100e2932014-09-08 15:34:24 -07001359 public final boolean isRingbackRequested() {
1360 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001361 }
1362
1363 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001364 * @return True if the connection's audio mode is VOIP.
1365 */
1366 public final boolean getAudioModeIsVoip() {
1367 return mAudioModeIsVoip;
1368 }
1369
1370 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001371 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1372 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1373 * start time of the conference.
1374 *
1375 * @return The time at which the {@code Connnection} was connected.
1376 *
1377 * @hide
1378 */
1379 public final long getConnectTimeMillis() {
1380 return mConnectTimeMillis;
1381 }
1382
1383 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001384 * @return The status hints for this connection.
1385 */
1386 public final StatusHints getStatusHints() {
1387 return mStatusHints;
1388 }
1389
1390 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001391 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001392 * <p>
1393 * Extras should be updated using {@link #putExtras(Bundle)}.
1394 * <p>
1395 * Telecom or an {@link InCallService} can also update the extras via
1396 * {@link android.telecom.Call#putExtras(Bundle)}, and
1397 * {@link Call#removeExtras(List)}.
1398 * <p>
1399 * The connection is notified of changes to the extras made by Telecom or an
1400 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001401 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001402 * @return The extras associated with this connection.
1403 */
1404 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001405 Bundle extras = null;
1406 synchronized (mExtrasLock) {
1407 if (mExtras != null) {
1408 extras = new Bundle(mExtras);
1409 }
1410 }
1411 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001412 }
1413
1414 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001415 * Assign a listener to be notified of state changes.
1416 *
1417 * @param l A listener.
1418 * @return This Connection.
1419 *
1420 * @hide
1421 */
1422 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001423 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001424 return this;
1425 }
1426
1427 /**
1428 * Remove a previously assigned listener that was being notified of state changes.
1429 *
1430 * @param l A Listener.
1431 * @return This Connection.
1432 *
1433 * @hide
1434 */
1435 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001436 if (l != null) {
1437 mListeners.remove(l);
1438 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001439 return this;
1440 }
1441
1442 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001443 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001444 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001445 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001446 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001447 }
1448
1449 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001450 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1451 * ONLY for debugging purposes.
1452 *
1453 * @param callId The telecom call ID.
1454 * @hide
1455 */
1456 public void setTelecomCallId(String callId) {
1457 mTelecomCallId = callId;
1458 }
1459
1460 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001461 * Inform this Connection that the state of its audio output has been changed externally.
1462 *
1463 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001464 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001465 */
Yorke Lee4af59352015-05-13 14:14:54 -07001466 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001467 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001468 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001469 mCallAudioState = state;
1470 onAudioStateChanged(getAudioState());
1471 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001472 }
1473
1474 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001475 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001476 * @return A string representation of the value.
1477 */
1478 public static String stateToString(int state) {
1479 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001481 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001483 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001485 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001486 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001487 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001489 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001491 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493 return "DISCONNECTED";
1494 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001495 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001496 return "UNKNOWN";
1497 }
1498 }
1499
1500 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001502 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001503 public final int getConnectionCapabilities() {
1504 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001505 }
1506
1507 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001508 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1509 */
1510 public final int getConnectionProperties() {
1511 return mConnectionProperties;
1512 }
1513
1514 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001515 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001516 *
Andrew Lee100e2932014-09-08 15:34:24 -07001517 * @param address The new address.
1518 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001519 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001520 */
Andrew Lee100e2932014-09-08 15:34:24 -07001521 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001522 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001523 Log.d(this, "setAddress %s", address);
1524 mAddress = address;
1525 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001526 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001527 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001528 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001529 }
1530
1531 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001532 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001533 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001534 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001535 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001536 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001537 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001538 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001540 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001541 mCallerDisplayName = callerDisplayName;
1542 mCallerDisplayNamePresentation = presentation;
1543 for (Listener l : mListeners) {
1544 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1545 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001546 }
1547
1548 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001549 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001550 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1551 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1552 * {@link VideoProfile#STATE_TX_ENABLED},
1553 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001554 *
1555 * @param videoState The new video state.
1556 */
1557 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001558 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001559 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001560 mVideoState = videoState;
1561 for (Listener l : mListeners) {
1562 l.onVideoStateChanged(this, mVideoState);
1563 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001564 }
1565
1566 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001567 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001568 * communicate).
1569 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001570 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001571 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001572 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001573 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001574 }
1575
1576 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001578 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001579 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001580 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001581 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001582 }
1583
1584 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001585 * Sets state to initializing (this Connection is not yet ready to be used).
1586 */
1587 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001588 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001590 }
1591
1592 /**
1593 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1594 */
1595 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001596 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001598 }
1599
1600 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001601 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001602 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001603 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001604 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001606 }
1607
1608 /**
1609 * Sets state to be on hold.
1610 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001611 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001612 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001613 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001614 }
1615
1616 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001617 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001618 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001619 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001621 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001622 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001623 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001624 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001625 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001626 }
1627
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 public final VideoProvider getVideoProvider() {
1629 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001630 }
1631
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001632 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001633 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001634 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001635 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001636 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001637 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001638 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001639 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001640 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001642 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001643 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001644 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001645 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001646 }
1647
1648 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001649 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1650 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1651 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1652 * to send an {@link #onPostDialContinue(boolean)} signal.
1653 *
1654 * @param remaining The DTMF character sequence remaining to be emitted once the
1655 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1656 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001657 */
1658 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001659 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001660 for (Listener l : mListeners) {
1661 l.onPostDialWait(this, remaining);
1662 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001663 }
1664
1665 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001666 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1667 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001668 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001669 *
1670 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001671 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001672 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001673 checkImmutable();
1674 for (Listener l : mListeners) {
1675 l.onPostDialChar(this, nextChar);
1676 }
1677 }
1678
1679 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001680 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001681 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001682 *
1683 * @param ringback Whether the ringback tone is to be played.
1684 */
Andrew Lee100e2932014-09-08 15:34:24 -07001685 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001686 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001687 if (mRingbackRequested != ringback) {
1688 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001689 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001690 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001691 }
1692 }
Ihab Awadf8358972014-05-28 16:46:42 -07001693 }
1694
1695 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001696 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001697 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001698 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001699 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001700 public final void setConnectionCapabilities(int connectionCapabilities) {
1701 checkImmutable();
1702 if (mConnectionCapabilities != connectionCapabilities) {
1703 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001704 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001705 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001706 }
1707 }
Santos Cordonb6939982014-06-04 20:20:58 -07001708 }
1709
1710 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001711 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1712 *
1713 * @param connectionProperties The new connection properties.
1714 */
1715 public final void setConnectionProperties(int connectionProperties) {
1716 checkImmutable();
1717 if (mConnectionProperties != connectionProperties) {
1718 mConnectionProperties = connectionProperties;
1719 for (Listener l : mListeners) {
1720 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1721 }
1722 }
1723 }
1724
1725 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001726 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001727 */
Evan Charlton36a71342014-07-19 16:31:02 -07001728 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001729 for (Listener l : mListeners) {
1730 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001731 }
Santos Cordonb6939982014-06-04 20:20:58 -07001732 }
1733
1734 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001735 * Requests that the framework use VOIP audio mode for this connection.
1736 *
1737 * @param isVoip True if the audio mode is VOIP.
1738 */
1739 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001740 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001741 mAudioModeIsVoip = isVoip;
1742 for (Listener l : mListeners) {
1743 l.onAudioModeIsVoipChanged(this, isVoip);
1744 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001745 }
1746
1747 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001748 * Sets the time at which a call became active on this Connection. This is set only
1749 * when a conference call becomes active on this connection.
1750 *
1751 * @param connectionTimeMillis The connection time, in milliseconds.
1752 *
1753 * @hide
1754 */
1755 public final void setConnectTimeMillis(long connectTimeMillis) {
1756 mConnectTimeMillis = connectTimeMillis;
1757 }
1758
1759 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001760 * Sets the label and icon status to display in the in-call UI.
1761 *
1762 * @param statusHints The status label and icon to set.
1763 */
1764 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001765 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001766 mStatusHints = statusHints;
1767 for (Listener l : mListeners) {
1768 l.onStatusHintsChanged(this, statusHints);
1769 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001770 }
1771
1772 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001773 * Sets the connections with which this connection can be conferenced.
1774 *
1775 * @param conferenceableConnections The set of connections this connection can conference with.
1776 */
1777 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001778 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001779 clearConferenceableList();
1780 for (Connection c : conferenceableConnections) {
1781 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1782 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001783 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001784 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001785 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001786 }
1787 }
1788 fireOnConferenceableConnectionsChanged();
1789 }
1790
1791 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001792 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1793 * or conferences with which this connection can be conferenced.
1794 *
1795 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001796 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001797 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001798 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001799 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001800 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1801 // small amount of items here.
1802 if (!mConferenceables.contains(c)) {
1803 if (c instanceof Connection) {
1804 Connection connection = (Connection) c;
1805 connection.addConnectionListener(mConnectionDeathListener);
1806 } else if (c instanceof Conference) {
1807 Conference conference = (Conference) c;
1808 conference.addListener(mConferenceDeathListener);
1809 }
1810 mConferenceables.add(c);
1811 }
1812 }
1813 fireOnConferenceableConnectionsChanged();
1814 }
1815
1816 /**
1817 * Returns the connections or conferences with which this connection can be conferenced.
1818 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001819 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001820 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001821 }
1822
Yorke Lee53463962015-08-04 16:07:19 -07001823 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001824 * @hide
1825 */
1826 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001827 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001828 if (mConnectionService != null) {
1829 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1830 "which is already associated with another ConnectionService.");
1831 } else {
1832 mConnectionService = connectionService;
1833 }
1834 }
1835
1836 /**
1837 * @hide
1838 */
1839 public final void unsetConnectionService(ConnectionService connectionService) {
1840 if (mConnectionService != connectionService) {
1841 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1842 "that does not belong to the ConnectionService.");
1843 } else {
1844 mConnectionService = null;
1845 }
1846 }
1847
1848 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001849 * @hide
1850 */
1851 public final ConnectionService getConnectionService() {
1852 return mConnectionService;
1853 }
1854
1855 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001856 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001857 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001858 *
1859 * @param conference The conference.
1860 * @return {@code true} if the conference was successfully set.
1861 * @hide
1862 */
1863 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001864 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001865 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001866 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001867 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001868 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1869 fireConferenceChanged();
1870 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001871 return true;
1872 }
1873 return false;
1874 }
1875
1876 /**
1877 * Resets the conference that this connection is a part of.
1878 * @hide
1879 */
1880 public final void resetConference() {
1881 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001882 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001883 mConference = null;
1884 fireConferenceChanged();
1885 }
1886 }
1887
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001888 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001889 * Set some extras that can be associated with this {@code Connection}.
1890 * <p>
1891 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1892 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1893 * <p>
1894 * 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 -07001895 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1896 *
1897 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001898 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1899 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001900 */
1901 public final void setExtras(@Nullable Bundle extras) {
1902 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001903
1904 // Add/replace any new or changed extras values.
1905 putExtras(extras);
1906
1907 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1908 // the current one and remove any keys that went away.
1909 if (mPreviousExtraKeys != null) {
1910 List<String> toRemove = new ArrayList<String>();
1911 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001912 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001913 toRemove.add(oldKey);
1914 }
1915 }
1916 if (!toRemove.isEmpty()) {
1917 removeExtras(toRemove);
1918 }
1919 }
1920
1921 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1922 // called we can see if the caller has removed any extras values.
1923 if (mPreviousExtraKeys == null) {
1924 mPreviousExtraKeys = new ArraySet<String>();
1925 }
1926 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001927 if (extras != null) {
1928 mPreviousExtraKeys.addAll(extras.keySet());
1929 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001930 }
1931
1932 /**
1933 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1934 * added.
1935 * <p>
1936 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1937 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1938 *
1939 * @param extras The extras to add.
1940 */
1941 public final void putExtras(@NonNull Bundle extras) {
1942 checkImmutable();
1943 if (extras == null) {
1944 return;
1945 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001946 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
1947 // the listeners.
1948 Bundle listenerExtras;
1949 synchronized (mExtrasLock) {
1950 if (mExtras == null) {
1951 mExtras = new Bundle();
1952 }
1953 mExtras.putAll(extras);
1954 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07001955 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001956 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001957 // Create a new clone of the extras for each listener so that they don't clobber
1958 // each other
1959 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07001960 }
1961 }
1962
1963 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001964 * Adds a boolean extra to this {@code Connection}.
1965 *
1966 * @param key The extra key.
1967 * @param value The value.
1968 * @hide
1969 */
1970 public final void putExtra(String key, boolean value) {
1971 Bundle newExtras = new Bundle();
1972 newExtras.putBoolean(key, value);
1973 putExtras(newExtras);
1974 }
1975
1976 /**
1977 * Adds an integer extra to this {@code Connection}.
1978 *
1979 * @param key The extra key.
1980 * @param value The value.
1981 * @hide
1982 */
1983 public final void putExtra(String key, int value) {
1984 Bundle newExtras = new Bundle();
1985 newExtras.putInt(key, value);
1986 putExtras(newExtras);
1987 }
1988
1989 /**
1990 * Adds a string extra to this {@code Connection}.
1991 *
1992 * @param key The extra key.
1993 * @param value The value.
1994 * @hide
1995 */
1996 public final void putExtra(String key, String value) {
1997 Bundle newExtras = new Bundle();
1998 newExtras.putString(key, value);
1999 putExtras(newExtras);
2000 }
2001
2002 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002003 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002004 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002005 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002006 */
2007 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002008 synchronized (mExtrasLock) {
2009 if (mExtras != null) {
2010 for (String key : keys) {
2011 mExtras.remove(key);
2012 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002013 }
2014 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002015 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002016 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002017 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002018 }
2019 }
2020
2021 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002022 * Removes extras from this {@code Connection}.
2023 *
2024 * @param keys The keys of the extras to remove.
2025 */
2026 public final void removeExtras(String ... keys) {
2027 removeExtras(Arrays.asList(keys));
2028 }
2029
2030 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002031 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002032 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002033 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002034 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2035 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002036 */
Yorke Lee4af59352015-05-13 14:14:54 -07002037 @SystemApi
2038 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002039 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002040
2041 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002042 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2043 *
2044 * @param state The new connection audio state.
2045 */
2046 public void onCallAudioStateChanged(CallAudioState state) {}
2047
2048 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002049 * Notifies this Connection of an internal state change. This method is called after the
2050 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002051 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002052 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002053 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002054 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002055
2056 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002057 * Notifies this Connection of a request to play a DTMF tone.
2058 *
2059 * @param c A DTMF character.
2060 */
Santos Cordonf2951102014-07-20 19:06:29 -07002061 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002062
2063 /**
2064 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2065 */
Santos Cordonf2951102014-07-20 19:06:29 -07002066 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002067
2068 /**
2069 * Notifies this Connection of a request to disconnect.
2070 */
Santos Cordonf2951102014-07-20 19:06:29 -07002071 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072
2073 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002074 * Notifies this Connection of a request to disconnect a participant of the conference managed
2075 * by the connection.
2076 *
2077 * @param endpoint the {@link Uri} of the participant to disconnect.
2078 * @hide
2079 */
2080 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2081
2082 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002083 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002084 */
Santos Cordonf2951102014-07-20 19:06:29 -07002085 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002086
2087 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002088 * Notifies this Connection of a request to abort.
2089 */
Santos Cordonf2951102014-07-20 19:06:29 -07002090 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002091
2092 /**
2093 * Notifies this Connection of a request to hold.
2094 */
Santos Cordonf2951102014-07-20 19:06:29 -07002095 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002096
2097 /**
2098 * Notifies this Connection of a request to exit a hold state.
2099 */
Santos Cordonf2951102014-07-20 19:06:29 -07002100 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002101
2102 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002103 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002104 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002105 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002106 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 */
Santos Cordonf2951102014-07-20 19:06:29 -07002108 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002109
2110 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002111 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002112 * a request to accept.
2113 */
2114 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002115 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002116 }
2117
2118 /**
2119 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002120 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002121 */
Santos Cordonf2951102014-07-20 19:06:29 -07002122 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002123
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002124 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002125 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2126 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002127 */
2128 public void onReject(String replyMessage) {}
2129
2130 /**
Bryce Leecac50772015-11-17 15:13:29 -08002131 * Notifies the Connection of a request to silence the ringer.
2132 *
2133 * @hide
2134 */
2135 public void onSilence() {}
2136
2137 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002138 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2139 */
Santos Cordonf2951102014-07-20 19:06:29 -07002140 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002141
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002142 /**
2143 * Notifies this Connection of a request to pull an external call to the local device.
2144 * <p>
2145 * The {@link InCallService} issues a request to pull an external call to the local device via
2146 * {@link Call#pullExternalCall()}.
2147 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002148 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2149 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002150 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002151 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002152 */
2153 public void onPullExternalCall() {}
2154
2155 /**
2156 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2157 * <p>
2158 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2159 * <p>
2160 * See also {@link Call#sendCallEvent(String, Bundle)}.
2161 *
2162 * @param event The call event.
2163 * @param extras Extras associated with the call event.
2164 */
2165 public void onCallEvent(String event, Bundle extras) {}
2166
Tyler Gunndee56a82016-03-23 16:06:34 -07002167 /**
2168 * Notifies this {@link Connection} of a change to the extras made outside the
2169 * {@link ConnectionService}.
2170 * <p>
2171 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2172 * the {@link android.telecom.Call#putExtras(Bundle)} and
2173 * {@link Call#removeExtras(List)}.
2174 *
2175 * @param extras The new extras bundle.
2176 */
2177 public void onExtrasChanged(Bundle extras) {}
2178
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002179 static String toLogSafePhoneNumber(String number) {
2180 // For unknown number, log empty string.
2181 if (number == null) {
2182 return "";
2183 }
2184
2185 if (PII_DEBUG) {
2186 // When PII_DEBUG is true we emit PII.
2187 return number;
2188 }
2189
2190 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2191 // sanitized phone numbers.
2192 StringBuilder builder = new StringBuilder();
2193 for (int i = 0; i < number.length(); i++) {
2194 char c = number.charAt(i);
2195 if (c == '-' || c == '@' || c == '.') {
2196 builder.append(c);
2197 } else {
2198 builder.append('x');
2199 }
2200 }
2201 return builder.toString();
2202 }
2203
Ihab Awad542e0ea2014-05-16 10:22:16 -07002204 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002205 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002206 if (mState == STATE_DISCONNECTED && mState != state) {
2207 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002208 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002209 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002210 if (mState != state) {
2211 Log.d(this, "setState: %s", stateToString(state));
2212 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002213 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002214 for (Listener l : mListeners) {
2215 l.onStateChanged(this, state);
2216 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002217 }
2218 }
2219
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002220 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002221 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002222 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2223 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002224 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002225 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002226
2227 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002228 if (mImmutable) {
2229 throw new UnsupportedOperationException("Connection is immutable");
2230 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002231 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002232 }
2233
Evan Charltonbf11f982014-07-20 22:06:28 -07002234 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002235 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002236 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2237 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002238 * <p>
2239 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2240 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002241 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002242 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002243 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002244 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002245 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2246 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002247 }
2248
Evan Charltonbf11f982014-07-20 22:06:28 -07002249 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002250 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2251 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2252 * this should never be un-@hide-den.
2253 *
2254 * @hide
2255 */
2256 public void checkImmutable() {}
2257
2258 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002259 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2260 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2261 * that state. This connection should not be used for anything, and no other
2262 * {@code Connection}s should be attempted.
2263 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002264 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002265 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002266 * @return A {@code Connection} which indicates that the underlying connection should
2267 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002268 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002269 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002270 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002271 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002272
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002273 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002274 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002275 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002276 }
2277 }
2278
Santos Cordon823fd3c2014-08-07 18:35:18 -07002279 private final void fireConferenceChanged() {
2280 for (Listener l : mListeners) {
2281 l.onConferenceChanged(this, mConference);
2282 }
2283 }
2284
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002285 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002286 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002287 if (c instanceof Connection) {
2288 Connection connection = (Connection) c;
2289 connection.removeConnectionListener(mConnectionDeathListener);
2290 } else if (c instanceof Conference) {
2291 Conference conference = (Conference) c;
2292 conference.removeListener(mConferenceDeathListener);
2293 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002294 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002295 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002296 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002297
2298 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002299 * Handles a change to extras received from Telecom.
2300 *
2301 * @param extras The new extras.
2302 * @hide
2303 */
2304 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002305 Bundle b = null;
2306 synchronized (mExtrasLock) {
2307 mExtras = extras;
2308 if (mExtras != null) {
2309 b = new Bundle(mExtras);
2310 }
2311 }
2312 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002313 }
2314
2315 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002316 * Notifies listeners that the merge request failed.
2317 *
2318 * @hide
2319 */
2320 protected final void notifyConferenceMergeFailed() {
2321 for (Listener l : mListeners) {
2322 l.onConferenceMergeFailed(this);
2323 }
2324 }
2325
2326 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002327 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002328 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002329 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002330 * @hide
2331 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002332 protected final void updateConferenceParticipants(
2333 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002334 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002335 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002336 }
2337 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002338
2339 /**
2340 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002341 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002342 */
2343 protected void notifyConferenceStarted() {
2344 for (Listener l : mListeners) {
2345 l.onConferenceStarted();
2346 }
2347 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002348
2349 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002350 * Sends an event associated with this {@code Connection}, with associated event extras.
2351 *
2352 * Events are exposed to {@link InCallService} implementations via the
2353 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2354 *
2355 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2356 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002357 *
2358 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002359 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002360 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002361 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002362 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002363 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002364 }
2365 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002366}