blob: 3316bc8a9176b1cb18e64552d38eaf8a8ddde010 [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
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 // Flag controlling whether PII is emitted into the logs
400 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
401
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800402 /**
403 * Whether the given capabilities support the specified capability.
404 *
405 * @param capabilities A capability bit field.
406 * @param capability The capability to check capabilities for.
407 * @return Whether the specified capability is supported.
408 * @hide
409 */
410 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800411 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 }
413
414 /**
415 * Whether the capabilities of this {@code Connection} supports the specified capability.
416 *
417 * @param capability The capability to check capabilities for.
418 * @return Whether the specified capability is supported.
419 * @hide
420 */
421 public boolean can(int capability) {
422 return can(mConnectionCapabilities, capability);
423 }
424
425 /**
426 * Removes the specified capability from the set of capabilities of this {@code Connection}.
427 *
428 * @param capability The capability to remove from the set.
429 * @hide
430 */
431 public void removeCapability(int capability) {
432 mConnectionCapabilities &= ~capability;
433 }
434
435 /**
436 * Adds the specified capability to the set of capabilities of this {@code Connection}.
437 *
438 * @param capability The capability to add to the set.
439 * @hide
440 */
441 public void addCapability(int capability) {
442 mConnectionCapabilities |= capability;
443 }
444
445
446 public static String capabilitiesToString(int capabilities) {
447 StringBuilder builder = new StringBuilder();
448 builder.append("[Capabilities:");
449 if (can(capabilities, CAPABILITY_HOLD)) {
450 builder.append(" CAPABILITY_HOLD");
451 }
452 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
453 builder.append(" CAPABILITY_SUPPORT_HOLD");
454 }
455 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
456 builder.append(" CAPABILITY_MERGE_CONFERENCE");
457 }
458 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
459 builder.append(" CAPABILITY_SWAP_CONFERENCE");
460 }
461 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
462 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
463 }
464 if (can(capabilities, CAPABILITY_MUTE)) {
465 builder.append(" CAPABILITY_MUTE");
466 }
467 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
468 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
469 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700470 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
471 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
472 }
473 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
474 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
475 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700476 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
477 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800478 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700479 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
480 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
481 }
482 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
483 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
484 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700485 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
486 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800487 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800488 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
489 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
490 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500491 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700492 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500493 }
Rekha Kumar07366812015-03-24 16:42:31 -0700494 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
495 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
496 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700497 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
498 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
499 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700500 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
501 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
502 }
Bryce Lee81901682015-08-28 16:38:02 -0700503 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
504 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
505 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700506 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
507 builder.append(" CAPABILITY_CAN_PULL_CALL");
508 }
Bryce Lee81901682015-08-28 16:38:02 -0700509
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800510 builder.append("]");
511 return builder.toString();
512 }
513
Tyler Gunn720c6642016-03-22 09:02:47 -0700514 public static String propertiesToString(int properties) {
515 StringBuilder builder = new StringBuilder();
516 builder.append("[Properties:");
517
518 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
519 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
520 }
521
522 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
523 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
524 }
525
526 if (can(properties, PROPERTY_WIFI)) {
527 builder.append(" PROPERTY_WIFI");
528 }
529
530 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
531 builder.append(" PROPERTY_GENERIC_CONFERENCE");
532 }
533
534 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
535 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
536 }
537
Brad Ebinger15847072016-05-18 11:08:36 -0700538 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
539 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
540 }
541
Tyler Gunn720c6642016-03-22 09:02:47 -0700542 builder.append("]");
543 return builder.toString();
544 }
545
Sailesh Nepal091768c2014-06-30 15:15:23 -0700546 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700547 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700548 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700549 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700550 public void onCallerDisplayNameChanged(
551 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700552 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700553 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700554 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800555 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700556 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700557 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800558 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700559 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700560 public void onVideoProviderChanged(
561 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700562 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
563 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800564 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700565 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700566 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700567 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800568 public void onConferenceParticipantsChanged(Connection c,
569 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800570 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700571 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700572 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700573 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700574 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700575 }
576
Tyler Gunnb702ef82015-05-29 11:51:53 -0700577 /**
578 * Provides a means of controlling the video session associated with a {@link Connection}.
579 * <p>
580 * Implementations create a custom subclass of {@link VideoProvider} and the
581 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
582 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
583 * should set the {@link VideoProvider}.
584 * <p>
585 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
586 * {@link InCallService} implementations to issue requests related to the video session;
587 * it provides a means for the {@link ConnectionService} to report events and information
588 * related to the video session to Telecom and the {@link InCallService} implementations.
589 * <p>
590 * {@link InCallService} implementations interact with the {@link VideoProvider} via
591 * {@link android.telecom.InCallService.VideoCall}.
592 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700594
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595 /**
596 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700597 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700598 */
599 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700600
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700601 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700602 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
603 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700604 */
605 public static final int SESSION_EVENT_RX_RESUME = 2;
606
607 /**
608 * Video transmission has begun. This occurs after a negotiated start of video transmission
609 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700610 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 */
612 public static final int SESSION_EVENT_TX_START = 3;
613
614 /**
615 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
616 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700617 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 */
619 public static final int SESSION_EVENT_TX_STOP = 4;
620
621 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700622 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
623 * this as a cue to inform the user the camera is not available.
624 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 */
626 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
627
628 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700629 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
630 * for operation. The {@link InCallService} can use this as a cue to inform the user that
631 * the camera has become available again.
632 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 */
634 public static final int SESSION_EVENT_CAMERA_READY = 6;
635
636 /**
637 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700638 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 */
640 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
641
642 /**
643 * Session modify request failed.
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_FAIL = 2;
647
648 /**
649 * Session modify request ignored due to invalid parameters.
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_INVALID = 3;
653
Rekha Kumar07366812015-03-24 16:42:31 -0700654 /**
655 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700656 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700657 */
658 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
659
660 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700661 * Session modify request rejected by remote user.
662 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700663 */
664 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
665
Tyler Gunn75958422015-04-15 14:23:42 -0700666 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 private static final int MSG_SET_CAMERA = 2;
668 private static final int MSG_SET_PREVIEW_SURFACE = 3;
669 private static final int MSG_SET_DISPLAY_SURFACE = 4;
670 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
671 private static final int MSG_SET_ZOOM = 6;
672 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
673 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
674 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800675 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700677 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700678
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700679 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700681
682 /**
683 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700684 *
685 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
686 * load factor before resizing, 1 means we only expect a single thread to
687 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700688 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700689 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
690 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700691
692 /**
693 * Default handler used to consolidate binder method calls onto a single thread.
694 */
695 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700696 public VideoProviderHandler() {
697 super();
698 }
699
700 public VideoProviderHandler(Looper looper) {
701 super(looper);
702 }
703
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 @Override
705 public void handleMessage(Message msg) {
706 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700707 case MSG_ADD_VIDEO_CALLBACK: {
708 IBinder binder = (IBinder) msg.obj;
709 IVideoCallback callback = IVideoCallback.Stub
710 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700711 if (callback == null) {
712 Log.w(this, "addVideoProvider - skipped; callback is null.");
713 break;
714 }
715
Tyler Gunn75958422015-04-15 14:23:42 -0700716 if (mVideoCallbacks.containsKey(binder)) {
717 Log.i(this, "addVideoProvider - skipped; already present.");
718 break;
719 }
720 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700721 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700722 }
723 case MSG_REMOVE_VIDEO_CALLBACK: {
724 IBinder binder = (IBinder) msg.obj;
725 IVideoCallback callback = IVideoCallback.Stub
726 .asInterface((IBinder) msg.obj);
727 if (!mVideoCallbacks.containsKey(binder)) {
728 Log.i(this, "removeVideoProvider - skipped; not present.");
729 break;
730 }
731 mVideoCallbacks.remove(binder);
732 break;
733 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 case MSG_SET_CAMERA:
735 onSetCamera((String) msg.obj);
736 break;
737 case MSG_SET_PREVIEW_SURFACE:
738 onSetPreviewSurface((Surface) msg.obj);
739 break;
740 case MSG_SET_DISPLAY_SURFACE:
741 onSetDisplaySurface((Surface) msg.obj);
742 break;
743 case MSG_SET_DEVICE_ORIENTATION:
744 onSetDeviceOrientation(msg.arg1);
745 break;
746 case MSG_SET_ZOOM:
747 onSetZoom((Float) msg.obj);
748 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700749 case MSG_SEND_SESSION_MODIFY_REQUEST: {
750 SomeArgs args = (SomeArgs) msg.obj;
751 try {
752 onSendSessionModifyRequest((VideoProfile) args.arg1,
753 (VideoProfile) args.arg2);
754 } finally {
755 args.recycle();
756 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700757 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700758 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 case MSG_SEND_SESSION_MODIFY_RESPONSE:
760 onSendSessionModifyResponse((VideoProfile) msg.obj);
761 break;
762 case MSG_REQUEST_CAMERA_CAPABILITIES:
763 onRequestCameraCapabilities();
764 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800765 case MSG_REQUEST_CONNECTION_DATA_USAGE:
766 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700767 break;
768 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700769 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 break;
771 default:
772 break;
773 }
774 }
775 }
776
777 /**
778 * IVideoProvider stub implementation.
779 */
780 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700781 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700783 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
784 }
785
786 public void removeVideoCallback(IBinder videoCallbackBinder) {
787 mMessageHandler.obtainMessage(
788 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700789 }
790
791 public void setCamera(String cameraId) {
792 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
793 }
794
795 public void setPreviewSurface(Surface surface) {
796 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
797 }
798
799 public void setDisplaySurface(Surface surface) {
800 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
801 }
802
803 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700804 mMessageHandler.obtainMessage(
805 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 }
807
808 public void setZoom(float value) {
809 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
810 }
811
Tyler Gunn45382162015-05-06 08:52:27 -0700812 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
813 SomeArgs args = SomeArgs.obtain();
814 args.arg1 = fromProfile;
815 args.arg2 = toProfile;
816 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700817 }
818
819 public void sendSessionModifyResponse(VideoProfile responseProfile) {
820 mMessageHandler.obtainMessage(
821 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
822 }
823
824 public void requestCameraCapabilities() {
825 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
826 }
827
828 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800829 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 }
831
Yorke Lee32f24732015-05-12 16:18:03 -0700832 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
834 }
835 }
836
837 public VideoProvider() {
838 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700839 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700840 }
841
842 /**
843 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
844 *
845 * @param looper The looper.
846 * @hide
847 */
848 public VideoProvider(Looper looper) {
849 mBinder = new VideoProvider.VideoProviderBinder();
850 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 }
852
853 /**
854 * Returns binder object which can be used across IPC methods.
855 * @hide
856 */
857 public final IVideoProvider getInterface() {
858 return mBinder;
859 }
860
861 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * Sets the camera to be used for the outgoing video.
863 * <p>
864 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
865 * camera via
866 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
867 * <p>
868 * Sent from the {@link InCallService} via
869 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700871 * @param cameraId The id of the camera (use ids as reported by
872 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700873 */
874 public abstract void onSetCamera(String cameraId);
875
876 /**
877 * Sets the surface to be used for displaying a preview of what the user's camera is
878 * currently capturing. When video transmission is enabled, this is the video signal which
879 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700880 * <p>
881 * Sent from the {@link InCallService} via
882 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700884 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 */
886 public abstract void onSetPreviewSurface(Surface surface);
887
888 /**
889 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700890 * <p>
891 * Sent from the {@link InCallService} via
892 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700893 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700894 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 */
896 public abstract void onSetDisplaySurface(Surface surface);
897
898 /**
899 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
900 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700901 * <p>
902 * Sent from the {@link InCallService} via
903 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 *
905 * @param rotation The device orientation, in degrees.
906 */
907 public abstract void onSetDeviceOrientation(int rotation);
908
909 /**
910 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700911 * <p>
912 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700913 *
914 * @param value The camera zoom ratio.
915 */
916 public abstract void onSetZoom(float value);
917
918 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * Issues a request to modify the properties of the current video session.
920 * <p>
921 * Example scenarios include: requesting an audio-only call to be upgraded to a
922 * bi-directional video call, turning on or off the user's camera, sending a pause signal
923 * when the {@link InCallService} is no longer the foreground application.
924 * <p>
925 * If the {@link VideoProvider} determines a request to be invalid, it should call
926 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
927 * invalid request back to the {@link InCallService}.
928 * <p>
929 * Where a request requires confirmation from the user of the peer device, the
930 * {@link VideoProvider} must communicate the request to the peer device and handle the
931 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
932 * is used to inform the {@link InCallService} of the result of the request.
933 * <p>
934 * Sent from the {@link InCallService} via
935 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700937 * @param fromProfile The video profile prior to the request.
938 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700939 */
Tyler Gunn45382162015-05-06 08:52:27 -0700940 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
941 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 /**
944 * Provides a response to a request to change the current video session properties.
945 * <p>
946 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
947 * video call, could decline the request and keep the call as audio-only.
948 * In such a scenario, the {@code responseProfile} would have a video state of
949 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
950 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
951 * <p>
952 * Sent from the {@link InCallService} via
953 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
954 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
955 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700956 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700957 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 */
959 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
960
961 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700962 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
963 * <p>
964 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
965 * camera via
966 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
967 * <p>
968 * Sent from the {@link InCallService} via
969 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 */
971 public abstract void onRequestCameraCapabilities();
972
973 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700974 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
975 * video component of the current {@link Connection}.
976 * <p>
977 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
978 * via {@link VideoProvider#setCallDataUsage(long)}.
979 * <p>
980 * Sent from the {@link InCallService} via
981 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800983 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984
985 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
987 * the peer device when the video signal is paused.
988 * <p>
989 * Sent from the {@link InCallService} via
990 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 *
992 * @param uri URI of image to display.
993 */
Yorke Lee32f24732015-05-12 16:18:03 -0700994 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Used to inform listening {@link InCallService} implementations when the
998 * {@link VideoProvider} receives a session modification request.
999 * <p>
1000 * Received by the {@link InCallService} via
1001 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001003 * @param videoProfile The requested video profile.
1004 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 */
1006 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001007 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001008 for (IVideoCallback callback : mVideoCallbacks.values()) {
1009 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001010 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001011 } catch (RemoteException ignored) {
1012 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001013 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 }
1015 }
1016 }
1017
1018 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001019 * Used to inform listening {@link InCallService} implementations when the
1020 * {@link VideoProvider} receives a response to a session modification request.
1021 * <p>
1022 * Received by the {@link InCallService} via
1023 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1024 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001025 *
1026 * @param status Status of the session modify request. Valid values are
1027 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1028 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001029 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1030 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1031 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1032 * @param requestedProfile The original request which was sent to the peer device.
1033 * @param responseProfile The actual profile changes agreed to by the peer device.
1034 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001035 */
1036 public void receiveSessionModifyResponse(int status,
1037 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001038 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001039 for (IVideoCallback callback : mVideoCallbacks.values()) {
1040 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001041 callback.receiveSessionModifyResponse(status, requestedProfile,
1042 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001043 } catch (RemoteException ignored) {
1044 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001045 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001046 }
1047 }
1048 }
1049
1050 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001051 * Used to inform listening {@link InCallService} implementations when the
1052 * {@link VideoProvider} reports a call session event.
1053 * <p>
1054 * Received by the {@link InCallService} via
1055 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001057 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1058 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1059 * {@link VideoProvider#SESSION_EVENT_TX_START},
1060 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1061 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1062 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 */
1064 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001065 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001066 for (IVideoCallback callback : mVideoCallbacks.values()) {
1067 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001068 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001069 } catch (RemoteException ignored) {
1070 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001071 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 }
1073 }
1074 }
1075
1076 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001077 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1078 * peer's video have changed.
1079 * <p>
1080 * This could occur if, for example, the peer rotates their device, changing the aspect
1081 * ratio of the video, or if the user switches between the back and front cameras.
1082 * <p>
1083 * Received by the {@link InCallService} via
1084 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001085 *
1086 * @param width The updated peer video width.
1087 * @param height The updated peer video height.
1088 */
1089 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001090 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001091 for (IVideoCallback callback : mVideoCallbacks.values()) {
1092 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001093 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001094 } catch (RemoteException ignored) {
1095 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001096 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 }
1098 }
1099 }
1100
1101 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001102 * Used to inform listening {@link InCallService} implementations when the data usage of the
1103 * video associated with the current {@link Connection} has changed.
1104 * <p>
1105 * This could be in response to a preview request via
1106 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001107 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1108 * 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 -07001109 * <p>
1110 * Received by the {@link InCallService} via
1111 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001112 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001113 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1114 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001115 */
Yorke Lee32f24732015-05-12 16:18:03 -07001116 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001117 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001118 for (IVideoCallback callback : mVideoCallbacks.values()) {
1119 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001120 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001121 } catch (RemoteException ignored) {
1122 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001123 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 }
1125 }
1126 }
1127
1128 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001131 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001132 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1133 * @hide
1134 */
1135 public void changeCallDataUsage(long dataUsage) {
1136 setCallDataUsage(dataUsage);
1137 }
1138
1139 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001140 * Used to inform listening {@link InCallService} implementations when the capabilities of
1141 * the current camera have changed.
1142 * <p>
1143 * The {@link VideoProvider} should call this in response to
1144 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1145 * changed via {@link VideoProvider#onSetCamera(String)}.
1146 * <p>
1147 * Received by the {@link InCallService} via
1148 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1149 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001150 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001151 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001152 */
Yorke Lee400470f2015-05-12 13:31:25 -07001153 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001154 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001155 for (IVideoCallback callback : mVideoCallbacks.values()) {
1156 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001157 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001158 } catch (RemoteException ignored) {
1159 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001160 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 }
1162 }
1163 }
Rekha Kumar07366812015-03-24 16:42:31 -07001164
1165 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001166 * Used to inform listening {@link InCallService} implementations when the video quality
1167 * of the call has changed.
1168 * <p>
1169 * Received by the {@link InCallService} via
1170 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001171 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001172 * @param videoQuality The updated video quality. Valid values:
1173 * {@link VideoProfile#QUALITY_HIGH},
1174 * {@link VideoProfile#QUALITY_MEDIUM},
1175 * {@link VideoProfile#QUALITY_LOW},
1176 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001177 */
1178 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001179 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001180 for (IVideoCallback callback : mVideoCallbacks.values()) {
1181 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001182 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001183 } catch (RemoteException ignored) {
1184 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001185 }
Rekha Kumar07366812015-03-24 16:42:31 -07001186 }
1187 }
1188 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001189 }
1190
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001191 private final Listener mConnectionDeathListener = new Listener() {
1192 @Override
1193 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001194 if (mConferenceables.remove(c)) {
1195 fireOnConferenceableConnectionsChanged();
1196 }
1197 }
1198 };
1199
1200 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1201 @Override
1202 public void onDestroyed(Conference c) {
1203 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001204 fireOnConferenceableConnectionsChanged();
1205 }
1206 }
1207 };
1208
Jay Shrauner229e3822014-08-15 09:23:07 -07001209 /**
1210 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1211 * load factor before resizing, 1 means we only expect a single thread to
1212 * access the map so make only a single shard
1213 */
1214 private final Set<Listener> mListeners = Collections.newSetFromMap(
1215 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001216 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1217 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001218 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001219
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001220 // The internal telecom call ID associated with this connection.
1221 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001222 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001223 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001224 private Uri mAddress;
1225 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001226 private String mCallerDisplayName;
1227 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001228 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001229 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001230 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001231 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001232 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001233 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001234 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001235 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001236 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001237 private Conference mConference;
1238 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001239 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001240
1241 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001242 * Tracks the key set for the extras bundle provided on the last invocation of
1243 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1244 * keys which were set previously but are no longer present in the replacement Bundle.
1245 */
1246 private Set<String> mPreviousExtraKeys;
1247
1248 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001249 * Create a new Connection.
1250 */
Santos Cordonf2951102014-07-20 19:06:29 -07001251 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001252
1253 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001254 * Returns the Telecom internal call ID associated with this connection. Should only be used
1255 * for debugging and tracing purposes.
1256 *
1257 * @return The Telecom call ID.
1258 * @hide
1259 */
1260 public final String getTelecomCallId() {
1261 return mTelecomCallId;
1262 }
1263
1264 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001265 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001266 */
Andrew Lee100e2932014-09-08 15:34:24 -07001267 public final Uri getAddress() {
1268 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269 }
1270
1271 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001272 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001273 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001274 */
Andrew Lee100e2932014-09-08 15:34:24 -07001275 public final int getAddressPresentation() {
1276 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001277 }
1278
1279 /**
1280 * @return The caller display name (CNAP).
1281 */
1282 public final String getCallerDisplayName() {
1283 return mCallerDisplayName;
1284 }
1285
1286 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001287 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001288 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001289 */
1290 public final int getCallerDisplayNamePresentation() {
1291 return mCallerDisplayNamePresentation;
1292 }
1293
1294 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001295 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 */
1297 public final int getState() {
1298 return mState;
1299 }
1300
1301 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001302 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001303 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1304 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1305 * {@link VideoProfile#STATE_TX_ENABLED},
1306 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001307 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001308 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001309 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001310 */
1311 public final int getVideoState() {
1312 return mVideoState;
1313 }
1314
1315 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001316 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 * being routed by the system. This is {@code null} if this Connection
1318 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001319 * @deprecated Use {@link #getCallAudioState()} instead.
1320 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001321 */
Yorke Lee4af59352015-05-13 14:14:54 -07001322 @SystemApi
1323 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001325 if (mCallAudioState == null) {
1326 return null;
1327 }
Yorke Lee4af59352015-05-13 14:14:54 -07001328 return new AudioState(mCallAudioState);
1329 }
1330
1331 /**
1332 * @return The audio state of the connection, describing how its audio is currently
1333 * being routed by the system. This is {@code null} if this Connection
1334 * does not directly know about its audio state.
1335 */
1336 public final CallAudioState getCallAudioState() {
1337 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001338 }
1339
1340 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001341 * @return The conference that this connection is a part of. Null if it is not part of any
1342 * conference.
1343 */
1344 public final Conference getConference() {
1345 return mConference;
1346 }
1347
1348 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001349 * Returns whether this connection is requesting that the system play a ringback tone
1350 * on its behalf.
1351 */
Andrew Lee100e2932014-09-08 15:34:24 -07001352 public final boolean isRingbackRequested() {
1353 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001354 }
1355
1356 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001357 * @return True if the connection's audio mode is VOIP.
1358 */
1359 public final boolean getAudioModeIsVoip() {
1360 return mAudioModeIsVoip;
1361 }
1362
1363 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001364 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1365 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1366 * start time of the conference.
1367 *
1368 * @return The time at which the {@code Connnection} was connected.
1369 *
1370 * @hide
1371 */
1372 public final long getConnectTimeMillis() {
1373 return mConnectTimeMillis;
1374 }
1375
1376 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001377 * @return The status hints for this connection.
1378 */
1379 public final StatusHints getStatusHints() {
1380 return mStatusHints;
1381 }
1382
1383 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001384 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001385 * <p>
1386 * Extras should be updated using {@link #putExtras(Bundle)}.
1387 * <p>
1388 * Telecom or an {@link InCallService} can also update the extras via
1389 * {@link android.telecom.Call#putExtras(Bundle)}, and
1390 * {@link Call#removeExtras(List)}.
1391 * <p>
1392 * The connection is notified of changes to the extras made by Telecom or an
1393 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001394 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001395 * @return The extras associated with this connection.
1396 */
1397 public final Bundle getExtras() {
1398 return mExtras;
1399 }
1400
1401 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001402 * Assign a listener to be notified of state changes.
1403 *
1404 * @param l A listener.
1405 * @return This Connection.
1406 *
1407 * @hide
1408 */
1409 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001410 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001411 return this;
1412 }
1413
1414 /**
1415 * Remove a previously assigned listener that was being notified of state changes.
1416 *
1417 * @param l A Listener.
1418 * @return This Connection.
1419 *
1420 * @hide
1421 */
1422 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001423 if (l != null) {
1424 mListeners.remove(l);
1425 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426 return this;
1427 }
1428
1429 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001430 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001431 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001432 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001433 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001434 }
1435
1436 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001437 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1438 * ONLY for debugging purposes.
1439 *
1440 * @param callId The telecom call ID.
1441 * @hide
1442 */
1443 public void setTelecomCallId(String callId) {
1444 mTelecomCallId = callId;
1445 }
1446
1447 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001448 * Inform this Connection that the state of its audio output has been changed externally.
1449 *
1450 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001451 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001452 */
Yorke Lee4af59352015-05-13 14:14:54 -07001453 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001454 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001455 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001456 mCallAudioState = state;
1457 onAudioStateChanged(getAudioState());
1458 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001459 }
1460
1461 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001463 * @return A string representation of the value.
1464 */
1465 public static String stateToString(int state) {
1466 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001468 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001469 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001470 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001472 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001474 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001475 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001476 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001478 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001480 return "DISCONNECTED";
1481 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001482 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001483 return "UNKNOWN";
1484 }
1485 }
1486
1487 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001488 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001489 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001490 public final int getConnectionCapabilities() {
1491 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001492 }
1493
1494 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001495 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1496 */
1497 public final int getConnectionProperties() {
1498 return mConnectionProperties;
1499 }
1500
1501 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001502 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001503 *
Andrew Lee100e2932014-09-08 15:34:24 -07001504 * @param address The new address.
1505 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001506 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001507 */
Andrew Lee100e2932014-09-08 15:34:24 -07001508 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001509 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001510 Log.d(this, "setAddress %s", address);
1511 mAddress = address;
1512 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001513 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001514 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001515 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001516 }
1517
1518 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001519 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001520 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001521 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001522 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001523 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001524 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001525 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001526 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001527 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001528 mCallerDisplayName = callerDisplayName;
1529 mCallerDisplayNamePresentation = presentation;
1530 for (Listener l : mListeners) {
1531 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1532 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001533 }
1534
1535 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001536 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001537 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1538 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1539 * {@link VideoProfile#STATE_TX_ENABLED},
1540 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001541 *
1542 * @param videoState The new video state.
1543 */
1544 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001545 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001546 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001547 mVideoState = videoState;
1548 for (Listener l : mListeners) {
1549 l.onVideoStateChanged(this, mVideoState);
1550 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001551 }
1552
1553 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001554 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001555 * communicate).
1556 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001557 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001558 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001559 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001561 }
1562
1563 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001564 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001565 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001566 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001567 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001569 }
1570
1571 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001572 * Sets state to initializing (this Connection is not yet ready to be used).
1573 */
1574 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001575 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001576 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001577 }
1578
1579 /**
1580 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1581 */
1582 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001583 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001584 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001585 }
1586
1587 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001588 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001589 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001590 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001591 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001592 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001593 }
1594
1595 /**
1596 * Sets state to be on hold.
1597 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001598 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001599 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001601 }
1602
1603 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001604 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001606 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001608 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001610 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001611 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001612 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001613 }
1614
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 public final VideoProvider getVideoProvider() {
1616 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001617 }
1618
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001619 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001620 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001621 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001622 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001625 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001626 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001627 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001629 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001630 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001631 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001632 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001633 }
1634
1635 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001636 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1637 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1638 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1639 * to send an {@link #onPostDialContinue(boolean)} signal.
1640 *
1641 * @param remaining The DTMF character sequence remaining to be emitted once the
1642 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1643 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001644 */
1645 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001646 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001647 for (Listener l : mListeners) {
1648 l.onPostDialWait(this, remaining);
1649 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001650 }
1651
1652 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001653 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1654 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001655 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001656 *
1657 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001658 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001659 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001660 checkImmutable();
1661 for (Listener l : mListeners) {
1662 l.onPostDialChar(this, nextChar);
1663 }
1664 }
1665
1666 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001667 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001668 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001669 *
1670 * @param ringback Whether the ringback tone is to be played.
1671 */
Andrew Lee100e2932014-09-08 15:34:24 -07001672 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001673 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001674 if (mRingbackRequested != ringback) {
1675 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001676 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001677 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001678 }
1679 }
Ihab Awadf8358972014-05-28 16:46:42 -07001680 }
1681
1682 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001683 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001684 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001685 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001686 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001687 public final void setConnectionCapabilities(int connectionCapabilities) {
1688 checkImmutable();
1689 if (mConnectionCapabilities != connectionCapabilities) {
1690 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001691 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001692 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001693 }
1694 }
Santos Cordonb6939982014-06-04 20:20:58 -07001695 }
1696
1697 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001698 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1699 *
1700 * @param connectionProperties The new connection properties.
1701 */
1702 public final void setConnectionProperties(int connectionProperties) {
1703 checkImmutable();
1704 if (mConnectionProperties != connectionProperties) {
1705 mConnectionProperties = connectionProperties;
1706 for (Listener l : mListeners) {
1707 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1708 }
1709 }
1710 }
1711
1712 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001713 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001714 */
Evan Charlton36a71342014-07-19 16:31:02 -07001715 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001716 for (Listener l : mListeners) {
1717 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001718 }
Santos Cordonb6939982014-06-04 20:20:58 -07001719 }
1720
1721 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001722 * Requests that the framework use VOIP audio mode for this connection.
1723 *
1724 * @param isVoip True if the audio mode is VOIP.
1725 */
1726 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001727 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001728 mAudioModeIsVoip = isVoip;
1729 for (Listener l : mListeners) {
1730 l.onAudioModeIsVoipChanged(this, isVoip);
1731 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001732 }
1733
1734 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001735 * Sets the time at which a call became active on this Connection. This is set only
1736 * when a conference call becomes active on this connection.
1737 *
1738 * @param connectionTimeMillis The connection time, in milliseconds.
1739 *
1740 * @hide
1741 */
1742 public final void setConnectTimeMillis(long connectTimeMillis) {
1743 mConnectTimeMillis = connectTimeMillis;
1744 }
1745
1746 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001747 * Sets the label and icon status to display in the in-call UI.
1748 *
1749 * @param statusHints The status label and icon to set.
1750 */
1751 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001752 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001753 mStatusHints = statusHints;
1754 for (Listener l : mListeners) {
1755 l.onStatusHintsChanged(this, statusHints);
1756 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001757 }
1758
1759 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001760 * Sets the connections with which this connection can be conferenced.
1761 *
1762 * @param conferenceableConnections The set of connections this connection can conference with.
1763 */
1764 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001765 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001766 clearConferenceableList();
1767 for (Connection c : conferenceableConnections) {
1768 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1769 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001770 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001771 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001772 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001773 }
1774 }
1775 fireOnConferenceableConnectionsChanged();
1776 }
1777
1778 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001779 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1780 * or conferences with which this connection can be conferenced.
1781 *
1782 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001784 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001785 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001786 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001787 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1788 // small amount of items here.
1789 if (!mConferenceables.contains(c)) {
1790 if (c instanceof Connection) {
1791 Connection connection = (Connection) c;
1792 connection.addConnectionListener(mConnectionDeathListener);
1793 } else if (c instanceof Conference) {
1794 Conference conference = (Conference) c;
1795 conference.addListener(mConferenceDeathListener);
1796 }
1797 mConferenceables.add(c);
1798 }
1799 }
1800 fireOnConferenceableConnectionsChanged();
1801 }
1802
1803 /**
1804 * Returns the connections or conferences with which this connection can be conferenced.
1805 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001806 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001807 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001808 }
1809
Yorke Lee53463962015-08-04 16:07:19 -07001810 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001811 * @hide
1812 */
1813 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001814 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001815 if (mConnectionService != null) {
1816 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1817 "which is already associated with another ConnectionService.");
1818 } else {
1819 mConnectionService = connectionService;
1820 }
1821 }
1822
1823 /**
1824 * @hide
1825 */
1826 public final void unsetConnectionService(ConnectionService connectionService) {
1827 if (mConnectionService != connectionService) {
1828 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1829 "that does not belong to the ConnectionService.");
1830 } else {
1831 mConnectionService = null;
1832 }
1833 }
1834
1835 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001836 * @hide
1837 */
1838 public final ConnectionService getConnectionService() {
1839 return mConnectionService;
1840 }
1841
1842 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001843 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001844 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001845 *
1846 * @param conference The conference.
1847 * @return {@code true} if the conference was successfully set.
1848 * @hide
1849 */
1850 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001851 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001852 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001853 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001854 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001855 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1856 fireConferenceChanged();
1857 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001858 return true;
1859 }
1860 return false;
1861 }
1862
1863 /**
1864 * Resets the conference that this connection is a part of.
1865 * @hide
1866 */
1867 public final void resetConference() {
1868 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001869 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001870 mConference = null;
1871 fireConferenceChanged();
1872 }
1873 }
1874
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001876 * Set some extras that can be associated with this {@code Connection}.
1877 * <p>
1878 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1879 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1880 * <p>
1881 * 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 -07001882 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1883 *
1884 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001885 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1886 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001887 */
1888 public final void setExtras(@Nullable Bundle extras) {
1889 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001890
1891 // Add/replace any new or changed extras values.
1892 putExtras(extras);
1893
1894 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1895 // the current one and remove any keys that went away.
1896 if (mPreviousExtraKeys != null) {
1897 List<String> toRemove = new ArrayList<String>();
1898 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001899 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001900 toRemove.add(oldKey);
1901 }
1902 }
1903 if (!toRemove.isEmpty()) {
1904 removeExtras(toRemove);
1905 }
1906 }
1907
1908 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1909 // called we can see if the caller has removed any extras values.
1910 if (mPreviousExtraKeys == null) {
1911 mPreviousExtraKeys = new ArraySet<String>();
1912 }
1913 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001914 if (extras != null) {
1915 mPreviousExtraKeys.addAll(extras.keySet());
1916 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001917 }
1918
1919 /**
1920 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1921 * added.
1922 * <p>
1923 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1924 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1925 *
1926 * @param extras The extras to add.
1927 */
1928 public final void putExtras(@NonNull Bundle extras) {
1929 checkImmutable();
1930 if (extras == null) {
1931 return;
1932 }
1933
1934 if (mExtras == null) {
1935 mExtras = new Bundle();
1936 }
1937 mExtras.putAll(extras);
1938
Santos Cordon6b7f9552015-05-27 17:21:45 -07001939 for (Listener l : mListeners) {
1940 l.onExtrasChanged(this, extras);
1941 }
1942 }
1943
1944 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001945 * Adds a boolean extra to this {@code Connection}.
1946 *
1947 * @param key The extra key.
1948 * @param value The value.
1949 * @hide
1950 */
1951 public final void putExtra(String key, boolean value) {
1952 Bundle newExtras = new Bundle();
1953 newExtras.putBoolean(key, value);
1954 putExtras(newExtras);
1955 }
1956
1957 /**
1958 * Adds an integer extra to this {@code Connection}.
1959 *
1960 * @param key The extra key.
1961 * @param value The value.
1962 * @hide
1963 */
1964 public final void putExtra(String key, int value) {
1965 Bundle newExtras = new Bundle();
1966 newExtras.putInt(key, value);
1967 putExtras(newExtras);
1968 }
1969
1970 /**
1971 * Adds a string extra to this {@code Connection}.
1972 *
1973 * @param key The extra key.
1974 * @param value The value.
1975 * @hide
1976 */
1977 public final void putExtra(String key, String value) {
1978 Bundle newExtras = new Bundle();
1979 newExtras.putString(key, value);
1980 putExtras(newExtras);
1981 }
1982
1983 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001984 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001985 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07001986 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07001987 */
1988 public final void removeExtras(List<String> keys) {
1989 if (mExtras != null) {
1990 for (String key : keys) {
1991 mExtras.remove(key);
1992 }
1993
1994 if (mExtras.size() == 0) {
1995 mExtras = null;
1996 }
1997 }
1998
1999 for (Listener l : mListeners) {
2000 l.onExtrasRemoved(this, keys);
2001 }
2002 }
2003
2004 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002005 * Removes extras from this {@code Connection}.
2006 *
2007 * @param keys The keys of the extras to remove.
2008 */
2009 public final void removeExtras(String ... keys) {
2010 removeExtras(Arrays.asList(keys));
2011 }
2012
2013 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002014 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002015 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002016 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002017 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2018 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002019 */
Yorke Lee4af59352015-05-13 14:14:54 -07002020 @SystemApi
2021 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002022 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002023
2024 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002025 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2026 *
2027 * @param state The new connection audio state.
2028 */
2029 public void onCallAudioStateChanged(CallAudioState state) {}
2030
2031 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002032 * Notifies this Connection of an internal state change. This method is called after the
2033 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002034 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002035 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002036 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002037 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002038
2039 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002040 * Notifies this Connection of a request to play a DTMF tone.
2041 *
2042 * @param c A DTMF character.
2043 */
Santos Cordonf2951102014-07-20 19:06:29 -07002044 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002045
2046 /**
2047 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2048 */
Santos Cordonf2951102014-07-20 19:06:29 -07002049 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002050
2051 /**
2052 * Notifies this Connection of a request to disconnect.
2053 */
Santos Cordonf2951102014-07-20 19:06:29 -07002054 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055
2056 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002057 * Notifies this Connection of a request to disconnect a participant of the conference managed
2058 * by the connection.
2059 *
2060 * @param endpoint the {@link Uri} of the participant to disconnect.
2061 * @hide
2062 */
2063 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2064
2065 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002066 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002067 */
Santos Cordonf2951102014-07-20 19:06:29 -07002068 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002069
2070 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002071 * Notifies this Connection of a request to abort.
2072 */
Santos Cordonf2951102014-07-20 19:06:29 -07002073 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002074
2075 /**
2076 * Notifies this Connection of a request to hold.
2077 */
Santos Cordonf2951102014-07-20 19:06:29 -07002078 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002079
2080 /**
2081 * Notifies this Connection of a request to exit a hold state.
2082 */
Santos Cordonf2951102014-07-20 19:06:29 -07002083 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084
2085 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002086 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002087 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002088 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 */
Santos Cordonf2951102014-07-20 19:06:29 -07002091 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092
2093 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002094 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002095 * a request to accept.
2096 */
2097 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002098 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002099 }
2100
2101 /**
2102 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002103 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002104 */
Santos Cordonf2951102014-07-20 19:06:29 -07002105 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002106
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002107 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002108 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2109 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002110 */
2111 public void onReject(String replyMessage) {}
2112
2113 /**
Bryce Leecac50772015-11-17 15:13:29 -08002114 * Notifies the Connection of a request to silence the ringer.
2115 *
2116 * @hide
2117 */
2118 public void onSilence() {}
2119
2120 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002121 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2122 */
Santos Cordonf2951102014-07-20 19:06:29 -07002123 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002124
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002125 /**
2126 * Notifies this Connection of a request to pull an external call to the local device.
2127 * <p>
2128 * The {@link InCallService} issues a request to pull an external call to the local device via
2129 * {@link Call#pullExternalCall()}.
2130 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002131 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2132 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002133 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002134 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002135 */
2136 public void onPullExternalCall() {}
2137
2138 /**
2139 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2140 * <p>
2141 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2142 * <p>
2143 * See also {@link Call#sendCallEvent(String, Bundle)}.
2144 *
2145 * @param event The call event.
2146 * @param extras Extras associated with the call event.
2147 */
2148 public void onCallEvent(String event, Bundle extras) {}
2149
Tyler Gunndee56a82016-03-23 16:06:34 -07002150 /**
2151 * Notifies this {@link Connection} of a change to the extras made outside the
2152 * {@link ConnectionService}.
2153 * <p>
2154 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2155 * the {@link android.telecom.Call#putExtras(Bundle)} and
2156 * {@link Call#removeExtras(List)}.
2157 *
2158 * @param extras The new extras bundle.
2159 */
2160 public void onExtrasChanged(Bundle extras) {}
2161
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002162 static String toLogSafePhoneNumber(String number) {
2163 // For unknown number, log empty string.
2164 if (number == null) {
2165 return "";
2166 }
2167
2168 if (PII_DEBUG) {
2169 // When PII_DEBUG is true we emit PII.
2170 return number;
2171 }
2172
2173 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2174 // sanitized phone numbers.
2175 StringBuilder builder = new StringBuilder();
2176 for (int i = 0; i < number.length(); i++) {
2177 char c = number.charAt(i);
2178 if (c == '-' || c == '@' || c == '.') {
2179 builder.append(c);
2180 } else {
2181 builder.append('x');
2182 }
2183 }
2184 return builder.toString();
2185 }
2186
Ihab Awad542e0ea2014-05-16 10:22:16 -07002187 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002188 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002189 if (mState == STATE_DISCONNECTED && mState != state) {
2190 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002191 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002192 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002193 if (mState != state) {
2194 Log.d(this, "setState: %s", stateToString(state));
2195 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002196 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002197 for (Listener l : mListeners) {
2198 l.onStateChanged(this, state);
2199 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002200 }
2201 }
2202
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002203 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002204 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002205 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2206 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002207 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002208 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002209
2210 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002211 if (mImmutable) {
2212 throw new UnsupportedOperationException("Connection is immutable");
2213 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002214 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002215 }
2216
Evan Charltonbf11f982014-07-20 22:06:28 -07002217 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002218 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002219 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2220 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002221 * <p>
2222 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2223 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002224 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002225 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002226 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002227 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002228 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2229 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002230 }
2231
Evan Charltonbf11f982014-07-20 22:06:28 -07002232 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002233 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2234 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2235 * this should never be un-@hide-den.
2236 *
2237 * @hide
2238 */
2239 public void checkImmutable() {}
2240
2241 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002242 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2243 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2244 * that state. This connection should not be used for anything, and no other
2245 * {@code Connection}s should be attempted.
2246 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002247 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002248 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002249 * @return A {@code Connection} which indicates that the underlying connection should
2250 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002251 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002252 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002253 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002254 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002255
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002256 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002257 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002258 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002259 }
2260 }
2261
Santos Cordon823fd3c2014-08-07 18:35:18 -07002262 private final void fireConferenceChanged() {
2263 for (Listener l : mListeners) {
2264 l.onConferenceChanged(this, mConference);
2265 }
2266 }
2267
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002268 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002269 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002270 if (c instanceof Connection) {
2271 Connection connection = (Connection) c;
2272 connection.removeConnectionListener(mConnectionDeathListener);
2273 } else if (c instanceof Conference) {
2274 Conference conference = (Conference) c;
2275 conference.removeListener(mConferenceDeathListener);
2276 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002277 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002278 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002279 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002280
2281 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002282 * Handles a change to extras received from Telecom.
2283 *
2284 * @param extras The new extras.
2285 * @hide
2286 */
2287 final void handleExtrasChanged(Bundle extras) {
2288 mExtras = extras;
2289 onExtrasChanged(mExtras);
2290 }
2291
2292 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002293 * Notifies listeners that the merge request failed.
2294 *
2295 * @hide
2296 */
2297 protected final void notifyConferenceMergeFailed() {
2298 for (Listener l : mListeners) {
2299 l.onConferenceMergeFailed(this);
2300 }
2301 }
2302
2303 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002304 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002305 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002306 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002307 * @hide
2308 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002309 protected final void updateConferenceParticipants(
2310 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002311 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002312 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002313 }
2314 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002315
2316 /**
2317 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002318 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002319 */
2320 protected void notifyConferenceStarted() {
2321 for (Listener l : mListeners) {
2322 l.onConferenceStarted();
2323 }
2324 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002325
2326 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002327 * Sends an event associated with this {@code Connection}, with associated event extras.
2328 *
2329 * Events are exposed to {@link InCallService} implementations via the
2330 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2331 *
2332 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2333 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002334 *
2335 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002336 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002337 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002338 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002339 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002340 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002341 }
2342 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002343}