blob: 833affa379f34924fb2ffd835a0b642e5eb8a756 [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
Hall Liu57006aa2017-02-06 10:49:48 -080023import android.annotation.IntDef;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070026import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.app.Notification;
28import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070039import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041
Hall Liu95d55872017-01-25 17:12:49 -080042import java.io.IOException;
43import java.io.InputStreamReader;
44import java.io.OutputStreamWriter;
Hall Liu57006aa2017-02-06 10:49:48 -080045import java.lang.annotation.Retention;
46import java.lang.annotation.RetentionPolicy;
Santos Cordonb6939982014-06-04 20:20:58 -070047import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070048import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070050import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070052import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053
54/**
Santos Cordon895d4b82015-06-25 16:41:48 -070055 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
56 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070057 * <p>
58 * Implementations create a custom subclass of {@code Connection} and return it to the framework
59 * as the return value of
60 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
61 * or
62 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
63 * Implementations are then responsible for updating the state of the {@code Connection}, and
64 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
65 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070066 * <p>
67 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
68 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
69 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
70 * {@code Connection} instance.
71 * <p>
72 * Basic call support requires overriding the following methods: {@link #onAnswer()},
73 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
74 * <p>
75 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
76 * {@link #onUnhold()} methods should be overridden to provide hold support for the
77 * {@code Connection}.
78 * <p>
79 * Where a {@code Connection} supports a variation of video calling (e.g. the
80 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
81 * to support answering a call as a video call.
82 * <p>
83 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
84 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
85 * support for pulling the external call.
86 * <p>
87 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
88 * overridden.
89 * <p>
90 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
91 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
92 * for example, call events from a {@link InCallService} are handled,
93 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
94 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
95 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
96 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070097 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070098public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070099
Santos Cordon895d4b82015-06-25 16:41:48 -0700100 /**
101 * The connection is initializing. This is generally the first state for a {@code Connection}
102 * returned by a {@link ConnectionService}.
103 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 public static final int STATE_INITIALIZING = 0;
105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * The connection is new and not connected.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_NEW = 1;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * An incoming connection is in the ringing state. During this state, the user's ringer or
113 * vibration feature will be activated.
114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 public static final int STATE_RINGING = 2;
116
Santos Cordon895d4b82015-06-25 16:41:48 -0700117 /**
118 * An outgoing connection is in the dialing state. In this state the other party has not yet
119 * answered the call and the user traditionally hears a ringback tone.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_DIALING = 3;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * A connection is active. Both parties are connected to the call and can actively communicate.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_ACTIVE = 4;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is on hold.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_HOLDING = 5;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection has been disconnected. This is the final state once the user has been
135 * disconnected from a call either locally, remotely or by an error in the service.
136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final int STATE_DISCONNECTED = 6;
138
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700140 * The state of an external connection which is in the process of being pulled from a remote
141 * device to the local device.
142 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700143 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700144 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
145 */
146 public static final int STATE_PULLING_CALL = 7;
147
148 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700149 * Connection can currently be put on hold or unheld. This is distinct from
150 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
151 * it does not at the moment support the function. This can be true while the call is in the
152 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
153 * display a disabled 'hold' button.
154 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 public static final int CAPABILITY_HOLD = 0x00000001;
156
157 /** Connection supports the hold feature. */
158 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
159
160 /**
161 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
162 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
163 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
164 * capability allows a merge button to be shown while the conference is in the foreground
165 * of the in-call UI.
166 * <p>
167 * This is only intended for use by a {@link Conference}.
168 */
169 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
170
171 /**
172 * Connections within a conference can be swapped between foreground and background.
173 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
174 * <p>
175 * This is only intended for use by a {@link Conference}.
176 */
177 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
178
179 /**
180 * @hide
181 */
182 public static final int CAPABILITY_UNUSED = 0x00000010;
183
184 /** Connection supports responding via text option. */
185 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
186
187 /** Connection can be muted. */
188 public static final int CAPABILITY_MUTE = 0x00000040;
189
190 /**
191 * Connection supports conference management. This capability only applies to
192 * {@link Conference}s which can have {@link Connection}s as children.
193 */
194 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
195
196 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211
212 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
216
217 /**
218 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 */
220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
221
222 /**
223 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800227
228 /**
229 * Connection is able to be separated from its parent {@code Conference}, if any.
230 */
231 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
232
233 /**
234 * Connection is able to be individually disconnected when in a {@code Conference}.
235 */
236 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
237
238 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800240 * @hide
241 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700242 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 * @hide
247 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249
250 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * @hide
253 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255
Tyler Gunn068085b2015-02-06 13:56:52 -0800256 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800258 * @hide
259 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700260 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800261
Tyler Gunn96d6c402015-03-18 12:39:23 -0700262 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500263 * Speed up audio setup for MT call.
264 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700265 */
266 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Rekha Kumar07366812015-03-24 16:42:31 -0700268 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700269 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700270 */
271 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
272
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700273 /**
274 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700275 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700276 */
277 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
278
Tyler Gunnd4091732015-06-29 09:15:37 -0700279 /**
280 * For a conference, indicates the conference will not have child connections.
281 * <p>
282 * An example of a conference with child connections is a GSM conference call, where the radio
283 * retains connections to the individual participants of the conference. Another example is an
284 * IMS conference call where conference event package functionality is supported; in this case
285 * the conference server ensures the radio is aware of the participants in the conference, which
286 * are represented by child connections.
287 * <p>
288 * An example of a conference with no child connections is an IMS conference call with no
289 * conference event package support. Such a conference is represented by the radio as a single
290 * connection to the IMS conference server.
291 * <p>
292 * Indicating whether a conference has children or not is important to help user interfaces
293 * visually represent a conference. A conference with no children, for example, will have the
294 * conference connection shown in the list of calls on a Bluetooth device, where if the
295 * conference has children, only the children will be shown in the list of calls on a Bluetooth
296 * device.
297 * @hide
298 */
299 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
300
Bryce Lee81901682015-08-28 16:38:02 -0700301 /**
302 * Indicates that the connection itself wants to handle any sort of reply response, rather than
303 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700304 */
305 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
306
Tyler Gunnf97a0092016-01-19 15:59:34 -0800307 /**
308 * When set, prevents a video call from being downgraded to an audio-only call.
309 * <p>
310 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
311 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
312 * downgraded from a video call back to a VideoState of
313 * {@link VideoProfile#STATE_AUDIO_ONLY}.
314 * <p>
315 * Intuitively, a call which can be downgraded to audio should also have local and remote
316 * video
317 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
318 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
319 */
320 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
321
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700323 * When set for an external connection, indicates that this {@code Connection} can be pulled
324 * from a remote device to the current device.
325 * <p>
326 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
327 * is set.
328 */
329 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
330
331 //**********************************************************************************************
332 // Next CAPABILITY value: 0x02000000
333 //**********************************************************************************************
334
335 /**
336 * Indicates that the current device callback number should be shown.
337 *
338 * @hide
339 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700340 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700341
342 /**
343 * Whether the call is a generic conference, where we do not know the precise state of
344 * participants in the conference (eg. on CDMA).
345 *
346 * @hide
347 */
348 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
349
350 /**
351 * Connection is using high definition audio.
352 * @hide
353 */
354 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
355
356 /**
357 * Connection is using WIFI.
358 * @hide
359 */
360 public static final int PROPERTY_WIFI = 1<<3;
361
362 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700363 * When set, indicates that the {@code Connection} does not actually exist locally for the
364 * {@link ConnectionService}.
365 * <p>
366 * Consider, for example, a scenario where a user has two devices with the same phone number.
367 * When a user places a call on one devices, the telephony stack can represent that call on the
368 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700369 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700370 * <p>
371 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
372 * external connections. Only those {@link InCallService}s which have the
373 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
374 * manifest will see external connections.
375 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700376 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700377
Brad Ebinger15847072016-05-18 11:08:36 -0700378 /**
379 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
380 */
381 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382
Hall Liu9f332c72016-07-14 15:37:37 -0700383 /**
384 * Indicates that the connection represents a downgraded IMS conference.
385 * @hide
386 */
387 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
388
Tyler Gunnf5035432017-01-09 09:43:12 -0800389 /**
390 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
391 * {@link ConnectionService}.
392 * <p>
393 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
394 */
395 public static final int PROPERTY_SELF_MANAGED = 1<<7;
396
Hall Liu95d55872017-01-25 17:12:49 -0800397 /**
398 * When set, indicates that a connection has an active RTT session associated with it.
399 * @hide
400 */
401 public static final int PROPERTY_IS_RTT = 1 << 8;
402
Tyler Gunn96d6c402015-03-18 12:39:23 -0700403 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800404 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700405 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800406
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700407 /**
408 * Connection extra key used to store the last forwarded number associated with the current
409 * connection. Used to communicate to the user interface that the connection was forwarded via
410 * the specified number.
411 */
412 public static final String EXTRA_LAST_FORWARDED_NUMBER =
413 "android.telecom.extra.LAST_FORWARDED_NUMBER";
414
415 /**
416 * Connection extra key used to store a child number associated with the current connection.
417 * Used to communicate to the user interface that the connection was received via
418 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
419 * address.
420 */
421 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
422
423 /**
424 * Connection extra key used to store the subject for an incoming call. The user interface can
425 * query this extra and display its contents for incoming calls. Will only be used if the
426 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
427 */
428 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
429
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800430 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700431 * Boolean connection extra key set on a {@link Connection} in
432 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
433 * current active foreground call to be dropped.
434 */
435 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
436 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
437
438 /**
Hall Liu10208662016-06-15 17:55:00 -0700439 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700440 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700441 * @hide
442 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700443 public static final String EXTRA_DISABLE_ADD_CALL =
444 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700445
446 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700447 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
448 * original Connection ID associated with the connection. Used in
449 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
450 * connection/conference added via
451 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
452 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
453 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
454 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
455 * be a way to ensure that we don't add the connection again as a duplicate.
456 * <p>
457 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
458 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
459 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
460 * in a new {@link Connection} which it adds to Telecom via
461 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
462 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
463 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
464 * ID it originally referred to the connection as. Thus Telecom needs to know that the
465 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
466 * @hide
467 */
468 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
469 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
470
471 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800472 * Connection event used to inform Telecom that it should play the on hold tone. This is used
473 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700474 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800475 * @hide
476 */
477 public static final String EVENT_ON_HOLD_TONE_START =
478 "android.telecom.event.ON_HOLD_TONE_START";
479
480 /**
481 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
482 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700483 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800484 * @hide
485 */
486 public static final String EVENT_ON_HOLD_TONE_END =
487 "android.telecom.event.ON_HOLD_TONE_END";
488
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700489 /**
490 * Connection event used to inform {@link InCallService}s when pulling of an external call has
491 * failed. The user interface should inform the user of the error.
492 * <p>
493 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
494 * API is called on a {@link Call} with the properties
495 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
496 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
497 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700498 * <p>
499 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
500 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700501 */
502 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
503
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700504 /**
505 * Connection event used to inform {@link InCallService}s when the merging of two calls has
506 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700507 * <p>
508 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
509 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700510 */
511 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
512
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700513 /**
514 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
515 * the remote party.
516 * <p>
517 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
518 * call is being held locally on the device. When a capable {@link ConnectionService} receives
519 * signalling to indicate that the remote party has put the call on hold, it can send this
520 * connection event.
521 * @hide
522 */
523 public static final String EVENT_CALL_REMOTELY_HELD =
524 "android.telecom.event.CALL_REMOTELY_HELD";
525
526 /**
527 * Connection event used to inform {@link InCallService}s when a call which was remotely held
528 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
529 * <p>
530 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
531 * call is being held locally on the device. When a capable {@link ConnectionService} receives
532 * signalling to indicate that the remote party has taken the call off hold, it can send this
533 * connection event.
534 * @hide
535 */
536 public static final String EVENT_CALL_REMOTELY_UNHELD =
537 "android.telecom.event.CALL_REMOTELY_UNHELD";
538
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700539 // Flag controlling whether PII is emitted into the logs
540 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
541
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800542 /**
543 * Whether the given capabilities support the specified capability.
544 *
545 * @param capabilities A capability bit field.
546 * @param capability The capability to check capabilities for.
547 * @return Whether the specified capability is supported.
548 * @hide
549 */
550 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800551 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800552 }
553
554 /**
555 * Whether the capabilities of this {@code Connection} supports the specified capability.
556 *
557 * @param capability The capability to check capabilities for.
558 * @return Whether the specified capability is supported.
559 * @hide
560 */
561 public boolean can(int capability) {
562 return can(mConnectionCapabilities, capability);
563 }
564
565 /**
566 * Removes the specified capability from the set of capabilities of this {@code Connection}.
567 *
568 * @param capability The capability to remove from the set.
569 * @hide
570 */
571 public void removeCapability(int capability) {
572 mConnectionCapabilities &= ~capability;
573 }
574
575 /**
576 * Adds the specified capability to the set of capabilities of this {@code Connection}.
577 *
578 * @param capability The capability to add to the set.
579 * @hide
580 */
581 public void addCapability(int capability) {
582 mConnectionCapabilities |= capability;
583 }
584
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700585 /**
586 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
587 *
588 * @param capabilities A capability bit field.
589 * @return A human readable string representation.
590 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800591 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700592 return capabilitiesToStringInternal(capabilities, true /* isLong */);
593 }
594
595 /**
596 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
597 * string.
598 *
599 * @param capabilities A capability bit field.
600 * @return A human readable string representation.
601 * @hide
602 */
603 public static String capabilitiesToStringShort(int capabilities) {
604 return capabilitiesToStringInternal(capabilities, false /* isLong */);
605 }
606
607 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800608 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700609 builder.append("[");
610 if (isLong) {
611 builder.append("Capabilities:");
612 }
613
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800614 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700615 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800616 }
617 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700618 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800619 }
620 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700621 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800622 }
623 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700624 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800625 }
626 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700627 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800628 }
629 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700630 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
632 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700633 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800634 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700635 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700636 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700637 }
638 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700639 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700640 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700641 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700642 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800643 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700644 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700645 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700646 }
647 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700648 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700649 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700650 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700651 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800652 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800653 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700654 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800655 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500656 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700657 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500658 }
Rekha Kumar07366812015-03-24 16:42:31 -0700659 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700661 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700662 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700664 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700665 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700667 }
Bryce Lee81901682015-08-28 16:38:02 -0700668 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700670 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700671 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700673 }
Bryce Lee81901682015-08-28 16:38:02 -0700674
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800675 builder.append("]");
676 return builder.toString();
677 }
678
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700679 /**
680 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
681 *
682 * @param properties A property bit field.
683 * @return A human readable string representation.
684 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700685 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700686 return propertiesToStringInternal(properties, true /* isLong */);
687 }
688
689 /**
690 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
691 *
692 * @param properties A property bit field.
693 * @return A human readable string representation.
694 * @hide
695 */
696 public static String propertiesToStringShort(int properties) {
697 return propertiesToStringInternal(properties, false /* isLong */);
698 }
699
700 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700701 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append("[");
703 if (isLong) {
704 builder.append("Properties:");
705 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700706
Tyler Gunnf5035432017-01-09 09:43:12 -0800707 if (can(properties, PROPERTY_SELF_MANAGED)) {
708 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
709 }
710
Hall Liu25c7c4d2016-08-30 13:41:02 -0700711 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
712 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700713 }
714
715 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700716 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700717 }
718
719 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700721 }
722
723 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700725 }
726
727 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700729 }
730
Brad Ebinger15847072016-05-18 11:08:36 -0700731 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700732 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700733 }
734
Tyler Gunn720c6642016-03-22 09:02:47 -0700735 builder.append("]");
736 return builder.toString();
737 }
738
Sailesh Nepal091768c2014-06-30 15:15:23 -0700739 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700740 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700741 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700742 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700743 public void onCallerDisplayNameChanged(
744 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700745 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700746 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700747 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800748 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700749 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700750 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800751 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700752 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800753 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 public void onVideoProviderChanged(
755 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700756 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
757 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800758 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700759 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700760 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700761 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800762 public void onConferenceParticipantsChanged(Connection c,
763 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800764 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700765 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700766 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700767 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700768 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700769 /** @hide */
770 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800771 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800772 public void onRttInitiationSuccess(Connection c) {}
773 public void onRttInitiationFailure(Connection c, int reason) {}
774 public void onRttSessionRemotelyTerminated(Connection c) {}
775 public void onRemoteRttRequest(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700776 }
777
Tyler Gunnb702ef82015-05-29 11:51:53 -0700778 /**
Hall Liu95d55872017-01-25 17:12:49 -0800779 * Provides methods to read and write RTT data to/from the in-call app.
780 * @hide
781 */
782 public static final class RttTextStream {
783 private static final int READ_BUFFER_SIZE = 1000;
784 private final InputStreamReader mPipeFromInCall;
785 private final OutputStreamWriter mPipeToInCall;
Hall Liu57006aa2017-02-06 10:49:48 -0800786 private final ParcelFileDescriptor mFdFromInCall;
787 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800788 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
789
790 /**
791 * @hide
792 */
793 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liu57006aa2017-02-06 10:49:48 -0800794 mFdFromInCall = fromInCall;
795 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800796 mPipeFromInCall = new InputStreamReader(
797 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
798 mPipeToInCall = new OutputStreamWriter(
799 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
800 }
801
802 /**
803 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
804 * RTT transmits text in real-time, this method should be called as often as text snippets
805 * are received from the remote user, even if it is only one character.
806 *
807 * This method is not thread-safe -- calling it from multiple threads simultaneously may
808 * lead to interleaved text.
809 * @param input The message to send to the in-call app.
810 */
811 public void write(String input) throws IOException {
812 mPipeToInCall.write(input);
813 mPipeToInCall.flush();
814 }
815
816
817 /**
818 * Reads a string from the in-call app, blocking if there is no data available. Returns
819 * {@code null} if the RTT conversation has been terminated and there is no further data
820 * to read.
821 *
822 * This method is not thread-safe -- calling it from multiple threads simultaneously may
823 * lead to interleaved text.
824 * @return A string containing text entered by the user, or {@code null} if the
825 * conversation has been terminated or if there was an error while reading.
826 */
827 public String read() {
828 try {
829 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
830 if (numRead < 0) {
831 return null;
832 }
833 return new String(mReadBuffer, 0, numRead);
834 } catch (IOException e) {
835 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
836 return null;
837 }
838 }
Hall Liu57006aa2017-02-06 10:49:48 -0800839
840 /** @hide */
841 public ParcelFileDescriptor getFdFromInCall() {
842 return mFdFromInCall;
843 }
844
845 /** @hide */
846 public ParcelFileDescriptor getFdToInCall() {
847 return mFdToInCall;
848 }
849 }
850
851 /**
852 * Provides constants to represent the results of responses to session modify requests sent via
853 * {@link Call#sendRttRequest()}
854 */
855 public static final class RttModifyStatus {
856 /**
857 * Session modify request was successful.
858 */
859 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
860
861 /**
862 * Session modify request failed.
863 */
864 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
865
866 /**
867 * Session modify request ignored due to invalid parameters.
868 */
869 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
870
871 /**
872 * Session modify request timed out.
873 */
874 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
875
876 /**
877 * Session modify request rejected by remote user.
878 */
879 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800880 }
881
882 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * Provides a means of controlling the video session associated with a {@link Connection}.
884 * <p>
885 * Implementations create a custom subclass of {@link VideoProvider} and the
886 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
887 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
888 * should set the {@link VideoProvider}.
889 * <p>
890 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
891 * {@link InCallService} implementations to issue requests related to the video session;
892 * it provides a means for the {@link ConnectionService} to report events and information
893 * related to the video session to Telecom and the {@link InCallService} implementations.
894 * <p>
895 * {@link InCallService} implementations interact with the {@link VideoProvider} via
896 * {@link android.telecom.InCallService.VideoCall}.
897 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700898 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700899 /**
900 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700901 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 */
903 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700904
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
907 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700908 */
909 public static final int SESSION_EVENT_RX_RESUME = 2;
910
911 /**
912 * Video transmission has begun. This occurs after a negotiated start of video transmission
913 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700914 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 */
916 public static final int SESSION_EVENT_TX_START = 3;
917
918 /**
919 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
920 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700921 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700922 */
923 public static final int SESSION_EVENT_TX_STOP = 4;
924
925 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800926 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700927 * this as a cue to inform the user the camera is not available.
928 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700929 */
930 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
931
932 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700933 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800934 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700935 * the camera has become available again.
936 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700937 */
938 public static final int SESSION_EVENT_CAMERA_READY = 6;
939
940 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800941 * Session event raised by Telecom when
942 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
943 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
944 * @see #handleCallSessionEvent(int)
945 */
946 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
947
948 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700950 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 */
952 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
953
954 /**
955 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700956 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700957 */
958 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
959
960 /**
961 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700962 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 */
964 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
965
Rekha Kumar07366812015-03-24 16:42:31 -0700966 /**
967 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700968 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700969 */
970 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
971
972 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700973 * Session modify request rejected by remote user.
974 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700975 */
976 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
977
Tyler Gunn75958422015-04-15 14:23:42 -0700978 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 private static final int MSG_SET_CAMERA = 2;
980 private static final int MSG_SET_PREVIEW_SURFACE = 3;
981 private static final int MSG_SET_DISPLAY_SURFACE = 4;
982 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
983 private static final int MSG_SET_ZOOM = 6;
984 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
985 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
986 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800987 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700988 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700989 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700991 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
992 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
993 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
994 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
995 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
996 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800997 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
998 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700999 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1000
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001001 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001003
1004 /**
1005 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001006 *
1007 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1008 * load factor before resizing, 1 means we only expect a single thread to
1009 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001010 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001011 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1012 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001013
1014 /**
1015 * Default handler used to consolidate binder method calls onto a single thread.
1016 */
1017 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001018 public VideoProviderHandler() {
1019 super();
1020 }
1021
1022 public VideoProviderHandler(Looper looper) {
1023 super(looper);
1024 }
1025
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001026 @Override
1027 public void handleMessage(Message msg) {
1028 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001029 case MSG_ADD_VIDEO_CALLBACK: {
1030 IBinder binder = (IBinder) msg.obj;
1031 IVideoCallback callback = IVideoCallback.Stub
1032 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001033 if (callback == null) {
1034 Log.w(this, "addVideoProvider - skipped; callback is null.");
1035 break;
1036 }
1037
Tyler Gunn75958422015-04-15 14:23:42 -07001038 if (mVideoCallbacks.containsKey(binder)) {
1039 Log.i(this, "addVideoProvider - skipped; already present.");
1040 break;
1041 }
1042 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001044 }
1045 case MSG_REMOVE_VIDEO_CALLBACK: {
1046 IBinder binder = (IBinder) msg.obj;
1047 IVideoCallback callback = IVideoCallback.Stub
1048 .asInterface((IBinder) msg.obj);
1049 if (!mVideoCallbacks.containsKey(binder)) {
1050 Log.i(this, "removeVideoProvider - skipped; not present.");
1051 break;
1052 }
1053 mVideoCallbacks.remove(binder);
1054 break;
1055 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001057 {
1058 SomeArgs args = (SomeArgs) msg.obj;
1059 try {
1060 onSetCamera((String) args.arg1);
1061 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001062 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001063 } finally {
1064 args.recycle();
1065 }
1066 }
1067 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 case MSG_SET_PREVIEW_SURFACE:
1069 onSetPreviewSurface((Surface) msg.obj);
1070 break;
1071 case MSG_SET_DISPLAY_SURFACE:
1072 onSetDisplaySurface((Surface) msg.obj);
1073 break;
1074 case MSG_SET_DEVICE_ORIENTATION:
1075 onSetDeviceOrientation(msg.arg1);
1076 break;
1077 case MSG_SET_ZOOM:
1078 onSetZoom((Float) msg.obj);
1079 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001080 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1081 SomeArgs args = (SomeArgs) msg.obj;
1082 try {
1083 onSendSessionModifyRequest((VideoProfile) args.arg1,
1084 (VideoProfile) args.arg2);
1085 } finally {
1086 args.recycle();
1087 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001089 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001090 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1091 onSendSessionModifyResponse((VideoProfile) msg.obj);
1092 break;
1093 case MSG_REQUEST_CAMERA_CAPABILITIES:
1094 onRequestCameraCapabilities();
1095 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001096 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1097 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098 break;
1099 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001100 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 break;
1102 default:
1103 break;
1104 }
1105 }
1106 }
1107
1108 /**
1109 * IVideoProvider stub implementation.
1110 */
1111 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001112 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001114 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1115 }
1116
1117 public void removeVideoCallback(IBinder videoCallbackBinder) {
1118 mMessageHandler.obtainMessage(
1119 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001120 }
1121
Tyler Gunn159f35c2017-03-02 09:28:37 -08001122 public void setCamera(String cameraId, String callingPackageName,
1123 int targetSdkVersion) {
1124
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001125 SomeArgs args = SomeArgs.obtain();
1126 args.arg1 = cameraId;
1127 // Propagate the calling package; originally determined in
1128 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1129 // process.
1130 args.arg2 = callingPackageName;
1131 // Pass along the uid and pid of the calling app; this gets lost when we put the
1132 // message onto the handler. These are required for Telecom to perform a permission
1133 // check to see if the calling app is able to use the camera.
1134 args.argi1 = Binder.getCallingUid();
1135 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001136 // Pass along the target SDK version of the calling InCallService. This is used to
1137 // maintain backwards compatibility of the API for older callers.
1138 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001139 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 }
1141
1142 public void setPreviewSurface(Surface surface) {
1143 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1144 }
1145
1146 public void setDisplaySurface(Surface surface) {
1147 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1148 }
1149
1150 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001151 mMessageHandler.obtainMessage(
1152 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 }
1154
1155 public void setZoom(float value) {
1156 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1157 }
1158
Tyler Gunn45382162015-05-06 08:52:27 -07001159 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1160 SomeArgs args = SomeArgs.obtain();
1161 args.arg1 = fromProfile;
1162 args.arg2 = toProfile;
1163 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 }
1165
1166 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1167 mMessageHandler.obtainMessage(
1168 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1169 }
1170
1171 public void requestCameraCapabilities() {
1172 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1173 }
1174
1175 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001176 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 }
1178
Yorke Lee32f24732015-05-12 16:18:03 -07001179 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1181 }
1182 }
1183
1184 public VideoProvider() {
1185 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001186 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001187 }
1188
1189 /**
1190 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1191 *
1192 * @param looper The looper.
1193 * @hide
1194 */
1195 public VideoProvider(Looper looper) {
1196 mBinder = new VideoProvider.VideoProviderBinder();
1197 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001198 }
1199
1200 /**
1201 * Returns binder object which can be used across IPC methods.
1202 * @hide
1203 */
1204 public final IVideoProvider getInterface() {
1205 return mBinder;
1206 }
1207
1208 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001209 * Sets the camera to be used for the outgoing video.
1210 * <p>
1211 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1212 * camera via
1213 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1214 * <p>
1215 * Sent from the {@link InCallService} via
1216 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001217 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001218 * @param cameraId The id of the camera (use ids as reported by
1219 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001220 */
1221 public abstract void onSetCamera(String cameraId);
1222
1223 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001224 * Sets the camera to be used for the outgoing video.
1225 * <p>
1226 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1227 * camera via
1228 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1229 * <p>
1230 * This prototype is used internally to ensure that the calling package name, UID and PID
1231 * are sent to Telecom so that can perform a camera permission check on the caller.
1232 * <p>
1233 * Sent from the {@link InCallService} via
1234 * {@link InCallService.VideoCall#setCamera(String)}.
1235 *
1236 * @param cameraId The id of the camera (use ids as reported by
1237 * {@link CameraManager#getCameraIdList()}).
1238 * @param callingPackageName The AppOpps package name of the caller.
1239 * @param callingUid The UID of the caller.
1240 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001241 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001242 * @hide
1243 */
1244 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001245 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001246
1247 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 * Sets the surface to be used for displaying a preview of what the user's camera is
1249 * currently capturing. When video transmission is enabled, this is the video signal which
1250 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001251 * <p>
1252 * Sent from the {@link InCallService} via
1253 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001254 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001255 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001256 */
1257 public abstract void onSetPreviewSurface(Surface surface);
1258
1259 /**
1260 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001261 * <p>
1262 * Sent from the {@link InCallService} via
1263 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001265 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001266 */
1267 public abstract void onSetDisplaySurface(Surface surface);
1268
1269 /**
1270 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1271 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001272 * <p>
1273 * Sent from the {@link InCallService} via
1274 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 *
1276 * @param rotation The device orientation, in degrees.
1277 */
1278 public abstract void onSetDeviceOrientation(int rotation);
1279
1280 /**
1281 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * <p>
1283 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 *
1285 * @param value The camera zoom ratio.
1286 */
1287 public abstract void onSetZoom(float value);
1288
1289 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001290 * Issues a request to modify the properties of the current video session.
1291 * <p>
1292 * Example scenarios include: requesting an audio-only call to be upgraded to a
1293 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1294 * when the {@link InCallService} is no longer the foreground application.
1295 * <p>
1296 * If the {@link VideoProvider} determines a request to be invalid, it should call
1297 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1298 * invalid request back to the {@link InCallService}.
1299 * <p>
1300 * Where a request requires confirmation from the user of the peer device, the
1301 * {@link VideoProvider} must communicate the request to the peer device and handle the
1302 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1303 * is used to inform the {@link InCallService} of the result of the request.
1304 * <p>
1305 * Sent from the {@link InCallService} via
1306 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001308 * @param fromProfile The video profile prior to the request.
1309 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 */
Tyler Gunn45382162015-05-06 08:52:27 -07001311 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1312 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313
Tyler Gunnb702ef82015-05-29 11:51:53 -07001314 /**
1315 * Provides a response to a request to change the current video session properties.
1316 * <p>
1317 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1318 * video call, could decline the request and keep the call as audio-only.
1319 * In such a scenario, the {@code responseProfile} would have a video state of
1320 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1321 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1322 * <p>
1323 * Sent from the {@link InCallService} via
1324 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1325 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1326 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001328 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001329 */
1330 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1331
1332 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001333 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1334 * <p>
1335 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1336 * camera via
1337 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1338 * <p>
1339 * Sent from the {@link InCallService} via
1340 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 */
1342 public abstract void onRequestCameraCapabilities();
1343
1344 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001345 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1346 * video component of the current {@link Connection}.
1347 * <p>
1348 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1349 * via {@link VideoProvider#setCallDataUsage(long)}.
1350 * <p>
1351 * Sent from the {@link InCallService} via
1352 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001354 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355
1356 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001357 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1358 * the peer device when the video signal is paused.
1359 * <p>
1360 * Sent from the {@link InCallService} via
1361 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001362 *
1363 * @param uri URI of image to display.
1364 */
Yorke Lee32f24732015-05-12 16:18:03 -07001365 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366
1367 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001368 * Used to inform listening {@link InCallService} implementations when the
1369 * {@link VideoProvider} receives a session modification request.
1370 * <p>
1371 * Received by the {@link InCallService} via
1372 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 * @param videoProfile The requested video profile.
1375 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 */
1377 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001378 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001379 for (IVideoCallback callback : mVideoCallbacks.values()) {
1380 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001381 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001382 } catch (RemoteException ignored) {
1383 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001384 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001385 }
1386 }
1387 }
1388
1389 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001390 * Used to inform listening {@link InCallService} implementations when the
1391 * {@link VideoProvider} receives a response to a session modification request.
1392 * <p>
1393 * Received by the {@link InCallService} via
1394 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1395 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 *
1397 * @param status Status of the session modify request. Valid values are
1398 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1399 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001400 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1401 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1402 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1403 * @param requestedProfile The original request which was sent to the peer device.
1404 * @param responseProfile The actual profile changes agreed to by the peer device.
1405 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 */
1407 public void receiveSessionModifyResponse(int status,
1408 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001409 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001410 for (IVideoCallback callback : mVideoCallbacks.values()) {
1411 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001412 callback.receiveSessionModifyResponse(status, requestedProfile,
1413 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001414 } catch (RemoteException ignored) {
1415 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001416 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001417 }
1418 }
1419 }
1420
1421 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001422 * Used to inform listening {@link InCallService} implementations when the
1423 * {@link VideoProvider} reports a call session event.
1424 * <p>
1425 * Received by the {@link InCallService} via
1426 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1429 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1430 * {@link VideoProvider#SESSION_EVENT_TX_START},
1431 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1432 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001433 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1434 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001435 */
1436 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001437 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001438 for (IVideoCallback callback : mVideoCallbacks.values()) {
1439 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001440 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001441 } catch (RemoteException ignored) {
1442 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001443 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 }
1445 }
1446 }
1447
1448 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001449 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1450 * peer's video have changed.
1451 * <p>
1452 * This could occur if, for example, the peer rotates their device, changing the aspect
1453 * ratio of the video, or if the user switches between the back and front cameras.
1454 * <p>
1455 * Received by the {@link InCallService} via
1456 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 *
1458 * @param width The updated peer video width.
1459 * @param height The updated peer video height.
1460 */
1461 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001462 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001463 for (IVideoCallback callback : mVideoCallbacks.values()) {
1464 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001465 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001466 } catch (RemoteException ignored) {
1467 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001468 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001469 }
1470 }
1471 }
1472
1473 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001474 * Used to inform listening {@link InCallService} implementations when the data usage of the
1475 * video associated with the current {@link Connection} has changed.
1476 * <p>
1477 * This could be in response to a preview request via
1478 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001479 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1480 * 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 -07001481 * <p>
1482 * Received by the {@link InCallService} via
1483 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001485 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1486 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 */
Yorke Lee32f24732015-05-12 16:18:03 -07001488 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001489 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001490 for (IVideoCallback callback : mVideoCallbacks.values()) {
1491 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001492 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001493 } catch (RemoteException ignored) {
1494 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001495 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 }
1497 }
1498 }
1499
1500 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001501 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001503 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001504 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1505 * @hide
1506 */
1507 public void changeCallDataUsage(long dataUsage) {
1508 setCallDataUsage(dataUsage);
1509 }
1510
1511 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001512 * Used to inform listening {@link InCallService} implementations when the capabilities of
1513 * the current camera have changed.
1514 * <p>
1515 * The {@link VideoProvider} should call this in response to
1516 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1517 * changed via {@link VideoProvider#onSetCamera(String)}.
1518 * <p>
1519 * Received by the {@link InCallService} via
1520 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1521 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001522 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001523 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001524 */
Yorke Lee400470f2015-05-12 13:31:25 -07001525 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001526 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001527 for (IVideoCallback callback : mVideoCallbacks.values()) {
1528 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001529 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001530 } catch (RemoteException ignored) {
1531 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001532 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001533 }
1534 }
1535 }
Rekha Kumar07366812015-03-24 16:42:31 -07001536
1537 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001538 * Used to inform listening {@link InCallService} implementations when the video quality
1539 * of the call has changed.
1540 * <p>
1541 * Received by the {@link InCallService} via
1542 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001543 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001544 * @param videoQuality The updated video quality. Valid values:
1545 * {@link VideoProfile#QUALITY_HIGH},
1546 * {@link VideoProfile#QUALITY_MEDIUM},
1547 * {@link VideoProfile#QUALITY_LOW},
1548 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001549 */
1550 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001551 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001552 for (IVideoCallback callback : mVideoCallbacks.values()) {
1553 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001554 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001555 } catch (RemoteException ignored) {
1556 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001557 }
Rekha Kumar07366812015-03-24 16:42:31 -07001558 }
1559 }
1560 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001561
1562 /**
1563 * Returns a string representation of a call session event.
1564 *
1565 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1566 * @return String representation of the call session event.
1567 * @hide
1568 */
1569 public static String sessionEventToString(int event) {
1570 switch (event) {
1571 case SESSION_EVENT_CAMERA_FAILURE:
1572 return SESSION_EVENT_CAMERA_FAILURE_STR;
1573 case SESSION_EVENT_CAMERA_READY:
1574 return SESSION_EVENT_CAMERA_READY_STR;
1575 case SESSION_EVENT_RX_PAUSE:
1576 return SESSION_EVENT_RX_PAUSE_STR;
1577 case SESSION_EVENT_RX_RESUME:
1578 return SESSION_EVENT_RX_RESUME_STR;
1579 case SESSION_EVENT_TX_START:
1580 return SESSION_EVENT_TX_START_STR;
1581 case SESSION_EVENT_TX_STOP:
1582 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001583 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1584 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001585 default:
1586 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1587 }
1588 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001589 }
1590
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001591 private final Listener mConnectionDeathListener = new Listener() {
1592 @Override
1593 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001594 if (mConferenceables.remove(c)) {
1595 fireOnConferenceableConnectionsChanged();
1596 }
1597 }
1598 };
1599
1600 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1601 @Override
1602 public void onDestroyed(Conference c) {
1603 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001604 fireOnConferenceableConnectionsChanged();
1605 }
1606 }
1607 };
1608
Jay Shrauner229e3822014-08-15 09:23:07 -07001609 /**
1610 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1611 * load factor before resizing, 1 means we only expect a single thread to
1612 * access the map so make only a single shard
1613 */
1614 private final Set<Listener> mListeners = Collections.newSetFromMap(
1615 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001616 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1617 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001618 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001619
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001620 // The internal telecom call ID associated with this connection.
1621 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001622 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001623 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001624 private Uri mAddress;
1625 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001626 private String mCallerDisplayName;
1627 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001628 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001629 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001630 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001631 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001632 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001633 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001634 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001635 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001636 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001637 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001638 private Conference mConference;
1639 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001640 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001641 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001642
1643 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001644 * Tracks the key set for the extras bundle provided on the last invocation of
1645 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1646 * keys which were set previously but are no longer present in the replacement Bundle.
1647 */
1648 private Set<String> mPreviousExtraKeys;
1649
1650 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001651 * Create a new Connection.
1652 */
Santos Cordonf2951102014-07-20 19:06:29 -07001653 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001654
1655 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001656 * Returns the Telecom internal call ID associated with this connection. Should only be used
1657 * for debugging and tracing purposes.
1658 *
1659 * @return The Telecom call ID.
1660 * @hide
1661 */
1662 public final String getTelecomCallId() {
1663 return mTelecomCallId;
1664 }
1665
1666 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001667 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001668 */
Andrew Lee100e2932014-09-08 15:34:24 -07001669 public final Uri getAddress() {
1670 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001671 }
1672
1673 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001674 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001675 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001676 */
Andrew Lee100e2932014-09-08 15:34:24 -07001677 public final int getAddressPresentation() {
1678 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001679 }
1680
1681 /**
1682 * @return The caller display name (CNAP).
1683 */
1684 public final String getCallerDisplayName() {
1685 return mCallerDisplayName;
1686 }
1687
1688 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001689 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001690 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001691 */
1692 public final int getCallerDisplayNamePresentation() {
1693 return mCallerDisplayNamePresentation;
1694 }
1695
1696 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001697 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001698 */
1699 public final int getState() {
1700 return mState;
1701 }
1702
1703 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001704 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001705 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1706 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1707 * {@link VideoProfile#STATE_TX_ENABLED},
1708 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001709 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001710 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001711 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001712 */
1713 public final int getVideoState() {
1714 return mVideoState;
1715 }
1716
1717 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001718 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001719 * being routed by the system. This is {@code null} if this Connection
1720 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001721 * @deprecated Use {@link #getCallAudioState()} instead.
1722 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723 */
Yorke Lee4af59352015-05-13 14:14:54 -07001724 @SystemApi
1725 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001726 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001727 if (mCallAudioState == null) {
1728 return null;
1729 }
Yorke Lee4af59352015-05-13 14:14:54 -07001730 return new AudioState(mCallAudioState);
1731 }
1732
1733 /**
1734 * @return The audio state of the connection, describing how its audio is currently
1735 * being routed by the system. This is {@code null} if this Connection
1736 * does not directly know about its audio state.
1737 */
1738 public final CallAudioState getCallAudioState() {
1739 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001740 }
1741
1742 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001743 * @return The conference that this connection is a part of. Null if it is not part of any
1744 * conference.
1745 */
1746 public final Conference getConference() {
1747 return mConference;
1748 }
1749
1750 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001751 * Returns whether this connection is requesting that the system play a ringback tone
1752 * on its behalf.
1753 */
Andrew Lee100e2932014-09-08 15:34:24 -07001754 public final boolean isRingbackRequested() {
1755 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001756 }
1757
1758 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001759 * @return True if the connection's audio mode is VOIP.
1760 */
1761 public final boolean getAudioModeIsVoip() {
1762 return mAudioModeIsVoip;
1763 }
1764
1765 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001766 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1767 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1768 * start time of the conference.
1769 *
1770 * @return The time at which the {@code Connnection} was connected.
1771 *
1772 * @hide
1773 */
1774 public final long getConnectTimeMillis() {
1775 return mConnectTimeMillis;
1776 }
1777
1778 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001779 * @return The status hints for this connection.
1780 */
1781 public final StatusHints getStatusHints() {
1782 return mStatusHints;
1783 }
1784
1785 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001786 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001787 * <p>
1788 * Extras should be updated using {@link #putExtras(Bundle)}.
1789 * <p>
1790 * Telecom or an {@link InCallService} can also update the extras via
1791 * {@link android.telecom.Call#putExtras(Bundle)}, and
1792 * {@link Call#removeExtras(List)}.
1793 * <p>
1794 * The connection is notified of changes to the extras made by Telecom or an
1795 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001796 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001797 * @return The extras associated with this connection.
1798 */
1799 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001800 Bundle extras = null;
1801 synchronized (mExtrasLock) {
1802 if (mExtras != null) {
1803 extras = new Bundle(mExtras);
1804 }
1805 }
1806 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001807 }
1808
1809 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001810 * Assign a listener to be notified of state changes.
1811 *
1812 * @param l A listener.
1813 * @return This Connection.
1814 *
1815 * @hide
1816 */
1817 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001818 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001819 return this;
1820 }
1821
1822 /**
1823 * Remove a previously assigned listener that was being notified of state changes.
1824 *
1825 * @param l A Listener.
1826 * @return This Connection.
1827 *
1828 * @hide
1829 */
1830 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001831 if (l != null) {
1832 mListeners.remove(l);
1833 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001834 return this;
1835 }
1836
1837 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001838 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001839 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001840 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001841 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001842 }
1843
1844 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001845 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1846 * ONLY for debugging purposes.
1847 *
1848 * @param callId The telecom call ID.
1849 * @hide
1850 */
1851 public void setTelecomCallId(String callId) {
1852 mTelecomCallId = callId;
1853 }
1854
1855 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001856 * Inform this Connection that the state of its audio output has been changed externally.
1857 *
1858 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001859 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001860 */
Yorke Lee4af59352015-05-13 14:14:54 -07001861 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001862 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001863 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001864 mCallAudioState = state;
1865 onAudioStateChanged(getAudioState());
1866 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001867 }
1868
1869 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001870 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001871 * @return A string representation of the value.
1872 */
1873 public static String stateToString(int state) {
1874 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001876 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001878 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001879 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001880 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001881 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001882 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001883 case STATE_PULLING_CALL:
1884 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001885 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001886 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001887 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001888 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001889 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001890 return "DISCONNECTED";
1891 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001892 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001893 return "UNKNOWN";
1894 }
1895 }
1896
1897 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001898 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001899 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001900 public final int getConnectionCapabilities() {
1901 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001902 }
1903
1904 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001905 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1906 */
1907 public final int getConnectionProperties() {
1908 return mConnectionProperties;
1909 }
1910
1911 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001912 * Returns the connection's supported audio routes.
1913 *
1914 * @hide
1915 */
1916 public final int getSupportedAudioRoutes() {
1917 return mSupportedAudioRoutes;
1918 }
1919
1920 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001921 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001922 *
Andrew Lee100e2932014-09-08 15:34:24 -07001923 * @param address The new address.
1924 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001925 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001926 */
Andrew Lee100e2932014-09-08 15:34:24 -07001927 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001928 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001929 Log.d(this, "setAddress %s", address);
1930 mAddress = address;
1931 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001932 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001933 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001934 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001935 }
1936
1937 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001938 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001939 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001940 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001941 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001942 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001943 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001944 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001945 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001946 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001947 mCallerDisplayName = callerDisplayName;
1948 mCallerDisplayNamePresentation = presentation;
1949 for (Listener l : mListeners) {
1950 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1951 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001952 }
1953
1954 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001955 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001956 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1957 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1958 * {@link VideoProfile#STATE_TX_ENABLED},
1959 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001960 *
1961 * @param videoState The new video state.
1962 */
1963 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001964 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001965 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001966 mVideoState = videoState;
1967 for (Listener l : mListeners) {
1968 l.onVideoStateChanged(this, mVideoState);
1969 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001970 }
1971
1972 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001973 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001974 * communicate).
1975 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001976 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001977 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001978 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001979 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001980 }
1981
1982 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001983 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001984 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001985 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001986 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001987 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001988 }
1989
1990 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001991 * Sets state to initializing (this Connection is not yet ready to be used).
1992 */
1993 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001994 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001995 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001996 }
1997
1998 /**
1999 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2000 */
2001 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002002 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002003 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002004 }
2005
2006 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002007 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002008 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002009 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002010 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002011 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002012 }
2013
2014 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002015 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2016 * device). Only applicable for {@link Connection}s with
2017 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2018 */
2019 public final void setPulling() {
2020 checkImmutable();
2021 setState(STATE_PULLING_CALL);
2022 }
2023
2024 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002025 * Sets state to be on hold.
2026 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002027 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002028 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002029 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002030 }
2031
2032 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002033 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002034 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002035 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002036 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002037 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002038 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002039 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002040 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002041 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002042 }
2043
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002044 public final VideoProvider getVideoProvider() {
2045 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002046 }
2047
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002048 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002049 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002050 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002051 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002052 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002053 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002054 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002055 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002056 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002057 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002058 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002059 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002060 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002061 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002062 }
2063
2064 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002065 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2066 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2067 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2068 * to send an {@link #onPostDialContinue(boolean)} signal.
2069 *
2070 * @param remaining The DTMF character sequence remaining to be emitted once the
2071 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2072 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002073 */
2074 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002075 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002076 for (Listener l : mListeners) {
2077 l.onPostDialWait(this, remaining);
2078 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002079 }
2080
2081 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002082 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2083 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002084 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002085 *
2086 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002087 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002088 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002089 checkImmutable();
2090 for (Listener l : mListeners) {
2091 l.onPostDialChar(this, nextChar);
2092 }
2093 }
2094
2095 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002096 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002098 *
2099 * @param ringback Whether the ringback tone is to be played.
2100 */
Andrew Lee100e2932014-09-08 15:34:24 -07002101 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002102 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002103 if (mRingbackRequested != ringback) {
2104 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002105 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002106 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002107 }
2108 }
Ihab Awadf8358972014-05-28 16:46:42 -07002109 }
2110
2111 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002112 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002113 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002114 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002115 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 public final void setConnectionCapabilities(int connectionCapabilities) {
2117 checkImmutable();
2118 if (mConnectionCapabilities != connectionCapabilities) {
2119 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002120 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002121 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002122 }
2123 }
Santos Cordonb6939982014-06-04 20:20:58 -07002124 }
2125
2126 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002127 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2128 *
2129 * @param connectionProperties The new connection properties.
2130 */
2131 public final void setConnectionProperties(int connectionProperties) {
2132 checkImmutable();
2133 if (mConnectionProperties != connectionProperties) {
2134 mConnectionProperties = connectionProperties;
2135 for (Listener l : mListeners) {
2136 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2137 }
2138 }
2139 }
2140
2141 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002142 * Sets the supported audio routes.
2143 *
2144 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2145 * See {@link CallAudioState}
2146 * @hide
2147 */
2148 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2149 if ((supportedAudioRoutes
2150 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2151 throw new IllegalArgumentException(
2152 "supported audio routes must include either speaker or earpiece");
2153 }
2154
2155 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2156 mSupportedAudioRoutes = supportedAudioRoutes;
2157 for (Listener l : mListeners) {
2158 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2159 }
2160 }
2161 }
2162
2163 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002164 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002165 */
Evan Charlton36a71342014-07-19 16:31:02 -07002166 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002167 for (Listener l : mListeners) {
2168 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002169 }
Santos Cordonb6939982014-06-04 20:20:58 -07002170 }
2171
2172 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002173 * Requests that the framework use VOIP audio mode for this connection.
2174 *
2175 * @param isVoip True if the audio mode is VOIP.
2176 */
2177 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002178 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002179 mAudioModeIsVoip = isVoip;
2180 for (Listener l : mListeners) {
2181 l.onAudioModeIsVoipChanged(this, isVoip);
2182 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002183 }
2184
2185 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002186 * Sets the time at which a call became active on this Connection. This is set only
2187 * when a conference call becomes active on this connection.
2188 *
2189 * @param connectionTimeMillis The connection time, in milliseconds.
2190 *
2191 * @hide
2192 */
2193 public final void setConnectTimeMillis(long connectTimeMillis) {
2194 mConnectTimeMillis = connectTimeMillis;
2195 }
2196
2197 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002198 * Sets the label and icon status to display in the in-call UI.
2199 *
2200 * @param statusHints The status label and icon to set.
2201 */
2202 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002203 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002204 mStatusHints = statusHints;
2205 for (Listener l : mListeners) {
2206 l.onStatusHintsChanged(this, statusHints);
2207 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002208 }
2209
2210 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002211 * Sets the connections with which this connection can be conferenced.
2212 *
2213 * @param conferenceableConnections The set of connections this connection can conference with.
2214 */
2215 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002216 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002217 clearConferenceableList();
2218 for (Connection c : conferenceableConnections) {
2219 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2220 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002221 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002222 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002223 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002224 }
2225 }
2226 fireOnConferenceableConnectionsChanged();
2227 }
2228
2229 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002230 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2231 * or conferences with which this connection can be conferenced.
2232 *
2233 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002235 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002236 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002237 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002238 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2239 // small amount of items here.
2240 if (!mConferenceables.contains(c)) {
2241 if (c instanceof Connection) {
2242 Connection connection = (Connection) c;
2243 connection.addConnectionListener(mConnectionDeathListener);
2244 } else if (c instanceof Conference) {
2245 Conference conference = (Conference) c;
2246 conference.addListener(mConferenceDeathListener);
2247 }
2248 mConferenceables.add(c);
2249 }
2250 }
2251 fireOnConferenceableConnectionsChanged();
2252 }
2253
2254 /**
2255 * Returns the connections or conferences with which this connection can be conferenced.
2256 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002257 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002258 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002259 }
2260
Yorke Lee53463962015-08-04 16:07:19 -07002261 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002262 * @hide
2263 */
2264 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002265 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002266 if (mConnectionService != null) {
2267 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2268 "which is already associated with another ConnectionService.");
2269 } else {
2270 mConnectionService = connectionService;
2271 }
2272 }
2273
2274 /**
2275 * @hide
2276 */
2277 public final void unsetConnectionService(ConnectionService connectionService) {
2278 if (mConnectionService != connectionService) {
2279 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2280 "that does not belong to the ConnectionService.");
2281 } else {
2282 mConnectionService = null;
2283 }
2284 }
2285
2286 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002287 * @hide
2288 */
2289 public final ConnectionService getConnectionService() {
2290 return mConnectionService;
2291 }
2292
2293 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002294 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002295 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002296 *
2297 * @param conference The conference.
2298 * @return {@code true} if the conference was successfully set.
2299 * @hide
2300 */
2301 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002302 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002303 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002304 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002305 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002306 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2307 fireConferenceChanged();
2308 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002309 return true;
2310 }
2311 return false;
2312 }
2313
2314 /**
2315 * Resets the conference that this connection is a part of.
2316 * @hide
2317 */
2318 public final void resetConference() {
2319 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002320 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002321 mConference = null;
2322 fireConferenceChanged();
2323 }
2324 }
2325
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002326 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002327 * Set some extras that can be associated with this {@code Connection}.
2328 * <p>
2329 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2330 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2331 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002332 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2333 * {@link #removeExtras(String...)} methods to modify the extras.
2334 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002335 * 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 -07002336 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2337 *
2338 * @param extras The extras associated with this {@code Connection}.
2339 */
2340 public final void setExtras(@Nullable Bundle extras) {
2341 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002342
2343 // Add/replace any new or changed extras values.
2344 putExtras(extras);
2345
2346 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2347 // the current one and remove any keys that went away.
2348 if (mPreviousExtraKeys != null) {
2349 List<String> toRemove = new ArrayList<String>();
2350 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002351 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002352 toRemove.add(oldKey);
2353 }
2354 }
2355 if (!toRemove.isEmpty()) {
2356 removeExtras(toRemove);
2357 }
2358 }
2359
2360 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2361 // called we can see if the caller has removed any extras values.
2362 if (mPreviousExtraKeys == null) {
2363 mPreviousExtraKeys = new ArraySet<String>();
2364 }
2365 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002366 if (extras != null) {
2367 mPreviousExtraKeys.addAll(extras.keySet());
2368 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002369 }
2370
2371 /**
2372 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2373 * added.
2374 * <p>
2375 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2376 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2377 *
2378 * @param extras The extras to add.
2379 */
2380 public final void putExtras(@NonNull Bundle extras) {
2381 checkImmutable();
2382 if (extras == null) {
2383 return;
2384 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002385 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2386 // the listeners.
2387 Bundle listenerExtras;
2388 synchronized (mExtrasLock) {
2389 if (mExtras == null) {
2390 mExtras = new Bundle();
2391 }
2392 mExtras.putAll(extras);
2393 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002394 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002395 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002396 // Create a new clone of the extras for each listener so that they don't clobber
2397 // each other
2398 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002399 }
2400 }
2401
2402 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002403 * Adds a boolean extra to this {@code Connection}.
2404 *
2405 * @param key The extra key.
2406 * @param value The value.
2407 * @hide
2408 */
2409 public final void putExtra(String key, boolean value) {
2410 Bundle newExtras = new Bundle();
2411 newExtras.putBoolean(key, value);
2412 putExtras(newExtras);
2413 }
2414
2415 /**
2416 * Adds an integer extra to this {@code Connection}.
2417 *
2418 * @param key The extra key.
2419 * @param value The value.
2420 * @hide
2421 */
2422 public final void putExtra(String key, int value) {
2423 Bundle newExtras = new Bundle();
2424 newExtras.putInt(key, value);
2425 putExtras(newExtras);
2426 }
2427
2428 /**
2429 * Adds a string extra to this {@code Connection}.
2430 *
2431 * @param key The extra key.
2432 * @param value The value.
2433 * @hide
2434 */
2435 public final void putExtra(String key, String value) {
2436 Bundle newExtras = new Bundle();
2437 newExtras.putString(key, value);
2438 putExtras(newExtras);
2439 }
2440
2441 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002442 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002443 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002444 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002445 */
2446 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002447 synchronized (mExtrasLock) {
2448 if (mExtras != null) {
2449 for (String key : keys) {
2450 mExtras.remove(key);
2451 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002452 }
2453 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002454 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002455 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002456 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002457 }
2458 }
2459
2460 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002461 * Removes extras from this {@code Connection}.
2462 *
2463 * @param keys The keys of the extras to remove.
2464 */
2465 public final void removeExtras(String ... keys) {
2466 removeExtras(Arrays.asList(keys));
2467 }
2468
2469 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002470 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2471 * be change to the {@link #getCallAudioState()}.
2472 * <p>
2473 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2474 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2475 * <p>
2476 * See also {@link InCallService#setAudioRoute(int)}.
2477 *
2478 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2479 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2480 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2481 */
2482 public final void setAudioRoute(int route) {
2483 for (Listener l : mListeners) {
2484 l.onAudioRouteChanged(this, route);
2485 }
2486 }
2487
2488 /**
Hall Liu57006aa2017-02-06 10:49:48 -08002489 * Informs listeners that a previously requested RTT session via
2490 * {@link ConnectionRequest#isRequestingRtt()} or
2491 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2492 * @hide
2493 */
2494 public final void sendRttInitiationSuccess() {
2495 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2496 }
2497
2498 /**
2499 * Informs listeners that a previously requested RTT session via
2500 * {@link ConnectionRequest#isRequestingRtt()} or
2501 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2502 * has failed.
2503 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2504 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2505 * @hide
2506 */
2507 public final void sendRttInitiationFailure(int reason) {
2508 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2509 }
2510
2511 /**
2512 * Informs listeners that a currently active RTT session has been terminated by the remote
2513 * side of the coll.
2514 * @hide
2515 */
2516 public final void sendRttSessionRemotelyTerminated() {
2517 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2518 }
2519
2520 /**
2521 * Informs listeners that the remote side of the call has requested an upgrade to include an
2522 * RTT session in the call.
2523 * @hide
2524 */
2525 public final void sendRemoteRttRequest() {
2526 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2527 }
2528
2529 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002530 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002531 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002532 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002533 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2534 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002535 */
Yorke Lee4af59352015-05-13 14:14:54 -07002536 @SystemApi
2537 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002538 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002539
2540 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002541 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2542 *
2543 * @param state The new connection audio state.
2544 */
2545 public void onCallAudioStateChanged(CallAudioState state) {}
2546
2547 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002548 * Notifies this Connection of an internal state change. This method is called after the
2549 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002550 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002551 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002552 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002553 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002554
2555 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002556 * Notifies this Connection of a request to play a DTMF tone.
2557 *
2558 * @param c A DTMF character.
2559 */
Santos Cordonf2951102014-07-20 19:06:29 -07002560 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002561
2562 /**
2563 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2564 */
Santos Cordonf2951102014-07-20 19:06:29 -07002565 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002566
2567 /**
2568 * Notifies this Connection of a request to disconnect.
2569 */
Santos Cordonf2951102014-07-20 19:06:29 -07002570 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002571
2572 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002573 * Notifies this Connection of a request to disconnect a participant of the conference managed
2574 * by the connection.
2575 *
2576 * @param endpoint the {@link Uri} of the participant to disconnect.
2577 * @hide
2578 */
2579 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2580
2581 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002582 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002583 */
Santos Cordonf2951102014-07-20 19:06:29 -07002584 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002585
2586 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002587 * Notifies this Connection of a request to abort.
2588 */
Santos Cordonf2951102014-07-20 19:06:29 -07002589 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002590
2591 /**
2592 * Notifies this Connection of a request to hold.
2593 */
Santos Cordonf2951102014-07-20 19:06:29 -07002594 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002595
2596 /**
2597 * Notifies this Connection of a request to exit a hold state.
2598 */
Santos Cordonf2951102014-07-20 19:06:29 -07002599 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002600
2601 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002602 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002603 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002604 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002605 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002606 */
Santos Cordonf2951102014-07-20 19:06:29 -07002607 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002608
2609 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002610 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002611 * a request to accept.
2612 */
2613 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002614 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002615 }
2616
2617 /**
2618 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002619 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002620 */
Santos Cordonf2951102014-07-20 19:06:29 -07002621 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002622
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002623 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002624 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2625 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002626 */
2627 public void onReject(String replyMessage) {}
2628
2629 /**
Bryce Leecac50772015-11-17 15:13:29 -08002630 * Notifies the Connection of a request to silence the ringer.
2631 *
2632 * @hide
2633 */
2634 public void onSilence() {}
2635
2636 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002637 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2638 */
Santos Cordonf2951102014-07-20 19:06:29 -07002639 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002640
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002641 /**
2642 * Notifies this Connection of a request to pull an external call to the local device.
2643 * <p>
2644 * The {@link InCallService} issues a request to pull an external call to the local device via
2645 * {@link Call#pullExternalCall()}.
2646 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002647 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2648 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002649 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002650 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002651 */
2652 public void onPullExternalCall() {}
2653
2654 /**
2655 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2656 * <p>
2657 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2658 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002659 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2660 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2661 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2662 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2663 * not aware of.
2664 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002665 * See also {@link Call#sendCallEvent(String, Bundle)}.
2666 *
2667 * @param event The call event.
2668 * @param extras Extras associated with the call event.
2669 */
2670 public void onCallEvent(String event, Bundle extras) {}
2671
Tyler Gunndee56a82016-03-23 16:06:34 -07002672 /**
2673 * Notifies this {@link Connection} of a change to the extras made outside the
2674 * {@link ConnectionService}.
2675 * <p>
2676 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2677 * the {@link android.telecom.Call#putExtras(Bundle)} and
2678 * {@link Call#removeExtras(List)}.
2679 *
2680 * @param extras The new extras bundle.
2681 */
2682 public void onExtrasChanged(Bundle extras) {}
2683
Tyler Gunnf5035432017-01-09 09:43:12 -08002684 /**
2685 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2686 * displaying its incoming call user interface for the {@link Connection}.
2687 * <p>
2688 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2689 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2690 * should show its own incoming call user interface.
2691 * <p>
2692 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2693 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2694 * user interface to allow the user to choose whether to answer the new incoming call and
2695 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002696 * <p>
2697 * You should trigger the display of the incoming call user interface for your application by
2698 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2699 * For example:
2700 * <pre><code>
2701 * // Create an intent which triggers your fullscreen incoming call user interface.
2702 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2703 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2704 * intent.setClass(context, YourIncomingCallActivity.class);
2705 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2706 *
2707 * // Build the notification as an ongoing high priority item; this ensures it will show as
2708 * // a heads up notification which slides down over top of the current content.
2709 * final Notification.Builder builder = new Notification.Builder(context);
2710 * builder.setOngoing(true);
2711 * builder.setPriority(Notification.PRIORITY_HIGH);
2712 *
2713 * // Set notification content intent to take user to fullscreen UI if user taps on the
2714 * // notification body.
2715 * builder.setContentIntent(pendingIntent);
2716 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2717 * // manager deems it appropriate.
2718 * builder.setFullScreenIntent(pendingIntent, true);
2719 *
2720 * // Setup notification content.
2721 * builder.setSmallIcon( yourIconResourceId );
2722 * builder.setContentTitle("Your notification title");
2723 * builder.setContentText("Your notification content.");
2724 *
2725 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2726 *
2727 * NotificationManager notificationManager = mContext.getSystemService(
2728 * NotificationManager.class);
2729 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2730 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002731 */
2732 public void onShowIncomingCallUi() {}
2733
Hall Liu57006aa2017-02-06 10:49:48 -08002734 /**
2735 * Notifies this {@link Connection} that the user has requested an RTT session.
2736 * The connection service should call {@link #sendRttInitiationSuccess} or
2737 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2738 * request, respectively.
2739 * @param rttTextStream The object that should be used to send text to or receive text from
2740 * the in-call app.
2741 * @hide
2742 */
2743 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2744
2745 /**
2746 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2747 * channel. No response to Telecom is needed for this method.
2748 * @hide
2749 */
2750 public void onStopRtt() {}
2751
2752 /**
2753 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2754 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2755 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2756 * indicated by {@code rttTextStream} being {@code null}
2757 * @hide
2758 * @param rttTextStream The object that should be used to send text to or receive text from
2759 * the in-call app.
2760 */
2761 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2762
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002763 static String toLogSafePhoneNumber(String number) {
2764 // For unknown number, log empty string.
2765 if (number == null) {
2766 return "";
2767 }
2768
2769 if (PII_DEBUG) {
2770 // When PII_DEBUG is true we emit PII.
2771 return number;
2772 }
2773
2774 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2775 // sanitized phone numbers.
2776 StringBuilder builder = new StringBuilder();
2777 for (int i = 0; i < number.length(); i++) {
2778 char c = number.charAt(i);
2779 if (c == '-' || c == '@' || c == '.') {
2780 builder.append(c);
2781 } else {
2782 builder.append('x');
2783 }
2784 }
2785 return builder.toString();
2786 }
2787
Ihab Awad542e0ea2014-05-16 10:22:16 -07002788 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002789 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002790 if (mState == STATE_DISCONNECTED && mState != state) {
2791 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002792 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002793 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002794 if (mState != state) {
2795 Log.d(this, "setState: %s", stateToString(state));
2796 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002797 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002798 for (Listener l : mListeners) {
2799 l.onStateChanged(this, state);
2800 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002801 }
2802 }
2803
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002804 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002805 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002806 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2807 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002808 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002809 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002810
2811 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002812 if (mImmutable) {
2813 throw new UnsupportedOperationException("Connection is immutable");
2814 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002815 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002816 }
2817
Evan Charltonbf11f982014-07-20 22:06:28 -07002818 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002819 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002820 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2821 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002822 * <p>
2823 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2824 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002825 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002826 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002827 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002828 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002829 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2830 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002831 }
2832
Evan Charltonbf11f982014-07-20 22:06:28 -07002833 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002834 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2835 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2836 * this should never be un-@hide-den.
2837 *
2838 * @hide
2839 */
2840 public void checkImmutable() {}
2841
2842 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002843 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2844 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2845 * that state. This connection should not be used for anything, and no other
2846 * {@code Connection}s should be attempted.
2847 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002848 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002849 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002850 * @return A {@code Connection} which indicates that the underlying connection should
2851 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002852 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002853 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002854 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002855 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002856
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002857 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002858 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002859 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002860 }
2861 }
2862
Santos Cordon823fd3c2014-08-07 18:35:18 -07002863 private final void fireConferenceChanged() {
2864 for (Listener l : mListeners) {
2865 l.onConferenceChanged(this, mConference);
2866 }
2867 }
2868
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002869 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002870 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002871 if (c instanceof Connection) {
2872 Connection connection = (Connection) c;
2873 connection.removeConnectionListener(mConnectionDeathListener);
2874 } else if (c instanceof Conference) {
2875 Conference conference = (Conference) c;
2876 conference.removeListener(mConferenceDeathListener);
2877 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002878 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002879 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002880 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002881
2882 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002883 * Handles a change to extras received from Telecom.
2884 *
2885 * @param extras The new extras.
2886 * @hide
2887 */
2888 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002889 Bundle b = null;
2890 synchronized (mExtrasLock) {
2891 mExtras = extras;
2892 if (mExtras != null) {
2893 b = new Bundle(mExtras);
2894 }
2895 }
2896 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002897 }
2898
2899 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002900 * Notifies listeners that the merge request failed.
2901 *
2902 * @hide
2903 */
2904 protected final void notifyConferenceMergeFailed() {
2905 for (Listener l : mListeners) {
2906 l.onConferenceMergeFailed(this);
2907 }
2908 }
2909
2910 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002911 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002912 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002913 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002914 * @hide
2915 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002916 protected final void updateConferenceParticipants(
2917 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002918 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002919 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002920 }
2921 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002922
2923 /**
2924 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002925 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002926 */
2927 protected void notifyConferenceStarted() {
2928 for (Listener l : mListeners) {
2929 l.onConferenceStarted();
2930 }
2931 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002932
2933 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002934 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2935 * be a part of a conference call.
2936 * @param isConferenceSupported {@code true} if the connection supports being part of a
2937 * conference call, {@code false} otherwise.
2938 * @hide
2939 */
2940 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2941 for (Listener l : mListeners) {
2942 l.onConferenceSupportedChanged(this, isConferenceSupported);
2943 }
2944 }
2945
2946 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002947 * Sends an event associated with this {@code Connection} with associated event extras to the
2948 * {@link InCallService}.
2949 * <p>
2950 * Connection events are used to communicate point in time information from a
2951 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2952 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2953 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2954 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2955 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2956 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2957 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2958 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2959 * <p>
2960 * Events are exposed to {@link InCallService} implementations via
2961 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2962 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002963 * No assumptions should be made as to how an In-Call UI or service will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002964 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2965 * some events altogether.
2966 * <p>
2967 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2968 * conflicts between {@link ConnectionService} implementations. Further, custom
2969 * {@link ConnectionService} implementations shall not re-purpose events in the
2970 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2971 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2972 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2973 * {@code com.example.extra.MY_EXTRA}).
2974 * <p>
2975 * When defining events and the associated extras, it is important to keep their behavior
2976 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2977 * events/extras should me maintained to ensure backwards compatibility with older
2978 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002979 *
2980 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002981 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002982 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002983 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002984 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002985 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002986 }
2987 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002988}