blob: 52f75f680560c82e7310a80df3bddcb99b2fe8b9 [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.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070056 * <p>
57 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
58 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
59 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
60 * {@code Connection} instance.
61 * <p>
62 * Basic call support requires overriding the following methods: {@link #onAnswer()},
63 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
64 * <p>
65 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
66 * {@link #onUnhold()} methods should be overridden to provide hold support for the
67 * {@code Connection}.
68 * <p>
69 * Where a {@code Connection} supports a variation of video calling (e.g. the
70 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
71 * to support answering a call as a video call.
72 * <p>
73 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
74 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
75 * support for pulling the external call.
76 * <p>
77 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
78 * overridden.
79 * <p>
80 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
81 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
82 * for example, call events from a {@link InCallService} are handled,
83 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
84 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
85 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
86 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070087 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070088public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070089
Santos Cordon895d4b82015-06-25 16:41:48 -070090 /**
91 * The connection is initializing. This is generally the first state for a {@code Connection}
92 * returned by a {@link ConnectionService}.
93 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070094 public static final int STATE_INITIALIZING = 0;
95
Santos Cordon895d4b82015-06-25 16:41:48 -070096 /**
97 * The connection is new and not connected.
98 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 public static final int STATE_NEW = 1;
100
Santos Cordon895d4b82015-06-25 16:41:48 -0700101 /**
102 * An incoming connection is in the ringing state. During this state, the user's ringer or
103 * vibration feature will be activated.
104 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 public static final int STATE_RINGING = 2;
106
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 /**
108 * An outgoing connection is in the dialing state. In this state the other party has not yet
109 * answered the call and the user traditionally hears a ringback tone.
110 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700111 public static final int STATE_DIALING = 3;
112
Santos Cordon895d4b82015-06-25 16:41:48 -0700113 /**
114 * A connection is active. Both parties are connected to the call and can actively communicate.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_ACTIVE = 4;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * A connection is on hold.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_HOLDING = 5;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * A connection has been disconnected. This is the final state once the user has been
125 * disconnected from a call either locally, remotely or by an error in the service.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_DISCONNECTED = 6;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700130 * The state of an external connection which is in the process of being pulled from a remote
131 * device to the local device.
132 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700133 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700134 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
135 */
136 public static final int STATE_PULLING_CALL = 7;
137
138 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 * Connection can currently be put on hold or unheld. This is distinct from
140 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
141 * it does not at the moment support the function. This can be true while the call is in the
142 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
143 * display a disabled 'hold' button.
144 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145 public static final int CAPABILITY_HOLD = 0x00000001;
146
147 /** Connection supports the hold feature. */
148 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
149
150 /**
151 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
152 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
153 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
154 * capability allows a merge button to be shown while the conference is in the foreground
155 * of the in-call UI.
156 * <p>
157 * This is only intended for use by a {@link Conference}.
158 */
159 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
160
161 /**
162 * Connections within a conference can be swapped between foreground and background.
163 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
164 * <p>
165 * This is only intended for use by a {@link Conference}.
166 */
167 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
168
169 /**
170 * @hide
171 */
172 public static final int CAPABILITY_UNUSED = 0x00000010;
173
174 /** Connection supports responding via text option. */
175 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
176
177 /** Connection can be muted. */
178 public static final int CAPABILITY_MUTE = 0x00000040;
179
180 /**
181 * Connection supports conference management. This capability only applies to
182 * {@link Conference}s which can have {@link Connection}s as children.
183 */
184 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
185
186 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700187 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800188 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700189 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800190
191 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700192 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700194 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800195
196 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700199 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700200 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
206
207 /**
208 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 */
210 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
211
212 /**
213 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700215 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217
218 /**
219 * Connection is able to be separated from its parent {@code Conference}, if any.
220 */
221 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
222
223 /**
224 * Connection is able to be individually disconnected when in a {@code Conference}.
225 */
226 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
227
228 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700229 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800230 * @hide
231 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700232 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800233
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700234 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700235 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700236 * @hide
237 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700238 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700239
240 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700241 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700242 * @hide
243 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245
Tyler Gunn068085b2015-02-06 13:56:52 -0800246 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800248 * @hide
249 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800251
Tyler Gunn96d6c402015-03-18 12:39:23 -0700252 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500253 * Speed up audio setup for MT call.
254 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700255 */
256 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800257
Rekha Kumar07366812015-03-24 16:42:31 -0700258 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700259 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700260 */
261 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
262
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700263 /**
264 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700265 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700266 */
267 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
268
Tyler Gunnd4091732015-06-29 09:15:37 -0700269 /**
270 * For a conference, indicates the conference will not have child connections.
271 * <p>
272 * An example of a conference with child connections is a GSM conference call, where the radio
273 * retains connections to the individual participants of the conference. Another example is an
274 * IMS conference call where conference event package functionality is supported; in this case
275 * the conference server ensures the radio is aware of the participants in the conference, which
276 * are represented by child connections.
277 * <p>
278 * An example of a conference with no child connections is an IMS conference call with no
279 * conference event package support. Such a conference is represented by the radio as a single
280 * connection to the IMS conference server.
281 * <p>
282 * Indicating whether a conference has children or not is important to help user interfaces
283 * visually represent a conference. A conference with no children, for example, will have the
284 * conference connection shown in the list of calls on a Bluetooth device, where if the
285 * conference has children, only the children will be shown in the list of calls on a Bluetooth
286 * device.
287 * @hide
288 */
289 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
290
Bryce Lee81901682015-08-28 16:38:02 -0700291 /**
292 * Indicates that the connection itself wants to handle any sort of reply response, rather than
293 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700294 */
295 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
296
Tyler Gunnf97a0092016-01-19 15:59:34 -0800297 /**
298 * When set, prevents a video call from being downgraded to an audio-only call.
299 * <p>
300 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
301 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
302 * downgraded from a video call back to a VideoState of
303 * {@link VideoProfile#STATE_AUDIO_ONLY}.
304 * <p>
305 * Intuitively, a call which can be downgraded to audio should also have local and remote
306 * video
307 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
308 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
309 */
310 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
311
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700312 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700313 * When set for an external connection, indicates that this {@code Connection} can be pulled
314 * from a remote device to the current device.
315 * <p>
316 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
317 * is set.
318 */
319 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
320
321 //**********************************************************************************************
322 // Next CAPABILITY value: 0x02000000
323 //**********************************************************************************************
324
325 /**
326 * Indicates that the current device callback number should be shown.
327 *
328 * @hide
329 */
330 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
331
332 /**
333 * Whether the call is a generic conference, where we do not know the precise state of
334 * participants in the conference (eg. on CDMA).
335 *
336 * @hide
337 */
338 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
339
340 /**
341 * Connection is using high definition audio.
342 * @hide
343 */
344 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
345
346 /**
347 * Connection is using WIFI.
348 * @hide
349 */
350 public static final int PROPERTY_WIFI = 1<<3;
351
352 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700353 * When set, indicates that the {@code Connection} does not actually exist locally for the
354 * {@link ConnectionService}.
355 * <p>
356 * Consider, for example, a scenario where a user has two devices with the same phone number.
357 * When a user places a call on one devices, the telephony stack can represent that call on the
358 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700359 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700360 * <p>
361 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
362 * external connections. Only those {@link InCallService}s which have the
363 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
364 * manifest will see external connections.
365 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700366 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367
Brad Ebinger15847072016-05-18 11:08:36 -0700368 /**
369 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
370 */
371 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700372
Tyler Gunn96d6c402015-03-18 12:39:23 -0700373 //**********************************************************************************************
Brad Ebinger15847072016-05-18 11:08:36 -0700374 // Next PROPERTY value: 1<<6
Tyler Gunn96d6c402015-03-18 12:39:23 -0700375 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800376
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700377 /**
378 * Connection extra key used to store the last forwarded number associated with the current
379 * connection. Used to communicate to the user interface that the connection was forwarded via
380 * the specified number.
381 */
382 public static final String EXTRA_LAST_FORWARDED_NUMBER =
383 "android.telecom.extra.LAST_FORWARDED_NUMBER";
384
385 /**
386 * Connection extra key used to store a child number associated with the current connection.
387 * Used to communicate to the user interface that the connection was received via
388 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
389 * address.
390 */
391 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
392
393 /**
394 * Connection extra key used to store the subject for an incoming call. The user interface can
395 * query this extra and display its contents for incoming calls. Will only be used if the
396 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
397 */
398 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
399
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800400 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700401 * Boolean connection extra key set on a {@link Connection} in
402 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
403 * current active foreground call to be dropped.
404 */
405 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
406 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
407
408 /**
Hall Liu10208662016-06-15 17:55:00 -0700409 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700410 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700411 * @hide
412 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700413 public static final String EXTRA_DISABLE_ADD_CALL =
414 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700415
416 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800417 * Connection event used to inform Telecom that it should play the on hold tone. This is used
418 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700419 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800420 * @hide
421 */
422 public static final String EVENT_ON_HOLD_TONE_START =
423 "android.telecom.event.ON_HOLD_TONE_START";
424
425 /**
426 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
427 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700428 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800429 * @hide
430 */
431 public static final String EVENT_ON_HOLD_TONE_END =
432 "android.telecom.event.ON_HOLD_TONE_END";
433
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700434 /**
435 * Connection event used to inform {@link InCallService}s when pulling of an external call has
436 * failed. The user interface should inform the user of the error.
437 * <p>
438 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
439 * API is called on a {@link Call} with the properties
440 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
441 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
442 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700443 * <p>
444 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
445 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700446 */
447 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
448
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700449 /**
450 * Connection event used to inform {@link InCallService}s when the merging of two calls has
451 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700452 * <p>
453 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
454 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700455 */
456 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
457
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 // Flag controlling whether PII is emitted into the logs
459 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
460
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800461 /**
462 * Whether the given capabilities support the specified capability.
463 *
464 * @param capabilities A capability bit field.
465 * @param capability The capability to check capabilities for.
466 * @return Whether the specified capability is supported.
467 * @hide
468 */
469 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800470 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800471 }
472
473 /**
474 * Whether the capabilities of this {@code Connection} supports the specified capability.
475 *
476 * @param capability The capability to check capabilities for.
477 * @return Whether the specified capability is supported.
478 * @hide
479 */
480 public boolean can(int capability) {
481 return can(mConnectionCapabilities, capability);
482 }
483
484 /**
485 * Removes the specified capability from the set of capabilities of this {@code Connection}.
486 *
487 * @param capability The capability to remove from the set.
488 * @hide
489 */
490 public void removeCapability(int capability) {
491 mConnectionCapabilities &= ~capability;
492 }
493
494 /**
495 * Adds the specified capability to the set of capabilities of this {@code Connection}.
496 *
497 * @param capability The capability to add to the set.
498 * @hide
499 */
500 public void addCapability(int capability) {
501 mConnectionCapabilities |= capability;
502 }
503
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700504 /**
505 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
506 *
507 * @param capabilities A capability bit field.
508 * @return A human readable string representation.
509 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800510 public static String capabilitiesToString(int capabilities) {
511 StringBuilder builder = new StringBuilder();
512 builder.append("[Capabilities:");
513 if (can(capabilities, CAPABILITY_HOLD)) {
514 builder.append(" CAPABILITY_HOLD");
515 }
516 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
517 builder.append(" CAPABILITY_SUPPORT_HOLD");
518 }
519 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
520 builder.append(" CAPABILITY_MERGE_CONFERENCE");
521 }
522 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
523 builder.append(" CAPABILITY_SWAP_CONFERENCE");
524 }
525 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
526 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
527 }
528 if (can(capabilities, CAPABILITY_MUTE)) {
529 builder.append(" CAPABILITY_MUTE");
530 }
531 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
532 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
533 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700534 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
535 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
536 }
537 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
538 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
539 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700540 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
541 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800542 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700543 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
544 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
545 }
546 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
547 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
548 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700549 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
550 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800551 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800552 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
553 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
554 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500555 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700556 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500557 }
Rekha Kumar07366812015-03-24 16:42:31 -0700558 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
559 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
560 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700561 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
562 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
563 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700564 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
565 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
566 }
Bryce Lee81901682015-08-28 16:38:02 -0700567 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
568 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
569 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700570 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
571 builder.append(" CAPABILITY_CAN_PULL_CALL");
572 }
Bryce Lee81901682015-08-28 16:38:02 -0700573
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800574 builder.append("]");
575 return builder.toString();
576 }
577
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700578 /**
579 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
580 *
581 * @param properties A property bit field.
582 * @return A human readable string representation.
583 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700584 public static String propertiesToString(int properties) {
585 StringBuilder builder = new StringBuilder();
586 builder.append("[Properties:");
587
588 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
589 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
590 }
591
592 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
593 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
594 }
595
596 if (can(properties, PROPERTY_WIFI)) {
597 builder.append(" PROPERTY_WIFI");
598 }
599
600 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
601 builder.append(" PROPERTY_GENERIC_CONFERENCE");
602 }
603
604 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
605 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
606 }
607
Brad Ebinger15847072016-05-18 11:08:36 -0700608 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
609 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
610 }
611
Tyler Gunn720c6642016-03-22 09:02:47 -0700612 builder.append("]");
613 return builder.toString();
614 }
615
Sailesh Nepal091768c2014-06-30 15:15:23 -0700616 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700617 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700618 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700619 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700620 public void onCallerDisplayNameChanged(
621 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700622 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700623 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700624 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800625 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700626 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700627 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800628 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700629 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 public void onVideoProviderChanged(
631 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700632 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
633 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800634 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700635 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700636 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700637 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800638 public void onConferenceParticipantsChanged(Connection c,
639 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800640 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700641 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700642 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700643 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700644 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700645 /** @hide */
646 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700647 }
648
Tyler Gunnb702ef82015-05-29 11:51:53 -0700649 /**
650 * Provides a means of controlling the video session associated with a {@link Connection}.
651 * <p>
652 * Implementations create a custom subclass of {@link VideoProvider} and the
653 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
654 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
655 * should set the {@link VideoProvider}.
656 * <p>
657 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
658 * {@link InCallService} implementations to issue requests related to the video session;
659 * it provides a means for the {@link ConnectionService} to report events and information
660 * related to the video session to Telecom and the {@link InCallService} implementations.
661 * <p>
662 * {@link InCallService} implementations interact with the {@link VideoProvider} via
663 * {@link android.telecom.InCallService.VideoCall}.
664 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700666
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 /**
668 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700669 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 */
671 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700672
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700673 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700674 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
675 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 */
677 public static final int SESSION_EVENT_RX_RESUME = 2;
678
679 /**
680 * Video transmission has begun. This occurs after a negotiated start of video transmission
681 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700682 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683 */
684 public static final int SESSION_EVENT_TX_START = 3;
685
686 /**
687 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
688 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700689 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690 */
691 public static final int SESSION_EVENT_TX_STOP = 4;
692
693 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700694 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
695 * this as a cue to inform the user the camera is not available.
696 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697 */
698 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
699
700 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700701 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
702 * for operation. The {@link InCallService} can use this as a cue to inform the user that
703 * the camera has become available again.
704 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 */
706 public static final int SESSION_EVENT_CAMERA_READY = 6;
707
708 /**
709 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700710 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 */
712 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
713
714 /**
715 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700716 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700717 */
718 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
719
720 /**
721 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700722 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 */
724 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
725
Rekha Kumar07366812015-03-24 16:42:31 -0700726 /**
727 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700728 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700729 */
730 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
731
732 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700733 * Session modify request rejected by remote user.
734 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700735 */
736 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
737
Tyler Gunn75958422015-04-15 14:23:42 -0700738 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 private static final int MSG_SET_CAMERA = 2;
740 private static final int MSG_SET_PREVIEW_SURFACE = 3;
741 private static final int MSG_SET_DISPLAY_SURFACE = 4;
742 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
743 private static final int MSG_SET_ZOOM = 6;
744 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
745 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
746 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800747 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700749 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700751 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700753
754 /**
755 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700756 *
757 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
758 * load factor before resizing, 1 means we only expect a single thread to
759 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700760 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700761 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
762 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700763
764 /**
765 * Default handler used to consolidate binder method calls onto a single thread.
766 */
767 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700768 public VideoProviderHandler() {
769 super();
770 }
771
772 public VideoProviderHandler(Looper looper) {
773 super(looper);
774 }
775
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 @Override
777 public void handleMessage(Message msg) {
778 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700779 case MSG_ADD_VIDEO_CALLBACK: {
780 IBinder binder = (IBinder) msg.obj;
781 IVideoCallback callback = IVideoCallback.Stub
782 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700783 if (callback == null) {
784 Log.w(this, "addVideoProvider - skipped; callback is null.");
785 break;
786 }
787
Tyler Gunn75958422015-04-15 14:23:42 -0700788 if (mVideoCallbacks.containsKey(binder)) {
789 Log.i(this, "addVideoProvider - skipped; already present.");
790 break;
791 }
792 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700793 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700794 }
795 case MSG_REMOVE_VIDEO_CALLBACK: {
796 IBinder binder = (IBinder) msg.obj;
797 IVideoCallback callback = IVideoCallback.Stub
798 .asInterface((IBinder) msg.obj);
799 if (!mVideoCallbacks.containsKey(binder)) {
800 Log.i(this, "removeVideoProvider - skipped; not present.");
801 break;
802 }
803 mVideoCallbacks.remove(binder);
804 break;
805 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 case MSG_SET_CAMERA:
807 onSetCamera((String) msg.obj);
808 break;
809 case MSG_SET_PREVIEW_SURFACE:
810 onSetPreviewSurface((Surface) msg.obj);
811 break;
812 case MSG_SET_DISPLAY_SURFACE:
813 onSetDisplaySurface((Surface) msg.obj);
814 break;
815 case MSG_SET_DEVICE_ORIENTATION:
816 onSetDeviceOrientation(msg.arg1);
817 break;
818 case MSG_SET_ZOOM:
819 onSetZoom((Float) msg.obj);
820 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700821 case MSG_SEND_SESSION_MODIFY_REQUEST: {
822 SomeArgs args = (SomeArgs) msg.obj;
823 try {
824 onSendSessionModifyRequest((VideoProfile) args.arg1,
825 (VideoProfile) args.arg2);
826 } finally {
827 args.recycle();
828 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700830 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 case MSG_SEND_SESSION_MODIFY_RESPONSE:
832 onSendSessionModifyResponse((VideoProfile) msg.obj);
833 break;
834 case MSG_REQUEST_CAMERA_CAPABILITIES:
835 onRequestCameraCapabilities();
836 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800837 case MSG_REQUEST_CONNECTION_DATA_USAGE:
838 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 break;
840 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700841 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700842 break;
843 default:
844 break;
845 }
846 }
847 }
848
849 /**
850 * IVideoProvider stub implementation.
851 */
852 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700853 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700854 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700855 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
856 }
857
858 public void removeVideoCallback(IBinder videoCallbackBinder) {
859 mMessageHandler.obtainMessage(
860 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700861 }
862
863 public void setCamera(String cameraId) {
864 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
865 }
866
867 public void setPreviewSurface(Surface surface) {
868 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
869 }
870
871 public void setDisplaySurface(Surface surface) {
872 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
873 }
874
875 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700876 mMessageHandler.obtainMessage(
877 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700878 }
879
880 public void setZoom(float value) {
881 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
882 }
883
Tyler Gunn45382162015-05-06 08:52:27 -0700884 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
885 SomeArgs args = SomeArgs.obtain();
886 args.arg1 = fromProfile;
887 args.arg2 = toProfile;
888 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 }
890
891 public void sendSessionModifyResponse(VideoProfile responseProfile) {
892 mMessageHandler.obtainMessage(
893 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
894 }
895
896 public void requestCameraCapabilities() {
897 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
898 }
899
900 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800901 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 }
903
Yorke Lee32f24732015-05-12 16:18:03 -0700904 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
906 }
907 }
908
909 public VideoProvider() {
910 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700911 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700912 }
913
914 /**
915 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
916 *
917 * @param looper The looper.
918 * @hide
919 */
920 public VideoProvider(Looper looper) {
921 mBinder = new VideoProvider.VideoProviderBinder();
922 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700923 }
924
925 /**
926 * Returns binder object which can be used across IPC methods.
927 * @hide
928 */
929 public final IVideoProvider getInterface() {
930 return mBinder;
931 }
932
933 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 * Sets the camera to be used for the outgoing video.
935 * <p>
936 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
937 * camera via
938 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
939 * <p>
940 * Sent from the {@link InCallService} via
941 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * @param cameraId The id of the camera (use ids as reported by
944 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 */
946 public abstract void onSetCamera(String cameraId);
947
948 /**
949 * Sets the surface to be used for displaying a preview of what the user's camera is
950 * currently capturing. When video transmission is enabled, this is the video signal which
951 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700952 * <p>
953 * Sent from the {@link InCallService} via
954 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700956 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700957 */
958 public abstract void onSetPreviewSurface(Surface surface);
959
960 /**
961 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700962 * <p>
963 * Sent from the {@link InCallService} via
964 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 */
968 public abstract void onSetDisplaySurface(Surface surface);
969
970 /**
971 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
972 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700973 * <p>
974 * Sent from the {@link InCallService} via
975 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 *
977 * @param rotation The device orientation, in degrees.
978 */
979 public abstract void onSetDeviceOrientation(int rotation);
980
981 /**
982 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700983 * <p>
984 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700985 *
986 * @param value The camera zoom ratio.
987 */
988 public abstract void onSetZoom(float value);
989
990 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700991 * Issues a request to modify the properties of the current video session.
992 * <p>
993 * Example scenarios include: requesting an audio-only call to be upgraded to a
994 * bi-directional video call, turning on or off the user's camera, sending a pause signal
995 * when the {@link InCallService} is no longer the foreground application.
996 * <p>
997 * If the {@link VideoProvider} determines a request to be invalid, it should call
998 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
999 * invalid request back to the {@link InCallService}.
1000 * <p>
1001 * Where a request requires confirmation from the user of the peer device, the
1002 * {@link VideoProvider} must communicate the request to the peer device and handle the
1003 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1004 * is used to inform the {@link InCallService} of the result of the request.
1005 * <p>
1006 * Sent from the {@link InCallService} via
1007 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001009 * @param fromProfile The video profile prior to the request.
1010 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
Tyler Gunn45382162015-05-06 08:52:27 -07001012 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1013 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 /**
1016 * Provides a response to a request to change the current video session properties.
1017 * <p>
1018 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1019 * video call, could decline the request and keep the call as audio-only.
1020 * In such a scenario, the {@code responseProfile} would have a video state of
1021 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1022 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1023 * <p>
1024 * Sent from the {@link InCallService} via
1025 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1026 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1027 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001028 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001029 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001030 */
1031 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1032
1033 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001034 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1035 * <p>
1036 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1037 * camera via
1038 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1039 * <p>
1040 * Sent from the {@link InCallService} via
1041 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001042 */
1043 public abstract void onRequestCameraCapabilities();
1044
1045 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001046 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1047 * video component of the current {@link Connection}.
1048 * <p>
1049 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1050 * via {@link VideoProvider#setCallDataUsage(long)}.
1051 * <p>
1052 * Sent from the {@link InCallService} via
1053 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001055 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056
1057 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001058 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1059 * the peer device when the video signal is paused.
1060 * <p>
1061 * Sent from the {@link InCallService} via
1062 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 *
1064 * @param uri URI of image to display.
1065 */
Yorke Lee32f24732015-05-12 16:18:03 -07001066 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001067
1068 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001069 * Used to inform listening {@link InCallService} implementations when the
1070 * {@link VideoProvider} receives a session modification request.
1071 * <p>
1072 * Received by the {@link InCallService} via
1073 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * @param videoProfile The requested video profile.
1076 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 */
1078 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001079 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001080 for (IVideoCallback callback : mVideoCallbacks.values()) {
1081 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001082 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001083 } catch (RemoteException ignored) {
1084 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001085 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 }
1087 }
1088 }
1089
1090 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001091 * Used to inform listening {@link InCallService} implementations when the
1092 * {@link VideoProvider} receives a response to a session modification request.
1093 * <p>
1094 * Received by the {@link InCallService} via
1095 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1096 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 *
1098 * @param status Status of the session modify request. Valid values are
1099 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1100 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001101 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1102 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1103 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1104 * @param requestedProfile The original request which was sent to the peer device.
1105 * @param responseProfile The actual profile changes agreed to by the peer device.
1106 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 */
1108 public void receiveSessionModifyResponse(int status,
1109 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001110 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001111 for (IVideoCallback callback : mVideoCallbacks.values()) {
1112 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001113 callback.receiveSessionModifyResponse(status, requestedProfile,
1114 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001115 } catch (RemoteException ignored) {
1116 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001117 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 }
1119 }
1120 }
1121
1122 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001123 * Used to inform listening {@link InCallService} implementations when the
1124 * {@link VideoProvider} reports a call session event.
1125 * <p>
1126 * Received by the {@link InCallService} via
1127 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1130 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1131 * {@link VideoProvider#SESSION_EVENT_TX_START},
1132 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1133 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1134 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001135 */
1136 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001137 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001138 for (IVideoCallback callback : mVideoCallbacks.values()) {
1139 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001140 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001141 } catch (RemoteException ignored) {
1142 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001143 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144 }
1145 }
1146 }
1147
1148 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001149 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1150 * peer's video have changed.
1151 * <p>
1152 * This could occur if, for example, the peer rotates their device, changing the aspect
1153 * ratio of the video, or if the user switches between the back and front cameras.
1154 * <p>
1155 * Received by the {@link InCallService} via
1156 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001157 *
1158 * @param width The updated peer video width.
1159 * @param height The updated peer video height.
1160 */
1161 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001162 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001163 for (IVideoCallback callback : mVideoCallbacks.values()) {
1164 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001165 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001166 } catch (RemoteException ignored) {
1167 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001168 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001169 }
1170 }
1171 }
1172
1173 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001174 * Used to inform listening {@link InCallService} implementations when the data usage of the
1175 * video associated with the current {@link Connection} has changed.
1176 * <p>
1177 * This could be in response to a preview request via
1178 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001179 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1180 * 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 -07001181 * <p>
1182 * Received by the {@link InCallService} via
1183 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001185 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1186 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001187 */
Yorke Lee32f24732015-05-12 16:18:03 -07001188 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001189 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001190 for (IVideoCallback callback : mVideoCallbacks.values()) {
1191 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001192 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001193 } catch (RemoteException ignored) {
1194 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001195 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001196 }
1197 }
1198 }
1199
1200 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001201 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001203 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001204 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1205 * @hide
1206 */
1207 public void changeCallDataUsage(long dataUsage) {
1208 setCallDataUsage(dataUsage);
1209 }
1210
1211 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001212 * Used to inform listening {@link InCallService} implementations when the capabilities of
1213 * the current camera have changed.
1214 * <p>
1215 * The {@link VideoProvider} should call this in response to
1216 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1217 * changed via {@link VideoProvider#onSetCamera(String)}.
1218 * <p>
1219 * Received by the {@link InCallService} via
1220 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1221 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001222 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001223 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 */
Yorke Lee400470f2015-05-12 13:31:25 -07001225 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001226 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001227 for (IVideoCallback callback : mVideoCallbacks.values()) {
1228 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001229 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001230 } catch (RemoteException ignored) {
1231 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001232 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 }
1234 }
1235 }
Rekha Kumar07366812015-03-24 16:42:31 -07001236
1237 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001238 * Used to inform listening {@link InCallService} implementations when the video quality
1239 * of the call has changed.
1240 * <p>
1241 * Received by the {@link InCallService} via
1242 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001243 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001244 * @param videoQuality The updated video quality. Valid values:
1245 * {@link VideoProfile#QUALITY_HIGH},
1246 * {@link VideoProfile#QUALITY_MEDIUM},
1247 * {@link VideoProfile#QUALITY_LOW},
1248 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001249 */
1250 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001251 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001252 for (IVideoCallback callback : mVideoCallbacks.values()) {
1253 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001254 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001255 } catch (RemoteException ignored) {
1256 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001257 }
Rekha Kumar07366812015-03-24 16:42:31 -07001258 }
1259 }
1260 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001261 }
1262
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001263 private final Listener mConnectionDeathListener = new Listener() {
1264 @Override
1265 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001266 if (mConferenceables.remove(c)) {
1267 fireOnConferenceableConnectionsChanged();
1268 }
1269 }
1270 };
1271
1272 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1273 @Override
1274 public void onDestroyed(Conference c) {
1275 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001276 fireOnConferenceableConnectionsChanged();
1277 }
1278 }
1279 };
1280
Jay Shrauner229e3822014-08-15 09:23:07 -07001281 /**
1282 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1283 * load factor before resizing, 1 means we only expect a single thread to
1284 * access the map so make only a single shard
1285 */
1286 private final Set<Listener> mListeners = Collections.newSetFromMap(
1287 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001288 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1289 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001290 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001291
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001292 // The internal telecom call ID associated with this connection.
1293 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001295 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001296 private Uri mAddress;
1297 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001298 private String mCallerDisplayName;
1299 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001300 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001301 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001302 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001304 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001305 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001306 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001307 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001308 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001309 private Conference mConference;
1310 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001311 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001312 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001313
1314 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001315 * Tracks the key set for the extras bundle provided on the last invocation of
1316 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1317 * keys which were set previously but are no longer present in the replacement Bundle.
1318 */
1319 private Set<String> mPreviousExtraKeys;
1320
1321 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001322 * Create a new Connection.
1323 */
Santos Cordonf2951102014-07-20 19:06:29 -07001324 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001325
1326 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001327 * Returns the Telecom internal call ID associated with this connection. Should only be used
1328 * for debugging and tracing purposes.
1329 *
1330 * @return The Telecom call ID.
1331 * @hide
1332 */
1333 public final String getTelecomCallId() {
1334 return mTelecomCallId;
1335 }
1336
1337 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001338 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001339 */
Andrew Lee100e2932014-09-08 15:34:24 -07001340 public final Uri getAddress() {
1341 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001342 }
1343
1344 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001345 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001346 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001347 */
Andrew Lee100e2932014-09-08 15:34:24 -07001348 public final int getAddressPresentation() {
1349 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001350 }
1351
1352 /**
1353 * @return The caller display name (CNAP).
1354 */
1355 public final String getCallerDisplayName() {
1356 return mCallerDisplayName;
1357 }
1358
1359 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001360 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001361 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001362 */
1363 public final int getCallerDisplayNamePresentation() {
1364 return mCallerDisplayNamePresentation;
1365 }
1366
1367 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001368 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001369 */
1370 public final int getState() {
1371 return mState;
1372 }
1373
1374 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001375 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001376 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1377 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1378 * {@link VideoProfile#STATE_TX_ENABLED},
1379 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001380 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001382 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001383 */
1384 public final int getVideoState() {
1385 return mVideoState;
1386 }
1387
1388 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001389 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001390 * being routed by the system. This is {@code null} if this Connection
1391 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001392 * @deprecated Use {@link #getCallAudioState()} instead.
1393 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001394 */
Yorke Lee4af59352015-05-13 14:14:54 -07001395 @SystemApi
1396 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001398 if (mCallAudioState == null) {
1399 return null;
1400 }
Yorke Lee4af59352015-05-13 14:14:54 -07001401 return new AudioState(mCallAudioState);
1402 }
1403
1404 /**
1405 * @return The audio state of the connection, describing how its audio is currently
1406 * being routed by the system. This is {@code null} if this Connection
1407 * does not directly know about its audio state.
1408 */
1409 public final CallAudioState getCallAudioState() {
1410 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001411 }
1412
1413 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001414 * @return The conference that this connection is a part of. Null if it is not part of any
1415 * conference.
1416 */
1417 public final Conference getConference() {
1418 return mConference;
1419 }
1420
1421 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001422 * Returns whether this connection is requesting that the system play a ringback tone
1423 * on its behalf.
1424 */
Andrew Lee100e2932014-09-08 15:34:24 -07001425 public final boolean isRingbackRequested() {
1426 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001427 }
1428
1429 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001430 * @return True if the connection's audio mode is VOIP.
1431 */
1432 public final boolean getAudioModeIsVoip() {
1433 return mAudioModeIsVoip;
1434 }
1435
1436 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001437 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1438 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1439 * start time of the conference.
1440 *
1441 * @return The time at which the {@code Connnection} was connected.
1442 *
1443 * @hide
1444 */
1445 public final long getConnectTimeMillis() {
1446 return mConnectTimeMillis;
1447 }
1448
1449 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001450 * @return The status hints for this connection.
1451 */
1452 public final StatusHints getStatusHints() {
1453 return mStatusHints;
1454 }
1455
1456 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001457 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001458 * <p>
1459 * Extras should be updated using {@link #putExtras(Bundle)}.
1460 * <p>
1461 * Telecom or an {@link InCallService} can also update the extras via
1462 * {@link android.telecom.Call#putExtras(Bundle)}, and
1463 * {@link Call#removeExtras(List)}.
1464 * <p>
1465 * The connection is notified of changes to the extras made by Telecom or an
1466 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001467 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001468 * @return The extras associated with this connection.
1469 */
1470 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001471 Bundle extras = null;
1472 synchronized (mExtrasLock) {
1473 if (mExtras != null) {
1474 extras = new Bundle(mExtras);
1475 }
1476 }
1477 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001478 }
1479
1480 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001481 * Assign a listener to be notified of state changes.
1482 *
1483 * @param l A listener.
1484 * @return This Connection.
1485 *
1486 * @hide
1487 */
1488 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001489 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 return this;
1491 }
1492
1493 /**
1494 * Remove a previously assigned listener that was being notified of state changes.
1495 *
1496 * @param l A Listener.
1497 * @return This Connection.
1498 *
1499 * @hide
1500 */
1501 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001502 if (l != null) {
1503 mListeners.remove(l);
1504 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001505 return this;
1506 }
1507
1508 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001509 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001510 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001511 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001512 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001513 }
1514
1515 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001516 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1517 * ONLY for debugging purposes.
1518 *
1519 * @param callId The telecom call ID.
1520 * @hide
1521 */
1522 public void setTelecomCallId(String callId) {
1523 mTelecomCallId = callId;
1524 }
1525
1526 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001527 * Inform this Connection that the state of its audio output has been changed externally.
1528 *
1529 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001530 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001531 */
Yorke Lee4af59352015-05-13 14:14:54 -07001532 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001533 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001534 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001535 mCallAudioState = state;
1536 onAudioStateChanged(getAudioState());
1537 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001538 }
1539
1540 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001541 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001542 * @return A string representation of the value.
1543 */
1544 public static String stateToString(int state) {
1545 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001546 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001547 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001549 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001551 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001553 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001554 case STATE_PULLING_CALL:
1555 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001557 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001559 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001561 return "DISCONNECTED";
1562 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001563 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001564 return "UNKNOWN";
1565 }
1566 }
1567
1568 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001569 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001570 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001571 public final int getConnectionCapabilities() {
1572 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001573 }
1574
1575 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001576 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1577 */
1578 public final int getConnectionProperties() {
1579 return mConnectionProperties;
1580 }
1581
1582 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001583 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 *
Andrew Lee100e2932014-09-08 15:34:24 -07001585 * @param address The new address.
1586 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001587 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001588 */
Andrew Lee100e2932014-09-08 15:34:24 -07001589 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001590 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001591 Log.d(this, "setAddress %s", address);
1592 mAddress = address;
1593 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001594 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001595 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001596 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001597 }
1598
1599 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001600 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001601 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001602 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001603 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001604 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001605 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001606 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001607 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001608 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001609 mCallerDisplayName = callerDisplayName;
1610 mCallerDisplayNamePresentation = presentation;
1611 for (Listener l : mListeners) {
1612 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1613 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001614 }
1615
1616 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001617 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001618 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1619 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1620 * {@link VideoProfile#STATE_TX_ENABLED},
1621 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001622 *
1623 * @param videoState The new video state.
1624 */
1625 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001626 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001627 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001628 mVideoState = videoState;
1629 for (Listener l : mListeners) {
1630 l.onVideoStateChanged(this, mVideoState);
1631 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001632 }
1633
1634 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001635 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001636 * communicate).
1637 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001638 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001639 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001640 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001642 }
1643
1644 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001645 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001646 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001647 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001648 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001650 }
1651
1652 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001653 * Sets state to initializing (this Connection is not yet ready to be used).
1654 */
1655 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001656 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001657 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001658 }
1659
1660 /**
1661 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1662 */
1663 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001664 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001665 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001666 }
1667
1668 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001669 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001670 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001671 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001672 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001673 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001674 }
1675
1676 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001677 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1678 * device). Only applicable for {@link Connection}s with
1679 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1680 */
1681 public final void setPulling() {
1682 checkImmutable();
1683 setState(STATE_PULLING_CALL);
1684 }
1685
1686 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001687 * Sets state to be on hold.
1688 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001689 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001690 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001691 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001692 }
1693
1694 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001695 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001697 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001698 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001699 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001701 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001702 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001703 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001704 }
1705
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001706 public final VideoProvider getVideoProvider() {
1707 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001708 }
1709
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001710 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001711 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001712 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001713 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001714 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001715 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001716 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001718 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001719 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001720 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001721 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001722 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001723 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001724 }
1725
1726 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001727 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1728 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1729 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1730 * to send an {@link #onPostDialContinue(boolean)} signal.
1731 *
1732 * @param remaining The DTMF character sequence remaining to be emitted once the
1733 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1734 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001735 */
1736 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001737 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001738 for (Listener l : mListeners) {
1739 l.onPostDialWait(this, remaining);
1740 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001741 }
1742
1743 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001744 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1745 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001746 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001747 *
1748 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001749 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001750 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001751 checkImmutable();
1752 for (Listener l : mListeners) {
1753 l.onPostDialChar(this, nextChar);
1754 }
1755 }
1756
1757 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001758 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001759 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001760 *
1761 * @param ringback Whether the ringback tone is to be played.
1762 */
Andrew Lee100e2932014-09-08 15:34:24 -07001763 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001764 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001765 if (mRingbackRequested != ringback) {
1766 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001767 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001768 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001769 }
1770 }
Ihab Awadf8358972014-05-28 16:46:42 -07001771 }
1772
1773 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001774 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001775 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001776 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001777 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001778 public final void setConnectionCapabilities(int connectionCapabilities) {
1779 checkImmutable();
1780 if (mConnectionCapabilities != connectionCapabilities) {
1781 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001782 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001783 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001784 }
1785 }
Santos Cordonb6939982014-06-04 20:20:58 -07001786 }
1787
1788 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001789 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1790 *
1791 * @param connectionProperties The new connection properties.
1792 */
1793 public final void setConnectionProperties(int connectionProperties) {
1794 checkImmutable();
1795 if (mConnectionProperties != connectionProperties) {
1796 mConnectionProperties = connectionProperties;
1797 for (Listener l : mListeners) {
1798 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1799 }
1800 }
1801 }
1802
1803 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001804 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001805 */
Evan Charlton36a71342014-07-19 16:31:02 -07001806 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001807 for (Listener l : mListeners) {
1808 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001809 }
Santos Cordonb6939982014-06-04 20:20:58 -07001810 }
1811
1812 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001813 * Requests that the framework use VOIP audio mode for this connection.
1814 *
1815 * @param isVoip True if the audio mode is VOIP.
1816 */
1817 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001818 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001819 mAudioModeIsVoip = isVoip;
1820 for (Listener l : mListeners) {
1821 l.onAudioModeIsVoipChanged(this, isVoip);
1822 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001823 }
1824
1825 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001826 * Sets the time at which a call became active on this Connection. This is set only
1827 * when a conference call becomes active on this connection.
1828 *
1829 * @param connectionTimeMillis The connection time, in milliseconds.
1830 *
1831 * @hide
1832 */
1833 public final void setConnectTimeMillis(long connectTimeMillis) {
1834 mConnectTimeMillis = connectTimeMillis;
1835 }
1836
1837 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001838 * Sets the label and icon status to display in the in-call UI.
1839 *
1840 * @param statusHints The status label and icon to set.
1841 */
1842 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001843 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001844 mStatusHints = statusHints;
1845 for (Listener l : mListeners) {
1846 l.onStatusHintsChanged(this, statusHints);
1847 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001848 }
1849
1850 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001851 * Sets the connections with which this connection can be conferenced.
1852 *
1853 * @param conferenceableConnections The set of connections this connection can conference with.
1854 */
1855 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001856 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001857 clearConferenceableList();
1858 for (Connection c : conferenceableConnections) {
1859 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1860 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001861 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001862 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001863 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001864 }
1865 }
1866 fireOnConferenceableConnectionsChanged();
1867 }
1868
1869 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001870 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1871 * or conferences with which this connection can be conferenced.
1872 *
1873 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001874 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001875 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001876 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001877 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001878 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1879 // small amount of items here.
1880 if (!mConferenceables.contains(c)) {
1881 if (c instanceof Connection) {
1882 Connection connection = (Connection) c;
1883 connection.addConnectionListener(mConnectionDeathListener);
1884 } else if (c instanceof Conference) {
1885 Conference conference = (Conference) c;
1886 conference.addListener(mConferenceDeathListener);
1887 }
1888 mConferenceables.add(c);
1889 }
1890 }
1891 fireOnConferenceableConnectionsChanged();
1892 }
1893
1894 /**
1895 * Returns the connections or conferences with which this connection can be conferenced.
1896 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001897 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001898 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001899 }
1900
Yorke Lee53463962015-08-04 16:07:19 -07001901 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001902 * @hide
1903 */
1904 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001905 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001906 if (mConnectionService != null) {
1907 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1908 "which is already associated with another ConnectionService.");
1909 } else {
1910 mConnectionService = connectionService;
1911 }
1912 }
1913
1914 /**
1915 * @hide
1916 */
1917 public final void unsetConnectionService(ConnectionService connectionService) {
1918 if (mConnectionService != connectionService) {
1919 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1920 "that does not belong to the ConnectionService.");
1921 } else {
1922 mConnectionService = null;
1923 }
1924 }
1925
1926 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001927 * @hide
1928 */
1929 public final ConnectionService getConnectionService() {
1930 return mConnectionService;
1931 }
1932
1933 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001934 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001935 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001936 *
1937 * @param conference The conference.
1938 * @return {@code true} if the conference was successfully set.
1939 * @hide
1940 */
1941 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001942 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001943 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001944 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001945 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001946 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1947 fireConferenceChanged();
1948 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001949 return true;
1950 }
1951 return false;
1952 }
1953
1954 /**
1955 * Resets the conference that this connection is a part of.
1956 * @hide
1957 */
1958 public final void resetConference() {
1959 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001960 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001961 mConference = null;
1962 fireConferenceChanged();
1963 }
1964 }
1965
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001967 * Set some extras that can be associated with this {@code Connection}.
1968 * <p>
1969 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1970 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1971 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001972 * Alternatively you may use the {@link #putExtras(Bundle)}, and
1973 * {@link #removeExtras(String...)} methods to modify the extras.
1974 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07001975 * 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 -07001976 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1977 *
1978 * @param extras The extras associated with this {@code Connection}.
1979 */
1980 public final void setExtras(@Nullable Bundle extras) {
1981 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001982
1983 // Add/replace any new or changed extras values.
1984 putExtras(extras);
1985
1986 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1987 // the current one and remove any keys that went away.
1988 if (mPreviousExtraKeys != null) {
1989 List<String> toRemove = new ArrayList<String>();
1990 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001991 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001992 toRemove.add(oldKey);
1993 }
1994 }
1995 if (!toRemove.isEmpty()) {
1996 removeExtras(toRemove);
1997 }
1998 }
1999
2000 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2001 // called we can see if the caller has removed any extras values.
2002 if (mPreviousExtraKeys == null) {
2003 mPreviousExtraKeys = new ArraySet<String>();
2004 }
2005 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002006 if (extras != null) {
2007 mPreviousExtraKeys.addAll(extras.keySet());
2008 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002009 }
2010
2011 /**
2012 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2013 * added.
2014 * <p>
2015 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2016 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2017 *
2018 * @param extras The extras to add.
2019 */
2020 public final void putExtras(@NonNull Bundle extras) {
2021 checkImmutable();
2022 if (extras == null) {
2023 return;
2024 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002025 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2026 // the listeners.
2027 Bundle listenerExtras;
2028 synchronized (mExtrasLock) {
2029 if (mExtras == null) {
2030 mExtras = new Bundle();
2031 }
2032 mExtras.putAll(extras);
2033 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002034 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002035 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002036 // Create a new clone of the extras for each listener so that they don't clobber
2037 // each other
2038 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002039 }
2040 }
2041
2042 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002043 * Adds a boolean extra to this {@code Connection}.
2044 *
2045 * @param key The extra key.
2046 * @param value The value.
2047 * @hide
2048 */
2049 public final void putExtra(String key, boolean value) {
2050 Bundle newExtras = new Bundle();
2051 newExtras.putBoolean(key, value);
2052 putExtras(newExtras);
2053 }
2054
2055 /**
2056 * Adds an integer extra to this {@code Connection}.
2057 *
2058 * @param key The extra key.
2059 * @param value The value.
2060 * @hide
2061 */
2062 public final void putExtra(String key, int value) {
2063 Bundle newExtras = new Bundle();
2064 newExtras.putInt(key, value);
2065 putExtras(newExtras);
2066 }
2067
2068 /**
2069 * Adds a string extra to this {@code Connection}.
2070 *
2071 * @param key The extra key.
2072 * @param value The value.
2073 * @hide
2074 */
2075 public final void putExtra(String key, String value) {
2076 Bundle newExtras = new Bundle();
2077 newExtras.putString(key, value);
2078 putExtras(newExtras);
2079 }
2080
2081 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002082 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002083 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002084 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002085 */
2086 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002087 synchronized (mExtrasLock) {
2088 if (mExtras != null) {
2089 for (String key : keys) {
2090 mExtras.remove(key);
2091 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002092 }
2093 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002094 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002095 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002096 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002097 }
2098 }
2099
2100 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002101 * Removes extras from this {@code Connection}.
2102 *
2103 * @param keys The keys of the extras to remove.
2104 */
2105 public final void removeExtras(String ... keys) {
2106 removeExtras(Arrays.asList(keys));
2107 }
2108
2109 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002110 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002111 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002112 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002113 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2114 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002115 */
Yorke Lee4af59352015-05-13 14:14:54 -07002116 @SystemApi
2117 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002118 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002119
2120 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002121 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2122 *
2123 * @param state The new connection audio state.
2124 */
2125 public void onCallAudioStateChanged(CallAudioState state) {}
2126
2127 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002128 * Notifies this Connection of an internal state change. This method is called after the
2129 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002130 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002132 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002133 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002134
2135 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002136 * Notifies this Connection of a request to play a DTMF tone.
2137 *
2138 * @param c A DTMF character.
2139 */
Santos Cordonf2951102014-07-20 19:06:29 -07002140 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002141
2142 /**
2143 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2144 */
Santos Cordonf2951102014-07-20 19:06:29 -07002145 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002146
2147 /**
2148 * Notifies this Connection of a request to disconnect.
2149 */
Santos Cordonf2951102014-07-20 19:06:29 -07002150 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002151
2152 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002153 * Notifies this Connection of a request to disconnect a participant of the conference managed
2154 * by the connection.
2155 *
2156 * @param endpoint the {@link Uri} of the participant to disconnect.
2157 * @hide
2158 */
2159 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2160
2161 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002162 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002163 */
Santos Cordonf2951102014-07-20 19:06:29 -07002164 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002165
2166 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002167 * Notifies this Connection of a request to abort.
2168 */
Santos Cordonf2951102014-07-20 19:06:29 -07002169 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002170
2171 /**
2172 * Notifies this Connection of a request to hold.
2173 */
Santos Cordonf2951102014-07-20 19:06:29 -07002174 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002175
2176 /**
2177 * Notifies this Connection of a request to exit a hold state.
2178 */
Santos Cordonf2951102014-07-20 19:06:29 -07002179 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002180
2181 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002182 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002183 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002184 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002185 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002186 */
Santos Cordonf2951102014-07-20 19:06:29 -07002187 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002188
2189 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002190 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002191 * a request to accept.
2192 */
2193 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002194 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002195 }
2196
2197 /**
2198 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002199 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002200 */
Santos Cordonf2951102014-07-20 19:06:29 -07002201 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002202
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002203 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002204 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2205 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002206 */
2207 public void onReject(String replyMessage) {}
2208
2209 /**
Bryce Leecac50772015-11-17 15:13:29 -08002210 * Notifies the Connection of a request to silence the ringer.
2211 *
2212 * @hide
2213 */
2214 public void onSilence() {}
2215
2216 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002217 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2218 */
Santos Cordonf2951102014-07-20 19:06:29 -07002219 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002220
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002221 /**
2222 * Notifies this Connection of a request to pull an external call to the local device.
2223 * <p>
2224 * The {@link InCallService} issues a request to pull an external call to the local device via
2225 * {@link Call#pullExternalCall()}.
2226 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002227 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2228 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002229 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002230 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002231 */
2232 public void onPullExternalCall() {}
2233
2234 /**
2235 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2236 * <p>
2237 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2238 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002239 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2240 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2241 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2242 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2243 * not aware of.
2244 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002245 * See also {@link Call#sendCallEvent(String, Bundle)}.
2246 *
2247 * @param event The call event.
2248 * @param extras Extras associated with the call event.
2249 */
2250 public void onCallEvent(String event, Bundle extras) {}
2251
Tyler Gunndee56a82016-03-23 16:06:34 -07002252 /**
2253 * Notifies this {@link Connection} of a change to the extras made outside the
2254 * {@link ConnectionService}.
2255 * <p>
2256 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2257 * the {@link android.telecom.Call#putExtras(Bundle)} and
2258 * {@link Call#removeExtras(List)}.
2259 *
2260 * @param extras The new extras bundle.
2261 */
2262 public void onExtrasChanged(Bundle extras) {}
2263
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002264 static String toLogSafePhoneNumber(String number) {
2265 // For unknown number, log empty string.
2266 if (number == null) {
2267 return "";
2268 }
2269
2270 if (PII_DEBUG) {
2271 // When PII_DEBUG is true we emit PII.
2272 return number;
2273 }
2274
2275 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2276 // sanitized phone numbers.
2277 StringBuilder builder = new StringBuilder();
2278 for (int i = 0; i < number.length(); i++) {
2279 char c = number.charAt(i);
2280 if (c == '-' || c == '@' || c == '.') {
2281 builder.append(c);
2282 } else {
2283 builder.append('x');
2284 }
2285 }
2286 return builder.toString();
2287 }
2288
Ihab Awad542e0ea2014-05-16 10:22:16 -07002289 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002290 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002291 if (mState == STATE_DISCONNECTED && mState != state) {
2292 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002293 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002294 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002295 if (mState != state) {
2296 Log.d(this, "setState: %s", stateToString(state));
2297 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002298 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002299 for (Listener l : mListeners) {
2300 l.onStateChanged(this, state);
2301 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002302 }
2303 }
2304
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002305 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002306 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002307 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2308 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002309 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002310 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002311
2312 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002313 if (mImmutable) {
2314 throw new UnsupportedOperationException("Connection is immutable");
2315 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002316 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002317 }
2318
Evan Charltonbf11f982014-07-20 22:06:28 -07002319 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002320 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002321 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2322 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002323 * <p>
2324 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2325 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002326 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002327 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002328 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002329 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002330 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2331 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002332 }
2333
Evan Charltonbf11f982014-07-20 22:06:28 -07002334 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002335 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2336 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2337 * this should never be un-@hide-den.
2338 *
2339 * @hide
2340 */
2341 public void checkImmutable() {}
2342
2343 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002344 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2345 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2346 * that state. This connection should not be used for anything, and no other
2347 * {@code Connection}s should be attempted.
2348 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002349 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002350 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002351 * @return A {@code Connection} which indicates that the underlying connection should
2352 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002353 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002354 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002355 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002356 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002357
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002358 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002359 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002360 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002361 }
2362 }
2363
Santos Cordon823fd3c2014-08-07 18:35:18 -07002364 private final void fireConferenceChanged() {
2365 for (Listener l : mListeners) {
2366 l.onConferenceChanged(this, mConference);
2367 }
2368 }
2369
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002370 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002371 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002372 if (c instanceof Connection) {
2373 Connection connection = (Connection) c;
2374 connection.removeConnectionListener(mConnectionDeathListener);
2375 } else if (c instanceof Conference) {
2376 Conference conference = (Conference) c;
2377 conference.removeListener(mConferenceDeathListener);
2378 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002379 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002380 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002381 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002382
2383 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002384 * Handles a change to extras received from Telecom.
2385 *
2386 * @param extras The new extras.
2387 * @hide
2388 */
2389 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002390 Bundle b = null;
2391 synchronized (mExtrasLock) {
2392 mExtras = extras;
2393 if (mExtras != null) {
2394 b = new Bundle(mExtras);
2395 }
2396 }
2397 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002398 }
2399
2400 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002401 * Notifies listeners that the merge request failed.
2402 *
2403 * @hide
2404 */
2405 protected final void notifyConferenceMergeFailed() {
2406 for (Listener l : mListeners) {
2407 l.onConferenceMergeFailed(this);
2408 }
2409 }
2410
2411 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002412 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002413 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002414 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002415 * @hide
2416 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002417 protected final void updateConferenceParticipants(
2418 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002419 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002420 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002421 }
2422 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002423
2424 /**
2425 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002426 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002427 */
2428 protected void notifyConferenceStarted() {
2429 for (Listener l : mListeners) {
2430 l.onConferenceStarted();
2431 }
2432 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002433
2434 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002435 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2436 * be a part of a conference call.
2437 * @param isConferenceSupported {@code true} if the connection supports being part of a
2438 * conference call, {@code false} otherwise.
2439 * @hide
2440 */
2441 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2442 for (Listener l : mListeners) {
2443 l.onConferenceSupportedChanged(this, isConferenceSupported);
2444 }
2445 }
2446
2447 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002448 * Sends an event associated with this {@code Connection} with associated event extras to the
2449 * {@link InCallService}.
2450 * <p>
2451 * Connection events are used to communicate point in time information from a
2452 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2453 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2454 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2455 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2456 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2457 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2458 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2459 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2460 * <p>
2461 * Events are exposed to {@link InCallService} implementations via
2462 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2463 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002464 * No assumptions should be made as to how an In-Call UI or service will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002465 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2466 * some events altogether.
2467 * <p>
2468 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2469 * conflicts between {@link ConnectionService} implementations. Further, custom
2470 * {@link ConnectionService} implementations shall not re-purpose events in the
2471 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2472 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2473 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2474 * {@code com.example.extra.MY_EXTRA}).
2475 * <p>
2476 * When defining events and the associated extras, it is important to keep their behavior
2477 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2478 * events/extras should me maintained to ensure backwards compatibility with older
2479 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002480 *
2481 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002482 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002483 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002484 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002485 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002486 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002487 }
2488 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002489}