blob: c2824f403fa9f9d0e9b19a120a35400f3c6fb567 [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 Gunnb702ef82015-05-29 11:51:53 -070027import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080029import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070030import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Handler;
32import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070033import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080035import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070037import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070039
Hall Liu95d55872017-01-25 17:12:49 -080040import java.io.IOException;
41import java.io.InputStreamReader;
42import java.io.OutputStreamWriter;
Hall Liu57006aa2017-02-06 10:49:48 -080043import java.lang.annotation.Retention;
44import java.lang.annotation.RetentionPolicy;
Santos Cordonb6939982014-06-04 20:20:58 -070045import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070046import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070047import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070048import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070049import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070050import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051
52/**
Santos Cordon895d4b82015-06-25 16:41:48 -070053 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
54 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070055 * <p>
56 * Implementations create a custom subclass of {@code Connection} and return it to the framework
57 * as the return value of
58 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
59 * or
60 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
61 * Implementations are then responsible for updating the state of the {@code Connection}, and
62 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
63 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070064 * <p>
65 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
66 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
67 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
68 * {@code Connection} instance.
69 * <p>
70 * Basic call support requires overriding the following methods: {@link #onAnswer()},
71 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
72 * <p>
73 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
74 * {@link #onUnhold()} methods should be overridden to provide hold support for the
75 * {@code Connection}.
76 * <p>
77 * Where a {@code Connection} supports a variation of video calling (e.g. the
78 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
79 * to support answering a call as a video call.
80 * <p>
81 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
82 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
83 * support for pulling the external call.
84 * <p>
85 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
86 * overridden.
87 * <p>
88 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
89 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
90 * for example, call events from a {@link InCallService} are handled,
91 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
92 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
93 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
94 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070095 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070096public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070097
Santos Cordon895d4b82015-06-25 16:41:48 -070098 /**
99 * The connection is initializing. This is generally the first state for a {@code Connection}
100 * returned by a {@link ConnectionService}.
101 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700102 public static final int STATE_INITIALIZING = 0;
103
Santos Cordon895d4b82015-06-25 16:41:48 -0700104 /**
105 * The connection is new and not connected.
106 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 public static final int STATE_NEW = 1;
108
Santos Cordon895d4b82015-06-25 16:41:48 -0700109 /**
110 * An incoming connection is in the ringing state. During this state, the user's ringer or
111 * vibration feature will be activated.
112 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700113 public static final int STATE_RINGING = 2;
114
Santos Cordon895d4b82015-06-25 16:41:48 -0700115 /**
116 * An outgoing connection is in the dialing state. In this state the other party has not yet
117 * answered the call and the user traditionally hears a ringback tone.
118 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700119 public static final int STATE_DIALING = 3;
120
Santos Cordon895d4b82015-06-25 16:41:48 -0700121 /**
122 * A connection is active. Both parties are connected to the call and can actively communicate.
123 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700124 public static final int STATE_ACTIVE = 4;
125
Santos Cordon895d4b82015-06-25 16:41:48 -0700126 /**
127 * A connection is on hold.
128 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700129 public static final int STATE_HOLDING = 5;
130
Santos Cordon895d4b82015-06-25 16:41:48 -0700131 /**
132 * A connection has been disconnected. This is the final state once the user has been
133 * disconnected from a call either locally, remotely or by an error in the service.
134 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700135 public static final int STATE_DISCONNECTED = 6;
136
Santos Cordon895d4b82015-06-25 16:41:48 -0700137 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700138 * The state of an external connection which is in the process of being pulled from a remote
139 * device to the local device.
140 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700141 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700142 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
143 */
144 public static final int STATE_PULLING_CALL = 7;
145
146 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700147 * Connection can currently be put on hold or unheld. This is distinct from
148 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
149 * it does not at the moment support the function. This can be true while the call is in the
150 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
151 * display a disabled 'hold' button.
152 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800153 public static final int CAPABILITY_HOLD = 0x00000001;
154
155 /** Connection supports the hold feature. */
156 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
157
158 /**
159 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
160 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
161 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
162 * capability allows a merge button to be shown while the conference is in the foreground
163 * of the in-call UI.
164 * <p>
165 * This is only intended for use by a {@link Conference}.
166 */
167 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
168
169 /**
170 * Connections within a conference can be swapped between foreground and background.
171 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
172 * <p>
173 * This is only intended for use by a {@link Conference}.
174 */
175 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
176
177 /**
178 * @hide
179 */
180 public static final int CAPABILITY_UNUSED = 0x00000010;
181
182 /** Connection supports responding via text option. */
183 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
184
185 /** Connection can be muted. */
186 public static final int CAPABILITY_MUTE = 0x00000040;
187
188 /**
189 * Connection supports conference management. This capability only applies to
190 * {@link Conference}s which can have {@link Connection}s as children.
191 */
192 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
193
194 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700195 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800196 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198
199 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700200 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203
204 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700207 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209
210 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
214
215 /**
216 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 */
218 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
219
220 /**
221 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700222 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700223 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800225
226 /**
227 * Connection is able to be separated from its parent {@code Conference}, if any.
228 */
229 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
230
231 /**
232 * Connection is able to be individually disconnected when in a {@code Conference}.
233 */
234 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
235
236 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700237 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800238 * @hide
239 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700240 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800241
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700242 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 * @hide
245 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247
248 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 * @hide
251 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253
Tyler Gunn068085b2015-02-06 13:56:52 -0800254 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800256 * @hide
257 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800259
Tyler Gunn96d6c402015-03-18 12:39:23 -0700260 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500261 * Speed up audio setup for MT call.
262 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700263 */
264 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800265
Rekha Kumar07366812015-03-24 16:42:31 -0700266 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700267 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700268 */
269 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
270
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700271 /**
272 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700273 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 */
275 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
276
Tyler Gunnd4091732015-06-29 09:15:37 -0700277 /**
278 * For a conference, indicates the conference will not have child connections.
279 * <p>
280 * An example of a conference with child connections is a GSM conference call, where the radio
281 * retains connections to the individual participants of the conference. Another example is an
282 * IMS conference call where conference event package functionality is supported; in this case
283 * the conference server ensures the radio is aware of the participants in the conference, which
284 * are represented by child connections.
285 * <p>
286 * An example of a conference with no child connections is an IMS conference call with no
287 * conference event package support. Such a conference is represented by the radio as a single
288 * connection to the IMS conference server.
289 * <p>
290 * Indicating whether a conference has children or not is important to help user interfaces
291 * visually represent a conference. A conference with no children, for example, will have the
292 * conference connection shown in the list of calls on a Bluetooth device, where if the
293 * conference has children, only the children will be shown in the list of calls on a Bluetooth
294 * device.
295 * @hide
296 */
297 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
298
Bryce Lee81901682015-08-28 16:38:02 -0700299 /**
300 * Indicates that the connection itself wants to handle any sort of reply response, rather than
301 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700302 */
303 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
304
Tyler Gunnf97a0092016-01-19 15:59:34 -0800305 /**
306 * When set, prevents a video call from being downgraded to an audio-only call.
307 * <p>
308 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
309 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
310 * downgraded from a video call back to a VideoState of
311 * {@link VideoProfile#STATE_AUDIO_ONLY}.
312 * <p>
313 * Intuitively, a call which can be downgraded to audio should also have local and remote
314 * video
315 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
316 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
317 */
318 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
319
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700320 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700321 * When set for an external connection, indicates that this {@code Connection} can be pulled
322 * from a remote device to the current device.
323 * <p>
324 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
325 * is set.
326 */
327 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
328
329 //**********************************************************************************************
330 // Next CAPABILITY value: 0x02000000
331 //**********************************************************************************************
332
333 /**
334 * Indicates that the current device callback number should be shown.
335 *
336 * @hide
337 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700338 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700339
340 /**
341 * Whether the call is a generic conference, where we do not know the precise state of
342 * participants in the conference (eg. on CDMA).
343 *
344 * @hide
345 */
346 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
347
348 /**
349 * Connection is using high definition audio.
350 * @hide
351 */
352 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
353
354 /**
355 * Connection is using WIFI.
356 * @hide
357 */
358 public static final int PROPERTY_WIFI = 1<<3;
359
360 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700361 * When set, indicates that the {@code Connection} does not actually exist locally for the
362 * {@link ConnectionService}.
363 * <p>
364 * Consider, for example, a scenario where a user has two devices with the same phone number.
365 * When a user places a call on one devices, the telephony stack can represent that call on the
366 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700367 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368 * <p>
369 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
370 * external connections. Only those {@link InCallService}s which have the
371 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
372 * manifest will see external connections.
373 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700374 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700375
Brad Ebinger15847072016-05-18 11:08:36 -0700376 /**
377 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
378 */
379 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700380
Hall Liu9f332c72016-07-14 15:37:37 -0700381 /**
382 * Indicates that the connection represents a downgraded IMS conference.
383 * @hide
384 */
385 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
386
Tyler Gunnf5035432017-01-09 09:43:12 -0800387 /**
388 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
389 * {@link ConnectionService}.
390 * <p>
391 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
392 */
393 public static final int PROPERTY_SELF_MANAGED = 1<<7;
394
Hall Liu95d55872017-01-25 17:12:49 -0800395 /**
396 * When set, indicates that a connection has an active RTT session associated with it.
397 * @hide
398 */
399 public static final int PROPERTY_IS_RTT = 1 << 8;
400
Tyler Gunn96d6c402015-03-18 12:39:23 -0700401 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800402 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700403 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800404
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700405 /**
406 * Connection extra key used to store the last forwarded number associated with the current
407 * connection. Used to communicate to the user interface that the connection was forwarded via
408 * the specified number.
409 */
410 public static final String EXTRA_LAST_FORWARDED_NUMBER =
411 "android.telecom.extra.LAST_FORWARDED_NUMBER";
412
413 /**
414 * Connection extra key used to store a child number associated with the current connection.
415 * Used to communicate to the user interface that the connection was received via
416 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
417 * address.
418 */
419 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
420
421 /**
422 * Connection extra key used to store the subject for an incoming call. The user interface can
423 * query this extra and display its contents for incoming calls. Will only be used if the
424 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
425 */
426 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
427
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800428 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700429 * Boolean connection extra key set on a {@link Connection} in
430 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
431 * current active foreground call to be dropped.
432 */
433 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
434 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
435
436 /**
Hall Liu10208662016-06-15 17:55:00 -0700437 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700438 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700439 * @hide
440 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700441 public static final String EXTRA_DISABLE_ADD_CALL =
442 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700443
444 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700445 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
446 * original Connection ID associated with the connection. Used in
447 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
448 * connection/conference added via
449 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
450 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
451 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
452 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
453 * be a way to ensure that we don't add the connection again as a duplicate.
454 * <p>
455 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
456 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
457 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
458 * in a new {@link Connection} which it adds to Telecom via
459 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
460 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
461 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
462 * ID it originally referred to the connection as. Thus Telecom needs to know that the
463 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
464 * @hide
465 */
466 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
467 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
468
469 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800470 * Connection event used to inform Telecom that it should play the on hold tone. This is used
471 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700472 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800473 * @hide
474 */
475 public static final String EVENT_ON_HOLD_TONE_START =
476 "android.telecom.event.ON_HOLD_TONE_START";
477
478 /**
479 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
480 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700481 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800482 * @hide
483 */
484 public static final String EVENT_ON_HOLD_TONE_END =
485 "android.telecom.event.ON_HOLD_TONE_END";
486
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700487 /**
488 * Connection event used to inform {@link InCallService}s when pulling of an external call has
489 * failed. The user interface should inform the user of the error.
490 * <p>
491 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
492 * API is called on a {@link Call} with the properties
493 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
494 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
495 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700496 * <p>
497 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
498 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700499 */
500 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
501
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700502 /**
503 * Connection event used to inform {@link InCallService}s when the merging of two calls has
504 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700505 * <p>
506 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
507 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700508 */
509 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
510
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700511 /**
512 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
513 * the remote party.
514 * <p>
515 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
516 * call is being held locally on the device. When a capable {@link ConnectionService} receives
517 * signalling to indicate that the remote party has put the call on hold, it can send this
518 * connection event.
519 * @hide
520 */
521 public static final String EVENT_CALL_REMOTELY_HELD =
522 "android.telecom.event.CALL_REMOTELY_HELD";
523
524 /**
525 * Connection event used to inform {@link InCallService}s when a call which was remotely held
526 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
527 * <p>
528 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
529 * call is being held locally on the device. When a capable {@link ConnectionService} receives
530 * signalling to indicate that the remote party has taken the call off hold, it can send this
531 * connection event.
532 * @hide
533 */
534 public static final String EVENT_CALL_REMOTELY_UNHELD =
535 "android.telecom.event.CALL_REMOTELY_UNHELD";
536
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700537 // Flag controlling whether PII is emitted into the logs
538 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
539
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800540 /**
541 * Whether the given capabilities support the specified capability.
542 *
543 * @param capabilities A capability bit field.
544 * @param capability The capability to check capabilities for.
545 * @return Whether the specified capability is supported.
546 * @hide
547 */
548 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800549 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 }
551
552 /**
553 * Whether the capabilities of this {@code Connection} supports the specified capability.
554 *
555 * @param capability The capability to check capabilities for.
556 * @return Whether the specified capability is supported.
557 * @hide
558 */
559 public boolean can(int capability) {
560 return can(mConnectionCapabilities, capability);
561 }
562
563 /**
564 * Removes the specified capability from the set of capabilities of this {@code Connection}.
565 *
566 * @param capability The capability to remove from the set.
567 * @hide
568 */
569 public void removeCapability(int capability) {
570 mConnectionCapabilities &= ~capability;
571 }
572
573 /**
574 * Adds the specified capability to the set of capabilities of this {@code Connection}.
575 *
576 * @param capability The capability to add to the set.
577 * @hide
578 */
579 public void addCapability(int capability) {
580 mConnectionCapabilities |= capability;
581 }
582
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700583 /**
584 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
585 *
586 * @param capabilities A capability bit field.
587 * @return A human readable string representation.
588 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800589 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700590 return capabilitiesToStringInternal(capabilities, true /* isLong */);
591 }
592
593 /**
594 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
595 * string.
596 *
597 * @param capabilities A capability bit field.
598 * @return A human readable string representation.
599 * @hide
600 */
601 public static String capabilitiesToStringShort(int capabilities) {
602 return capabilitiesToStringInternal(capabilities, false /* isLong */);
603 }
604
605 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800606 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700607 builder.append("[");
608 if (isLong) {
609 builder.append("Capabilities:");
610 }
611
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800612 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700613 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800614 }
615 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700616 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800617 }
618 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700619 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 }
621 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700622 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 }
624 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700625 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 }
627 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700628 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 }
630 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700631 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800632 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700633 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700634 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700635 }
636 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700637 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700638 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700639 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700640 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800641 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700642 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700643 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700644 }
645 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700646 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700647 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700648 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700649 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800650 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800651 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700652 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800653 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500654 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700655 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500656 }
Rekha Kumar07366812015-03-24 16:42:31 -0700657 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700658 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700659 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700660 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700661 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700662 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700663 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700664 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700665 }
Bryce Lee81901682015-08-28 16:38:02 -0700666 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700668 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700669 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700670 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700671 }
Bryce Lee81901682015-08-28 16:38:02 -0700672
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800673 builder.append("]");
674 return builder.toString();
675 }
676
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700677 /**
678 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
679 *
680 * @param properties A property bit field.
681 * @return A human readable string representation.
682 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700683 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 return propertiesToStringInternal(properties, true /* isLong */);
685 }
686
687 /**
688 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
689 *
690 * @param properties A property bit field.
691 * @return A human readable string representation.
692 * @hide
693 */
694 public static String propertiesToStringShort(int properties) {
695 return propertiesToStringInternal(properties, false /* isLong */);
696 }
697
698 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700699 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append("[");
701 if (isLong) {
702 builder.append("Properties:");
703 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700704
Tyler Gunnf5035432017-01-09 09:43:12 -0800705 if (can(properties, PROPERTY_SELF_MANAGED)) {
706 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
707 }
708
Hall Liu25c7c4d2016-08-30 13:41:02 -0700709 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
710 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700711 }
712
713 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700714 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700715 }
716
717 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700719 }
720
721 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700722 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700723 }
724
725 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700726 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700727 }
728
Brad Ebinger15847072016-05-18 11:08:36 -0700729 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700730 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700731 }
732
Tyler Gunn720c6642016-03-22 09:02:47 -0700733 builder.append("]");
734 return builder.toString();
735 }
736
Sailesh Nepal091768c2014-06-30 15:15:23 -0700737 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700738 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700739 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700740 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700741 public void onCallerDisplayNameChanged(
742 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700743 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700744 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700745 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800746 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700747 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700748 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800749 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700750 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800751 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 public void onVideoProviderChanged(
753 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700754 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
755 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800756 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700757 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700758 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700759 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800760 public void onConferenceParticipantsChanged(Connection c,
761 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800762 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700763 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700764 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700765 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700766 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700767 /** @hide */
768 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800769 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800770 public void onRttInitiationSuccess(Connection c) {}
771 public void onRttInitiationFailure(Connection c, int reason) {}
772 public void onRttSessionRemotelyTerminated(Connection c) {}
773 public void onRemoteRttRequest(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700774 }
775
Tyler Gunnb702ef82015-05-29 11:51:53 -0700776 /**
Hall Liu95d55872017-01-25 17:12:49 -0800777 * Provides methods to read and write RTT data to/from the in-call app.
778 * @hide
779 */
780 public static final class RttTextStream {
781 private static final int READ_BUFFER_SIZE = 1000;
782 private final InputStreamReader mPipeFromInCall;
783 private final OutputStreamWriter mPipeToInCall;
Hall Liu57006aa2017-02-06 10:49:48 -0800784 private final ParcelFileDescriptor mFdFromInCall;
785 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800786 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
787
788 /**
789 * @hide
790 */
791 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liu57006aa2017-02-06 10:49:48 -0800792 mFdFromInCall = fromInCall;
793 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800794 mPipeFromInCall = new InputStreamReader(
795 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
796 mPipeToInCall = new OutputStreamWriter(
797 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
798 }
799
800 /**
801 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
802 * RTT transmits text in real-time, this method should be called as often as text snippets
803 * are received from the remote user, even if it is only one character.
804 *
805 * This method is not thread-safe -- calling it from multiple threads simultaneously may
806 * lead to interleaved text.
807 * @param input The message to send to the in-call app.
808 */
809 public void write(String input) throws IOException {
810 mPipeToInCall.write(input);
811 mPipeToInCall.flush();
812 }
813
814
815 /**
816 * Reads a string from the in-call app, blocking if there is no data available. Returns
817 * {@code null} if the RTT conversation has been terminated and there is no further data
818 * to read.
819 *
820 * This method is not thread-safe -- calling it from multiple threads simultaneously may
821 * lead to interleaved text.
822 * @return A string containing text entered by the user, or {@code null} if the
823 * conversation has been terminated or if there was an error while reading.
824 */
825 public String read() {
826 try {
827 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
828 if (numRead < 0) {
829 return null;
830 }
831 return new String(mReadBuffer, 0, numRead);
832 } catch (IOException e) {
833 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
834 return null;
835 }
836 }
Hall Liu57006aa2017-02-06 10:49:48 -0800837
838 /** @hide */
839 public ParcelFileDescriptor getFdFromInCall() {
840 return mFdFromInCall;
841 }
842
843 /** @hide */
844 public ParcelFileDescriptor getFdToInCall() {
845 return mFdToInCall;
846 }
847 }
848
849 /**
850 * Provides constants to represent the results of responses to session modify requests sent via
851 * {@link Call#sendRttRequest()}
852 */
853 public static final class RttModifyStatus {
854 /**
855 * Session modify request was successful.
856 */
857 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
858
859 /**
860 * Session modify request failed.
861 */
862 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
863
864 /**
865 * Session modify request ignored due to invalid parameters.
866 */
867 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
868
869 /**
870 * Session modify request timed out.
871 */
872 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
873
874 /**
875 * Session modify request rejected by remote user.
876 */
877 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800878 }
879
880 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * Provides a means of controlling the video session associated with a {@link Connection}.
882 * <p>
883 * Implementations create a custom subclass of {@link VideoProvider} and the
884 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
885 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
886 * should set the {@link VideoProvider}.
887 * <p>
888 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
889 * {@link InCallService} implementations to issue requests related to the video session;
890 * it provides a means for the {@link ConnectionService} to report events and information
891 * related to the video session to Telecom and the {@link InCallService} implementations.
892 * <p>
893 * {@link InCallService} implementations interact with the {@link VideoProvider} via
894 * {@link android.telecom.InCallService.VideoCall}.
895 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700896 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 /**
898 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700900 */
901 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700902
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700903 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
905 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 */
907 public static final int SESSION_EVENT_RX_RESUME = 2;
908
909 /**
910 * Video transmission has begun. This occurs after a negotiated start of video transmission
911 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700912 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700913 */
914 public static final int SESSION_EVENT_TX_START = 3;
915
916 /**
917 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
918 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700920 */
921 public static final int SESSION_EVENT_TX_STOP = 4;
922
923 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800924 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700925 * this as a cue to inform the user the camera is not available.
926 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 */
928 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
929
930 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700931 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800932 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700933 * the camera has become available again.
934 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700935 */
936 public static final int SESSION_EVENT_CAMERA_READY = 6;
937
938 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800939 * Session event raised by Telecom when
940 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
941 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
942 * @see #handleCallSessionEvent(int)
943 */
944 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
945
946 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 */
950 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
951
952 /**
953 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 */
956 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
957
958 /**
959 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700960 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 */
962 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
963
Rekha Kumar07366812015-03-24 16:42:31 -0700964 /**
965 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700967 */
968 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
969
970 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700971 * Session modify request rejected by remote user.
972 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700973 */
974 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
975
Tyler Gunn75958422015-04-15 14:23:42 -0700976 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700977 private static final int MSG_SET_CAMERA = 2;
978 private static final int MSG_SET_PREVIEW_SURFACE = 3;
979 private static final int MSG_SET_DISPLAY_SURFACE = 4;
980 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
981 private static final int MSG_SET_ZOOM = 6;
982 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
983 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
984 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700987 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700988
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700989 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
990 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
991 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
992 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
993 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
994 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800995 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
996 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700997 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
998
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700999 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001001
1002 /**
1003 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001004 *
1005 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1006 * load factor before resizing, 1 means we only expect a single thread to
1007 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001008 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001009 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1010 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011
1012 /**
1013 * Default handler used to consolidate binder method calls onto a single thread.
1014 */
1015 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001016 public VideoProviderHandler() {
1017 super();
1018 }
1019
1020 public VideoProviderHandler(Looper looper) {
1021 super(looper);
1022 }
1023
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001024 @Override
1025 public void handleMessage(Message msg) {
1026 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001027 case MSG_ADD_VIDEO_CALLBACK: {
1028 IBinder binder = (IBinder) msg.obj;
1029 IVideoCallback callback = IVideoCallback.Stub
1030 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001031 if (callback == null) {
1032 Log.w(this, "addVideoProvider - skipped; callback is null.");
1033 break;
1034 }
1035
Tyler Gunn75958422015-04-15 14:23:42 -07001036 if (mVideoCallbacks.containsKey(binder)) {
1037 Log.i(this, "addVideoProvider - skipped; already present.");
1038 break;
1039 }
1040 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001041 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001042 }
1043 case MSG_REMOVE_VIDEO_CALLBACK: {
1044 IBinder binder = (IBinder) msg.obj;
1045 IVideoCallback callback = IVideoCallback.Stub
1046 .asInterface((IBinder) msg.obj);
1047 if (!mVideoCallbacks.containsKey(binder)) {
1048 Log.i(this, "removeVideoProvider - skipped; not present.");
1049 break;
1050 }
1051 mVideoCallbacks.remove(binder);
1052 break;
1053 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001055 {
1056 SomeArgs args = (SomeArgs) msg.obj;
1057 try {
1058 onSetCamera((String) args.arg1);
1059 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
1060 args.argi2);
1061 } finally {
1062 args.recycle();
1063 }
1064 }
1065 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 case MSG_SET_PREVIEW_SURFACE:
1067 onSetPreviewSurface((Surface) msg.obj);
1068 break;
1069 case MSG_SET_DISPLAY_SURFACE:
1070 onSetDisplaySurface((Surface) msg.obj);
1071 break;
1072 case MSG_SET_DEVICE_ORIENTATION:
1073 onSetDeviceOrientation(msg.arg1);
1074 break;
1075 case MSG_SET_ZOOM:
1076 onSetZoom((Float) msg.obj);
1077 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001078 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1079 SomeArgs args = (SomeArgs) msg.obj;
1080 try {
1081 onSendSessionModifyRequest((VideoProfile) args.arg1,
1082 (VideoProfile) args.arg2);
1083 } finally {
1084 args.recycle();
1085 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001087 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1089 onSendSessionModifyResponse((VideoProfile) msg.obj);
1090 break;
1091 case MSG_REQUEST_CAMERA_CAPABILITIES:
1092 onRequestCameraCapabilities();
1093 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001094 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1095 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 break;
1097 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001098 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001099 break;
1100 default:
1101 break;
1102 }
1103 }
1104 }
1105
1106 /**
1107 * IVideoProvider stub implementation.
1108 */
1109 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001110 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001112 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1113 }
1114
1115 public void removeVideoCallback(IBinder videoCallbackBinder) {
1116 mMessageHandler.obtainMessage(
1117 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 }
1119
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001120 public void setCamera(String cameraId, String callingPackageName) {
1121 SomeArgs args = SomeArgs.obtain();
1122 args.arg1 = cameraId;
1123 // Propagate the calling package; originally determined in
1124 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1125 // process.
1126 args.arg2 = callingPackageName;
1127 // Pass along the uid and pid of the calling app; this gets lost when we put the
1128 // message onto the handler. These are required for Telecom to perform a permission
1129 // check to see if the calling app is able to use the camera.
1130 args.argi1 = Binder.getCallingUid();
1131 args.argi2 = Binder.getCallingPid();
1132 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 }
1134
1135 public void setPreviewSurface(Surface surface) {
1136 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1137 }
1138
1139 public void setDisplaySurface(Surface surface) {
1140 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1141 }
1142
1143 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001144 mMessageHandler.obtainMessage(
1145 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 }
1147
1148 public void setZoom(float value) {
1149 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1150 }
1151
Tyler Gunn45382162015-05-06 08:52:27 -07001152 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1153 SomeArgs args = SomeArgs.obtain();
1154 args.arg1 = fromProfile;
1155 args.arg2 = toProfile;
1156 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001157 }
1158
1159 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1160 mMessageHandler.obtainMessage(
1161 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1162 }
1163
1164 public void requestCameraCapabilities() {
1165 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1166 }
1167
1168 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001169 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170 }
1171
Yorke Lee32f24732015-05-12 16:18:03 -07001172 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001173 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1174 }
1175 }
1176
1177 public VideoProvider() {
1178 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001179 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001180 }
1181
1182 /**
1183 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1184 *
1185 * @param looper The looper.
1186 * @hide
1187 */
1188 public VideoProvider(Looper looper) {
1189 mBinder = new VideoProvider.VideoProviderBinder();
1190 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001191 }
1192
1193 /**
1194 * Returns binder object which can be used across IPC methods.
1195 * @hide
1196 */
1197 public final IVideoProvider getInterface() {
1198 return mBinder;
1199 }
1200
1201 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001202 * Sets the camera to be used for the outgoing video.
1203 * <p>
1204 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1205 * camera via
1206 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1207 * <p>
1208 * Sent from the {@link InCallService} via
1209 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001211 * @param cameraId The id of the camera (use ids as reported by
1212 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 */
1214 public abstract void onSetCamera(String cameraId);
1215
1216 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001217 * Sets the camera to be used for the outgoing video.
1218 * <p>
1219 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1220 * camera via
1221 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1222 * <p>
1223 * This prototype is used internally to ensure that the calling package name, UID and PID
1224 * are sent to Telecom so that can perform a camera permission check on the caller.
1225 * <p>
1226 * Sent from the {@link InCallService} via
1227 * {@link InCallService.VideoCall#setCamera(String)}.
1228 *
1229 * @param cameraId The id of the camera (use ids as reported by
1230 * {@link CameraManager#getCameraIdList()}).
1231 * @param callingPackageName The AppOpps package name of the caller.
1232 * @param callingUid The UID of the caller.
1233 * @param callingPid The PID of the caller.
1234 * @hide
1235 */
1236 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
1237 int callingPid) {}
1238
1239 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 * Sets the surface to be used for displaying a preview of what the user's camera is
1241 * currently capturing. When video transmission is enabled, this is the video signal which
1242 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001243 * <p>
1244 * Sent from the {@link InCallService} via
1245 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001247 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 */
1249 public abstract void onSetPreviewSurface(Surface surface);
1250
1251 /**
1252 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001253 * <p>
1254 * Sent from the {@link InCallService} via
1255 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001256 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001257 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 */
1259 public abstract void onSetDisplaySurface(Surface surface);
1260
1261 /**
1262 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1263 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001264 * <p>
1265 * Sent from the {@link InCallService} via
1266 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 *
1268 * @param rotation The device orientation, in degrees.
1269 */
1270 public abstract void onSetDeviceOrientation(int rotation);
1271
1272 /**
1273 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001274 * <p>
1275 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 *
1277 * @param value The camera zoom ratio.
1278 */
1279 public abstract void onSetZoom(float value);
1280
1281 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * Issues a request to modify the properties of the current video session.
1283 * <p>
1284 * Example scenarios include: requesting an audio-only call to be upgraded to a
1285 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1286 * when the {@link InCallService} is no longer the foreground application.
1287 * <p>
1288 * If the {@link VideoProvider} determines a request to be invalid, it should call
1289 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1290 * invalid request back to the {@link InCallService}.
1291 * <p>
1292 * Where a request requires confirmation from the user of the peer device, the
1293 * {@link VideoProvider} must communicate the request to the peer device and handle the
1294 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1295 * is used to inform the {@link InCallService} of the result of the request.
1296 * <p>
1297 * Sent from the {@link InCallService} via
1298 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001300 * @param fromProfile The video profile prior to the request.
1301 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 */
Tyler Gunn45382162015-05-06 08:52:27 -07001303 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1304 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001305
Tyler Gunnb702ef82015-05-29 11:51:53 -07001306 /**
1307 * Provides a response to a request to change the current video session properties.
1308 * <p>
1309 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1310 * video call, could decline the request and keep the call as audio-only.
1311 * In such a scenario, the {@code responseProfile} would have a video state of
1312 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1313 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1314 * <p>
1315 * Sent from the {@link InCallService} via
1316 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1317 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1318 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001320 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 */
1322 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1323
1324 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001325 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1326 * <p>
1327 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1328 * camera via
1329 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1330 * <p>
1331 * Sent from the {@link InCallService} via
1332 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 */
1334 public abstract void onRequestCameraCapabilities();
1335
1336 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001337 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1338 * video component of the current {@link Connection}.
1339 * <p>
1340 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1341 * via {@link VideoProvider#setCallDataUsage(long)}.
1342 * <p>
1343 * Sent from the {@link InCallService} via
1344 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001345 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001346 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347
1348 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001349 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1350 * the peer device when the video signal is paused.
1351 * <p>
1352 * Sent from the {@link InCallService} via
1353 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001354 *
1355 * @param uri URI of image to display.
1356 */
Yorke Lee32f24732015-05-12 16:18:03 -07001357 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001358
1359 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001360 * Used to inform listening {@link InCallService} implementations when the
1361 * {@link VideoProvider} receives a session modification request.
1362 * <p>
1363 * Received by the {@link InCallService} via
1364 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001366 * @param videoProfile The requested video profile.
1367 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 */
1369 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001370 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001371 for (IVideoCallback callback : mVideoCallbacks.values()) {
1372 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001373 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001374 } catch (RemoteException ignored) {
1375 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001376 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 }
1378 }
1379 }
1380
1381 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001382 * Used to inform listening {@link InCallService} implementations when the
1383 * {@link VideoProvider} receives a response to a session modification request.
1384 * <p>
1385 * Received by the {@link InCallService} via
1386 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1387 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 *
1389 * @param status Status of the session modify request. Valid values are
1390 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1391 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001392 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1393 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1394 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1395 * @param requestedProfile The original request which was sent to the peer device.
1396 * @param responseProfile The actual profile changes agreed to by the peer device.
1397 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 */
1399 public void receiveSessionModifyResponse(int status,
1400 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001401 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001402 for (IVideoCallback callback : mVideoCallbacks.values()) {
1403 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001404 callback.receiveSessionModifyResponse(status, requestedProfile,
1405 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001406 } catch (RemoteException ignored) {
1407 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001408 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 }
1410 }
1411 }
1412
1413 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001414 * Used to inform listening {@link InCallService} implementations when the
1415 * {@link VideoProvider} reports a call session event.
1416 * <p>
1417 * Received by the {@link InCallService} via
1418 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001420 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1421 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1422 * {@link VideoProvider#SESSION_EVENT_TX_START},
1423 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1424 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001425 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1426 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 */
1428 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001429 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001430 for (IVideoCallback callback : mVideoCallbacks.values()) {
1431 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001432 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001433 } catch (RemoteException ignored) {
1434 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001435 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 }
1437 }
1438 }
1439
1440 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001441 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1442 * peer's video have changed.
1443 * <p>
1444 * This could occur if, for example, the peer rotates their device, changing the aspect
1445 * ratio of the video, or if the user switches between the back and front cameras.
1446 * <p>
1447 * Received by the {@link InCallService} via
1448 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 *
1450 * @param width The updated peer video width.
1451 * @param height The updated peer video height.
1452 */
1453 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001454 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001455 for (IVideoCallback callback : mVideoCallbacks.values()) {
1456 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001457 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001458 } catch (RemoteException ignored) {
1459 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001460 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 }
1462 }
1463 }
1464
1465 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001466 * Used to inform listening {@link InCallService} implementations when the data usage of the
1467 * video associated with the current {@link Connection} has changed.
1468 * <p>
1469 * This could be in response to a preview request via
1470 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001471 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1472 * 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 -07001473 * <p>
1474 * Received by the {@link InCallService} via
1475 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001476 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001477 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1478 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 */
Yorke Lee32f24732015-05-12 16:18:03 -07001480 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001481 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001482 for (IVideoCallback callback : mVideoCallbacks.values()) {
1483 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001484 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001485 } catch (RemoteException ignored) {
1486 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001487 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 }
1489 }
1490 }
1491
1492 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001493 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001494 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001495 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001496 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1497 * @hide
1498 */
1499 public void changeCallDataUsage(long dataUsage) {
1500 setCallDataUsage(dataUsage);
1501 }
1502
1503 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001504 * Used to inform listening {@link InCallService} implementations when the capabilities of
1505 * the current camera have changed.
1506 * <p>
1507 * The {@link VideoProvider} should call this in response to
1508 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1509 * changed via {@link VideoProvider#onSetCamera(String)}.
1510 * <p>
1511 * Received by the {@link InCallService} via
1512 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1513 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001514 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001515 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001516 */
Yorke Lee400470f2015-05-12 13:31:25 -07001517 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001518 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001519 for (IVideoCallback callback : mVideoCallbacks.values()) {
1520 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001521 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001522 } catch (RemoteException ignored) {
1523 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001524 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 }
1526 }
1527 }
Rekha Kumar07366812015-03-24 16:42:31 -07001528
1529 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001530 * Used to inform listening {@link InCallService} implementations when the video quality
1531 * of the call has changed.
1532 * <p>
1533 * Received by the {@link InCallService} via
1534 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001535 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001536 * @param videoQuality The updated video quality. Valid values:
1537 * {@link VideoProfile#QUALITY_HIGH},
1538 * {@link VideoProfile#QUALITY_MEDIUM},
1539 * {@link VideoProfile#QUALITY_LOW},
1540 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001541 */
1542 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001543 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001544 for (IVideoCallback callback : mVideoCallbacks.values()) {
1545 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001546 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001547 } catch (RemoteException ignored) {
1548 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001549 }
Rekha Kumar07366812015-03-24 16:42:31 -07001550 }
1551 }
1552 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001553
1554 /**
1555 * Returns a string representation of a call session event.
1556 *
1557 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1558 * @return String representation of the call session event.
1559 * @hide
1560 */
1561 public static String sessionEventToString(int event) {
1562 switch (event) {
1563 case SESSION_EVENT_CAMERA_FAILURE:
1564 return SESSION_EVENT_CAMERA_FAILURE_STR;
1565 case SESSION_EVENT_CAMERA_READY:
1566 return SESSION_EVENT_CAMERA_READY_STR;
1567 case SESSION_EVENT_RX_PAUSE:
1568 return SESSION_EVENT_RX_PAUSE_STR;
1569 case SESSION_EVENT_RX_RESUME:
1570 return SESSION_EVENT_RX_RESUME_STR;
1571 case SESSION_EVENT_TX_START:
1572 return SESSION_EVENT_TX_START_STR;
1573 case SESSION_EVENT_TX_STOP:
1574 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001575 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1576 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001577 default:
1578 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1579 }
1580 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001581 }
1582
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001583 private final Listener mConnectionDeathListener = new Listener() {
1584 @Override
1585 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001586 if (mConferenceables.remove(c)) {
1587 fireOnConferenceableConnectionsChanged();
1588 }
1589 }
1590 };
1591
1592 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1593 @Override
1594 public void onDestroyed(Conference c) {
1595 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001596 fireOnConferenceableConnectionsChanged();
1597 }
1598 }
1599 };
1600
Jay Shrauner229e3822014-08-15 09:23:07 -07001601 /**
1602 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1603 * load factor before resizing, 1 means we only expect a single thread to
1604 * access the map so make only a single shard
1605 */
1606 private final Set<Listener> mListeners = Collections.newSetFromMap(
1607 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001608 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1609 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001610 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001611
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001612 // The internal telecom call ID associated with this connection.
1613 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001615 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001616 private Uri mAddress;
1617 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001618 private String mCallerDisplayName;
1619 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001620 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001621 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001622 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001623 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001624 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001625 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001626 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001627 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001628 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001629 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001630 private Conference mConference;
1631 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001632 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001633 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001634
1635 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001636 * Tracks the key set for the extras bundle provided on the last invocation of
1637 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1638 * keys which were set previously but are no longer present in the replacement Bundle.
1639 */
1640 private Set<String> mPreviousExtraKeys;
1641
1642 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001643 * Create a new Connection.
1644 */
Santos Cordonf2951102014-07-20 19:06:29 -07001645 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001646
1647 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001648 * Returns the Telecom internal call ID associated with this connection. Should only be used
1649 * for debugging and tracing purposes.
1650 *
1651 * @return The Telecom call ID.
1652 * @hide
1653 */
1654 public final String getTelecomCallId() {
1655 return mTelecomCallId;
1656 }
1657
1658 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001659 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001660 */
Andrew Lee100e2932014-09-08 15:34:24 -07001661 public final Uri getAddress() {
1662 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001663 }
1664
1665 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001666 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001667 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001668 */
Andrew Lee100e2932014-09-08 15:34:24 -07001669 public final int getAddressPresentation() {
1670 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001671 }
1672
1673 /**
1674 * @return The caller display name (CNAP).
1675 */
1676 public final String getCallerDisplayName() {
1677 return mCallerDisplayName;
1678 }
1679
1680 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001681 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001682 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001683 */
1684 public final int getCallerDisplayNamePresentation() {
1685 return mCallerDisplayNamePresentation;
1686 }
1687
1688 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001689 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 */
1691 public final int getState() {
1692 return mState;
1693 }
1694
1695 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001696 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001697 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1698 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1699 * {@link VideoProfile#STATE_TX_ENABLED},
1700 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001701 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001702 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001703 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001704 */
1705 public final int getVideoState() {
1706 return mVideoState;
1707 }
1708
1709 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001710 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001711 * being routed by the system. This is {@code null} if this Connection
1712 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001713 * @deprecated Use {@link #getCallAudioState()} instead.
1714 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001715 */
Yorke Lee4af59352015-05-13 14:14:54 -07001716 @SystemApi
1717 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001718 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001719 if (mCallAudioState == null) {
1720 return null;
1721 }
Yorke Lee4af59352015-05-13 14:14:54 -07001722 return new AudioState(mCallAudioState);
1723 }
1724
1725 /**
1726 * @return The audio state of the connection, describing how its audio is currently
1727 * being routed by the system. This is {@code null} if this Connection
1728 * does not directly know about its audio state.
1729 */
1730 public final CallAudioState getCallAudioState() {
1731 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001732 }
1733
1734 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001735 * @return The conference that this connection is a part of. Null if it is not part of any
1736 * conference.
1737 */
1738 public final Conference getConference() {
1739 return mConference;
1740 }
1741
1742 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001743 * Returns whether this connection is requesting that the system play a ringback tone
1744 * on its behalf.
1745 */
Andrew Lee100e2932014-09-08 15:34:24 -07001746 public final boolean isRingbackRequested() {
1747 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001748 }
1749
1750 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001751 * @return True if the connection's audio mode is VOIP.
1752 */
1753 public final boolean getAudioModeIsVoip() {
1754 return mAudioModeIsVoip;
1755 }
1756
1757 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001758 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1759 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1760 * start time of the conference.
1761 *
1762 * @return The time at which the {@code Connnection} was connected.
1763 *
1764 * @hide
1765 */
1766 public final long getConnectTimeMillis() {
1767 return mConnectTimeMillis;
1768 }
1769
1770 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001771 * @return The status hints for this connection.
1772 */
1773 public final StatusHints getStatusHints() {
1774 return mStatusHints;
1775 }
1776
1777 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001778 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001779 * <p>
1780 * Extras should be updated using {@link #putExtras(Bundle)}.
1781 * <p>
1782 * Telecom or an {@link InCallService} can also update the extras via
1783 * {@link android.telecom.Call#putExtras(Bundle)}, and
1784 * {@link Call#removeExtras(List)}.
1785 * <p>
1786 * The connection is notified of changes to the extras made by Telecom or an
1787 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001788 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001789 * @return The extras associated with this connection.
1790 */
1791 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001792 Bundle extras = null;
1793 synchronized (mExtrasLock) {
1794 if (mExtras != null) {
1795 extras = new Bundle(mExtras);
1796 }
1797 }
1798 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001799 }
1800
1801 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 * Assign a listener to be notified of state changes.
1803 *
1804 * @param l A listener.
1805 * @return This Connection.
1806 *
1807 * @hide
1808 */
1809 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001810 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001811 return this;
1812 }
1813
1814 /**
1815 * Remove a previously assigned listener that was being notified of state changes.
1816 *
1817 * @param l A Listener.
1818 * @return This Connection.
1819 *
1820 * @hide
1821 */
1822 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001823 if (l != null) {
1824 mListeners.remove(l);
1825 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001826 return this;
1827 }
1828
1829 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001830 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001831 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001832 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001833 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001834 }
1835
1836 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001837 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1838 * ONLY for debugging purposes.
1839 *
1840 * @param callId The telecom call ID.
1841 * @hide
1842 */
1843 public void setTelecomCallId(String callId) {
1844 mTelecomCallId = callId;
1845 }
1846
1847 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001848 * Inform this Connection that the state of its audio output has been changed externally.
1849 *
1850 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001851 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001852 */
Yorke Lee4af59352015-05-13 14:14:54 -07001853 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001854 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001855 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001856 mCallAudioState = state;
1857 onAudioStateChanged(getAudioState());
1858 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001859 }
1860
1861 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001862 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001863 * @return A string representation of the value.
1864 */
1865 public static String stateToString(int state) {
1866 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001867 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001868 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001869 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001870 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001871 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001872 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001873 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001874 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001875 case STATE_PULLING_CALL:
1876 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001878 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001879 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001880 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001881 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 return "DISCONNECTED";
1883 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001884 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001885 return "UNKNOWN";
1886 }
1887 }
1888
1889 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001890 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001891 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001892 public final int getConnectionCapabilities() {
1893 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001894 }
1895
1896 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001897 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1898 */
1899 public final int getConnectionProperties() {
1900 return mConnectionProperties;
1901 }
1902
1903 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001904 * Returns the connection's supported audio routes.
1905 *
1906 * @hide
1907 */
1908 public final int getSupportedAudioRoutes() {
1909 return mSupportedAudioRoutes;
1910 }
1911
1912 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001913 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914 *
Andrew Lee100e2932014-09-08 15:34:24 -07001915 * @param address The new address.
1916 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001917 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001918 */
Andrew Lee100e2932014-09-08 15:34:24 -07001919 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001920 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001921 Log.d(this, "setAddress %s", address);
1922 mAddress = address;
1923 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001924 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001925 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001926 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001927 }
1928
1929 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001930 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001931 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001932 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001933 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001934 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001935 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001936 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001937 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001938 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001939 mCallerDisplayName = callerDisplayName;
1940 mCallerDisplayNamePresentation = presentation;
1941 for (Listener l : mListeners) {
1942 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1943 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001944 }
1945
1946 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001947 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001948 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1949 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1950 * {@link VideoProfile#STATE_TX_ENABLED},
1951 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001952 *
1953 * @param videoState The new video state.
1954 */
1955 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001956 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001957 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001958 mVideoState = videoState;
1959 for (Listener l : mListeners) {
1960 l.onVideoStateChanged(this, mVideoState);
1961 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001962 }
1963
1964 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001965 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966 * communicate).
1967 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001968 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001969 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001970 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001971 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001972 }
1973
1974 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001975 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001976 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001977 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001978 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001979 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001980 }
1981
1982 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001983 * Sets state to initializing (this Connection is not yet ready to be used).
1984 */
1985 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001986 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001987 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001988 }
1989
1990 /**
1991 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1992 */
1993 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001994 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001995 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001996 }
1997
1998 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001999 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002000 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002001 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002002 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002003 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 }
2005
2006 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002007 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2008 * device). Only applicable for {@link Connection}s with
2009 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2010 */
2011 public final void setPulling() {
2012 checkImmutable();
2013 setState(STATE_PULLING_CALL);
2014 }
2015
2016 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002017 * Sets state to be on hold.
2018 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002019 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002020 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002021 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002022 }
2023
2024 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002025 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002026 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002027 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002028 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002029 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002030 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002031 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002032 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002033 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002034 }
2035
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002036 public final VideoProvider getVideoProvider() {
2037 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002038 }
2039
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002040 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002041 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002042 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002043 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002044 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002045 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002046 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002047 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002048 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002049 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002050 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002051 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002052 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002053 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002054 }
2055
2056 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002057 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2058 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2059 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2060 * to send an {@link #onPostDialContinue(boolean)} signal.
2061 *
2062 * @param remaining The DTMF character sequence remaining to be emitted once the
2063 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2064 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002065 */
2066 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002067 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002068 for (Listener l : mListeners) {
2069 l.onPostDialWait(this, remaining);
2070 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002071 }
2072
2073 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002074 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2075 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002076 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002077 *
2078 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002079 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002080 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002081 checkImmutable();
2082 for (Listener l : mListeners) {
2083 l.onPostDialChar(this, nextChar);
2084 }
2085 }
2086
2087 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002088 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002090 *
2091 * @param ringback Whether the ringback tone is to be played.
2092 */
Andrew Lee100e2932014-09-08 15:34:24 -07002093 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002094 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002095 if (mRingbackRequested != ringback) {
2096 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002097 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002098 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002099 }
2100 }
Ihab Awadf8358972014-05-28 16:46:42 -07002101 }
2102
2103 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002104 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002105 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002106 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002107 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002108 public final void setConnectionCapabilities(int connectionCapabilities) {
2109 checkImmutable();
2110 if (mConnectionCapabilities != connectionCapabilities) {
2111 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002112 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002113 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002114 }
2115 }
Santos Cordonb6939982014-06-04 20:20:58 -07002116 }
2117
2118 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002119 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2120 *
2121 * @param connectionProperties The new connection properties.
2122 */
2123 public final void setConnectionProperties(int connectionProperties) {
2124 checkImmutable();
2125 if (mConnectionProperties != connectionProperties) {
2126 mConnectionProperties = connectionProperties;
2127 for (Listener l : mListeners) {
2128 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2129 }
2130 }
2131 }
2132
2133 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002134 * Sets the supported audio routes.
2135 *
2136 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2137 * See {@link CallAudioState}
2138 * @hide
2139 */
2140 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2141 if ((supportedAudioRoutes
2142 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2143 throw new IllegalArgumentException(
2144 "supported audio routes must include either speaker or earpiece");
2145 }
2146
2147 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2148 mSupportedAudioRoutes = supportedAudioRoutes;
2149 for (Listener l : mListeners) {
2150 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2151 }
2152 }
2153 }
2154
2155 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002156 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002157 */
Evan Charlton36a71342014-07-19 16:31:02 -07002158 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002159 for (Listener l : mListeners) {
2160 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002161 }
Santos Cordonb6939982014-06-04 20:20:58 -07002162 }
2163
2164 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002165 * Requests that the framework use VOIP audio mode for this connection.
2166 *
2167 * @param isVoip True if the audio mode is VOIP.
2168 */
2169 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002171 mAudioModeIsVoip = isVoip;
2172 for (Listener l : mListeners) {
2173 l.onAudioModeIsVoipChanged(this, isVoip);
2174 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002175 }
2176
2177 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002178 * Sets the time at which a call became active on this Connection. This is set only
2179 * when a conference call becomes active on this connection.
2180 *
2181 * @param connectionTimeMillis The connection time, in milliseconds.
2182 *
2183 * @hide
2184 */
2185 public final void setConnectTimeMillis(long connectTimeMillis) {
2186 mConnectTimeMillis = connectTimeMillis;
2187 }
2188
2189 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002190 * Sets the label and icon status to display in the in-call UI.
2191 *
2192 * @param statusHints The status label and icon to set.
2193 */
2194 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002195 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002196 mStatusHints = statusHints;
2197 for (Listener l : mListeners) {
2198 l.onStatusHintsChanged(this, statusHints);
2199 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002200 }
2201
2202 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002203 * Sets the connections with which this connection can be conferenced.
2204 *
2205 * @param conferenceableConnections The set of connections this connection can conference with.
2206 */
2207 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002208 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002209 clearConferenceableList();
2210 for (Connection c : conferenceableConnections) {
2211 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2212 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002213 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002214 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002215 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002216 }
2217 }
2218 fireOnConferenceableConnectionsChanged();
2219 }
2220
2221 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002222 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2223 * or conferences with which this connection can be conferenced.
2224 *
2225 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002226 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002227 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002228 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002229 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002230 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2231 // small amount of items here.
2232 if (!mConferenceables.contains(c)) {
2233 if (c instanceof Connection) {
2234 Connection connection = (Connection) c;
2235 connection.addConnectionListener(mConnectionDeathListener);
2236 } else if (c instanceof Conference) {
2237 Conference conference = (Conference) c;
2238 conference.addListener(mConferenceDeathListener);
2239 }
2240 mConferenceables.add(c);
2241 }
2242 }
2243 fireOnConferenceableConnectionsChanged();
2244 }
2245
2246 /**
2247 * Returns the connections or conferences with which this connection can be conferenced.
2248 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002249 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002250 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002251 }
2252
Yorke Lee53463962015-08-04 16:07:19 -07002253 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002254 * @hide
2255 */
2256 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002257 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002258 if (mConnectionService != null) {
2259 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2260 "which is already associated with another ConnectionService.");
2261 } else {
2262 mConnectionService = connectionService;
2263 }
2264 }
2265
2266 /**
2267 * @hide
2268 */
2269 public final void unsetConnectionService(ConnectionService connectionService) {
2270 if (mConnectionService != connectionService) {
2271 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2272 "that does not belong to the ConnectionService.");
2273 } else {
2274 mConnectionService = null;
2275 }
2276 }
2277
2278 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002279 * @hide
2280 */
2281 public final ConnectionService getConnectionService() {
2282 return mConnectionService;
2283 }
2284
2285 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002286 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002287 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002288 *
2289 * @param conference The conference.
2290 * @return {@code true} if the conference was successfully set.
2291 * @hide
2292 */
2293 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002294 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002295 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002296 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002297 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002298 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2299 fireConferenceChanged();
2300 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002301 return true;
2302 }
2303 return false;
2304 }
2305
2306 /**
2307 * Resets the conference that this connection is a part of.
2308 * @hide
2309 */
2310 public final void resetConference() {
2311 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002312 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002313 mConference = null;
2314 fireConferenceChanged();
2315 }
2316 }
2317
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002318 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002319 * Set some extras that can be associated with this {@code Connection}.
2320 * <p>
2321 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2322 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2323 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002324 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2325 * {@link #removeExtras(String...)} methods to modify the extras.
2326 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002327 * 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 -07002328 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2329 *
2330 * @param extras The extras associated with this {@code Connection}.
2331 */
2332 public final void setExtras(@Nullable Bundle extras) {
2333 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002334
2335 // Add/replace any new or changed extras values.
2336 putExtras(extras);
2337
2338 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2339 // the current one and remove any keys that went away.
2340 if (mPreviousExtraKeys != null) {
2341 List<String> toRemove = new ArrayList<String>();
2342 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002343 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002344 toRemove.add(oldKey);
2345 }
2346 }
2347 if (!toRemove.isEmpty()) {
2348 removeExtras(toRemove);
2349 }
2350 }
2351
2352 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2353 // called we can see if the caller has removed any extras values.
2354 if (mPreviousExtraKeys == null) {
2355 mPreviousExtraKeys = new ArraySet<String>();
2356 }
2357 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002358 if (extras != null) {
2359 mPreviousExtraKeys.addAll(extras.keySet());
2360 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002361 }
2362
2363 /**
2364 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2365 * added.
2366 * <p>
2367 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2368 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2369 *
2370 * @param extras The extras to add.
2371 */
2372 public final void putExtras(@NonNull Bundle extras) {
2373 checkImmutable();
2374 if (extras == null) {
2375 return;
2376 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002377 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2378 // the listeners.
2379 Bundle listenerExtras;
2380 synchronized (mExtrasLock) {
2381 if (mExtras == null) {
2382 mExtras = new Bundle();
2383 }
2384 mExtras.putAll(extras);
2385 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002386 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002387 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002388 // Create a new clone of the extras for each listener so that they don't clobber
2389 // each other
2390 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002391 }
2392 }
2393
2394 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002395 * Adds a boolean extra to this {@code Connection}.
2396 *
2397 * @param key The extra key.
2398 * @param value The value.
2399 * @hide
2400 */
2401 public final void putExtra(String key, boolean value) {
2402 Bundle newExtras = new Bundle();
2403 newExtras.putBoolean(key, value);
2404 putExtras(newExtras);
2405 }
2406
2407 /**
2408 * Adds an integer extra to this {@code Connection}.
2409 *
2410 * @param key The extra key.
2411 * @param value The value.
2412 * @hide
2413 */
2414 public final void putExtra(String key, int value) {
2415 Bundle newExtras = new Bundle();
2416 newExtras.putInt(key, value);
2417 putExtras(newExtras);
2418 }
2419
2420 /**
2421 * Adds a string extra to this {@code Connection}.
2422 *
2423 * @param key The extra key.
2424 * @param value The value.
2425 * @hide
2426 */
2427 public final void putExtra(String key, String value) {
2428 Bundle newExtras = new Bundle();
2429 newExtras.putString(key, value);
2430 putExtras(newExtras);
2431 }
2432
2433 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002434 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002435 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002436 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002437 */
2438 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002439 synchronized (mExtrasLock) {
2440 if (mExtras != null) {
2441 for (String key : keys) {
2442 mExtras.remove(key);
2443 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002444 }
2445 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002446 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002447 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002448 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002449 }
2450 }
2451
2452 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002453 * Removes extras from this {@code Connection}.
2454 *
2455 * @param keys The keys of the extras to remove.
2456 */
2457 public final void removeExtras(String ... keys) {
2458 removeExtras(Arrays.asList(keys));
2459 }
2460
2461 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002462 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2463 * be change to the {@link #getCallAudioState()}.
2464 * <p>
2465 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2466 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2467 * <p>
2468 * See also {@link InCallService#setAudioRoute(int)}.
2469 *
2470 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2471 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2472 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2473 */
2474 public final void setAudioRoute(int route) {
2475 for (Listener l : mListeners) {
2476 l.onAudioRouteChanged(this, route);
2477 }
2478 }
2479
2480 /**
Hall Liu57006aa2017-02-06 10:49:48 -08002481 * Informs listeners that a previously requested RTT session via
2482 * {@link ConnectionRequest#isRequestingRtt()} or
2483 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2484 * @hide
2485 */
2486 public final void sendRttInitiationSuccess() {
2487 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2488 }
2489
2490 /**
2491 * Informs listeners that a previously requested RTT session via
2492 * {@link ConnectionRequest#isRequestingRtt()} or
2493 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2494 * has failed.
2495 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2496 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2497 * @hide
2498 */
2499 public final void sendRttInitiationFailure(int reason) {
2500 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2501 }
2502
2503 /**
2504 * Informs listeners that a currently active RTT session has been terminated by the remote
2505 * side of the coll.
2506 * @hide
2507 */
2508 public final void sendRttSessionRemotelyTerminated() {
2509 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2510 }
2511
2512 /**
2513 * Informs listeners that the remote side of the call has requested an upgrade to include an
2514 * RTT session in the call.
2515 * @hide
2516 */
2517 public final void sendRemoteRttRequest() {
2518 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2519 }
2520
2521 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002522 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002523 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002524 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002525 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2526 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002527 */
Yorke Lee4af59352015-05-13 14:14:54 -07002528 @SystemApi
2529 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002530 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002531
2532 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002533 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2534 *
2535 * @param state The new connection audio state.
2536 */
2537 public void onCallAudioStateChanged(CallAudioState state) {}
2538
2539 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002540 * Notifies this Connection of an internal state change. This method is called after the
2541 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002542 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002543 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002544 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002545 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002546
2547 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002548 * Notifies this Connection of a request to play a DTMF tone.
2549 *
2550 * @param c A DTMF character.
2551 */
Santos Cordonf2951102014-07-20 19:06:29 -07002552 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002553
2554 /**
2555 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2556 */
Santos Cordonf2951102014-07-20 19:06:29 -07002557 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002558
2559 /**
2560 * Notifies this Connection of a request to disconnect.
2561 */
Santos Cordonf2951102014-07-20 19:06:29 -07002562 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002563
2564 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002565 * Notifies this Connection of a request to disconnect a participant of the conference managed
2566 * by the connection.
2567 *
2568 * @param endpoint the {@link Uri} of the participant to disconnect.
2569 * @hide
2570 */
2571 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2572
2573 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002574 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002575 */
Santos Cordonf2951102014-07-20 19:06:29 -07002576 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002577
2578 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002579 * Notifies this Connection of a request to abort.
2580 */
Santos Cordonf2951102014-07-20 19:06:29 -07002581 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002582
2583 /**
2584 * Notifies this Connection of a request to hold.
2585 */
Santos Cordonf2951102014-07-20 19:06:29 -07002586 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002587
2588 /**
2589 * Notifies this Connection of a request to exit a hold state.
2590 */
Santos Cordonf2951102014-07-20 19:06:29 -07002591 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002592
2593 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002594 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002595 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002596 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002597 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002598 */
Santos Cordonf2951102014-07-20 19:06:29 -07002599 public void onAnswer(int videoState) {}
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
Tyler Gunnbe74de02014-08-29 14:51:48 -07002603 * a request to accept.
2604 */
2605 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002606 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002607 }
2608
2609 /**
2610 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002611 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002612 */
Santos Cordonf2951102014-07-20 19:06:29 -07002613 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002614
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002615 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002616 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2617 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002618 */
2619 public void onReject(String replyMessage) {}
2620
2621 /**
Bryce Leecac50772015-11-17 15:13:29 -08002622 * Notifies the Connection of a request to silence the ringer.
2623 *
2624 * @hide
2625 */
2626 public void onSilence() {}
2627
2628 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002629 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2630 */
Santos Cordonf2951102014-07-20 19:06:29 -07002631 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002632
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002633 /**
2634 * Notifies this Connection of a request to pull an external call to the local device.
2635 * <p>
2636 * The {@link InCallService} issues a request to pull an external call to the local device via
2637 * {@link Call#pullExternalCall()}.
2638 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002639 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2640 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002641 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002642 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002643 */
2644 public void onPullExternalCall() {}
2645
2646 /**
2647 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2648 * <p>
2649 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2650 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002651 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2652 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2653 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2654 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2655 * not aware of.
2656 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002657 * See also {@link Call#sendCallEvent(String, Bundle)}.
2658 *
2659 * @param event The call event.
2660 * @param extras Extras associated with the call event.
2661 */
2662 public void onCallEvent(String event, Bundle extras) {}
2663
Tyler Gunndee56a82016-03-23 16:06:34 -07002664 /**
2665 * Notifies this {@link Connection} of a change to the extras made outside the
2666 * {@link ConnectionService}.
2667 * <p>
2668 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2669 * the {@link android.telecom.Call#putExtras(Bundle)} and
2670 * {@link Call#removeExtras(List)}.
2671 *
2672 * @param extras The new extras bundle.
2673 */
2674 public void onExtrasChanged(Bundle extras) {}
2675
Tyler Gunnf5035432017-01-09 09:43:12 -08002676 /**
2677 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2678 * displaying its incoming call user interface for the {@link Connection}.
2679 * <p>
2680 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2681 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2682 * should show its own incoming call user interface.
2683 * <p>
2684 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2685 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2686 * user interface to allow the user to choose whether to answer the new incoming call and
2687 * disconnect other ongoing calls, or to reject the new incoming call.
2688 */
2689 public void onShowIncomingCallUi() {}
2690
Hall Liu57006aa2017-02-06 10:49:48 -08002691 /**
2692 * Notifies this {@link Connection} that the user has requested an RTT session.
2693 * The connection service should call {@link #sendRttInitiationSuccess} or
2694 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2695 * request, respectively.
2696 * @param rttTextStream The object that should be used to send text to or receive text from
2697 * the in-call app.
2698 * @hide
2699 */
2700 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2701
2702 /**
2703 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2704 * channel. No response to Telecom is needed for this method.
2705 * @hide
2706 */
2707 public void onStopRtt() {}
2708
2709 /**
2710 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2711 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2712 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2713 * indicated by {@code rttTextStream} being {@code null}
2714 * @hide
2715 * @param rttTextStream The object that should be used to send text to or receive text from
2716 * the in-call app.
2717 */
2718 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2719
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002720 static String toLogSafePhoneNumber(String number) {
2721 // For unknown number, log empty string.
2722 if (number == null) {
2723 return "";
2724 }
2725
2726 if (PII_DEBUG) {
2727 // When PII_DEBUG is true we emit PII.
2728 return number;
2729 }
2730
2731 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2732 // sanitized phone numbers.
2733 StringBuilder builder = new StringBuilder();
2734 for (int i = 0; i < number.length(); i++) {
2735 char c = number.charAt(i);
2736 if (c == '-' || c == '@' || c == '.') {
2737 builder.append(c);
2738 } else {
2739 builder.append('x');
2740 }
2741 }
2742 return builder.toString();
2743 }
2744
Ihab Awad542e0ea2014-05-16 10:22:16 -07002745 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002746 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002747 if (mState == STATE_DISCONNECTED && mState != state) {
2748 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002749 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002750 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002751 if (mState != state) {
2752 Log.d(this, "setState: %s", stateToString(state));
2753 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002754 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002755 for (Listener l : mListeners) {
2756 l.onStateChanged(this, state);
2757 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002758 }
2759 }
2760
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002761 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002762 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002763 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2764 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002765 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002766 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002767
2768 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002769 if (mImmutable) {
2770 throw new UnsupportedOperationException("Connection is immutable");
2771 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002772 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002773 }
2774
Evan Charltonbf11f982014-07-20 22:06:28 -07002775 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002776 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002777 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2778 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002779 * <p>
2780 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2781 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002782 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002783 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002784 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002785 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002786 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2787 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002788 }
2789
Evan Charltonbf11f982014-07-20 22:06:28 -07002790 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002791 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2792 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2793 * this should never be un-@hide-den.
2794 *
2795 * @hide
2796 */
2797 public void checkImmutable() {}
2798
2799 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002800 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2801 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2802 * that state. This connection should not be used for anything, and no other
2803 * {@code Connection}s should be attempted.
2804 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002805 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002806 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002807 * @return A {@code Connection} which indicates that the underlying connection should
2808 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002809 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002810 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002811 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002812 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002813
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002814 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002815 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002816 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002817 }
2818 }
2819
Santos Cordon823fd3c2014-08-07 18:35:18 -07002820 private final void fireConferenceChanged() {
2821 for (Listener l : mListeners) {
2822 l.onConferenceChanged(this, mConference);
2823 }
2824 }
2825
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002826 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002827 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002828 if (c instanceof Connection) {
2829 Connection connection = (Connection) c;
2830 connection.removeConnectionListener(mConnectionDeathListener);
2831 } else if (c instanceof Conference) {
2832 Conference conference = (Conference) c;
2833 conference.removeListener(mConferenceDeathListener);
2834 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002835 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002836 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002837 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002838
2839 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002840 * Handles a change to extras received from Telecom.
2841 *
2842 * @param extras The new extras.
2843 * @hide
2844 */
2845 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002846 Bundle b = null;
2847 synchronized (mExtrasLock) {
2848 mExtras = extras;
2849 if (mExtras != null) {
2850 b = new Bundle(mExtras);
2851 }
2852 }
2853 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002854 }
2855
2856 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002857 * Notifies listeners that the merge request failed.
2858 *
2859 * @hide
2860 */
2861 protected final void notifyConferenceMergeFailed() {
2862 for (Listener l : mListeners) {
2863 l.onConferenceMergeFailed(this);
2864 }
2865 }
2866
2867 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002868 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002869 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002870 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002871 * @hide
2872 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002873 protected final void updateConferenceParticipants(
2874 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002875 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002876 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002877 }
2878 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002879
2880 /**
2881 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002882 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002883 */
2884 protected void notifyConferenceStarted() {
2885 for (Listener l : mListeners) {
2886 l.onConferenceStarted();
2887 }
2888 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002889
2890 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002891 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2892 * be a part of a conference call.
2893 * @param isConferenceSupported {@code true} if the connection supports being part of a
2894 * conference call, {@code false} otherwise.
2895 * @hide
2896 */
2897 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2898 for (Listener l : mListeners) {
2899 l.onConferenceSupportedChanged(this, isConferenceSupported);
2900 }
2901 }
2902
2903 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002904 * Sends an event associated with this {@code Connection} with associated event extras to the
2905 * {@link InCallService}.
2906 * <p>
2907 * Connection events are used to communicate point in time information from a
2908 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2909 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2910 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2911 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2912 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2913 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2914 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2915 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2916 * <p>
2917 * Events are exposed to {@link InCallService} implementations via
2918 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2919 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002920 * 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 -07002921 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2922 * some events altogether.
2923 * <p>
2924 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2925 * conflicts between {@link ConnectionService} implementations. Further, custom
2926 * {@link ConnectionService} implementations shall not re-purpose events in the
2927 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2928 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2929 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2930 * {@code com.example.extra.MY_EXTRA}).
2931 * <p>
2932 * When defining events and the associated extras, it is important to keep their behavior
2933 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2934 * events/extras should me maintained to ensure backwards compatibility with older
2935 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002936 *
2937 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002938 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002939 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002940 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002941 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002942 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002943 }
2944 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002945}