blob: 91380b2e16f7d67e7744cd2dcbe08b6123745925 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070038import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
44/**
Santos Cordon895d4b82015-06-25 16:41:48 -070045 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
46 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070047 * <p>
48 * Implementations create a custom subclass of {@code Connection} and return it to the framework
49 * as the return value of
50 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
51 * or
52 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
53 * Implementations are then responsible for updating the state of the {@code Connection}, and
54 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
55 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070056 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070057public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
Santos Cordon895d4b82015-06-25 16:41:48 -070059 /**
60 * The connection is initializing. This is generally the first state for a {@code Connection}
61 * returned by a {@link ConnectionService}.
62 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 public static final int STATE_INITIALIZING = 0;
64
Santos Cordon895d4b82015-06-25 16:41:48 -070065 /**
66 * The connection is new and not connected.
67 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 public static final int STATE_NEW = 1;
69
Santos Cordon895d4b82015-06-25 16:41:48 -070070 /**
71 * An incoming connection is in the ringing state. During this state, the user's ringer or
72 * vibration feature will be activated.
73 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 public static final int STATE_RINGING = 2;
75
Santos Cordon895d4b82015-06-25 16:41:48 -070076 /**
77 * An outgoing connection is in the dialing state. In this state the other party has not yet
78 * answered the call and the user traditionally hears a ringback tone.
79 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 public static final int STATE_DIALING = 3;
81
Santos Cordon895d4b82015-06-25 16:41:48 -070082 /**
83 * A connection is active. Both parties are connected to the call and can actively communicate.
84 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 public static final int STATE_ACTIVE = 4;
86
Santos Cordon895d4b82015-06-25 16:41:48 -070087 /**
88 * A connection is on hold.
89 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 public static final int STATE_HOLDING = 5;
91
Santos Cordon895d4b82015-06-25 16:41:48 -070092 /**
93 * A connection has been disconnected. This is the final state once the user has been
94 * disconnected from a call either locally, remotely or by an error in the service.
95 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public static final int STATE_DISCONNECTED = 6;
97
Santos Cordon895d4b82015-06-25 16:41:48 -070098 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external connection which is in the process of being pulled from a remote
100 * device to the local device.
101 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700102 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700103 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
104 */
105 public static final int STATE_PULLING_CALL = 7;
106
107 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 * Connection can currently be put on hold or unheld. This is distinct from
109 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
110 * it does not at the moment support the function. This can be true while the call is in the
111 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
112 * display a disabled 'hold' button.
113 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 public static final int CAPABILITY_HOLD = 0x00000001;
115
116 /** Connection supports the hold feature. */
117 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
118
119 /**
120 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
121 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
122 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
123 * capability allows a merge button to be shown while the conference is in the foreground
124 * of the in-call UI.
125 * <p>
126 * This is only intended for use by a {@link Conference}.
127 */
128 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
129
130 /**
131 * Connections within a conference can be swapped between foreground and background.
132 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
133 * <p>
134 * This is only intended for use by a {@link Conference}.
135 */
136 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
137
138 /**
139 * @hide
140 */
141 public static final int CAPABILITY_UNUSED = 0x00000010;
142
143 /** Connection supports responding via text option. */
144 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
145
146 /** Connection can be muted. */
147 public static final int CAPABILITY_MUTE = 0x00000040;
148
149 /**
150 * Connection supports conference management. This capability only applies to
151 * {@link Conference}s which can have {@link Connection}s as children.
152 */
153 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
154
155 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700158 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159
160 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164
165 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700168 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
175
176 /**
177 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 */
179 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
180
181 /**
182 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
188 * Connection is able to be separated from its parent {@code Conference}, if any.
189 */
190 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
191
192 /**
193 * Connection is able to be individually disconnected when in a {@code Conference}.
194 */
195 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
196
197 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700198 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 * @hide
200 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700201 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700204 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 * @hide
206 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700207 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208
209 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700210 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * @hide
212 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700213 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214
Tyler Gunn068085b2015-02-06 13:56:52 -0800215 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700216 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800217 * @hide
218 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700219 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800220
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 */
225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Tyler Gunnd4091732015-06-29 09:15:37 -0700238 /**
239 * For a conference, indicates the conference will not have child connections.
240 * <p>
241 * An example of a conference with child connections is a GSM conference call, where the radio
242 * retains connections to the individual participants of the conference. Another example is an
243 * IMS conference call where conference event package functionality is supported; in this case
244 * the conference server ensures the radio is aware of the participants in the conference, which
245 * are represented by child connections.
246 * <p>
247 * An example of a conference with no child connections is an IMS conference call with no
248 * conference event package support. Such a conference is represented by the radio as a single
249 * connection to the IMS conference server.
250 * <p>
251 * Indicating whether a conference has children or not is important to help user interfaces
252 * visually represent a conference. A conference with no children, for example, will have the
253 * conference connection shown in the list of calls on a Bluetooth device, where if the
254 * conference has children, only the children will be shown in the list of calls on a Bluetooth
255 * device.
256 * @hide
257 */
258 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259
Bryce Lee81901682015-08-28 16:38:02 -0700260 /**
261 * Indicates that the connection itself wants to handle any sort of reply response, rather than
262 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700263 */
264 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
265
Tyler Gunnf97a0092016-01-19 15:59:34 -0800266 /**
267 * When set, prevents a video call from being downgraded to an audio-only call.
268 * <p>
269 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271 * downgraded from a video call back to a VideoState of
272 * {@link VideoProfile#STATE_AUDIO_ONLY}.
273 * <p>
274 * Intuitively, a call which can be downgraded to audio should also have local and remote
275 * video
276 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278 */
279 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700281 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 * When set for an external connection, indicates that this {@code Connection} can be pulled
283 * from a remote device to the current device.
284 * <p>
285 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
286 * is set.
287 */
288 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
289
290 //**********************************************************************************************
291 // Next CAPABILITY value: 0x02000000
292 //**********************************************************************************************
293
294 /**
295 * Indicates that the current device callback number should be shown.
296 *
297 * @hide
298 */
299 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
300
301 /**
302 * Whether the call is a generic conference, where we do not know the precise state of
303 * participants in the conference (eg. on CDMA).
304 *
305 * @hide
306 */
307 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
308
309 /**
310 * Connection is using high definition audio.
311 * @hide
312 */
313 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
314
315 /**
316 * Connection is using WIFI.
317 * @hide
318 */
319 public static final int PROPERTY_WIFI = 1<<3;
320
321 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 * When set, indicates that the {@code Connection} does not actually exist locally for the
323 * {@link ConnectionService}.
324 * <p>
325 * Consider, for example, a scenario where a user has two devices with the same phone number.
326 * When a user places a call on one devices, the telephony stack can represent that call on the
327 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700328 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700329 * <p>
330 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
331 * external connections. Only those {@link InCallService}s which have the
332 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
333 * manifest will see external connections.
334 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336
Brad Ebinger15847072016-05-18 11:08:36 -0700337 /**
338 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
339 */
340 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700341
Tyler Gunn96d6c402015-03-18 12:39:23 -0700342 //**********************************************************************************************
Brad Ebinger15847072016-05-18 11:08:36 -0700343 // Next PROPERTY value: 1<<6
Tyler Gunn96d6c402015-03-18 12:39:23 -0700344 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800345
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700346 /**
347 * Connection extra key used to store the last forwarded number associated with the current
348 * connection. Used to communicate to the user interface that the connection was forwarded via
349 * the specified number.
350 */
351 public static final String EXTRA_LAST_FORWARDED_NUMBER =
352 "android.telecom.extra.LAST_FORWARDED_NUMBER";
353
354 /**
355 * Connection extra key used to store a child number associated with the current connection.
356 * Used to communicate to the user interface that the connection was received via
357 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
358 * address.
359 */
360 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
361
362 /**
363 * Connection extra key used to store the subject for an incoming call. The user interface can
364 * query this extra and display its contents for incoming calls. Will only be used if the
365 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
366 */
367 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
368
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800369 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700370 * Boolean connection extra key set on a {@link Connection} in
371 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
372 * current active foreground call to be dropped.
373 */
374 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
375 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
376
377 /**
Hall Liu10208662016-06-15 17:55:00 -0700378 * Boolean connection extra key on a {@link Connection} which indicates that adding an
379 * additional call is disallowed when there is a video call in progress.
380 * @hide
381 */
382 public static final String EXTRA_DISABLE_ADD_CALL_DURING_VIDEO_CALL =
383 "android.telecom.extra.DISABLE_ADD_CALL_DURING_VIDEO_CALL";
384
385 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800386 * Connection event used to inform Telecom that it should play the on hold tone. This is used
387 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
388 * {@link #sendConnectionEvent(String)}.
389 * @hide
390 */
391 public static final String EVENT_ON_HOLD_TONE_START =
392 "android.telecom.event.ON_HOLD_TONE_START";
393
394 /**
395 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
396 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
397 * {@link #sendConnectionEvent(String)}.
398 * @hide
399 */
400 public static final String EVENT_ON_HOLD_TONE_END =
401 "android.telecom.event.ON_HOLD_TONE_END";
402
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700403 /**
404 * Connection event used to inform {@link InCallService}s when pulling of an external call has
405 * failed. The user interface should inform the user of the error.
406 * <p>
407 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
408 * API is called on a {@link Call} with the properties
409 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
410 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
411 * pull the external call due to an error condition.
412 */
413 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
414
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700415 /**
416 * Connection event used to inform {@link InCallService}s when the merging of two calls has
417 * failed. The User Interface should use this message to inform the user of the error.
418 */
419 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
420
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700421 // Flag controlling whether PII is emitted into the logs
422 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
423
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800424 /**
425 * Whether the given capabilities support the specified capability.
426 *
427 * @param capabilities A capability bit field.
428 * @param capability The capability to check capabilities for.
429 * @return Whether the specified capability is supported.
430 * @hide
431 */
432 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800433 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800434 }
435
436 /**
437 * Whether the capabilities of this {@code Connection} supports the specified capability.
438 *
439 * @param capability The capability to check capabilities for.
440 * @return Whether the specified capability is supported.
441 * @hide
442 */
443 public boolean can(int capability) {
444 return can(mConnectionCapabilities, capability);
445 }
446
447 /**
448 * Removes the specified capability from the set of capabilities of this {@code Connection}.
449 *
450 * @param capability The capability to remove from the set.
451 * @hide
452 */
453 public void removeCapability(int capability) {
454 mConnectionCapabilities &= ~capability;
455 }
456
457 /**
458 * Adds the specified capability to the set of capabilities of this {@code Connection}.
459 *
460 * @param capability The capability to add to the set.
461 * @hide
462 */
463 public void addCapability(int capability) {
464 mConnectionCapabilities |= capability;
465 }
466
467
468 public static String capabilitiesToString(int capabilities) {
469 StringBuilder builder = new StringBuilder();
470 builder.append("[Capabilities:");
471 if (can(capabilities, CAPABILITY_HOLD)) {
472 builder.append(" CAPABILITY_HOLD");
473 }
474 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
475 builder.append(" CAPABILITY_SUPPORT_HOLD");
476 }
477 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
478 builder.append(" CAPABILITY_MERGE_CONFERENCE");
479 }
480 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
481 builder.append(" CAPABILITY_SWAP_CONFERENCE");
482 }
483 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
484 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
485 }
486 if (can(capabilities, CAPABILITY_MUTE)) {
487 builder.append(" CAPABILITY_MUTE");
488 }
489 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
490 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
491 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700492 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
493 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
494 }
495 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
496 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
497 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700498 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
499 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800500 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700501 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
502 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
503 }
504 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
505 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
506 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700507 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
508 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800509 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800510 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
511 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
512 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500513 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700514 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500515 }
Rekha Kumar07366812015-03-24 16:42:31 -0700516 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
517 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
518 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700519 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
520 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
521 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700522 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
523 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
524 }
Bryce Lee81901682015-08-28 16:38:02 -0700525 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
526 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
527 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700528 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
529 builder.append(" CAPABILITY_CAN_PULL_CALL");
530 }
Bryce Lee81901682015-08-28 16:38:02 -0700531
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 builder.append("]");
533 return builder.toString();
534 }
535
Tyler Gunn720c6642016-03-22 09:02:47 -0700536 public static String propertiesToString(int properties) {
537 StringBuilder builder = new StringBuilder();
538 builder.append("[Properties:");
539
540 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
541 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
542 }
543
544 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
545 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
546 }
547
548 if (can(properties, PROPERTY_WIFI)) {
549 builder.append(" PROPERTY_WIFI");
550 }
551
552 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
553 builder.append(" PROPERTY_GENERIC_CONFERENCE");
554 }
555
556 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
557 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
558 }
559
Brad Ebinger15847072016-05-18 11:08:36 -0700560 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
561 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
562 }
563
Tyler Gunn720c6642016-03-22 09:02:47 -0700564 builder.append("]");
565 return builder.toString();
566 }
567
Sailesh Nepal091768c2014-06-30 15:15:23 -0700568 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700569 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700570 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700571 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700572 public void onCallerDisplayNameChanged(
573 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700574 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700575 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700576 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800577 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700578 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700579 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800580 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700581 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700582 public void onVideoProviderChanged(
583 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700584 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
585 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800586 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700587 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700588 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700589 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800590 public void onConferenceParticipantsChanged(Connection c,
591 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800592 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700593 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700594 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700595 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700596 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700597 /** @hide */
598 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700599 }
600
Tyler Gunnb702ef82015-05-29 11:51:53 -0700601 /**
602 * Provides a means of controlling the video session associated with a {@link Connection}.
603 * <p>
604 * Implementations create a custom subclass of {@link VideoProvider} and the
605 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
606 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
607 * should set the {@link VideoProvider}.
608 * <p>
609 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
610 * {@link InCallService} implementations to issue requests related to the video session;
611 * it provides a means for the {@link ConnectionService} to report events and information
612 * related to the video session to Telecom and the {@link InCallService} implementations.
613 * <p>
614 * {@link InCallService} implementations interact with the {@link VideoProvider} via
615 * {@link android.telecom.InCallService.VideoCall}.
616 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700618
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 /**
620 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700621 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700622 */
623 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700624
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700626 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
627 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 */
629 public static final int SESSION_EVENT_RX_RESUME = 2;
630
631 /**
632 * Video transmission has begun. This occurs after a negotiated start of video transmission
633 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700634 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700635 */
636 public static final int SESSION_EVENT_TX_START = 3;
637
638 /**
639 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
640 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700641 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 */
643 public static final int SESSION_EVENT_TX_STOP = 4;
644
645 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700646 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
647 * this as a cue to inform the user the camera is not available.
648 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 */
650 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
651
652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700653 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
654 * for operation. The {@link InCallService} can use this as a cue to inform the user that
655 * the camera has become available again.
656 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 */
658 public static final int SESSION_EVENT_CAMERA_READY = 6;
659
660 /**
661 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700662 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 */
664 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
665
666 /**
667 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700668 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669 */
670 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
671
672 /**
673 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700674 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 */
676 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
677
Rekha Kumar07366812015-03-24 16:42:31 -0700678 /**
679 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700680 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700681 */
682 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
683
684 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700685 * Session modify request rejected by remote user.
686 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700687 */
688 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
689
Tyler Gunn75958422015-04-15 14:23:42 -0700690 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700691 private static final int MSG_SET_CAMERA = 2;
692 private static final int MSG_SET_PREVIEW_SURFACE = 3;
693 private static final int MSG_SET_DISPLAY_SURFACE = 4;
694 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
695 private static final int MSG_SET_ZOOM = 6;
696 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
697 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
698 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800699 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700700 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700701 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700702
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700703 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700705
706 /**
707 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700708 *
709 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
710 * load factor before resizing, 1 means we only expect a single thread to
711 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700712 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700713 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
714 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700715
716 /**
717 * Default handler used to consolidate binder method calls onto a single thread.
718 */
719 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700720 public VideoProviderHandler() {
721 super();
722 }
723
724 public VideoProviderHandler(Looper looper) {
725 super(looper);
726 }
727
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 @Override
729 public void handleMessage(Message msg) {
730 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700731 case MSG_ADD_VIDEO_CALLBACK: {
732 IBinder binder = (IBinder) msg.obj;
733 IVideoCallback callback = IVideoCallback.Stub
734 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700735 if (callback == null) {
736 Log.w(this, "addVideoProvider - skipped; callback is null.");
737 break;
738 }
739
Tyler Gunn75958422015-04-15 14:23:42 -0700740 if (mVideoCallbacks.containsKey(binder)) {
741 Log.i(this, "addVideoProvider - skipped; already present.");
742 break;
743 }
744 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700745 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700746 }
747 case MSG_REMOVE_VIDEO_CALLBACK: {
748 IBinder binder = (IBinder) msg.obj;
749 IVideoCallback callback = IVideoCallback.Stub
750 .asInterface((IBinder) msg.obj);
751 if (!mVideoCallbacks.containsKey(binder)) {
752 Log.i(this, "removeVideoProvider - skipped; not present.");
753 break;
754 }
755 mVideoCallbacks.remove(binder);
756 break;
757 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 case MSG_SET_CAMERA:
759 onSetCamera((String) msg.obj);
760 break;
761 case MSG_SET_PREVIEW_SURFACE:
762 onSetPreviewSurface((Surface) msg.obj);
763 break;
764 case MSG_SET_DISPLAY_SURFACE:
765 onSetDisplaySurface((Surface) msg.obj);
766 break;
767 case MSG_SET_DEVICE_ORIENTATION:
768 onSetDeviceOrientation(msg.arg1);
769 break;
770 case MSG_SET_ZOOM:
771 onSetZoom((Float) msg.obj);
772 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700773 case MSG_SEND_SESSION_MODIFY_REQUEST: {
774 SomeArgs args = (SomeArgs) msg.obj;
775 try {
776 onSendSessionModifyRequest((VideoProfile) args.arg1,
777 (VideoProfile) args.arg2);
778 } finally {
779 args.recycle();
780 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700782 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700783 case MSG_SEND_SESSION_MODIFY_RESPONSE:
784 onSendSessionModifyResponse((VideoProfile) msg.obj);
785 break;
786 case MSG_REQUEST_CAMERA_CAPABILITIES:
787 onRequestCameraCapabilities();
788 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800789 case MSG_REQUEST_CONNECTION_DATA_USAGE:
790 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700791 break;
792 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700793 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700794 break;
795 default:
796 break;
797 }
798 }
799 }
800
801 /**
802 * IVideoProvider stub implementation.
803 */
804 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700805 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700807 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
808 }
809
810 public void removeVideoCallback(IBinder videoCallbackBinder) {
811 mMessageHandler.obtainMessage(
812 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700813 }
814
815 public void setCamera(String cameraId) {
816 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
817 }
818
819 public void setPreviewSurface(Surface surface) {
820 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
821 }
822
823 public void setDisplaySurface(Surface surface) {
824 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
825 }
826
827 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700828 mMessageHandler.obtainMessage(
829 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 }
831
832 public void setZoom(float value) {
833 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
834 }
835
Tyler Gunn45382162015-05-06 08:52:27 -0700836 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
837 SomeArgs args = SomeArgs.obtain();
838 args.arg1 = fromProfile;
839 args.arg2 = toProfile;
840 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700841 }
842
843 public void sendSessionModifyResponse(VideoProfile responseProfile) {
844 mMessageHandler.obtainMessage(
845 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
846 }
847
848 public void requestCameraCapabilities() {
849 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
850 }
851
852 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800853 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700854 }
855
Yorke Lee32f24732015-05-12 16:18:03 -0700856 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700857 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
858 }
859 }
860
861 public VideoProvider() {
862 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700863 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700864 }
865
866 /**
867 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
868 *
869 * @param looper The looper.
870 * @hide
871 */
872 public VideoProvider(Looper looper) {
873 mBinder = new VideoProvider.VideoProviderBinder();
874 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 }
876
877 /**
878 * Returns binder object which can be used across IPC methods.
879 * @hide
880 */
881 public final IVideoProvider getInterface() {
882 return mBinder;
883 }
884
885 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700886 * Sets the camera to be used for the outgoing video.
887 * <p>
888 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
889 * camera via
890 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
891 * <p>
892 * Sent from the {@link InCallService} via
893 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700894 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700895 * @param cameraId The id of the camera (use ids as reported by
896 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 */
898 public abstract void onSetCamera(String cameraId);
899
900 /**
901 * Sets the surface to be used for displaying a preview of what the user's camera is
902 * currently capturing. When video transmission is enabled, this is the video signal which
903 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * <p>
905 * Sent from the {@link InCallService} via
906 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700908 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 */
910 public abstract void onSetPreviewSurface(Surface surface);
911
912 /**
913 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * <p>
915 * Sent from the {@link InCallService} via
916 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700917 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700918 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700919 */
920 public abstract void onSetDisplaySurface(Surface surface);
921
922 /**
923 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
924 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700925 * <p>
926 * Sent from the {@link InCallService} via
927 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 *
929 * @param rotation The device orientation, in degrees.
930 */
931 public abstract void onSetDeviceOrientation(int rotation);
932
933 /**
934 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 * <p>
936 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700937 *
938 * @param value The camera zoom ratio.
939 */
940 public abstract void onSetZoom(float value);
941
942 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * Issues a request to modify the properties of the current video session.
944 * <p>
945 * Example scenarios include: requesting an audio-only call to be upgraded to a
946 * bi-directional video call, turning on or off the user's camera, sending a pause signal
947 * when the {@link InCallService} is no longer the foreground application.
948 * <p>
949 * If the {@link VideoProvider} determines a request to be invalid, it should call
950 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
951 * invalid request back to the {@link InCallService}.
952 * <p>
953 * Where a request requires confirmation from the user of the peer device, the
954 * {@link VideoProvider} must communicate the request to the peer device and handle the
955 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
956 * is used to inform the {@link InCallService} of the result of the request.
957 * <p>
958 * Sent from the {@link InCallService} via
959 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700961 * @param fromProfile The video profile prior to the request.
962 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 */
Tyler Gunn45382162015-05-06 08:52:27 -0700964 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
965 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966
Tyler Gunnb702ef82015-05-29 11:51:53 -0700967 /**
968 * Provides a response to a request to change the current video session properties.
969 * <p>
970 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
971 * video call, could decline the request and keep the call as audio-only.
972 * In such a scenario, the {@code responseProfile} would have a video state of
973 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
974 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
975 * <p>
976 * Sent from the {@link InCallService} via
977 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
978 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
979 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700981 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 */
983 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
984
985 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
987 * <p>
988 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
989 * camera via
990 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
991 * <p>
992 * Sent from the {@link InCallService} via
993 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700994 */
995 public abstract void onRequestCameraCapabilities();
996
997 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700998 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
999 * video component of the current {@link Connection}.
1000 * <p>
1001 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1002 * via {@link VideoProvider#setCallDataUsage(long)}.
1003 * <p>
1004 * Sent from the {@link InCallService} via
1005 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001006 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001007 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008
1009 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001010 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1011 * the peer device when the video signal is paused.
1012 * <p>
1013 * Sent from the {@link InCallService} via
1014 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 *
1016 * @param uri URI of image to display.
1017 */
Yorke Lee32f24732015-05-12 16:18:03 -07001018 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019
1020 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * Used to inform listening {@link InCallService} implementations when the
1022 * {@link VideoProvider} receives a session modification request.
1023 * <p>
1024 * Received by the {@link InCallService} via
1025 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001026 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001027 * @param videoProfile The requested video profile.
1028 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 */
1030 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001031 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001032 for (IVideoCallback callback : mVideoCallbacks.values()) {
1033 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001034 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001035 } catch (RemoteException ignored) {
1036 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001037 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 }
1039 }
1040 }
1041
1042 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * Used to inform listening {@link InCallService} implementations when the
1044 * {@link VideoProvider} receives a response to a session modification request.
1045 * <p>
1046 * Received by the {@link InCallService} via
1047 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1048 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 *
1050 * @param status Status of the session modify request. Valid values are
1051 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1052 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001053 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1054 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1055 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1056 * @param requestedProfile The original request which was sent to the peer device.
1057 * @param responseProfile The actual profile changes agreed to by the peer device.
1058 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059 */
1060 public void receiveSessionModifyResponse(int status,
1061 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001062 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001063 for (IVideoCallback callback : mVideoCallbacks.values()) {
1064 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001065 callback.receiveSessionModifyResponse(status, requestedProfile,
1066 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001067 } catch (RemoteException ignored) {
1068 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001069 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001070 }
1071 }
1072 }
1073
1074 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * Used to inform listening {@link InCallService} implementations when the
1076 * {@link VideoProvider} reports a call session event.
1077 * <p>
1078 * Received by the {@link InCallService} via
1079 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001080 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001081 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1082 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1083 * {@link VideoProvider#SESSION_EVENT_TX_START},
1084 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1085 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1086 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001087 */
1088 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001089 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001090 for (IVideoCallback callback : mVideoCallbacks.values()) {
1091 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001092 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001093 } catch (RemoteException ignored) {
1094 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001095 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 }
1097 }
1098 }
1099
1100 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001101 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1102 * peer's video have changed.
1103 * <p>
1104 * This could occur if, for example, the peer rotates their device, changing the aspect
1105 * ratio of the video, or if the user switches between the back and front cameras.
1106 * <p>
1107 * Received by the {@link InCallService} via
1108 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 *
1110 * @param width The updated peer video width.
1111 * @param height The updated peer video height.
1112 */
1113 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001114 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001115 for (IVideoCallback callback : mVideoCallbacks.values()) {
1116 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001117 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001118 } catch (RemoteException ignored) {
1119 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001120 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 }
1122 }
1123 }
1124
1125 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001126 * Used to inform listening {@link InCallService} implementations when the data usage of the
1127 * video associated with the current {@link Connection} has changed.
1128 * <p>
1129 * This could be in response to a preview request via
1130 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001131 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1132 * 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 -07001133 * <p>
1134 * Received by the {@link InCallService} via
1135 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001137 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1138 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001139 */
Yorke Lee32f24732015-05-12 16:18:03 -07001140 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001141 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001142 for (IVideoCallback callback : mVideoCallbacks.values()) {
1143 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001144 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001145 } catch (RemoteException ignored) {
1146 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001147 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 }
1149 }
1150 }
1151
1152 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001153 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001155 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001156 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1157 * @hide
1158 */
1159 public void changeCallDataUsage(long dataUsage) {
1160 setCallDataUsage(dataUsage);
1161 }
1162
1163 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001164 * Used to inform listening {@link InCallService} implementations when the capabilities of
1165 * the current camera have changed.
1166 * <p>
1167 * The {@link VideoProvider} should call this in response to
1168 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1169 * changed via {@link VideoProvider#onSetCamera(String)}.
1170 * <p>
1171 * Received by the {@link InCallService} via
1172 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1173 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001174 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001175 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001176 */
Yorke Lee400470f2015-05-12 13:31:25 -07001177 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001178 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001179 for (IVideoCallback callback : mVideoCallbacks.values()) {
1180 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001181 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001182 } catch (RemoteException ignored) {
1183 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001184 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001185 }
1186 }
1187 }
Rekha Kumar07366812015-03-24 16:42:31 -07001188
1189 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001190 * Used to inform listening {@link InCallService} implementations when the video quality
1191 * of the call has changed.
1192 * <p>
1193 * Received by the {@link InCallService} via
1194 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001195 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001196 * @param videoQuality The updated video quality. Valid values:
1197 * {@link VideoProfile#QUALITY_HIGH},
1198 * {@link VideoProfile#QUALITY_MEDIUM},
1199 * {@link VideoProfile#QUALITY_LOW},
1200 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001201 */
1202 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001203 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001204 for (IVideoCallback callback : mVideoCallbacks.values()) {
1205 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001206 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001207 } catch (RemoteException ignored) {
1208 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001209 }
Rekha Kumar07366812015-03-24 16:42:31 -07001210 }
1211 }
1212 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001213 }
1214
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001215 private final Listener mConnectionDeathListener = new Listener() {
1216 @Override
1217 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001218 if (mConferenceables.remove(c)) {
1219 fireOnConferenceableConnectionsChanged();
1220 }
1221 }
1222 };
1223
1224 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1225 @Override
1226 public void onDestroyed(Conference c) {
1227 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001228 fireOnConferenceableConnectionsChanged();
1229 }
1230 }
1231 };
1232
Jay Shrauner229e3822014-08-15 09:23:07 -07001233 /**
1234 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1235 * load factor before resizing, 1 means we only expect a single thread to
1236 * access the map so make only a single shard
1237 */
1238 private final Set<Listener> mListeners = Collections.newSetFromMap(
1239 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001240 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1241 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001242 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001243
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001244 // The internal telecom call ID associated with this connection.
1245 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001247 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001248 private Uri mAddress;
1249 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001250 private String mCallerDisplayName;
1251 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001252 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001253 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001254 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001256 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001257 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001258 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001259 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001260 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001261 private Conference mConference;
1262 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001263 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001264 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001265
1266 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001267 * Tracks the key set for the extras bundle provided on the last invocation of
1268 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1269 * keys which were set previously but are no longer present in the replacement Bundle.
1270 */
1271 private Set<String> mPreviousExtraKeys;
1272
1273 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001274 * Create a new Connection.
1275 */
Santos Cordonf2951102014-07-20 19:06:29 -07001276 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001277
1278 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001279 * Returns the Telecom internal call ID associated with this connection. Should only be used
1280 * for debugging and tracing purposes.
1281 *
1282 * @return The Telecom call ID.
1283 * @hide
1284 */
1285 public final String getTelecomCallId() {
1286 return mTelecomCallId;
1287 }
1288
1289 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001290 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001291 */
Andrew Lee100e2932014-09-08 15:34:24 -07001292 public final Uri getAddress() {
1293 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001294 }
1295
1296 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001297 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001298 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001299 */
Andrew Lee100e2932014-09-08 15:34:24 -07001300 public final int getAddressPresentation() {
1301 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001302 }
1303
1304 /**
1305 * @return The caller display name (CNAP).
1306 */
1307 public final String getCallerDisplayName() {
1308 return mCallerDisplayName;
1309 }
1310
1311 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001312 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001313 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001314 */
1315 public final int getCallerDisplayNamePresentation() {
1316 return mCallerDisplayNamePresentation;
1317 }
1318
1319 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001320 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001321 */
1322 public final int getState() {
1323 return mState;
1324 }
1325
1326 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001327 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001328 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1329 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1330 * {@link VideoProfile#STATE_TX_ENABLED},
1331 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001332 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001333 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001334 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001335 */
1336 public final int getVideoState() {
1337 return mVideoState;
1338 }
1339
1340 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001341 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001342 * being routed by the system. This is {@code null} if this Connection
1343 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001344 * @deprecated Use {@link #getCallAudioState()} instead.
1345 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001346 */
Yorke Lee4af59352015-05-13 14:14:54 -07001347 @SystemApi
1348 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001350 if (mCallAudioState == null) {
1351 return null;
1352 }
Yorke Lee4af59352015-05-13 14:14:54 -07001353 return new AudioState(mCallAudioState);
1354 }
1355
1356 /**
1357 * @return The audio state of the connection, describing how its audio is currently
1358 * being routed by the system. This is {@code null} if this Connection
1359 * does not directly know about its audio state.
1360 */
1361 public final CallAudioState getCallAudioState() {
1362 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001363 }
1364
1365 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001366 * @return The conference that this connection is a part of. Null if it is not part of any
1367 * conference.
1368 */
1369 public final Conference getConference() {
1370 return mConference;
1371 }
1372
1373 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001374 * Returns whether this connection is requesting that the system play a ringback tone
1375 * on its behalf.
1376 */
Andrew Lee100e2932014-09-08 15:34:24 -07001377 public final boolean isRingbackRequested() {
1378 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001379 }
1380
1381 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001382 * @return True if the connection's audio mode is VOIP.
1383 */
1384 public final boolean getAudioModeIsVoip() {
1385 return mAudioModeIsVoip;
1386 }
1387
1388 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001389 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1390 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1391 * start time of the conference.
1392 *
1393 * @return The time at which the {@code Connnection} was connected.
1394 *
1395 * @hide
1396 */
1397 public final long getConnectTimeMillis() {
1398 return mConnectTimeMillis;
1399 }
1400
1401 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001402 * @return The status hints for this connection.
1403 */
1404 public final StatusHints getStatusHints() {
1405 return mStatusHints;
1406 }
1407
1408 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001409 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001410 * <p>
1411 * Extras should be updated using {@link #putExtras(Bundle)}.
1412 * <p>
1413 * Telecom or an {@link InCallService} can also update the extras via
1414 * {@link android.telecom.Call#putExtras(Bundle)}, and
1415 * {@link Call#removeExtras(List)}.
1416 * <p>
1417 * The connection is notified of changes to the extras made by Telecom or an
1418 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001419 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001420 * @return The extras associated with this connection.
1421 */
1422 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001423 Bundle extras = null;
1424 synchronized (mExtrasLock) {
1425 if (mExtras != null) {
1426 extras = new Bundle(mExtras);
1427 }
1428 }
1429 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001430 }
1431
1432 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001433 * Assign a listener to be notified of state changes.
1434 *
1435 * @param l A listener.
1436 * @return This Connection.
1437 *
1438 * @hide
1439 */
1440 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001441 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442 return this;
1443 }
1444
1445 /**
1446 * Remove a previously assigned listener that was being notified of state changes.
1447 *
1448 * @param l A Listener.
1449 * @return This Connection.
1450 *
1451 * @hide
1452 */
1453 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001454 if (l != null) {
1455 mListeners.remove(l);
1456 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001457 return this;
1458 }
1459
1460 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001461 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001462 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001463 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001464 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001465 }
1466
1467 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001468 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1469 * ONLY for debugging purposes.
1470 *
1471 * @param callId The telecom call ID.
1472 * @hide
1473 */
1474 public void setTelecomCallId(String callId) {
1475 mTelecomCallId = callId;
1476 }
1477
1478 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001479 * Inform this Connection that the state of its audio output has been changed externally.
1480 *
1481 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001482 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001483 */
Yorke Lee4af59352015-05-13 14:14:54 -07001484 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001485 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001486 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001487 mCallAudioState = state;
1488 onAudioStateChanged(getAudioState());
1489 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 }
1491
1492 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001494 * @return A string representation of the value.
1495 */
1496 public static String stateToString(int state) {
1497 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001499 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001501 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001503 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001504 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001505 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001506 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001507 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001509 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001510 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001511 return "DISCONNECTED";
1512 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001513 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001514 return "UNKNOWN";
1515 }
1516 }
1517
1518 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001519 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001520 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001521 public final int getConnectionCapabilities() {
1522 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001523 }
1524
1525 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001526 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1527 */
1528 public final int getConnectionProperties() {
1529 return mConnectionProperties;
1530 }
1531
1532 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001533 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001534 *
Andrew Lee100e2932014-09-08 15:34:24 -07001535 * @param address The new address.
1536 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001537 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001538 */
Andrew Lee100e2932014-09-08 15:34:24 -07001539 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001540 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001541 Log.d(this, "setAddress %s", address);
1542 mAddress = address;
1543 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001544 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001545 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001546 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001547 }
1548
1549 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001550 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001551 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001552 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001553 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001554 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001555 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001556 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001557 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001558 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001559 mCallerDisplayName = callerDisplayName;
1560 mCallerDisplayNamePresentation = presentation;
1561 for (Listener l : mListeners) {
1562 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1563 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001564 }
1565
1566 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001567 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001568 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1569 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1570 * {@link VideoProfile#STATE_TX_ENABLED},
1571 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001572 *
1573 * @param videoState The new video state.
1574 */
1575 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001576 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001577 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001578 mVideoState = videoState;
1579 for (Listener l : mListeners) {
1580 l.onVideoStateChanged(this, mVideoState);
1581 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001582 }
1583
1584 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001585 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001586 * communicate).
1587 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001588 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001589 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001590 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001592 }
1593
1594 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001595 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001596 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001597 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001598 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001600 }
1601
1602 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001603 * Sets state to initializing (this Connection is not yet ready to be used).
1604 */
1605 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001606 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001608 }
1609
1610 /**
1611 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1612 */
1613 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001614 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001616 }
1617
1618 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001619 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001620 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001621 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001622 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 }
1625
1626 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001627 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1628 * device). Only applicable for {@link Connection}s with
1629 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1630 */
1631 public final void setPulling() {
1632 checkImmutable();
1633 setState(STATE_PULLING_CALL);
1634 }
1635
1636 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001637 * Sets state to be on hold.
1638 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001639 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001640 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001642 }
1643
1644 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001645 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001647 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001649 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001650 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001651 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001652 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001653 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001654 }
1655
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001656 public final VideoProvider getVideoProvider() {
1657 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001658 }
1659
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001660 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001661 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001662 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001663 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001664 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001665 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001666 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001667 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001668 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001669 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001670 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001671 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001672 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001673 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001674 }
1675
1676 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1678 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1679 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1680 * to send an {@link #onPostDialContinue(boolean)} signal.
1681 *
1682 * @param remaining The DTMF character sequence remaining to be emitted once the
1683 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1684 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001685 */
1686 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001687 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001688 for (Listener l : mListeners) {
1689 l.onPostDialWait(this, remaining);
1690 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001691 }
1692
1693 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001694 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1695 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001696 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001697 *
1698 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001699 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001700 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001701 checkImmutable();
1702 for (Listener l : mListeners) {
1703 l.onPostDialChar(this, nextChar);
1704 }
1705 }
1706
1707 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001708 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001709 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001710 *
1711 * @param ringback Whether the ringback tone is to be played.
1712 */
Andrew Lee100e2932014-09-08 15:34:24 -07001713 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001714 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001715 if (mRingbackRequested != ringback) {
1716 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001717 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001718 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001719 }
1720 }
Ihab Awadf8358972014-05-28 16:46:42 -07001721 }
1722
1723 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001724 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001725 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001726 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001727 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001728 public final void setConnectionCapabilities(int connectionCapabilities) {
1729 checkImmutable();
1730 if (mConnectionCapabilities != connectionCapabilities) {
1731 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001732 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001733 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001734 }
1735 }
Santos Cordonb6939982014-06-04 20:20:58 -07001736 }
1737
1738 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001739 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1740 *
1741 * @param connectionProperties The new connection properties.
1742 */
1743 public final void setConnectionProperties(int connectionProperties) {
1744 checkImmutable();
1745 if (mConnectionProperties != connectionProperties) {
1746 mConnectionProperties = connectionProperties;
1747 for (Listener l : mListeners) {
1748 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1749 }
1750 }
1751 }
1752
1753 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001754 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001755 */
Evan Charlton36a71342014-07-19 16:31:02 -07001756 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001757 for (Listener l : mListeners) {
1758 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001759 }
Santos Cordonb6939982014-06-04 20:20:58 -07001760 }
1761
1762 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001763 * Requests that the framework use VOIP audio mode for this connection.
1764 *
1765 * @param isVoip True if the audio mode is VOIP.
1766 */
1767 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001768 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001769 mAudioModeIsVoip = isVoip;
1770 for (Listener l : mListeners) {
1771 l.onAudioModeIsVoipChanged(this, isVoip);
1772 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001773 }
1774
1775 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001776 * Sets the time at which a call became active on this Connection. This is set only
1777 * when a conference call becomes active on this connection.
1778 *
1779 * @param connectionTimeMillis The connection time, in milliseconds.
1780 *
1781 * @hide
1782 */
1783 public final void setConnectTimeMillis(long connectTimeMillis) {
1784 mConnectTimeMillis = connectTimeMillis;
1785 }
1786
1787 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001788 * Sets the label and icon status to display in the in-call UI.
1789 *
1790 * @param statusHints The status label and icon to set.
1791 */
1792 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001793 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001794 mStatusHints = statusHints;
1795 for (Listener l : mListeners) {
1796 l.onStatusHintsChanged(this, statusHints);
1797 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001798 }
1799
1800 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001801 * Sets the connections with which this connection can be conferenced.
1802 *
1803 * @param conferenceableConnections The set of connections this connection can conference with.
1804 */
1805 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001806 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001807 clearConferenceableList();
1808 for (Connection c : conferenceableConnections) {
1809 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1810 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001811 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001812 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001813 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001814 }
1815 }
1816 fireOnConferenceableConnectionsChanged();
1817 }
1818
1819 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001820 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1821 * or conferences with which this connection can be conferenced.
1822 *
1823 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001824 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001825 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001826 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001827 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001828 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1829 // small amount of items here.
1830 if (!mConferenceables.contains(c)) {
1831 if (c instanceof Connection) {
1832 Connection connection = (Connection) c;
1833 connection.addConnectionListener(mConnectionDeathListener);
1834 } else if (c instanceof Conference) {
1835 Conference conference = (Conference) c;
1836 conference.addListener(mConferenceDeathListener);
1837 }
1838 mConferenceables.add(c);
1839 }
1840 }
1841 fireOnConferenceableConnectionsChanged();
1842 }
1843
1844 /**
1845 * Returns the connections or conferences with which this connection can be conferenced.
1846 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001847 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001848 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001849 }
1850
Yorke Lee53463962015-08-04 16:07:19 -07001851 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001852 * @hide
1853 */
1854 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001855 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001856 if (mConnectionService != null) {
1857 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1858 "which is already associated with another ConnectionService.");
1859 } else {
1860 mConnectionService = connectionService;
1861 }
1862 }
1863
1864 /**
1865 * @hide
1866 */
1867 public final void unsetConnectionService(ConnectionService connectionService) {
1868 if (mConnectionService != connectionService) {
1869 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1870 "that does not belong to the ConnectionService.");
1871 } else {
1872 mConnectionService = null;
1873 }
1874 }
1875
1876 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001877 * @hide
1878 */
1879 public final ConnectionService getConnectionService() {
1880 return mConnectionService;
1881 }
1882
1883 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001884 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001885 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001886 *
1887 * @param conference The conference.
1888 * @return {@code true} if the conference was successfully set.
1889 * @hide
1890 */
1891 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001892 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001893 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001894 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001895 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001896 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1897 fireConferenceChanged();
1898 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001899 return true;
1900 }
1901 return false;
1902 }
1903
1904 /**
1905 * Resets the conference that this connection is a part of.
1906 * @hide
1907 */
1908 public final void resetConference() {
1909 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001910 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001911 mConference = null;
1912 fireConferenceChanged();
1913 }
1914 }
1915
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001916 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001917 * Set some extras that can be associated with this {@code Connection}.
1918 * <p>
1919 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1920 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1921 * <p>
1922 * 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 -07001923 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1924 *
1925 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001926 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1927 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001928 */
1929 public final void setExtras(@Nullable Bundle extras) {
1930 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001931
1932 // Add/replace any new or changed extras values.
1933 putExtras(extras);
1934
1935 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1936 // the current one and remove any keys that went away.
1937 if (mPreviousExtraKeys != null) {
1938 List<String> toRemove = new ArrayList<String>();
1939 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001940 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001941 toRemove.add(oldKey);
1942 }
1943 }
1944 if (!toRemove.isEmpty()) {
1945 removeExtras(toRemove);
1946 }
1947 }
1948
1949 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1950 // called we can see if the caller has removed any extras values.
1951 if (mPreviousExtraKeys == null) {
1952 mPreviousExtraKeys = new ArraySet<String>();
1953 }
1954 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001955 if (extras != null) {
1956 mPreviousExtraKeys.addAll(extras.keySet());
1957 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001958 }
1959
1960 /**
1961 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1962 * added.
1963 * <p>
1964 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1965 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1966 *
1967 * @param extras The extras to add.
1968 */
1969 public final void putExtras(@NonNull Bundle extras) {
1970 checkImmutable();
1971 if (extras == null) {
1972 return;
1973 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001974 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
1975 // the listeners.
1976 Bundle listenerExtras;
1977 synchronized (mExtrasLock) {
1978 if (mExtras == null) {
1979 mExtras = new Bundle();
1980 }
1981 mExtras.putAll(extras);
1982 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07001983 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001984 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001985 // Create a new clone of the extras for each listener so that they don't clobber
1986 // each other
1987 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07001988 }
1989 }
1990
1991 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001992 * Adds a boolean extra to this {@code Connection}.
1993 *
1994 * @param key The extra key.
1995 * @param value The value.
1996 * @hide
1997 */
1998 public final void putExtra(String key, boolean value) {
1999 Bundle newExtras = new Bundle();
2000 newExtras.putBoolean(key, value);
2001 putExtras(newExtras);
2002 }
2003
2004 /**
2005 * Adds an integer extra to this {@code Connection}.
2006 *
2007 * @param key The extra key.
2008 * @param value The value.
2009 * @hide
2010 */
2011 public final void putExtra(String key, int value) {
2012 Bundle newExtras = new Bundle();
2013 newExtras.putInt(key, value);
2014 putExtras(newExtras);
2015 }
2016
2017 /**
2018 * Adds a string extra to this {@code Connection}.
2019 *
2020 * @param key The extra key.
2021 * @param value The value.
2022 * @hide
2023 */
2024 public final void putExtra(String key, String value) {
2025 Bundle newExtras = new Bundle();
2026 newExtras.putString(key, value);
2027 putExtras(newExtras);
2028 }
2029
2030 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002031 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002032 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002033 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002034 */
2035 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002036 synchronized (mExtrasLock) {
2037 if (mExtras != null) {
2038 for (String key : keys) {
2039 mExtras.remove(key);
2040 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002041 }
2042 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002043 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002044 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002045 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002046 }
2047 }
2048
2049 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002050 * Removes extras from this {@code Connection}.
2051 *
2052 * @param keys The keys of the extras to remove.
2053 */
2054 public final void removeExtras(String ... keys) {
2055 removeExtras(Arrays.asList(keys));
2056 }
2057
2058 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002059 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002060 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002061 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002062 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2063 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002064 */
Yorke Lee4af59352015-05-13 14:14:54 -07002065 @SystemApi
2066 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002067 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002068
2069 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002070 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2071 *
2072 * @param state The new connection audio state.
2073 */
2074 public void onCallAudioStateChanged(CallAudioState state) {}
2075
2076 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002077 * Notifies this Connection of an internal state change. This method is called after the
2078 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002079 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002080 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002081 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002082 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002083
2084 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002085 * Notifies this Connection of a request to play a DTMF tone.
2086 *
2087 * @param c A DTMF character.
2088 */
Santos Cordonf2951102014-07-20 19:06:29 -07002089 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090
2091 /**
2092 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2093 */
Santos Cordonf2951102014-07-20 19:06:29 -07002094 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002095
2096 /**
2097 * Notifies this Connection of a request to disconnect.
2098 */
Santos Cordonf2951102014-07-20 19:06:29 -07002099 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002100
2101 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002102 * Notifies this Connection of a request to disconnect a participant of the conference managed
2103 * by the connection.
2104 *
2105 * @param endpoint the {@link Uri} of the participant to disconnect.
2106 * @hide
2107 */
2108 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2109
2110 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002111 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002112 */
Santos Cordonf2951102014-07-20 19:06:29 -07002113 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002114
2115 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116 * Notifies this Connection of a request to abort.
2117 */
Santos Cordonf2951102014-07-20 19:06:29 -07002118 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002119
2120 /**
2121 * Notifies this Connection of a request to hold.
2122 */
Santos Cordonf2951102014-07-20 19:06:29 -07002123 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002124
2125 /**
2126 * Notifies this Connection of a request to exit a hold state.
2127 */
Santos Cordonf2951102014-07-20 19:06:29 -07002128 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002129
2130 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002132 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002133 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002134 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 */
Santos Cordonf2951102014-07-20 19:06:29 -07002136 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002137
2138 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002139 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002140 * a request to accept.
2141 */
2142 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002143 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002144 }
2145
2146 /**
2147 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002148 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002149 */
Santos Cordonf2951102014-07-20 19:06:29 -07002150 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002151
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002152 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002153 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2154 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002155 */
2156 public void onReject(String replyMessage) {}
2157
2158 /**
Bryce Leecac50772015-11-17 15:13:29 -08002159 * Notifies the Connection of a request to silence the ringer.
2160 *
2161 * @hide
2162 */
2163 public void onSilence() {}
2164
2165 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002166 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2167 */
Santos Cordonf2951102014-07-20 19:06:29 -07002168 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002169
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002170 /**
2171 * Notifies this Connection of a request to pull an external call to the local device.
2172 * <p>
2173 * The {@link InCallService} issues a request to pull an external call to the local device via
2174 * {@link Call#pullExternalCall()}.
2175 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002176 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2177 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002178 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002179 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002180 */
2181 public void onPullExternalCall() {}
2182
2183 /**
2184 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2185 * <p>
2186 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2187 * <p>
2188 * See also {@link Call#sendCallEvent(String, Bundle)}.
2189 *
2190 * @param event The call event.
2191 * @param extras Extras associated with the call event.
2192 */
2193 public void onCallEvent(String event, Bundle extras) {}
2194
Tyler Gunndee56a82016-03-23 16:06:34 -07002195 /**
2196 * Notifies this {@link Connection} of a change to the extras made outside the
2197 * {@link ConnectionService}.
2198 * <p>
2199 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2200 * the {@link android.telecom.Call#putExtras(Bundle)} and
2201 * {@link Call#removeExtras(List)}.
2202 *
2203 * @param extras The new extras bundle.
2204 */
2205 public void onExtrasChanged(Bundle extras) {}
2206
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002207 static String toLogSafePhoneNumber(String number) {
2208 // For unknown number, log empty string.
2209 if (number == null) {
2210 return "";
2211 }
2212
2213 if (PII_DEBUG) {
2214 // When PII_DEBUG is true we emit PII.
2215 return number;
2216 }
2217
2218 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2219 // sanitized phone numbers.
2220 StringBuilder builder = new StringBuilder();
2221 for (int i = 0; i < number.length(); i++) {
2222 char c = number.charAt(i);
2223 if (c == '-' || c == '@' || c == '.') {
2224 builder.append(c);
2225 } else {
2226 builder.append('x');
2227 }
2228 }
2229 return builder.toString();
2230 }
2231
Ihab Awad542e0ea2014-05-16 10:22:16 -07002232 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002233 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002234 if (mState == STATE_DISCONNECTED && mState != state) {
2235 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002236 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002237 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002238 if (mState != state) {
2239 Log.d(this, "setState: %s", stateToString(state));
2240 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002241 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002242 for (Listener l : mListeners) {
2243 l.onStateChanged(this, state);
2244 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002245 }
2246 }
2247
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002248 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002249 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002250 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2251 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002252 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002253 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002254
2255 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002256 if (mImmutable) {
2257 throw new UnsupportedOperationException("Connection is immutable");
2258 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002259 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002260 }
2261
Evan Charltonbf11f982014-07-20 22:06:28 -07002262 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002263 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002264 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2265 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002266 * <p>
2267 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2268 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002269 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002270 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002271 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002272 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002273 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2274 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002275 }
2276
Evan Charltonbf11f982014-07-20 22:06:28 -07002277 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002278 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2279 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2280 * this should never be un-@hide-den.
2281 *
2282 * @hide
2283 */
2284 public void checkImmutable() {}
2285
2286 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002287 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2288 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2289 * that state. This connection should not be used for anything, and no other
2290 * {@code Connection}s should be attempted.
2291 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002292 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002293 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002294 * @return A {@code Connection} which indicates that the underlying connection should
2295 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002296 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002297 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002298 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002299 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002300
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002301 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002302 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002303 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002304 }
2305 }
2306
Santos Cordon823fd3c2014-08-07 18:35:18 -07002307 private final void fireConferenceChanged() {
2308 for (Listener l : mListeners) {
2309 l.onConferenceChanged(this, mConference);
2310 }
2311 }
2312
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002313 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002314 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002315 if (c instanceof Connection) {
2316 Connection connection = (Connection) c;
2317 connection.removeConnectionListener(mConnectionDeathListener);
2318 } else if (c instanceof Conference) {
2319 Conference conference = (Conference) c;
2320 conference.removeListener(mConferenceDeathListener);
2321 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002322 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002323 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002324 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002325
2326 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002327 * Handles a change to extras received from Telecom.
2328 *
2329 * @param extras The new extras.
2330 * @hide
2331 */
2332 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002333 Bundle b = null;
2334 synchronized (mExtrasLock) {
2335 mExtras = extras;
2336 if (mExtras != null) {
2337 b = new Bundle(mExtras);
2338 }
2339 }
2340 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002341 }
2342
2343 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002344 * Notifies listeners that the merge request failed.
2345 *
2346 * @hide
2347 */
2348 protected final void notifyConferenceMergeFailed() {
2349 for (Listener l : mListeners) {
2350 l.onConferenceMergeFailed(this);
2351 }
2352 }
2353
2354 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002355 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002356 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002357 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002358 * @hide
2359 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002360 protected final void updateConferenceParticipants(
2361 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002362 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002363 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002364 }
2365 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002366
2367 /**
2368 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002369 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002370 */
2371 protected void notifyConferenceStarted() {
2372 for (Listener l : mListeners) {
2373 l.onConferenceStarted();
2374 }
2375 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002376
2377 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002378 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2379 * be a part of a conference call.
2380 * @param isConferenceSupported {@code true} if the connection supports being part of a
2381 * conference call, {@code false} otherwise.
2382 * @hide
2383 */
2384 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2385 for (Listener l : mListeners) {
2386 l.onConferenceSupportedChanged(this, isConferenceSupported);
2387 }
2388 }
2389
2390 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002391 * Sends an event associated with this {@code Connection}, with associated event extras.
2392 *
2393 * Events are exposed to {@link InCallService} implementations via the
2394 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2395 *
2396 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2397 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002398 *
2399 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002400 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002401 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002402 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002403 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002404 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002405 }
2406 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002407}