blob: 2b9a508511861fabd1af04bdece1c21c6ed9cecc [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;
Tyler Gunnb88b3112016-11-09 10:19:23 -080028import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import android.os.Handler;
31import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070032import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Message;
34import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070035import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070037
Santos Cordonb6939982014-06-04 20:20:58 -070038import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070039import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070041import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070043import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070044
45/**
Santos Cordon895d4b82015-06-25 16:41:48 -070046 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
47 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070048 * <p>
49 * Implementations create a custom subclass of {@code Connection} and return it to the framework
50 * as the return value of
51 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
52 * or
53 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
54 * Implementations are then responsible for updating the state of the {@code Connection}, and
55 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
56 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070057 * <p>
58 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
59 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
60 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
61 * {@code Connection} instance.
62 * <p>
63 * Basic call support requires overriding the following methods: {@link #onAnswer()},
64 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
65 * <p>
66 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
67 * {@link #onUnhold()} methods should be overridden to provide hold support for the
68 * {@code Connection}.
69 * <p>
70 * Where a {@code Connection} supports a variation of video calling (e.g. the
71 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
72 * to support answering a call as a video call.
73 * <p>
74 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
75 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
76 * support for pulling the external call.
77 * <p>
78 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
79 * overridden.
80 * <p>
81 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
82 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
83 * for example, call events from a {@link InCallService} are handled,
84 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
85 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
86 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
87 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070088 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070089public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070090
Santos Cordon895d4b82015-06-25 16:41:48 -070091 /**
92 * The connection is initializing. This is generally the first state for a {@code Connection}
93 * returned by a {@link ConnectionService}.
94 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070095 public static final int STATE_INITIALIZING = 0;
96
Santos Cordon895d4b82015-06-25 16:41:48 -070097 /**
98 * The connection is new and not connected.
99 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 public static final int STATE_NEW = 1;
101
Santos Cordon895d4b82015-06-25 16:41:48 -0700102 /**
103 * An incoming connection is in the ringing state. During this state, the user's ringer or
104 * vibration feature will be activated.
105 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 public static final int STATE_RINGING = 2;
107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * An outgoing connection is in the dialing state. In this state the other party has not yet
110 * answered the call and the user traditionally hears a ringback tone.
111 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 public static final int STATE_DIALING = 3;
113
Santos Cordon895d4b82015-06-25 16:41:48 -0700114 /**
115 * A connection is active. Both parties are connected to the call and can actively communicate.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_ACTIVE = 4;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * A connection is on hold.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_HOLDING = 5;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * A connection has been disconnected. This is the final state once the user has been
126 * disconnected from a call either locally, remotely or by an error in the service.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_DISCONNECTED = 6;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700131 * The state of an external connection which is in the process of being pulled from a remote
132 * device to the local device.
133 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700134 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700135 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
136 */
137 public static final int STATE_PULLING_CALL = 7;
138
139 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 * Connection can currently be put on hold or unheld. This is distinct from
141 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
142 * it does not at the moment support the function. This can be true while the call is in the
143 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
144 * display a disabled 'hold' button.
145 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800146 public static final int CAPABILITY_HOLD = 0x00000001;
147
148 /** Connection supports the hold feature. */
149 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
150
151 /**
152 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
153 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
154 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
155 * capability allows a merge button to be shown while the conference is in the foreground
156 * of the in-call UI.
157 * <p>
158 * This is only intended for use by a {@link Conference}.
159 */
160 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
161
162 /**
163 * Connections within a conference can be swapped between foreground and background.
164 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
165 * <p>
166 * This is only intended for use by a {@link Conference}.
167 */
168 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
169
170 /**
171 * @hide
172 */
173 public static final int CAPABILITY_UNUSED = 0x00000010;
174
175 /** Connection supports responding via text option. */
176 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
177
178 /** Connection can be muted. */
179 public static final int CAPABILITY_MUTE = 0x00000040;
180
181 /**
182 * Connection supports conference management. This capability only applies to
183 * {@link Conference}s which can have {@link Connection}s as children.
184 */
185 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
186
187 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700188 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800191
192 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700193 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800194 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700195 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800196
197 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700200 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
207
208 /**
209 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 */
211 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
212
213 /**
214 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700216 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800218
219 /**
220 * Connection is able to be separated from its parent {@code Conference}, if any.
221 */
222 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
223
224 /**
225 * Connection is able to be individually disconnected when in a {@code Conference}.
226 */
227 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
228
229 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700230 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800231 * @hide
232 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700233 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700235 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700236 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700237 * @hide
238 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700240
241 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700242 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700243 * @hide
244 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246
Tyler Gunn068085b2015-02-06 13:56:52 -0800247 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800249 * @hide
250 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800252
Tyler Gunn96d6c402015-03-18 12:39:23 -0700253 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500254 * Speed up audio setup for MT call.
255 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700256 */
257 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800258
Rekha Kumar07366812015-03-24 16:42:31 -0700259 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700260 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700261 */
262 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
263
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700264 /**
265 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700266 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700267 */
268 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
269
Tyler Gunnd4091732015-06-29 09:15:37 -0700270 /**
271 * For a conference, indicates the conference will not have child connections.
272 * <p>
273 * An example of a conference with child connections is a GSM conference call, where the radio
274 * retains connections to the individual participants of the conference. Another example is an
275 * IMS conference call where conference event package functionality is supported; in this case
276 * the conference server ensures the radio is aware of the participants in the conference, which
277 * are represented by child connections.
278 * <p>
279 * An example of a conference with no child connections is an IMS conference call with no
280 * conference event package support. Such a conference is represented by the radio as a single
281 * connection to the IMS conference server.
282 * <p>
283 * Indicating whether a conference has children or not is important to help user interfaces
284 * visually represent a conference. A conference with no children, for example, will have the
285 * conference connection shown in the list of calls on a Bluetooth device, where if the
286 * conference has children, only the children will be shown in the list of calls on a Bluetooth
287 * device.
288 * @hide
289 */
290 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
291
Bryce Lee81901682015-08-28 16:38:02 -0700292 /**
293 * Indicates that the connection itself wants to handle any sort of reply response, rather than
294 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700295 */
296 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
297
Tyler Gunnf97a0092016-01-19 15:59:34 -0800298 /**
299 * When set, prevents a video call from being downgraded to an audio-only call.
300 * <p>
301 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
302 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
303 * downgraded from a video call back to a VideoState of
304 * {@link VideoProfile#STATE_AUDIO_ONLY}.
305 * <p>
306 * Intuitively, a call which can be downgraded to audio should also have local and remote
307 * video
308 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
309 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
310 */
311 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
312
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700313 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700314 * When set for an external connection, indicates that this {@code Connection} can be pulled
315 * from a remote device to the current device.
316 * <p>
317 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
318 * is set.
319 */
320 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
321
322 //**********************************************************************************************
323 // Next CAPABILITY value: 0x02000000
324 //**********************************************************************************************
325
326 /**
327 * Indicates that the current device callback number should be shown.
328 *
329 * @hide
330 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700331 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700332
333 /**
334 * Whether the call is a generic conference, where we do not know the precise state of
335 * participants in the conference (eg. on CDMA).
336 *
337 * @hide
338 */
339 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
340
341 /**
342 * Connection is using high definition audio.
343 * @hide
344 */
345 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
346
347 /**
348 * Connection is using WIFI.
349 * @hide
350 */
351 public static final int PROPERTY_WIFI = 1<<3;
352
353 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700354 * When set, indicates that the {@code Connection} does not actually exist locally for the
355 * {@link ConnectionService}.
356 * <p>
357 * Consider, for example, a scenario where a user has two devices with the same phone number.
358 * When a user places a call on one devices, the telephony stack can represent that call on the
359 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700360 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700361 * <p>
362 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
363 * external connections. Only those {@link InCallService}s which have the
364 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
365 * manifest will see external connections.
366 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700367 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368
Brad Ebinger15847072016-05-18 11:08:36 -0700369 /**
370 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
371 */
372 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700373
Hall Liu9f332c72016-07-14 15:37:37 -0700374 /**
375 * Indicates that the connection represents a downgraded IMS conference.
376 * @hide
377 */
378 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
379
Tyler Gunn96d6c402015-03-18 12:39:23 -0700380 //**********************************************************************************************
Hall Liu9f332c72016-07-14 15:37:37 -0700381 // Next PROPERTY value: 1<<7
Tyler Gunn96d6c402015-03-18 12:39:23 -0700382 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800383
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700384 /**
385 * Connection extra key used to store the last forwarded number associated with the current
386 * connection. Used to communicate to the user interface that the connection was forwarded via
387 * the specified number.
388 */
389 public static final String EXTRA_LAST_FORWARDED_NUMBER =
390 "android.telecom.extra.LAST_FORWARDED_NUMBER";
391
392 /**
393 * Connection extra key used to store a child number associated with the current connection.
394 * Used to communicate to the user interface that the connection was received via
395 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
396 * address.
397 */
398 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
399
400 /**
401 * Connection extra key used to store the subject for an incoming call. The user interface can
402 * query this extra and display its contents for incoming calls. Will only be used if the
403 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
404 */
405 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
406
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800407 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700408 * Boolean connection extra key set on a {@link Connection} in
409 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
410 * current active foreground call to be dropped.
411 */
412 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
413 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
414
415 /**
Hall Liu10208662016-06-15 17:55:00 -0700416 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700417 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700418 * @hide
419 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700420 public static final String EXTRA_DISABLE_ADD_CALL =
421 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700422
423 /**
Tyler Gunn2282bb92016-10-17 15:48:19 -0700424 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
425 * original Connection ID associated with the connection. Used in
426 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
427 * connection/conference added via
428 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
429 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
430 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
431 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
432 * be a way to ensure that we don't add the connection again as a duplicate.
433 * <p>
434 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
435 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
436 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
437 * in a new {@link Connection} which it adds to Telecom via
438 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
439 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
440 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
441 * ID it originally referred to the connection as. Thus Telecom needs to know that the
442 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
443 * @hide
444 */
445 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
446 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
447
448 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800449 * Connection event used to inform Telecom that it should play the on hold tone. This is used
450 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700451 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800452 * @hide
453 */
454 public static final String EVENT_ON_HOLD_TONE_START =
455 "android.telecom.event.ON_HOLD_TONE_START";
456
457 /**
458 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
459 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700460 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800461 * @hide
462 */
463 public static final String EVENT_ON_HOLD_TONE_END =
464 "android.telecom.event.ON_HOLD_TONE_END";
465
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700466 /**
467 * Connection event used to inform {@link InCallService}s when pulling of an external call has
468 * failed. The user interface should inform the user of the error.
469 * <p>
470 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
471 * API is called on a {@link Call} with the properties
472 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
473 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
474 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700475 * <p>
476 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
477 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700478 */
479 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
480
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700481 /**
482 * Connection event used to inform {@link InCallService}s when the merging of two calls has
483 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700484 * <p>
485 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
486 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700487 */
488 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
489
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700490 /**
491 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
492 * the remote party.
493 * <p>
494 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
495 * call is being held locally on the device. When a capable {@link ConnectionService} receives
496 * signalling to indicate that the remote party has put the call on hold, it can send this
497 * connection event.
498 * @hide
499 */
500 public static final String EVENT_CALL_REMOTELY_HELD =
501 "android.telecom.event.CALL_REMOTELY_HELD";
502
503 /**
504 * Connection event used to inform {@link InCallService}s when a call which was remotely held
505 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
506 * <p>
507 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
508 * call is being held locally on the device. When a capable {@link ConnectionService} receives
509 * signalling to indicate that the remote party has taken the call off hold, it can send this
510 * connection event.
511 * @hide
512 */
513 public static final String EVENT_CALL_REMOTELY_UNHELD =
514 "android.telecom.event.CALL_REMOTELY_UNHELD";
515
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700516 // Flag controlling whether PII is emitted into the logs
517 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
518
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800519 /**
520 * Whether the given capabilities support the specified capability.
521 *
522 * @param capabilities A capability bit field.
523 * @param capability The capability to check capabilities for.
524 * @return Whether the specified capability is supported.
525 * @hide
526 */
527 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800528 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800529 }
530
531 /**
532 * Whether the capabilities of this {@code Connection} supports the specified capability.
533 *
534 * @param capability The capability to check capabilities for.
535 * @return Whether the specified capability is supported.
536 * @hide
537 */
538 public boolean can(int capability) {
539 return can(mConnectionCapabilities, capability);
540 }
541
542 /**
543 * Removes the specified capability from the set of capabilities of this {@code Connection}.
544 *
545 * @param capability The capability to remove from the set.
546 * @hide
547 */
548 public void removeCapability(int capability) {
549 mConnectionCapabilities &= ~capability;
550 }
551
552 /**
553 * Adds the specified capability to the set of capabilities of this {@code Connection}.
554 *
555 * @param capability The capability to add to the set.
556 * @hide
557 */
558 public void addCapability(int capability) {
559 mConnectionCapabilities |= capability;
560 }
561
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700562 /**
563 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
564 *
565 * @param capabilities A capability bit field.
566 * @return A human readable string representation.
567 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800568 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700569 return capabilitiesToStringInternal(capabilities, true /* isLong */);
570 }
571
572 /**
573 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
574 * string.
575 *
576 * @param capabilities A capability bit field.
577 * @return A human readable string representation.
578 * @hide
579 */
580 public static String capabilitiesToStringShort(int capabilities) {
581 return capabilitiesToStringInternal(capabilities, false /* isLong */);
582 }
583
584 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800585 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700586 builder.append("[");
587 if (isLong) {
588 builder.append("Capabilities:");
589 }
590
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800591 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700592 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800593 }
594 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700595 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800596 }
597 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700598 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800599 }
600 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700601 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800602 }
603 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700604 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800605 }
606 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700607 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800608 }
609 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700610 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700612 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700613 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700614 }
615 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700616 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700617 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700618 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700619 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700621 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700622 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700623 }
624 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700625 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700626 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700627 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700628 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800630 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700631 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800632 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500633 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700634 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500635 }
Rekha Kumar07366812015-03-24 16:42:31 -0700636 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700637 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700638 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700639 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700640 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700641 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700642 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700643 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700644 }
Bryce Lee81901682015-08-28 16:38:02 -0700645 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700646 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700647 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700648 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700649 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700650 }
Bryce Lee81901682015-08-28 16:38:02 -0700651
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800652 builder.append("]");
653 return builder.toString();
654 }
655
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700656 /**
657 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
658 *
659 * @param properties A property bit field.
660 * @return A human readable string representation.
661 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700662 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 return propertiesToStringInternal(properties, true /* isLong */);
664 }
665
666 /**
667 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
668 *
669 * @param properties A property bit field.
670 * @return A human readable string representation.
671 * @hide
672 */
673 public static String propertiesToStringShort(int properties) {
674 return propertiesToStringInternal(properties, false /* isLong */);
675 }
676
677 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700678 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append("[");
680 if (isLong) {
681 builder.append("Properties:");
682 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700683
Hall Liu25c7c4d2016-08-30 13:41:02 -0700684 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
685 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700686 }
687
688 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700689 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700690 }
691
692 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700694 }
695
696 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700698 }
699
700 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700701 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700702 }
703
Brad Ebinger15847072016-05-18 11:08:36 -0700704 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700706 }
707
Tyler Gunn720c6642016-03-22 09:02:47 -0700708 builder.append("]");
709 return builder.toString();
710 }
711
Sailesh Nepal091768c2014-06-30 15:15:23 -0700712 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700713 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700714 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700715 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700716 public void onCallerDisplayNameChanged(
717 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700718 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700719 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700720 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800721 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700722 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700723 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800724 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700725 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 public void onVideoProviderChanged(
727 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700728 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
729 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800730 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700731 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700732 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700733 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800734 public void onConferenceParticipantsChanged(Connection c,
735 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800736 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700737 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700738 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700739 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700740 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700741 /** @hide */
742 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700743 }
744
Tyler Gunnb702ef82015-05-29 11:51:53 -0700745 /**
746 * Provides a means of controlling the video session associated with a {@link Connection}.
747 * <p>
748 * Implementations create a custom subclass of {@link VideoProvider} and the
749 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
750 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
751 * should set the {@link VideoProvider}.
752 * <p>
753 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
754 * {@link InCallService} implementations to issue requests related to the video session;
755 * it provides a means for the {@link ConnectionService} to report events and information
756 * related to the video session to Telecom and the {@link InCallService} implementations.
757 * <p>
758 * {@link InCallService} implementations interact with the {@link VideoProvider} via
759 * {@link android.telecom.InCallService.VideoCall}.
760 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 /**
763 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700764 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 */
766 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700767
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700768 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700769 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
770 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700771 */
772 public static final int SESSION_EVENT_RX_RESUME = 2;
773
774 /**
775 * Video transmission has begun. This occurs after a negotiated start of video transmission
776 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700777 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 */
779 public static final int SESSION_EVENT_TX_START = 3;
780
781 /**
782 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
783 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700784 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700785 */
786 public static final int SESSION_EVENT_TX_STOP = 4;
787
788 /**
Tyler Gunnb88b3112016-11-09 10:19:23 -0800789 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700790 * this as a cue to inform the user the camera is not available.
791 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 */
793 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
794
795 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700796 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnb88b3112016-11-09 10:19:23 -0800797 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700798 * the camera has become available again.
799 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700800 */
801 public static final int SESSION_EVENT_CAMERA_READY = 6;
802
803 /**
Tyler Gunnb88b3112016-11-09 10:19:23 -0800804 * Session event raised by Telecom when
805 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
806 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
807 * @see #handleCallSessionEvent(int)
808 */
809 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
810
811 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700813 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 */
815 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
816
817 /**
818 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700819 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 */
821 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
822
823 /**
824 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700825 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700826 */
827 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
828
Rekha Kumar07366812015-03-24 16:42:31 -0700829 /**
830 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700831 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700832 */
833 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
834
835 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700836 * Session modify request rejected by remote user.
837 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700838 */
839 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
840
Tyler Gunn75958422015-04-15 14:23:42 -0700841 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700842 private static final int MSG_SET_CAMERA = 2;
843 private static final int MSG_SET_PREVIEW_SURFACE = 3;
844 private static final int MSG_SET_DISPLAY_SURFACE = 4;
845 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
846 private static final int MSG_SET_ZOOM = 6;
847 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
848 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
849 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800850 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700852 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700854 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
855 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
856 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
857 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
858 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
859 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnb88b3112016-11-09 10:19:23 -0800860 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
861 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700862 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
863
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700864 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700866
867 /**
868 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700869 *
870 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
871 * load factor before resizing, 1 means we only expect a single thread to
872 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700873 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700874 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
875 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876
877 /**
878 * Default handler used to consolidate binder method calls onto a single thread.
879 */
880 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700881 public VideoProviderHandler() {
882 super();
883 }
884
885 public VideoProviderHandler(Looper looper) {
886 super(looper);
887 }
888
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 @Override
890 public void handleMessage(Message msg) {
891 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700892 case MSG_ADD_VIDEO_CALLBACK: {
893 IBinder binder = (IBinder) msg.obj;
894 IVideoCallback callback = IVideoCallback.Stub
895 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700896 if (callback == null) {
897 Log.w(this, "addVideoProvider - skipped; callback is null.");
898 break;
899 }
900
Tyler Gunn75958422015-04-15 14:23:42 -0700901 if (mVideoCallbacks.containsKey(binder)) {
902 Log.i(this, "addVideoProvider - skipped; already present.");
903 break;
904 }
905 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700907 }
908 case MSG_REMOVE_VIDEO_CALLBACK: {
909 IBinder binder = (IBinder) msg.obj;
910 IVideoCallback callback = IVideoCallback.Stub
911 .asInterface((IBinder) msg.obj);
912 if (!mVideoCallbacks.containsKey(binder)) {
913 Log.i(this, "removeVideoProvider - skipped; not present.");
914 break;
915 }
916 mVideoCallbacks.remove(binder);
917 break;
918 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700919 case MSG_SET_CAMERA:
Tyler Gunnb88b3112016-11-09 10:19:23 -0800920 {
921 SomeArgs args = (SomeArgs) msg.obj;
922 try {
923 onSetCamera((String) args.arg1);
924 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
925 args.argi2);
926 } finally {
927 args.recycle();
928 }
929 }
930 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 case MSG_SET_PREVIEW_SURFACE:
932 onSetPreviewSurface((Surface) msg.obj);
933 break;
934 case MSG_SET_DISPLAY_SURFACE:
935 onSetDisplaySurface((Surface) msg.obj);
936 break;
937 case MSG_SET_DEVICE_ORIENTATION:
938 onSetDeviceOrientation(msg.arg1);
939 break;
940 case MSG_SET_ZOOM:
941 onSetZoom((Float) msg.obj);
942 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700943 case MSG_SEND_SESSION_MODIFY_REQUEST: {
944 SomeArgs args = (SomeArgs) msg.obj;
945 try {
946 onSendSessionModifyRequest((VideoProfile) args.arg1,
947 (VideoProfile) args.arg2);
948 } finally {
949 args.recycle();
950 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700952 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 case MSG_SEND_SESSION_MODIFY_RESPONSE:
954 onSendSessionModifyResponse((VideoProfile) msg.obj);
955 break;
956 case MSG_REQUEST_CAMERA_CAPABILITIES:
957 onRequestCameraCapabilities();
958 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800959 case MSG_REQUEST_CONNECTION_DATA_USAGE:
960 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 break;
962 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700963 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 break;
965 default:
966 break;
967 }
968 }
969 }
970
971 /**
972 * IVideoProvider stub implementation.
973 */
974 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700975 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700977 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
978 }
979
980 public void removeVideoCallback(IBinder videoCallbackBinder) {
981 mMessageHandler.obtainMessage(
982 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 }
984
Tyler Gunnb88b3112016-11-09 10:19:23 -0800985 public void setCamera(String cameraId, String callingPackageName) {
986 SomeArgs args = SomeArgs.obtain();
987 args.arg1 = cameraId;
988 // Propagate the calling package; originally determined in
989 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
990 // process.
991 args.arg2 = callingPackageName;
992 // Pass along the uid and pid of the calling app; this gets lost when we put the
993 // message onto the handler. These are required for Telecom to perform a permission
994 // check to see if the calling app is able to use the camera.
995 args.argi1 = Binder.getCallingUid();
996 args.argi2 = Binder.getCallingPid();
997 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 }
999
1000 public void setPreviewSurface(Surface surface) {
1001 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1002 }
1003
1004 public void setDisplaySurface(Surface surface) {
1005 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1006 }
1007
1008 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001009 mMessageHandler.obtainMessage(
1010 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 }
1012
1013 public void setZoom(float value) {
1014 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1015 }
1016
Tyler Gunn45382162015-05-06 08:52:27 -07001017 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1018 SomeArgs args = SomeArgs.obtain();
1019 args.arg1 = fromProfile;
1020 args.arg2 = toProfile;
1021 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 }
1023
1024 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1025 mMessageHandler.obtainMessage(
1026 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1027 }
1028
1029 public void requestCameraCapabilities() {
1030 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1031 }
1032
1033 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001034 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001035 }
1036
Yorke Lee32f24732015-05-12 16:18:03 -07001037 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1039 }
1040 }
1041
1042 public VideoProvider() {
1043 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001044 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001045 }
1046
1047 /**
1048 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1049 *
1050 * @param looper The looper.
1051 * @hide
1052 */
1053 public VideoProvider(Looper looper) {
1054 mBinder = new VideoProvider.VideoProviderBinder();
1055 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 }
1057
1058 /**
1059 * Returns binder object which can be used across IPC methods.
1060 * @hide
1061 */
1062 public final IVideoProvider getInterface() {
1063 return mBinder;
1064 }
1065
1066 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001067 * Sets the camera to be used for the outgoing video.
1068 * <p>
1069 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1070 * camera via
1071 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1072 * <p>
1073 * Sent from the {@link InCallService} via
1074 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001076 * @param cameraId The id of the camera (use ids as reported by
1077 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078 */
1079 public abstract void onSetCamera(String cameraId);
1080
1081 /**
Tyler Gunnb88b3112016-11-09 10:19:23 -08001082 * Sets the camera to be used for the outgoing video.
1083 * <p>
1084 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1085 * camera via
1086 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1087 * <p>
1088 * This prototype is used internally to ensure that the calling package name, UID and PID
1089 * are sent to Telecom so that can perform a camera permission check on the caller.
1090 * <p>
1091 * Sent from the {@link InCallService} via
1092 * {@link InCallService.VideoCall#setCamera(String)}.
1093 *
1094 * @param cameraId The id of the camera (use ids as reported by
1095 * {@link CameraManager#getCameraIdList()}).
1096 * @param callingPackageName The AppOpps package name of the caller.
1097 * @param callingUid The UID of the caller.
1098 * @param callingPid The PID of the caller.
1099 * @hide
1100 */
1101 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
1102 int callingPid) {}
1103
1104 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 * Sets the surface to be used for displaying a preview of what the user's camera is
1106 * currently capturing. When video transmission is enabled, this is the video signal which
1107 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001108 * <p>
1109 * Sent from the {@link InCallService} via
1110 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001112 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 */
1114 public abstract void onSetPreviewSurface(Surface surface);
1115
1116 /**
1117 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001118 * <p>
1119 * Sent from the {@link InCallService} via
1120 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001122 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001123 */
1124 public abstract void onSetDisplaySurface(Surface surface);
1125
1126 /**
1127 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1128 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 * <p>
1130 * Sent from the {@link InCallService} via
1131 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 *
1133 * @param rotation The device orientation, in degrees.
1134 */
1135 public abstract void onSetDeviceOrientation(int rotation);
1136
1137 /**
1138 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001139 * <p>
1140 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 *
1142 * @param value The camera zoom ratio.
1143 */
1144 public abstract void onSetZoom(float value);
1145
1146 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001147 * Issues a request to modify the properties of the current video session.
1148 * <p>
1149 * Example scenarios include: requesting an audio-only call to be upgraded to a
1150 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1151 * when the {@link InCallService} is no longer the foreground application.
1152 * <p>
1153 * If the {@link VideoProvider} determines a request to be invalid, it should call
1154 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1155 * invalid request back to the {@link InCallService}.
1156 * <p>
1157 * Where a request requires confirmation from the user of the peer device, the
1158 * {@link VideoProvider} must communicate the request to the peer device and handle the
1159 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1160 * is used to inform the {@link InCallService} of the result of the request.
1161 * <p>
1162 * Sent from the {@link InCallService} via
1163 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001165 * @param fromProfile The video profile prior to the request.
1166 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167 */
Tyler Gunn45382162015-05-06 08:52:27 -07001168 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1169 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170
Tyler Gunnb702ef82015-05-29 11:51:53 -07001171 /**
1172 * Provides a response to a request to change the current video session properties.
1173 * <p>
1174 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1175 * video call, could decline the request and keep the call as audio-only.
1176 * In such a scenario, the {@code responseProfile} would have a video state of
1177 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1178 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1179 * <p>
1180 * Sent from the {@link InCallService} via
1181 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1182 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1183 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001185 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001186 */
1187 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1188
1189 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001190 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1191 * <p>
1192 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1193 * camera via
1194 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1195 * <p>
1196 * Sent from the {@link InCallService} via
1197 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001198 */
1199 public abstract void onRequestCameraCapabilities();
1200
1201 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001202 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1203 * video component of the current {@link Connection}.
1204 * <p>
1205 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1206 * via {@link VideoProvider#setCallDataUsage(long)}.
1207 * <p>
1208 * Sent from the {@link InCallService} via
1209 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001211 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001212
1213 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001214 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1215 * the peer device when the video signal is paused.
1216 * <p>
1217 * Sent from the {@link InCallService} via
1218 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001219 *
1220 * @param uri URI of image to display.
1221 */
Yorke Lee32f24732015-05-12 16:18:03 -07001222 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223
1224 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001225 * Used to inform listening {@link InCallService} implementations when the
1226 * {@link VideoProvider} receives a session modification request.
1227 * <p>
1228 * Received by the {@link InCallService} via
1229 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001230 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001231 * @param videoProfile The requested video profile.
1232 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 */
1234 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001235 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001236 for (IVideoCallback callback : mVideoCallbacks.values()) {
1237 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001238 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001239 } catch (RemoteException ignored) {
1240 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001241 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001242 }
1243 }
1244 }
1245
1246 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001247 * Used to inform listening {@link InCallService} implementations when the
1248 * {@link VideoProvider} receives a response to a session modification request.
1249 * <p>
1250 * Received by the {@link InCallService} via
1251 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1252 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 *
1254 * @param status Status of the session modify request. Valid values are
1255 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1256 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001257 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1258 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1259 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1260 * @param requestedProfile The original request which was sent to the peer device.
1261 * @param responseProfile The actual profile changes agreed to by the peer device.
1262 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001263 */
1264 public void receiveSessionModifyResponse(int status,
1265 VideoProfile requestedProfile, VideoProfile responseProfile) {
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.receiveSessionModifyResponse(status, requestedProfile,
1270 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001271 } catch (RemoteException ignored) {
1272 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001273 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 }
1275 }
1276 }
1277
1278 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001279 * Used to inform listening {@link InCallService} implementations when the
1280 * {@link VideoProvider} reports a call session event.
1281 * <p>
1282 * Received by the {@link InCallService} via
1283 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001285 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1286 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1287 * {@link VideoProvider#SESSION_EVENT_TX_START},
1288 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1289 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnb88b3112016-11-09 10:19:23 -08001290 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1291 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001292 */
1293 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001294 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001295 for (IVideoCallback callback : mVideoCallbacks.values()) {
1296 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001297 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001298 } catch (RemoteException ignored) {
1299 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001300 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 }
1302 }
1303 }
1304
1305 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001306 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1307 * peer's video have changed.
1308 * <p>
1309 * This could occur if, for example, the peer rotates their device, changing the aspect
1310 * ratio of the video, or if the user switches between the back and front cameras.
1311 * <p>
1312 * Received by the {@link InCallService} via
1313 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 *
1315 * @param width The updated peer video width.
1316 * @param height The updated peer video height.
1317 */
1318 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001319 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001320 for (IVideoCallback callback : mVideoCallbacks.values()) {
1321 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001322 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001323 } catch (RemoteException ignored) {
1324 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001325 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 }
1327 }
1328 }
1329
1330 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001331 * Used to inform listening {@link InCallService} implementations when the data usage of the
1332 * video associated with the current {@link Connection} has changed.
1333 * <p>
1334 * This could be in response to a preview request via
1335 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001336 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1337 * 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 -07001338 * <p>
1339 * Received by the {@link InCallService} via
1340 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001342 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1343 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001344 */
Yorke Lee32f24732015-05-12 16:18:03 -07001345 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001346 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001347 for (IVideoCallback callback : mVideoCallbacks.values()) {
1348 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001349 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001350 } catch (RemoteException ignored) {
1351 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001352 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 }
1354 }
1355 }
1356
1357 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001358 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001359 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001360 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001361 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1362 * @hide
1363 */
1364 public void changeCallDataUsage(long dataUsage) {
1365 setCallDataUsage(dataUsage);
1366 }
1367
1368 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001369 * Used to inform listening {@link InCallService} implementations when the capabilities of
1370 * the current camera have changed.
1371 * <p>
1372 * The {@link VideoProvider} should call this in response to
1373 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1374 * changed via {@link VideoProvider#onSetCamera(String)}.
1375 * <p>
1376 * Received by the {@link InCallService} via
1377 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1378 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001379 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001380 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 */
Yorke Lee400470f2015-05-12 13:31:25 -07001382 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001383 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001384 for (IVideoCallback callback : mVideoCallbacks.values()) {
1385 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001386 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001387 } catch (RemoteException ignored) {
1388 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001389 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 }
1391 }
1392 }
Rekha Kumar07366812015-03-24 16:42:31 -07001393
1394 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001395 * Used to inform listening {@link InCallService} implementations when the video quality
1396 * of the call has changed.
1397 * <p>
1398 * Received by the {@link InCallService} via
1399 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001400 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001401 * @param videoQuality The updated video quality. Valid values:
1402 * {@link VideoProfile#QUALITY_HIGH},
1403 * {@link VideoProfile#QUALITY_MEDIUM},
1404 * {@link VideoProfile#QUALITY_LOW},
1405 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001406 */
1407 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001408 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001409 for (IVideoCallback callback : mVideoCallbacks.values()) {
1410 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001411 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001412 } catch (RemoteException ignored) {
1413 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001414 }
Rekha Kumar07366812015-03-24 16:42:31 -07001415 }
1416 }
1417 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001418
1419 /**
1420 * Returns a string representation of a call session event.
1421 *
1422 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1423 * @return String representation of the call session event.
1424 * @hide
1425 */
1426 public static String sessionEventToString(int event) {
1427 switch (event) {
1428 case SESSION_EVENT_CAMERA_FAILURE:
1429 return SESSION_EVENT_CAMERA_FAILURE_STR;
1430 case SESSION_EVENT_CAMERA_READY:
1431 return SESSION_EVENT_CAMERA_READY_STR;
1432 case SESSION_EVENT_RX_PAUSE:
1433 return SESSION_EVENT_RX_PAUSE_STR;
1434 case SESSION_EVENT_RX_RESUME:
1435 return SESSION_EVENT_RX_RESUME_STR;
1436 case SESSION_EVENT_TX_START:
1437 return SESSION_EVENT_TX_START_STR;
1438 case SESSION_EVENT_TX_STOP:
1439 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001440 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1441 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001442 default:
1443 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1444 }
1445 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001446 }
1447
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001448 private final Listener mConnectionDeathListener = new Listener() {
1449 @Override
1450 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001451 if (mConferenceables.remove(c)) {
1452 fireOnConferenceableConnectionsChanged();
1453 }
1454 }
1455 };
1456
1457 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1458 @Override
1459 public void onDestroyed(Conference c) {
1460 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001461 fireOnConferenceableConnectionsChanged();
1462 }
1463 }
1464 };
1465
Jay Shrauner229e3822014-08-15 09:23:07 -07001466 /**
1467 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1468 * load factor before resizing, 1 means we only expect a single thread to
1469 * access the map so make only a single shard
1470 */
1471 private final Set<Listener> mListeners = Collections.newSetFromMap(
1472 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001473 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1474 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001475 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001476
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001477 // The internal telecom call ID associated with this connection.
1478 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001480 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001481 private Uri mAddress;
1482 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001483 private String mCallerDisplayName;
1484 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001485 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001486 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001487 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001489 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001490 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001491 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001492 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001493 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001494 private Conference mConference;
1495 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001496 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001497 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001498
1499 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001500 * Tracks the key set for the extras bundle provided on the last invocation of
1501 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1502 * keys which were set previously but are no longer present in the replacement Bundle.
1503 */
1504 private Set<String> mPreviousExtraKeys;
1505
1506 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001507 * Create a new Connection.
1508 */
Santos Cordonf2951102014-07-20 19:06:29 -07001509 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001510
1511 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001512 * Returns the Telecom internal call ID associated with this connection. Should only be used
1513 * for debugging and tracing purposes.
1514 *
1515 * @return The Telecom call ID.
1516 * @hide
1517 */
1518 public final String getTelecomCallId() {
1519 return mTelecomCallId;
1520 }
1521
1522 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001523 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001524 */
Andrew Lee100e2932014-09-08 15:34:24 -07001525 public final Uri getAddress() {
1526 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001527 }
1528
1529 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001530 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001531 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001532 */
Andrew Lee100e2932014-09-08 15:34:24 -07001533 public final int getAddressPresentation() {
1534 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001535 }
1536
1537 /**
1538 * @return The caller display name (CNAP).
1539 */
1540 public final String getCallerDisplayName() {
1541 return mCallerDisplayName;
1542 }
1543
1544 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001545 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001546 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001547 */
1548 public final int getCallerDisplayNamePresentation() {
1549 return mCallerDisplayNamePresentation;
1550 }
1551
1552 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001553 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001554 */
1555 public final int getState() {
1556 return mState;
1557 }
1558
1559 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001560 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001561 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1562 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1563 * {@link VideoProfile#STATE_TX_ENABLED},
1564 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001565 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001566 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001567 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001568 */
1569 public final int getVideoState() {
1570 return mVideoState;
1571 }
1572
1573 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001574 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001575 * being routed by the system. This is {@code null} if this Connection
1576 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001577 * @deprecated Use {@link #getCallAudioState()} instead.
1578 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001579 */
Yorke Lee4af59352015-05-13 14:14:54 -07001580 @SystemApi
1581 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001583 if (mCallAudioState == null) {
1584 return null;
1585 }
Yorke Lee4af59352015-05-13 14:14:54 -07001586 return new AudioState(mCallAudioState);
1587 }
1588
1589 /**
1590 * @return The audio state of the connection, describing how its audio is currently
1591 * being routed by the system. This is {@code null} if this Connection
1592 * does not directly know about its audio state.
1593 */
1594 public final CallAudioState getCallAudioState() {
1595 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001596 }
1597
1598 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001599 * @return The conference that this connection is a part of. Null if it is not part of any
1600 * conference.
1601 */
1602 public final Conference getConference() {
1603 return mConference;
1604 }
1605
1606 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001607 * Returns whether this connection is requesting that the system play a ringback tone
1608 * on its behalf.
1609 */
Andrew Lee100e2932014-09-08 15:34:24 -07001610 public final boolean isRingbackRequested() {
1611 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001612 }
1613
1614 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001615 * @return True if the connection's audio mode is VOIP.
1616 */
1617 public final boolean getAudioModeIsVoip() {
1618 return mAudioModeIsVoip;
1619 }
1620
1621 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001622 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1623 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1624 * start time of the conference.
1625 *
1626 * @return The time at which the {@code Connnection} was connected.
1627 *
1628 * @hide
1629 */
1630 public final long getConnectTimeMillis() {
1631 return mConnectTimeMillis;
1632 }
1633
1634 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001635 * @return The status hints for this connection.
1636 */
1637 public final StatusHints getStatusHints() {
1638 return mStatusHints;
1639 }
1640
1641 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001642 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001643 * <p>
1644 * Extras should be updated using {@link #putExtras(Bundle)}.
1645 * <p>
1646 * Telecom or an {@link InCallService} can also update the extras via
1647 * {@link android.telecom.Call#putExtras(Bundle)}, and
1648 * {@link Call#removeExtras(List)}.
1649 * <p>
1650 * The connection is notified of changes to the extras made by Telecom or an
1651 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001652 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001653 * @return The extras associated with this connection.
1654 */
1655 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001656 Bundle extras = null;
1657 synchronized (mExtrasLock) {
1658 if (mExtras != null) {
1659 extras = new Bundle(mExtras);
1660 }
1661 }
1662 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001663 }
1664
1665 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001666 * Assign a listener to be notified of state changes.
1667 *
1668 * @param l A listener.
1669 * @return This Connection.
1670 *
1671 * @hide
1672 */
1673 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001674 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001675 return this;
1676 }
1677
1678 /**
1679 * Remove a previously assigned listener that was being notified of state changes.
1680 *
1681 * @param l A Listener.
1682 * @return This Connection.
1683 *
1684 * @hide
1685 */
1686 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001687 if (l != null) {
1688 mListeners.remove(l);
1689 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 return this;
1691 }
1692
1693 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001694 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001695 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001696 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001697 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001698 }
1699
1700 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001701 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1702 * ONLY for debugging purposes.
1703 *
1704 * @param callId The telecom call ID.
1705 * @hide
1706 */
1707 public void setTelecomCallId(String callId) {
1708 mTelecomCallId = callId;
1709 }
1710
1711 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001712 * Inform this Connection that the state of its audio output has been changed externally.
1713 *
1714 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001715 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001716 */
Yorke Lee4af59352015-05-13 14:14:54 -07001717 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001718 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001719 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001720 mCallAudioState = state;
1721 onAudioStateChanged(getAudioState());
1722 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723 }
1724
1725 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001726 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001727 * @return A string representation of the value.
1728 */
1729 public static String stateToString(int state) {
1730 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001732 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001733 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001734 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001735 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001736 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001737 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001738 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001739 case STATE_PULLING_CALL:
1740 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001741 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001742 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001743 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001744 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001745 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001746 return "DISCONNECTED";
1747 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001748 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001749 return "UNKNOWN";
1750 }
1751 }
1752
1753 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001754 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001755 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001756 public final int getConnectionCapabilities() {
1757 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001758 }
1759
1760 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001761 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1762 */
1763 public final int getConnectionProperties() {
1764 return mConnectionProperties;
1765 }
1766
1767 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001768 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001769 *
Andrew Lee100e2932014-09-08 15:34:24 -07001770 * @param address The new address.
1771 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001772 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001773 */
Andrew Lee100e2932014-09-08 15:34:24 -07001774 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001775 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001776 Log.d(this, "setAddress %s", address);
1777 mAddress = address;
1778 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001779 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001780 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001781 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001782 }
1783
1784 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001785 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001786 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001787 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001788 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001789 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001790 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001791 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001792 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001793 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001794 mCallerDisplayName = callerDisplayName;
1795 mCallerDisplayNamePresentation = presentation;
1796 for (Listener l : mListeners) {
1797 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1798 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001799 }
1800
1801 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001802 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001803 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1804 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1805 * {@link VideoProfile#STATE_TX_ENABLED},
1806 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001807 *
1808 * @param videoState The new video state.
1809 */
1810 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001811 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001812 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001813 mVideoState = videoState;
1814 for (Listener l : mListeners) {
1815 l.onVideoStateChanged(this, mVideoState);
1816 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001817 }
1818
1819 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001820 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001821 * communicate).
1822 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001823 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001824 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001825 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001826 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001827 }
1828
1829 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001830 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001831 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001832 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001833 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001834 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001835 }
1836
1837 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001838 * Sets state to initializing (this Connection is not yet ready to be used).
1839 */
1840 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001841 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001842 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001843 }
1844
1845 /**
1846 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1847 */
1848 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001849 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001850 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001851 }
1852
1853 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001854 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001855 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001856 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001857 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001858 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001859 }
1860
1861 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001862 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1863 * device). Only applicable for {@link Connection}s with
1864 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1865 */
1866 public final void setPulling() {
1867 checkImmutable();
1868 setState(STATE_PULLING_CALL);
1869 }
1870
1871 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001872 * Sets state to be on hold.
1873 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001874 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001875 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001876 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001877 }
1878
1879 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001880 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001881 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001882 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001883 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001884 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001885 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001886 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001887 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001888 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001889 }
1890
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001891 public final VideoProvider getVideoProvider() {
1892 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001893 }
1894
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001895 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001896 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001897 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001898 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001899 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001900 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001901 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001902 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001903 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001904 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001905 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001906 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001907 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001908 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001909 }
1910
1911 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001912 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1913 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1914 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1915 * to send an {@link #onPostDialContinue(boolean)} signal.
1916 *
1917 * @param remaining The DTMF character sequence remaining to be emitted once the
1918 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1919 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001920 */
1921 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001922 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001923 for (Listener l : mListeners) {
1924 l.onPostDialWait(this, remaining);
1925 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001926 }
1927
1928 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001929 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1930 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001931 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001932 *
1933 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001934 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001935 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001936 checkImmutable();
1937 for (Listener l : mListeners) {
1938 l.onPostDialChar(this, nextChar);
1939 }
1940 }
1941
1942 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001943 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001944 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001945 *
1946 * @param ringback Whether the ringback tone is to be played.
1947 */
Andrew Lee100e2932014-09-08 15:34:24 -07001948 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001949 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001950 if (mRingbackRequested != ringback) {
1951 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001952 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001953 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001954 }
1955 }
Ihab Awadf8358972014-05-28 16:46:42 -07001956 }
1957
1958 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001959 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001960 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001961 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001962 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001963 public final void setConnectionCapabilities(int connectionCapabilities) {
1964 checkImmutable();
1965 if (mConnectionCapabilities != connectionCapabilities) {
1966 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001967 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001968 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001969 }
1970 }
Santos Cordonb6939982014-06-04 20:20:58 -07001971 }
1972
1973 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001974 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1975 *
1976 * @param connectionProperties The new connection properties.
1977 */
1978 public final void setConnectionProperties(int connectionProperties) {
1979 checkImmutable();
1980 if (mConnectionProperties != connectionProperties) {
1981 mConnectionProperties = connectionProperties;
1982 for (Listener l : mListeners) {
1983 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1984 }
1985 }
1986 }
1987
1988 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001989 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001990 */
Evan Charlton36a71342014-07-19 16:31:02 -07001991 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001992 for (Listener l : mListeners) {
1993 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001994 }
Santos Cordonb6939982014-06-04 20:20:58 -07001995 }
1996
1997 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001998 * Requests that the framework use VOIP audio mode for this connection.
1999 *
2000 * @param isVoip True if the audio mode is VOIP.
2001 */
2002 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002003 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002004 mAudioModeIsVoip = isVoip;
2005 for (Listener l : mListeners) {
2006 l.onAudioModeIsVoipChanged(this, isVoip);
2007 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002008 }
2009
2010 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002011 * Sets the time at which a call became active on this Connection. This is set only
2012 * when a conference call becomes active on this connection.
2013 *
2014 * @param connectionTimeMillis The connection time, in milliseconds.
2015 *
2016 * @hide
2017 */
2018 public final void setConnectTimeMillis(long connectTimeMillis) {
2019 mConnectTimeMillis = connectTimeMillis;
2020 }
2021
2022 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002023 * Sets the label and icon status to display in the in-call UI.
2024 *
2025 * @param statusHints The status label and icon to set.
2026 */
2027 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002028 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002029 mStatusHints = statusHints;
2030 for (Listener l : mListeners) {
2031 l.onStatusHintsChanged(this, statusHints);
2032 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002033 }
2034
2035 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002036 * Sets the connections with which this connection can be conferenced.
2037 *
2038 * @param conferenceableConnections The set of connections this connection can conference with.
2039 */
2040 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002041 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002042 clearConferenceableList();
2043 for (Connection c : conferenceableConnections) {
2044 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2045 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002046 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002047 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002048 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002049 }
2050 }
2051 fireOnConferenceableConnectionsChanged();
2052 }
2053
2054 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002055 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2056 * or conferences with which this connection can be conferenced.
2057 *
2058 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002059 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002060 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002061 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002062 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002063 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2064 // small amount of items here.
2065 if (!mConferenceables.contains(c)) {
2066 if (c instanceof Connection) {
2067 Connection connection = (Connection) c;
2068 connection.addConnectionListener(mConnectionDeathListener);
2069 } else if (c instanceof Conference) {
2070 Conference conference = (Conference) c;
2071 conference.addListener(mConferenceDeathListener);
2072 }
2073 mConferenceables.add(c);
2074 }
2075 }
2076 fireOnConferenceableConnectionsChanged();
2077 }
2078
2079 /**
2080 * Returns the connections or conferences with which this connection can be conferenced.
2081 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002082 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002083 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002084 }
2085
Yorke Lee53463962015-08-04 16:07:19 -07002086 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002087 * @hide
2088 */
2089 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002090 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002091 if (mConnectionService != null) {
2092 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2093 "which is already associated with another ConnectionService.");
2094 } else {
2095 mConnectionService = connectionService;
2096 }
2097 }
2098
2099 /**
2100 * @hide
2101 */
2102 public final void unsetConnectionService(ConnectionService connectionService) {
2103 if (mConnectionService != connectionService) {
2104 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2105 "that does not belong to the ConnectionService.");
2106 } else {
2107 mConnectionService = null;
2108 }
2109 }
2110
2111 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002112 * @hide
2113 */
2114 public final ConnectionService getConnectionService() {
2115 return mConnectionService;
2116 }
2117
2118 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002119 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002120 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002121 *
2122 * @param conference The conference.
2123 * @return {@code true} if the conference was successfully set.
2124 * @hide
2125 */
2126 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002127 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002128 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002129 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002130 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002131 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2132 fireConferenceChanged();
2133 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002134 return true;
2135 }
2136 return false;
2137 }
2138
2139 /**
2140 * Resets the conference that this connection is a part of.
2141 * @hide
2142 */
2143 public final void resetConference() {
2144 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002145 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002146 mConference = null;
2147 fireConferenceChanged();
2148 }
2149 }
2150
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002151 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002152 * Set some extras that can be associated with this {@code Connection}.
2153 * <p>
2154 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2155 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2156 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002157 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2158 * {@link #removeExtras(String...)} methods to modify the extras.
2159 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002160 * 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 -07002161 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2162 *
2163 * @param extras The extras associated with this {@code Connection}.
2164 */
2165 public final void setExtras(@Nullable Bundle extras) {
2166 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002167
2168 // Add/replace any new or changed extras values.
2169 putExtras(extras);
2170
2171 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2172 // the current one and remove any keys that went away.
2173 if (mPreviousExtraKeys != null) {
2174 List<String> toRemove = new ArrayList<String>();
2175 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002176 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002177 toRemove.add(oldKey);
2178 }
2179 }
2180 if (!toRemove.isEmpty()) {
2181 removeExtras(toRemove);
2182 }
2183 }
2184
2185 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2186 // called we can see if the caller has removed any extras values.
2187 if (mPreviousExtraKeys == null) {
2188 mPreviousExtraKeys = new ArraySet<String>();
2189 }
2190 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002191 if (extras != null) {
2192 mPreviousExtraKeys.addAll(extras.keySet());
2193 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002194 }
2195
2196 /**
2197 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2198 * added.
2199 * <p>
2200 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2201 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2202 *
2203 * @param extras The extras to add.
2204 */
2205 public final void putExtras(@NonNull Bundle extras) {
2206 checkImmutable();
2207 if (extras == null) {
2208 return;
2209 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002210 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2211 // the listeners.
2212 Bundle listenerExtras;
2213 synchronized (mExtrasLock) {
2214 if (mExtras == null) {
2215 mExtras = new Bundle();
2216 }
2217 mExtras.putAll(extras);
2218 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002219 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002220 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002221 // Create a new clone of the extras for each listener so that they don't clobber
2222 // each other
2223 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002224 }
2225 }
2226
2227 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002228 * Adds a boolean extra to this {@code Connection}.
2229 *
2230 * @param key The extra key.
2231 * @param value The value.
2232 * @hide
2233 */
2234 public final void putExtra(String key, boolean value) {
2235 Bundle newExtras = new Bundle();
2236 newExtras.putBoolean(key, value);
2237 putExtras(newExtras);
2238 }
2239
2240 /**
2241 * Adds an integer extra to this {@code Connection}.
2242 *
2243 * @param key The extra key.
2244 * @param value The value.
2245 * @hide
2246 */
2247 public final void putExtra(String key, int value) {
2248 Bundle newExtras = new Bundle();
2249 newExtras.putInt(key, value);
2250 putExtras(newExtras);
2251 }
2252
2253 /**
2254 * Adds a string extra to this {@code Connection}.
2255 *
2256 * @param key The extra key.
2257 * @param value The value.
2258 * @hide
2259 */
2260 public final void putExtra(String key, String value) {
2261 Bundle newExtras = new Bundle();
2262 newExtras.putString(key, value);
2263 putExtras(newExtras);
2264 }
2265
2266 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002267 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002268 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002269 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002270 */
2271 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002272 synchronized (mExtrasLock) {
2273 if (mExtras != null) {
2274 for (String key : keys) {
2275 mExtras.remove(key);
2276 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002277 }
2278 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002279 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002280 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002281 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002282 }
2283 }
2284
2285 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002286 * Removes extras from this {@code Connection}.
2287 *
2288 * @param keys The keys of the extras to remove.
2289 */
2290 public final void removeExtras(String ... keys) {
2291 removeExtras(Arrays.asList(keys));
2292 }
2293
2294 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002295 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002296 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002297 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002298 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2299 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002300 */
Yorke Lee4af59352015-05-13 14:14:54 -07002301 @SystemApi
2302 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002303 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002304
2305 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002306 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2307 *
2308 * @param state The new connection audio state.
2309 */
2310 public void onCallAudioStateChanged(CallAudioState state) {}
2311
2312 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002313 * Notifies this Connection of an internal state change. This method is called after the
2314 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002315 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002316 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002317 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002318 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002319
2320 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002321 * Notifies this Connection of a request to play a DTMF tone.
2322 *
2323 * @param c A DTMF character.
2324 */
Santos Cordonf2951102014-07-20 19:06:29 -07002325 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002326
2327 /**
2328 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2329 */
Santos Cordonf2951102014-07-20 19:06:29 -07002330 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002331
2332 /**
2333 * Notifies this Connection of a request to disconnect.
2334 */
Santos Cordonf2951102014-07-20 19:06:29 -07002335 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002336
2337 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002338 * Notifies this Connection of a request to disconnect a participant of the conference managed
2339 * by the connection.
2340 *
2341 * @param endpoint the {@link Uri} of the participant to disconnect.
2342 * @hide
2343 */
2344 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2345
2346 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002347 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002348 */
Santos Cordonf2951102014-07-20 19:06:29 -07002349 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002350
2351 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002352 * Notifies this Connection of a request to abort.
2353 */
Santos Cordonf2951102014-07-20 19:06:29 -07002354 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002355
2356 /**
2357 * Notifies this Connection of a request to hold.
2358 */
Santos Cordonf2951102014-07-20 19:06:29 -07002359 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002360
2361 /**
2362 * Notifies this Connection of a request to exit a hold state.
2363 */
Santos Cordonf2951102014-07-20 19:06:29 -07002364 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002365
2366 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002367 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002368 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002369 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002370 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002371 */
Santos Cordonf2951102014-07-20 19:06:29 -07002372 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002373
2374 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002375 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002376 * a request to accept.
2377 */
2378 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002379 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002380 }
2381
2382 /**
2383 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002384 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002385 */
Santos Cordonf2951102014-07-20 19:06:29 -07002386 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002387
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002388 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002389 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2390 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002391 */
2392 public void onReject(String replyMessage) {}
2393
2394 /**
Bryce Leecac50772015-11-17 15:13:29 -08002395 * Notifies the Connection of a request to silence the ringer.
2396 *
2397 * @hide
2398 */
2399 public void onSilence() {}
2400
2401 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002402 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2403 */
Santos Cordonf2951102014-07-20 19:06:29 -07002404 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002405
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002406 /**
2407 * Notifies this Connection of a request to pull an external call to the local device.
2408 * <p>
2409 * The {@link InCallService} issues a request to pull an external call to the local device via
2410 * {@link Call#pullExternalCall()}.
2411 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002412 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2413 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002414 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002415 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002416 */
2417 public void onPullExternalCall() {}
2418
2419 /**
2420 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2421 * <p>
2422 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2423 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002424 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2425 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2426 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2427 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2428 * not aware of.
2429 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002430 * See also {@link Call#sendCallEvent(String, Bundle)}.
2431 *
2432 * @param event The call event.
2433 * @param extras Extras associated with the call event.
2434 */
2435 public void onCallEvent(String event, Bundle extras) {}
2436
Tyler Gunndee56a82016-03-23 16:06:34 -07002437 /**
2438 * Notifies this {@link Connection} of a change to the extras made outside the
2439 * {@link ConnectionService}.
2440 * <p>
2441 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2442 * the {@link android.telecom.Call#putExtras(Bundle)} and
2443 * {@link Call#removeExtras(List)}.
2444 *
2445 * @param extras The new extras bundle.
2446 */
2447 public void onExtrasChanged(Bundle extras) {}
2448
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002449 static String toLogSafePhoneNumber(String number) {
2450 // For unknown number, log empty string.
2451 if (number == null) {
2452 return "";
2453 }
2454
2455 if (PII_DEBUG) {
2456 // When PII_DEBUG is true we emit PII.
2457 return number;
2458 }
2459
2460 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2461 // sanitized phone numbers.
2462 StringBuilder builder = new StringBuilder();
2463 for (int i = 0; i < number.length(); i++) {
2464 char c = number.charAt(i);
2465 if (c == '-' || c == '@' || c == '.') {
2466 builder.append(c);
2467 } else {
2468 builder.append('x');
2469 }
2470 }
2471 return builder.toString();
2472 }
2473
Ihab Awad542e0ea2014-05-16 10:22:16 -07002474 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002475 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002476 if (mState == STATE_DISCONNECTED && mState != state) {
2477 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002478 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002479 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002480 if (mState != state) {
2481 Log.d(this, "setState: %s", stateToString(state));
2482 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002483 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002484 for (Listener l : mListeners) {
2485 l.onStateChanged(this, state);
2486 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002487 }
2488 }
2489
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002490 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002491 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002492 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2493 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002494 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002495 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002496
2497 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002498 if (mImmutable) {
2499 throw new UnsupportedOperationException("Connection is immutable");
2500 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002501 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002502 }
2503
Evan Charltonbf11f982014-07-20 22:06:28 -07002504 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002505 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002506 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2507 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002508 * <p>
2509 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2510 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002511 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002512 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002513 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002514 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002515 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2516 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002517 }
2518
Evan Charltonbf11f982014-07-20 22:06:28 -07002519 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002520 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2521 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2522 * this should never be un-@hide-den.
2523 *
2524 * @hide
2525 */
2526 public void checkImmutable() {}
2527
2528 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002529 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2530 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2531 * that state. This connection should not be used for anything, and no other
2532 * {@code Connection}s should be attempted.
2533 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002534 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002535 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002536 * @return A {@code Connection} which indicates that the underlying connection should
2537 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002538 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002539 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002540 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002541 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002542
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002543 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002544 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002545 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002546 }
2547 }
2548
Santos Cordon823fd3c2014-08-07 18:35:18 -07002549 private final void fireConferenceChanged() {
2550 for (Listener l : mListeners) {
2551 l.onConferenceChanged(this, mConference);
2552 }
2553 }
2554
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002555 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002556 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002557 if (c instanceof Connection) {
2558 Connection connection = (Connection) c;
2559 connection.removeConnectionListener(mConnectionDeathListener);
2560 } else if (c instanceof Conference) {
2561 Conference conference = (Conference) c;
2562 conference.removeListener(mConferenceDeathListener);
2563 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002564 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002565 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002566 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002567
2568 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002569 * Handles a change to extras received from Telecom.
2570 *
2571 * @param extras The new extras.
2572 * @hide
2573 */
2574 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002575 Bundle b = null;
2576 synchronized (mExtrasLock) {
2577 mExtras = extras;
2578 if (mExtras != null) {
2579 b = new Bundle(mExtras);
2580 }
2581 }
2582 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002583 }
2584
2585 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002586 * Notifies listeners that the merge request failed.
2587 *
2588 * @hide
2589 */
2590 protected final void notifyConferenceMergeFailed() {
2591 for (Listener l : mListeners) {
2592 l.onConferenceMergeFailed(this);
2593 }
2594 }
2595
2596 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002597 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002598 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002599 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002600 * @hide
2601 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002602 protected final void updateConferenceParticipants(
2603 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002604 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002605 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002606 }
2607 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002608
2609 /**
2610 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002611 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002612 */
2613 protected void notifyConferenceStarted() {
2614 for (Listener l : mListeners) {
2615 l.onConferenceStarted();
2616 }
2617 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002618
2619 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002620 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2621 * be a part of a conference call.
2622 * @param isConferenceSupported {@code true} if the connection supports being part of a
2623 * conference call, {@code false} otherwise.
2624 * @hide
2625 */
2626 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2627 for (Listener l : mListeners) {
2628 l.onConferenceSupportedChanged(this, isConferenceSupported);
2629 }
2630 }
2631
2632 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002633 * Sends an event associated with this {@code Connection} with associated event extras to the
2634 * {@link InCallService}.
2635 * <p>
2636 * Connection events are used to communicate point in time information from a
2637 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2638 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2639 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2640 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2641 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2642 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2643 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2644 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2645 * <p>
2646 * Events are exposed to {@link InCallService} implementations via
2647 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2648 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002649 * 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 -07002650 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2651 * some events altogether.
2652 * <p>
2653 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2654 * conflicts between {@link ConnectionService} implementations. Further, custom
2655 * {@link ConnectionService} implementations shall not re-purpose events in the
2656 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2657 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2658 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2659 * {@code com.example.extra.MY_EXTRA}).
2660 * <p>
2661 * When defining events and the associated extras, it is important to keep their behavior
2662 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2663 * events/extras should me maintained to ensure backwards compatibility with older
2664 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002665 *
2666 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002667 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002668 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002669 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002670 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002671 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002672 }
2673 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002674}