blob: 4da5ff28204e61e7ed9031cc460077f9fb65c222 [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) {
Santos Cordon1a749302016-07-26 16:08:53 -0700517 return capabilitiesToStringInternal(capabilities, true /* isLong */);
518 }
519
520 /**
521 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
522 * string.
523 *
524 * @param capabilities A capability bit field.
525 * @return A human readable string representation.
526 * @hide
527 */
528 public static String capabilitiesToStringShort(int capabilities) {
529 return capabilitiesToStringInternal(capabilities, false /* isLong */);
530 }
531
532 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800533 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700534 builder.append("[");
535 if (isLong) {
536 builder.append("Capabilities:");
537 }
538
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800539 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700540 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800541 }
542 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700543 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800544 }
545 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700546 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800547 }
548 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700549 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 }
551 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700552 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800553 }
554 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700555 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 }
557 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700558 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800559 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700560 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700561 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700562 }
563 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700564 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700565 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700566 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700567 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800568 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700569 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700570 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700571 }
572 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700573 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700574 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700575 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700576 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800577 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800578 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700579 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800580 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500581 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700582 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500583 }
Rekha Kumar07366812015-03-24 16:42:31 -0700584 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700585 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700586 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700587 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700588 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700589 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700590 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700591 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700592 }
Bryce Lee81901682015-08-28 16:38:02 -0700593 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700594 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700595 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700596 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700597 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700598 }
Bryce Lee81901682015-08-28 16:38:02 -0700599
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800600 builder.append("]");
601 return builder.toString();
602 }
603
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700604 /**
605 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
606 *
607 * @param properties A property bit field.
608 * @return A human readable string representation.
609 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700610 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700611 return propertiesToStringInternal(properties, true /* isLong */);
612 }
613
614 /**
615 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
616 *
617 * @param properties A property bit field.
618 * @return A human readable string representation.
619 * @hide
620 */
621 public static String propertiesToStringShort(int properties) {
622 return propertiesToStringInternal(properties, false /* isLong */);
623 }
624
625 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700626 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700627 builder.append("[");
628 if (isLong) {
629 builder.append("Properties:");
630 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700631
632 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700633 builder.append(isLong ? " PROPERTY_SHOW_CALLBACK_NUMBER" : " clbk");
Tyler Gunn720c6642016-03-22 09:02:47 -0700634 }
635
636 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700637 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700638 }
639
640 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700641 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700642 }
643
644 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700645 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700646 }
647
648 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700649 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700650 }
651
Brad Ebinger15847072016-05-18 11:08:36 -0700652 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700653 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700654 }
655
Tyler Gunn720c6642016-03-22 09:02:47 -0700656 builder.append("]");
657 return builder.toString();
658 }
659
Sailesh Nepal091768c2014-06-30 15:15:23 -0700660 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700661 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700662 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700663 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700664 public void onCallerDisplayNameChanged(
665 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700666 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700667 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700668 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800669 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700670 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700671 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800672 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700673 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700674 public void onVideoProviderChanged(
675 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700676 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
677 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800678 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700679 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700680 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700681 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800682 public void onConferenceParticipantsChanged(Connection c,
683 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800684 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700685 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700686 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700687 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700688 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700689 /** @hide */
690 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700691 }
692
Tyler Gunnb702ef82015-05-29 11:51:53 -0700693 /**
694 * Provides a means of controlling the video session associated with a {@link Connection}.
695 * <p>
696 * Implementations create a custom subclass of {@link VideoProvider} and the
697 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
698 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
699 * should set the {@link VideoProvider}.
700 * <p>
701 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
702 * {@link InCallService} implementations to issue requests related to the video session;
703 * it provides a means for the {@link ConnectionService} to report events and information
704 * related to the video session to Telecom and the {@link InCallService} implementations.
705 * <p>
706 * {@link InCallService} implementations interact with the {@link VideoProvider} via
707 * {@link android.telecom.InCallService.VideoCall}.
708 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700710
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 /**
712 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700713 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700714 */
715 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700716
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700717 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700718 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
719 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 */
721 public static final int SESSION_EVENT_RX_RESUME = 2;
722
723 /**
724 * Video transmission has begun. This occurs after a negotiated start of video transmission
725 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700726 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 */
728 public static final int SESSION_EVENT_TX_START = 3;
729
730 /**
731 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
732 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700733 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 */
735 public static final int SESSION_EVENT_TX_STOP = 4;
736
737 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700738 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
739 * this as a cue to inform the user the camera is not available.
740 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700741 */
742 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
743
744 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700745 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
746 * for operation. The {@link InCallService} can use this as a cue to inform the user that
747 * the camera has become available again.
748 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 */
750 public static final int SESSION_EVENT_CAMERA_READY = 6;
751
752 /**
753 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700754 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700755 */
756 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
757
758 /**
759 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700760 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 */
762 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
763
764 /**
765 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700766 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700767 */
768 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
769
Rekha Kumar07366812015-03-24 16:42:31 -0700770 /**
771 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700772 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700773 */
774 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
775
776 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700777 * Session modify request rejected by remote user.
778 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700779 */
780 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
781
Tyler Gunn75958422015-04-15 14:23:42 -0700782 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700783 private static final int MSG_SET_CAMERA = 2;
784 private static final int MSG_SET_PREVIEW_SURFACE = 3;
785 private static final int MSG_SET_DISPLAY_SURFACE = 4;
786 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
787 private static final int MSG_SET_ZOOM = 6;
788 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
789 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
790 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800791 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700793 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700794
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700795 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700797
798 /**
799 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700800 *
801 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
802 * load factor before resizing, 1 means we only expect a single thread to
803 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700804 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700805 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
806 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700807
808 /**
809 * Default handler used to consolidate binder method calls onto a single thread.
810 */
811 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700812 public VideoProviderHandler() {
813 super();
814 }
815
816 public VideoProviderHandler(Looper looper) {
817 super(looper);
818 }
819
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 @Override
821 public void handleMessage(Message msg) {
822 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700823 case MSG_ADD_VIDEO_CALLBACK: {
824 IBinder binder = (IBinder) msg.obj;
825 IVideoCallback callback = IVideoCallback.Stub
826 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700827 if (callback == null) {
828 Log.w(this, "addVideoProvider - skipped; callback is null.");
829 break;
830 }
831
Tyler Gunn75958422015-04-15 14:23:42 -0700832 if (mVideoCallbacks.containsKey(binder)) {
833 Log.i(this, "addVideoProvider - skipped; already present.");
834 break;
835 }
836 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700838 }
839 case MSG_REMOVE_VIDEO_CALLBACK: {
840 IBinder binder = (IBinder) msg.obj;
841 IVideoCallback callback = IVideoCallback.Stub
842 .asInterface((IBinder) msg.obj);
843 if (!mVideoCallbacks.containsKey(binder)) {
844 Log.i(this, "removeVideoProvider - skipped; not present.");
845 break;
846 }
847 mVideoCallbacks.remove(binder);
848 break;
849 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700850 case MSG_SET_CAMERA:
851 onSetCamera((String) msg.obj);
852 break;
853 case MSG_SET_PREVIEW_SURFACE:
854 onSetPreviewSurface((Surface) msg.obj);
855 break;
856 case MSG_SET_DISPLAY_SURFACE:
857 onSetDisplaySurface((Surface) msg.obj);
858 break;
859 case MSG_SET_DEVICE_ORIENTATION:
860 onSetDeviceOrientation(msg.arg1);
861 break;
862 case MSG_SET_ZOOM:
863 onSetZoom((Float) msg.obj);
864 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700865 case MSG_SEND_SESSION_MODIFY_REQUEST: {
866 SomeArgs args = (SomeArgs) msg.obj;
867 try {
868 onSendSessionModifyRequest((VideoProfile) args.arg1,
869 (VideoProfile) args.arg2);
870 } finally {
871 args.recycle();
872 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700873 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700874 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 case MSG_SEND_SESSION_MODIFY_RESPONSE:
876 onSendSessionModifyResponse((VideoProfile) msg.obj);
877 break;
878 case MSG_REQUEST_CAMERA_CAPABILITIES:
879 onRequestCameraCapabilities();
880 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800881 case MSG_REQUEST_CONNECTION_DATA_USAGE:
882 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 break;
884 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700885 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 break;
887 default:
888 break;
889 }
890 }
891 }
892
893 /**
894 * IVideoProvider stub implementation.
895 */
896 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700897 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700898 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700899 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
900 }
901
902 public void removeVideoCallback(IBinder videoCallbackBinder) {
903 mMessageHandler.obtainMessage(
904 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 }
906
907 public void setCamera(String cameraId) {
908 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
909 }
910
911 public void setPreviewSurface(Surface surface) {
912 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
913 }
914
915 public void setDisplaySurface(Surface surface) {
916 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
917 }
918
919 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700920 mMessageHandler.obtainMessage(
921 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700922 }
923
924 public void setZoom(float value) {
925 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
926 }
927
Tyler Gunn45382162015-05-06 08:52:27 -0700928 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
929 SomeArgs args = SomeArgs.obtain();
930 args.arg1 = fromProfile;
931 args.arg2 = toProfile;
932 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700933 }
934
935 public void sendSessionModifyResponse(VideoProfile responseProfile) {
936 mMessageHandler.obtainMessage(
937 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
938 }
939
940 public void requestCameraCapabilities() {
941 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
942 }
943
944 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800945 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700946 }
947
Yorke Lee32f24732015-05-12 16:18:03 -0700948 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
950 }
951 }
952
953 public VideoProvider() {
954 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700955 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700956 }
957
958 /**
959 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
960 *
961 * @param looper The looper.
962 * @hide
963 */
964 public VideoProvider(Looper looper) {
965 mBinder = new VideoProvider.VideoProviderBinder();
966 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 }
968
969 /**
970 * Returns binder object which can be used across IPC methods.
971 * @hide
972 */
973 public final IVideoProvider getInterface() {
974 return mBinder;
975 }
976
977 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700978 * Sets the camera to be used for the outgoing video.
979 * <p>
980 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
981 * camera via
982 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
983 * <p>
984 * Sent from the {@link InCallService} via
985 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 * @param cameraId The id of the camera (use ids as reported by
988 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 */
990 public abstract void onSetCamera(String cameraId);
991
992 /**
993 * Sets the surface to be used for displaying a preview of what the user's camera is
994 * currently capturing. When video transmission is enabled, this is the video signal which
995 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700996 * <p>
997 * Sent from the {@link InCallService} via
998 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700999 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001000 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 */
1002 public abstract void onSetPreviewSurface(Surface surface);
1003
1004 /**
1005 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * <p>
1007 * Sent from the {@link InCallService} via
1008 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001010 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
1012 public abstract void onSetDisplaySurface(Surface surface);
1013
1014 /**
1015 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1016 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001017 * <p>
1018 * Sent from the {@link InCallService} via
1019 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 *
1021 * @param rotation The device orientation, in degrees.
1022 */
1023 public abstract void onSetDeviceOrientation(int rotation);
1024
1025 /**
1026 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001027 * <p>
1028 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 *
1030 * @param value The camera zoom ratio.
1031 */
1032 public abstract void onSetZoom(float value);
1033
1034 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * Issues a request to modify the properties of the current video session.
1036 * <p>
1037 * Example scenarios include: requesting an audio-only call to be upgraded to a
1038 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1039 * when the {@link InCallService} is no longer the foreground application.
1040 * <p>
1041 * If the {@link VideoProvider} determines a request to be invalid, it should call
1042 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1043 * invalid request back to the {@link InCallService}.
1044 * <p>
1045 * Where a request requires confirmation from the user of the peer device, the
1046 * {@link VideoProvider} must communicate the request to the peer device and handle the
1047 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1048 * is used to inform the {@link InCallService} of the result of the request.
1049 * <p>
1050 * Sent from the {@link InCallService} via
1051 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001053 * @param fromProfile The video profile prior to the request.
1054 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001055 */
Tyler Gunn45382162015-05-06 08:52:27 -07001056 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1057 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001058
Tyler Gunnb702ef82015-05-29 11:51:53 -07001059 /**
1060 * Provides a response to a request to change the current video session properties.
1061 * <p>
1062 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1063 * video call, could decline the request and keep the call as audio-only.
1064 * In such a scenario, the {@code responseProfile} would have a video state of
1065 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1066 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1067 * <p>
1068 * Sent from the {@link InCallService} via
1069 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1070 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1071 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001073 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 */
1075 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1076
1077 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001078 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1079 * <p>
1080 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1081 * camera via
1082 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1083 * <p>
1084 * Sent from the {@link InCallService} via
1085 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 */
1087 public abstract void onRequestCameraCapabilities();
1088
1089 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001090 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1091 * video component of the current {@link Connection}.
1092 * <p>
1093 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1094 * via {@link VideoProvider#setCallDataUsage(long)}.
1095 * <p>
1096 * Sent from the {@link InCallService} via
1097 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001099 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001100
1101 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001102 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1103 * the peer device when the video signal is paused.
1104 * <p>
1105 * Sent from the {@link InCallService} via
1106 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 *
1108 * @param uri URI of image to display.
1109 */
Yorke Lee32f24732015-05-12 16:18:03 -07001110 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111
1112 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001113 * Used to inform listening {@link InCallService} implementations when the
1114 * {@link VideoProvider} receives a session modification request.
1115 * <p>
1116 * Received by the {@link InCallService} via
1117 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001119 * @param videoProfile The requested video profile.
1120 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 */
1122 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001123 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001124 for (IVideoCallback callback : mVideoCallbacks.values()) {
1125 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001126 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001127 } catch (RemoteException ignored) {
1128 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001129 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 }
1131 }
1132 }
1133
1134 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001135 * Used to inform listening {@link InCallService} implementations when the
1136 * {@link VideoProvider} receives a response to a session modification request.
1137 * <p>
1138 * Received by the {@link InCallService} via
1139 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1140 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 *
1142 * @param status Status of the session modify request. Valid values are
1143 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1144 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001145 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1146 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1147 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1148 * @param requestedProfile The original request which was sent to the peer device.
1149 * @param responseProfile The actual profile changes agreed to by the peer device.
1150 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 */
1152 public void receiveSessionModifyResponse(int status,
1153 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001154 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001155 for (IVideoCallback callback : mVideoCallbacks.values()) {
1156 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001157 callback.receiveSessionModifyResponse(status, requestedProfile,
1158 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001159 } catch (RemoteException ignored) {
1160 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001161 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001162 }
1163 }
1164 }
1165
1166 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001167 * Used to inform listening {@link InCallService} implementations when the
1168 * {@link VideoProvider} reports a call session event.
1169 * <p>
1170 * Received by the {@link InCallService} via
1171 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001173 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1174 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1175 * {@link VideoProvider#SESSION_EVENT_TX_START},
1176 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1177 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1178 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 */
1180 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001181 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001182 for (IVideoCallback callback : mVideoCallbacks.values()) {
1183 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001184 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001185 } catch (RemoteException ignored) {
1186 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001187 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001188 }
1189 }
1190 }
1191
1192 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001193 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1194 * peer's video have changed.
1195 * <p>
1196 * This could occur if, for example, the peer rotates their device, changing the aspect
1197 * ratio of the video, or if the user switches between the back and front cameras.
1198 * <p>
1199 * Received by the {@link InCallService} via
1200 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 *
1202 * @param width The updated peer video width.
1203 * @param height The updated peer video height.
1204 */
1205 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001206 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001207 for (IVideoCallback callback : mVideoCallbacks.values()) {
1208 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001209 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001210 } catch (RemoteException ignored) {
1211 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001212 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 }
1214 }
1215 }
1216
1217 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001218 * Used to inform listening {@link InCallService} implementations when the data usage of the
1219 * video associated with the current {@link Connection} has changed.
1220 * <p>
1221 * This could be in response to a preview request via
1222 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001223 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1224 * 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 -07001225 * <p>
1226 * Received by the {@link InCallService} via
1227 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001229 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1230 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001231 */
Yorke Lee32f24732015-05-12 16:18:03 -07001232 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001233 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001234 for (IVideoCallback callback : mVideoCallbacks.values()) {
1235 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001236 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001237 } catch (RemoteException ignored) {
1238 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001239 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 }
1241 }
1242 }
1243
1244 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001245 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001247 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001248 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1249 * @hide
1250 */
1251 public void changeCallDataUsage(long dataUsage) {
1252 setCallDataUsage(dataUsage);
1253 }
1254
1255 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001256 * Used to inform listening {@link InCallService} implementations when the capabilities of
1257 * the current camera have changed.
1258 * <p>
1259 * The {@link VideoProvider} should call this in response to
1260 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1261 * changed via {@link VideoProvider#onSetCamera(String)}.
1262 * <p>
1263 * Received by the {@link InCallService} via
1264 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1265 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001266 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001267 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001268 */
Yorke Lee400470f2015-05-12 13:31:25 -07001269 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001270 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001271 for (IVideoCallback callback : mVideoCallbacks.values()) {
1272 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001273 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001274 } catch (RemoteException ignored) {
1275 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001276 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 }
1278 }
1279 }
Rekha Kumar07366812015-03-24 16:42:31 -07001280
1281 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * Used to inform listening {@link InCallService} implementations when the video quality
1283 * of the call has changed.
1284 * <p>
1285 * Received by the {@link InCallService} via
1286 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001287 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001288 * @param videoQuality The updated video quality. Valid values:
1289 * {@link VideoProfile#QUALITY_HIGH},
1290 * {@link VideoProfile#QUALITY_MEDIUM},
1291 * {@link VideoProfile#QUALITY_LOW},
1292 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001293 */
1294 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001295 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001296 for (IVideoCallback callback : mVideoCallbacks.values()) {
1297 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001298 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001299 } catch (RemoteException ignored) {
1300 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001301 }
Rekha Kumar07366812015-03-24 16:42:31 -07001302 }
1303 }
1304 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001305 }
1306
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001307 private final Listener mConnectionDeathListener = new Listener() {
1308 @Override
1309 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001310 if (mConferenceables.remove(c)) {
1311 fireOnConferenceableConnectionsChanged();
1312 }
1313 }
1314 };
1315
1316 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1317 @Override
1318 public void onDestroyed(Conference c) {
1319 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001320 fireOnConferenceableConnectionsChanged();
1321 }
1322 }
1323 };
1324
Jay Shrauner229e3822014-08-15 09:23:07 -07001325 /**
1326 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1327 * load factor before resizing, 1 means we only expect a single thread to
1328 * access the map so make only a single shard
1329 */
1330 private final Set<Listener> mListeners = Collections.newSetFromMap(
1331 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001332 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1333 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001334 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001335
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001336 // The internal telecom call ID associated with this connection.
1337 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001339 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001340 private Uri mAddress;
1341 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001342 private String mCallerDisplayName;
1343 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001344 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001345 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001346 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001348 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001349 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001350 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001351 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001352 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001353 private Conference mConference;
1354 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001355 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001356 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001357
1358 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001359 * Tracks the key set for the extras bundle provided on the last invocation of
1360 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1361 * keys which were set previously but are no longer present in the replacement Bundle.
1362 */
1363 private Set<String> mPreviousExtraKeys;
1364
1365 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001366 * Create a new Connection.
1367 */
Santos Cordonf2951102014-07-20 19:06:29 -07001368 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001369
1370 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001371 * Returns the Telecom internal call ID associated with this connection. Should only be used
1372 * for debugging and tracing purposes.
1373 *
1374 * @return The Telecom call ID.
1375 * @hide
1376 */
1377 public final String getTelecomCallId() {
1378 return mTelecomCallId;
1379 }
1380
1381 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001382 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001383 */
Andrew Lee100e2932014-09-08 15:34:24 -07001384 public final Uri getAddress() {
1385 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001386 }
1387
1388 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001389 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001390 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001391 */
Andrew Lee100e2932014-09-08 15:34:24 -07001392 public final int getAddressPresentation() {
1393 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001394 }
1395
1396 /**
1397 * @return The caller display name (CNAP).
1398 */
1399 public final String getCallerDisplayName() {
1400 return mCallerDisplayName;
1401 }
1402
1403 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001404 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001405 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001406 */
1407 public final int getCallerDisplayNamePresentation() {
1408 return mCallerDisplayNamePresentation;
1409 }
1410
1411 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001412 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001413 */
1414 public final int getState() {
1415 return mState;
1416 }
1417
1418 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001419 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001420 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1421 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1422 * {@link VideoProfile#STATE_TX_ENABLED},
1423 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001424 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001425 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001426 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001427 */
1428 public final int getVideoState() {
1429 return mVideoState;
1430 }
1431
1432 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001433 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001434 * being routed by the system. This is {@code null} if this Connection
1435 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001436 * @deprecated Use {@link #getCallAudioState()} instead.
1437 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001438 */
Yorke Lee4af59352015-05-13 14:14:54 -07001439 @SystemApi
1440 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001442 if (mCallAudioState == null) {
1443 return null;
1444 }
Yorke Lee4af59352015-05-13 14:14:54 -07001445 return new AudioState(mCallAudioState);
1446 }
1447
1448 /**
1449 * @return The audio state of the connection, describing how its audio is currently
1450 * being routed by the system. This is {@code null} if this Connection
1451 * does not directly know about its audio state.
1452 */
1453 public final CallAudioState getCallAudioState() {
1454 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001455 }
1456
1457 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001458 * @return The conference that this connection is a part of. Null if it is not part of any
1459 * conference.
1460 */
1461 public final Conference getConference() {
1462 return mConference;
1463 }
1464
1465 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001466 * Returns whether this connection is requesting that the system play a ringback tone
1467 * on its behalf.
1468 */
Andrew Lee100e2932014-09-08 15:34:24 -07001469 public final boolean isRingbackRequested() {
1470 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001471 }
1472
1473 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001474 * @return True if the connection's audio mode is VOIP.
1475 */
1476 public final boolean getAudioModeIsVoip() {
1477 return mAudioModeIsVoip;
1478 }
1479
1480 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001481 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1482 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1483 * start time of the conference.
1484 *
1485 * @return The time at which the {@code Connnection} was connected.
1486 *
1487 * @hide
1488 */
1489 public final long getConnectTimeMillis() {
1490 return mConnectTimeMillis;
1491 }
1492
1493 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001494 * @return The status hints for this connection.
1495 */
1496 public final StatusHints getStatusHints() {
1497 return mStatusHints;
1498 }
1499
1500 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001501 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001502 * <p>
1503 * Extras should be updated using {@link #putExtras(Bundle)}.
1504 * <p>
1505 * Telecom or an {@link InCallService} can also update the extras via
1506 * {@link android.telecom.Call#putExtras(Bundle)}, and
1507 * {@link Call#removeExtras(List)}.
1508 * <p>
1509 * The connection is notified of changes to the extras made by Telecom or an
1510 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001511 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001512 * @return The extras associated with this connection.
1513 */
1514 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001515 Bundle extras = null;
1516 synchronized (mExtrasLock) {
1517 if (mExtras != null) {
1518 extras = new Bundle(mExtras);
1519 }
1520 }
1521 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001522 }
1523
1524 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001525 * Assign a listener to be notified of state changes.
1526 *
1527 * @param l A listener.
1528 * @return This Connection.
1529 *
1530 * @hide
1531 */
1532 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001533 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001534 return this;
1535 }
1536
1537 /**
1538 * Remove a previously assigned listener that was being notified of state changes.
1539 *
1540 * @param l A Listener.
1541 * @return This Connection.
1542 *
1543 * @hide
1544 */
1545 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001546 if (l != null) {
1547 mListeners.remove(l);
1548 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001549 return this;
1550 }
1551
1552 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001553 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001554 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001555 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001556 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001557 }
1558
1559 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001560 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1561 * ONLY for debugging purposes.
1562 *
1563 * @param callId The telecom call ID.
1564 * @hide
1565 */
1566 public void setTelecomCallId(String callId) {
1567 mTelecomCallId = callId;
1568 }
1569
1570 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001571 * Inform this Connection that the state of its audio output has been changed externally.
1572 *
1573 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001574 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001575 */
Yorke Lee4af59352015-05-13 14:14:54 -07001576 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001578 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001579 mCallAudioState = state;
1580 onAudioStateChanged(getAudioState());
1581 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001582 }
1583
1584 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001585 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001586 * @return A string representation of the value.
1587 */
1588 public static String stateToString(int state) {
1589 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001590 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001591 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001592 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001593 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001594 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001595 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001596 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001597 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001598 case STATE_PULLING_CALL:
1599 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001601 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001603 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605 return "DISCONNECTED";
1606 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001607 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608 return "UNKNOWN";
1609 }
1610 }
1611
1612 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001613 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001614 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001615 public final int getConnectionCapabilities() {
1616 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001617 }
1618
1619 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001620 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1621 */
1622 public final int getConnectionProperties() {
1623 return mConnectionProperties;
1624 }
1625
1626 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001627 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001628 *
Andrew Lee100e2932014-09-08 15:34:24 -07001629 * @param address The new address.
1630 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001631 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001632 */
Andrew Lee100e2932014-09-08 15:34:24 -07001633 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001634 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001635 Log.d(this, "setAddress %s", address);
1636 mAddress = address;
1637 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001638 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001639 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001640 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001641 }
1642
1643 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001644 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001645 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001646 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001647 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001648 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001649 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001650 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001651 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001652 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001653 mCallerDisplayName = callerDisplayName;
1654 mCallerDisplayNamePresentation = presentation;
1655 for (Listener l : mListeners) {
1656 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1657 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001658 }
1659
1660 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001661 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001662 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1663 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1664 * {@link VideoProfile#STATE_TX_ENABLED},
1665 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001666 *
1667 * @param videoState The new video state.
1668 */
1669 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001670 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001671 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001672 mVideoState = videoState;
1673 for (Listener l : mListeners) {
1674 l.onVideoStateChanged(this, mVideoState);
1675 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001676 }
1677
1678 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001679 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680 * communicate).
1681 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001682 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001683 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001684 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001685 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001686 }
1687
1688 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001689 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001691 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001692 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001693 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001694 }
1695
1696 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001697 * Sets state to initializing (this Connection is not yet ready to be used).
1698 */
1699 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001700 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001701 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001702 }
1703
1704 /**
1705 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1706 */
1707 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001708 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001709 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001710 }
1711
1712 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001713 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001715 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001716 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001717 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 }
1719
1720 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001721 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1722 * device). Only applicable for {@link Connection}s with
1723 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1724 */
1725 public final void setPulling() {
1726 checkImmutable();
1727 setState(STATE_PULLING_CALL);
1728 }
1729
1730 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001731 * Sets state to be on hold.
1732 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001733 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001734 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001735 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736 }
1737
1738 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001739 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001740 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001741 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001742 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001743 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001744 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001745 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001746 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001747 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001748 }
1749
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001750 public final VideoProvider getVideoProvider() {
1751 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001752 }
1753
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001754 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001755 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001756 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001757 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001758 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001759 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001760 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001761 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001762 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001763 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001764 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001765 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001766 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001767 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001768 }
1769
1770 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001771 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1772 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1773 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1774 * to send an {@link #onPostDialContinue(boolean)} signal.
1775 *
1776 * @param remaining The DTMF character sequence remaining to be emitted once the
1777 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1778 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001779 */
1780 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001781 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001782 for (Listener l : mListeners) {
1783 l.onPostDialWait(this, remaining);
1784 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001785 }
1786
1787 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001788 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1789 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001790 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001791 *
1792 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001793 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001794 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001795 checkImmutable();
1796 for (Listener l : mListeners) {
1797 l.onPostDialChar(this, nextChar);
1798 }
1799 }
1800
1801 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001802 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001803 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001804 *
1805 * @param ringback Whether the ringback tone is to be played.
1806 */
Andrew Lee100e2932014-09-08 15:34:24 -07001807 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001808 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001809 if (mRingbackRequested != ringback) {
1810 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001811 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001812 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001813 }
1814 }
Ihab Awadf8358972014-05-28 16:46:42 -07001815 }
1816
1817 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001818 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001819 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001820 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001821 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001822 public final void setConnectionCapabilities(int connectionCapabilities) {
1823 checkImmutable();
1824 if (mConnectionCapabilities != connectionCapabilities) {
1825 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001826 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001827 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001828 }
1829 }
Santos Cordonb6939982014-06-04 20:20:58 -07001830 }
1831
1832 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001833 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1834 *
1835 * @param connectionProperties The new connection properties.
1836 */
1837 public final void setConnectionProperties(int connectionProperties) {
1838 checkImmutable();
1839 if (mConnectionProperties != connectionProperties) {
1840 mConnectionProperties = connectionProperties;
1841 for (Listener l : mListeners) {
1842 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1843 }
1844 }
1845 }
1846
1847 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001848 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001849 */
Evan Charlton36a71342014-07-19 16:31:02 -07001850 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001851 for (Listener l : mListeners) {
1852 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001853 }
Santos Cordonb6939982014-06-04 20:20:58 -07001854 }
1855
1856 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001857 * Requests that the framework use VOIP audio mode for this connection.
1858 *
1859 * @param isVoip True if the audio mode is VOIP.
1860 */
1861 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001862 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001863 mAudioModeIsVoip = isVoip;
1864 for (Listener l : mListeners) {
1865 l.onAudioModeIsVoipChanged(this, isVoip);
1866 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001867 }
1868
1869 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001870 * Sets the time at which a call became active on this Connection. This is set only
1871 * when a conference call becomes active on this connection.
1872 *
1873 * @param connectionTimeMillis The connection time, in milliseconds.
1874 *
1875 * @hide
1876 */
1877 public final void setConnectTimeMillis(long connectTimeMillis) {
1878 mConnectTimeMillis = connectTimeMillis;
1879 }
1880
1881 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001882 * Sets the label and icon status to display in the in-call UI.
1883 *
1884 * @param statusHints The status label and icon to set.
1885 */
1886 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001887 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001888 mStatusHints = statusHints;
1889 for (Listener l : mListeners) {
1890 l.onStatusHintsChanged(this, statusHints);
1891 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001892 }
1893
1894 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001895 * Sets the connections with which this connection can be conferenced.
1896 *
1897 * @param conferenceableConnections The set of connections this connection can conference with.
1898 */
1899 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001900 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001901 clearConferenceableList();
1902 for (Connection c : conferenceableConnections) {
1903 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1904 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001905 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001906 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001907 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001908 }
1909 }
1910 fireOnConferenceableConnectionsChanged();
1911 }
1912
1913 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001914 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1915 * or conferences with which this connection can be conferenced.
1916 *
1917 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001918 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001919 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001920 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001921 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001922 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1923 // small amount of items here.
1924 if (!mConferenceables.contains(c)) {
1925 if (c instanceof Connection) {
1926 Connection connection = (Connection) c;
1927 connection.addConnectionListener(mConnectionDeathListener);
1928 } else if (c instanceof Conference) {
1929 Conference conference = (Conference) c;
1930 conference.addListener(mConferenceDeathListener);
1931 }
1932 mConferenceables.add(c);
1933 }
1934 }
1935 fireOnConferenceableConnectionsChanged();
1936 }
1937
1938 /**
1939 * Returns the connections or conferences with which this connection can be conferenced.
1940 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001941 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001942 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001943 }
1944
Yorke Lee53463962015-08-04 16:07:19 -07001945 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001946 * @hide
1947 */
1948 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001949 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001950 if (mConnectionService != null) {
1951 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1952 "which is already associated with another ConnectionService.");
1953 } else {
1954 mConnectionService = connectionService;
1955 }
1956 }
1957
1958 /**
1959 * @hide
1960 */
1961 public final void unsetConnectionService(ConnectionService connectionService) {
1962 if (mConnectionService != connectionService) {
1963 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1964 "that does not belong to the ConnectionService.");
1965 } else {
1966 mConnectionService = null;
1967 }
1968 }
1969
1970 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001971 * @hide
1972 */
1973 public final ConnectionService getConnectionService() {
1974 return mConnectionService;
1975 }
1976
1977 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001978 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001979 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001980 *
1981 * @param conference The conference.
1982 * @return {@code true} if the conference was successfully set.
1983 * @hide
1984 */
1985 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001986 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001987 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001988 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001989 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001990 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1991 fireConferenceChanged();
1992 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001993 return true;
1994 }
1995 return false;
1996 }
1997
1998 /**
1999 * Resets the conference that this connection is a part of.
2000 * @hide
2001 */
2002 public final void resetConference() {
2003 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002004 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002005 mConference = null;
2006 fireConferenceChanged();
2007 }
2008 }
2009
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002010 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002011 * Set some extras that can be associated with this {@code Connection}.
2012 * <p>
2013 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2014 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2015 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002016 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2017 * {@link #removeExtras(String...)} methods to modify the extras.
2018 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002019 * 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 -07002020 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2021 *
2022 * @param extras The extras associated with this {@code Connection}.
2023 */
2024 public final void setExtras(@Nullable Bundle extras) {
2025 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002026
2027 // Add/replace any new or changed extras values.
2028 putExtras(extras);
2029
2030 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2031 // the current one and remove any keys that went away.
2032 if (mPreviousExtraKeys != null) {
2033 List<String> toRemove = new ArrayList<String>();
2034 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002035 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002036 toRemove.add(oldKey);
2037 }
2038 }
2039 if (!toRemove.isEmpty()) {
2040 removeExtras(toRemove);
2041 }
2042 }
2043
2044 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2045 // called we can see if the caller has removed any extras values.
2046 if (mPreviousExtraKeys == null) {
2047 mPreviousExtraKeys = new ArraySet<String>();
2048 }
2049 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002050 if (extras != null) {
2051 mPreviousExtraKeys.addAll(extras.keySet());
2052 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002053 }
2054
2055 /**
2056 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2057 * added.
2058 * <p>
2059 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2060 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2061 *
2062 * @param extras The extras to add.
2063 */
2064 public final void putExtras(@NonNull Bundle extras) {
2065 checkImmutable();
2066 if (extras == null) {
2067 return;
2068 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002069 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2070 // the listeners.
2071 Bundle listenerExtras;
2072 synchronized (mExtrasLock) {
2073 if (mExtras == null) {
2074 mExtras = new Bundle();
2075 }
2076 mExtras.putAll(extras);
2077 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002078 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002079 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002080 // Create a new clone of the extras for each listener so that they don't clobber
2081 // each other
2082 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002083 }
2084 }
2085
2086 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002087 * Adds a boolean extra to this {@code Connection}.
2088 *
2089 * @param key The extra key.
2090 * @param value The value.
2091 * @hide
2092 */
2093 public final void putExtra(String key, boolean value) {
2094 Bundle newExtras = new Bundle();
2095 newExtras.putBoolean(key, value);
2096 putExtras(newExtras);
2097 }
2098
2099 /**
2100 * Adds an integer extra to this {@code Connection}.
2101 *
2102 * @param key The extra key.
2103 * @param value The value.
2104 * @hide
2105 */
2106 public final void putExtra(String key, int value) {
2107 Bundle newExtras = new Bundle();
2108 newExtras.putInt(key, value);
2109 putExtras(newExtras);
2110 }
2111
2112 /**
2113 * Adds a string extra to this {@code Connection}.
2114 *
2115 * @param key The extra key.
2116 * @param value The value.
2117 * @hide
2118 */
2119 public final void putExtra(String key, String value) {
2120 Bundle newExtras = new Bundle();
2121 newExtras.putString(key, value);
2122 putExtras(newExtras);
2123 }
2124
2125 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002126 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002127 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002128 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002129 */
2130 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002131 synchronized (mExtrasLock) {
2132 if (mExtras != null) {
2133 for (String key : keys) {
2134 mExtras.remove(key);
2135 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002136 }
2137 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002138 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002139 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002140 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002141 }
2142 }
2143
2144 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002145 * Removes extras from this {@code Connection}.
2146 *
2147 * @param keys The keys of the extras to remove.
2148 */
2149 public final void removeExtras(String ... keys) {
2150 removeExtras(Arrays.asList(keys));
2151 }
2152
2153 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002154 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002155 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002156 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002157 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2158 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002159 */
Yorke Lee4af59352015-05-13 14:14:54 -07002160 @SystemApi
2161 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002162 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002163
2164 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002165 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2166 *
2167 * @param state The new connection audio state.
2168 */
2169 public void onCallAudioStateChanged(CallAudioState state) {}
2170
2171 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002172 * Notifies this Connection of an internal state change. This method is called after the
2173 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002174 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002175 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002176 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002177 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002178
2179 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002180 * Notifies this Connection of a request to play a DTMF tone.
2181 *
2182 * @param c A DTMF character.
2183 */
Santos Cordonf2951102014-07-20 19:06:29 -07002184 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002185
2186 /**
2187 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2188 */
Santos Cordonf2951102014-07-20 19:06:29 -07002189 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002190
2191 /**
2192 * Notifies this Connection of a request to disconnect.
2193 */
Santos Cordonf2951102014-07-20 19:06:29 -07002194 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002195
2196 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002197 * Notifies this Connection of a request to disconnect a participant of the conference managed
2198 * by the connection.
2199 *
2200 * @param endpoint the {@link Uri} of the participant to disconnect.
2201 * @hide
2202 */
2203 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2204
2205 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002206 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002207 */
Santos Cordonf2951102014-07-20 19:06:29 -07002208 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002209
2210 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002211 * Notifies this Connection of a request to abort.
2212 */
Santos Cordonf2951102014-07-20 19:06:29 -07002213 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002214
2215 /**
2216 * Notifies this Connection of a request to hold.
2217 */
Santos Cordonf2951102014-07-20 19:06:29 -07002218 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002219
2220 /**
2221 * Notifies this Connection of a request to exit a hold state.
2222 */
Santos Cordonf2951102014-07-20 19:06:29 -07002223 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002224
2225 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002226 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002227 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002228 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002229 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002230 */
Santos Cordonf2951102014-07-20 19:06:29 -07002231 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002232
2233 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002235 * a request to accept.
2236 */
2237 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002238 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002239 }
2240
2241 /**
2242 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002243 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244 */
Santos Cordonf2951102014-07-20 19:06:29 -07002245 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002246
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002247 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002248 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2249 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002250 */
2251 public void onReject(String replyMessage) {}
2252
2253 /**
Bryce Leecac50772015-11-17 15:13:29 -08002254 * Notifies the Connection of a request to silence the ringer.
2255 *
2256 * @hide
2257 */
2258 public void onSilence() {}
2259
2260 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002261 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2262 */
Santos Cordonf2951102014-07-20 19:06:29 -07002263 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002264
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002265 /**
2266 * Notifies this Connection of a request to pull an external call to the local device.
2267 * <p>
2268 * The {@link InCallService} issues a request to pull an external call to the local device via
2269 * {@link Call#pullExternalCall()}.
2270 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002271 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2272 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002273 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002274 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002275 */
2276 public void onPullExternalCall() {}
2277
2278 /**
2279 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2280 * <p>
2281 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2282 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002283 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2284 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2285 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2286 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2287 * not aware of.
2288 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002289 * See also {@link Call#sendCallEvent(String, Bundle)}.
2290 *
2291 * @param event The call event.
2292 * @param extras Extras associated with the call event.
2293 */
2294 public void onCallEvent(String event, Bundle extras) {}
2295
Tyler Gunndee56a82016-03-23 16:06:34 -07002296 /**
2297 * Notifies this {@link Connection} of a change to the extras made outside the
2298 * {@link ConnectionService}.
2299 * <p>
2300 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2301 * the {@link android.telecom.Call#putExtras(Bundle)} and
2302 * {@link Call#removeExtras(List)}.
2303 *
2304 * @param extras The new extras bundle.
2305 */
2306 public void onExtrasChanged(Bundle extras) {}
2307
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002308 static String toLogSafePhoneNumber(String number) {
2309 // For unknown number, log empty string.
2310 if (number == null) {
2311 return "";
2312 }
2313
2314 if (PII_DEBUG) {
2315 // When PII_DEBUG is true we emit PII.
2316 return number;
2317 }
2318
2319 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2320 // sanitized phone numbers.
2321 StringBuilder builder = new StringBuilder();
2322 for (int i = 0; i < number.length(); i++) {
2323 char c = number.charAt(i);
2324 if (c == '-' || c == '@' || c == '.') {
2325 builder.append(c);
2326 } else {
2327 builder.append('x');
2328 }
2329 }
2330 return builder.toString();
2331 }
2332
Ihab Awad542e0ea2014-05-16 10:22:16 -07002333 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002334 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002335 if (mState == STATE_DISCONNECTED && mState != state) {
2336 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002337 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002338 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002339 if (mState != state) {
2340 Log.d(this, "setState: %s", stateToString(state));
2341 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002342 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002343 for (Listener l : mListeners) {
2344 l.onStateChanged(this, state);
2345 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002346 }
2347 }
2348
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002349 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002350 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002351 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2352 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002353 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002354 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002355
2356 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002357 if (mImmutable) {
2358 throw new UnsupportedOperationException("Connection is immutable");
2359 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002360 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002361 }
2362
Evan Charltonbf11f982014-07-20 22:06:28 -07002363 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002364 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002365 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2366 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002367 * <p>
2368 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2369 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002370 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002371 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002372 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002373 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002374 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2375 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002376 }
2377
Evan Charltonbf11f982014-07-20 22:06:28 -07002378 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002379 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2380 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2381 * this should never be un-@hide-den.
2382 *
2383 * @hide
2384 */
2385 public void checkImmutable() {}
2386
2387 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002388 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2389 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2390 * that state. This connection should not be used for anything, and no other
2391 * {@code Connection}s should be attempted.
2392 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002393 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002394 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002395 * @return A {@code Connection} which indicates that the underlying connection should
2396 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002397 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002398 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002399 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002400 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002401
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002402 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002403 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002404 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002405 }
2406 }
2407
Santos Cordon823fd3c2014-08-07 18:35:18 -07002408 private final void fireConferenceChanged() {
2409 for (Listener l : mListeners) {
2410 l.onConferenceChanged(this, mConference);
2411 }
2412 }
2413
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002414 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002415 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002416 if (c instanceof Connection) {
2417 Connection connection = (Connection) c;
2418 connection.removeConnectionListener(mConnectionDeathListener);
2419 } else if (c instanceof Conference) {
2420 Conference conference = (Conference) c;
2421 conference.removeListener(mConferenceDeathListener);
2422 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002423 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002424 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002425 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002426
2427 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002428 * Handles a change to extras received from Telecom.
2429 *
2430 * @param extras The new extras.
2431 * @hide
2432 */
2433 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002434 Bundle b = null;
2435 synchronized (mExtrasLock) {
2436 mExtras = extras;
2437 if (mExtras != null) {
2438 b = new Bundle(mExtras);
2439 }
2440 }
2441 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002442 }
2443
2444 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002445 * Notifies listeners that the merge request failed.
2446 *
2447 * @hide
2448 */
2449 protected final void notifyConferenceMergeFailed() {
2450 for (Listener l : mListeners) {
2451 l.onConferenceMergeFailed(this);
2452 }
2453 }
2454
2455 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002456 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002457 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002458 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002459 * @hide
2460 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002461 protected final void updateConferenceParticipants(
2462 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002463 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002464 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002465 }
2466 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002467
2468 /**
2469 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002470 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002471 */
2472 protected void notifyConferenceStarted() {
2473 for (Listener l : mListeners) {
2474 l.onConferenceStarted();
2475 }
2476 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002477
2478 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002479 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2480 * be a part of a conference call.
2481 * @param isConferenceSupported {@code true} if the connection supports being part of a
2482 * conference call, {@code false} otherwise.
2483 * @hide
2484 */
2485 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2486 for (Listener l : mListeners) {
2487 l.onConferenceSupportedChanged(this, isConferenceSupported);
2488 }
2489 }
2490
2491 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002492 * Sends an event associated with this {@code Connection} with associated event extras to the
2493 * {@link InCallService}.
2494 * <p>
2495 * Connection events are used to communicate point in time information from a
2496 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2497 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2498 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2499 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2500 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2501 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2502 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2503 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2504 * <p>
2505 * Events are exposed to {@link InCallService} implementations via
2506 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2507 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002508 * 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 -07002509 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2510 * some events altogether.
2511 * <p>
2512 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2513 * conflicts between {@link ConnectionService} implementations. Further, custom
2514 * {@link ConnectionService} implementations shall not re-purpose events in the
2515 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2516 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2517 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2518 * {@code com.example.extra.MY_EXTRA}).
2519 * <p>
2520 * When defining events and the associated extras, it is important to keep their behavior
2521 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2522 * events/extras should me maintained to ensure backwards compatibility with older
2523 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002524 *
2525 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002526 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002527 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002528 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002529 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002530 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002531 }
2532 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002533}