blob: 417fa3bfb178b1d40f1364ff8d7efabbfa2ed8ab [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.app.Notification;
27import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070028import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080030import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070031import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Handler;
33import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070034import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080036import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.RemoteException;
Tyler Gunndee56a82016-03-23 16:06:34 -070038import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040
Hall Liu95d55872017-01-25 17:12:49 -080041import java.io.IOException;
42import java.io.InputStreamReader;
43import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070044import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070045import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070046import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070047import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070048import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070049import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070050
51/**
Santos Cordon895d4b82015-06-25 16:41:48 -070052 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
53 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070054 * <p>
55 * Implementations create a custom subclass of {@code Connection} and return it to the framework
56 * as the return value of
57 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
58 * or
59 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
60 * Implementations are then responsible for updating the state of the {@code Connection}, and
61 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
62 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070063 * <p>
64 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
65 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
66 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
67 * {@code Connection} instance.
68 * <p>
69 * Basic call support requires overriding the following methods: {@link #onAnswer()},
70 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
71 * <p>
72 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
73 * {@link #onUnhold()} methods should be overridden to provide hold support for the
74 * {@code Connection}.
75 * <p>
76 * Where a {@code Connection} supports a variation of video calling (e.g. the
77 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
78 * to support answering a call as a video call.
79 * <p>
80 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
81 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
82 * support for pulling the external call.
83 * <p>
84 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
85 * overridden.
86 * <p>
87 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
88 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
89 * for example, call events from a {@link InCallService} are handled,
90 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
91 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
92 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
93 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070094 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070095public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070096
Santos Cordon895d4b82015-06-25 16:41:48 -070097 /**
98 * The connection is initializing. This is generally the first state for a {@code Connection}
99 * returned by a {@link ConnectionService}.
100 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700101 public static final int STATE_INITIALIZING = 0;
102
Santos Cordon895d4b82015-06-25 16:41:48 -0700103 /**
104 * The connection is new and not connected.
105 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 public static final int STATE_NEW = 1;
107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * An incoming connection is in the ringing state. During this state, the user's ringer or
110 * vibration feature will be activated.
111 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 public static final int STATE_RINGING = 2;
113
Santos Cordon895d4b82015-06-25 16:41:48 -0700114 /**
115 * An outgoing connection is in the dialing state. In this state the other party has not yet
116 * answered the call and the user traditionally hears a ringback tone.
117 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700118 public static final int STATE_DIALING = 3;
119
Santos Cordon895d4b82015-06-25 16:41:48 -0700120 /**
121 * A connection is active. Both parties are connected to the call and can actively communicate.
122 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 public static final int STATE_ACTIVE = 4;
124
Santos Cordon895d4b82015-06-25 16:41:48 -0700125 /**
126 * A connection is on hold.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_HOLDING = 5;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * A connection has been disconnected. This is the final state once the user has been
132 * disconnected from a call either locally, remotely or by an error in the service.
133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 public static final int STATE_DISCONNECTED = 6;
135
Santos Cordon895d4b82015-06-25 16:41:48 -0700136 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700137 * The state of an external connection which is in the process of being pulled from a remote
138 * device to the local device.
139 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700140 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700141 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
142 */
143 public static final int STATE_PULLING_CALL = 7;
144
145 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700146 * Connection can currently be put on hold or unheld. This is distinct from
147 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
148 * it does not at the moment support the function. This can be true while the call is in the
149 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
150 * display a disabled 'hold' button.
151 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152 public static final int CAPABILITY_HOLD = 0x00000001;
153
154 /** Connection supports the hold feature. */
155 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
156
157 /**
158 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
159 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
160 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
161 * capability allows a merge button to be shown while the conference is in the foreground
162 * of the in-call UI.
163 * <p>
164 * This is only intended for use by a {@link Conference}.
165 */
166 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
167
168 /**
169 * Connections within a conference can be swapped between foreground and background.
170 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
171 * <p>
172 * This is only intended for use by a {@link Conference}.
173 */
174 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
175
176 /**
177 * @hide
178 */
179 public static final int CAPABILITY_UNUSED = 0x00000010;
180
181 /** Connection supports responding via text option. */
182 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
183
184 /** Connection can be muted. */
185 public static final int CAPABILITY_MUTE = 0x00000040;
186
187 /**
188 * Connection supports conference management. This capability only applies to
189 * {@link Conference}s which can have {@link Connection}s as children.
190 */
191 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
192
193 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700194 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800195 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700196 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800197
198 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700206 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208
209 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
213
214 /**
215 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 */
217 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
218
219 /**
220 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700222 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700223 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800224
225 /**
226 * Connection is able to be separated from its parent {@code Conference}, if any.
227 */
228 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
229
230 /**
231 * Connection is able to be individually disconnected when in a {@code Conference}.
232 */
233 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
234
235 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700236 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800237 * @hide
238 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800240
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700242 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700243 * @hide
244 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246
247 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 * @hide
250 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252
Tyler Gunn068085b2015-02-06 13:56:52 -0800253 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800255 * @hide
256 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800258
Tyler Gunn96d6c402015-03-18 12:39:23 -0700259 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500260 * Speed up audio setup for MT call.
261 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700262 */
263 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800264
Rekha Kumar07366812015-03-24 16:42:31 -0700265 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700266 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700267 */
268 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
269
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700270 /**
271 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700272 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700273 */
274 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
275
Tyler Gunnd4091732015-06-29 09:15:37 -0700276 /**
277 * For a conference, indicates the conference will not have child connections.
278 * <p>
279 * An example of a conference with child connections is a GSM conference call, where the radio
280 * retains connections to the individual participants of the conference. Another example is an
281 * IMS conference call where conference event package functionality is supported; in this case
282 * the conference server ensures the radio is aware of the participants in the conference, which
283 * are represented by child connections.
284 * <p>
285 * An example of a conference with no child connections is an IMS conference call with no
286 * conference event package support. Such a conference is represented by the radio as a single
287 * connection to the IMS conference server.
288 * <p>
289 * Indicating whether a conference has children or not is important to help user interfaces
290 * visually represent a conference. A conference with no children, for example, will have the
291 * conference connection shown in the list of calls on a Bluetooth device, where if the
292 * conference has children, only the children will be shown in the list of calls on a Bluetooth
293 * device.
294 * @hide
295 */
296 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
297
Bryce Lee81901682015-08-28 16:38:02 -0700298 /**
299 * Indicates that the connection itself wants to handle any sort of reply response, rather than
300 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700301 */
302 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
303
Tyler Gunnf97a0092016-01-19 15:59:34 -0800304 /**
305 * When set, prevents a video call from being downgraded to an audio-only call.
306 * <p>
307 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
308 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
309 * downgraded from a video call back to a VideoState of
310 * {@link VideoProfile#STATE_AUDIO_ONLY}.
311 * <p>
312 * Intuitively, a call which can be downgraded to audio should also have local and remote
313 * video
314 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
315 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
316 */
317 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
318
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700319 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700320 * When set for an external connection, indicates that this {@code Connection} can be pulled
321 * from a remote device to the current device.
322 * <p>
323 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
324 * is set.
325 */
326 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
327
328 //**********************************************************************************************
329 // Next CAPABILITY value: 0x02000000
330 //**********************************************************************************************
331
332 /**
333 * Indicates that the current device callback number should be shown.
334 *
335 * @hide
336 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700337 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700338
339 /**
340 * Whether the call is a generic conference, where we do not know the precise state of
341 * participants in the conference (eg. on CDMA).
342 *
343 * @hide
344 */
345 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
346
347 /**
348 * Connection is using high definition audio.
349 * @hide
350 */
351 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
352
353 /**
354 * Connection is using WIFI.
355 * @hide
356 */
357 public static final int PROPERTY_WIFI = 1<<3;
358
359 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700360 * When set, indicates that the {@code Connection} does not actually exist locally for the
361 * {@link ConnectionService}.
362 * <p>
363 * Consider, for example, a scenario where a user has two devices with the same phone number.
364 * When a user places a call on one devices, the telephony stack can represent that call on the
365 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700366 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367 * <p>
368 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
369 * external connections. Only those {@link InCallService}s which have the
370 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
371 * manifest will see external connections.
372 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700373 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700374
Brad Ebinger15847072016-05-18 11:08:36 -0700375 /**
376 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
377 */
378 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700379
Hall Liu9f332c72016-07-14 15:37:37 -0700380 /**
381 * Indicates that the connection represents a downgraded IMS conference.
382 * @hide
383 */
384 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
385
Tyler Gunnf5035432017-01-09 09:43:12 -0800386 /**
387 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
388 * {@link ConnectionService}.
389 * <p>
390 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
391 */
392 public static final int PROPERTY_SELF_MANAGED = 1<<7;
393
Hall Liu95d55872017-01-25 17:12:49 -0800394 /**
395 * When set, indicates that a connection has an active RTT session associated with it.
396 * @hide
397 */
398 public static final int PROPERTY_IS_RTT = 1 << 8;
399
Tyler Gunn96d6c402015-03-18 12:39:23 -0700400 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800401 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700402 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800403
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700404 /**
405 * Connection extra key used to store the last forwarded number associated with the current
406 * connection. Used to communicate to the user interface that the connection was forwarded via
407 * the specified number.
408 */
409 public static final String EXTRA_LAST_FORWARDED_NUMBER =
410 "android.telecom.extra.LAST_FORWARDED_NUMBER";
411
412 /**
413 * Connection extra key used to store a child number associated with the current connection.
414 * Used to communicate to the user interface that the connection was received via
415 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
416 * address.
417 */
418 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
419
420 /**
421 * Connection extra key used to store the subject for an incoming call. The user interface can
422 * query this extra and display its contents for incoming calls. Will only be used if the
423 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
424 */
425 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
426
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800427 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700428 * Boolean connection extra key set on a {@link Connection} in
429 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
430 * current active foreground call to be dropped.
431 */
432 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
433 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
434
435 /**
Hall Liu10208662016-06-15 17:55:00 -0700436 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700437 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700438 * @hide
439 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700440 public static final String EXTRA_DISABLE_ADD_CALL =
441 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700442
443 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700444 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
445 * original Connection ID associated with the connection. Used in
446 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
447 * connection/conference added via
448 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
449 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
450 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
451 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
452 * be a way to ensure that we don't add the connection again as a duplicate.
453 * <p>
454 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
455 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
456 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
457 * in a new {@link Connection} which it adds to Telecom via
458 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
459 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
460 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
461 * ID it originally referred to the connection as. Thus Telecom needs to know that the
462 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
463 * @hide
464 */
465 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
466 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
467
468 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800469 * Connection event used to inform Telecom that it should play the on hold tone. This is used
470 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700471 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800472 * @hide
473 */
474 public static final String EVENT_ON_HOLD_TONE_START =
475 "android.telecom.event.ON_HOLD_TONE_START";
476
477 /**
478 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
479 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700480 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800481 * @hide
482 */
483 public static final String EVENT_ON_HOLD_TONE_END =
484 "android.telecom.event.ON_HOLD_TONE_END";
485
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700486 /**
487 * Connection event used to inform {@link InCallService}s when pulling of an external call has
488 * failed. The user interface should inform the user of the error.
489 * <p>
490 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
491 * API is called on a {@link Call} with the properties
492 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
493 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
494 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700495 * <p>
496 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
497 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700498 */
499 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
500
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700501 /**
502 * Connection event used to inform {@link InCallService}s when the merging of two calls has
503 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700504 * <p>
505 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
506 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700507 */
508 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
509
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700510 /**
511 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
512 * the remote party.
513 * <p>
514 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
515 * call is being held locally on the device. When a capable {@link ConnectionService} receives
516 * signalling to indicate that the remote party has put the call on hold, it can send this
517 * connection event.
518 * @hide
519 */
520 public static final String EVENT_CALL_REMOTELY_HELD =
521 "android.telecom.event.CALL_REMOTELY_HELD";
522
523 /**
524 * Connection event used to inform {@link InCallService}s when a call which was remotely held
525 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
526 * <p>
527 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
528 * call is being held locally on the device. When a capable {@link ConnectionService} receives
529 * signalling to indicate that the remote party has taken the call off hold, it can send this
530 * connection event.
531 * @hide
532 */
533 public static final String EVENT_CALL_REMOTELY_UNHELD =
534 "android.telecom.event.CALL_REMOTELY_UNHELD";
535
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700536 // Flag controlling whether PII is emitted into the logs
537 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
538
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800539 /**
540 * Whether the given capabilities support the specified capability.
541 *
542 * @param capabilities A capability bit field.
543 * @param capability The capability to check capabilities for.
544 * @return Whether the specified capability is supported.
545 * @hide
546 */
547 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800548 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800549 }
550
551 /**
552 * Whether the capabilities of this {@code Connection} supports the specified capability.
553 *
554 * @param capability The capability to check capabilities for.
555 * @return Whether the specified capability is supported.
556 * @hide
557 */
558 public boolean can(int capability) {
559 return can(mConnectionCapabilities, capability);
560 }
561
562 /**
563 * Removes the specified capability from the set of capabilities of this {@code Connection}.
564 *
565 * @param capability The capability to remove from the set.
566 * @hide
567 */
568 public void removeCapability(int capability) {
569 mConnectionCapabilities &= ~capability;
570 }
571
572 /**
573 * Adds the specified capability to the set of capabilities of this {@code Connection}.
574 *
575 * @param capability The capability to add to the set.
576 * @hide
577 */
578 public void addCapability(int capability) {
579 mConnectionCapabilities |= capability;
580 }
581
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700582 /**
583 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
584 *
585 * @param capabilities A capability bit field.
586 * @return A human readable string representation.
587 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800588 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700589 return capabilitiesToStringInternal(capabilities, true /* isLong */);
590 }
591
592 /**
593 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
594 * string.
595 *
596 * @param capabilities A capability bit field.
597 * @return A human readable string representation.
598 * @hide
599 */
600 public static String capabilitiesToStringShort(int capabilities) {
601 return capabilitiesToStringInternal(capabilities, false /* isLong */);
602 }
603
604 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800605 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700606 builder.append("[");
607 if (isLong) {
608 builder.append("Capabilities:");
609 }
610
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700612 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800613 }
614 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700615 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800616 }
617 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700618 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800619 }
620 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700621 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800622 }
623 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700624 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800625 }
626 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700627 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800628 }
629 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700630 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800631 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700632 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700633 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700634 }
635 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700636 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700637 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700638 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700639 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700641 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700642 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700643 }
644 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700645 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700646 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700647 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700648 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800650 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700651 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800652 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500653 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700654 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500655 }
Rekha Kumar07366812015-03-24 16:42:31 -0700656 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700657 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700658 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700659 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700661 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700662 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700663 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700664 }
Bryce Lee81901682015-08-28 16:38:02 -0700665 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700667 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700668 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700670 }
Bryce Lee81901682015-08-28 16:38:02 -0700671
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800672 builder.append("]");
673 return builder.toString();
674 }
675
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700676 /**
677 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
678 *
679 * @param properties A property bit field.
680 * @return A human readable string representation.
681 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700682 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700683 return propertiesToStringInternal(properties, true /* isLong */);
684 }
685
686 /**
687 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
688 *
689 * @param properties A property bit field.
690 * @return A human readable string representation.
691 * @hide
692 */
693 public static String propertiesToStringShort(int properties) {
694 return propertiesToStringInternal(properties, false /* isLong */);
695 }
696
697 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700698 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append("[");
700 if (isLong) {
701 builder.append("Properties:");
702 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700703
Tyler Gunnf5035432017-01-09 09:43:12 -0800704 if (can(properties, PROPERTY_SELF_MANAGED)) {
705 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
706 }
707
Hall Liu25c7c4d2016-08-30 13:41:02 -0700708 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
709 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700710 }
711
712 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700713 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700714 }
715
716 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700718 }
719
720 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700722 }
723
724 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700726 }
727
Brad Ebinger15847072016-05-18 11:08:36 -0700728 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700729 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700730 }
731
Tyler Gunn720c6642016-03-22 09:02:47 -0700732 builder.append("]");
733 return builder.toString();
734 }
735
Sailesh Nepal091768c2014-06-30 15:15:23 -0700736 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700737 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700738 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700739 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700740 public void onCallerDisplayNameChanged(
741 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700742 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700743 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700744 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800745 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700746 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700747 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800748 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700749 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800750 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751 public void onVideoProviderChanged(
752 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700753 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
754 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800755 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700756 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700757 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700758 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800759 public void onConferenceParticipantsChanged(Connection c,
760 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800761 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700762 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700763 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700764 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700765 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700766 /** @hide */
767 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Tyler Gunnf5035432017-01-09 09:43:12 -0800768 public void onAudioRouteChanged(Connection c, int audioRoute) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700769 }
770
Tyler Gunnb702ef82015-05-29 11:51:53 -0700771 /**
Hall Liu95d55872017-01-25 17:12:49 -0800772 * Provides methods to read and write RTT data to/from the in-call app.
773 * @hide
774 */
775 public static final class RttTextStream {
776 private static final int READ_BUFFER_SIZE = 1000;
777 private final InputStreamReader mPipeFromInCall;
778 private final OutputStreamWriter mPipeToInCall;
779 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
780
781 /**
782 * @hide
783 */
784 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
785 mPipeFromInCall = new InputStreamReader(
786 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
787 mPipeToInCall = new OutputStreamWriter(
788 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
789 }
790
791 /**
792 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
793 * RTT transmits text in real-time, this method should be called as often as text snippets
794 * are received from the remote user, even if it is only one character.
795 *
796 * This method is not thread-safe -- calling it from multiple threads simultaneously may
797 * lead to interleaved text.
798 * @param input The message to send to the in-call app.
799 */
800 public void write(String input) throws IOException {
801 mPipeToInCall.write(input);
802 mPipeToInCall.flush();
803 }
804
805
806 /**
807 * Reads a string from the in-call app, blocking if there is no data available. Returns
808 * {@code null} if the RTT conversation has been terminated and there is no further data
809 * to read.
810 *
811 * This method is not thread-safe -- calling it from multiple threads simultaneously may
812 * lead to interleaved text.
813 * @return A string containing text entered by the user, or {@code null} if the
814 * conversation has been terminated or if there was an error while reading.
815 */
816 public String read() {
817 try {
818 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
819 if (numRead < 0) {
820 return null;
821 }
822 return new String(mReadBuffer, 0, numRead);
823 } catch (IOException e) {
824 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
825 return null;
826 }
827 }
828 }
829
830 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700831 * Provides a means of controlling the video session associated with a {@link Connection}.
832 * <p>
833 * Implementations create a custom subclass of {@link VideoProvider} and the
834 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
835 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
836 * should set the {@link VideoProvider}.
837 * <p>
838 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
839 * {@link InCallService} implementations to issue requests related to the video session;
840 * it provides a means for the {@link ConnectionService} to report events and information
841 * related to the video session to Telecom and the {@link InCallService} implementations.
842 * <p>
843 * {@link InCallService} implementations interact with the {@link VideoProvider} via
844 * {@link android.telecom.InCallService.VideoCall}.
845 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700846 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700847 /**
848 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700849 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700850 */
851 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700852
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700854 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
855 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700856 */
857 public static final int SESSION_EVENT_RX_RESUME = 2;
858
859 /**
860 * Video transmission has begun. This occurs after a negotiated start of video transmission
861 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700863 */
864 public static final int SESSION_EVENT_TX_START = 3;
865
866 /**
867 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
868 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700869 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870 */
871 public static final int SESSION_EVENT_TX_STOP = 4;
872
873 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800874 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700875 * this as a cue to inform the user the camera is not available.
876 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 */
878 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
879
880 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700881 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800882 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * the camera has become available again.
884 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 */
886 public static final int SESSION_EVENT_CAMERA_READY = 6;
887
888 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800889 * Session event raised by Telecom when
890 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
891 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
892 * @see #handleCallSessionEvent(int)
893 */
894 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
895
896 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700897 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700899 */
900 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
901
902 /**
903 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 */
906 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
907
908 /**
909 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700910 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700911 */
912 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
913
Rekha Kumar07366812015-03-24 16:42:31 -0700914 /**
915 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700916 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700917 */
918 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
919
920 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700921 * Session modify request rejected by remote user.
922 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700923 */
924 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
925
Tyler Gunn75958422015-04-15 14:23:42 -0700926 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 private static final int MSG_SET_CAMERA = 2;
928 private static final int MSG_SET_PREVIEW_SURFACE = 3;
929 private static final int MSG_SET_DISPLAY_SURFACE = 4;
930 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
931 private static final int MSG_SET_ZOOM = 6;
932 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
933 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
934 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800935 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700937 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700939 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
940 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
941 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
942 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
943 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
944 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800945 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
946 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -0700947 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
948
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700949 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700951
952 /**
953 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700954 *
955 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
956 * load factor before resizing, 1 means we only expect a single thread to
957 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700958 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700959 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
960 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961
962 /**
963 * Default handler used to consolidate binder method calls onto a single thread.
964 */
965 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700966 public VideoProviderHandler() {
967 super();
968 }
969
970 public VideoProviderHandler(Looper looper) {
971 super(looper);
972 }
973
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 @Override
975 public void handleMessage(Message msg) {
976 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700977 case MSG_ADD_VIDEO_CALLBACK: {
978 IBinder binder = (IBinder) msg.obj;
979 IVideoCallback callback = IVideoCallback.Stub
980 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700981 if (callback == null) {
982 Log.w(this, "addVideoProvider - skipped; callback is null.");
983 break;
984 }
985
Tyler Gunn75958422015-04-15 14:23:42 -0700986 if (mVideoCallbacks.containsKey(binder)) {
987 Log.i(this, "addVideoProvider - skipped; already present.");
988 break;
989 }
990 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700992 }
993 case MSG_REMOVE_VIDEO_CALLBACK: {
994 IBinder binder = (IBinder) msg.obj;
995 IVideoCallback callback = IVideoCallback.Stub
996 .asInterface((IBinder) msg.obj);
997 if (!mVideoCallbacks.containsKey(binder)) {
998 Log.i(this, "removeVideoProvider - skipped; not present.");
999 break;
1000 }
1001 mVideoCallbacks.remove(binder);
1002 break;
1003 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001005 {
1006 SomeArgs args = (SomeArgs) msg.obj;
1007 try {
1008 onSetCamera((String) args.arg1);
1009 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001010 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001011 } finally {
1012 args.recycle();
1013 }
1014 }
1015 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 case MSG_SET_PREVIEW_SURFACE:
1017 onSetPreviewSurface((Surface) msg.obj);
1018 break;
1019 case MSG_SET_DISPLAY_SURFACE:
1020 onSetDisplaySurface((Surface) msg.obj);
1021 break;
1022 case MSG_SET_DEVICE_ORIENTATION:
1023 onSetDeviceOrientation(msg.arg1);
1024 break;
1025 case MSG_SET_ZOOM:
1026 onSetZoom((Float) msg.obj);
1027 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001028 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1029 SomeArgs args = (SomeArgs) msg.obj;
1030 try {
1031 onSendSessionModifyRequest((VideoProfile) args.arg1,
1032 (VideoProfile) args.arg2);
1033 } finally {
1034 args.recycle();
1035 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001037 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1039 onSendSessionModifyResponse((VideoProfile) msg.obj);
1040 break;
1041 case MSG_REQUEST_CAMERA_CAPABILITIES:
1042 onRequestCameraCapabilities();
1043 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001044 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1045 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001046 break;
1047 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001048 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 break;
1050 default:
1051 break;
1052 }
1053 }
1054 }
1055
1056 /**
1057 * IVideoProvider stub implementation.
1058 */
1059 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001060 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001062 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1063 }
1064
1065 public void removeVideoCallback(IBinder videoCallbackBinder) {
1066 mMessageHandler.obtainMessage(
1067 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 }
1069
Tyler Gunn159f35c2017-03-02 09:28:37 -08001070 public void setCamera(String cameraId, String callingPackageName,
1071 int targetSdkVersion) {
1072
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001073 SomeArgs args = SomeArgs.obtain();
1074 args.arg1 = cameraId;
1075 // Propagate the calling package; originally determined in
1076 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1077 // process.
1078 args.arg2 = callingPackageName;
1079 // Pass along the uid and pid of the calling app; this gets lost when we put the
1080 // message onto the handler. These are required for Telecom to perform a permission
1081 // check to see if the calling app is able to use the camera.
1082 args.argi1 = Binder.getCallingUid();
1083 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001084 // Pass along the target SDK version of the calling InCallService. This is used to
1085 // maintain backwards compatibility of the API for older callers.
1086 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001087 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 }
1089
1090 public void setPreviewSurface(Surface surface) {
1091 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1092 }
1093
1094 public void setDisplaySurface(Surface surface) {
1095 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1096 }
1097
1098 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001099 mMessageHandler.obtainMessage(
1100 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 }
1102
1103 public void setZoom(float value) {
1104 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1105 }
1106
Tyler Gunn45382162015-05-06 08:52:27 -07001107 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1108 SomeArgs args = SomeArgs.obtain();
1109 args.arg1 = fromProfile;
1110 args.arg2 = toProfile;
1111 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001112 }
1113
1114 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1115 mMessageHandler.obtainMessage(
1116 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1117 }
1118
1119 public void requestCameraCapabilities() {
1120 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1121 }
1122
1123 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001124 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 }
1126
Yorke Lee32f24732015-05-12 16:18:03 -07001127 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1129 }
1130 }
1131
1132 public VideoProvider() {
1133 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001134 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001135 }
1136
1137 /**
1138 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1139 *
1140 * @param looper The looper.
1141 * @hide
1142 */
1143 public VideoProvider(Looper looper) {
1144 mBinder = new VideoProvider.VideoProviderBinder();
1145 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 }
1147
1148 /**
1149 * Returns binder object which can be used across IPC methods.
1150 * @hide
1151 */
1152 public final IVideoProvider getInterface() {
1153 return mBinder;
1154 }
1155
1156 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001157 * Sets the camera to be used for the outgoing video.
1158 * <p>
1159 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1160 * camera via
1161 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1162 * <p>
1163 * Sent from the {@link InCallService} via
1164 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001165 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001166 * @param cameraId The id of the camera (use ids as reported by
1167 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001168 */
1169 public abstract void onSetCamera(String cameraId);
1170
1171 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001172 * Sets the camera to be used for the outgoing video.
1173 * <p>
1174 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1175 * camera via
1176 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1177 * <p>
1178 * This prototype is used internally to ensure that the calling package name, UID and PID
1179 * are sent to Telecom so that can perform a camera permission check on the caller.
1180 * <p>
1181 * Sent from the {@link InCallService} via
1182 * {@link InCallService.VideoCall#setCamera(String)}.
1183 *
1184 * @param cameraId The id of the camera (use ids as reported by
1185 * {@link CameraManager#getCameraIdList()}).
1186 * @param callingPackageName The AppOpps package name of the caller.
1187 * @param callingUid The UID of the caller.
1188 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001189 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001190 * @hide
1191 */
1192 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001193 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001194
1195 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001196 * Sets the surface to be used for displaying a preview of what the user's camera is
1197 * currently capturing. When video transmission is enabled, this is the video signal which
1198 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001199 * <p>
1200 * Sent from the {@link InCallService} via
1201 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001203 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001204 */
1205 public abstract void onSetPreviewSurface(Surface surface);
1206
1207 /**
1208 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001209 * <p>
1210 * Sent from the {@link InCallService} via
1211 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001212 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001213 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001214 */
1215 public abstract void onSetDisplaySurface(Surface surface);
1216
1217 /**
1218 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1219 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001220 * <p>
1221 * Sent from the {@link InCallService} via
1222 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 *
1224 * @param rotation The device orientation, in degrees.
1225 */
1226 public abstract void onSetDeviceOrientation(int rotation);
1227
1228 /**
1229 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001230 * <p>
1231 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001232 *
1233 * @param value The camera zoom ratio.
1234 */
1235 public abstract void onSetZoom(float value);
1236
1237 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001238 * Issues a request to modify the properties of the current video session.
1239 * <p>
1240 * Example scenarios include: requesting an audio-only call to be upgraded to a
1241 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1242 * when the {@link InCallService} is no longer the foreground application.
1243 * <p>
1244 * If the {@link VideoProvider} determines a request to be invalid, it should call
1245 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1246 * invalid request back to the {@link InCallService}.
1247 * <p>
1248 * Where a request requires confirmation from the user of the peer device, the
1249 * {@link VideoProvider} must communicate the request to the peer device and handle the
1250 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1251 * is used to inform the {@link InCallService} of the result of the request.
1252 * <p>
1253 * Sent from the {@link InCallService} via
1254 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001256 * @param fromProfile The video profile prior to the request.
1257 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 */
Tyler Gunn45382162015-05-06 08:52:27 -07001259 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1260 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001261
Tyler Gunnb702ef82015-05-29 11:51:53 -07001262 /**
1263 * Provides a response to a request to change the current video session properties.
1264 * <p>
1265 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1266 * video call, could decline the request and keep the call as audio-only.
1267 * In such a scenario, the {@code responseProfile} would have a video state of
1268 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1269 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1270 * <p>
1271 * Sent from the {@link InCallService} via
1272 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1273 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1274 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001276 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 */
1278 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1279
1280 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001281 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1282 * <p>
1283 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1284 * camera via
1285 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1286 * <p>
1287 * Sent from the {@link InCallService} via
1288 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001289 */
1290 public abstract void onRequestCameraCapabilities();
1291
1292 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001293 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1294 * video component of the current {@link Connection}.
1295 * <p>
1296 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1297 * via {@link VideoProvider#setCallDataUsage(long)}.
1298 * <p>
1299 * Sent from the {@link InCallService} via
1300 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001302 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303
1304 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001305 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1306 * the peer device when the video signal is paused.
1307 * <p>
1308 * Sent from the {@link InCallService} via
1309 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 *
1311 * @param uri URI of image to display.
1312 */
Yorke Lee32f24732015-05-12 16:18:03 -07001313 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314
1315 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001316 * Used to inform listening {@link InCallService} implementations when the
1317 * {@link VideoProvider} receives a session modification request.
1318 * <p>
1319 * Received by the {@link InCallService} via
1320 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001322 * @param videoProfile The requested video profile.
1323 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 */
1325 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001326 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001327 for (IVideoCallback callback : mVideoCallbacks.values()) {
1328 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001329 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001330 } catch (RemoteException ignored) {
1331 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001332 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 }
1334 }
1335 }
1336
1337 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001338 * Used to inform listening {@link InCallService} implementations when the
1339 * {@link VideoProvider} receives a response to a session modification request.
1340 * <p>
1341 * Received by the {@link InCallService} via
1342 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1343 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001344 *
1345 * @param status Status of the session modify request. Valid values are
1346 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1347 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1349 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1350 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1351 * @param requestedProfile The original request which was sent to the peer device.
1352 * @param responseProfile The actual profile changes agreed to by the peer device.
1353 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001354 */
1355 public void receiveSessionModifyResponse(int status,
1356 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001357 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001358 for (IVideoCallback callback : mVideoCallbacks.values()) {
1359 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001360 callback.receiveSessionModifyResponse(status, requestedProfile,
1361 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001362 } catch (RemoteException ignored) {
1363 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001364 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 }
1366 }
1367 }
1368
1369 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001370 * Used to inform listening {@link InCallService} implementations when the
1371 * {@link VideoProvider} reports a call session event.
1372 * <p>
1373 * Received by the {@link InCallService} via
1374 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001376 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1377 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1378 * {@link VideoProvider#SESSION_EVENT_TX_START},
1379 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1380 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001381 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1382 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001383 */
1384 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001385 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001386 for (IVideoCallback callback : mVideoCallbacks.values()) {
1387 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001388 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001389 } catch (RemoteException ignored) {
1390 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001391 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 }
1393 }
1394 }
1395
1396 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1398 * peer's video have changed.
1399 * <p>
1400 * This could occur if, for example, the peer rotates their device, changing the aspect
1401 * ratio of the video, or if the user switches between the back and front cameras.
1402 * <p>
1403 * Received by the {@link InCallService} via
1404 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 *
1406 * @param width The updated peer video width.
1407 * @param height The updated peer video height.
1408 */
1409 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001410 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001411 for (IVideoCallback callback : mVideoCallbacks.values()) {
1412 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001413 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001414 } catch (RemoteException ignored) {
1415 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001416 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001417 }
1418 }
1419 }
1420
1421 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001422 * Used to inform listening {@link InCallService} implementations when the data usage of the
1423 * video associated with the current {@link Connection} has changed.
1424 * <p>
1425 * This could be in response to a preview request via
1426 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001427 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1428 * 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 -07001429 * <p>
1430 * Received by the {@link InCallService} via
1431 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001433 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1434 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001435 */
Yorke Lee32f24732015-05-12 16:18:03 -07001436 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001437 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001438 for (IVideoCallback callback : mVideoCallbacks.values()) {
1439 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001440 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001441 } catch (RemoteException ignored) {
1442 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001443 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 }
1445 }
1446 }
1447
1448 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001449 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001451 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001452 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1453 * @hide
1454 */
1455 public void changeCallDataUsage(long dataUsage) {
1456 setCallDataUsage(dataUsage);
1457 }
1458
1459 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 * Used to inform listening {@link InCallService} implementations when the capabilities of
1461 * the current camera have changed.
1462 * <p>
1463 * The {@link VideoProvider} should call this in response to
1464 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1465 * changed via {@link VideoProvider#onSetCamera(String)}.
1466 * <p>
1467 * Received by the {@link InCallService} via
1468 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1469 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001470 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001471 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 */
Yorke Lee400470f2015-05-12 13:31:25 -07001473 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001474 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001475 for (IVideoCallback callback : mVideoCallbacks.values()) {
1476 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001477 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001478 } catch (RemoteException ignored) {
1479 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001480 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 }
1482 }
1483 }
Rekha Kumar07366812015-03-24 16:42:31 -07001484
1485 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001486 * Used to inform listening {@link InCallService} implementations when the video quality
1487 * of the call has changed.
1488 * <p>
1489 * Received by the {@link InCallService} via
1490 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001491 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001492 * @param videoQuality The updated video quality. Valid values:
1493 * {@link VideoProfile#QUALITY_HIGH},
1494 * {@link VideoProfile#QUALITY_MEDIUM},
1495 * {@link VideoProfile#QUALITY_LOW},
1496 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001497 */
1498 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001499 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001500 for (IVideoCallback callback : mVideoCallbacks.values()) {
1501 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001502 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001503 } catch (RemoteException ignored) {
1504 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001505 }
Rekha Kumar07366812015-03-24 16:42:31 -07001506 }
1507 }
1508 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001509
1510 /**
1511 * Returns a string representation of a call session event.
1512 *
1513 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1514 * @return String representation of the call session event.
1515 * @hide
1516 */
1517 public static String sessionEventToString(int event) {
1518 switch (event) {
1519 case SESSION_EVENT_CAMERA_FAILURE:
1520 return SESSION_EVENT_CAMERA_FAILURE_STR;
1521 case SESSION_EVENT_CAMERA_READY:
1522 return SESSION_EVENT_CAMERA_READY_STR;
1523 case SESSION_EVENT_RX_PAUSE:
1524 return SESSION_EVENT_RX_PAUSE_STR;
1525 case SESSION_EVENT_RX_RESUME:
1526 return SESSION_EVENT_RX_RESUME_STR;
1527 case SESSION_EVENT_TX_START:
1528 return SESSION_EVENT_TX_START_STR;
1529 case SESSION_EVENT_TX_STOP:
1530 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001531 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1532 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001533 default:
1534 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1535 }
1536 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001537 }
1538
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001539 private final Listener mConnectionDeathListener = new Listener() {
1540 @Override
1541 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001542 if (mConferenceables.remove(c)) {
1543 fireOnConferenceableConnectionsChanged();
1544 }
1545 }
1546 };
1547
1548 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1549 @Override
1550 public void onDestroyed(Conference c) {
1551 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001552 fireOnConferenceableConnectionsChanged();
1553 }
1554 }
1555 };
1556
Jay Shrauner229e3822014-08-15 09:23:07 -07001557 /**
1558 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1559 * load factor before resizing, 1 means we only expect a single thread to
1560 * access the map so make only a single shard
1561 */
1562 private final Set<Listener> mListeners = Collections.newSetFromMap(
1563 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001564 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1565 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001566 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001567
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001568 // The internal telecom call ID associated with this connection.
1569 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001571 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001572 private Uri mAddress;
1573 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001574 private String mCallerDisplayName;
1575 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001576 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001577 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001578 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001579 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001580 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001581 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001582 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001583 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001584 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001585 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001586 private Conference mConference;
1587 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001588 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001589 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001590
1591 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001592 * Tracks the key set for the extras bundle provided on the last invocation of
1593 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1594 * keys which were set previously but are no longer present in the replacement Bundle.
1595 */
1596 private Set<String> mPreviousExtraKeys;
1597
1598 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001599 * Create a new Connection.
1600 */
Santos Cordonf2951102014-07-20 19:06:29 -07001601 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001602
1603 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001604 * Returns the Telecom internal call ID associated with this connection. Should only be used
1605 * for debugging and tracing purposes.
1606 *
1607 * @return The Telecom call ID.
1608 * @hide
1609 */
1610 public final String getTelecomCallId() {
1611 return mTelecomCallId;
1612 }
1613
1614 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001615 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001616 */
Andrew Lee100e2932014-09-08 15:34:24 -07001617 public final Uri getAddress() {
1618 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001619 }
1620
1621 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001622 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001623 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001624 */
Andrew Lee100e2932014-09-08 15:34:24 -07001625 public final int getAddressPresentation() {
1626 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001627 }
1628
1629 /**
1630 * @return The caller display name (CNAP).
1631 */
1632 public final String getCallerDisplayName() {
1633 return mCallerDisplayName;
1634 }
1635
1636 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001637 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001638 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001639 */
1640 public final int getCallerDisplayNamePresentation() {
1641 return mCallerDisplayNamePresentation;
1642 }
1643
1644 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001645 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001646 */
1647 public final int getState() {
1648 return mState;
1649 }
1650
1651 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001652 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001653 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1654 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1655 * {@link VideoProfile#STATE_TX_ENABLED},
1656 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001657 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001658 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001659 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001660 */
1661 public final int getVideoState() {
1662 return mVideoState;
1663 }
1664
1665 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001666 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001667 * being routed by the system. This is {@code null} if this Connection
1668 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001669 * @deprecated Use {@link #getCallAudioState()} instead.
1670 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001671 */
Yorke Lee4af59352015-05-13 14:14:54 -07001672 @SystemApi
1673 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001674 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001675 if (mCallAudioState == null) {
1676 return null;
1677 }
Yorke Lee4af59352015-05-13 14:14:54 -07001678 return new AudioState(mCallAudioState);
1679 }
1680
1681 /**
1682 * @return The audio state of the connection, describing how its audio is currently
1683 * being routed by the system. This is {@code null} if this Connection
1684 * does not directly know about its audio state.
1685 */
1686 public final CallAudioState getCallAudioState() {
1687 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001688 }
1689
1690 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001691 * @return The conference that this connection is a part of. Null if it is not part of any
1692 * conference.
1693 */
1694 public final Conference getConference() {
1695 return mConference;
1696 }
1697
1698 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001699 * Returns whether this connection is requesting that the system play a ringback tone
1700 * on its behalf.
1701 */
Andrew Lee100e2932014-09-08 15:34:24 -07001702 public final boolean isRingbackRequested() {
1703 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001704 }
1705
1706 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001707 * @return True if the connection's audio mode is VOIP.
1708 */
1709 public final boolean getAudioModeIsVoip() {
1710 return mAudioModeIsVoip;
1711 }
1712
1713 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001714 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1715 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1716 * start time of the conference.
1717 *
1718 * @return The time at which the {@code Connnection} was connected.
1719 *
1720 * @hide
1721 */
1722 public final long getConnectTimeMillis() {
1723 return mConnectTimeMillis;
1724 }
1725
1726 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001727 * @return The status hints for this connection.
1728 */
1729 public final StatusHints getStatusHints() {
1730 return mStatusHints;
1731 }
1732
1733 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001734 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001735 * <p>
1736 * Extras should be updated using {@link #putExtras(Bundle)}.
1737 * <p>
1738 * Telecom or an {@link InCallService} can also update the extras via
1739 * {@link android.telecom.Call#putExtras(Bundle)}, and
1740 * {@link Call#removeExtras(List)}.
1741 * <p>
1742 * The connection is notified of changes to the extras made by Telecom or an
1743 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001744 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001745 * @return The extras associated with this connection.
1746 */
1747 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001748 Bundle extras = null;
1749 synchronized (mExtrasLock) {
1750 if (mExtras != null) {
1751 extras = new Bundle(mExtras);
1752 }
1753 }
1754 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001755 }
1756
1757 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001758 * Assign a listener to be notified of state changes.
1759 *
1760 * @param l A listener.
1761 * @return This Connection.
1762 *
1763 * @hide
1764 */
1765 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001766 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001767 return this;
1768 }
1769
1770 /**
1771 * Remove a previously assigned listener that was being notified of state changes.
1772 *
1773 * @param l A Listener.
1774 * @return This Connection.
1775 *
1776 * @hide
1777 */
1778 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001779 if (l != null) {
1780 mListeners.remove(l);
1781 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001782 return this;
1783 }
1784
1785 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001786 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001787 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001788 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001789 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001790 }
1791
1792 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001793 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1794 * ONLY for debugging purposes.
1795 *
1796 * @param callId The telecom call ID.
1797 * @hide
1798 */
1799 public void setTelecomCallId(String callId) {
1800 mTelecomCallId = callId;
1801 }
1802
1803 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001804 * Inform this Connection that the state of its audio output has been changed externally.
1805 *
1806 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001807 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001808 */
Yorke Lee4af59352015-05-13 14:14:54 -07001809 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001810 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001811 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001812 mCallAudioState = state;
1813 onAudioStateChanged(getAudioState());
1814 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815 }
1816
1817 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001818 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001819 * @return A string representation of the value.
1820 */
1821 public static String stateToString(int state) {
1822 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001823 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001824 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001825 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001826 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001827 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001828 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001829 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001830 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001831 case STATE_PULLING_CALL:
1832 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001833 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001834 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001835 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001836 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001837 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001838 return "DISCONNECTED";
1839 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001840 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001841 return "UNKNOWN";
1842 }
1843 }
1844
1845 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001846 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001847 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001848 public final int getConnectionCapabilities() {
1849 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001850 }
1851
1852 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001853 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1854 */
1855 public final int getConnectionProperties() {
1856 return mConnectionProperties;
1857 }
1858
1859 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001860 * Returns the connection's supported audio routes.
1861 *
1862 * @hide
1863 */
1864 public final int getSupportedAudioRoutes() {
1865 return mSupportedAudioRoutes;
1866 }
1867
1868 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001869 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001870 *
Andrew Lee100e2932014-09-08 15:34:24 -07001871 * @param address The new address.
1872 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001873 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001874 */
Andrew Lee100e2932014-09-08 15:34:24 -07001875 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001876 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001877 Log.d(this, "setAddress %s", address);
1878 mAddress = address;
1879 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001880 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001881 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001882 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001883 }
1884
1885 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001886 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001887 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001888 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001889 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001890 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001891 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001892 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001893 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001894 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001895 mCallerDisplayName = callerDisplayName;
1896 mCallerDisplayNamePresentation = presentation;
1897 for (Listener l : mListeners) {
1898 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1899 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001900 }
1901
1902 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001903 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001904 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1905 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1906 * {@link VideoProfile#STATE_TX_ENABLED},
1907 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001908 *
1909 * @param videoState The new video state.
1910 */
1911 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001912 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001913 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001914 mVideoState = videoState;
1915 for (Listener l : mListeners) {
1916 l.onVideoStateChanged(this, mVideoState);
1917 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001918 }
1919
1920 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001921 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001922 * communicate).
1923 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001924 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001925 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001926 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001927 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001928 }
1929
1930 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001931 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001932 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001933 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001934 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001935 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001936 }
1937
1938 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001939 * Sets state to initializing (this Connection is not yet ready to be used).
1940 */
1941 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001942 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001943 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001944 }
1945
1946 /**
1947 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1948 */
1949 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001950 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001951 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001952 }
1953
1954 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001955 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001957 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001958 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001959 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001960 }
1961
1962 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07001963 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
1964 * device). Only applicable for {@link Connection}s with
1965 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
1966 */
1967 public final void setPulling() {
1968 checkImmutable();
1969 setState(STATE_PULLING_CALL);
1970 }
1971
1972 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001973 * Sets state to be on hold.
1974 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001975 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001976 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001978 }
1979
1980 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001981 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001982 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001983 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001984 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001985 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001986 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001987 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001988 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001989 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001990 }
1991
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001992 public final VideoProvider getVideoProvider() {
1993 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001994 }
1995
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001996 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001997 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001998 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001999 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002000 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002001 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002002 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002003 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002004 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002005 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002006 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002007 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002008 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002009 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002010 }
2011
2012 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002013 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2014 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2015 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2016 * to send an {@link #onPostDialContinue(boolean)} signal.
2017 *
2018 * @param remaining The DTMF character sequence remaining to be emitted once the
2019 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2020 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002021 */
2022 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002023 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002024 for (Listener l : mListeners) {
2025 l.onPostDialWait(this, remaining);
2026 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002027 }
2028
2029 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002030 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2031 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002032 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002033 *
2034 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002035 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002036 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002037 checkImmutable();
2038 for (Listener l : mListeners) {
2039 l.onPostDialChar(this, nextChar);
2040 }
2041 }
2042
2043 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002044 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002045 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002046 *
2047 * @param ringback Whether the ringback tone is to be played.
2048 */
Andrew Lee100e2932014-09-08 15:34:24 -07002049 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002050 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002051 if (mRingbackRequested != ringback) {
2052 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002053 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002054 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002055 }
2056 }
Ihab Awadf8358972014-05-28 16:46:42 -07002057 }
2058
2059 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002060 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002061 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002062 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002063 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002064 public final void setConnectionCapabilities(int connectionCapabilities) {
2065 checkImmutable();
2066 if (mConnectionCapabilities != connectionCapabilities) {
2067 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002068 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002069 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002070 }
2071 }
Santos Cordonb6939982014-06-04 20:20:58 -07002072 }
2073
2074 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002075 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2076 *
2077 * @param connectionProperties The new connection properties.
2078 */
2079 public final void setConnectionProperties(int connectionProperties) {
2080 checkImmutable();
2081 if (mConnectionProperties != connectionProperties) {
2082 mConnectionProperties = connectionProperties;
2083 for (Listener l : mListeners) {
2084 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2085 }
2086 }
2087 }
2088
2089 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002090 * Sets the supported audio routes.
2091 *
2092 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2093 * See {@link CallAudioState}
2094 * @hide
2095 */
2096 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2097 if ((supportedAudioRoutes
2098 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2099 throw new IllegalArgumentException(
2100 "supported audio routes must include either speaker or earpiece");
2101 }
2102
2103 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2104 mSupportedAudioRoutes = supportedAudioRoutes;
2105 for (Listener l : mListeners) {
2106 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2107 }
2108 }
2109 }
2110
2111 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002112 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002113 */
Evan Charlton36a71342014-07-19 16:31:02 -07002114 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002115 for (Listener l : mListeners) {
2116 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002117 }
Santos Cordonb6939982014-06-04 20:20:58 -07002118 }
2119
2120 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002121 * Requests that the framework use VOIP audio mode for this connection.
2122 *
2123 * @param isVoip True if the audio mode is VOIP.
2124 */
2125 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002126 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002127 mAudioModeIsVoip = isVoip;
2128 for (Listener l : mListeners) {
2129 l.onAudioModeIsVoipChanged(this, isVoip);
2130 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002131 }
2132
2133 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002134 * Sets the time at which a call became active on this Connection. This is set only
2135 * when a conference call becomes active on this connection.
2136 *
2137 * @param connectionTimeMillis The connection time, in milliseconds.
2138 *
2139 * @hide
2140 */
2141 public final void setConnectTimeMillis(long connectTimeMillis) {
2142 mConnectTimeMillis = connectTimeMillis;
2143 }
2144
2145 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002146 * Sets the label and icon status to display in the in-call UI.
2147 *
2148 * @param statusHints The status label and icon to set.
2149 */
2150 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002151 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002152 mStatusHints = statusHints;
2153 for (Listener l : mListeners) {
2154 l.onStatusHintsChanged(this, statusHints);
2155 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002156 }
2157
2158 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002159 * Sets the connections with which this connection can be conferenced.
2160 *
2161 * @param conferenceableConnections The set of connections this connection can conference with.
2162 */
2163 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002164 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002165 clearConferenceableList();
2166 for (Connection c : conferenceableConnections) {
2167 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2168 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002169 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002170 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002171 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002172 }
2173 }
2174 fireOnConferenceableConnectionsChanged();
2175 }
2176
2177 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002178 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2179 * or conferences with which this connection can be conferenced.
2180 *
2181 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002182 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002183 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002184 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002185 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002186 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2187 // small amount of items here.
2188 if (!mConferenceables.contains(c)) {
2189 if (c instanceof Connection) {
2190 Connection connection = (Connection) c;
2191 connection.addConnectionListener(mConnectionDeathListener);
2192 } else if (c instanceof Conference) {
2193 Conference conference = (Conference) c;
2194 conference.addListener(mConferenceDeathListener);
2195 }
2196 mConferenceables.add(c);
2197 }
2198 }
2199 fireOnConferenceableConnectionsChanged();
2200 }
2201
2202 /**
2203 * Returns the connections or conferences with which this connection can be conferenced.
2204 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002205 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002206 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002207 }
2208
Yorke Lee53463962015-08-04 16:07:19 -07002209 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002210 * @hide
2211 */
2212 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002214 if (mConnectionService != null) {
2215 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2216 "which is already associated with another ConnectionService.");
2217 } else {
2218 mConnectionService = connectionService;
2219 }
2220 }
2221
2222 /**
2223 * @hide
2224 */
2225 public final void unsetConnectionService(ConnectionService connectionService) {
2226 if (mConnectionService != connectionService) {
2227 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2228 "that does not belong to the ConnectionService.");
2229 } else {
2230 mConnectionService = null;
2231 }
2232 }
2233
2234 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002235 * @hide
2236 */
2237 public final ConnectionService getConnectionService() {
2238 return mConnectionService;
2239 }
2240
2241 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002242 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002243 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002244 *
2245 * @param conference The conference.
2246 * @return {@code true} if the conference was successfully set.
2247 * @hide
2248 */
2249 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002250 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002251 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002252 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002253 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002254 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2255 fireConferenceChanged();
2256 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002257 return true;
2258 }
2259 return false;
2260 }
2261
2262 /**
2263 * Resets the conference that this connection is a part of.
2264 * @hide
2265 */
2266 public final void resetConference() {
2267 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002268 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002269 mConference = null;
2270 fireConferenceChanged();
2271 }
2272 }
2273
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002274 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002275 * Set some extras that can be associated with this {@code Connection}.
2276 * <p>
2277 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2278 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2279 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002280 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2281 * {@link #removeExtras(String...)} methods to modify the extras.
2282 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002283 * 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 -07002284 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2285 *
2286 * @param extras The extras associated with this {@code Connection}.
2287 */
2288 public final void setExtras(@Nullable Bundle extras) {
2289 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002290
2291 // Add/replace any new or changed extras values.
2292 putExtras(extras);
2293
2294 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2295 // the current one and remove any keys that went away.
2296 if (mPreviousExtraKeys != null) {
2297 List<String> toRemove = new ArrayList<String>();
2298 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002299 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002300 toRemove.add(oldKey);
2301 }
2302 }
2303 if (!toRemove.isEmpty()) {
2304 removeExtras(toRemove);
2305 }
2306 }
2307
2308 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2309 // called we can see if the caller has removed any extras values.
2310 if (mPreviousExtraKeys == null) {
2311 mPreviousExtraKeys = new ArraySet<String>();
2312 }
2313 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002314 if (extras != null) {
2315 mPreviousExtraKeys.addAll(extras.keySet());
2316 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002317 }
2318
2319 /**
2320 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2321 * added.
2322 * <p>
2323 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2324 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2325 *
2326 * @param extras The extras to add.
2327 */
2328 public final void putExtras(@NonNull Bundle extras) {
2329 checkImmutable();
2330 if (extras == null) {
2331 return;
2332 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002333 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2334 // the listeners.
2335 Bundle listenerExtras;
2336 synchronized (mExtrasLock) {
2337 if (mExtras == null) {
2338 mExtras = new Bundle();
2339 }
2340 mExtras.putAll(extras);
2341 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002342 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002343 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002344 // Create a new clone of the extras for each listener so that they don't clobber
2345 // each other
2346 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002347 }
2348 }
2349
2350 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002351 * Adds a boolean extra to this {@code Connection}.
2352 *
2353 * @param key The extra key.
2354 * @param value The value.
2355 * @hide
2356 */
2357 public final void putExtra(String key, boolean value) {
2358 Bundle newExtras = new Bundle();
2359 newExtras.putBoolean(key, value);
2360 putExtras(newExtras);
2361 }
2362
2363 /**
2364 * Adds an integer extra to this {@code Connection}.
2365 *
2366 * @param key The extra key.
2367 * @param value The value.
2368 * @hide
2369 */
2370 public final void putExtra(String key, int value) {
2371 Bundle newExtras = new Bundle();
2372 newExtras.putInt(key, value);
2373 putExtras(newExtras);
2374 }
2375
2376 /**
2377 * Adds a string extra to this {@code Connection}.
2378 *
2379 * @param key The extra key.
2380 * @param value The value.
2381 * @hide
2382 */
2383 public final void putExtra(String key, String value) {
2384 Bundle newExtras = new Bundle();
2385 newExtras.putString(key, value);
2386 putExtras(newExtras);
2387 }
2388
2389 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002390 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002391 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002392 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002393 */
2394 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002395 synchronized (mExtrasLock) {
2396 if (mExtras != null) {
2397 for (String key : keys) {
2398 mExtras.remove(key);
2399 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002400 }
2401 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002402 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002403 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002404 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002405 }
2406 }
2407
2408 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002409 * Removes extras from this {@code Connection}.
2410 *
2411 * @param keys The keys of the extras to remove.
2412 */
2413 public final void removeExtras(String ... keys) {
2414 removeExtras(Arrays.asList(keys));
2415 }
2416
2417 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002418 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2419 * be change to the {@link #getCallAudioState()}.
2420 * <p>
2421 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2422 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2423 * <p>
2424 * See also {@link InCallService#setAudioRoute(int)}.
2425 *
2426 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2427 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2428 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2429 */
2430 public final void setAudioRoute(int route) {
2431 for (Listener l : mListeners) {
2432 l.onAudioRouteChanged(this, route);
2433 }
2434 }
2435
2436 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002437 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002438 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002439 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002440 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2441 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002442 */
Yorke Lee4af59352015-05-13 14:14:54 -07002443 @SystemApi
2444 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002445 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002446
2447 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002448 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2449 *
2450 * @param state The new connection audio state.
2451 */
2452 public void onCallAudioStateChanged(CallAudioState state) {}
2453
2454 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002455 * Notifies this Connection of an internal state change. This method is called after the
2456 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002457 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002458 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002459 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002460 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002461
2462 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002463 * Notifies this Connection of a request to play a DTMF tone.
2464 *
2465 * @param c A DTMF character.
2466 */
Santos Cordonf2951102014-07-20 19:06:29 -07002467 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002468
2469 /**
2470 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2471 */
Santos Cordonf2951102014-07-20 19:06:29 -07002472 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002473
2474 /**
2475 * Notifies this Connection of a request to disconnect.
2476 */
Santos Cordonf2951102014-07-20 19:06:29 -07002477 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002478
2479 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002480 * Notifies this Connection of a request to disconnect a participant of the conference managed
2481 * by the connection.
2482 *
2483 * @param endpoint the {@link Uri} of the participant to disconnect.
2484 * @hide
2485 */
2486 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2487
2488 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002489 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002490 */
Santos Cordonf2951102014-07-20 19:06:29 -07002491 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002492
2493 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002494 * Notifies this Connection of a request to abort.
2495 */
Santos Cordonf2951102014-07-20 19:06:29 -07002496 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002497
2498 /**
2499 * Notifies this Connection of a request to hold.
2500 */
Santos Cordonf2951102014-07-20 19:06:29 -07002501 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002502
2503 /**
2504 * Notifies this Connection of a request to exit a hold state.
2505 */
Santos Cordonf2951102014-07-20 19:06:29 -07002506 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002507
2508 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002509 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002510 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002511 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002512 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002513 */
Santos Cordonf2951102014-07-20 19:06:29 -07002514 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002515
2516 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002517 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002518 * a request to accept.
2519 */
2520 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002521 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002522 }
2523
2524 /**
2525 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002526 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002527 */
Santos Cordonf2951102014-07-20 19:06:29 -07002528 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002529
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002530 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002531 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2532 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002533 */
2534 public void onReject(String replyMessage) {}
2535
2536 /**
Bryce Leecac50772015-11-17 15:13:29 -08002537 * Notifies the Connection of a request to silence the ringer.
2538 *
2539 * @hide
2540 */
2541 public void onSilence() {}
2542
2543 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002544 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2545 */
Santos Cordonf2951102014-07-20 19:06:29 -07002546 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002547
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002548 /**
2549 * Notifies this Connection of a request to pull an external call to the local device.
2550 * <p>
2551 * The {@link InCallService} issues a request to pull an external call to the local device via
2552 * {@link Call#pullExternalCall()}.
2553 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002554 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2555 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002556 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002557 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002558 */
2559 public void onPullExternalCall() {}
2560
2561 /**
2562 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2563 * <p>
2564 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2565 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002566 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2567 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2568 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2569 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2570 * not aware of.
2571 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002572 * See also {@link Call#sendCallEvent(String, Bundle)}.
2573 *
2574 * @param event The call event.
2575 * @param extras Extras associated with the call event.
2576 */
2577 public void onCallEvent(String event, Bundle extras) {}
2578
Tyler Gunndee56a82016-03-23 16:06:34 -07002579 /**
2580 * Notifies this {@link Connection} of a change to the extras made outside the
2581 * {@link ConnectionService}.
2582 * <p>
2583 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2584 * the {@link android.telecom.Call#putExtras(Bundle)} and
2585 * {@link Call#removeExtras(List)}.
2586 *
2587 * @param extras The new extras bundle.
2588 */
2589 public void onExtrasChanged(Bundle extras) {}
2590
Tyler Gunnf5035432017-01-09 09:43:12 -08002591 /**
2592 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2593 * displaying its incoming call user interface for the {@link Connection}.
2594 * <p>
2595 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2596 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2597 * should show its own incoming call user interface.
2598 * <p>
2599 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2600 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2601 * user interface to allow the user to choose whether to answer the new incoming call and
2602 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002603 * <p>
2604 * You should trigger the display of the incoming call user interface for your application by
2605 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2606 * For example:
2607 * <pre><code>
2608 * // Create an intent which triggers your fullscreen incoming call user interface.
2609 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2610 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2611 * intent.setClass(context, YourIncomingCallActivity.class);
2612 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2613 *
2614 * // Build the notification as an ongoing high priority item; this ensures it will show as
2615 * // a heads up notification which slides down over top of the current content.
2616 * final Notification.Builder builder = new Notification.Builder(context);
2617 * builder.setOngoing(true);
2618 * builder.setPriority(Notification.PRIORITY_HIGH);
2619 *
2620 * // Set notification content intent to take user to fullscreen UI if user taps on the
2621 * // notification body.
2622 * builder.setContentIntent(pendingIntent);
2623 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2624 * // manager deems it appropriate.
2625 * builder.setFullScreenIntent(pendingIntent, true);
2626 *
2627 * // Setup notification content.
2628 * builder.setSmallIcon( yourIconResourceId );
2629 * builder.setContentTitle("Your notification title");
2630 * builder.setContentText("Your notification content.");
2631 *
2632 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2633 *
2634 * NotificationManager notificationManager = mContext.getSystemService(
2635 * NotificationManager.class);
2636 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2637 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002638 */
2639 public void onShowIncomingCallUi() {}
2640
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002641 static String toLogSafePhoneNumber(String number) {
2642 // For unknown number, log empty string.
2643 if (number == null) {
2644 return "";
2645 }
2646
2647 if (PII_DEBUG) {
2648 // When PII_DEBUG is true we emit PII.
2649 return number;
2650 }
2651
2652 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2653 // sanitized phone numbers.
2654 StringBuilder builder = new StringBuilder();
2655 for (int i = 0; i < number.length(); i++) {
2656 char c = number.charAt(i);
2657 if (c == '-' || c == '@' || c == '.') {
2658 builder.append(c);
2659 } else {
2660 builder.append('x');
2661 }
2662 }
2663 return builder.toString();
2664 }
2665
Ihab Awad542e0ea2014-05-16 10:22:16 -07002666 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002667 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002668 if (mState == STATE_DISCONNECTED && mState != state) {
2669 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002670 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002671 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002672 if (mState != state) {
2673 Log.d(this, "setState: %s", stateToString(state));
2674 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002675 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002676 for (Listener l : mListeners) {
2677 l.onStateChanged(this, state);
2678 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002679 }
2680 }
2681
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002682 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002683 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002684 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2685 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002686 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002687 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002688
2689 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002690 if (mImmutable) {
2691 throw new UnsupportedOperationException("Connection is immutable");
2692 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002693 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002694 }
2695
Evan Charltonbf11f982014-07-20 22:06:28 -07002696 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002697 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002698 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2699 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002700 * <p>
2701 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2702 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002703 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002704 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002705 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002706 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002707 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2708 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002709 }
2710
Evan Charltonbf11f982014-07-20 22:06:28 -07002711 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002712 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2713 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2714 * this should never be un-@hide-den.
2715 *
2716 * @hide
2717 */
2718 public void checkImmutable() {}
2719
2720 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002721 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2722 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2723 * that state. This connection should not be used for anything, and no other
2724 * {@code Connection}s should be attempted.
2725 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002726 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002727 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002728 * @return A {@code Connection} which indicates that the underlying connection should
2729 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002730 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002731 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002732 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002733 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002734
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002735 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002736 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002737 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002738 }
2739 }
2740
Santos Cordon823fd3c2014-08-07 18:35:18 -07002741 private final void fireConferenceChanged() {
2742 for (Listener l : mListeners) {
2743 l.onConferenceChanged(this, mConference);
2744 }
2745 }
2746
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002747 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002748 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002749 if (c instanceof Connection) {
2750 Connection connection = (Connection) c;
2751 connection.removeConnectionListener(mConnectionDeathListener);
2752 } else if (c instanceof Conference) {
2753 Conference conference = (Conference) c;
2754 conference.removeListener(mConferenceDeathListener);
2755 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002756 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002757 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002758 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002759
2760 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002761 * Handles a change to extras received from Telecom.
2762 *
2763 * @param extras The new extras.
2764 * @hide
2765 */
2766 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002767 Bundle b = null;
2768 synchronized (mExtrasLock) {
2769 mExtras = extras;
2770 if (mExtras != null) {
2771 b = new Bundle(mExtras);
2772 }
2773 }
2774 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07002775 }
2776
2777 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002778 * Notifies listeners that the merge request failed.
2779 *
2780 * @hide
2781 */
2782 protected final void notifyConferenceMergeFailed() {
2783 for (Listener l : mListeners) {
2784 l.onConferenceMergeFailed(this);
2785 }
2786 }
2787
2788 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002789 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002790 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002791 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002792 * @hide
2793 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002794 protected final void updateConferenceParticipants(
2795 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002796 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002797 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002798 }
2799 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002800
2801 /**
2802 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002803 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002804 */
2805 protected void notifyConferenceStarted() {
2806 for (Listener l : mListeners) {
2807 l.onConferenceStarted();
2808 }
2809 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002810
2811 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07002812 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
2813 * be a part of a conference call.
2814 * @param isConferenceSupported {@code true} if the connection supports being part of a
2815 * conference call, {@code false} otherwise.
2816 * @hide
2817 */
2818 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
2819 for (Listener l : mListeners) {
2820 l.onConferenceSupportedChanged(this, isConferenceSupported);
2821 }
2822 }
2823
2824 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002825 * Sends an event associated with this {@code Connection} with associated event extras to the
2826 * {@link InCallService}.
2827 * <p>
2828 * Connection events are used to communicate point in time information from a
2829 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
2830 * custom connection event includes notifying the UI when a WIFI call has been handed over to
2831 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
2832 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
2833 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
2834 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
2835 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
2836 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
2837 * <p>
2838 * Events are exposed to {@link InCallService} implementations via
2839 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
2840 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002841 * 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 -07002842 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
2843 * some events altogether.
2844 * <p>
2845 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
2846 * conflicts between {@link ConnectionService} implementations. Further, custom
2847 * {@link ConnectionService} implementations shall not re-purpose events in the
2848 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
2849 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
2850 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
2851 * {@code com.example.extra.MY_EXTRA}).
2852 * <p>
2853 * When defining events and the associated extras, it is important to keep their behavior
2854 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
2855 * events/extras should me maintained to ensure backwards compatibility with older
2856 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002857 *
2858 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002859 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002860 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002861 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002862 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002863 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002864 }
2865 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002866}