blob: c0061859bf60e1955ad126e2c654329d5ed96897 [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 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700330 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700331
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
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700464 /**
465 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
466 * the remote party.
467 * <p>
468 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
469 * call is being held locally on the device. When a capable {@link ConnectionService} receives
470 * signalling to indicate that the remote party has put the call on hold, it can send this
471 * connection event.
472 * @hide
473 */
474 public static final String EVENT_CALL_REMOTELY_HELD =
475 "android.telecom.event.CALL_REMOTELY_HELD";
476
477 /**
478 * Connection event used to inform {@link InCallService}s when a call which was remotely held
479 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
480 * <p>
481 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
482 * call is being held locally on the device. When a capable {@link ConnectionService} receives
483 * signalling to indicate that the remote party has taken the call off hold, it can send this
484 * connection event.
485 * @hide
486 */
487 public static final String EVENT_CALL_REMOTELY_UNHELD =
488 "android.telecom.event.CALL_REMOTELY_UNHELD";
489
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 // Flag controlling whether PII is emitted into the logs
491 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
492
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 /**
494 * Whether the given capabilities support the specified capability.
495 *
496 * @param capabilities A capability bit field.
497 * @param capability The capability to check capabilities for.
498 * @return Whether the specified capability is supported.
499 * @hide
500 */
501 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800502 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800503 }
504
505 /**
506 * Whether the capabilities of this {@code Connection} supports the specified capability.
507 *
508 * @param capability The capability to check capabilities for.
509 * @return Whether the specified capability is supported.
510 * @hide
511 */
512 public boolean can(int capability) {
513 return can(mConnectionCapabilities, capability);
514 }
515
516 /**
517 * Removes the specified capability from the set of capabilities of this {@code Connection}.
518 *
519 * @param capability The capability to remove from the set.
520 * @hide
521 */
522 public void removeCapability(int capability) {
523 mConnectionCapabilities &= ~capability;
524 }
525
526 /**
527 * Adds the specified capability to the set of capabilities of this {@code Connection}.
528 *
529 * @param capability The capability to add to the set.
530 * @hide
531 */
532 public void addCapability(int capability) {
533 mConnectionCapabilities |= capability;
534 }
535
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700536 /**
537 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
538 *
539 * @param capabilities A capability bit field.
540 * @return A human readable string representation.
541 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800542 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700543 return capabilitiesToStringInternal(capabilities, true /* isLong */);
544 }
545
546 /**
547 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
548 * string.
549 *
550 * @param capabilities A capability bit field.
551 * @return A human readable string representation.
552 * @hide
553 */
554 public static String capabilitiesToStringShort(int capabilities) {
555 return capabilitiesToStringInternal(capabilities, false /* isLong */);
556 }
557
558 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800559 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700560 builder.append("[");
561 if (isLong) {
562 builder.append("Capabilities:");
563 }
564
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800565 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700566 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800567 }
568 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700569 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800570 }
571 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700572 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800573 }
574 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700575 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800576 }
577 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700578 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800579 }
580 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700581 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800582 }
583 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700584 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800585 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700586 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700587 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700588 }
589 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700590 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700591 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700592 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700593 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800594 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700595 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700596 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700597 }
598 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700599 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700600 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700601 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700602 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800604 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700605 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800606 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500607 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700608 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500609 }
Rekha Kumar07366812015-03-24 16:42:31 -0700610 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700611 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700612 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700613 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700614 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700615 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700616 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700617 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700618 }
Bryce Lee81901682015-08-28 16:38:02 -0700619 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700620 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700621 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700622 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700623 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700624 }
Bryce Lee81901682015-08-28 16:38:02 -0700625
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 builder.append("]");
627 return builder.toString();
628 }
629
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700630 /**
631 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
632 *
633 * @param properties A property bit field.
634 * @return A human readable string representation.
635 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700636 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700637 return propertiesToStringInternal(properties, true /* isLong */);
638 }
639
640 /**
641 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
642 *
643 * @param properties A property bit field.
644 * @return A human readable string representation.
645 * @hide
646 */
647 public static String propertiesToStringShort(int properties) {
648 return propertiesToStringInternal(properties, false /* isLong */);
649 }
650
651 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700652 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700653 builder.append("[");
654 if (isLong) {
655 builder.append("Properties:");
656 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700657
Hall Liu25c7c4d2016-08-30 13:41:02 -0700658 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
659 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700660 }
661
662 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700664 }
665
666 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700668 }
669
670 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700671 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700672 }
673
674 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700676 }
677
Brad Ebinger15847072016-05-18 11:08:36 -0700678 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700680 }
681
Tyler Gunn720c6642016-03-22 09:02:47 -0700682 builder.append("]");
683 return builder.toString();
684 }
685
Sailesh Nepal091768c2014-06-30 15:15:23 -0700686 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700687 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700688 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700689 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700690 public void onCallerDisplayNameChanged(
691 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700692 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700693 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700694 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800695 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700696 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700697 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800698 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700699 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700700 public void onVideoProviderChanged(
701 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700702 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
703 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800704 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700705 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700706 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700707 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800708 public void onConferenceParticipantsChanged(Connection c,
709 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800710 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700711 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700712 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700713 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700714 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700715 /** @hide */
716 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700717 }
718
Tyler Gunnb702ef82015-05-29 11:51:53 -0700719 /**
720 * Provides a means of controlling the video session associated with a {@link Connection}.
721 * <p>
722 * Implementations create a custom subclass of {@link VideoProvider} and the
723 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
724 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
725 * should set the {@link VideoProvider}.
726 * <p>
727 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
728 * {@link InCallService} implementations to issue requests related to the video session;
729 * it provides a means for the {@link ConnectionService} to report events and information
730 * related to the video session to Telecom and the {@link InCallService} implementations.
731 * <p>
732 * {@link InCallService} implementations interact with the {@link VideoProvider} via
733 * {@link android.telecom.InCallService.VideoCall}.
734 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700735 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700736 /**
737 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700738 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 */
740 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700741
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700742 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700743 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
744 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700745 */
746 public static final int SESSION_EVENT_RX_RESUME = 2;
747
748 /**
749 * Video transmission has begun. This occurs after a negotiated start of video transmission
750 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700751 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 */
753 public static final int SESSION_EVENT_TX_START = 3;
754
755 /**
756 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
757 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700758 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 */
760 public static final int SESSION_EVENT_TX_STOP = 4;
761
762 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700763 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
764 * this as a cue to inform the user the camera is not available.
765 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700766 */
767 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
768
769 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700770 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
771 * for operation. The {@link InCallService} can use this as a cue to inform the user that
772 * the camera has become available again.
773 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700774 */
775 public static final int SESSION_EVENT_CAMERA_READY = 6;
776
777 /**
778 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700779 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700780 */
781 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
782
783 /**
784 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700785 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700786 */
787 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
788
789 /**
790 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700791 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 */
793 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
794
Rekha Kumar07366812015-03-24 16:42:31 -0700795 /**
796 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700797 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700798 */
799 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
800
801 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700802 * Session modify request rejected by remote user.
803 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700804 */
805 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
806
Tyler Gunn75958422015-04-15 14:23:42 -0700807 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 private static final int MSG_SET_CAMERA = 2;
809 private static final int MSG_SET_PREVIEW_SURFACE = 3;
810 private static final int MSG_SET_DISPLAY_SURFACE = 4;
811 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
812 private static final int MSG_SET_ZOOM = 6;
813 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
814 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
815 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700817 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700818 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700820 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
821 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
822 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
823 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
824 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
825 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
826 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
827
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700828 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700830
831 /**
832 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700833 *
834 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
835 * load factor before resizing, 1 means we only expect a single thread to
836 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700837 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700838 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
839 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700840
841 /**
842 * Default handler used to consolidate binder method calls onto a single thread.
843 */
844 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700845 public VideoProviderHandler() {
846 super();
847 }
848
849 public VideoProviderHandler(Looper looper) {
850 super(looper);
851 }
852
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853 @Override
854 public void handleMessage(Message msg) {
855 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700856 case MSG_ADD_VIDEO_CALLBACK: {
857 IBinder binder = (IBinder) msg.obj;
858 IVideoCallback callback = IVideoCallback.Stub
859 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700860 if (callback == null) {
861 Log.w(this, "addVideoProvider - skipped; callback is null.");
862 break;
863 }
864
Tyler Gunn75958422015-04-15 14:23:42 -0700865 if (mVideoCallbacks.containsKey(binder)) {
866 Log.i(this, "addVideoProvider - skipped; already present.");
867 break;
868 }
869 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700871 }
872 case MSG_REMOVE_VIDEO_CALLBACK: {
873 IBinder binder = (IBinder) msg.obj;
874 IVideoCallback callback = IVideoCallback.Stub
875 .asInterface((IBinder) msg.obj);
876 if (!mVideoCallbacks.containsKey(binder)) {
877 Log.i(this, "removeVideoProvider - skipped; not present.");
878 break;
879 }
880 mVideoCallbacks.remove(binder);
881 break;
882 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 case MSG_SET_CAMERA:
884 onSetCamera((String) msg.obj);
885 break;
886 case MSG_SET_PREVIEW_SURFACE:
887 onSetPreviewSurface((Surface) msg.obj);
888 break;
889 case MSG_SET_DISPLAY_SURFACE:
890 onSetDisplaySurface((Surface) msg.obj);
891 break;
892 case MSG_SET_DEVICE_ORIENTATION:
893 onSetDeviceOrientation(msg.arg1);
894 break;
895 case MSG_SET_ZOOM:
896 onSetZoom((Float) msg.obj);
897 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700898 case MSG_SEND_SESSION_MODIFY_REQUEST: {
899 SomeArgs args = (SomeArgs) msg.obj;
900 try {
901 onSendSessionModifyRequest((VideoProfile) args.arg1,
902 (VideoProfile) args.arg2);
903 } finally {
904 args.recycle();
905 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700907 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700908 case MSG_SEND_SESSION_MODIFY_RESPONSE:
909 onSendSessionModifyResponse((VideoProfile) msg.obj);
910 break;
911 case MSG_REQUEST_CAMERA_CAPABILITIES:
912 onRequestCameraCapabilities();
913 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800914 case MSG_REQUEST_CONNECTION_DATA_USAGE:
915 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700916 break;
917 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700918 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700919 break;
920 default:
921 break;
922 }
923 }
924 }
925
926 /**
927 * IVideoProvider stub implementation.
928 */
929 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700930 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700932 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
933 }
934
935 public void removeVideoCallback(IBinder videoCallbackBinder) {
936 mMessageHandler.obtainMessage(
937 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938 }
939
940 public void setCamera(String cameraId) {
941 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
942 }
943
944 public void setPreviewSurface(Surface surface) {
945 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
946 }
947
948 public void setDisplaySurface(Surface surface) {
949 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
950 }
951
952 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700953 mMessageHandler.obtainMessage(
954 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 }
956
957 public void setZoom(float value) {
958 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
959 }
960
Tyler Gunn45382162015-05-06 08:52:27 -0700961 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
962 SomeArgs args = SomeArgs.obtain();
963 args.arg1 = fromProfile;
964 args.arg2 = toProfile;
965 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 }
967
968 public void sendSessionModifyResponse(VideoProfile responseProfile) {
969 mMessageHandler.obtainMessage(
970 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
971 }
972
973 public void requestCameraCapabilities() {
974 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
975 }
976
977 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800978 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 }
980
Yorke Lee32f24732015-05-12 16:18:03 -0700981 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
983 }
984 }
985
986 public VideoProvider() {
987 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700988 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700989 }
990
991 /**
992 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
993 *
994 * @param looper The looper.
995 * @hide
996 */
997 public VideoProvider(Looper looper) {
998 mBinder = new VideoProvider.VideoProviderBinder();
999 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000 }
1001
1002 /**
1003 * Returns binder object which can be used across IPC methods.
1004 * @hide
1005 */
1006 public final IVideoProvider getInterface() {
1007 return mBinder;
1008 }
1009
1010 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001011 * Sets the camera to be used for the outgoing video.
1012 * <p>
1013 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1014 * camera via
1015 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1016 * <p>
1017 * Sent from the {@link InCallService} via
1018 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * @param cameraId The id of the camera (use ids as reported by
1021 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 */
1023 public abstract void onSetCamera(String cameraId);
1024
1025 /**
1026 * Sets the surface to be used for displaying a preview of what the user's camera is
1027 * currently capturing. When video transmission is enabled, this is the video signal which
1028 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001029 * <p>
1030 * Sent from the {@link InCallService} via
1031 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001032 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 */
1035 public abstract void onSetPreviewSurface(Surface surface);
1036
1037 /**
1038 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001039 * <p>
1040 * Sent from the {@link InCallService} via
1041 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001042 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 */
1045 public abstract void onSetDisplaySurface(Surface surface);
1046
1047 /**
1048 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1049 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * <p>
1051 * Sent from the {@link InCallService} via
1052 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 *
1054 * @param rotation The device orientation, in degrees.
1055 */
1056 public abstract void onSetDeviceOrientation(int rotation);
1057
1058 /**
1059 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001060 * <p>
1061 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062 *
1063 * @param value The camera zoom ratio.
1064 */
1065 public abstract void onSetZoom(float value);
1066
1067 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001068 * Issues a request to modify the properties of the current video session.
1069 * <p>
1070 * Example scenarios include: requesting an audio-only call to be upgraded to a
1071 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1072 * when the {@link InCallService} is no longer the foreground application.
1073 * <p>
1074 * If the {@link VideoProvider} determines a request to be invalid, it should call
1075 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1076 * invalid request back to the {@link InCallService}.
1077 * <p>
1078 * Where a request requires confirmation from the user of the peer device, the
1079 * {@link VideoProvider} must communicate the request to the peer device and handle the
1080 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1081 * is used to inform the {@link InCallService} of the result of the request.
1082 * <p>
1083 * Sent from the {@link InCallService} via
1084 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001085 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001086 * @param fromProfile The video profile prior to the request.
1087 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 */
Tyler Gunn45382162015-05-06 08:52:27 -07001089 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1090 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001091
Tyler Gunnb702ef82015-05-29 11:51:53 -07001092 /**
1093 * Provides a response to a request to change the current video session properties.
1094 * <p>
1095 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1096 * video call, could decline the request and keep the call as audio-only.
1097 * In such a scenario, the {@code responseProfile} would have a video state of
1098 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1099 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1100 * <p>
1101 * Sent from the {@link InCallService} via
1102 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1103 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1104 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001106 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 */
1108 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1109
1110 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001111 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1112 * <p>
1113 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1114 * camera via
1115 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1116 * <p>
1117 * Sent from the {@link InCallService} via
1118 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001119 */
1120 public abstract void onRequestCameraCapabilities();
1121
1122 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001123 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1124 * video component of the current {@link Connection}.
1125 * <p>
1126 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1127 * via {@link VideoProvider#setCallDataUsage(long)}.
1128 * <p>
1129 * Sent from the {@link InCallService} via
1130 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001132 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133
1134 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001135 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1136 * the peer device when the video signal is paused.
1137 * <p>
1138 * Sent from the {@link InCallService} via
1139 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 *
1141 * @param uri URI of image to display.
1142 */
Yorke Lee32f24732015-05-12 16:18:03 -07001143 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144
1145 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001146 * Used to inform listening {@link InCallService} implementations when the
1147 * {@link VideoProvider} receives a session modification request.
1148 * <p>
1149 * Received by the {@link InCallService} via
1150 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001152 * @param videoProfile The requested video profile.
1153 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 */
1155 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001156 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001157 for (IVideoCallback callback : mVideoCallbacks.values()) {
1158 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001159 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001160 } catch (RemoteException ignored) {
1161 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001162 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 }
1164 }
1165 }
1166
1167 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001168 * Used to inform listening {@link InCallService} implementations when the
1169 * {@link VideoProvider} receives a response to a session modification request.
1170 * <p>
1171 * Received by the {@link InCallService} via
1172 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1173 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001174 *
1175 * @param status Status of the session modify request. Valid values are
1176 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1177 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001178 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1179 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1180 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1181 * @param requestedProfile The original request which was sent to the peer device.
1182 * @param responseProfile The actual profile changes agreed to by the peer device.
1183 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 */
1185 public void receiveSessionModifyResponse(int status,
1186 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001187 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001188 for (IVideoCallback callback : mVideoCallbacks.values()) {
1189 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001190 callback.receiveSessionModifyResponse(status, requestedProfile,
1191 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001192 } catch (RemoteException ignored) {
1193 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001194 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001195 }
1196 }
1197 }
1198
1199 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001200 * Used to inform listening {@link InCallService} implementations when the
1201 * {@link VideoProvider} reports a call session event.
1202 * <p>
1203 * Received by the {@link InCallService} via
1204 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001205 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001206 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1207 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1208 * {@link VideoProvider#SESSION_EVENT_TX_START},
1209 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1210 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1211 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001212 */
1213 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001214 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001215 for (IVideoCallback callback : mVideoCallbacks.values()) {
1216 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001217 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001218 } catch (RemoteException ignored) {
1219 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001220 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001221 }
1222 }
1223 }
1224
1225 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001226 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1227 * peer's video have changed.
1228 * <p>
1229 * This could occur if, for example, the peer rotates their device, changing the aspect
1230 * ratio of the video, or if the user switches between the back and front cameras.
1231 * <p>
1232 * Received by the {@link InCallService} via
1233 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001234 *
1235 * @param width The updated peer video width.
1236 * @param height The updated peer video height.
1237 */
1238 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001239 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001240 for (IVideoCallback callback : mVideoCallbacks.values()) {
1241 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001242 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001243 } catch (RemoteException ignored) {
1244 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001245 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 }
1247 }
1248 }
1249
1250 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001251 * Used to inform listening {@link InCallService} implementations when the data usage of the
1252 * video associated with the current {@link Connection} has changed.
1253 * <p>
1254 * This could be in response to a preview request via
1255 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001256 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1257 * 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 -07001258 * <p>
1259 * Received by the {@link InCallService} via
1260 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001261 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001262 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1263 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 */
Yorke Lee32f24732015-05-12 16:18:03 -07001265 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001266 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001267 for (IVideoCallback callback : mVideoCallbacks.values()) {
1268 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001269 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001270 } catch (RemoteException ignored) {
1271 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001272 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001273 }
1274 }
1275 }
1276
1277 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001278 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001280 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001281 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1282 * @hide
1283 */
1284 public void changeCallDataUsage(long dataUsage) {
1285 setCallDataUsage(dataUsage);
1286 }
1287
1288 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001289 * Used to inform listening {@link InCallService} implementations when the capabilities of
1290 * the current camera have changed.
1291 * <p>
1292 * The {@link VideoProvider} should call this in response to
1293 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1294 * changed via {@link VideoProvider#onSetCamera(String)}.
1295 * <p>
1296 * Received by the {@link InCallService} via
1297 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1298 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001299 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001300 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 */
Yorke Lee400470f2015-05-12 13:31:25 -07001302 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001303 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001304 for (IVideoCallback callback : mVideoCallbacks.values()) {
1305 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001306 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001307 } catch (RemoteException ignored) {
1308 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001309 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 }
1311 }
1312 }
Rekha Kumar07366812015-03-24 16:42:31 -07001313
1314 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001315 * Used to inform listening {@link InCallService} implementations when the video quality
1316 * of the call has changed.
1317 * <p>
1318 * Received by the {@link InCallService} via
1319 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001320 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001321 * @param videoQuality The updated video quality. Valid values:
1322 * {@link VideoProfile#QUALITY_HIGH},
1323 * {@link VideoProfile#QUALITY_MEDIUM},
1324 * {@link VideoProfile#QUALITY_LOW},
1325 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001326 */
1327 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001328 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001329 for (IVideoCallback callback : mVideoCallbacks.values()) {
1330 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001331 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001332 } catch (RemoteException ignored) {
1333 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001334 }
Rekha Kumar07366812015-03-24 16:42:31 -07001335 }
1336 }
1337 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001338
1339 /**
1340 * Returns a string representation of a call session event.
1341 *
1342 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1343 * @return String representation of the call session event.
1344 * @hide
1345 */
1346 public static String sessionEventToString(int event) {
1347 switch (event) {
1348 case SESSION_EVENT_CAMERA_FAILURE:
1349 return SESSION_EVENT_CAMERA_FAILURE_STR;
1350 case SESSION_EVENT_CAMERA_READY:
1351 return SESSION_EVENT_CAMERA_READY_STR;
1352 case SESSION_EVENT_RX_PAUSE:
1353 return SESSION_EVENT_RX_PAUSE_STR;
1354 case SESSION_EVENT_RX_RESUME:
1355 return SESSION_EVENT_RX_RESUME_STR;
1356 case SESSION_EVENT_TX_START:
1357 return SESSION_EVENT_TX_START_STR;
1358 case SESSION_EVENT_TX_STOP:
1359 return SESSION_EVENT_TX_STOP_STR;
1360 default:
1361 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1362 }
1363 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001364 }
1365
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001366 private final Listener mConnectionDeathListener = new Listener() {
1367 @Override
1368 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001369 if (mConferenceables.remove(c)) {
1370 fireOnConferenceableConnectionsChanged();
1371 }
1372 }
1373 };
1374
1375 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1376 @Override
1377 public void onDestroyed(Conference c) {
1378 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001379 fireOnConferenceableConnectionsChanged();
1380 }
1381 }
1382 };
1383
Jay Shrauner229e3822014-08-15 09:23:07 -07001384 /**
1385 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1386 * load factor before resizing, 1 means we only expect a single thread to
1387 * access the map so make only a single shard
1388 */
1389 private final Set<Listener> mListeners = Collections.newSetFromMap(
1390 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001391 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1392 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001393 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001394
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001395 // The internal telecom call ID associated with this connection.
1396 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001398 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001399 private Uri mAddress;
1400 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001401 private String mCallerDisplayName;
1402 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001403 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001404 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001405 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001407 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001408 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001409 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001410 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001411 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001412 private Conference mConference;
1413 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001414 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001415 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001416
1417 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001418 * Tracks the key set for the extras bundle provided on the last invocation of
1419 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1420 * keys which were set previously but are no longer present in the replacement Bundle.
1421 */
1422 private Set<String> mPreviousExtraKeys;
1423
1424 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001425 * Create a new Connection.
1426 */
Santos Cordonf2951102014-07-20 19:06:29 -07001427 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001428
1429 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001430 * Returns the Telecom internal call ID associated with this connection. Should only be used
1431 * for debugging and tracing purposes.
1432 *
1433 * @return The Telecom call ID.
1434 * @hide
1435 */
1436 public final String getTelecomCallId() {
1437 return mTelecomCallId;
1438 }
1439
1440 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001441 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442 */
Andrew Lee100e2932014-09-08 15:34:24 -07001443 public final Uri getAddress() {
1444 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001445 }
1446
1447 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001448 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001449 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001450 */
Andrew Lee100e2932014-09-08 15:34:24 -07001451 public final int getAddressPresentation() {
1452 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001453 }
1454
1455 /**
1456 * @return The caller display name (CNAP).
1457 */
1458 public final String getCallerDisplayName() {
1459 return mCallerDisplayName;
1460 }
1461
1462 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001463 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001464 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001465 */
1466 public final int getCallerDisplayNamePresentation() {
1467 return mCallerDisplayNamePresentation;
1468 }
1469
1470 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001471 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001472 */
1473 public final int getState() {
1474 return mState;
1475 }
1476
1477 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001478 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001479 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1480 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1481 * {@link VideoProfile#STATE_TX_ENABLED},
1482 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001483 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001484 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001485 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001486 */
1487 public final int getVideoState() {
1488 return mVideoState;
1489 }
1490
1491 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001492 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493 * being routed by the system. This is {@code null} if this Connection
1494 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001495 * @deprecated Use {@link #getCallAudioState()} instead.
1496 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001497 */
Yorke Lee4af59352015-05-13 14:14:54 -07001498 @SystemApi
1499 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001501 if (mCallAudioState == null) {
1502 return null;
1503 }
Yorke Lee4af59352015-05-13 14:14:54 -07001504 return new AudioState(mCallAudioState);
1505 }
1506
1507 /**
1508 * @return The audio state of the connection, describing how its audio is currently
1509 * being routed by the system. This is {@code null} if this Connection
1510 * does not directly know about its audio state.
1511 */
1512 public final CallAudioState getCallAudioState() {
1513 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001514 }
1515
1516 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001517 * @return The conference that this connection is a part of. Null if it is not part of any
1518 * conference.
1519 */
1520 public final Conference getConference() {
1521 return mConference;
1522 }
1523
1524 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001525 * Returns whether this connection is requesting that the system play a ringback tone
1526 * on its behalf.
1527 */
Andrew Lee100e2932014-09-08 15:34:24 -07001528 public final boolean isRingbackRequested() {
1529 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001530 }
1531
1532 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001533 * @return True if the connection's audio mode is VOIP.
1534 */
1535 public final boolean getAudioModeIsVoip() {
1536 return mAudioModeIsVoip;
1537 }
1538
1539 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001540 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1541 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1542 * start time of the conference.
1543 *
1544 * @return The time at which the {@code Connnection} was connected.
1545 *
1546 * @hide
1547 */
1548 public final long getConnectTimeMillis() {
1549 return mConnectTimeMillis;
1550 }
1551
1552 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001553 * @return The status hints for this connection.
1554 */
1555 public final StatusHints getStatusHints() {
1556 return mStatusHints;
1557 }
1558
1559 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001560 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001561 * <p>
1562 * Extras should be updated using {@link #putExtras(Bundle)}.
1563 * <p>
1564 * Telecom or an {@link InCallService} can also update the extras via
1565 * {@link android.telecom.Call#putExtras(Bundle)}, and
1566 * {@link Call#removeExtras(List)}.
1567 * <p>
1568 * The connection is notified of changes to the extras made by Telecom or an
1569 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001570 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001571 * @return The extras associated with this connection.
1572 */
1573 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001574 Bundle extras = null;
1575 synchronized (mExtrasLock) {
1576 if (mExtras != null) {
1577 extras = new Bundle(mExtras);
1578 }
1579 }
1580 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001581 }
1582
1583 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 * Assign a listener to be notified of state changes.
1585 *
1586 * @param l A listener.
1587 * @return This Connection.
1588 *
1589 * @hide
1590 */
1591 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001592 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001593 return this;
1594 }
1595
1596 /**
1597 * Remove a previously assigned listener that was being notified of state changes.
1598 *
1599 * @param l A Listener.
1600 * @return This Connection.
1601 *
1602 * @hide
1603 */
1604 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001605 if (l != null) {
1606 mListeners.remove(l);
1607 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608 return this;
1609 }
1610
1611 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001612 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001613 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001614 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001615 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001616 }
1617
1618 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001619 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1620 * ONLY for debugging purposes.
1621 *
1622 * @param callId The telecom call ID.
1623 * @hide
1624 */
1625 public void setTelecomCallId(String callId) {
1626 mTelecomCallId = callId;
1627 }
1628
1629 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001630 * Inform this Connection that the state of its audio output has been changed externally.
1631 *
1632 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001633 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001634 */
Yorke Lee4af59352015-05-13 14:14:54 -07001635 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001636 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001637 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001638 mCallAudioState = state;
1639 onAudioStateChanged(getAudioState());
1640 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001641 }
1642
1643 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001644 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001645 * @return A string representation of the value.
1646 */
1647 public static String stateToString(int state) {
1648 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001650 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001651 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001652 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001653 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001654 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001655 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001656 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001657 case STATE_PULLING_CALL:
1658 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001659 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001660 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001661 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001662 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001663 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001664 return "DISCONNECTED";
1665 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001666 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001667 return "UNKNOWN";
1668 }
1669 }
1670
1671 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001672 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001673 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001674 public final int getConnectionCapabilities() {
1675 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001676 }
1677
1678 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001679 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1680 */
1681 public final int getConnectionProperties() {
1682 return mConnectionProperties;
1683 }
1684
1685 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001686 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001687 *
Andrew Lee100e2932014-09-08 15:34:24 -07001688 * @param address The new address.
1689 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001690 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001691 */
Andrew Lee100e2932014-09-08 15:34:24 -07001692 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001693 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001694 Log.d(this, "setAddress %s", address);
1695 mAddress = address;
1696 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001697 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001698 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001699 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001700 }
1701
1702 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001703 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001704 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001705 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001706 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001707 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001708 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001709 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001710 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001711 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001712 mCallerDisplayName = callerDisplayName;
1713 mCallerDisplayNamePresentation = presentation;
1714 for (Listener l : mListeners) {
1715 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1716 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001717 }
1718
1719 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001720 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001721 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1722 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1723 * {@link VideoProfile#STATE_TX_ENABLED},
1724 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001725 *
1726 * @param videoState The new video state.
1727 */
1728 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001729 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001730 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001731 mVideoState = videoState;
1732 for (Listener l : mListeners) {
1733 l.onVideoStateChanged(this, mVideoState);
1734 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001735 }
1736
1737 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001738 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001739 * communicate).
1740 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001741 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001742 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001743 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001744 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001745 }
1746
1747 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001748 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001749 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001750 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001751 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001752 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001753 }
1754
1755 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001756 * Sets state to initializing (this Connection is not yet ready to be used).
1757 */
1758 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001759 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001760 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001761 }
1762
1763 /**
1764 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1765 */
1766 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001767 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001768 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001769 }
1770
1771 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001772 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001773 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001774 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001775 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001776 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001777 }
1778
1779 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001780 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1781 * device). Only applicable for {@link Connection}s with
1782 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1783 */
1784 public final void setPulling() {
1785 checkImmutable();
1786 setState(STATE_PULLING_CALL);
1787 }
1788
1789 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001790 * Sets state to be on hold.
1791 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001792 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001793 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001794 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795 }
1796
1797 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001798 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001799 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001800 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001801 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001802 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001803 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001804 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001805 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001806 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001807 }
1808
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001809 public final VideoProvider getVideoProvider() {
1810 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001811 }
1812
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001813 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001814 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001816 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001818 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001819 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001820 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001821 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001822 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001823 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001824 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001825 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001826 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001827 }
1828
1829 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001830 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1831 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1832 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1833 * to send an {@link #onPostDialContinue(boolean)} signal.
1834 *
1835 * @param remaining The DTMF character sequence remaining to be emitted once the
1836 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1837 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001838 */
1839 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001840 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001841 for (Listener l : mListeners) {
1842 l.onPostDialWait(this, remaining);
1843 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001844 }
1845
1846 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001847 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1848 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001849 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001850 *
1851 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001852 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001853 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001854 checkImmutable();
1855 for (Listener l : mListeners) {
1856 l.onPostDialChar(this, nextChar);
1857 }
1858 }
1859
1860 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001861 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001862 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001863 *
1864 * @param ringback Whether the ringback tone is to be played.
1865 */
Andrew Lee100e2932014-09-08 15:34:24 -07001866 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001867 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001868 if (mRingbackRequested != ringback) {
1869 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001870 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001871 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001872 }
1873 }
Ihab Awadf8358972014-05-28 16:46:42 -07001874 }
1875
1876 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001877 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001878 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001879 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001880 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001881 public final void setConnectionCapabilities(int connectionCapabilities) {
1882 checkImmutable();
1883 if (mConnectionCapabilities != connectionCapabilities) {
1884 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001885 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001886 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001887 }
1888 }
Santos Cordonb6939982014-06-04 20:20:58 -07001889 }
1890
1891 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001892 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1893 *
1894 * @param connectionProperties The new connection properties.
1895 */
1896 public final void setConnectionProperties(int connectionProperties) {
1897 checkImmutable();
1898 if (mConnectionProperties != connectionProperties) {
1899 mConnectionProperties = connectionProperties;
1900 for (Listener l : mListeners) {
1901 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1902 }
1903 }
1904 }
1905
1906 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001907 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001908 */
Evan Charlton36a71342014-07-19 16:31:02 -07001909 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001910 for (Listener l : mListeners) {
1911 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001912 }
Santos Cordonb6939982014-06-04 20:20:58 -07001913 }
1914
1915 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001916 * Requests that the framework use VOIP audio mode for this connection.
1917 *
1918 * @param isVoip True if the audio mode is VOIP.
1919 */
1920 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001921 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001922 mAudioModeIsVoip = isVoip;
1923 for (Listener l : mListeners) {
1924 l.onAudioModeIsVoipChanged(this, isVoip);
1925 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001926 }
1927
1928 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001929 * Sets the time at which a call became active on this Connection. This is set only
1930 * when a conference call becomes active on this connection.
1931 *
1932 * @param connectionTimeMillis The connection time, in milliseconds.
1933 *
1934 * @hide
1935 */
1936 public final void setConnectTimeMillis(long connectTimeMillis) {
1937 mConnectTimeMillis = connectTimeMillis;
1938 }
1939
1940 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001941 * Sets the label and icon status to display in the in-call UI.
1942 *
1943 * @param statusHints The status label and icon to set.
1944 */
1945 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001946 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001947 mStatusHints = statusHints;
1948 for (Listener l : mListeners) {
1949 l.onStatusHintsChanged(this, statusHints);
1950 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001951 }
1952
1953 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001954 * Sets the connections with which this connection can be conferenced.
1955 *
1956 * @param conferenceableConnections The set of connections this connection can conference with.
1957 */
1958 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001959 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001960 clearConferenceableList();
1961 for (Connection c : conferenceableConnections) {
1962 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1963 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001964 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001965 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001966 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001967 }
1968 }
1969 fireOnConferenceableConnectionsChanged();
1970 }
1971
1972 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001973 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1974 * or conferences with which this connection can be conferenced.
1975 *
1976 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001978 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001979 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001980 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001981 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1982 // small amount of items here.
1983 if (!mConferenceables.contains(c)) {
1984 if (c instanceof Connection) {
1985 Connection connection = (Connection) c;
1986 connection.addConnectionListener(mConnectionDeathListener);
1987 } else if (c instanceof Conference) {
1988 Conference conference = (Conference) c;
1989 conference.addListener(mConferenceDeathListener);
1990 }
1991 mConferenceables.add(c);
1992 }
1993 }
1994 fireOnConferenceableConnectionsChanged();
1995 }
1996
1997 /**
1998 * Returns the connections or conferences with which this connection can be conferenced.
1999 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002000 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002001 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002002 }
2003
Yorke Lee53463962015-08-04 16:07:19 -07002004 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002005 * @hide
2006 */
2007 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002008 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002009 if (mConnectionService != null) {
2010 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2011 "which is already associated with another ConnectionService.");
2012 } else {
2013 mConnectionService = connectionService;
2014 }
2015 }
2016
2017 /**
2018 * @hide
2019 */
2020 public final void unsetConnectionService(ConnectionService connectionService) {
2021 if (mConnectionService != connectionService) {
2022 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2023 "that does not belong to the ConnectionService.");
2024 } else {
2025 mConnectionService = null;
2026 }
2027 }
2028
2029 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002030 * @hide
2031 */
2032 public final ConnectionService getConnectionService() {
2033 return mConnectionService;
2034 }
2035
2036 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002037 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002038 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002039 *
2040 * @param conference The conference.
2041 * @return {@code true} if the conference was successfully set.
2042 * @hide
2043 */
2044 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002045 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002046 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002047 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002048 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002049 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2050 fireConferenceChanged();
2051 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002052 return true;
2053 }
2054 return false;
2055 }
2056
2057 /**
2058 * Resets the conference that this connection is a part of.
2059 * @hide
2060 */
2061 public final void resetConference() {
2062 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002063 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002064 mConference = null;
2065 fireConferenceChanged();
2066 }
2067 }
2068
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002069 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002070 * Set some extras that can be associated with this {@code Connection}.
2071 * <p>
2072 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2073 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2074 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002075 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2076 * {@link #removeExtras(String...)} methods to modify the extras.
2077 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002078 * 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 -07002079 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2080 *
2081 * @param extras The extras associated with this {@code Connection}.
2082 */
2083 public final void setExtras(@Nullable Bundle extras) {
2084 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002085
2086 // Add/replace any new or changed extras values.
2087 putExtras(extras);
2088
2089 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2090 // the current one and remove any keys that went away.
2091 if (mPreviousExtraKeys != null) {
2092 List<String> toRemove = new ArrayList<String>();
2093 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002094 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002095 toRemove.add(oldKey);
2096 }
2097 }
2098 if (!toRemove.isEmpty()) {
2099 removeExtras(toRemove);
2100 }
2101 }
2102
2103 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2104 // called we can see if the caller has removed any extras values.
2105 if (mPreviousExtraKeys == null) {
2106 mPreviousExtraKeys = new ArraySet<String>();
2107 }
2108 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002109 if (extras != null) {
2110 mPreviousExtraKeys.addAll(extras.keySet());
2111 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002112 }
2113
2114 /**
2115 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2116 * added.
2117 * <p>
2118 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2119 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2120 *
2121 * @param extras The extras to add.
2122 */
2123 public final void putExtras(@NonNull Bundle extras) {
2124 checkImmutable();
2125 if (extras == null) {
2126 return;
2127 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002128 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2129 // the listeners.
2130 Bundle listenerExtras;
2131 synchronized (mExtrasLock) {
2132 if (mExtras == null) {
2133 mExtras = new Bundle();
2134 }
2135 mExtras.putAll(extras);
2136 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002137 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002138 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002139 // Create a new clone of the extras for each listener so that they don't clobber
2140 // each other
2141 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002142 }
2143 }
2144
2145 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002146 * Adds a boolean extra to this {@code Connection}.
2147 *
2148 * @param key The extra key.
2149 * @param value The value.
2150 * @hide
2151 */
2152 public final void putExtra(String key, boolean value) {
2153 Bundle newExtras = new Bundle();
2154 newExtras.putBoolean(key, value);
2155 putExtras(newExtras);
2156 }
2157
2158 /**
2159 * Adds an integer extra to this {@code Connection}.
2160 *
2161 * @param key The extra key.
2162 * @param value The value.
2163 * @hide
2164 */
2165 public final void putExtra(String key, int value) {
2166 Bundle newExtras = new Bundle();
2167 newExtras.putInt(key, value);
2168 putExtras(newExtras);
2169 }
2170
2171 /**
2172 * Adds a string extra to this {@code Connection}.
2173 *
2174 * @param key The extra key.
2175 * @param value The value.
2176 * @hide
2177 */
2178 public final void putExtra(String key, String value) {
2179 Bundle newExtras = new Bundle();
2180 newExtras.putString(key, value);
2181 putExtras(newExtras);
2182 }
2183
2184 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002185 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002186 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002187 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002188 */
2189 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002190 synchronized (mExtrasLock) {
2191 if (mExtras != null) {
2192 for (String key : keys) {
2193 mExtras.remove(key);
2194 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002195 }
2196 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002197 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002198 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002199 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002200 }
2201 }
2202
2203 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002204 * Removes extras from this {@code Connection}.
2205 *
2206 * @param keys The keys of the extras to remove.
2207 */
2208 public final void removeExtras(String ... keys) {
2209 removeExtras(Arrays.asList(keys));
2210 }
2211
2212 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002213 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002214 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002215 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002216 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2217 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002218 */
Yorke Lee4af59352015-05-13 14:14:54 -07002219 @SystemApi
2220 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002221 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002222
2223 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002224 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2225 *
2226 * @param state The new connection audio state.
2227 */
2228 public void onCallAudioStateChanged(CallAudioState state) {}
2229
2230 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002231 * Notifies this Connection of an internal state change. This method is called after the
2232 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002233 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002235 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002236 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002237
2238 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002239 * Notifies this Connection of a request to play a DTMF tone.
2240 *
2241 * @param c A DTMF character.
2242 */
Santos Cordonf2951102014-07-20 19:06:29 -07002243 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244
2245 /**
2246 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2247 */
Santos Cordonf2951102014-07-20 19:06:29 -07002248 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002249
2250 /**
2251 * Notifies this Connection of a request to disconnect.
2252 */
Santos Cordonf2951102014-07-20 19:06:29 -07002253 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002254
2255 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002256 * Notifies this Connection of a request to disconnect a participant of the conference managed
2257 * by the connection.
2258 *
2259 * @param endpoint the {@link Uri} of the participant to disconnect.
2260 * @hide
2261 */
2262 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2263
2264 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002265 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002266 */
Santos Cordonf2951102014-07-20 19:06:29 -07002267 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002268
2269 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002270 * Notifies this Connection of a request to abort.
2271 */
Santos Cordonf2951102014-07-20 19:06:29 -07002272 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002273
2274 /**
2275 * Notifies this Connection of a request to hold.
2276 */
Santos Cordonf2951102014-07-20 19:06:29 -07002277 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002278
2279 /**
2280 * Notifies this Connection of a request to exit a hold state.
2281 */
Santos Cordonf2951102014-07-20 19:06:29 -07002282 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002283
2284 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002285 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002286 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002287 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002288 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002289 */
Santos Cordonf2951102014-07-20 19:06:29 -07002290 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002291
2292 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002293 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002294 * a request to accept.
2295 */
2296 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002297 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002298 }
2299
2300 /**
2301 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002302 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002303 */
Santos Cordonf2951102014-07-20 19:06:29 -07002304 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002305
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002306 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002307 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2308 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002309 */
2310 public void onReject(String replyMessage) {}
2311
2312 /**
Bryce Leecac50772015-11-17 15:13:29 -08002313 * Notifies the Connection of a request to silence the ringer.
2314 *
2315 * @hide
2316 */
2317 public void onSilence() {}
2318
2319 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002320 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2321 */
Santos Cordonf2951102014-07-20 19:06:29 -07002322 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002323
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002324 /**
2325 * Notifies this Connection of a request to pull an external call to the local device.
2326 * <p>
2327 * The {@link InCallService} issues a request to pull an external call to the local device via
2328 * {@link Call#pullExternalCall()}.
2329 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002330 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2331 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002332 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002333 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002334 */
2335 public void onPullExternalCall() {}
2336
2337 /**
2338 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2339 * <p>
2340 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2341 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002342 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2343 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2344 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2345 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2346 * not aware of.
2347 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002348 * See also {@link Call#sendCallEvent(String, Bundle)}.
2349 *
2350 * @param event The call event.
2351 * @param extras Extras associated with the call event.
2352 */
2353 public void onCallEvent(String event, Bundle extras) {}
2354
Tyler Gunndee56a82016-03-23 16:06:34 -07002355 /**
2356 * Notifies this {@link Connection} of a change to the extras made outside the
2357 * {@link ConnectionService}.
2358 * <p>
2359 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2360 * the {@link android.telecom.Call#putExtras(Bundle)} and
2361 * {@link Call#removeExtras(List)}.
2362 *
2363 * @param extras The new extras bundle.
2364 */
2365 public void onExtrasChanged(Bundle extras) {}
2366
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002367 static String toLogSafePhoneNumber(String number) {
2368 // For unknown number, log empty string.
2369 if (number == null) {
2370 return "";
2371 }
2372
2373 if (PII_DEBUG) {
2374 // When PII_DEBUG is true we emit PII.
2375 return number;
2376 }
2377
2378 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2379 // sanitized phone numbers.
2380 StringBuilder builder = new StringBuilder();
2381 for (int i = 0; i < number.length(); i++) {
2382 char c = number.charAt(i);
2383 if (c == '-' || c == '@' || c == '.') {
2384 builder.append(c);
2385 } else {
2386 builder.append('x');
2387 }
2388 }
2389 return builder.toString();
2390 }
2391
Ihab Awad542e0ea2014-05-16 10:22:16 -07002392 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002393 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002394 if (mState == STATE_DISCONNECTED && mState != state) {
2395 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002396 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002397 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002398 if (mState != state) {
2399 Log.d(this, "setState: %s", stateToString(state));
2400 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002401 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002402 for (Listener l : mListeners) {
2403 l.onStateChanged(this, state);
2404 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002405 }
2406 }
2407
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002408 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002409 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002410 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2411 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002412 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002413 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002414
2415 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002416 if (mImmutable) {
2417 throw new UnsupportedOperationException("Connection is immutable");
2418 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002419 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002420 }
2421
Evan Charltonbf11f982014-07-20 22:06:28 -07002422 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002423 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002424 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2425 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002426 * <p>
2427 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2428 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002429 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002430 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002431 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002432 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002433 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2434 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002435 }
2436
Evan Charltonbf11f982014-07-20 22:06:28 -07002437 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002438 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2439 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2440 * this should never be un-@hide-den.
2441 *
2442 * @hide
2443 */
2444 public void checkImmutable() {}
2445
2446 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002447 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2448 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2449 * that state. This connection should not be used for anything, and no other
2450 * {@code Connection}s should be attempted.
2451 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002452 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002453 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002454 * @return A {@code Connection} which indicates that the underlying connection should
2455 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002456 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002457 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002458 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002459 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002460
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002461 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002462 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002463 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002464 }
2465 }
2466
Santos Cordon823fd3c2014-08-07 18:35:18 -07002467 private final void fireConferenceChanged() {
2468 for (Listener l : mListeners) {
2469 l.onConferenceChanged(this, mConference);
2470 }
2471 }
2472
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002473 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002474 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002475 if (c instanceof Connection) {
2476 Connection connection = (Connection) c;
2477 connection.removeConnectionListener(mConnectionDeathListener);
2478 } else if (c instanceof Conference) {
2479 Conference conference = (Conference) c;
2480 conference.removeListener(mConferenceDeathListener);
2481 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002482 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002483 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002484 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002485
2486 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002487 * Handles a change to extras received from Telecom.
2488 *
2489 * @param extras The new extras.
2490 * @hide
2491 */
2492 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002493 Bundle b = null;
2494 synchronized (mExtrasLock) {
2495 mExtras = extras;
2496 if (mExtras != null) {
2497 b = new Bundle(mExtras);
2498 }
2499 }
2500 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002501 }
2502
2503 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002504 * Notifies listeners that the merge request failed.
2505 *
2506 * @hide
2507 */
2508 protected final void notifyConferenceMergeFailed() {
2509 for (Listener l : mListeners) {
2510 l.onConferenceMergeFailed(this);
2511 }
2512 }
2513
2514 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002515 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002516 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002517 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002518 * @hide
2519 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002520 protected final void updateConferenceParticipants(
2521 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002522 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002523 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002524 }
2525 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002526
2527 /**
2528 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002529 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002530 */
2531 protected void notifyConferenceStarted() {
2532 for (Listener l : mListeners) {
2533 l.onConferenceStarted();
2534 }
2535 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002536
2537 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002538 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2539 * be a part of a conference call.
2540 * @param isConferenceSupported {@code true} if the connection supports being part of a
2541 * conference call, {@code false} otherwise.
2542 * @hide
2543 */
2544 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2545 for (Listener l : mListeners) {
2546 l.onConferenceSupportedChanged(this, isConferenceSupported);
2547 }
2548 }
2549
2550 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002551 * Sends an event associated with this {@code Connection} with associated event extras to the
2552 * {@link InCallService}.
2553 * <p>
2554 * Connection events are used to communicate point in time information from a
2555 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2556 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2557 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2558 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2559 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2560 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2561 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2562 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2563 * <p>
2564 * Events are exposed to {@link InCallService} implementations via
2565 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2566 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002567 * 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 -07002568 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2569 * some events altogether.
2570 * <p>
2571 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2572 * conflicts between {@link ConnectionService} implementations. Further, custom
2573 * {@link ConnectionService} implementations shall not re-purpose events in the
2574 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2575 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2576 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2577 * {@code com.example.extra.MY_EXTRA}).
2578 * <p>
2579 * When defining events and the associated extras, it is important to keep their behavior
2580 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2581 * events/extras should me maintained to ensure backwards compatibility with older
2582 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002583 *
2584 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002585 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002586 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002587 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002588 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002589 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002590 }
2591 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002592}