blob: a5e3c4612a5d50c4db706876c84933e192f9268c [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070038import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070042import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
44/**
Santos Cordon895d4b82015-06-25 16:41:48 -070045 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
46 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070047 * <p>
48 * Implementations create a custom subclass of {@code Connection} and return it to the framework
49 * as the return value of
50 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
51 * or
52 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
53 * Implementations are then responsible for updating the state of the {@code Connection}, and
54 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
55 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070056 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070057public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
Santos Cordon895d4b82015-06-25 16:41:48 -070059 /**
60 * The connection is initializing. This is generally the first state for a {@code Connection}
61 * returned by a {@link ConnectionService}.
62 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 public static final int STATE_INITIALIZING = 0;
64
Santos Cordon895d4b82015-06-25 16:41:48 -070065 /**
66 * The connection is new and not connected.
67 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070068 public static final int STATE_NEW = 1;
69
Santos Cordon895d4b82015-06-25 16:41:48 -070070 /**
71 * An incoming connection is in the ringing state. During this state, the user's ringer or
72 * vibration feature will be activated.
73 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 public static final int STATE_RINGING = 2;
75
Santos Cordon895d4b82015-06-25 16:41:48 -070076 /**
77 * An outgoing connection is in the dialing state. In this state the other party has not yet
78 * answered the call and the user traditionally hears a ringback tone.
79 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 public static final int STATE_DIALING = 3;
81
Santos Cordon895d4b82015-06-25 16:41:48 -070082 /**
83 * A connection is active. Both parties are connected to the call and can actively communicate.
84 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 public static final int STATE_ACTIVE = 4;
86
Santos Cordon895d4b82015-06-25 16:41:48 -070087 /**
88 * A connection is on hold.
89 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 public static final int STATE_HOLDING = 5;
91
Santos Cordon895d4b82015-06-25 16:41:48 -070092 /**
93 * A connection has been disconnected. This is the final state once the user has been
94 * disconnected from a call either locally, remotely or by an error in the service.
95 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public static final int STATE_DISCONNECTED = 6;
97
Santos Cordon895d4b82015-06-25 16:41:48 -070098 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070099 * The state of an external connection which is in the process of being pulled from a remote
100 * device to the local device.
101 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700102 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700103 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
104 */
105 public static final int STATE_PULLING_CALL = 7;
106
107 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 * Connection can currently be put on hold or unheld. This is distinct from
109 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
110 * it does not at the moment support the function. This can be true while the call is in the
111 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
112 * display a disabled 'hold' button.
113 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800114 public static final int CAPABILITY_HOLD = 0x00000001;
115
116 /** Connection supports the hold feature. */
117 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
118
119 /**
120 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
121 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
122 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
123 * capability allows a merge button to be shown while the conference is in the foreground
124 * of the in-call UI.
125 * <p>
126 * This is only intended for use by a {@link Conference}.
127 */
128 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
129
130 /**
131 * Connections within a conference can be swapped between foreground and background.
132 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
133 * <p>
134 * This is only intended for use by a {@link Conference}.
135 */
136 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
137
138 /**
139 * @hide
140 */
141 public static final int CAPABILITY_UNUSED = 0x00000010;
142
143 /** Connection supports responding via text option. */
144 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
145
146 /** Connection can be muted. */
147 public static final int CAPABILITY_MUTE = 0x00000040;
148
149 /**
150 * Connection supports conference management. This capability only applies to
151 * {@link Conference}s which can have {@link Connection}s as children.
152 */
153 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
154
155 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700158 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159
160 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164
165 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700168 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
175
176 /**
177 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700178 */
179 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
180
181 /**
182 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
188 * Connection is able to be separated from its parent {@code Conference}, if any.
189 */
190 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
191
192 /**
193 * Connection is able to be individually disconnected when in a {@code Conference}.
194 */
195 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
196
197 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700198 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 * @hide
200 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700201 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700204 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 * @hide
206 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700207 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208
209 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700210 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * @hide
212 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700213 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214
Tyler Gunn068085b2015-02-06 13:56:52 -0800215 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700216 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800217 * @hide
218 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700219 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800220
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 */
225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Tyler Gunnd4091732015-06-29 09:15:37 -0700238 /**
239 * For a conference, indicates the conference will not have child connections.
240 * <p>
241 * An example of a conference with child connections is a GSM conference call, where the radio
242 * retains connections to the individual participants of the conference. Another example is an
243 * IMS conference call where conference event package functionality is supported; in this case
244 * the conference server ensures the radio is aware of the participants in the conference, which
245 * are represented by child connections.
246 * <p>
247 * An example of a conference with no child connections is an IMS conference call with no
248 * conference event package support. Such a conference is represented by the radio as a single
249 * connection to the IMS conference server.
250 * <p>
251 * Indicating whether a conference has children or not is important to help user interfaces
252 * visually represent a conference. A conference with no children, for example, will have the
253 * conference connection shown in the list of calls on a Bluetooth device, where if the
254 * conference has children, only the children will be shown in the list of calls on a Bluetooth
255 * device.
256 * @hide
257 */
258 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259
Bryce Lee81901682015-08-28 16:38:02 -0700260 /**
261 * Indicates that the connection itself wants to handle any sort of reply response, rather than
262 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700263 */
264 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
265
Tyler Gunnf97a0092016-01-19 15:59:34 -0800266 /**
267 * When set, prevents a video call from being downgraded to an audio-only call.
268 * <p>
269 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271 * downgraded from a video call back to a VideoState of
272 * {@link VideoProfile#STATE_AUDIO_ONLY}.
273 * <p>
274 * Intuitively, a call which can be downgraded to audio should also have local and remote
275 * video
276 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278 */
279 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700281 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 * When set for an external connection, indicates that this {@code Connection} can be pulled
283 * from a remote device to the current device.
284 * <p>
285 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
286 * is set.
287 */
288 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
289
290 //**********************************************************************************************
291 // Next CAPABILITY value: 0x02000000
292 //**********************************************************************************************
293
294 /**
295 * Indicates that the current device callback number should be shown.
296 *
297 * @hide
298 */
299 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
300
301 /**
302 * Whether the call is a generic conference, where we do not know the precise state of
303 * participants in the conference (eg. on CDMA).
304 *
305 * @hide
306 */
307 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
308
309 /**
310 * Connection is using high definition audio.
311 * @hide
312 */
313 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
314
315 /**
316 * Connection is using WIFI.
317 * @hide
318 */
319 public static final int PROPERTY_WIFI = 1<<3;
320
321 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 * When set, indicates that the {@code Connection} does not actually exist locally for the
323 * {@link ConnectionService}.
324 * <p>
325 * Consider, for example, a scenario where a user has two devices with the same phone number.
326 * When a user places a call on one devices, the telephony stack can represent that call on the
327 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700328 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700329 * <p>
330 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
331 * external connections. Only those {@link InCallService}s which have the
332 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
333 * manifest will see external connections.
334 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700337
Tyler Gunn96d6c402015-03-18 12:39:23 -0700338 //**********************************************************************************************
Tyler Gunn720c6642016-03-22 09:02:47 -0700339 // Next PROPERTY value: 1<<5
Tyler Gunn96d6c402015-03-18 12:39:23 -0700340 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800341
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700342 /**
343 * Connection extra key used to store the last forwarded number associated with the current
344 * connection. Used to communicate to the user interface that the connection was forwarded via
345 * the specified number.
346 */
347 public static final String EXTRA_LAST_FORWARDED_NUMBER =
348 "android.telecom.extra.LAST_FORWARDED_NUMBER";
349
350 /**
351 * Connection extra key used to store a child number associated with the current connection.
352 * Used to communicate to the user interface that the connection was received via
353 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
354 * address.
355 */
356 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
357
358 /**
359 * Connection extra key used to store the subject for an incoming call. The user interface can
360 * query this extra and display its contents for incoming calls. Will only be used if the
361 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
362 */
363 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
364
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800365 /**
366 * Connection event used to inform Telecom that it should play the on hold tone. This is used
367 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
368 * {@link #sendConnectionEvent(String)}.
369 * @hide
370 */
371 public static final String EVENT_ON_HOLD_TONE_START =
372 "android.telecom.event.ON_HOLD_TONE_START";
373
374 /**
375 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
376 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
377 * {@link #sendConnectionEvent(String)}.
378 * @hide
379 */
380 public static final String EVENT_ON_HOLD_TONE_END =
381 "android.telecom.event.ON_HOLD_TONE_END";
382
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700383 /**
384 * Connection event used to inform {@link InCallService}s when pulling of an external call has
385 * failed. The user interface should inform the user of the error.
386 * <p>
387 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
388 * API is called on a {@link Call} with the properties
389 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
390 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
391 * pull the external call due to an error condition.
392 */
393 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
394
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700395 // Flag controlling whether PII is emitted into the logs
396 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
397
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800398 /**
399 * Whether the given capabilities support the specified capability.
400 *
401 * @param capabilities A capability bit field.
402 * @param capability The capability to check capabilities for.
403 * @return Whether the specified capability is supported.
404 * @hide
405 */
406 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800407 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800408 }
409
410 /**
411 * Whether the capabilities of this {@code Connection} supports the specified capability.
412 *
413 * @param capability The capability to check capabilities for.
414 * @return Whether the specified capability is supported.
415 * @hide
416 */
417 public boolean can(int capability) {
418 return can(mConnectionCapabilities, capability);
419 }
420
421 /**
422 * Removes the specified capability from the set of capabilities of this {@code Connection}.
423 *
424 * @param capability The capability to remove from the set.
425 * @hide
426 */
427 public void removeCapability(int capability) {
428 mConnectionCapabilities &= ~capability;
429 }
430
431 /**
432 * Adds the specified capability to the set of capabilities of this {@code Connection}.
433 *
434 * @param capability The capability to add to the set.
435 * @hide
436 */
437 public void addCapability(int capability) {
438 mConnectionCapabilities |= capability;
439 }
440
441
442 public static String capabilitiesToString(int capabilities) {
443 StringBuilder builder = new StringBuilder();
444 builder.append("[Capabilities:");
445 if (can(capabilities, CAPABILITY_HOLD)) {
446 builder.append(" CAPABILITY_HOLD");
447 }
448 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
449 builder.append(" CAPABILITY_SUPPORT_HOLD");
450 }
451 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
452 builder.append(" CAPABILITY_MERGE_CONFERENCE");
453 }
454 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
455 builder.append(" CAPABILITY_SWAP_CONFERENCE");
456 }
457 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
458 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
459 }
460 if (can(capabilities, CAPABILITY_MUTE)) {
461 builder.append(" CAPABILITY_MUTE");
462 }
463 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
464 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
465 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700466 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
467 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
468 }
469 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
470 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
471 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700472 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
473 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800474 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700475 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
476 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
477 }
478 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
479 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
480 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700481 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
482 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800483 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800484 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
485 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
486 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500487 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700488 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500489 }
Rekha Kumar07366812015-03-24 16:42:31 -0700490 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
491 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
492 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700493 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
494 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
495 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700496 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
497 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
498 }
Bryce Lee81901682015-08-28 16:38:02 -0700499 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
500 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
501 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700502 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
503 builder.append(" CAPABILITY_CAN_PULL_CALL");
504 }
Bryce Lee81901682015-08-28 16:38:02 -0700505
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800506 builder.append("]");
507 return builder.toString();
508 }
509
Tyler Gunn720c6642016-03-22 09:02:47 -0700510 public static String propertiesToString(int properties) {
511 StringBuilder builder = new StringBuilder();
512 builder.append("[Properties:");
513
514 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
515 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
516 }
517
518 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
519 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
520 }
521
522 if (can(properties, PROPERTY_WIFI)) {
523 builder.append(" PROPERTY_WIFI");
524 }
525
526 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
527 builder.append(" PROPERTY_GENERIC_CONFERENCE");
528 }
529
530 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
531 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
532 }
533
534 builder.append("]");
535 return builder.toString();
536 }
537
Sailesh Nepal091768c2014-06-30 15:15:23 -0700538 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700539 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700540 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700541 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700542 public void onCallerDisplayNameChanged(
543 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700544 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700545 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700546 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800547 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700548 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700549 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700551 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 public void onVideoProviderChanged(
553 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700554 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
555 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800556 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700557 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700558 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700559 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800560 public void onConferenceParticipantsChanged(Connection c,
561 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800562 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700563 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700564 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700565 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700566 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700567 }
568
Tyler Gunnb702ef82015-05-29 11:51:53 -0700569 /**
570 * Provides a means of controlling the video session associated with a {@link Connection}.
571 * <p>
572 * Implementations create a custom subclass of {@link VideoProvider} and the
573 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
574 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
575 * should set the {@link VideoProvider}.
576 * <p>
577 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
578 * {@link InCallService} implementations to issue requests related to the video session;
579 * it provides a means for the {@link ConnectionService} to report events and information
580 * related to the video session to Telecom and the {@link InCallService} implementations.
581 * <p>
582 * {@link InCallService} implementations interact with the {@link VideoProvider} via
583 * {@link android.telecom.InCallService.VideoCall}.
584 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700585 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700586
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 /**
588 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700589 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700590 */
591 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700592
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700594 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
595 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700596 */
597 public static final int SESSION_EVENT_RX_RESUME = 2;
598
599 /**
600 * Video transmission has begun. This occurs after a negotiated start of video transmission
601 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700602 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700603 */
604 public static final int SESSION_EVENT_TX_START = 3;
605
606 /**
607 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
608 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700609 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700610 */
611 public static final int SESSION_EVENT_TX_STOP = 4;
612
613 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700614 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
615 * this as a cue to inform the user the camera is not available.
616 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 */
618 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
619
620 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700621 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
622 * for operation. The {@link InCallService} can use this as a cue to inform the user that
623 * the camera has become available again.
624 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 */
626 public static final int SESSION_EVENT_CAMERA_READY = 6;
627
628 /**
629 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700630 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 */
632 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
633
634 /**
635 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700636 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700637 */
638 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
639
640 /**
641 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700642 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700643 */
644 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
645
Rekha Kumar07366812015-03-24 16:42:31 -0700646 /**
647 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700648 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700649 */
650 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
651
652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700653 * Session modify request rejected by remote user.
654 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700655 */
656 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
657
Tyler Gunn75958422015-04-15 14:23:42 -0700658 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700659 private static final int MSG_SET_CAMERA = 2;
660 private static final int MSG_SET_PREVIEW_SURFACE = 3;
661 private static final int MSG_SET_DISPLAY_SURFACE = 4;
662 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
663 private static final int MSG_SET_ZOOM = 6;
664 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
665 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
666 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700669 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700671 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700672 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700673
674 /**
675 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700676 *
677 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
678 * load factor before resizing, 1 means we only expect a single thread to
679 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700680 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700681 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
682 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683
684 /**
685 * Default handler used to consolidate binder method calls onto a single thread.
686 */
687 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700688 public VideoProviderHandler() {
689 super();
690 }
691
692 public VideoProviderHandler(Looper looper) {
693 super(looper);
694 }
695
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 @Override
697 public void handleMessage(Message msg) {
698 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700699 case MSG_ADD_VIDEO_CALLBACK: {
700 IBinder binder = (IBinder) msg.obj;
701 IVideoCallback callback = IVideoCallback.Stub
702 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700703 if (callback == null) {
704 Log.w(this, "addVideoProvider - skipped; callback is null.");
705 break;
706 }
707
Tyler Gunn75958422015-04-15 14:23:42 -0700708 if (mVideoCallbacks.containsKey(binder)) {
709 Log.i(this, "addVideoProvider - skipped; already present.");
710 break;
711 }
712 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700714 }
715 case MSG_REMOVE_VIDEO_CALLBACK: {
716 IBinder binder = (IBinder) msg.obj;
717 IVideoCallback callback = IVideoCallback.Stub
718 .asInterface((IBinder) msg.obj);
719 if (!mVideoCallbacks.containsKey(binder)) {
720 Log.i(this, "removeVideoProvider - skipped; not present.");
721 break;
722 }
723 mVideoCallbacks.remove(binder);
724 break;
725 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 case MSG_SET_CAMERA:
727 onSetCamera((String) msg.obj);
728 break;
729 case MSG_SET_PREVIEW_SURFACE:
730 onSetPreviewSurface((Surface) msg.obj);
731 break;
732 case MSG_SET_DISPLAY_SURFACE:
733 onSetDisplaySurface((Surface) msg.obj);
734 break;
735 case MSG_SET_DEVICE_ORIENTATION:
736 onSetDeviceOrientation(msg.arg1);
737 break;
738 case MSG_SET_ZOOM:
739 onSetZoom((Float) msg.obj);
740 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700741 case MSG_SEND_SESSION_MODIFY_REQUEST: {
742 SomeArgs args = (SomeArgs) msg.obj;
743 try {
744 onSendSessionModifyRequest((VideoProfile) args.arg1,
745 (VideoProfile) args.arg2);
746 } finally {
747 args.recycle();
748 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700750 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751 case MSG_SEND_SESSION_MODIFY_RESPONSE:
752 onSendSessionModifyResponse((VideoProfile) msg.obj);
753 break;
754 case MSG_REQUEST_CAMERA_CAPABILITIES:
755 onRequestCameraCapabilities();
756 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800757 case MSG_REQUEST_CONNECTION_DATA_USAGE:
758 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 break;
760 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700761 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 break;
763 default:
764 break;
765 }
766 }
767 }
768
769 /**
770 * IVideoProvider stub implementation.
771 */
772 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700773 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700774 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700775 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
776 }
777
778 public void removeVideoCallback(IBinder videoCallbackBinder) {
779 mMessageHandler.obtainMessage(
780 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 }
782
783 public void setCamera(String cameraId) {
784 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
785 }
786
787 public void setPreviewSurface(Surface surface) {
788 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
789 }
790
791 public void setDisplaySurface(Surface surface) {
792 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
793 }
794
795 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700796 mMessageHandler.obtainMessage(
797 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700798 }
799
800 public void setZoom(float value) {
801 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
802 }
803
Tyler Gunn45382162015-05-06 08:52:27 -0700804 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
805 SomeArgs args = SomeArgs.obtain();
806 args.arg1 = fromProfile;
807 args.arg2 = toProfile;
808 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700809 }
810
811 public void sendSessionModifyResponse(VideoProfile responseProfile) {
812 mMessageHandler.obtainMessage(
813 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
814 }
815
816 public void requestCameraCapabilities() {
817 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
818 }
819
820 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800821 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700822 }
823
Yorke Lee32f24732015-05-12 16:18:03 -0700824 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700825 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
826 }
827 }
828
829 public VideoProvider() {
830 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700831 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700832 }
833
834 /**
835 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
836 *
837 * @param looper The looper.
838 * @hide
839 */
840 public VideoProvider(Looper looper) {
841 mBinder = new VideoProvider.VideoProviderBinder();
842 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700843 }
844
845 /**
846 * Returns binder object which can be used across IPC methods.
847 * @hide
848 */
849 public final IVideoProvider getInterface() {
850 return mBinder;
851 }
852
853 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700854 * Sets the camera to be used for the outgoing video.
855 * <p>
856 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
857 * camera via
858 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
859 * <p>
860 * Sent from the {@link InCallService} via
861 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700862 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700863 * @param cameraId The id of the camera (use ids as reported by
864 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 */
866 public abstract void onSetCamera(String cameraId);
867
868 /**
869 * Sets the surface to be used for displaying a preview of what the user's camera is
870 * currently capturing. When video transmission is enabled, this is the video signal which
871 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700872 * <p>
873 * Sent from the {@link InCallService} via
874 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700876 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 */
878 public abstract void onSetPreviewSurface(Surface surface);
879
880 /**
881 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700882 * <p>
883 * Sent from the {@link InCallService} via
884 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700886 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887 */
888 public abstract void onSetDisplaySurface(Surface surface);
889
890 /**
891 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
892 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700893 * <p>
894 * Sent from the {@link InCallService} via
895 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700896 *
897 * @param rotation The device orientation, in degrees.
898 */
899 public abstract void onSetDeviceOrientation(int rotation);
900
901 /**
902 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700903 * <p>
904 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 *
906 * @param value The camera zoom ratio.
907 */
908 public abstract void onSetZoom(float value);
909
910 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700911 * Issues a request to modify the properties of the current video session.
912 * <p>
913 * Example scenarios include: requesting an audio-only call to be upgraded to a
914 * bi-directional video call, turning on or off the user's camera, sending a pause signal
915 * when the {@link InCallService} is no longer the foreground application.
916 * <p>
917 * If the {@link VideoProvider} determines a request to be invalid, it should call
918 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
919 * invalid request back to the {@link InCallService}.
920 * <p>
921 * Where a request requires confirmation from the user of the peer device, the
922 * {@link VideoProvider} must communicate the request to the peer device and handle the
923 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
924 * is used to inform the {@link InCallService} of the result of the request.
925 * <p>
926 * Sent from the {@link InCallService} via
927 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700929 * @param fromProfile The video profile prior to the request.
930 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 */
Tyler Gunn45382162015-05-06 08:52:27 -0700932 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
933 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700934
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 /**
936 * Provides a response to a request to change the current video session properties.
937 * <p>
938 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
939 * video call, could decline the request and keep the call as audio-only.
940 * In such a scenario, the {@code responseProfile} would have a video state of
941 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
942 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
943 * <p>
944 * Sent from the {@link InCallService} via
945 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
946 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
947 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 */
951 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
952
953 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
955 * <p>
956 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
957 * camera via
958 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
959 * <p>
960 * Sent from the {@link InCallService} via
961 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 */
963 public abstract void onRequestCameraCapabilities();
964
965 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
967 * video component of the current {@link Connection}.
968 * <p>
969 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
970 * via {@link VideoProvider#setCallDataUsage(long)}.
971 * <p>
972 * Sent from the {@link InCallService} via
973 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976
977 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700978 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
979 * the peer device when the video signal is paused.
980 * <p>
981 * Sent from the {@link InCallService} via
982 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 *
984 * @param uri URI of image to display.
985 */
Yorke Lee32f24732015-05-12 16:18:03 -0700986 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987
988 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700989 * Used to inform listening {@link InCallService} implementations when the
990 * {@link VideoProvider} receives a session modification request.
991 * <p>
992 * Received by the {@link InCallService} via
993 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700994 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700995 * @param videoProfile The requested video profile.
996 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997 */
998 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700999 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001000 for (IVideoCallback callback : mVideoCallbacks.values()) {
1001 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001002 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001003 } catch (RemoteException ignored) {
1004 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001005 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001006 }
1007 }
1008 }
1009
1010 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001011 * Used to inform listening {@link InCallService} implementations when the
1012 * {@link VideoProvider} receives a response to a session modification request.
1013 * <p>
1014 * Received by the {@link InCallService} via
1015 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1016 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 *
1018 * @param status Status of the session modify request. Valid values are
1019 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1020 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1022 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1023 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1024 * @param requestedProfile The original request which was sent to the peer device.
1025 * @param responseProfile The actual profile changes agreed to by the peer device.
1026 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 */
1028 public void receiveSessionModifyResponse(int status,
1029 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001030 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001031 for (IVideoCallback callback : mVideoCallbacks.values()) {
1032 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001033 callback.receiveSessionModifyResponse(status, requestedProfile,
1034 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001035 } catch (RemoteException ignored) {
1036 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001037 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 }
1039 }
1040 }
1041
1042 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * Used to inform listening {@link InCallService} implementations when the
1044 * {@link VideoProvider} reports a call session event.
1045 * <p>
1046 * Received by the {@link InCallService} via
1047 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1050 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1051 * {@link VideoProvider#SESSION_EVENT_TX_START},
1052 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1053 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1054 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001055 */
1056 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001057 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001058 for (IVideoCallback callback : mVideoCallbacks.values()) {
1059 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001060 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001061 } catch (RemoteException ignored) {
1062 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001063 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001064 }
1065 }
1066 }
1067
1068 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001069 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1070 * peer's video have changed.
1071 * <p>
1072 * This could occur if, for example, the peer rotates their device, changing the aspect
1073 * ratio of the video, or if the user switches between the back and front cameras.
1074 * <p>
1075 * Received by the {@link InCallService} via
1076 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 *
1078 * @param width The updated peer video width.
1079 * @param height The updated peer video height.
1080 */
1081 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001082 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001083 for (IVideoCallback callback : mVideoCallbacks.values()) {
1084 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001085 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001086 } catch (RemoteException ignored) {
1087 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001088 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 }
1090 }
1091 }
1092
1093 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001094 * Used to inform listening {@link InCallService} implementations when the data usage of the
1095 * video associated with the current {@link Connection} has changed.
1096 * <p>
1097 * This could be in response to a preview request via
1098 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001099 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1100 * 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 -07001101 * <p>
1102 * Received by the {@link InCallService} via
1103 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001104 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001105 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1106 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 */
Yorke Lee32f24732015-05-12 16:18:03 -07001108 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001109 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001110 for (IVideoCallback callback : mVideoCallbacks.values()) {
1111 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001112 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001113 } catch (RemoteException ignored) {
1114 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001115 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 }
1117 }
1118 }
1119
1120 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001121 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001122 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001123 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001124 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1125 * @hide
1126 */
1127 public void changeCallDataUsage(long dataUsage) {
1128 setCallDataUsage(dataUsage);
1129 }
1130
1131 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001132 * Used to inform listening {@link InCallService} implementations when the capabilities of
1133 * the current camera have changed.
1134 * <p>
1135 * The {@link VideoProvider} should call this in response to
1136 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1137 * changed via {@link VideoProvider#onSetCamera(String)}.
1138 * <p>
1139 * Received by the {@link InCallService} via
1140 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1141 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001142 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001143 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144 */
Yorke Lee400470f2015-05-12 13:31:25 -07001145 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001146 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001147 for (IVideoCallback callback : mVideoCallbacks.values()) {
1148 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001149 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001150 } catch (RemoteException ignored) {
1151 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001152 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 }
1154 }
1155 }
Rekha Kumar07366812015-03-24 16:42:31 -07001156
1157 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001158 * Used to inform listening {@link InCallService} implementations when the video quality
1159 * of the call has changed.
1160 * <p>
1161 * Received by the {@link InCallService} via
1162 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001163 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001164 * @param videoQuality The updated video quality. Valid values:
1165 * {@link VideoProfile#QUALITY_HIGH},
1166 * {@link VideoProfile#QUALITY_MEDIUM},
1167 * {@link VideoProfile#QUALITY_LOW},
1168 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001169 */
1170 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001171 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001172 for (IVideoCallback callback : mVideoCallbacks.values()) {
1173 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001174 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001175 } catch (RemoteException ignored) {
1176 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001177 }
Rekha Kumar07366812015-03-24 16:42:31 -07001178 }
1179 }
1180 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001181 }
1182
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001183 private final Listener mConnectionDeathListener = new Listener() {
1184 @Override
1185 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001186 if (mConferenceables.remove(c)) {
1187 fireOnConferenceableConnectionsChanged();
1188 }
1189 }
1190 };
1191
1192 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1193 @Override
1194 public void onDestroyed(Conference c) {
1195 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001196 fireOnConferenceableConnectionsChanged();
1197 }
1198 }
1199 };
1200
Jay Shrauner229e3822014-08-15 09:23:07 -07001201 /**
1202 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1203 * load factor before resizing, 1 means we only expect a single thread to
1204 * access the map so make only a single shard
1205 */
1206 private final Set<Listener> mListeners = Collections.newSetFromMap(
1207 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001208 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1209 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001210 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001211
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001212 // The internal telecom call ID associated with this connection.
1213 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001214 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001215 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001216 private Uri mAddress;
1217 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001218 private String mCallerDisplayName;
1219 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001220 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001221 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001222 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001224 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001225 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001226 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001227 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001228 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001229 private Conference mConference;
1230 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001231 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232
1233 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001234 * Tracks the key set for the extras bundle provided on the last invocation of
1235 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1236 * keys which were set previously but are no longer present in the replacement Bundle.
1237 */
1238 private Set<String> mPreviousExtraKeys;
1239
1240 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001241 * Create a new Connection.
1242 */
Santos Cordonf2951102014-07-20 19:06:29 -07001243 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001244
1245 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001246 * Returns the Telecom internal call ID associated with this connection. Should only be used
1247 * for debugging and tracing purposes.
1248 *
1249 * @return The Telecom call ID.
1250 * @hide
1251 */
1252 public final String getTelecomCallId() {
1253 return mTelecomCallId;
1254 }
1255
1256 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001257 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001258 */
Andrew Lee100e2932014-09-08 15:34:24 -07001259 public final Uri getAddress() {
1260 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001261 }
1262
1263 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001264 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001265 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001266 */
Andrew Lee100e2932014-09-08 15:34:24 -07001267 public final int getAddressPresentation() {
1268 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001269 }
1270
1271 /**
1272 * @return The caller display name (CNAP).
1273 */
1274 public final String getCallerDisplayName() {
1275 return mCallerDisplayName;
1276 }
1277
1278 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001279 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001280 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001281 */
1282 public final int getCallerDisplayNamePresentation() {
1283 return mCallerDisplayNamePresentation;
1284 }
1285
1286 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001287 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001288 */
1289 public final int getState() {
1290 return mState;
1291 }
1292
1293 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001294 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001295 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1296 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1297 * {@link VideoProfile#STATE_TX_ENABLED},
1298 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001299 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001300 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001301 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001302 */
1303 public final int getVideoState() {
1304 return mVideoState;
1305 }
1306
1307 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001308 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001309 * being routed by the system. This is {@code null} if this Connection
1310 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001311 * @deprecated Use {@link #getCallAudioState()} instead.
1312 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001313 */
Yorke Lee4af59352015-05-13 14:14:54 -07001314 @SystemApi
1315 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001317 if (mCallAudioState == null) {
1318 return null;
1319 }
Yorke Lee4af59352015-05-13 14:14:54 -07001320 return new AudioState(mCallAudioState);
1321 }
1322
1323 /**
1324 * @return The audio state of the connection, describing how its audio is currently
1325 * being routed by the system. This is {@code null} if this Connection
1326 * does not directly know about its audio state.
1327 */
1328 public final CallAudioState getCallAudioState() {
1329 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001330 }
1331
1332 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001333 * @return The conference that this connection is a part of. Null if it is not part of any
1334 * conference.
1335 */
1336 public final Conference getConference() {
1337 return mConference;
1338 }
1339
1340 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001341 * Returns whether this connection is requesting that the system play a ringback tone
1342 * on its behalf.
1343 */
Andrew Lee100e2932014-09-08 15:34:24 -07001344 public final boolean isRingbackRequested() {
1345 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001346 }
1347
1348 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001349 * @return True if the connection's audio mode is VOIP.
1350 */
1351 public final boolean getAudioModeIsVoip() {
1352 return mAudioModeIsVoip;
1353 }
1354
1355 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001356 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1357 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1358 * start time of the conference.
1359 *
1360 * @return The time at which the {@code Connnection} was connected.
1361 *
1362 * @hide
1363 */
1364 public final long getConnectTimeMillis() {
1365 return mConnectTimeMillis;
1366 }
1367
1368 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001369 * @return The status hints for this connection.
1370 */
1371 public final StatusHints getStatusHints() {
1372 return mStatusHints;
1373 }
1374
1375 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001376 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001377 * <p>
1378 * Extras should be updated using {@link #putExtras(Bundle)}.
1379 * <p>
1380 * Telecom or an {@link InCallService} can also update the extras via
1381 * {@link android.telecom.Call#putExtras(Bundle)}, and
1382 * {@link Call#removeExtras(List)}.
1383 * <p>
1384 * The connection is notified of changes to the extras made by Telecom or an
1385 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001386 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001387 * @return The extras associated with this connection.
1388 */
1389 public final Bundle getExtras() {
1390 return mExtras;
1391 }
1392
1393 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001394 * Assign a listener to be notified of state changes.
1395 *
1396 * @param l A listener.
1397 * @return This Connection.
1398 *
1399 * @hide
1400 */
1401 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001402 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001403 return this;
1404 }
1405
1406 /**
1407 * Remove a previously assigned listener that was being notified of state changes.
1408 *
1409 * @param l A Listener.
1410 * @return This Connection.
1411 *
1412 * @hide
1413 */
1414 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001415 if (l != null) {
1416 mListeners.remove(l);
1417 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001418 return this;
1419 }
1420
1421 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001422 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001423 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001424 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001425 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001426 }
1427
1428 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001429 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1430 * ONLY for debugging purposes.
1431 *
1432 * @param callId The telecom call ID.
1433 * @hide
1434 */
1435 public void setTelecomCallId(String callId) {
1436 mTelecomCallId = callId;
1437 }
1438
1439 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001440 * Inform this Connection that the state of its audio output has been changed externally.
1441 *
1442 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001443 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001444 */
Yorke Lee4af59352015-05-13 14:14:54 -07001445 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001446 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001447 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001448 mCallAudioState = state;
1449 onAudioStateChanged(getAudioState());
1450 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001451 }
1452
1453 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001455 * @return A string representation of the value.
1456 */
1457 public static String stateToString(int state) {
1458 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001460 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001462 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001463 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001464 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001466 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001468 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001469 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001470 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001472 return "DISCONNECTED";
1473 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001474 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 return "UNKNOWN";
1476 }
1477 }
1478
1479 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001480 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001481 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001482 public final int getConnectionCapabilities() {
1483 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001484 }
1485
1486 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001487 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1488 */
1489 public final int getConnectionProperties() {
1490 return mConnectionProperties;
1491 }
1492
1493 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001494 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001495 *
Andrew Lee100e2932014-09-08 15:34:24 -07001496 * @param address The new address.
1497 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001498 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001499 */
Andrew Lee100e2932014-09-08 15:34:24 -07001500 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001502 Log.d(this, "setAddress %s", address);
1503 mAddress = address;
1504 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001505 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001506 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001507 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001508 }
1509
1510 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001511 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001512 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001513 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001514 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001515 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001516 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001517 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001518 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001519 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001520 mCallerDisplayName = callerDisplayName;
1521 mCallerDisplayNamePresentation = presentation;
1522 for (Listener l : mListeners) {
1523 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1524 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001525 }
1526
1527 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001528 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001529 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1530 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1531 * {@link VideoProfile#STATE_TX_ENABLED},
1532 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001533 *
1534 * @param videoState The new video state.
1535 */
1536 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001537 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001538 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001539 mVideoState = videoState;
1540 for (Listener l : mListeners) {
1541 l.onVideoStateChanged(this, mVideoState);
1542 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001543 }
1544
1545 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001546 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001547 * communicate).
1548 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001549 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001550 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001551 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001553 }
1554
1555 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001556 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001557 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001558 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001559 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001561 }
1562
1563 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001564 * Sets state to initializing (this Connection is not yet ready to be used).
1565 */
1566 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001567 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001569 }
1570
1571 /**
1572 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1573 */
1574 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001575 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001576 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001577 }
1578
1579 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001580 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001581 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001582 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001583 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001584 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001585 }
1586
1587 /**
1588 * Sets state to be on hold.
1589 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001590 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001591 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001592 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001593 }
1594
1595 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001596 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001598 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001600 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001601 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001602 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001604 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001605 }
1606
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 public final VideoProvider getVideoProvider() {
1608 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001609 }
1610
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001611 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001612 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001613 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001614 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001616 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001617 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001618 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001619 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001621 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001622 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001623 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001624 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001625 }
1626
1627 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001628 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1629 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1630 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1631 * to send an {@link #onPostDialContinue(boolean)} signal.
1632 *
1633 * @param remaining The DTMF character sequence remaining to be emitted once the
1634 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1635 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001636 */
1637 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001638 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001639 for (Listener l : mListeners) {
1640 l.onPostDialWait(this, remaining);
1641 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001642 }
1643
1644 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001645 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1646 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001647 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001648 *
1649 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001650 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001651 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001652 checkImmutable();
1653 for (Listener l : mListeners) {
1654 l.onPostDialChar(this, nextChar);
1655 }
1656 }
1657
1658 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001659 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001660 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001661 *
1662 * @param ringback Whether the ringback tone is to be played.
1663 */
Andrew Lee100e2932014-09-08 15:34:24 -07001664 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001665 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001666 if (mRingbackRequested != ringback) {
1667 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001668 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001669 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001670 }
1671 }
Ihab Awadf8358972014-05-28 16:46:42 -07001672 }
1673
1674 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001675 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001676 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001678 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001679 public final void setConnectionCapabilities(int connectionCapabilities) {
1680 checkImmutable();
1681 if (mConnectionCapabilities != connectionCapabilities) {
1682 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001683 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001684 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001685 }
1686 }
Santos Cordonb6939982014-06-04 20:20:58 -07001687 }
1688
1689 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001690 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1691 *
1692 * @param connectionProperties The new connection properties.
1693 */
1694 public final void setConnectionProperties(int connectionProperties) {
1695 checkImmutable();
1696 if (mConnectionProperties != connectionProperties) {
1697 mConnectionProperties = connectionProperties;
1698 for (Listener l : mListeners) {
1699 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1700 }
1701 }
1702 }
1703
1704 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001705 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001706 */
Evan Charlton36a71342014-07-19 16:31:02 -07001707 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001708 for (Listener l : mListeners) {
1709 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001710 }
Santos Cordonb6939982014-06-04 20:20:58 -07001711 }
1712
1713 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001714 * Requests that the framework use VOIP audio mode for this connection.
1715 *
1716 * @param isVoip True if the audio mode is VOIP.
1717 */
1718 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001719 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001720 mAudioModeIsVoip = isVoip;
1721 for (Listener l : mListeners) {
1722 l.onAudioModeIsVoipChanged(this, isVoip);
1723 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001724 }
1725
1726 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001727 * Sets the time at which a call became active on this Connection. This is set only
1728 * when a conference call becomes active on this connection.
1729 *
1730 * @param connectionTimeMillis The connection time, in milliseconds.
1731 *
1732 * @hide
1733 */
1734 public final void setConnectTimeMillis(long connectTimeMillis) {
1735 mConnectTimeMillis = connectTimeMillis;
1736 }
1737
1738 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001739 * Sets the label and icon status to display in the in-call UI.
1740 *
1741 * @param statusHints The status label and icon to set.
1742 */
1743 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001744 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001745 mStatusHints = statusHints;
1746 for (Listener l : mListeners) {
1747 l.onStatusHintsChanged(this, statusHints);
1748 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001749 }
1750
1751 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001752 * Sets the connections with which this connection can be conferenced.
1753 *
1754 * @param conferenceableConnections The set of connections this connection can conference with.
1755 */
1756 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001757 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001758 clearConferenceableList();
1759 for (Connection c : conferenceableConnections) {
1760 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1761 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001762 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001763 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001764 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001765 }
1766 }
1767 fireOnConferenceableConnectionsChanged();
1768 }
1769
1770 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001771 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1772 * or conferences with which this connection can be conferenced.
1773 *
1774 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001775 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001776 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001777 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001778 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001779 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1780 // small amount of items here.
1781 if (!mConferenceables.contains(c)) {
1782 if (c instanceof Connection) {
1783 Connection connection = (Connection) c;
1784 connection.addConnectionListener(mConnectionDeathListener);
1785 } else if (c instanceof Conference) {
1786 Conference conference = (Conference) c;
1787 conference.addListener(mConferenceDeathListener);
1788 }
1789 mConferenceables.add(c);
1790 }
1791 }
1792 fireOnConferenceableConnectionsChanged();
1793 }
1794
1795 /**
1796 * Returns the connections or conferences with which this connection can be conferenced.
1797 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001798 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001799 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001800 }
1801
Yorke Lee53463962015-08-04 16:07:19 -07001802 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001803 * @hide
1804 */
1805 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001806 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001807 if (mConnectionService != null) {
1808 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1809 "which is already associated with another ConnectionService.");
1810 } else {
1811 mConnectionService = connectionService;
1812 }
1813 }
1814
1815 /**
1816 * @hide
1817 */
1818 public final void unsetConnectionService(ConnectionService connectionService) {
1819 if (mConnectionService != connectionService) {
1820 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1821 "that does not belong to the ConnectionService.");
1822 } else {
1823 mConnectionService = null;
1824 }
1825 }
1826
1827 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001828 * @hide
1829 */
1830 public final ConnectionService getConnectionService() {
1831 return mConnectionService;
1832 }
1833
1834 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001835 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001836 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001837 *
1838 * @param conference The conference.
1839 * @return {@code true} if the conference was successfully set.
1840 * @hide
1841 */
1842 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001843 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001844 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001845 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001846 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001847 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1848 fireConferenceChanged();
1849 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001850 return true;
1851 }
1852 return false;
1853 }
1854
1855 /**
1856 * Resets the conference that this connection is a part of.
1857 * @hide
1858 */
1859 public final void resetConference() {
1860 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001861 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001862 mConference = null;
1863 fireConferenceChanged();
1864 }
1865 }
1866
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001867 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001868 * Set some extras that can be associated with this {@code Connection}.
1869 * <p>
1870 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1871 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1872 * <p>
1873 * 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 -07001874 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1875 *
1876 * @param extras The extras associated with this {@code Connection}.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001877 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1878 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001879 */
1880 public final void setExtras(@Nullable Bundle extras) {
1881 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001882
1883 // Add/replace any new or changed extras values.
1884 putExtras(extras);
1885
1886 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1887 // the current one and remove any keys that went away.
1888 if (mPreviousExtraKeys != null) {
1889 List<String> toRemove = new ArrayList<String>();
1890 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001891 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001892 toRemove.add(oldKey);
1893 }
1894 }
1895 if (!toRemove.isEmpty()) {
1896 removeExtras(toRemove);
1897 }
1898 }
1899
1900 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1901 // called we can see if the caller has removed any extras values.
1902 if (mPreviousExtraKeys == null) {
1903 mPreviousExtraKeys = new ArraySet<String>();
1904 }
1905 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07001906 if (extras != null) {
1907 mPreviousExtraKeys.addAll(extras.keySet());
1908 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001909 }
1910
1911 /**
1912 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1913 * added.
1914 * <p>
1915 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1916 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1917 *
1918 * @param extras The extras to add.
1919 */
1920 public final void putExtras(@NonNull Bundle extras) {
1921 checkImmutable();
1922 if (extras == null) {
1923 return;
1924 }
1925
1926 if (mExtras == null) {
1927 mExtras = new Bundle();
1928 }
1929 mExtras.putAll(extras);
1930
Santos Cordon6b7f9552015-05-27 17:21:45 -07001931 for (Listener l : mListeners) {
1932 l.onExtrasChanged(this, extras);
1933 }
1934 }
1935
1936 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001937 * Adds a boolean extra to this {@code Connection}.
1938 *
1939 * @param key The extra key.
1940 * @param value The value.
1941 * @hide
1942 */
1943 public final void putExtra(String key, boolean value) {
1944 Bundle newExtras = new Bundle();
1945 newExtras.putBoolean(key, value);
1946 putExtras(newExtras);
1947 }
1948
1949 /**
1950 * Adds an integer extra to this {@code Connection}.
1951 *
1952 * @param key The extra key.
1953 * @param value The value.
1954 * @hide
1955 */
1956 public final void putExtra(String key, int value) {
1957 Bundle newExtras = new Bundle();
1958 newExtras.putInt(key, value);
1959 putExtras(newExtras);
1960 }
1961
1962 /**
1963 * Adds a string extra to this {@code Connection}.
1964 *
1965 * @param key The extra key.
1966 * @param value The value.
1967 * @hide
1968 */
1969 public final void putExtra(String key, String value) {
1970 Bundle newExtras = new Bundle();
1971 newExtras.putString(key, value);
1972 putExtras(newExtras);
1973 }
1974
1975 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001976 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001977 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07001978 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07001979 */
1980 public final void removeExtras(List<String> keys) {
1981 if (mExtras != null) {
1982 for (String key : keys) {
1983 mExtras.remove(key);
1984 }
1985
1986 if (mExtras.size() == 0) {
1987 mExtras = null;
1988 }
1989 }
1990
1991 for (Listener l : mListeners) {
1992 l.onExtrasRemoved(this, keys);
1993 }
1994 }
1995
1996 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001997 * Removes extras from this {@code Connection}.
1998 *
1999 * @param keys The keys of the extras to remove.
2000 */
2001 public final void removeExtras(String ... keys) {
2002 removeExtras(Arrays.asList(keys));
2003 }
2004
2005 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002006 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002007 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002008 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002009 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2010 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002011 */
Yorke Lee4af59352015-05-13 14:14:54 -07002012 @SystemApi
2013 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002014 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002015
2016 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002017 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2018 *
2019 * @param state The new connection audio state.
2020 */
2021 public void onCallAudioStateChanged(CallAudioState state) {}
2022
2023 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002024 * Notifies this Connection of an internal state change. This method is called after the
2025 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002026 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002027 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002028 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002029 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002030
2031 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002032 * Notifies this Connection of a request to play a DTMF tone.
2033 *
2034 * @param c A DTMF character.
2035 */
Santos Cordonf2951102014-07-20 19:06:29 -07002036 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002037
2038 /**
2039 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2040 */
Santos Cordonf2951102014-07-20 19:06:29 -07002041 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002042
2043 /**
2044 * Notifies this Connection of a request to disconnect.
2045 */
Santos Cordonf2951102014-07-20 19:06:29 -07002046 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047
2048 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002049 * Notifies this Connection of a request to disconnect a participant of the conference managed
2050 * by the connection.
2051 *
2052 * @param endpoint the {@link Uri} of the participant to disconnect.
2053 * @hide
2054 */
2055 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2056
2057 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002058 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002059 */
Santos Cordonf2951102014-07-20 19:06:29 -07002060 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002061
2062 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002063 * Notifies this Connection of a request to abort.
2064 */
Santos Cordonf2951102014-07-20 19:06:29 -07002065 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002066
2067 /**
2068 * Notifies this Connection of a request to hold.
2069 */
Santos Cordonf2951102014-07-20 19:06:29 -07002070 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002071
2072 /**
2073 * Notifies this Connection of a request to exit a hold state.
2074 */
Santos Cordonf2951102014-07-20 19:06:29 -07002075 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076
2077 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002079 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002080 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002081 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002082 */
Santos Cordonf2951102014-07-20 19:06:29 -07002083 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084
2085 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002086 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002087 * a request to accept.
2088 */
2089 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002090 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002091 }
2092
2093 /**
2094 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002095 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002096 */
Santos Cordonf2951102014-07-20 19:06:29 -07002097 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002099 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002100 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2101 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002102 */
2103 public void onReject(String replyMessage) {}
2104
2105 /**
Bryce Leecac50772015-11-17 15:13:29 -08002106 * Notifies the Connection of a request to silence the ringer.
2107 *
2108 * @hide
2109 */
2110 public void onSilence() {}
2111
2112 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002113 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2114 */
Santos Cordonf2951102014-07-20 19:06:29 -07002115 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002116
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002117 /**
2118 * Notifies this Connection of a request to pull an external call to the local device.
2119 * <p>
2120 * The {@link InCallService} issues a request to pull an external call to the local device via
2121 * {@link Call#pullExternalCall()}.
2122 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002123 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2124 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002125 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002126 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002127 */
2128 public void onPullExternalCall() {}
2129
2130 /**
2131 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2132 * <p>
2133 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2134 * <p>
2135 * See also {@link Call#sendCallEvent(String, Bundle)}.
2136 *
2137 * @param event The call event.
2138 * @param extras Extras associated with the call event.
2139 */
2140 public void onCallEvent(String event, Bundle extras) {}
2141
Tyler Gunndee56a82016-03-23 16:06:34 -07002142 /**
2143 * Notifies this {@link Connection} of a change to the extras made outside the
2144 * {@link ConnectionService}.
2145 * <p>
2146 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2147 * the {@link android.telecom.Call#putExtras(Bundle)} and
2148 * {@link Call#removeExtras(List)}.
2149 *
2150 * @param extras The new extras bundle.
2151 */
2152 public void onExtrasChanged(Bundle extras) {}
2153
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002154 static String toLogSafePhoneNumber(String number) {
2155 // For unknown number, log empty string.
2156 if (number == null) {
2157 return "";
2158 }
2159
2160 if (PII_DEBUG) {
2161 // When PII_DEBUG is true we emit PII.
2162 return number;
2163 }
2164
2165 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2166 // sanitized phone numbers.
2167 StringBuilder builder = new StringBuilder();
2168 for (int i = 0; i < number.length(); i++) {
2169 char c = number.charAt(i);
2170 if (c == '-' || c == '@' || c == '.') {
2171 builder.append(c);
2172 } else {
2173 builder.append('x');
2174 }
2175 }
2176 return builder.toString();
2177 }
2178
Ihab Awad542e0ea2014-05-16 10:22:16 -07002179 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002180 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002181 if (mState == STATE_DISCONNECTED && mState != state) {
2182 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002183 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002184 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002185 if (mState != state) {
2186 Log.d(this, "setState: %s", stateToString(state));
2187 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002188 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002189 for (Listener l : mListeners) {
2190 l.onStateChanged(this, state);
2191 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002192 }
2193 }
2194
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002195 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002196 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002197 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2198 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002199 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002200 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201
2202 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002203 if (mImmutable) {
2204 throw new UnsupportedOperationException("Connection is immutable");
2205 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002206 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002207 }
2208
Evan Charltonbf11f982014-07-20 22:06:28 -07002209 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002210 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002211 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2212 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002213 * <p>
2214 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2215 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002216 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002217 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002218 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002219 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002220 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2221 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002222 }
2223
Evan Charltonbf11f982014-07-20 22:06:28 -07002224 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002225 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2226 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2227 * this should never be un-@hide-den.
2228 *
2229 * @hide
2230 */
2231 public void checkImmutable() {}
2232
2233 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002234 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2235 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2236 * that state. This connection should not be used for anything, and no other
2237 * {@code Connection}s should be attempted.
2238 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002239 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002240 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002241 * @return A {@code Connection} which indicates that the underlying connection should
2242 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002243 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002244 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002245 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002246 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002247
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002248 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002249 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002250 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002251 }
2252 }
2253
Santos Cordon823fd3c2014-08-07 18:35:18 -07002254 private final void fireConferenceChanged() {
2255 for (Listener l : mListeners) {
2256 l.onConferenceChanged(this, mConference);
2257 }
2258 }
2259
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002260 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002261 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002262 if (c instanceof Connection) {
2263 Connection connection = (Connection) c;
2264 connection.removeConnectionListener(mConnectionDeathListener);
2265 } else if (c instanceof Conference) {
2266 Conference conference = (Conference) c;
2267 conference.removeListener(mConferenceDeathListener);
2268 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002269 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002270 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002271 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002272
2273 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002274 * Handles a change to extras received from Telecom.
2275 *
2276 * @param extras The new extras.
2277 * @hide
2278 */
2279 final void handleExtrasChanged(Bundle extras) {
2280 mExtras = extras;
2281 onExtrasChanged(mExtras);
2282 }
2283
2284 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002285 * Notifies listeners that the merge request failed.
2286 *
2287 * @hide
2288 */
2289 protected final void notifyConferenceMergeFailed() {
2290 for (Listener l : mListeners) {
2291 l.onConferenceMergeFailed(this);
2292 }
2293 }
2294
2295 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002296 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002297 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002298 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002299 * @hide
2300 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002301 protected final void updateConferenceParticipants(
2302 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002303 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002304 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002305 }
2306 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002307
2308 /**
2309 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002310 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002311 */
2312 protected void notifyConferenceStarted() {
2313 for (Listener l : mListeners) {
2314 l.onConferenceStarted();
2315 }
2316 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002317
2318 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002319 * Sends an event associated with this {@code Connection}, with associated event extras.
2320 *
2321 * Events are exposed to {@link InCallService} implementations via the
2322 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2323 *
2324 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2325 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002326 *
2327 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002328 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002329 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002330 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002331 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002332 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002333 }
2334 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002335}