blob: 310c957c94faaa13e385cde118e39a4911e9b284 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.os.Handler;
30import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070031import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Message;
33import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070034import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070041import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
43/**
Santos Cordon895d4b82015-06-25 16:41:48 -070044 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
45 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070046 * <p>
47 * Implementations create a custom subclass of {@code Connection} and return it to the framework
48 * as the return value of
49 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
50 * or
51 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
52 * Implementations are then responsible for updating the state of the {@code Connection}, and
53 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
54 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070055 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070056public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070057
Santos Cordon895d4b82015-06-25 16:41:48 -070058 /**
59 * The connection is initializing. This is generally the first state for a {@code Connection}
60 * returned by a {@link ConnectionService}.
61 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 public static final int STATE_INITIALIZING = 0;
63
Santos Cordon895d4b82015-06-25 16:41:48 -070064 /**
65 * The connection is new and not connected.
66 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070067 public static final int STATE_NEW = 1;
68
Santos Cordon895d4b82015-06-25 16:41:48 -070069 /**
70 * An incoming connection is in the ringing state. During this state, the user's ringer or
71 * vibration feature will be activated.
72 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070073 public static final int STATE_RINGING = 2;
74
Santos Cordon895d4b82015-06-25 16:41:48 -070075 /**
76 * An outgoing connection is in the dialing state. In this state the other party has not yet
77 * answered the call and the user traditionally hears a ringback tone.
78 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 public static final int STATE_DIALING = 3;
80
Santos Cordon895d4b82015-06-25 16:41:48 -070081 /**
82 * A connection is active. Both parties are connected to the call and can actively communicate.
83 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 public static final int STATE_ACTIVE = 4;
85
Santos Cordon895d4b82015-06-25 16:41:48 -070086 /**
87 * A connection is on hold.
88 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 public static final int STATE_HOLDING = 5;
90
Santos Cordon895d4b82015-06-25 16:41:48 -070091 /**
92 * A connection has been disconnected. This is the final state once the user has been
93 * disconnected from a call either locally, remotely or by an error in the service.
94 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070095 public static final int STATE_DISCONNECTED = 6;
96
Santos Cordon895d4b82015-06-25 16:41:48 -070097 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070098 * The state of an external connection which is in the process of being pulled from a remote
99 * device to the local device.
100 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700101 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700102 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
103 */
104 public static final int STATE_PULLING_CALL = 7;
105
106 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 * Connection can currently be put on hold or unheld. This is distinct from
108 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
109 * it does not at the moment support the function. This can be true while the call is in the
110 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
111 * display a disabled 'hold' button.
112 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113 public static final int CAPABILITY_HOLD = 0x00000001;
114
115 /** Connection supports the hold feature. */
116 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
117
118 /**
119 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
120 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
121 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
122 * capability allows a merge button to be shown while the conference is in the foreground
123 * of the in-call UI.
124 * <p>
125 * This is only intended for use by a {@link Conference}.
126 */
127 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
128
129 /**
130 * Connections within a conference can be swapped between foreground and background.
131 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
132 * <p>
133 * This is only intended for use by a {@link Conference}.
134 */
135 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
136
137 /**
138 * @hide
139 */
140 public static final int CAPABILITY_UNUSED = 0x00000010;
141
142 /** Connection supports responding via text option. */
143 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
144
145 /** Connection can be muted. */
146 public static final int CAPABILITY_MUTE = 0x00000040;
147
148 /**
149 * Connection supports conference management. This capability only applies to
150 * {@link Conference}s which can have {@link Connection}s as children.
151 */
152 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
153
154 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700155 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700157 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700162 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800163
164 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700165 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800166 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700167 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700168 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800169
170 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800172 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700173 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
174
175 /**
176 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700177 */
178 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
179
180 /**
181 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700183 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700184 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800185
186 /**
187 * Connection is able to be separated from its parent {@code Conference}, if any.
188 */
189 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
190
191 /**
192 * Connection is able to be individually disconnected when in a {@code Conference}.
193 */
194 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
195
196 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700197 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 * @hide
199 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700200 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700203 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * @hide
205 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700206 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207
208 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700209 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 * @hide
211 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700212 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213
Tyler Gunn068085b2015-02-06 13:56:52 -0800214 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700215 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800216 * @hide
217 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700218 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800219
Tyler Gunn96d6c402015-03-18 12:39:23 -0700220 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500221 * Speed up audio setup for MT call.
222 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700223 */
224 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800225
Rekha Kumar07366812015-03-24 16:42:31 -0700226 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700227 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700228 */
229 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
230
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700231 /**
232 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700233 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700234 */
235 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
236
Tyler Gunnd4091732015-06-29 09:15:37 -0700237 /**
238 * For a conference, indicates the conference will not have child connections.
239 * <p>
240 * An example of a conference with child connections is a GSM conference call, where the radio
241 * retains connections to the individual participants of the conference. Another example is an
242 * IMS conference call where conference event package functionality is supported; in this case
243 * the conference server ensures the radio is aware of the participants in the conference, which
244 * are represented by child connections.
245 * <p>
246 * An example of a conference with no child connections is an IMS conference call with no
247 * conference event package support. Such a conference is represented by the radio as a single
248 * connection to the IMS conference server.
249 * <p>
250 * Indicating whether a conference has children or not is important to help user interfaces
251 * visually represent a conference. A conference with no children, for example, will have the
252 * conference connection shown in the list of calls on a Bluetooth device, where if the
253 * conference has children, only the children will be shown in the list of calls on a Bluetooth
254 * device.
255 * @hide
256 */
257 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
258
Bryce Lee81901682015-08-28 16:38:02 -0700259 /**
260 * Indicates that the connection itself wants to handle any sort of reply response, rather than
261 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700262 */
263 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
264
Tyler Gunnf97a0092016-01-19 15:59:34 -0800265 /**
266 * When set, prevents a video call from being downgraded to an audio-only call.
267 * <p>
268 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
269 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
270 * downgraded from a video call back to a VideoState of
271 * {@link VideoProfile#STATE_AUDIO_ONLY}.
272 * <p>
273 * Intuitively, a call which can be downgraded to audio should also have local and remote
274 * video
275 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
276 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
277 */
278 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
279
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700280 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700281 * When set for an external connection, indicates that this {@code Connection} can be pulled
282 * from a remote device to the current device.
283 * <p>
284 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
285 * is set.
286 */
287 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
288
289 //**********************************************************************************************
290 // Next CAPABILITY value: 0x02000000
291 //**********************************************************************************************
292
293 /**
294 * Indicates that the current device callback number should be shown.
295 *
296 * @hide
297 */
298 public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
299
300 /**
301 * Whether the call is a generic conference, where we do not know the precise state of
302 * participants in the conference (eg. on CDMA).
303 *
304 * @hide
305 */
306 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
307
308 /**
309 * Connection is using high definition audio.
310 * @hide
311 */
312 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
313
314 /**
315 * Connection is using WIFI.
316 * @hide
317 */
318 public static final int PROPERTY_WIFI = 1<<3;
319
320 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700321 * When set, indicates that the {@code Connection} does not actually exist locally for the
322 * {@link ConnectionService}.
323 * <p>
324 * Consider, for example, a scenario where a user has two devices with the same phone number.
325 * When a user places a call on one devices, the telephony stack can represent that call on the
326 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700327 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700328 * <p>
329 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
330 * external connections. Only those {@link InCallService}s which have the
331 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
332 * manifest will see external connections.
333 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700334 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700335
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700336
Tyler Gunn96d6c402015-03-18 12:39:23 -0700337 //**********************************************************************************************
Tyler Gunn720c6642016-03-22 09:02:47 -0700338 // Next PROPERTY value: 1<<5
Tyler Gunn96d6c402015-03-18 12:39:23 -0700339 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800340
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700341 /**
342 * Connection extra key used to store the last forwarded number associated with the current
343 * connection. Used to communicate to the user interface that the connection was forwarded via
344 * the specified number.
345 */
346 public static final String EXTRA_LAST_FORWARDED_NUMBER =
347 "android.telecom.extra.LAST_FORWARDED_NUMBER";
348
349 /**
350 * Connection extra key used to store a child number associated with the current connection.
351 * Used to communicate to the user interface that the connection was received via
352 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
353 * address.
354 */
355 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
356
357 /**
358 * Connection extra key used to store the subject for an incoming call. The user interface can
359 * query this extra and display its contents for incoming calls. Will only be used if the
360 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
361 */
362 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
363
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800364 /**
365 * Connection event used to inform Telecom that it should play the on hold tone. This is used
366 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
367 * {@link #sendConnectionEvent(String)}.
368 * @hide
369 */
370 public static final String EVENT_ON_HOLD_TONE_START =
371 "android.telecom.event.ON_HOLD_TONE_START";
372
373 /**
374 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
375 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
376 * {@link #sendConnectionEvent(String)}.
377 * @hide
378 */
379 public static final String EVENT_ON_HOLD_TONE_END =
380 "android.telecom.event.ON_HOLD_TONE_END";
381
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382 /**
383 * Connection event used to inform {@link InCallService}s when pulling of an external call has
384 * failed. The user interface should inform the user of the error.
385 * <p>
386 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
387 * API is called on a {@link Call} with the properties
388 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
389 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
390 * pull the external call due to an error condition.
391 */
392 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
393
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700394 // Flag controlling whether PII is emitted into the logs
395 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
396
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800397 /**
398 * Whether the given capabilities support the specified capability.
399 *
400 * @param capabilities A capability bit field.
401 * @param capability The capability to check capabilities for.
402 * @return Whether the specified capability is supported.
403 * @hide
404 */
405 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800406 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800407 }
408
409 /**
410 * Whether the capabilities of this {@code Connection} supports the specified capability.
411 *
412 * @param capability The capability to check capabilities for.
413 * @return Whether the specified capability is supported.
414 * @hide
415 */
416 public boolean can(int capability) {
417 return can(mConnectionCapabilities, capability);
418 }
419
420 /**
421 * Removes the specified capability from the set of capabilities of this {@code Connection}.
422 *
423 * @param capability The capability to remove from the set.
424 * @hide
425 */
426 public void removeCapability(int capability) {
427 mConnectionCapabilities &= ~capability;
428 }
429
430 /**
431 * Adds the specified capability to the set of capabilities of this {@code Connection}.
432 *
433 * @param capability The capability to add to the set.
434 * @hide
435 */
436 public void addCapability(int capability) {
437 mConnectionCapabilities |= capability;
438 }
439
440
441 public static String capabilitiesToString(int capabilities) {
442 StringBuilder builder = new StringBuilder();
443 builder.append("[Capabilities:");
444 if (can(capabilities, CAPABILITY_HOLD)) {
445 builder.append(" CAPABILITY_HOLD");
446 }
447 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
448 builder.append(" CAPABILITY_SUPPORT_HOLD");
449 }
450 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
451 builder.append(" CAPABILITY_MERGE_CONFERENCE");
452 }
453 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
454 builder.append(" CAPABILITY_SWAP_CONFERENCE");
455 }
456 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
457 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
458 }
459 if (can(capabilities, CAPABILITY_MUTE)) {
460 builder.append(" CAPABILITY_MUTE");
461 }
462 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
463 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
464 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700465 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
466 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
467 }
468 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
469 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
470 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700471 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
472 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800473 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700474 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
475 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
476 }
477 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
478 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
479 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700480 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
481 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800482 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800483 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
484 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
485 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500486 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700487 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500488 }
Rekha Kumar07366812015-03-24 16:42:31 -0700489 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
490 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
491 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700492 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
493 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
494 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700495 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
496 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
497 }
Bryce Lee81901682015-08-28 16:38:02 -0700498 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
499 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
500 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700501 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
502 builder.append(" CAPABILITY_CAN_PULL_CALL");
503 }
Bryce Lee81901682015-08-28 16:38:02 -0700504
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800505 builder.append("]");
506 return builder.toString();
507 }
508
Tyler Gunn720c6642016-03-22 09:02:47 -0700509 public static String propertiesToString(int properties) {
510 StringBuilder builder = new StringBuilder();
511 builder.append("[Properties:");
512
513 if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
514 builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
515 }
516
517 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
518 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
519 }
520
521 if (can(properties, PROPERTY_WIFI)) {
522 builder.append(" PROPERTY_WIFI");
523 }
524
525 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
526 builder.append(" PROPERTY_GENERIC_CONFERENCE");
527 }
528
529 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
530 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
531 }
532
533 builder.append("]");
534 return builder.toString();
535 }
536
Sailesh Nepal091768c2014-06-30 15:15:23 -0700537 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700538 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700539 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700540 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700541 public void onCallerDisplayNameChanged(
542 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700543 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700544 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700545 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800546 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700547 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700548 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800549 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700550 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 public void onVideoProviderChanged(
552 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700553 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
554 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800555 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700556 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700557 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700558 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800559 public void onConferenceParticipantsChanged(Connection c,
560 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800561 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700562 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700563 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700564 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700565 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700566 }
567
Tyler Gunnb702ef82015-05-29 11:51:53 -0700568 /**
569 * Provides a means of controlling the video session associated with a {@link Connection}.
570 * <p>
571 * Implementations create a custom subclass of {@link VideoProvider} and the
572 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
573 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
574 * should set the {@link VideoProvider}.
575 * <p>
576 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
577 * {@link InCallService} implementations to issue requests related to the video session;
578 * it provides a means for the {@link ConnectionService} to report events and information
579 * related to the video session to Telecom and the {@link InCallService} implementations.
580 * <p>
581 * {@link InCallService} implementations interact with the {@link VideoProvider} via
582 * {@link android.telecom.InCallService.VideoCall}.
583 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700584 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700585
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700586 /**
587 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700588 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700589 */
590 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700591
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700592 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700593 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
594 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595 */
596 public static final int SESSION_EVENT_RX_RESUME = 2;
597
598 /**
599 * Video transmission has begun. This occurs after a negotiated start of video transmission
600 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700601 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700602 */
603 public static final int SESSION_EVENT_TX_START = 3;
604
605 /**
606 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
607 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700608 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 */
610 public static final int SESSION_EVENT_TX_STOP = 4;
611
612 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700613 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
614 * this as a cue to inform the user the camera is not available.
615 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700616 */
617 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
618
619 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700620 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
621 * for operation. The {@link InCallService} can use this as a cue to inform the user that
622 * the camera has become available again.
623 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 */
625 public static final int SESSION_EVENT_CAMERA_READY = 6;
626
627 /**
628 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700629 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 */
631 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
632
633 /**
634 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700635 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 */
637 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
638
639 /**
640 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700641 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 */
643 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
644
Rekha Kumar07366812015-03-24 16:42:31 -0700645 /**
646 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700647 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700648 */
649 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
650
651 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700652 * Session modify request rejected by remote user.
653 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700654 */
655 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
656
Tyler Gunn75958422015-04-15 14:23:42 -0700657 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 private static final int MSG_SET_CAMERA = 2;
659 private static final int MSG_SET_PREVIEW_SURFACE = 3;
660 private static final int MSG_SET_DISPLAY_SURFACE = 4;
661 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
662 private static final int MSG_SET_ZOOM = 6;
663 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
664 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
665 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800666 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700668 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700670 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700671 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700672
673 /**
674 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700675 *
676 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
677 * load factor before resizing, 1 means we only expect a single thread to
678 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700679 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700680 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
681 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682
683 /**
684 * Default handler used to consolidate binder method calls onto a single thread.
685 */
686 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700687 public VideoProviderHandler() {
688 super();
689 }
690
691 public VideoProviderHandler(Looper looper) {
692 super(looper);
693 }
694
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700695 @Override
696 public void handleMessage(Message msg) {
697 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700698 case MSG_ADD_VIDEO_CALLBACK: {
699 IBinder binder = (IBinder) msg.obj;
700 IVideoCallback callback = IVideoCallback.Stub
701 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700702 if (callback == null) {
703 Log.w(this, "addVideoProvider - skipped; callback is null.");
704 break;
705 }
706
Tyler Gunn75958422015-04-15 14:23:42 -0700707 if (mVideoCallbacks.containsKey(binder)) {
708 Log.i(this, "addVideoProvider - skipped; already present.");
709 break;
710 }
711 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700713 }
714 case MSG_REMOVE_VIDEO_CALLBACK: {
715 IBinder binder = (IBinder) msg.obj;
716 IVideoCallback callback = IVideoCallback.Stub
717 .asInterface((IBinder) msg.obj);
718 if (!mVideoCallbacks.containsKey(binder)) {
719 Log.i(this, "removeVideoProvider - skipped; not present.");
720 break;
721 }
722 mVideoCallbacks.remove(binder);
723 break;
724 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 case MSG_SET_CAMERA:
726 onSetCamera((String) msg.obj);
727 break;
728 case MSG_SET_PREVIEW_SURFACE:
729 onSetPreviewSurface((Surface) msg.obj);
730 break;
731 case MSG_SET_DISPLAY_SURFACE:
732 onSetDisplaySurface((Surface) msg.obj);
733 break;
734 case MSG_SET_DEVICE_ORIENTATION:
735 onSetDeviceOrientation(msg.arg1);
736 break;
737 case MSG_SET_ZOOM:
738 onSetZoom((Float) msg.obj);
739 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700740 case MSG_SEND_SESSION_MODIFY_REQUEST: {
741 SomeArgs args = (SomeArgs) msg.obj;
742 try {
743 onSendSessionModifyRequest((VideoProfile) args.arg1,
744 (VideoProfile) args.arg2);
745 } finally {
746 args.recycle();
747 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700749 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 case MSG_SEND_SESSION_MODIFY_RESPONSE:
751 onSendSessionModifyResponse((VideoProfile) msg.obj);
752 break;
753 case MSG_REQUEST_CAMERA_CAPABILITIES:
754 onRequestCameraCapabilities();
755 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800756 case MSG_REQUEST_CONNECTION_DATA_USAGE:
757 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700758 break;
759 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700760 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 break;
762 default:
763 break;
764 }
765 }
766 }
767
768 /**
769 * IVideoProvider stub implementation.
770 */
771 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700772 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700774 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
775 }
776
777 public void removeVideoCallback(IBinder videoCallbackBinder) {
778 mMessageHandler.obtainMessage(
779 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700780 }
781
782 public void setCamera(String cameraId) {
783 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
784 }
785
786 public void setPreviewSurface(Surface surface) {
787 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
788 }
789
790 public void setDisplaySurface(Surface surface) {
791 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
792 }
793
794 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700795 mMessageHandler.obtainMessage(
796 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700797 }
798
799 public void setZoom(float value) {
800 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
801 }
802
Tyler Gunn45382162015-05-06 08:52:27 -0700803 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
804 SomeArgs args = SomeArgs.obtain();
805 args.arg1 = fromProfile;
806 args.arg2 = toProfile;
807 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 }
809
810 public void sendSessionModifyResponse(VideoProfile responseProfile) {
811 mMessageHandler.obtainMessage(
812 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
813 }
814
815 public void requestCameraCapabilities() {
816 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
817 }
818
819 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800820 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 }
822
Yorke Lee32f24732015-05-12 16:18:03 -0700823 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700824 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
825 }
826 }
827
828 public VideoProvider() {
829 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700830 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700831 }
832
833 /**
834 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
835 *
836 * @param looper The looper.
837 * @hide
838 */
839 public VideoProvider(Looper looper) {
840 mBinder = new VideoProvider.VideoProviderBinder();
841 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700842 }
843
844 /**
845 * Returns binder object which can be used across IPC methods.
846 * @hide
847 */
848 public final IVideoProvider getInterface() {
849 return mBinder;
850 }
851
852 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700853 * Sets the camera to be used for the outgoing video.
854 * <p>
855 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
856 * camera via
857 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
858 * <p>
859 * Sent from the {@link InCallService} via
860 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700861 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * @param cameraId The id of the camera (use ids as reported by
863 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700864 */
865 public abstract void onSetCamera(String cameraId);
866
867 /**
868 * Sets the surface to be used for displaying a preview of what the user's camera is
869 * currently capturing. When video transmission is enabled, this is the video signal which
870 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700871 * <p>
872 * Sent from the {@link InCallService} via
873 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700874 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700875 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876 */
877 public abstract void onSetPreviewSurface(Surface surface);
878
879 /**
880 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * <p>
882 * Sent from the {@link InCallService} via
883 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700885 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 */
887 public abstract void onSetDisplaySurface(Surface surface);
888
889 /**
890 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
891 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700892 * <p>
893 * Sent from the {@link InCallService} via
894 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700895 *
896 * @param rotation The device orientation, in degrees.
897 */
898 public abstract void onSetDeviceOrientation(int rotation);
899
900 /**
901 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700902 * <p>
903 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 *
905 * @param value The camera zoom ratio.
906 */
907 public abstract void onSetZoom(float value);
908
909 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700910 * Issues a request to modify the properties of the current video session.
911 * <p>
912 * Example scenarios include: requesting an audio-only call to be upgraded to a
913 * bi-directional video call, turning on or off the user's camera, sending a pause signal
914 * when the {@link InCallService} is no longer the foreground application.
915 * <p>
916 * If the {@link VideoProvider} determines a request to be invalid, it should call
917 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
918 * invalid request back to the {@link InCallService}.
919 * <p>
920 * Where a request requires confirmation from the user of the peer device, the
921 * {@link VideoProvider} must communicate the request to the peer device and handle the
922 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
923 * is used to inform the {@link InCallService} of the result of the request.
924 * <p>
925 * Sent from the {@link InCallService} via
926 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700928 * @param fromProfile The video profile prior to the request.
929 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930 */
Tyler Gunn45382162015-05-06 08:52:27 -0700931 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
932 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700933
Tyler Gunnb702ef82015-05-29 11:51:53 -0700934 /**
935 * Provides a response to a request to change the current video session properties.
936 * <p>
937 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
938 * video call, could decline the request and keep the call as audio-only.
939 * In such a scenario, the {@code responseProfile} would have a video state of
940 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
941 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
942 * <p>
943 * Sent from the {@link InCallService} via
944 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
945 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
946 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 */
950 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
951
952 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700953 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
954 * <p>
955 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
956 * camera via
957 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
958 * <p>
959 * Sent from the {@link InCallService} via
960 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 */
962 public abstract void onRequestCameraCapabilities();
963
964 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700965 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
966 * video component of the current {@link Connection}.
967 * <p>
968 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
969 * via {@link VideoProvider#setCallDataUsage(long)}.
970 * <p>
971 * Sent from the {@link InCallService} via
972 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800974 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975
976 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
978 * the peer device when the video signal is paused.
979 * <p>
980 * Sent from the {@link InCallService} via
981 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 *
983 * @param uri URI of image to display.
984 */
Yorke Lee32f24732015-05-12 16:18:03 -0700985 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986
987 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * Used to inform listening {@link InCallService} implementations when the
989 * {@link VideoProvider} receives a session modification request.
990 * <p>
991 * Received by the {@link InCallService} via
992 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700994 * @param videoProfile The requested video profile.
995 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700996 */
997 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700998 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700999 for (IVideoCallback callback : mVideoCallbacks.values()) {
1000 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001001 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001002 } catch (RemoteException ignored) {
1003 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001004 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 }
1006 }
1007 }
1008
1009 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001010 * Used to inform listening {@link InCallService} implementations when the
1011 * {@link VideoProvider} receives a response to a session modification request.
1012 * <p>
1013 * Received by the {@link InCallService} via
1014 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1015 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 *
1017 * @param status Status of the session modify request. Valid values are
1018 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1019 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1021 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1022 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1023 * @param requestedProfile The original request which was sent to the peer device.
1024 * @param responseProfile The actual profile changes agreed to by the peer device.
1025 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001026 */
1027 public void receiveSessionModifyResponse(int status,
1028 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001029 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001030 for (IVideoCallback callback : mVideoCallbacks.values()) {
1031 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001032 callback.receiveSessionModifyResponse(status, requestedProfile,
1033 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001034 } catch (RemoteException ignored) {
1035 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001036 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001037 }
1038 }
1039 }
1040
1041 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001042 * Used to inform listening {@link InCallService} implementations when the
1043 * {@link VideoProvider} reports a call session event.
1044 * <p>
1045 * Received by the {@link InCallService} via
1046 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001047 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001048 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1049 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1050 * {@link VideoProvider#SESSION_EVENT_TX_START},
1051 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1052 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1053 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 */
1055 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001056 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001057 for (IVideoCallback callback : mVideoCallbacks.values()) {
1058 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001059 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001060 } catch (RemoteException ignored) {
1061 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001062 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 }
1064 }
1065 }
1066
1067 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001068 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1069 * peer's video have changed.
1070 * <p>
1071 * This could occur if, for example, the peer rotates their device, changing the aspect
1072 * ratio of the video, or if the user switches between the back and front cameras.
1073 * <p>
1074 * Received by the {@link InCallService} via
1075 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001076 *
1077 * @param width The updated peer video width.
1078 * @param height The updated peer video height.
1079 */
1080 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001081 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001082 for (IVideoCallback callback : mVideoCallbacks.values()) {
1083 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001084 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001085 } catch (RemoteException ignored) {
1086 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001087 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 }
1089 }
1090 }
1091
1092 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001093 * Used to inform listening {@link InCallService} implementations when the data usage of the
1094 * video associated with the current {@link Connection} has changed.
1095 * <p>
1096 * This could be in response to a preview request via
1097 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001098 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1099 * 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 -07001100 * <p>
1101 * Received by the {@link InCallService} via
1102 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001104 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1105 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 */
Yorke Lee32f24732015-05-12 16:18:03 -07001107 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001108 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001109 for (IVideoCallback callback : mVideoCallbacks.values()) {
1110 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001111 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001112 } catch (RemoteException ignored) {
1113 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001114 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001115 }
1116 }
1117 }
1118
1119 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001120 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001122 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001123 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1124 * @hide
1125 */
1126 public void changeCallDataUsage(long dataUsage) {
1127 setCallDataUsage(dataUsage);
1128 }
1129
1130 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001131 * Used to inform listening {@link InCallService} implementations when the capabilities of
1132 * the current camera have changed.
1133 * <p>
1134 * The {@link VideoProvider} should call this in response to
1135 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1136 * changed via {@link VideoProvider#onSetCamera(String)}.
1137 * <p>
1138 * Received by the {@link InCallService} via
1139 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1140 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001141 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001142 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 */
Yorke Lee400470f2015-05-12 13:31:25 -07001144 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001145 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001146 for (IVideoCallback callback : mVideoCallbacks.values()) {
1147 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001148 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001149 } catch (RemoteException ignored) {
1150 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001151 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001152 }
1153 }
1154 }
Rekha Kumar07366812015-03-24 16:42:31 -07001155
1156 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001157 * Used to inform listening {@link InCallService} implementations when the video quality
1158 * of the call has changed.
1159 * <p>
1160 * Received by the {@link InCallService} via
1161 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001162 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001163 * @param videoQuality The updated video quality. Valid values:
1164 * {@link VideoProfile#QUALITY_HIGH},
1165 * {@link VideoProfile#QUALITY_MEDIUM},
1166 * {@link VideoProfile#QUALITY_LOW},
1167 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001168 */
1169 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001170 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001171 for (IVideoCallback callback : mVideoCallbacks.values()) {
1172 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001173 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001174 } catch (RemoteException ignored) {
1175 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001176 }
Rekha Kumar07366812015-03-24 16:42:31 -07001177 }
1178 }
1179 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001180 }
1181
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001182 private final Listener mConnectionDeathListener = new Listener() {
1183 @Override
1184 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001185 if (mConferenceables.remove(c)) {
1186 fireOnConferenceableConnectionsChanged();
1187 }
1188 }
1189 };
1190
1191 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1192 @Override
1193 public void onDestroyed(Conference c) {
1194 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001195 fireOnConferenceableConnectionsChanged();
1196 }
1197 }
1198 };
1199
Jay Shrauner229e3822014-08-15 09:23:07 -07001200 /**
1201 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1202 * load factor before resizing, 1 means we only expect a single thread to
1203 * access the map so make only a single shard
1204 */
1205 private final Set<Listener> mListeners = Collections.newSetFromMap(
1206 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001207 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1208 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001209 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001210
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001211 // The internal telecom call ID associated with this connection.
1212 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001214 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001215 private Uri mAddress;
1216 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001217 private String mCallerDisplayName;
1218 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001219 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001220 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001221 private int mConnectionProperties;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001222 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001223 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001224 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001225 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001226 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001227 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001228 private Conference mConference;
1229 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001230 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001231
1232 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001233 * Tracks the key set for the extras bundle provided on the last invocation of
1234 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1235 * keys which were set previously but are no longer present in the replacement Bundle.
1236 */
1237 private Set<String> mPreviousExtraKeys;
1238
1239 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001240 * Create a new Connection.
1241 */
Santos Cordonf2951102014-07-20 19:06:29 -07001242 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001243
1244 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001245 * Returns the Telecom internal call ID associated with this connection. Should only be used
1246 * for debugging and tracing purposes.
1247 *
1248 * @return The Telecom call ID.
1249 * @hide
1250 */
1251 public final String getTelecomCallId() {
1252 return mTelecomCallId;
1253 }
1254
1255 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001256 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001257 */
Andrew Lee100e2932014-09-08 15:34:24 -07001258 public final Uri getAddress() {
1259 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001260 }
1261
1262 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001263 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001264 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001265 */
Andrew Lee100e2932014-09-08 15:34:24 -07001266 public final int getAddressPresentation() {
1267 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001268 }
1269
1270 /**
1271 * @return The caller display name (CNAP).
1272 */
1273 public final String getCallerDisplayName() {
1274 return mCallerDisplayName;
1275 }
1276
1277 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001278 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001279 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001280 */
1281 public final int getCallerDisplayNamePresentation() {
1282 return mCallerDisplayNamePresentation;
1283 }
1284
1285 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001286 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001287 */
1288 public final int getState() {
1289 return mState;
1290 }
1291
1292 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001293 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001294 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1295 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1296 * {@link VideoProfile#STATE_TX_ENABLED},
1297 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001298 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001299 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001300 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001301 */
1302 public final int getVideoState() {
1303 return mVideoState;
1304 }
1305
1306 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001307 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308 * being routed by the system. This is {@code null} if this Connection
1309 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001310 * @deprecated Use {@link #getCallAudioState()} instead.
1311 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001312 */
Yorke Lee4af59352015-05-13 14:14:54 -07001313 @SystemApi
1314 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001316 if (mCallAudioState == null) {
1317 return null;
1318 }
Yorke Lee4af59352015-05-13 14:14:54 -07001319 return new AudioState(mCallAudioState);
1320 }
1321
1322 /**
1323 * @return The audio state of the connection, describing how its audio is currently
1324 * being routed by the system. This is {@code null} if this Connection
1325 * does not directly know about its audio state.
1326 */
1327 public final CallAudioState getCallAudioState() {
1328 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001329 }
1330
1331 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001332 * @return The conference that this connection is a part of. Null if it is not part of any
1333 * conference.
1334 */
1335 public final Conference getConference() {
1336 return mConference;
1337 }
1338
1339 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001340 * Returns whether this connection is requesting that the system play a ringback tone
1341 * on its behalf.
1342 */
Andrew Lee100e2932014-09-08 15:34:24 -07001343 public final boolean isRingbackRequested() {
1344 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001345 }
1346
1347 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001348 * @return True if the connection's audio mode is VOIP.
1349 */
1350 public final boolean getAudioModeIsVoip() {
1351 return mAudioModeIsVoip;
1352 }
1353
1354 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001355 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1356 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1357 * start time of the conference.
1358 *
1359 * @return The time at which the {@code Connnection} was connected.
1360 *
1361 * @hide
1362 */
1363 public final long getConnectTimeMillis() {
1364 return mConnectTimeMillis;
1365 }
1366
1367 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001368 * @return The status hints for this connection.
1369 */
1370 public final StatusHints getStatusHints() {
1371 return mStatusHints;
1372 }
1373
1374 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001375 * Returns the extras associated with this connection.
1376 * <p>
1377 * Extras should be updated using {@link #putExtras(Bundle)}.
1378 * <p>
1379 * Telecom or an {@link InCallService} can also update the extras via
1380 * {@link android.telecom.Call#putExtras(Bundle)}, and
1381 * {@link Call#removeExtras(List)}.
1382 * <p>
1383 * The connection is notified of changes to the extras made by Telecom or an
1384 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
1385 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001386 * @return The extras associated with this connection.
1387 */
1388 public final Bundle getExtras() {
1389 return mExtras;
1390 }
1391
1392 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001393 * Assign a listener to be notified of state changes.
1394 *
1395 * @param l A listener.
1396 * @return This Connection.
1397 *
1398 * @hide
1399 */
1400 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001401 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001402 return this;
1403 }
1404
1405 /**
1406 * Remove a previously assigned listener that was being notified of state changes.
1407 *
1408 * @param l A Listener.
1409 * @return This Connection.
1410 *
1411 * @hide
1412 */
1413 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001414 if (l != null) {
1415 mListeners.remove(l);
1416 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001417 return this;
1418 }
1419
1420 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001421 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001422 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001423 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001424 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001425 }
1426
1427 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001428 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1429 * ONLY for debugging purposes.
1430 *
1431 * @param callId The telecom call ID.
1432 * @hide
1433 */
1434 public void setTelecomCallId(String callId) {
1435 mTelecomCallId = callId;
1436 }
1437
1438 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001439 * Inform this Connection that the state of its audio output has been changed externally.
1440 *
1441 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001442 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001443 */
Yorke Lee4af59352015-05-13 14:14:54 -07001444 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001445 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001446 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001447 mCallAudioState = state;
1448 onAudioStateChanged(getAudioState());
1449 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001450 }
1451
1452 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001454 * @return A string representation of the value.
1455 */
1456 public static String stateToString(int state) {
1457 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001459 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001461 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001463 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001465 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001467 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001469 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001471 return "DISCONNECTED";
1472 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001473 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001474 return "UNKNOWN";
1475 }
1476 }
1477
1478 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001479 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001480 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001481 public final int getConnectionCapabilities() {
1482 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001483 }
1484
1485 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001486 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1487 */
1488 public final int getConnectionProperties() {
1489 return mConnectionProperties;
1490 }
1491
1492 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001493 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001494 *
Andrew Lee100e2932014-09-08 15:34:24 -07001495 * @param address The new address.
1496 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001497 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001498 */
Andrew Lee100e2932014-09-08 15:34:24 -07001499 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001500 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001501 Log.d(this, "setAddress %s", address);
1502 mAddress = address;
1503 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001504 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001505 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001506 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001507 }
1508
1509 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001510 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001511 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001512 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001513 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001514 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001515 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001516 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001517 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001518 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001519 mCallerDisplayName = callerDisplayName;
1520 mCallerDisplayNamePresentation = presentation;
1521 for (Listener l : mListeners) {
1522 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1523 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001524 }
1525
1526 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001527 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001528 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1529 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1530 * {@link VideoProfile#STATE_TX_ENABLED},
1531 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001532 *
1533 * @param videoState The new video state.
1534 */
1535 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001536 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001537 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001538 mVideoState = videoState;
1539 for (Listener l : mListeners) {
1540 l.onVideoStateChanged(this, mVideoState);
1541 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001542 }
1543
1544 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001545 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001546 * communicate).
1547 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001548 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001549 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001550 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001552 }
1553
1554 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001555 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001556 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001557 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001558 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001559 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001560 }
1561
1562 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001563 * Sets state to initializing (this Connection is not yet ready to be used).
1564 */
1565 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001566 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001568 }
1569
1570 /**
1571 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1572 */
1573 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001574 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001575 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001576 }
1577
1578 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001579 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001580 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001581 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001582 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001583 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 }
1585
1586 /**
1587 * Sets state to be on hold.
1588 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001589 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001590 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001592 }
1593
1594 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001595 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001596 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001597 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001598 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001599 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001601 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001603 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001604 }
1605
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001606 public final VideoProvider getVideoProvider() {
1607 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001608 }
1609
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001610 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001611 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001612 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001613 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001615 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001616 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001617 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001618 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001619 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001620 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001621 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001622 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001623 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 }
1625
1626 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001627 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1628 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1629 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1630 * to send an {@link #onPostDialContinue(boolean)} signal.
1631 *
1632 * @param remaining The DTMF character sequence remaining to be emitted once the
1633 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1634 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001635 */
1636 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001637 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001638 for (Listener l : mListeners) {
1639 l.onPostDialWait(this, remaining);
1640 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001641 }
1642
1643 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001644 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1645 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001646 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001647 *
1648 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001649 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001650 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001651 checkImmutable();
1652 for (Listener l : mListeners) {
1653 l.onPostDialChar(this, nextChar);
1654 }
1655 }
1656
1657 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001658 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001659 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001660 *
1661 * @param ringback Whether the ringback tone is to be played.
1662 */
Andrew Lee100e2932014-09-08 15:34:24 -07001663 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001664 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001665 if (mRingbackRequested != ringback) {
1666 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001667 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001668 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001669 }
1670 }
Ihab Awadf8358972014-05-28 16:46:42 -07001671 }
1672
1673 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001674 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001675 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001676 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001677 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001678 public final void setConnectionCapabilities(int connectionCapabilities) {
1679 checkImmutable();
1680 if (mConnectionCapabilities != connectionCapabilities) {
1681 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001682 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001683 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001684 }
1685 }
Santos Cordonb6939982014-06-04 20:20:58 -07001686 }
1687
1688 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001689 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1690 *
1691 * @param connectionProperties The new connection properties.
1692 */
1693 public final void setConnectionProperties(int connectionProperties) {
1694 checkImmutable();
1695 if (mConnectionProperties != connectionProperties) {
1696 mConnectionProperties = connectionProperties;
1697 for (Listener l : mListeners) {
1698 l.onConnectionPropertiesChanged(this, mConnectionProperties);
1699 }
1700 }
1701 }
1702
1703 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001704 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001705 */
Evan Charlton36a71342014-07-19 16:31:02 -07001706 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001707 for (Listener l : mListeners) {
1708 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001709 }
Santos Cordonb6939982014-06-04 20:20:58 -07001710 }
1711
1712 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001713 * Requests that the framework use VOIP audio mode for this connection.
1714 *
1715 * @param isVoip True if the audio mode is VOIP.
1716 */
1717 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001718 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001719 mAudioModeIsVoip = isVoip;
1720 for (Listener l : mListeners) {
1721 l.onAudioModeIsVoipChanged(this, isVoip);
1722 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001723 }
1724
1725 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001726 * Sets the time at which a call became active on this Connection. This is set only
1727 * when a conference call becomes active on this connection.
1728 *
1729 * @param connectionTimeMillis The connection time, in milliseconds.
1730 *
1731 * @hide
1732 */
1733 public final void setConnectTimeMillis(long connectTimeMillis) {
1734 mConnectTimeMillis = connectTimeMillis;
1735 }
1736
1737 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001738 * Sets the label and icon status to display in the in-call UI.
1739 *
1740 * @param statusHints The status label and icon to set.
1741 */
1742 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001743 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001744 mStatusHints = statusHints;
1745 for (Listener l : mListeners) {
1746 l.onStatusHintsChanged(this, statusHints);
1747 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001748 }
1749
1750 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001751 * Sets the connections with which this connection can be conferenced.
1752 *
1753 * @param conferenceableConnections The set of connections this connection can conference with.
1754 */
1755 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001756 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001757 clearConferenceableList();
1758 for (Connection c : conferenceableConnections) {
1759 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1760 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001761 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001762 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001763 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001764 }
1765 }
1766 fireOnConferenceableConnectionsChanged();
1767 }
1768
1769 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001770 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1771 * or conferences with which this connection can be conferenced.
1772 *
1773 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001774 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001775 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001776 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001777 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001778 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1779 // small amount of items here.
1780 if (!mConferenceables.contains(c)) {
1781 if (c instanceof Connection) {
1782 Connection connection = (Connection) c;
1783 connection.addConnectionListener(mConnectionDeathListener);
1784 } else if (c instanceof Conference) {
1785 Conference conference = (Conference) c;
1786 conference.addListener(mConferenceDeathListener);
1787 }
1788 mConferenceables.add(c);
1789 }
1790 }
1791 fireOnConferenceableConnectionsChanged();
1792 }
1793
1794 /**
1795 * Returns the connections or conferences with which this connection can be conferenced.
1796 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001797 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001798 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001799 }
1800
Yorke Lee53463962015-08-04 16:07:19 -07001801 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001802 * @hide
1803 */
1804 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001805 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001806 if (mConnectionService != null) {
1807 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1808 "which is already associated with another ConnectionService.");
1809 } else {
1810 mConnectionService = connectionService;
1811 }
1812 }
1813
1814 /**
1815 * @hide
1816 */
1817 public final void unsetConnectionService(ConnectionService connectionService) {
1818 if (mConnectionService != connectionService) {
1819 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1820 "that does not belong to the ConnectionService.");
1821 } else {
1822 mConnectionService = null;
1823 }
1824 }
1825
1826 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001827 * @hide
1828 */
1829 public final ConnectionService getConnectionService() {
1830 return mConnectionService;
1831 }
1832
1833 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001834 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001835 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001836 *
1837 * @param conference The conference.
1838 * @return {@code true} if the conference was successfully set.
1839 * @hide
1840 */
1841 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001842 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001843 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001844 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001845 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001846 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1847 fireConferenceChanged();
1848 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001849 return true;
1850 }
1851 return false;
1852 }
1853
1854 /**
1855 * Resets the conference that this connection is a part of.
1856 * @hide
1857 */
1858 public final void resetConference() {
1859 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001860 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001861 mConference = null;
1862 fireConferenceChanged();
1863 }
1864 }
1865
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001866 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001867 * Set some extras that can be associated with this {@code Connection}.
1868 * <p>
1869 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
1870 * in the new extras, but were present the last time {@code setExtras} was called are removed.
1871 * <p>
1872 * 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 -07001873 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1874 *
1875 * @param extras The extras associated with this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001876 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
1877 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07001878 */
1879 public final void setExtras(@Nullable Bundle extras) {
1880 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07001881
1882 // Add/replace any new or changed extras values.
1883 putExtras(extras);
1884
1885 // If we have used "setExtras" in the past, compare the key set from the last invocation to
1886 // the current one and remove any keys that went away.
1887 if (mPreviousExtraKeys != null) {
1888 List<String> toRemove = new ArrayList<String>();
1889 for (String oldKey : mPreviousExtraKeys) {
1890 if (!extras.containsKey(oldKey)) {
1891 toRemove.add(oldKey);
1892 }
1893 }
1894 if (!toRemove.isEmpty()) {
1895 removeExtras(toRemove);
1896 }
1897 }
1898
1899 // Track the keys the last time set called setExtras. This way, the next time setExtras is
1900 // called we can see if the caller has removed any extras values.
1901 if (mPreviousExtraKeys == null) {
1902 mPreviousExtraKeys = new ArraySet<String>();
1903 }
1904 mPreviousExtraKeys.clear();
1905 mPreviousExtraKeys.addAll(extras.keySet());
1906 }
1907
1908 /**
1909 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
1910 * added.
1911 * <p>
1912 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1913 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1914 *
1915 * @param extras The extras to add.
1916 */
1917 public final void putExtras(@NonNull Bundle extras) {
1918 checkImmutable();
1919 if (extras == null) {
1920 return;
1921 }
1922
1923 if (mExtras == null) {
1924 mExtras = new Bundle();
1925 }
1926 mExtras.putAll(extras);
1927
Santos Cordon6b7f9552015-05-27 17:21:45 -07001928 for (Listener l : mListeners) {
1929 l.onExtrasChanged(this, extras);
1930 }
1931 }
1932
1933 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001934 * Adds a boolean extra to this {@code Connection}.
1935 *
1936 * @param key The extra key.
1937 * @param value The value.
1938 * @hide
1939 */
1940 public final void putExtra(String key, boolean value) {
1941 Bundle newExtras = new Bundle();
1942 newExtras.putBoolean(key, value);
1943 putExtras(newExtras);
1944 }
1945
1946 /**
1947 * Adds an integer extra to this {@code Connection}.
1948 *
1949 * @param key The extra key.
1950 * @param value The value.
1951 * @hide
1952 */
1953 public final void putExtra(String key, int value) {
1954 Bundle newExtras = new Bundle();
1955 newExtras.putInt(key, value);
1956 putExtras(newExtras);
1957 }
1958
1959 /**
1960 * Adds a string extra to this {@code Connection}.
1961 *
1962 * @param key The extra key.
1963 * @param value The value.
1964 * @hide
1965 */
1966 public final void putExtra(String key, String value) {
1967 Bundle newExtras = new Bundle();
1968 newExtras.putString(key, value);
1969 putExtras(newExtras);
1970 }
1971
1972 /**
1973 * Removes an extra from this {@code Connection}.
1974 *
1975 * @param keys The key of the extra key to remove.
1976 */
1977 public final void removeExtras(List<String> keys) {
1978 if (mExtras != null) {
1979 for (String key : keys) {
1980 mExtras.remove(key);
1981 }
1982
1983 if (mExtras.size() == 0) {
1984 mExtras = null;
1985 }
1986 }
1987
1988 for (Listener l : mListeners) {
1989 l.onExtrasRemoved(this, keys);
1990 }
1991 }
1992
1993 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001994 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001995 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001996 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001997 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1998 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001999 */
Yorke Lee4af59352015-05-13 14:14:54 -07002000 @SystemApi
2001 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002002 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002003
2004 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002005 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2006 *
2007 * @param state The new connection audio state.
2008 */
2009 public void onCallAudioStateChanged(CallAudioState state) {}
2010
2011 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002012 * Notifies this Connection of an internal state change. This method is called after the
2013 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002014 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002015 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002016 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002017 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002018
2019 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002020 * Notifies this Connection of a request to play a DTMF tone.
2021 *
2022 * @param c A DTMF character.
2023 */
Santos Cordonf2951102014-07-20 19:06:29 -07002024 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002025
2026 /**
2027 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2028 */
Santos Cordonf2951102014-07-20 19:06:29 -07002029 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002030
2031 /**
2032 * Notifies this Connection of a request to disconnect.
2033 */
Santos Cordonf2951102014-07-20 19:06:29 -07002034 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002035
2036 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002037 * Notifies this Connection of a request to disconnect a participant of the conference managed
2038 * by the connection.
2039 *
2040 * @param endpoint the {@link Uri} of the participant to disconnect.
2041 * @hide
2042 */
2043 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2044
2045 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002046 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002047 */
Santos Cordonf2951102014-07-20 19:06:29 -07002048 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002049
2050 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002051 * Notifies this Connection of a request to abort.
2052 */
Santos Cordonf2951102014-07-20 19:06:29 -07002053 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002054
2055 /**
2056 * Notifies this Connection of a request to hold.
2057 */
Santos Cordonf2951102014-07-20 19:06:29 -07002058 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002059
2060 /**
2061 * Notifies this Connection of a request to exit a hold state.
2062 */
Santos Cordonf2951102014-07-20 19:06:29 -07002063 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002064
2065 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002067 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002068 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002069 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070 */
Santos Cordonf2951102014-07-20 19:06:29 -07002071 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072
2073 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002075 * a request to accept.
2076 */
2077 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002078 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002079 }
2080
2081 /**
2082 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002083 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084 */
Santos Cordonf2951102014-07-20 19:06:29 -07002085 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002086
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002087 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002088 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2089 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002090 */
2091 public void onReject(String replyMessage) {}
2092
2093 /**
Bryce Leecac50772015-11-17 15:13:29 -08002094 * Notifies the Connection of a request to silence the ringer.
2095 *
2096 * @hide
2097 */
2098 public void onSilence() {}
2099
2100 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002101 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2102 */
Santos Cordonf2951102014-07-20 19:06:29 -07002103 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002104
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002105 /**
2106 * Notifies this Connection of a request to pull an external call to the local device.
2107 * <p>
2108 * The {@link InCallService} issues a request to pull an external call to the local device via
2109 * {@link Call#pullExternalCall()}.
2110 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002111 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2112 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002113 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002114 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002115 */
2116 public void onPullExternalCall() {}
2117
2118 /**
2119 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2120 * <p>
2121 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2122 * <p>
2123 * See also {@link Call#sendCallEvent(String, Bundle)}.
2124 *
2125 * @param event The call event.
2126 * @param extras Extras associated with the call event.
2127 */
2128 public void onCallEvent(String event, Bundle extras) {}
2129
Tyler Gunndee56a82016-03-23 16:06:34 -07002130 /**
2131 * Notifies this {@link Connection} of a change to the extras made outside the
2132 * {@link ConnectionService}.
2133 * <p>
2134 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2135 * the {@link android.telecom.Call#putExtras(Bundle)} and
2136 * {@link Call#removeExtras(List)}.
2137 *
2138 * @param extras The new extras bundle.
2139 */
2140 public void onExtrasChanged(Bundle extras) {}
2141
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002142 static String toLogSafePhoneNumber(String number) {
2143 // For unknown number, log empty string.
2144 if (number == null) {
2145 return "";
2146 }
2147
2148 if (PII_DEBUG) {
2149 // When PII_DEBUG is true we emit PII.
2150 return number;
2151 }
2152
2153 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2154 // sanitized phone numbers.
2155 StringBuilder builder = new StringBuilder();
2156 for (int i = 0; i < number.length(); i++) {
2157 char c = number.charAt(i);
2158 if (c == '-' || c == '@' || c == '.') {
2159 builder.append(c);
2160 } else {
2161 builder.append('x');
2162 }
2163 }
2164 return builder.toString();
2165 }
2166
Ihab Awad542e0ea2014-05-16 10:22:16 -07002167 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002168 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002169 if (mState == STATE_DISCONNECTED && mState != state) {
2170 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002171 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002172 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002173 if (mState != state) {
2174 Log.d(this, "setState: %s", stateToString(state));
2175 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002176 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002177 for (Listener l : mListeners) {
2178 l.onStateChanged(this, state);
2179 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002180 }
2181 }
2182
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002183 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002184 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002185 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2186 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002187 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002188 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002189
2190 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002191 if (mImmutable) {
2192 throw new UnsupportedOperationException("Connection is immutable");
2193 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002194 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002195 }
2196
Evan Charltonbf11f982014-07-20 22:06:28 -07002197 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002198 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002199 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2200 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002201 * <p>
2202 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2203 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002204 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002205 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002206 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002207 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002208 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2209 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002210 }
2211
Evan Charltonbf11f982014-07-20 22:06:28 -07002212 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2214 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2215 * this should never be un-@hide-den.
2216 *
2217 * @hide
2218 */
2219 public void checkImmutable() {}
2220
2221 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002222 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2223 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2224 * that state. This connection should not be used for anything, and no other
2225 * {@code Connection}s should be attempted.
2226 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002227 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002228 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002229 * @return A {@code Connection} which indicates that the underlying connection should
2230 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002231 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002232 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002233 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002234 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002235
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002236 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002237 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002238 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002239 }
2240 }
2241
Santos Cordon823fd3c2014-08-07 18:35:18 -07002242 private final void fireConferenceChanged() {
2243 for (Listener l : mListeners) {
2244 l.onConferenceChanged(this, mConference);
2245 }
2246 }
2247
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002248 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002249 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002250 if (c instanceof Connection) {
2251 Connection connection = (Connection) c;
2252 connection.removeConnectionListener(mConnectionDeathListener);
2253 } else if (c instanceof Conference) {
2254 Conference conference = (Conference) c;
2255 conference.removeListener(mConferenceDeathListener);
2256 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002257 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002258 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002259 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002260
2261 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002262 * Handles a change to extras received from Telecom.
2263 *
2264 * @param extras The new extras.
2265 * @hide
2266 */
2267 final void handleExtrasChanged(Bundle extras) {
2268 mExtras = extras;
2269 onExtrasChanged(mExtras);
2270 }
2271
2272 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002273 * Notifies listeners that the merge request failed.
2274 *
2275 * @hide
2276 */
2277 protected final void notifyConferenceMergeFailed() {
2278 for (Listener l : mListeners) {
2279 l.onConferenceMergeFailed(this);
2280 }
2281 }
2282
2283 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002284 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002285 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002286 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002287 * @hide
2288 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002289 protected final void updateConferenceParticipants(
2290 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002291 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002292 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002293 }
2294 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002295
2296 /**
2297 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002298 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002299 */
2300 protected void notifyConferenceStarted() {
2301 for (Listener l : mListeners) {
2302 l.onConferenceStarted();
2303 }
2304 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002305
2306 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002307 * Sends an event associated with this {@code Connection}, with associated event extras.
2308 *
2309 * Events are exposed to {@link InCallService} implementations via the
2310 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2311 *
2312 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2313 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002314 *
2315 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002316 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002317 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002318 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002319 for (Listener l : mListeners) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002320 l.onConnectionEvent(this, event, null);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002321 }
2322 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002323}