blob: d864833aa2b493aaa37c94050a4e255099fc74bd [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
43/**
Santos Cordon895d4b82015-06-25 16:41:48 -070044 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
45 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070046 * <p>
47 * Implementations create a custom subclass of {@code Connection} and return it to the framework
48 * as the return value of
49 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
50 * or
51 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
52 * Implementations are then responsible for updating the state of the {@code Connection}, and
53 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
54 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070055 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070056public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070057
Santos Cordon895d4b82015-06-25 16:41:48 -070058 /**
59 * The connection is initializing. This is generally the first state for a {@code Connection}
60 * returned by a {@link ConnectionService}.
61 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 public static final int STATE_INITIALIZING = 0;
63
Santos Cordon895d4b82015-06-25 16:41:48 -070064 /**
65 * The connection is new and not connected.
66 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070067 public static final int STATE_NEW = 1;
68
Santos Cordon895d4b82015-06-25 16:41:48 -070069 /**
70 * An incoming connection is in the ringing state. During this state, the user's ringer or
71 * vibration feature will be activated.
72 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070073 public static final int STATE_RINGING = 2;
74
Santos Cordon895d4b82015-06-25 16:41:48 -070075 /**
76 * An outgoing connection is in the dialing state. In this state the other party has not yet
77 * answered the call and the user traditionally hears a ringback tone.
78 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 public static final int STATE_DIALING = 3;
80
Santos Cordon895d4b82015-06-25 16:41:48 -070081 /**
82 * A connection is active. Both parties are connected to the call and can actively communicate.
83 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 public static final int STATE_ACTIVE = 4;
85
Santos Cordon895d4b82015-06-25 16:41:48 -070086 /**
87 * A connection is on hold.
88 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 public static final int STATE_HOLDING = 5;
90
Santos Cordon895d4b82015-06-25 16:41:48 -070091 /**
92 * A connection has been disconnected. This is the final state once the user has been
93 * disconnected from a call either locally, remotely or by an error in the service.
94 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070095 public static final int STATE_DISCONNECTED = 6;
96
Santos Cordon895d4b82015-06-25 16:41:48 -070097 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070098 * The state of an external connection which is in the process of being pulled from a remote
99 * device to the local device.
100 * <p>
101 * A connection can only be in this state if the {@link #CAPABILITY_IS_EXTERNAL_CALL} and
102 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
103 */
104 public static final int STATE_PULLING_CALL = 7;
105
106 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 * Connection can currently be put on hold or unheld. This is distinct from
108 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
109 * it does not at the moment support the function. This can be true while the call is in the
110 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
111 * display a disabled 'hold' button.
112 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113 public static final int CAPABILITY_HOLD = 0x00000001;
114
115 /** Connection supports the hold feature. */
116 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
117
118 /**
119 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
120 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
121 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
122 * capability allows a merge button to be shown while the conference is in the foreground
123 * of the in-call UI.
124 * <p>
125 * This is only intended for use by a {@link Conference}.
126 */
127 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
128
129 /**
130 * Connections within a conference can be swapped between foreground and background.
131 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
132 * <p>
133 * This is only intended for use by a {@link Conference}.
134 */
135 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
136
137 /**
138 * @hide
139 */
140 public static final int CAPABILITY_UNUSED = 0x00000010;
141
142 /** Connection supports responding via text option. */
143 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
144
145 /** Connection can be muted. */
146 public static final int CAPABILITY_MUTE = 0x00000040;
147
148 /**
149 * Connection supports conference management. This capability only applies to
150 * {@link Conference}s which can have {@link Connection}s as children.
151 */
152 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
153
154 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700155 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800163
164 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700165 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700167 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700168 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169
170 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800172 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
174
175 /**
176 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700177 */
178 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
179
180 /**
181 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700183 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700184 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800185
186 /**
187 * Connection is able to be separated from its parent {@code Conference}, if any.
188 */
189 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
190
191 /**
192 * Connection is able to be individually disconnected when in a {@code Conference}.
193 */
194 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
195
196 /**
197 * Whether the call is a generic conference, where we do not know the precise state of
198 * participants in the conference (eg. on CDMA).
199 *
200 * @hide
201 */
202 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
203
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 /**
205 * Connection is using high definition audio.
206 * @hide
207 */
208 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
209
210 /**
211 * Connection is using WIFI.
212 * @hide
213 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700214 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215
Tyler Gunn068085b2015-02-06 13:56:52 -0800216 /**
217 * Indicates that the current device callback number should be shown.
218 *
219 * @hide
220 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800222
Tyler Gunn96d6c402015-03-18 12:39:23 -0700223 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500224 * Speed up audio setup for MT call.
225 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700226 */
227 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800228
Rekha Kumar07366812015-03-24 16:42:31 -0700229 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700230 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700231 */
232 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
233
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700234 /**
235 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700236 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700237 */
238 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
239
Tyler Gunnd4091732015-06-29 09:15:37 -0700240 /**
241 * For a conference, indicates the conference will not have child connections.
242 * <p>
243 * An example of a conference with child connections is a GSM conference call, where the radio
244 * retains connections to the individual participants of the conference. Another example is an
245 * IMS conference call where conference event package functionality is supported; in this case
246 * the conference server ensures the radio is aware of the participants in the conference, which
247 * are represented by child connections.
248 * <p>
249 * An example of a conference with no child connections is an IMS conference call with no
250 * conference event package support. Such a conference is represented by the radio as a single
251 * connection to the IMS conference server.
252 * <p>
253 * Indicating whether a conference has children or not is important to help user interfaces
254 * visually represent a conference. A conference with no children, for example, will have the
255 * conference connection shown in the list of calls on a Bluetooth device, where if the
256 * conference has children, only the children will be shown in the list of calls on a Bluetooth
257 * device.
258 * @hide
259 */
260 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
261
Bryce Lee81901682015-08-28 16:38:02 -0700262 /**
263 * Indicates that the connection itself wants to handle any sort of reply response, rather than
264 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700265 */
266 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
267
Tyler Gunnf97a0092016-01-19 15:59:34 -0800268 /**
269 * When set, prevents a video call from being downgraded to an audio-only call.
270 * <p>
271 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
272 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
273 * downgraded from a video call back to a VideoState of
274 * {@link VideoProfile#STATE_AUDIO_ONLY}.
275 * <p>
276 * Intuitively, a call which can be downgraded to audio should also have local and remote
277 * video
278 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
279 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
280 */
281 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
282
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700283 /**
284 * When set, indicates that the {@code Connection} does not actually exist locally for the
285 * {@link ConnectionService}.
286 * <p>
287 * Consider, for example, a scenario where a user has two devices with the same phone number.
288 * When a user places a call on one devices, the telephony stack can represent that call on the
289 * other device by adding is to the {@link ConnectionService} with the
290 * {@code CAPABILITY_IS_EXTERNAL_CALL} capability set.
291 * <p>
292 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
293 * external connections. Only those {@link InCallService}s which have the
294 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
295 * manifest will see external connections.
296 */
297 public static final int CAPABILITY_IS_EXTERNAL_CALL = 0x01000000;
298
299 /**
300 * When set for an external connection, indicates that this {@code Connection} can be pulled
301 * from a remote device to the current device.
302 * <p>
303 * Should only be set on a {@code Connection} where {@link #CAPABILITY_IS_EXTERNAL_CALL}
304 * is set.
305 */
306 public static final int CAPABILITY_CAN_PULL_CALL = 0x02000000;
307
Tyler Gunn96d6c402015-03-18 12:39:23 -0700308 //**********************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700309 // Next CAPABILITY value: 0x04000000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700310 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800311
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700312 /**
313 * Connection extra key used to store the last forwarded number associated with the current
314 * connection. Used to communicate to the user interface that the connection was forwarded via
315 * the specified number.
316 */
317 public static final String EXTRA_LAST_FORWARDED_NUMBER =
318 "android.telecom.extra.LAST_FORWARDED_NUMBER";
319
320 /**
321 * Connection extra key used to store a child number associated with the current connection.
322 * Used to communicate to the user interface that the connection was received via
323 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
324 * address.
325 */
326 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
327
328 /**
329 * Connection extra key used to store the subject for an incoming call. The user interface can
330 * query this extra and display its contents for incoming calls. Will only be used if the
331 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
332 */
333 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
334
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800335 /**
336 * Connection event used to inform Telecom that it should play the on hold tone. This is used
337 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
338 * {@link #sendConnectionEvent(String)}.
339 * @hide
340 */
341 public static final String EVENT_ON_HOLD_TONE_START =
342 "android.telecom.event.ON_HOLD_TONE_START";
343
344 /**
345 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
346 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
347 * {@link #sendConnectionEvent(String)}.
348 * @hide
349 */
350 public static final String EVENT_ON_HOLD_TONE_END =
351 "android.telecom.event.ON_HOLD_TONE_END";
352
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700353 /**
354 * Connection event used to inform {@link InCallService}s when pulling of an external call has
355 * failed. The user interface should inform the user of the error.
356 * <p>
357 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
358 * API is called on a {@link Call} with the properties
359 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
360 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
361 * pull the external call due to an error condition.
362 */
363 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
364
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 // Flag controlling whether PII is emitted into the logs
366 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
367
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368 /**
369 * Whether the given capabilities support the specified capability.
370 *
371 * @param capabilities A capability bit field.
372 * @param capability The capability to check capabilities for.
373 * @return Whether the specified capability is supported.
374 * @hide
375 */
376 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800377 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800378 }
379
380 /**
381 * Whether the capabilities of this {@code Connection} supports the specified capability.
382 *
383 * @param capability The capability to check capabilities for.
384 * @return Whether the specified capability is supported.
385 * @hide
386 */
387 public boolean can(int capability) {
388 return can(mConnectionCapabilities, capability);
389 }
390
391 /**
392 * Removes the specified capability from the set of capabilities of this {@code Connection}.
393 *
394 * @param capability The capability to remove from the set.
395 * @hide
396 */
397 public void removeCapability(int capability) {
398 mConnectionCapabilities &= ~capability;
399 }
400
401 /**
402 * Adds the specified capability to the set of capabilities of this {@code Connection}.
403 *
404 * @param capability The capability to add to the set.
405 * @hide
406 */
407 public void addCapability(int capability) {
408 mConnectionCapabilities |= capability;
409 }
410
411
412 public static String capabilitiesToString(int capabilities) {
413 StringBuilder builder = new StringBuilder();
414 builder.append("[Capabilities:");
415 if (can(capabilities, CAPABILITY_HOLD)) {
416 builder.append(" CAPABILITY_HOLD");
417 }
418 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
419 builder.append(" CAPABILITY_SUPPORT_HOLD");
420 }
421 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
422 builder.append(" CAPABILITY_MERGE_CONFERENCE");
423 }
424 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
425 builder.append(" CAPABILITY_SWAP_CONFERENCE");
426 }
427 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
428 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
429 }
430 if (can(capabilities, CAPABILITY_MUTE)) {
431 builder.append(" CAPABILITY_MUTE");
432 }
433 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
434 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
435 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700436 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
437 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
438 }
439 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
440 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
441 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700442 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
443 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800444 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700445 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
446 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
447 }
448 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
449 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
450 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700451 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
452 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800453 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800454 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
455 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
456 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800457 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
458 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800459 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800460 if (can(capabilities, CAPABILITY_WIFI)) {
461 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800462 }
463 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
464 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
465 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800466 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
467 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
468 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500469 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700470 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500471 }
Rekha Kumar07366812015-03-24 16:42:31 -0700472 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
473 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
474 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700475 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
476 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
477 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700478 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
479 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
480 }
Bryce Lee81901682015-08-28 16:38:02 -0700481 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
482 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
483 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700484 if (can(capabilities, CAPABILITY_IS_EXTERNAL_CALL)) {
485 builder.append(" CAPABILITY_IS_EXTERNAL_CALL");
486 }
487 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
488 builder.append(" CAPABILITY_CAN_PULL_CALL");
489 }
Bryce Lee81901682015-08-28 16:38:02 -0700490
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800491 builder.append("]");
492 return builder.toString();
493 }
494
Sailesh Nepal091768c2014-06-30 15:15:23 -0700495 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700496 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700497 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700498 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700499 public void onCallerDisplayNameChanged(
500 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700501 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700502 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700503 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800504 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700505 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700506 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800507 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700508 public void onVideoProviderChanged(
509 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700510 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
511 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800512 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700513 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700514 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700515 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800516 public void onConferenceParticipantsChanged(Connection c,
517 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800518 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700519 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700520 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700521 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700522 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700523 }
524
Tyler Gunnb702ef82015-05-29 11:51:53 -0700525 /**
526 * Provides a means of controlling the video session associated with a {@link Connection}.
527 * <p>
528 * Implementations create a custom subclass of {@link VideoProvider} and the
529 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
530 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
531 * should set the {@link VideoProvider}.
532 * <p>
533 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
534 * {@link InCallService} implementations to issue requests related to the video session;
535 * it provides a means for the {@link ConnectionService} to report events and information
536 * related to the video session to Telecom and the {@link InCallService} implementations.
537 * <p>
538 * {@link InCallService} implementations interact with the {@link VideoProvider} via
539 * {@link android.telecom.InCallService.VideoCall}.
540 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700541 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700542
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700543 /**
544 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700545 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700546 */
547 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700548
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700550 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
551 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 */
553 public static final int SESSION_EVENT_RX_RESUME = 2;
554
555 /**
556 * Video transmission has begun. This occurs after a negotiated start of video transmission
557 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700558 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700559 */
560 public static final int SESSION_EVENT_TX_START = 3;
561
562 /**
563 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
564 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700565 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566 */
567 public static final int SESSION_EVENT_TX_STOP = 4;
568
569 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700570 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
571 * this as a cue to inform the user the camera is not available.
572 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 */
574 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
575
576 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700577 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
578 * for operation. The {@link InCallService} can use this as a cue to inform the user that
579 * the camera has become available again.
580 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700581 */
582 public static final int SESSION_EVENT_CAMERA_READY = 6;
583
584 /**
585 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700586 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 */
588 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
589
590 /**
591 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700592 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 */
594 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
595
596 /**
597 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700598 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 */
600 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
601
Rekha Kumar07366812015-03-24 16:42:31 -0700602 /**
603 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700604 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700605 */
606 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
607
608 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700609 * Session modify request rejected by remote user.
610 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700611 */
612 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
613
Tyler Gunn75958422015-04-15 14:23:42 -0700614 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 private static final int MSG_SET_CAMERA = 2;
616 private static final int MSG_SET_PREVIEW_SURFACE = 3;
617 private static final int MSG_SET_DISPLAY_SURFACE = 4;
618 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
619 private static final int MSG_SET_ZOOM = 6;
620 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
621 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
622 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700625 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700627 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700629
630 /**
631 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700632 *
633 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
634 * load factor before resizing, 1 means we only expect a single thread to
635 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700636 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700637 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
638 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639
640 /**
641 * Default handler used to consolidate binder method calls onto a single thread.
642 */
643 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700644 public VideoProviderHandler() {
645 super();
646 }
647
648 public VideoProviderHandler(Looper looper) {
649 super(looper);
650 }
651
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 @Override
653 public void handleMessage(Message msg) {
654 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700655 case MSG_ADD_VIDEO_CALLBACK: {
656 IBinder binder = (IBinder) msg.obj;
657 IVideoCallback callback = IVideoCallback.Stub
658 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700659 if (callback == null) {
660 Log.w(this, "addVideoProvider - skipped; callback is null.");
661 break;
662 }
663
Tyler Gunn75958422015-04-15 14:23:42 -0700664 if (mVideoCallbacks.containsKey(binder)) {
665 Log.i(this, "addVideoProvider - skipped; already present.");
666 break;
667 }
668 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700670 }
671 case MSG_REMOVE_VIDEO_CALLBACK: {
672 IBinder binder = (IBinder) msg.obj;
673 IVideoCallback callback = IVideoCallback.Stub
674 .asInterface((IBinder) msg.obj);
675 if (!mVideoCallbacks.containsKey(binder)) {
676 Log.i(this, "removeVideoProvider - skipped; not present.");
677 break;
678 }
679 mVideoCallbacks.remove(binder);
680 break;
681 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 case MSG_SET_CAMERA:
683 onSetCamera((String) msg.obj);
684 break;
685 case MSG_SET_PREVIEW_SURFACE:
686 onSetPreviewSurface((Surface) msg.obj);
687 break;
688 case MSG_SET_DISPLAY_SURFACE:
689 onSetDisplaySurface((Surface) msg.obj);
690 break;
691 case MSG_SET_DEVICE_ORIENTATION:
692 onSetDeviceOrientation(msg.arg1);
693 break;
694 case MSG_SET_ZOOM:
695 onSetZoom((Float) msg.obj);
696 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700697 case MSG_SEND_SESSION_MODIFY_REQUEST: {
698 SomeArgs args = (SomeArgs) msg.obj;
699 try {
700 onSendSessionModifyRequest((VideoProfile) args.arg1,
701 (VideoProfile) args.arg2);
702 } finally {
703 args.recycle();
704 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700706 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707 case MSG_SEND_SESSION_MODIFY_RESPONSE:
708 onSendSessionModifyResponse((VideoProfile) msg.obj);
709 break;
710 case MSG_REQUEST_CAMERA_CAPABILITIES:
711 onRequestCameraCapabilities();
712 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800713 case MSG_REQUEST_CONNECTION_DATA_USAGE:
714 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700715 break;
716 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700717 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700718 break;
719 default:
720 break;
721 }
722 }
723 }
724
725 /**
726 * IVideoProvider stub implementation.
727 */
728 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700729 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700730 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700731 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
732 }
733
734 public void removeVideoCallback(IBinder videoCallbackBinder) {
735 mMessageHandler.obtainMessage(
736 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 }
738
739 public void setCamera(String cameraId) {
740 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
741 }
742
743 public void setPreviewSurface(Surface surface) {
744 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
745 }
746
747 public void setDisplaySurface(Surface surface) {
748 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
749 }
750
751 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700752 mMessageHandler.obtainMessage(
753 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 }
755
756 public void setZoom(float value) {
757 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
758 }
759
Tyler Gunn45382162015-05-06 08:52:27 -0700760 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
761 SomeArgs args = SomeArgs.obtain();
762 args.arg1 = fromProfile;
763 args.arg2 = toProfile;
764 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 }
766
767 public void sendSessionModifyResponse(VideoProfile responseProfile) {
768 mMessageHandler.obtainMessage(
769 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
770 }
771
772 public void requestCameraCapabilities() {
773 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
774 }
775
776 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800777 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 }
779
Yorke Lee32f24732015-05-12 16:18:03 -0700780 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
782 }
783 }
784
785 public VideoProvider() {
786 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700787 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700788 }
789
790 /**
791 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
792 *
793 * @param looper The looper.
794 * @hide
795 */
796 public VideoProvider(Looper looper) {
797 mBinder = new VideoProvider.VideoProviderBinder();
798 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700799 }
800
801 /**
802 * Returns binder object which can be used across IPC methods.
803 * @hide
804 */
805 public final IVideoProvider getInterface() {
806 return mBinder;
807 }
808
809 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700810 * Sets the camera to be used for the outgoing video.
811 * <p>
812 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
813 * camera via
814 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
815 * <p>
816 * Sent from the {@link InCallService} via
817 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700818 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700819 * @param cameraId The id of the camera (use ids as reported by
820 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 */
822 public abstract void onSetCamera(String cameraId);
823
824 /**
825 * Sets the surface to be used for displaying a preview of what the user's camera is
826 * currently capturing. When video transmission is enabled, this is the video signal which
827 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700828 * <p>
829 * Sent from the {@link InCallService} via
830 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 */
834 public abstract void onSetPreviewSurface(Surface surface);
835
836 /**
837 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700838 * <p>
839 * Sent from the {@link InCallService} via
840 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700841 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700842 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700843 */
844 public abstract void onSetDisplaySurface(Surface surface);
845
846 /**
847 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
848 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700849 * <p>
850 * Sent from the {@link InCallService} via
851 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700852 *
853 * @param rotation The device orientation, in degrees.
854 */
855 public abstract void onSetDeviceOrientation(int rotation);
856
857 /**
858 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700859 * <p>
860 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700861 *
862 * @param value The camera zoom ratio.
863 */
864 public abstract void onSetZoom(float value);
865
866 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700867 * Issues a request to modify the properties of the current video session.
868 * <p>
869 * Example scenarios include: requesting an audio-only call to be upgraded to a
870 * bi-directional video call, turning on or off the user's camera, sending a pause signal
871 * when the {@link InCallService} is no longer the foreground application.
872 * <p>
873 * If the {@link VideoProvider} determines a request to be invalid, it should call
874 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
875 * invalid request back to the {@link InCallService}.
876 * <p>
877 * Where a request requires confirmation from the user of the peer device, the
878 * {@link VideoProvider} must communicate the request to the peer device and handle the
879 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
880 * is used to inform the {@link InCallService} of the result of the request.
881 * <p>
882 * Sent from the {@link InCallService} via
883 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700885 * @param fromProfile The video profile prior to the request.
886 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887 */
Tyler Gunn45382162015-05-06 08:52:27 -0700888 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
889 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700890
Tyler Gunnb702ef82015-05-29 11:51:53 -0700891 /**
892 * Provides a response to a request to change the current video session properties.
893 * <p>
894 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
895 * video call, could decline the request and keep the call as audio-only.
896 * In such a scenario, the {@code responseProfile} would have a video state of
897 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
898 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
899 * <p>
900 * Sent from the {@link InCallService} via
901 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
902 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
903 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700905 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 */
907 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
908
909 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700910 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
911 * <p>
912 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
913 * camera via
914 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
915 * <p>
916 * Sent from the {@link InCallService} via
917 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700918 */
919 public abstract void onRequestCameraCapabilities();
920
921 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700922 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
923 * video component of the current {@link Connection}.
924 * <p>
925 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
926 * via {@link VideoProvider#setCallDataUsage(long)}.
927 * <p>
928 * Sent from the {@link InCallService} via
929 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800931 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700932
933 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
935 * the peer device when the video signal is paused.
936 * <p>
937 * Sent from the {@link InCallService} via
938 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700939 *
940 * @param uri URI of image to display.
941 */
Yorke Lee32f24732015-05-12 16:18:03 -0700942 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943
944 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700945 * Used to inform listening {@link InCallService} implementations when the
946 * {@link VideoProvider} receives a session modification request.
947 * <p>
948 * Received by the {@link InCallService} via
949 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700951 * @param videoProfile The requested video profile.
952 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 */
954 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700955 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700956 for (IVideoCallback callback : mVideoCallbacks.values()) {
957 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700958 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700959 } catch (RemoteException ignored) {
960 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700961 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 }
963 }
964 }
965
966 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700967 * Used to inform listening {@link InCallService} implementations when the
968 * {@link VideoProvider} receives a response to a session modification request.
969 * <p>
970 * Received by the {@link InCallService} via
971 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
972 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 *
974 * @param status Status of the session modify request. Valid values are
975 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
976 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
978 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
979 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
980 * @param requestedProfile The original request which was sent to the peer device.
981 * @param responseProfile The actual profile changes agreed to by the peer device.
982 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 */
984 public void receiveSessionModifyResponse(int status,
985 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700986 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700987 for (IVideoCallback callback : mVideoCallbacks.values()) {
988 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700989 callback.receiveSessionModifyResponse(status, requestedProfile,
990 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700991 } catch (RemoteException ignored) {
992 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700993 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700994 }
995 }
996 }
997
998 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * Used to inform listening {@link InCallService} implementations when the
1000 * {@link VideoProvider} reports a call session event.
1001 * <p>
1002 * Received by the {@link InCallService} via
1003 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001005 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1006 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1007 * {@link VideoProvider#SESSION_EVENT_TX_START},
1008 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1009 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1010 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
1012 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001013 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001014 for (IVideoCallback callback : mVideoCallbacks.values()) {
1015 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001016 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001017 } catch (RemoteException ignored) {
1018 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001019 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 }
1021 }
1022 }
1023
1024 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001025 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1026 * peer's video have changed.
1027 * <p>
1028 * This could occur if, for example, the peer rotates their device, changing the aspect
1029 * ratio of the video, or if the user switches between the back and front cameras.
1030 * <p>
1031 * Received by the {@link InCallService} via
1032 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001033 *
1034 * @param width The updated peer video width.
1035 * @param height The updated peer video height.
1036 */
1037 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001038 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001039 for (IVideoCallback callback : mVideoCallbacks.values()) {
1040 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001041 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001042 } catch (RemoteException ignored) {
1043 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001044 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001045 }
1046 }
1047 }
1048
1049 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * Used to inform listening {@link InCallService} implementations when the data usage of the
1051 * video associated with the current {@link Connection} has changed.
1052 * <p>
1053 * This could be in response to a preview request via
1054 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001055 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1056 * 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 -07001057 * <p>
1058 * Received by the {@link InCallService} via
1059 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001061 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1062 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 */
Yorke Lee32f24732015-05-12 16:18:03 -07001064 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001065 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001066 for (IVideoCallback callback : mVideoCallbacks.values()) {
1067 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001068 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001069 } catch (RemoteException ignored) {
1070 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001071 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 }
1073 }
1074 }
1075
1076 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001077 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001079 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001080 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1081 * @hide
1082 */
1083 public void changeCallDataUsage(long dataUsage) {
1084 setCallDataUsage(dataUsage);
1085 }
1086
1087 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001088 * Used to inform listening {@link InCallService} implementations when the capabilities of
1089 * the current camera have changed.
1090 * <p>
1091 * The {@link VideoProvider} should call this in response to
1092 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1093 * changed via {@link VideoProvider#onSetCamera(String)}.
1094 * <p>
1095 * Received by the {@link InCallService} via
1096 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1097 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001098 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001099 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001100 */
Yorke Lee400470f2015-05-12 13:31:25 -07001101 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001102 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001103 for (IVideoCallback callback : mVideoCallbacks.values()) {
1104 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001105 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001106 } catch (RemoteException ignored) {
1107 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001108 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 }
1110 }
1111 }
Rekha Kumar07366812015-03-24 16:42:31 -07001112
1113 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001114 * Used to inform listening {@link InCallService} implementations when the video quality
1115 * of the call has changed.
1116 * <p>
1117 * Received by the {@link InCallService} via
1118 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001119 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001120 * @param videoQuality The updated video quality. Valid values:
1121 * {@link VideoProfile#QUALITY_HIGH},
1122 * {@link VideoProfile#QUALITY_MEDIUM},
1123 * {@link VideoProfile#QUALITY_LOW},
1124 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001125 */
1126 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001127 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001128 for (IVideoCallback callback : mVideoCallbacks.values()) {
1129 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001130 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001131 } catch (RemoteException ignored) {
1132 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001133 }
Rekha Kumar07366812015-03-24 16:42:31 -07001134 }
1135 }
1136 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001137 }
1138
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001139 private final Listener mConnectionDeathListener = new Listener() {
1140 @Override
1141 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001142 if (mConferenceables.remove(c)) {
1143 fireOnConferenceableConnectionsChanged();
1144 }
1145 }
1146 };
1147
1148 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1149 @Override
1150 public void onDestroyed(Conference c) {
1151 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001152 fireOnConferenceableConnectionsChanged();
1153 }
1154 }
1155 };
1156
Jay Shrauner229e3822014-08-15 09:23:07 -07001157 /**
1158 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1159 * load factor before resizing, 1 means we only expect a single thread to
1160 * access the map so make only a single shard
1161 */
1162 private final Set<Listener> mListeners = Collections.newSetFromMap(
1163 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001164 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1165 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001166 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001167
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001168 // The internal telecom call ID associated with this connection.
1169 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001171 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001172 private Uri mAddress;
1173 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001174 private String mCallerDisplayName;
1175 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001176 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001177 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001178 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001179 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001180 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001181 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001182 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001183 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001184 private Conference mConference;
1185 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001186 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001187
1188 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001189 * Tracks the key set for the extras bundle provided on the last invocation of
1190 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1191 * keys which were set previously but are no longer present in the replacement Bundle.
1192 */
1193 private Set<String> mPreviousExtraKeys;
1194
1195 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001196 * Create a new Connection.
1197 */
Santos Cordonf2951102014-07-20 19:06:29 -07001198 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001199
1200 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001201 * Returns the Telecom internal call ID associated with this connection. Should only be used
1202 * for debugging and tracing purposes.
1203 *
1204 * @return The Telecom call ID.
1205 * @hide
1206 */
1207 public final String getTelecomCallId() {
1208 return mTelecomCallId;
1209 }
1210
1211 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001212 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001213 */
Andrew Lee100e2932014-09-08 15:34:24 -07001214 public final Uri getAddress() {
1215 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001216 }
1217
1218 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001219 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001220 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001221 */
Andrew Lee100e2932014-09-08 15:34:24 -07001222 public final int getAddressPresentation() {
1223 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001224 }
1225
1226 /**
1227 * @return The caller display name (CNAP).
1228 */
1229 public final String getCallerDisplayName() {
1230 return mCallerDisplayName;
1231 }
1232
1233 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001234 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001235 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001236 */
1237 public final int getCallerDisplayNamePresentation() {
1238 return mCallerDisplayNamePresentation;
1239 }
1240
1241 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001242 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001243 */
1244 public final int getState() {
1245 return mState;
1246 }
1247
1248 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001249 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001250 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1251 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1252 * {@link VideoProfile#STATE_TX_ENABLED},
1253 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001254 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001255 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001256 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001257 */
1258 public final int getVideoState() {
1259 return mVideoState;
1260 }
1261
1262 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001263 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 * being routed by the system. This is {@code null} if this Connection
1265 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001266 * @deprecated Use {@link #getCallAudioState()} instead.
1267 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001268 */
Yorke Lee4af59352015-05-13 14:14:54 -07001269 @SystemApi
1270 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001272 if (mCallAudioState == null) {
1273 return null;
1274 }
Yorke Lee4af59352015-05-13 14:14:54 -07001275 return new AudioState(mCallAudioState);
1276 }
1277
1278 /**
1279 * @return The audio state of the connection, describing how its audio is currently
1280 * being routed by the system. This is {@code null} if this Connection
1281 * does not directly know about its audio state.
1282 */
1283 public final CallAudioState getCallAudioState() {
1284 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001285 }
1286
1287 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001288 * @return The conference that this connection is a part of. Null if it is not part of any
1289 * conference.
1290 */
1291 public final Conference getConference() {
1292 return mConference;
1293 }
1294
1295 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001296 * Returns whether this connection is requesting that the system play a ringback tone
1297 * on its behalf.
1298 */
Andrew Lee100e2932014-09-08 15:34:24 -07001299 public final boolean isRingbackRequested() {
1300 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001301 }
1302
1303 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001304 * @return True if the connection's audio mode is VOIP.
1305 */
1306 public final boolean getAudioModeIsVoip() {
1307 return mAudioModeIsVoip;
1308 }
1309
1310 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001311 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1312 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1313 * start time of the conference.
1314 *
1315 * @return The time at which the {@code Connnection} was connected.
1316 *
1317 * @hide
1318 */
1319 public final long getConnectTimeMillis() {
1320 return mConnectTimeMillis;
1321 }
1322
1323 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001324 * @return The status hints for this connection.
1325 */
1326 public final StatusHints getStatusHints() {
1327 return mStatusHints;
1328 }
1329
1330 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001331 * Returns the extras associated with this connection.
1332 * <p>
1333 * Extras should be updated using {@link #putExtras(Bundle)}.
1334 * <p>
1335 * Telecom or an {@link InCallService} can also update the extras via
1336 * {@link android.telecom.Call#putExtras(Bundle)}, and
1337 * {@link Call#removeExtras(List)}.
1338 * <p>
1339 * The connection is notified of changes to the extras made by Telecom or an
1340 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
1341 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001342 * @return The extras associated with this connection.
1343 */
1344 public final Bundle getExtras() {
1345 return mExtras;
1346 }
1347
1348 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001349 * Assign a listener to be notified of state changes.
1350 *
1351 * @param l A listener.
1352 * @return This Connection.
1353 *
1354 * @hide
1355 */
1356 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001357 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001358 return this;
1359 }
1360
1361 /**
1362 * Remove a previously assigned listener that was being notified of state changes.
1363 *
1364 * @param l A Listener.
1365 * @return This Connection.
1366 *
1367 * @hide
1368 */
1369 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001370 if (l != null) {
1371 mListeners.remove(l);
1372 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001373 return this;
1374 }
1375
1376 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001377 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001378 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001379 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001380 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001381 }
1382
1383 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001384 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1385 * ONLY for debugging purposes.
1386 *
1387 * @param callId The telecom call ID.
1388 * @hide
1389 */
1390 public void setTelecomCallId(String callId) {
1391 mTelecomCallId = callId;
1392 }
1393
1394 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001395 * Inform this Connection that the state of its audio output has been changed externally.
1396 *
1397 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001398 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001399 */
Yorke Lee4af59352015-05-13 14:14:54 -07001400 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001401 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001402 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001403 mCallAudioState = state;
1404 onAudioStateChanged(getAudioState());
1405 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001406 }
1407
1408 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001410 * @return A string representation of the value.
1411 */
1412 public static String stateToString(int state) {
1413 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001415 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001416 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001417 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001419 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001421 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001423 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001425 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001427 return "DISCONNECTED";
1428 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001429 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001430 return "UNKNOWN";
1431 }
1432 }
1433
1434 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001435 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001436 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001437 public final int getConnectionCapabilities() {
1438 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001439 }
1440
1441 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001442 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001443 *
Andrew Lee100e2932014-09-08 15:34:24 -07001444 * @param address The new address.
1445 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001446 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001447 */
Andrew Lee100e2932014-09-08 15:34:24 -07001448 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001449 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001450 Log.d(this, "setAddress %s", address);
1451 mAddress = address;
1452 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001453 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001454 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001455 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001456 }
1457
1458 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001459 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001460 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001461 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001462 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001463 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001464 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001465 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001466 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001467 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001468 mCallerDisplayName = callerDisplayName;
1469 mCallerDisplayNamePresentation = presentation;
1470 for (Listener l : mListeners) {
1471 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1472 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001473 }
1474
1475 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001476 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001477 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1478 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1479 * {@link VideoProfile#STATE_TX_ENABLED},
1480 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001481 *
1482 * @param videoState The new video state.
1483 */
1484 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001485 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001486 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001487 mVideoState = videoState;
1488 for (Listener l : mListeners) {
1489 l.onVideoStateChanged(this, mVideoState);
1490 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001491 }
1492
1493 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001494 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001495 * communicate).
1496 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001497 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001498 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001499 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001501 }
1502
1503 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001504 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001505 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001506 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001507 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001509 }
1510
1511 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001512 * Sets state to initializing (this Connection is not yet ready to be used).
1513 */
1514 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001515 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001516 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001517 }
1518
1519 /**
1520 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1521 */
1522 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001523 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001524 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001525 }
1526
1527 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001528 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001529 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001530 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001531 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001533 }
1534
1535 /**
1536 * Sets state to be on hold.
1537 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001538 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001541 }
1542
1543 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001544 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001546 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001547 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001548 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001549 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001550 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001552 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001553 }
1554
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001555 public final VideoProvider getVideoProvider() {
1556 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001557 }
1558
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001559 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001560 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001561 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001562 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001563 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001564 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001565 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001566 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001567 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001569 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001570 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001571 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001572 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001573 }
1574
1575 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001576 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1577 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1578 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1579 * to send an {@link #onPostDialContinue(boolean)} signal.
1580 *
1581 * @param remaining The DTMF character sequence remaining to be emitted once the
1582 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1583 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001584 */
1585 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001586 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001587 for (Listener l : mListeners) {
1588 l.onPostDialWait(this, remaining);
1589 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001590 }
1591
1592 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001593 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1594 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001595 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001596 *
1597 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001598 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001599 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001600 checkImmutable();
1601 for (Listener l : mListeners) {
1602 l.onPostDialChar(this, nextChar);
1603 }
1604 }
1605
1606 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001607 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001608 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001609 *
1610 * @param ringback Whether the ringback tone is to be played.
1611 */
Andrew Lee100e2932014-09-08 15:34:24 -07001612 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001613 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001614 if (mRingbackRequested != ringback) {
1615 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001616 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001617 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001618 }
1619 }
Ihab Awadf8358972014-05-28 16:46:42 -07001620 }
1621
1622 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001623 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001624 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001625 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001626 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001627 public final void setConnectionCapabilities(int connectionCapabilities) {
1628 checkImmutable();
1629 if (mConnectionCapabilities != connectionCapabilities) {
1630 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001631 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001632 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001633 }
1634 }
Santos Cordonb6939982014-06-04 20:20:58 -07001635 }
1636
1637 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001638 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001639 */
Evan Charlton36a71342014-07-19 16:31:02 -07001640 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001641 for (Listener l : mListeners) {
1642 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001643 }
Santos Cordonb6939982014-06-04 20:20:58 -07001644 }
1645
1646 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001647 * Requests that the framework use VOIP audio mode for this connection.
1648 *
1649 * @param isVoip True if the audio mode is VOIP.
1650 */
1651 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001652 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001653 mAudioModeIsVoip = isVoip;
1654 for (Listener l : mListeners) {
1655 l.onAudioModeIsVoipChanged(this, isVoip);
1656 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001657 }
1658
1659 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001660 * Sets the time at which a call became active on this Connection. This is set only
1661 * when a conference call becomes active on this connection.
1662 *
1663 * @param connectionTimeMillis The connection time, in milliseconds.
1664 *
1665 * @hide
1666 */
1667 public final void setConnectTimeMillis(long connectTimeMillis) {
1668 mConnectTimeMillis = connectTimeMillis;
1669 }
1670
1671 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001672 * Sets the label and icon status to display in the in-call UI.
1673 *
1674 * @param statusHints The status label and icon to set.
1675 */
1676 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001678 mStatusHints = statusHints;
1679 for (Listener l : mListeners) {
1680 l.onStatusHintsChanged(this, statusHints);
1681 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001682 }
1683
1684 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001685 * Sets the connections with which this connection can be conferenced.
1686 *
1687 * @param conferenceableConnections The set of connections this connection can conference with.
1688 */
1689 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001690 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001691 clearConferenceableList();
1692 for (Connection c : conferenceableConnections) {
1693 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1694 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001695 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001696 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001697 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001698 }
1699 }
1700 fireOnConferenceableConnectionsChanged();
1701 }
1702
1703 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001704 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1705 * or conferences with which this connection can be conferenced.
1706 *
1707 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001708 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001709 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001710 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001711 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001712 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1713 // small amount of items here.
1714 if (!mConferenceables.contains(c)) {
1715 if (c instanceof Connection) {
1716 Connection connection = (Connection) c;
1717 connection.addConnectionListener(mConnectionDeathListener);
1718 } else if (c instanceof Conference) {
1719 Conference conference = (Conference) c;
1720 conference.addListener(mConferenceDeathListener);
1721 }
1722 mConferenceables.add(c);
1723 }
1724 }
1725 fireOnConferenceableConnectionsChanged();
1726 }
1727
1728 /**
1729 * Returns the connections or conferences with which this connection can be conferenced.
1730 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001731 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001732 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001733 }
1734
Yorke Lee53463962015-08-04 16:07:19 -07001735 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001736 * @hide
1737 */
1738 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001739 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001740 if (mConnectionService != null) {
1741 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1742 "which is already associated with another ConnectionService.");
1743 } else {
1744 mConnectionService = connectionService;
1745 }
1746 }
1747
1748 /**
1749 * @hide
1750 */
1751 public final void unsetConnectionService(ConnectionService connectionService) {
1752 if (mConnectionService != connectionService) {
1753 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1754 "that does not belong to the ConnectionService.");
1755 } else {
1756 mConnectionService = null;
1757 }
1758 }
1759
1760 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001761 * @hide
1762 */
1763 public final ConnectionService getConnectionService() {
1764 return mConnectionService;
1765 }
1766
1767 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001768 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001769 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001770 *
1771 * @param conference The conference.
1772 * @return {@code true} if the conference was successfully set.
1773 * @hide
1774 */
1775 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001776 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001777 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001778 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001779 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001780 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1781 fireConferenceChanged();
1782 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001783 return true;
1784 }
1785 return false;
1786 }
1787
1788 /**
1789 * Resets the conference that this connection is a part of.
1790 * @hide
1791 */
1792 public final void resetConference() {
1793 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001794 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001795 mConference = null;
1796 fireConferenceChanged();
1797 }
1798 }
1799
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001800 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001801 * Set some extras that can be associated with this {@code Connection}.
1802 * <p>
1803 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1804 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1805 * <p>
1806 * 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 -07001807 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1808 *
1809 * @param extras The extras associated with this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001810 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1811 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001812 */
1813 public final void setExtras(@Nullable Bundle extras) {
1814 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001815
1816 // Add/replace any new or changed extras values.
1817 putExtras(extras);
1818
1819 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1820 // the current one and remove any keys that went away.
1821 if (mPreviousExtraKeys != null) {
1822 List<String> toRemove = new ArrayList<String>();
1823 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001824 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001825 toRemove.add(oldKey);
1826 }
1827 }
1828 if (!toRemove.isEmpty()) {
1829 removeExtras(toRemove);
1830 }
1831 }
1832
1833 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1834 // called we can see if the caller has removed any extras values.
1835 if (mPreviousExtraKeys == null) {
1836 mPreviousExtraKeys = new ArraySet<String>();
1837 }
1838 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001839 if (extras != null) {
1840 mPreviousExtraKeys.addAll(extras.keySet());
1841 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001842 }
1843
1844 /**
1845 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1846 * added.
1847 * <p>
1848 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1849 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1850 *
1851 * @param extras The extras to add.
1852 */
1853 public final void putExtras(@NonNull Bundle extras) {
1854 checkImmutable();
1855 if (extras == null) {
1856 return;
1857 }
1858
1859 if (mExtras == null) {
1860 mExtras = new Bundle();
1861 }
1862 mExtras.putAll(extras);
1863
Santos Cordon6b7f9552015-05-27 17:21:45 -07001864 for (Listener l : mListeners) {
1865 l.onExtrasChanged(this, extras);
1866 }
1867 }
1868
1869 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001870 * Adds a boolean extra to this {@code Connection}.
1871 *
1872 * @param key The extra key.
1873 * @param value The value.
1874 * @hide
1875 */
1876 public final void putExtra(String key, boolean value) {
1877 Bundle newExtras = new Bundle();
1878 newExtras.putBoolean(key, value);
1879 putExtras(newExtras);
1880 }
1881
1882 /**
1883 * Adds an integer extra to this {@code Connection}.
1884 *
1885 * @param key The extra key.
1886 * @param value The value.
1887 * @hide
1888 */
1889 public final void putExtra(String key, int value) {
1890 Bundle newExtras = new Bundle();
1891 newExtras.putInt(key, value);
1892 putExtras(newExtras);
1893 }
1894
1895 /**
1896 * Adds a string extra to this {@code Connection}.
1897 *
1898 * @param key The extra key.
1899 * @param value The value.
1900 * @hide
1901 */
1902 public final void putExtra(String key, String value) {
1903 Bundle newExtras = new Bundle();
1904 newExtras.putString(key, value);
1905 putExtras(newExtras);
1906 }
1907
1908 /**
1909 * Removes an extra from this {@code Connection}.
1910 *
1911 * @param keys The key of the extra key to remove.
1912 */
1913 public final void removeExtras(List<String> keys) {
1914 if (mExtras != null) {
1915 for (String key : keys) {
1916 mExtras.remove(key);
1917 }
1918
1919 if (mExtras.size() == 0) {
1920 mExtras = null;
1921 }
1922 }
1923
1924 for (Listener l : mListeners) {
1925 l.onExtrasRemoved(this, keys);
1926 }
1927 }
1928
1929 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001930 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001931 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001932 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001933 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1934 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001935 */
Yorke Lee4af59352015-05-13 14:14:54 -07001936 @SystemApi
1937 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001938 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001939
1940 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001941 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1942 *
1943 * @param state The new connection audio state.
1944 */
1945 public void onCallAudioStateChanged(CallAudioState state) {}
1946
1947 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001948 * Notifies this Connection of an internal state change. This method is called after the
1949 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001950 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001951 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001952 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001953 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001954
1955 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 * Notifies this Connection of a request to play a DTMF tone.
1957 *
1958 * @param c A DTMF character.
1959 */
Santos Cordonf2951102014-07-20 19:06:29 -07001960 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001961
1962 /**
1963 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1964 */
Santos Cordonf2951102014-07-20 19:06:29 -07001965 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966
1967 /**
1968 * Notifies this Connection of a request to disconnect.
1969 */
Santos Cordonf2951102014-07-20 19:06:29 -07001970 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001971
1972 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001973 * Notifies this Connection of a request to disconnect a participant of the conference managed
1974 * by the connection.
1975 *
1976 * @param endpoint the {@link Uri} of the participant to disconnect.
1977 * @hide
1978 */
1979 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1980
1981 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001982 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001983 */
Santos Cordonf2951102014-07-20 19:06:29 -07001984 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001985
1986 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001987 * Notifies this Connection of a request to abort.
1988 */
Santos Cordonf2951102014-07-20 19:06:29 -07001989 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001990
1991 /**
1992 * Notifies this Connection of a request to hold.
1993 */
Santos Cordonf2951102014-07-20 19:06:29 -07001994 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001995
1996 /**
1997 * Notifies this Connection of a request to exit a hold state.
1998 */
Santos Cordonf2951102014-07-20 19:06:29 -07001999 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002000
2001 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002002 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002003 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002004 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002005 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002006 */
Santos Cordonf2951102014-07-20 19:06:29 -07002007 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002008
2009 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002010 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002011 * a request to accept.
2012 */
2013 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002014 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002015 }
2016
2017 /**
2018 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002019 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002020 */
Santos Cordonf2951102014-07-20 19:06:29 -07002021 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002022
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002023 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002024 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2025 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002026 */
2027 public void onReject(String replyMessage) {}
2028
2029 /**
Bryce Leecac50772015-11-17 15:13:29 -08002030 * Notifies the Connection of a request to silence the ringer.
2031 *
2032 * @hide
2033 */
2034 public void onSilence() {}
2035
2036 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002037 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2038 */
Santos Cordonf2951102014-07-20 19:06:29 -07002039 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002040
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002041 /**
2042 * Notifies this Connection of a request to pull an external call to the local device.
2043 * <p>
2044 * The {@link InCallService} issues a request to pull an external call to the local device via
2045 * {@link Call#pullExternalCall()}.
2046 * <p>
2047 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL} and
2048 * {@link Connection#CAPABILITY_IS_EXTERNAL_CALL} capability bits must be set.
2049 * <p>
2050 * For more information on external calls, see {@link Connection#CAPABILITY_IS_EXTERNAL_CALL}.
2051 */
2052 public void onPullExternalCall() {}
2053
2054 /**
2055 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2056 * <p>
2057 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2058 * <p>
2059 * See also {@link Call#sendCallEvent(String, Bundle)}.
2060 *
2061 * @param event The call event.
2062 * @param extras Extras associated with the call event.
2063 */
2064 public void onCallEvent(String event, Bundle extras) {}
2065
Tyler Gunndee56a82016-03-23 16:06:34 -07002066 /**
2067 * Notifies this {@link Connection} of a change to the extras made outside the
2068 * {@link ConnectionService}.
2069 * <p>
2070 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2071 * the {@link android.telecom.Call#putExtras(Bundle)} and
2072 * {@link Call#removeExtras(List)}.
2073 *
2074 * @param extras The new extras bundle.
2075 */
2076 public void onExtrasChanged(Bundle extras) {}
2077
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 static String toLogSafePhoneNumber(String number) {
2079 // For unknown number, log empty string.
2080 if (number == null) {
2081 return "";
2082 }
2083
2084 if (PII_DEBUG) {
2085 // When PII_DEBUG is true we emit PII.
2086 return number;
2087 }
2088
2089 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2090 // sanitized phone numbers.
2091 StringBuilder builder = new StringBuilder();
2092 for (int i = 0; i < number.length(); i++) {
2093 char c = number.charAt(i);
2094 if (c == '-' || c == '@' || c == '.') {
2095 builder.append(c);
2096 } else {
2097 builder.append('x');
2098 }
2099 }
2100 return builder.toString();
2101 }
2102
Ihab Awad542e0ea2014-05-16 10:22:16 -07002103 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002104 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002105 if (mState == STATE_DISCONNECTED && mState != state) {
2106 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002107 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002108 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002109 if (mState != state) {
2110 Log.d(this, "setState: %s", stateToString(state));
2111 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002112 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002113 for (Listener l : mListeners) {
2114 l.onStateChanged(this, state);
2115 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002116 }
2117 }
2118
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002119 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002120 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002121 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2122 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002123 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002124 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125
2126 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002127 if (mImmutable) {
2128 throw new UnsupportedOperationException("Connection is immutable");
2129 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002130 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002131 }
2132
Evan Charltonbf11f982014-07-20 22:06:28 -07002133 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002134 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002135 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2136 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002137 * <p>
2138 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2139 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002140 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002141 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002142 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002143 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002144 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2145 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002146 }
2147
Evan Charltonbf11f982014-07-20 22:06:28 -07002148 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002149 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2150 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2151 * this should never be un-@hide-den.
2152 *
2153 * @hide
2154 */
2155 public void checkImmutable() {}
2156
2157 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002158 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2159 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2160 * that state. This connection should not be used for anything, and no other
2161 * {@code Connection}s should be attempted.
2162 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002163 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002164 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002165 * @return A {@code Connection} which indicates that the underlying connection should
2166 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002167 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002168 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002169 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002170 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002171
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002172 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002173 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002174 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002175 }
2176 }
2177
Santos Cordon823fd3c2014-08-07 18:35:18 -07002178 private final void fireConferenceChanged() {
2179 for (Listener l : mListeners) {
2180 l.onConferenceChanged(this, mConference);
2181 }
2182 }
2183
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002184 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002185 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002186 if (c instanceof Connection) {
2187 Connection connection = (Connection) c;
2188 connection.removeConnectionListener(mConnectionDeathListener);
2189 } else if (c instanceof Conference) {
2190 Conference conference = (Conference) c;
2191 conference.removeListener(mConferenceDeathListener);
2192 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002193 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002194 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002195 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002196
2197 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002198 * Handles a change to extras received from Telecom.
2199 *
2200 * @param extras The new extras.
2201 * @hide
2202 */
2203 final void handleExtrasChanged(Bundle extras) {
2204 mExtras = extras;
2205 onExtrasChanged(mExtras);
2206 }
2207
2208 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002209 * Notifies listeners that the merge request failed.
2210 *
2211 * @hide
2212 */
2213 protected final void notifyConferenceMergeFailed() {
2214 for (Listener l : mListeners) {
2215 l.onConferenceMergeFailed(this);
2216 }
2217 }
2218
2219 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002220 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002221 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002222 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002223 * @hide
2224 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002225 protected final void updateConferenceParticipants(
2226 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002227 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002228 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002229 }
2230 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002231
2232 /**
2233 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002234 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002235 */
2236 protected void notifyConferenceStarted() {
2237 for (Listener l : mListeners) {
2238 l.onConferenceStarted();
2239 }
2240 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002241
2242 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002243 * Sends an event associated with this {@code Connection}, with associated event extras.
2244 *
2245 * Events are exposed to {@link InCallService} implementations via the
2246 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2247 *
2248 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2249 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002250 *
2251 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002252 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002253 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002254 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002255 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002256 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002257 }
2258 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002259}