blob: ee055f45cecba217a056d034a2df2563f3949dc1 [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
Hall Liu9f332c72016-07-14 15:37:37 -0700373 /**
374 * Indicates that the connection represents a downgraded IMS conference.
375 * @hide
376 */
377 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
378
Tyler Gunn96d6c402015-03-18 12:39:23 -0700379 //**********************************************************************************************
Hall Liu9f332c72016-07-14 15:37:37 -0700380 // Next PROPERTY value: 1<<7
Tyler Gunn96d6c402015-03-18 12:39:23 -0700381 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800382
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700383 /**
384 * Connection extra key used to store the last forwarded number associated with the current
385 * connection. Used to communicate to the user interface that the connection was forwarded via
386 * the specified number.
387 */
388 public static final String EXTRA_LAST_FORWARDED_NUMBER =
389 "android.telecom.extra.LAST_FORWARDED_NUMBER";
390
391 /**
392 * Connection extra key used to store a child number associated with the current connection.
393 * Used to communicate to the user interface that the connection was received via
394 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
395 * address.
396 */
397 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
398
399 /**
400 * Connection extra key used to store the subject for an incoming call. The user interface can
401 * query this extra and display its contents for incoming calls. Will only be used if the
402 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
403 */
404 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
405
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800406 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700407 * Boolean connection extra key set on a {@link Connection} in
408 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
409 * current active foreground call to be dropped.
410 */
411 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
412 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
413
414 /**
Hall Liu10208662016-06-15 17:55:00 -0700415 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700416 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700417 * @hide
418 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700419 public static final String EXTRA_DISABLE_ADD_CALL =
420 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700421
422 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800423 * Connection event used to inform Telecom that it should play the on hold tone. This is used
424 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700425 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800426 * @hide
427 */
428 public static final String EVENT_ON_HOLD_TONE_START =
429 "android.telecom.event.ON_HOLD_TONE_START";
430
431 /**
432 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
433 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700434 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800435 * @hide
436 */
437 public static final String EVENT_ON_HOLD_TONE_END =
438 "android.telecom.event.ON_HOLD_TONE_END";
439
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700440 /**
441 * Connection event used to inform {@link InCallService}s when pulling of an external call has
442 * failed. The user interface should inform the user of the error.
443 * <p>
444 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
445 * API is called on a {@link Call} with the properties
446 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
447 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
448 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700449 * <p>
450 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
451 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700452 */
453 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
454
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700455 /**
456 * Connection event used to inform {@link InCallService}s when the merging of two calls has
457 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700458 * <p>
459 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
460 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700461 */
462 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
463
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700464 // Flag controlling whether PII is emitted into the logs
465 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
466
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800467 /**
468 * Whether the given capabilities support the specified capability.
469 *
470 * @param capabilities A capability bit field.
471 * @param capability The capability to check capabilities for.
472 * @return Whether the specified capability is supported.
473 * @hide
474 */
475 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800476 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800477 }
478
479 /**
480 * Whether the capabilities of this {@code Connection} supports the specified capability.
481 *
482 * @param capability The capability to check capabilities for.
483 * @return Whether the specified capability is supported.
484 * @hide
485 */
486 public boolean can(int capability) {
487 return can(mConnectionCapabilities, capability);
488 }
489
490 /**
491 * Removes the specified capability from the set of capabilities of this {@code Connection}.
492 *
493 * @param capability The capability to remove from the set.
494 * @hide
495 */
496 public void removeCapability(int capability) {
497 mConnectionCapabilities &= ~capability;
498 }
499
500 /**
501 * Adds the specified capability to the set of capabilities of this {@code Connection}.
502 *
503 * @param capability The capability to add to the set.
504 * @hide
505 */
506 public void addCapability(int capability) {
507 mConnectionCapabilities |= capability;
508 }
509
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700510 /**
511 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
512 *
513 * @param capabilities A capability bit field.
514 * @return A human readable string representation.
515 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800516 public static String capabilitiesToString(int capabilities) {
517 StringBuilder builder = new StringBuilder();
518 builder.append("[Capabilities:");
519 if (can(capabilities, CAPABILITY_HOLD)) {
520 builder.append(" CAPABILITY_HOLD");
521 }
522 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
523 builder.append(" CAPABILITY_SUPPORT_HOLD");
524 }
525 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
526 builder.append(" CAPABILITY_MERGE_CONFERENCE");
527 }
528 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
529 builder.append(" CAPABILITY_SWAP_CONFERENCE");
530 }
531 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
532 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
533 }
534 if (can(capabilities, CAPABILITY_MUTE)) {
535 builder.append(" CAPABILITY_MUTE");
536 }
537 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
538 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
539 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700540 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
541 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
542 }
543 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
544 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
545 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700546 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
547 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800548 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700549 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
550 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
551 }
552 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
553 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
554 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700555 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
556 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800557 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800558 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
559 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
560 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500561 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700562 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500563 }
Rekha Kumar07366812015-03-24 16:42:31 -0700564 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
565 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
566 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700567 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
568 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
569 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700570 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
571 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
572 }
Bryce Lee81901682015-08-28 16:38:02 -0700573 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
574 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
575 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700576 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
577 builder.append(" CAPABILITY_CAN_PULL_CALL");
578 }
Bryce Lee81901682015-08-28 16:38:02 -0700579
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800580 builder.append("]");
581 return builder.toString();
582 }
583
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700584 /**
585 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
586 *
587 * @param properties A property bit field.
588 * @return A human readable string representation.
589 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700590 public static String propertiesToString(int properties) {
591 StringBuilder builder = new StringBuilder();
592 builder.append("[Properties:");
593
594 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
595 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
596 }
597
598 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
599 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
600 }
601
602 if (can(properties, PROPERTY_WIFI)) {
603 builder.append(" PROPERTY_WIFI");
604 }
605
606 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
607 builder.append(" PROPERTY_GENERIC_CONFERENCE");
608 }
609
610 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
611 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
612 }
613
Brad Ebinger15847072016-05-18 11:08:36 -0700614 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
615 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
616 }
617
Tyler Gunn720c6642016-03-22 09:02:47 -0700618 builder.append("]");
619 return builder.toString();
620 }
621
Sailesh Nepal091768c2014-06-30 15:15:23 -0700622 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700623 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700624 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700625 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700626 public void onCallerDisplayNameChanged(
627 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700628 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700629 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700630 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800631 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700632 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700633 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800634 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700635 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 public void onVideoProviderChanged(
637 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700638 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
639 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800640 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700641 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700642 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700643 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800644 public void onConferenceParticipantsChanged(Connection c,
645 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800646 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700647 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700648 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700649 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700650 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700651 /** @hide */
652 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700653 }
654
Tyler Gunnb702ef82015-05-29 11:51:53 -0700655 /**
656 * Provides a means of controlling the video session associated with a {@link Connection}.
657 * <p>
658 * Implementations create a custom subclass of {@link VideoProvider} and the
659 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
660 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
661 * should set the {@link VideoProvider}.
662 * <p>
663 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
664 * {@link InCallService} implementations to issue requests related to the video session;
665 * it provides a means for the {@link ConnectionService} to report events and information
666 * related to the video session to Telecom and the {@link InCallService} implementations.
667 * <p>
668 * {@link InCallService} implementations interact with the {@link VideoProvider} via
669 * {@link android.telecom.InCallService.VideoCall}.
670 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700671 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700672
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700673 /**
674 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700675 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 */
677 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700678
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700679 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700680 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
681 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 */
683 public static final int SESSION_EVENT_RX_RESUME = 2;
684
685 /**
686 * Video transmission has begun. This occurs after a negotiated start of video transmission
687 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700688 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700689 */
690 public static final int SESSION_EVENT_TX_START = 3;
691
692 /**
693 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
694 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700695 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 */
697 public static final int SESSION_EVENT_TX_STOP = 4;
698
699 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700700 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
701 * this as a cue to inform the user the camera is not available.
702 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 */
704 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
705
706 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700707 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
708 * for operation. The {@link InCallService} can use this as a cue to inform the user that
709 * the camera has become available again.
710 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 */
712 public static final int SESSION_EVENT_CAMERA_READY = 6;
713
714 /**
715 * Session modify request was successful.
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_SUCCESS = 1;
719
720 /**
721 * Session modify request failed.
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_FAIL = 2;
725
726 /**
727 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700728 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700729 */
730 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
731
Rekha Kumar07366812015-03-24 16:42:31 -0700732 /**
733 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700734 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700735 */
736 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
737
738 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700739 * Session modify request rejected by remote user.
740 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700741 */
742 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
743
Tyler Gunn75958422015-04-15 14:23:42 -0700744 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700745 private static final int MSG_SET_CAMERA = 2;
746 private static final int MSG_SET_PREVIEW_SURFACE = 3;
747 private static final int MSG_SET_DISPLAY_SURFACE = 4;
748 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
749 private static final int MSG_SET_ZOOM = 6;
750 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
751 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
752 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800753 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700755 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700756
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700757 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700759
760 /**
761 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700762 *
763 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
764 * load factor before resizing, 1 means we only expect a single thread to
765 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700766 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700767 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
768 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700769
770 /**
771 * Default handler used to consolidate binder method calls onto a single thread.
772 */
773 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700774 public VideoProviderHandler() {
775 super();
776 }
777
778 public VideoProviderHandler(Looper looper) {
779 super(looper);
780 }
781
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 @Override
783 public void handleMessage(Message msg) {
784 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700785 case MSG_ADD_VIDEO_CALLBACK: {
786 IBinder binder = (IBinder) msg.obj;
787 IVideoCallback callback = IVideoCallback.Stub
788 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700789 if (callback == null) {
790 Log.w(this, "addVideoProvider - skipped; callback is null.");
791 break;
792 }
793
Tyler Gunn75958422015-04-15 14:23:42 -0700794 if (mVideoCallbacks.containsKey(binder)) {
795 Log.i(this, "addVideoProvider - skipped; already present.");
796 break;
797 }
798 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700799 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700800 }
801 case MSG_REMOVE_VIDEO_CALLBACK: {
802 IBinder binder = (IBinder) msg.obj;
803 IVideoCallback callback = IVideoCallback.Stub
804 .asInterface((IBinder) msg.obj);
805 if (!mVideoCallbacks.containsKey(binder)) {
806 Log.i(this, "removeVideoProvider - skipped; not present.");
807 break;
808 }
809 mVideoCallbacks.remove(binder);
810 break;
811 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 case MSG_SET_CAMERA:
813 onSetCamera((String) msg.obj);
814 break;
815 case MSG_SET_PREVIEW_SURFACE:
816 onSetPreviewSurface((Surface) msg.obj);
817 break;
818 case MSG_SET_DISPLAY_SURFACE:
819 onSetDisplaySurface((Surface) msg.obj);
820 break;
821 case MSG_SET_DEVICE_ORIENTATION:
822 onSetDeviceOrientation(msg.arg1);
823 break;
824 case MSG_SET_ZOOM:
825 onSetZoom((Float) msg.obj);
826 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700827 case MSG_SEND_SESSION_MODIFY_REQUEST: {
828 SomeArgs args = (SomeArgs) msg.obj;
829 try {
830 onSendSessionModifyRequest((VideoProfile) args.arg1,
831 (VideoProfile) args.arg2);
832 } finally {
833 args.recycle();
834 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700835 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700836 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837 case MSG_SEND_SESSION_MODIFY_RESPONSE:
838 onSendSessionModifyResponse((VideoProfile) msg.obj);
839 break;
840 case MSG_REQUEST_CAMERA_CAPABILITIES:
841 onRequestCameraCapabilities();
842 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800843 case MSG_REQUEST_CONNECTION_DATA_USAGE:
844 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700845 break;
846 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700847 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 break;
849 default:
850 break;
851 }
852 }
853 }
854
855 /**
856 * IVideoProvider stub implementation.
857 */
858 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700859 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700861 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
862 }
863
864 public void removeVideoCallback(IBinder videoCallbackBinder) {
865 mMessageHandler.obtainMessage(
866 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700867 }
868
869 public void setCamera(String cameraId) {
870 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
871 }
872
873 public void setPreviewSurface(Surface surface) {
874 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
875 }
876
877 public void setDisplaySurface(Surface surface) {
878 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
879 }
880
881 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700882 mMessageHandler.obtainMessage(
883 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 }
885
886 public void setZoom(float value) {
887 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
888 }
889
Tyler Gunn45382162015-05-06 08:52:27 -0700890 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
891 SomeArgs args = SomeArgs.obtain();
892 args.arg1 = fromProfile;
893 args.arg2 = toProfile;
894 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 }
896
897 public void sendSessionModifyResponse(VideoProfile responseProfile) {
898 mMessageHandler.obtainMessage(
899 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
900 }
901
902 public void requestCameraCapabilities() {
903 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
904 }
905
906 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800907 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700908 }
909
Yorke Lee32f24732015-05-12 16:18:03 -0700910 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700911 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
912 }
913 }
914
915 public VideoProvider() {
916 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700917 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700918 }
919
920 /**
921 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
922 *
923 * @param looper The looper.
924 * @hide
925 */
926 public VideoProvider(Looper looper) {
927 mBinder = new VideoProvider.VideoProviderBinder();
928 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700929 }
930
931 /**
932 * Returns binder object which can be used across IPC methods.
933 * @hide
934 */
935 public final IVideoProvider getInterface() {
936 return mBinder;
937 }
938
939 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700940 * Sets the camera to be used for the outgoing video.
941 * <p>
942 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
943 * camera via
944 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
945 * <p>
946 * Sent from the {@link InCallService} via
947 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 * @param cameraId The id of the camera (use ids as reported by
950 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 */
952 public abstract void onSetCamera(String cameraId);
953
954 /**
955 * Sets the surface to be used for displaying a preview of what the user's camera is
956 * currently capturing. When video transmission is enabled, this is the video signal which
957 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700958 * <p>
959 * Sent from the {@link InCallService} via
960 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700962 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 */
964 public abstract void onSetPreviewSurface(Surface surface);
965
966 /**
967 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700968 * <p>
969 * Sent from the {@link InCallService} via
970 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700972 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 */
974 public abstract void onSetDisplaySurface(Surface surface);
975
976 /**
977 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
978 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700979 * <p>
980 * Sent from the {@link InCallService} via
981 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 *
983 * @param rotation The device orientation, in degrees.
984 */
985 public abstract void onSetDeviceOrientation(int rotation);
986
987 /**
988 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700989 * <p>
990 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 *
992 * @param value The camera zoom ratio.
993 */
994 public abstract void onSetZoom(float value);
995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Issues a request to modify the properties of the current video session.
998 * <p>
999 * Example scenarios include: requesting an audio-only call to be upgraded to a
1000 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1001 * when the {@link InCallService} is no longer the foreground application.
1002 * <p>
1003 * If the {@link VideoProvider} determines a request to be invalid, it should call
1004 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1005 * invalid request back to the {@link InCallService}.
1006 * <p>
1007 * Where a request requires confirmation from the user of the peer device, the
1008 * {@link VideoProvider} must communicate the request to the peer device and handle the
1009 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1010 * is used to inform the {@link InCallService} of the result of the request.
1011 * <p>
1012 * Sent from the {@link InCallService} via
1013 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * @param fromProfile The video profile prior to the request.
1016 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 */
Tyler Gunn45382162015-05-06 08:52:27 -07001018 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1019 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 /**
1022 * Provides a response to a request to change the current video session properties.
1023 * <p>
1024 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1025 * video call, could decline the request and keep the call as audio-only.
1026 * In such a scenario, the {@code responseProfile} would have a video state of
1027 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1028 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1029 * <p>
1030 * Sent from the {@link InCallService} via
1031 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1032 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1033 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 */
1037 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1038
1039 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001040 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1041 * <p>
1042 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1043 * camera via
1044 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1045 * <p>
1046 * Sent from the {@link InCallService} via
1047 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 */
1049 public abstract void onRequestCameraCapabilities();
1050
1051 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001052 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1053 * video component of the current {@link Connection}.
1054 * <p>
1055 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1056 * via {@link VideoProvider#setCallDataUsage(long)}.
1057 * <p>
1058 * Sent from the {@link InCallService} via
1059 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001061 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062
1063 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001064 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1065 * the peer device when the video signal is paused.
1066 * <p>
1067 * Sent from the {@link InCallService} via
1068 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 *
1070 * @param uri URI of image to display.
1071 */
Yorke Lee32f24732015-05-12 16:18:03 -07001072 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073
1074 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * Used to inform listening {@link InCallService} implementations when the
1076 * {@link VideoProvider} receives a session modification request.
1077 * <p>
1078 * Received by the {@link InCallService} via
1079 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001080 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001081 * @param videoProfile The requested video profile.
1082 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 */
1084 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001085 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001086 for (IVideoCallback callback : mVideoCallbacks.values()) {
1087 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001088 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001089 } catch (RemoteException ignored) {
1090 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001091 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001092 }
1093 }
1094 }
1095
1096 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001097 * Used to inform listening {@link InCallService} implementations when the
1098 * {@link VideoProvider} receives a response to a session modification request.
1099 * <p>
1100 * Received by the {@link InCallService} via
1101 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1102 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 *
1104 * @param status Status of the session modify request. Valid values are
1105 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1106 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001107 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1108 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1109 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1110 * @param requestedProfile The original request which was sent to the peer device.
1111 * @param responseProfile The actual profile changes agreed to by the peer device.
1112 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 */
1114 public void receiveSessionModifyResponse(int status,
1115 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001116 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001117 for (IVideoCallback callback : mVideoCallbacks.values()) {
1118 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001119 callback.receiveSessionModifyResponse(status, requestedProfile,
1120 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001121 } catch (RemoteException ignored) {
1122 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001123 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 }
1125 }
1126 }
1127
1128 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 * Used to inform listening {@link InCallService} implementations when the
1130 * {@link VideoProvider} reports a call session event.
1131 * <p>
1132 * Received by the {@link InCallService} via
1133 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001135 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1136 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1137 * {@link VideoProvider#SESSION_EVENT_TX_START},
1138 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1139 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1140 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 */
1142 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001143 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001144 for (IVideoCallback callback : mVideoCallbacks.values()) {
1145 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001146 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001147 } catch (RemoteException ignored) {
1148 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001149 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001150 }
1151 }
1152 }
1153
1154 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001155 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1156 * peer's video have changed.
1157 * <p>
1158 * This could occur if, for example, the peer rotates their device, changing the aspect
1159 * ratio of the video, or if the user switches between the back and front cameras.
1160 * <p>
1161 * Received by the {@link InCallService} via
1162 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 *
1164 * @param width The updated peer video width.
1165 * @param height The updated peer video height.
1166 */
1167 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001168 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001169 for (IVideoCallback callback : mVideoCallbacks.values()) {
1170 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001171 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001172 } catch (RemoteException ignored) {
1173 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001174 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 }
1176 }
1177 }
1178
1179 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001180 * Used to inform listening {@link InCallService} implementations when the data usage of the
1181 * video associated with the current {@link Connection} has changed.
1182 * <p>
1183 * This could be in response to a preview request via
1184 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001185 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1186 * 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 -07001187 * <p>
1188 * Received by the {@link InCallService} via
1189 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001190 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001191 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1192 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001193 */
Yorke Lee32f24732015-05-12 16:18:03 -07001194 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001195 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001196 for (IVideoCallback callback : mVideoCallbacks.values()) {
1197 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001198 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001199 } catch (RemoteException ignored) {
1200 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001201 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 }
1203 }
1204 }
1205
1206 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001207 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001208 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001209 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001210 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1211 * @hide
1212 */
1213 public void changeCallDataUsage(long dataUsage) {
1214 setCallDataUsage(dataUsage);
1215 }
1216
1217 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001218 * Used to inform listening {@link InCallService} implementations when the capabilities of
1219 * the current camera have changed.
1220 * <p>
1221 * The {@link VideoProvider} should call this in response to
1222 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1223 * changed via {@link VideoProvider#onSetCamera(String)}.
1224 * <p>
1225 * Received by the {@link InCallService} via
1226 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1227 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001228 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001229 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001230 */
Yorke Lee400470f2015-05-12 13:31:25 -07001231 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001232 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001233 for (IVideoCallback callback : mVideoCallbacks.values()) {
1234 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001235 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001236 } catch (RemoteException ignored) {
1237 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001238 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001239 }
1240 }
1241 }
Rekha Kumar07366812015-03-24 16:42:31 -07001242
1243 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001244 * Used to inform listening {@link InCallService} implementations when the video quality
1245 * of the call has changed.
1246 * <p>
1247 * Received by the {@link InCallService} via
1248 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001249 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001250 * @param videoQuality The updated video quality. Valid values:
1251 * {@link VideoProfile#QUALITY_HIGH},
1252 * {@link VideoProfile#QUALITY_MEDIUM},
1253 * {@link VideoProfile#QUALITY_LOW},
1254 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001255 */
1256 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001257 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001258 for (IVideoCallback callback : mVideoCallbacks.values()) {
1259 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001260 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001261 } catch (RemoteException ignored) {
1262 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001263 }
Rekha Kumar07366812015-03-24 16:42:31 -07001264 }
1265 }
1266 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001267 }
1268
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001269 private final Listener mConnectionDeathListener = new Listener() {
1270 @Override
1271 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001272 if (mConferenceables.remove(c)) {
1273 fireOnConferenceableConnectionsChanged();
1274 }
1275 }
1276 };
1277
1278 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1279 @Override
1280 public void onDestroyed(Conference c) {
1281 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001282 fireOnConferenceableConnectionsChanged();
1283 }
1284 }
1285 };
1286
Jay Shrauner229e3822014-08-15 09:23:07 -07001287 /**
1288 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1289 * load factor before resizing, 1 means we only expect a single thread to
1290 * access the map so make only a single shard
1291 */
1292 private final Set<Listener> mListeners = Collections.newSetFromMap(
1293 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001294 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1295 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001296 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001297
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001298 // The internal telecom call ID associated with this connection.
1299 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001300 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001301 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001302 private Uri mAddress;
1303 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001304 private String mCallerDisplayName;
1305 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001306 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001307 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001308 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001309 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001310 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001311 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001312 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001313 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001314 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001315 private Conference mConference;
1316 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001317 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001318 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319
1320 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001321 * Tracks the key set for the extras bundle provided on the last invocation of
1322 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1323 * keys which were set previously but are no longer present in the replacement Bundle.
1324 */
1325 private Set<String> mPreviousExtraKeys;
1326
1327 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 * Create a new Connection.
1329 */
Santos Cordonf2951102014-07-20 19:06:29 -07001330 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001331
1332 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001333 * Returns the Telecom internal call ID associated with this connection. Should only be used
1334 * for debugging and tracing purposes.
1335 *
1336 * @return The Telecom call ID.
1337 * @hide
1338 */
1339 public final String getTelecomCallId() {
1340 return mTelecomCallId;
1341 }
1342
1343 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001344 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001345 */
Andrew Lee100e2932014-09-08 15:34:24 -07001346 public final Uri getAddress() {
1347 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001348 }
1349
1350 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001351 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001352 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001353 */
Andrew Lee100e2932014-09-08 15:34:24 -07001354 public final int getAddressPresentation() {
1355 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001356 }
1357
1358 /**
1359 * @return The caller display name (CNAP).
1360 */
1361 public final String getCallerDisplayName() {
1362 return mCallerDisplayName;
1363 }
1364
1365 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001366 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001367 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001368 */
1369 public final int getCallerDisplayNamePresentation() {
1370 return mCallerDisplayNamePresentation;
1371 }
1372
1373 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001374 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001375 */
1376 public final int getState() {
1377 return mState;
1378 }
1379
1380 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001382 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1383 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1384 * {@link VideoProfile#STATE_TX_ENABLED},
1385 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001386 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001387 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001388 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001389 */
1390 public final int getVideoState() {
1391 return mVideoState;
1392 }
1393
1394 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001395 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001396 * being routed by the system. This is {@code null} if this Connection
1397 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001398 * @deprecated Use {@link #getCallAudioState()} instead.
1399 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001400 */
Yorke Lee4af59352015-05-13 14:14:54 -07001401 @SystemApi
1402 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001404 if (mCallAudioState == null) {
1405 return null;
1406 }
Yorke Lee4af59352015-05-13 14:14:54 -07001407 return new AudioState(mCallAudioState);
1408 }
1409
1410 /**
1411 * @return The audio state of the connection, describing how its audio is currently
1412 * being routed by the system. This is {@code null} if this Connection
1413 * does not directly know about its audio state.
1414 */
1415 public final CallAudioState getCallAudioState() {
1416 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001417 }
1418
1419 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001420 * @return The conference that this connection is a part of. Null if it is not part of any
1421 * conference.
1422 */
1423 public final Conference getConference() {
1424 return mConference;
1425 }
1426
1427 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001428 * Returns whether this connection is requesting that the system play a ringback tone
1429 * on its behalf.
1430 */
Andrew Lee100e2932014-09-08 15:34:24 -07001431 public final boolean isRingbackRequested() {
1432 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001433 }
1434
1435 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001436 * @return True if the connection's audio mode is VOIP.
1437 */
1438 public final boolean getAudioModeIsVoip() {
1439 return mAudioModeIsVoip;
1440 }
1441
1442 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001443 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1444 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1445 * start time of the conference.
1446 *
1447 * @return The time at which the {@code Connnection} was connected.
1448 *
1449 * @hide
1450 */
1451 public final long getConnectTimeMillis() {
1452 return mConnectTimeMillis;
1453 }
1454
1455 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001456 * @return The status hints for this connection.
1457 */
1458 public final StatusHints getStatusHints() {
1459 return mStatusHints;
1460 }
1461
1462 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001463 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001464 * <p>
1465 * Extras should be updated using {@link #putExtras(Bundle)}.
1466 * <p>
1467 * Telecom or an {@link InCallService} can also update the extras via
1468 * {@link android.telecom.Call#putExtras(Bundle)}, and
1469 * {@link Call#removeExtras(List)}.
1470 * <p>
1471 * The connection is notified of changes to the extras made by Telecom or an
1472 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001473 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001474 * @return The extras associated with this connection.
1475 */
1476 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001477 Bundle extras = null;
1478 synchronized (mExtrasLock) {
1479 if (mExtras != null) {
1480 extras = new Bundle(mExtras);
1481 }
1482 }
1483 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001484 }
1485
1486 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001487 * Assign a listener to be notified of state changes.
1488 *
1489 * @param l A listener.
1490 * @return This Connection.
1491 *
1492 * @hide
1493 */
1494 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001495 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001496 return this;
1497 }
1498
1499 /**
1500 * Remove a previously assigned listener that was being notified of state changes.
1501 *
1502 * @param l A Listener.
1503 * @return This Connection.
1504 *
1505 * @hide
1506 */
1507 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001508 if (l != null) {
1509 mListeners.remove(l);
1510 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001511 return this;
1512 }
1513
1514 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001515 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001516 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001517 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001518 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001519 }
1520
1521 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001522 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1523 * ONLY for debugging purposes.
1524 *
1525 * @param callId The telecom call ID.
1526 * @hide
1527 */
1528 public void setTelecomCallId(String callId) {
1529 mTelecomCallId = callId;
1530 }
1531
1532 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001533 * Inform this Connection that the state of its audio output has been changed externally.
1534 *
1535 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001536 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001537 */
Yorke Lee4af59352015-05-13 14:14:54 -07001538 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001540 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001541 mCallAudioState = state;
1542 onAudioStateChanged(getAudioState());
1543 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001544 }
1545
1546 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001547 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001548 * @return A string representation of the value.
1549 */
1550 public static String stateToString(int state) {
1551 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001553 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001554 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001555 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001557 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001559 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001560 case STATE_PULLING_CALL:
1561 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001563 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001564 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001565 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001567 return "DISCONNECTED";
1568 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001569 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001570 return "UNKNOWN";
1571 }
1572 }
1573
1574 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001575 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001576 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 public final int getConnectionCapabilities() {
1578 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001579 }
1580
1581 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001582 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1583 */
1584 public final int getConnectionProperties() {
1585 return mConnectionProperties;
1586 }
1587
1588 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001589 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001590 *
Andrew Lee100e2932014-09-08 15:34:24 -07001591 * @param address The new address.
1592 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001593 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001594 */
Andrew Lee100e2932014-09-08 15:34:24 -07001595 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001596 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001597 Log.d(this, "setAddress %s", address);
1598 mAddress = address;
1599 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001600 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001601 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001602 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001603 }
1604
1605 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001606 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001607 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001608 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001609 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001610 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001611 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001612 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001613 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001614 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001615 mCallerDisplayName = callerDisplayName;
1616 mCallerDisplayNamePresentation = presentation;
1617 for (Listener l : mListeners) {
1618 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1619 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001620 }
1621
1622 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001623 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001624 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1625 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1626 * {@link VideoProfile#STATE_TX_ENABLED},
1627 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001628 *
1629 * @param videoState The new video state.
1630 */
1631 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001632 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001633 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001634 mVideoState = videoState;
1635 for (Listener l : mListeners) {
1636 l.onVideoStateChanged(this, mVideoState);
1637 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001638 }
1639
1640 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001641 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001642 * communicate).
1643 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001644 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001645 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001646 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001647 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001648 }
1649
1650 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001651 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001652 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001653 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001654 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001655 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001656 }
1657
1658 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001659 * Sets state to initializing (this Connection is not yet ready to be used).
1660 */
1661 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001662 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001663 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001664 }
1665
1666 /**
1667 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1668 */
1669 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001670 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001671 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001672 }
1673
1674 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001675 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001676 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001677 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001678 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001679 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680 }
1681
1682 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001683 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1684 * device). Only applicable for {@link Connection}s with
1685 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1686 */
1687 public final void setPulling() {
1688 checkImmutable();
1689 setState(STATE_PULLING_CALL);
1690 }
1691
1692 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001693 * Sets state to be on hold.
1694 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001695 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001696 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001697 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001698 }
1699
1700 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001701 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001702 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001703 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001704 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001705 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001706 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001707 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001708 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001709 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001710 }
1711
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001712 public final VideoProvider getVideoProvider() {
1713 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001714 }
1715
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001716 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001717 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001719 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001720 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001721 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001722 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001723 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001724 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001725 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001726 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001727 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001728 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001729 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001730 }
1731
1732 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001733 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1734 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1735 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1736 * to send an {@link #onPostDialContinue(boolean)} signal.
1737 *
1738 * @param remaining The DTMF character sequence remaining to be emitted once the
1739 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1740 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001741 */
1742 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001743 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001744 for (Listener l : mListeners) {
1745 l.onPostDialWait(this, remaining);
1746 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001747 }
1748
1749 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001750 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1751 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001752 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001753 *
1754 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001755 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001756 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001757 checkImmutable();
1758 for (Listener l : mListeners) {
1759 l.onPostDialChar(this, nextChar);
1760 }
1761 }
1762
1763 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001764 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001765 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001766 *
1767 * @param ringback Whether the ringback tone is to be played.
1768 */
Andrew Lee100e2932014-09-08 15:34:24 -07001769 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001770 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001771 if (mRingbackRequested != ringback) {
1772 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001773 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001774 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001775 }
1776 }
Ihab Awadf8358972014-05-28 16:46:42 -07001777 }
1778
1779 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001780 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001781 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001782 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001783 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001784 public final void setConnectionCapabilities(int connectionCapabilities) {
1785 checkImmutable();
1786 if (mConnectionCapabilities != connectionCapabilities) {
1787 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001788 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001789 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001790 }
1791 }
Santos Cordonb6939982014-06-04 20:20:58 -07001792 }
1793
1794 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001795 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1796 *
1797 * @param connectionProperties The new connection properties.
1798 */
1799 public final void setConnectionProperties(int connectionProperties) {
1800 checkImmutable();
1801 if (mConnectionProperties != connectionProperties) {
1802 mConnectionProperties = connectionProperties;
1803 for (Listener l : mListeners) {
1804 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1805 }
1806 }
1807 }
1808
1809 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001810 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001811 */
Evan Charlton36a71342014-07-19 16:31:02 -07001812 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001813 for (Listener l : mListeners) {
1814 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001815 }
Santos Cordonb6939982014-06-04 20:20:58 -07001816 }
1817
1818 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001819 * Requests that the framework use VOIP audio mode for this connection.
1820 *
1821 * @param isVoip True if the audio mode is VOIP.
1822 */
1823 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001824 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001825 mAudioModeIsVoip = isVoip;
1826 for (Listener l : mListeners) {
1827 l.onAudioModeIsVoipChanged(this, isVoip);
1828 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001829 }
1830
1831 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001832 * Sets the time at which a call became active on this Connection. This is set only
1833 * when a conference call becomes active on this connection.
1834 *
1835 * @param connectionTimeMillis The connection time, in milliseconds.
1836 *
1837 * @hide
1838 */
1839 public final void setConnectTimeMillis(long connectTimeMillis) {
1840 mConnectTimeMillis = connectTimeMillis;
1841 }
1842
1843 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001844 * Sets the label and icon status to display in the in-call UI.
1845 *
1846 * @param statusHints The status label and icon to set.
1847 */
1848 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001849 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001850 mStatusHints = statusHints;
1851 for (Listener l : mListeners) {
1852 l.onStatusHintsChanged(this, statusHints);
1853 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001854 }
1855
1856 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001857 * Sets the connections with which this connection can be conferenced.
1858 *
1859 * @param conferenceableConnections The set of connections this connection can conference with.
1860 */
1861 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001862 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001863 clearConferenceableList();
1864 for (Connection c : conferenceableConnections) {
1865 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1866 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001867 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001868 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001869 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001870 }
1871 }
1872 fireOnConferenceableConnectionsChanged();
1873 }
1874
1875 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001876 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1877 * or conferences with which this connection can be conferenced.
1878 *
1879 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001880 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001881 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001882 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001883 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001884 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1885 // small amount of items here.
1886 if (!mConferenceables.contains(c)) {
1887 if (c instanceof Connection) {
1888 Connection connection = (Connection) c;
1889 connection.addConnectionListener(mConnectionDeathListener);
1890 } else if (c instanceof Conference) {
1891 Conference conference = (Conference) c;
1892 conference.addListener(mConferenceDeathListener);
1893 }
1894 mConferenceables.add(c);
1895 }
1896 }
1897 fireOnConferenceableConnectionsChanged();
1898 }
1899
1900 /**
1901 * Returns the connections or conferences with which this connection can be conferenced.
1902 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001903 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001904 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001905 }
1906
Yorke Lee53463962015-08-04 16:07:19 -07001907 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001908 * @hide
1909 */
1910 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001911 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001912 if (mConnectionService != null) {
1913 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1914 "which is already associated with another ConnectionService.");
1915 } else {
1916 mConnectionService = connectionService;
1917 }
1918 }
1919
1920 /**
1921 * @hide
1922 */
1923 public final void unsetConnectionService(ConnectionService connectionService) {
1924 if (mConnectionService != connectionService) {
1925 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1926 "that does not belong to the ConnectionService.");
1927 } else {
1928 mConnectionService = null;
1929 }
1930 }
1931
1932 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001933 * @hide
1934 */
1935 public final ConnectionService getConnectionService() {
1936 return mConnectionService;
1937 }
1938
1939 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001940 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001941 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001942 *
1943 * @param conference The conference.
1944 * @return {@code true} if the conference was successfully set.
1945 * @hide
1946 */
1947 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001948 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001949 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001950 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001951 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001952 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1953 fireConferenceChanged();
1954 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001955 return true;
1956 }
1957 return false;
1958 }
1959
1960 /**
1961 * Resets the conference that this connection is a part of.
1962 * @hide
1963 */
1964 public final void resetConference() {
1965 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001966 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001967 mConference = null;
1968 fireConferenceChanged();
1969 }
1970 }
1971
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001972 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001973 * Set some extras that can be associated with this {@code Connection}.
1974 * <p>
1975 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1976 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1977 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001978 * Alternatively you may use the {@link #putExtras(Bundle)}, and
1979 * {@link #removeExtras(String...)} methods to modify the extras.
1980 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07001981 * 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 -07001982 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1983 *
1984 * @param extras The extras associated with this {@code Connection}.
1985 */
1986 public final void setExtras(@Nullable Bundle extras) {
1987 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001988
1989 // Add/replace any new or changed extras values.
1990 putExtras(extras);
1991
1992 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1993 // the current one and remove any keys that went away.
1994 if (mPreviousExtraKeys != null) {
1995 List<String> toRemove = new ArrayList<String>();
1996 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001997 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001998 toRemove.add(oldKey);
1999 }
2000 }
2001 if (!toRemove.isEmpty()) {
2002 removeExtras(toRemove);
2003 }
2004 }
2005
2006 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2007 // called we can see if the caller has removed any extras values.
2008 if (mPreviousExtraKeys == null) {
2009 mPreviousExtraKeys = new ArraySet<String>();
2010 }
2011 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002012 if (extras != null) {
2013 mPreviousExtraKeys.addAll(extras.keySet());
2014 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002015 }
2016
2017 /**
2018 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2019 * added.
2020 * <p>
2021 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2022 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2023 *
2024 * @param extras The extras to add.
2025 */
2026 public final void putExtras(@NonNull Bundle extras) {
2027 checkImmutable();
2028 if (extras == null) {
2029 return;
2030 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002031 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2032 // the listeners.
2033 Bundle listenerExtras;
2034 synchronized (mExtrasLock) {
2035 if (mExtras == null) {
2036 mExtras = new Bundle();
2037 }
2038 mExtras.putAll(extras);
2039 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002040 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002041 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002042 // Create a new clone of the extras for each listener so that they don't clobber
2043 // each other
2044 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002045 }
2046 }
2047
2048 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002049 * Adds a boolean extra to this {@code Connection}.
2050 *
2051 * @param key The extra key.
2052 * @param value The value.
2053 * @hide
2054 */
2055 public final void putExtra(String key, boolean value) {
2056 Bundle newExtras = new Bundle();
2057 newExtras.putBoolean(key, value);
2058 putExtras(newExtras);
2059 }
2060
2061 /**
2062 * Adds an integer extra to this {@code Connection}.
2063 *
2064 * @param key The extra key.
2065 * @param value The value.
2066 * @hide
2067 */
2068 public final void putExtra(String key, int value) {
2069 Bundle newExtras = new Bundle();
2070 newExtras.putInt(key, value);
2071 putExtras(newExtras);
2072 }
2073
2074 /**
2075 * Adds a string extra to this {@code Connection}.
2076 *
2077 * @param key The extra key.
2078 * @param value The value.
2079 * @hide
2080 */
2081 public final void putExtra(String key, String value) {
2082 Bundle newExtras = new Bundle();
2083 newExtras.putString(key, value);
2084 putExtras(newExtras);
2085 }
2086
2087 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002088 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002089 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002090 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002091 */
2092 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002093 synchronized (mExtrasLock) {
2094 if (mExtras != null) {
2095 for (String key : keys) {
2096 mExtras.remove(key);
2097 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002098 }
2099 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002100 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002101 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002102 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002103 }
2104 }
2105
2106 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002107 * Removes extras from this {@code Connection}.
2108 *
2109 * @param keys The keys of the extras to remove.
2110 */
2111 public final void removeExtras(String ... keys) {
2112 removeExtras(Arrays.asList(keys));
2113 }
2114
2115 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002116 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002117 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002119 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2120 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002121 */
Yorke Lee4af59352015-05-13 14:14:54 -07002122 @SystemApi
2123 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002124 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002125
2126 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002127 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2128 *
2129 * @param state The new connection audio state.
2130 */
2131 public void onCallAudioStateChanged(CallAudioState state) {}
2132
2133 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002134 * Notifies this Connection of an internal state change. This method is called after the
2135 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002136 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002137 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002138 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002139 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002140
2141 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002142 * Notifies this Connection of a request to play a DTMF tone.
2143 *
2144 * @param c A DTMF character.
2145 */
Santos Cordonf2951102014-07-20 19:06:29 -07002146 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002147
2148 /**
2149 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2150 */
Santos Cordonf2951102014-07-20 19:06:29 -07002151 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002152
2153 /**
2154 * Notifies this Connection of a request to disconnect.
2155 */
Santos Cordonf2951102014-07-20 19:06:29 -07002156 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002157
2158 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002159 * Notifies this Connection of a request to disconnect a participant of the conference managed
2160 * by the connection.
2161 *
2162 * @param endpoint the {@link Uri} of the participant to disconnect.
2163 * @hide
2164 */
2165 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2166
2167 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002168 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002169 */
Santos Cordonf2951102014-07-20 19:06:29 -07002170 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002171
2172 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002173 * Notifies this Connection of a request to abort.
2174 */
Santos Cordonf2951102014-07-20 19:06:29 -07002175 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176
2177 /**
2178 * Notifies this Connection of a request to hold.
2179 */
Santos Cordonf2951102014-07-20 19:06:29 -07002180 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002181
2182 /**
2183 * Notifies this Connection of a request to exit a hold state.
2184 */
Santos Cordonf2951102014-07-20 19:06:29 -07002185 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002186
2187 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002188 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002189 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002190 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002191 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002192 */
Santos Cordonf2951102014-07-20 19:06:29 -07002193 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002194
2195 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002196 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002197 * a request to accept.
2198 */
2199 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002200 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002201 }
2202
2203 /**
2204 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002205 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002206 */
Santos Cordonf2951102014-07-20 19:06:29 -07002207 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002208
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002209 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002210 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2211 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002212 */
2213 public void onReject(String replyMessage) {}
2214
2215 /**
Bryce Leecac50772015-11-17 15:13:29 -08002216 * Notifies the Connection of a request to silence the ringer.
2217 *
2218 * @hide
2219 */
2220 public void onSilence() {}
2221
2222 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002223 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2224 */
Santos Cordonf2951102014-07-20 19:06:29 -07002225 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002226
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002227 /**
2228 * Notifies this Connection of a request to pull an external call to the local device.
2229 * <p>
2230 * The {@link InCallService} issues a request to pull an external call to the local device via
2231 * {@link Call#pullExternalCall()}.
2232 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002233 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2234 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002235 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002236 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002237 */
2238 public void onPullExternalCall() {}
2239
2240 /**
2241 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2242 * <p>
2243 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2244 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002245 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2246 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2247 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2248 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2249 * not aware of.
2250 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002251 * See also {@link Call#sendCallEvent(String, Bundle)}.
2252 *
2253 * @param event The call event.
2254 * @param extras Extras associated with the call event.
2255 */
2256 public void onCallEvent(String event, Bundle extras) {}
2257
Tyler Gunndee56a82016-03-23 16:06:34 -07002258 /**
2259 * Notifies this {@link Connection} of a change to the extras made outside the
2260 * {@link ConnectionService}.
2261 * <p>
2262 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2263 * the {@link android.telecom.Call#putExtras(Bundle)} and
2264 * {@link Call#removeExtras(List)}.
2265 *
2266 * @param extras The new extras bundle.
2267 */
2268 public void onExtrasChanged(Bundle extras) {}
2269
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002270 static String toLogSafePhoneNumber(String number) {
2271 // For unknown number, log empty string.
2272 if (number == null) {
2273 return "";
2274 }
2275
2276 if (PII_DEBUG) {
2277 // When PII_DEBUG is true we emit PII.
2278 return number;
2279 }
2280
2281 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2282 // sanitized phone numbers.
2283 StringBuilder builder = new StringBuilder();
2284 for (int i = 0; i < number.length(); i++) {
2285 char c = number.charAt(i);
2286 if (c == '-' || c == '@' || c == '.') {
2287 builder.append(c);
2288 } else {
2289 builder.append('x');
2290 }
2291 }
2292 return builder.toString();
2293 }
2294
Ihab Awad542e0ea2014-05-16 10:22:16 -07002295 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002296 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002297 if (mState == STATE_DISCONNECTED && mState != state) {
2298 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002299 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002300 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002301 if (mState != state) {
2302 Log.d(this, "setState: %s", stateToString(state));
2303 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002304 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002305 for (Listener l : mListeners) {
2306 l.onStateChanged(this, state);
2307 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002308 }
2309 }
2310
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002311 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002312 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002313 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2314 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002315 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002316 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002317
2318 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002319 if (mImmutable) {
2320 throw new UnsupportedOperationException("Connection is immutable");
2321 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002322 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002323 }
2324
Evan Charltonbf11f982014-07-20 22:06:28 -07002325 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002326 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002327 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2328 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002329 * <p>
2330 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2331 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002332 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002333 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002334 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002335 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002336 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2337 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002338 }
2339
Evan Charltonbf11f982014-07-20 22:06:28 -07002340 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002341 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2342 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2343 * this should never be un-@hide-den.
2344 *
2345 * @hide
2346 */
2347 public void checkImmutable() {}
2348
2349 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002350 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2351 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2352 * that state. This connection should not be used for anything, and no other
2353 * {@code Connection}s should be attempted.
2354 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002355 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002356 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002357 * @return A {@code Connection} which indicates that the underlying connection should
2358 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002359 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002360 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002361 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002362 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002363
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002364 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002365 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002366 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002367 }
2368 }
2369
Santos Cordon823fd3c2014-08-07 18:35:18 -07002370 private final void fireConferenceChanged() {
2371 for (Listener l : mListeners) {
2372 l.onConferenceChanged(this, mConference);
2373 }
2374 }
2375
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002376 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002377 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002378 if (c instanceof Connection) {
2379 Connection connection = (Connection) c;
2380 connection.removeConnectionListener(mConnectionDeathListener);
2381 } else if (c instanceof Conference) {
2382 Conference conference = (Conference) c;
2383 conference.removeListener(mConferenceDeathListener);
2384 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002385 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002386 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002387 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002388
2389 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002390 * Handles a change to extras received from Telecom.
2391 *
2392 * @param extras The new extras.
2393 * @hide
2394 */
2395 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002396 Bundle b = null;
2397 synchronized (mExtrasLock) {
2398 mExtras = extras;
2399 if (mExtras != null) {
2400 b = new Bundle(mExtras);
2401 }
2402 }
2403 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002404 }
2405
2406 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002407 * Notifies listeners that the merge request failed.
2408 *
2409 * @hide
2410 */
2411 protected final void notifyConferenceMergeFailed() {
2412 for (Listener l : mListeners) {
2413 l.onConferenceMergeFailed(this);
2414 }
2415 }
2416
2417 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002418 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002419 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002420 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002421 * @hide
2422 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002423 protected final void updateConferenceParticipants(
2424 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002425 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002426 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002427 }
2428 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002429
2430 /**
2431 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002432 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002433 */
2434 protected void notifyConferenceStarted() {
2435 for (Listener l : mListeners) {
2436 l.onConferenceStarted();
2437 }
2438 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002439
2440 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002441 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2442 * be a part of a conference call.
2443 * @param isConferenceSupported {@code true} if the connection supports being part of a
2444 * conference call, {@code false} otherwise.
2445 * @hide
2446 */
2447 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2448 for (Listener l : mListeners) {
2449 l.onConferenceSupportedChanged(this, isConferenceSupported);
2450 }
2451 }
2452
2453 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002454 * Sends an event associated with this {@code Connection} with associated event extras to the
2455 * {@link InCallService}.
2456 * <p>
2457 * Connection events are used to communicate point in time information from a
2458 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2459 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2460 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2461 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2462 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2463 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2464 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2465 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2466 * <p>
2467 * Events are exposed to {@link InCallService} implementations via
2468 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2469 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002470 * 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 -07002471 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2472 * some events altogether.
2473 * <p>
2474 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2475 * conflicts between {@link ConnectionService} implementations. Further, custom
2476 * {@link ConnectionService} implementations shall not re-purpose events in the
2477 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2478 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2479 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2480 * {@code com.example.extra.MY_EXTRA}).
2481 * <p>
2482 * When defining events and the associated extras, it is important to keep their behavior
2483 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2484 * events/extras should me maintained to ensure backwards compatibility with older
2485 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002486 *
2487 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002488 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002489 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002490 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002491 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002492 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002493 }
2494 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002495}