blob: 8bc83c276a3e41d5853e7df63ba1844e588aa760 [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;
Mathew Inwood42346d12018-08-01 11:33:05 +010026import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080028import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080029import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070030import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070031import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080032import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070033import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Handler;
35import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070036import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080038import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070040import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070041import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
Hall Liua549fed2018-02-09 16:40:03 -080044import java.io.FileInputStream;
45import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080046import java.io.IOException;
47import java.io.InputStreamReader;
48import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070049import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070050import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070051import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070052import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070054import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
56/**
Santos Cordon895d4b82015-06-25 16:41:48 -070057 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
58 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070059 * <p>
60 * Implementations create a custom subclass of {@code Connection} and return it to the framework
61 * as the return value of
62 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
63 * or
64 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
65 * Implementations are then responsible for updating the state of the {@code Connection}, and
66 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
67 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070068 * <p>
69 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
70 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
71 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
72 * {@code Connection} instance.
73 * <p>
74 * Basic call support requires overriding the following methods: {@link #onAnswer()},
75 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
76 * <p>
77 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
78 * {@link #onUnhold()} methods should be overridden to provide hold support for the
79 * {@code Connection}.
80 * <p>
81 * Where a {@code Connection} supports a variation of video calling (e.g. the
82 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
83 * to support answering a call as a video call.
84 * <p>
85 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
86 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
87 * support for pulling the external call.
88 * <p>
89 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
90 * overridden.
91 * <p>
92 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
93 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
94 * for example, call events from a {@link InCallService} are handled,
95 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
96 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
97 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
98 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070099 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700100public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700101
Santos Cordon895d4b82015-06-25 16:41:48 -0700102 /**
103 * The connection is initializing. This is generally the first state for a {@code Connection}
104 * returned by a {@link ConnectionService}.
105 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 public static final int STATE_INITIALIZING = 0;
107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * The connection is new and not connected.
110 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700111 public static final int STATE_NEW = 1;
112
Santos Cordon895d4b82015-06-25 16:41:48 -0700113 /**
114 * An incoming connection is in the ringing state. During this state, the user's ringer or
115 * vibration feature will be activated.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_RINGING = 2;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * An outgoing connection is in the dialing state. In this state the other party has not yet
121 * answered the call and the user traditionally hears a ringback tone.
122 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 public static final int STATE_DIALING = 3;
124
Santos Cordon895d4b82015-06-25 16:41:48 -0700125 /**
126 * A connection is active. Both parties are connected to the call and can actively communicate.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_ACTIVE = 4;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * A connection is on hold.
132 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 public static final int STATE_HOLDING = 5;
134
Santos Cordon895d4b82015-06-25 16:41:48 -0700135 /**
136 * A connection has been disconnected. This is the final state once the user has been
137 * disconnected from a call either locally, remotely or by an error in the service.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_DISCONNECTED = 6;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700142 * The state of an external connection which is in the process of being pulled from a remote
143 * device to the local device.
144 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700145 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700146 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
147 */
148 public static final int STATE_PULLING_CALL = 7;
149
150 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700151 * Connection can currently be put on hold or unheld. This is distinct from
152 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
153 * it does not at the moment support the function. This can be true while the call is in the
154 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
155 * display a disabled 'hold' button.
156 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 public static final int CAPABILITY_HOLD = 0x00000001;
158
159 /** Connection supports the hold feature. */
160 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
161
162 /**
163 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
164 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
165 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
166 * capability allows a merge button to be shown while the conference is in the foreground
167 * of the in-call UI.
168 * <p>
169 * This is only intended for use by a {@link Conference}.
170 */
171 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
172
173 /**
174 * Connections within a conference can be swapped between foreground and background.
175 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
176 * <p>
177 * This is only intended for use by a {@link Conference}.
178 */
179 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
180
181 /**
182 * @hide
183 */
184 public static final int CAPABILITY_UNUSED = 0x00000010;
185
186 /** Connection supports responding via text option. */
187 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
188
189 /** Connection can be muted. */
190 public static final int CAPABILITY_MUTE = 0x00000040;
191
192 /**
193 * Connection supports conference management. This capability only applies to
194 * {@link Conference}s which can have {@link Connection}s as children.
195 */
196 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
197
198 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 * Local device supports receiving 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_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207
208 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700211 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213
214 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
218
219 /**
220 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 */
222 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
223
224 /**
225 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700227 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700228 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800229
230 /**
231 * Connection is able to be separated from its parent {@code Conference}, if any.
232 */
233 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
234
235 /**
236 * Connection is able to be individually disconnected when in a {@code Conference}.
237 */
238 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
239
240 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700241 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242 * @hide
243 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248 * @hide
249 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251
252 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254 * @hide
255 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257
Tyler Gunn068085b2015-02-06 13:56:52 -0800258 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800260 * @hide
261 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700262 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800263
Tyler Gunn96d6c402015-03-18 12:39:23 -0700264 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500265 * Speed up audio setup for MT call.
266 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700267 */
268 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800269
Rekha Kumar07366812015-03-24 16:42:31 -0700270 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700271 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700272 */
273 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
274
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700275 /**
276 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700277 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700278 */
279 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
280
Tyler Gunnd4091732015-06-29 09:15:37 -0700281 /**
282 * For a conference, indicates the conference will not have child connections.
283 * <p>
284 * An example of a conference with child connections is a GSM conference call, where the radio
285 * retains connections to the individual participants of the conference. Another example is an
286 * IMS conference call where conference event package functionality is supported; in this case
287 * the conference server ensures the radio is aware of the participants in the conference, which
288 * are represented by child connections.
289 * <p>
290 * An example of a conference with no child connections is an IMS conference call with no
291 * conference event package support. Such a conference is represented by the radio as a single
292 * connection to the IMS conference server.
293 * <p>
294 * Indicating whether a conference has children or not is important to help user interfaces
295 * visually represent a conference. A conference with no children, for example, will have the
296 * conference connection shown in the list of calls on a Bluetooth device, where if the
297 * conference has children, only the children will be shown in the list of calls on a Bluetooth
298 * device.
299 * @hide
300 */
301 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
302
Bryce Lee81901682015-08-28 16:38:02 -0700303 /**
304 * Indicates that the connection itself wants to handle any sort of reply response, rather than
305 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700306 */
307 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
308
Tyler Gunnf97a0092016-01-19 15:59:34 -0800309 /**
310 * When set, prevents a video call from being downgraded to an audio-only call.
311 * <p>
312 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
313 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
314 * downgraded from a video call back to a VideoState of
315 * {@link VideoProfile#STATE_AUDIO_ONLY}.
316 * <p>
317 * Intuitively, a call which can be downgraded to audio should also have local and remote
318 * video
319 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
320 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
321 */
322 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
323
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700324 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700325 * When set for an external connection, indicates that this {@code Connection} can be pulled
326 * from a remote device to the current device.
327 * <p>
328 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
329 * is set.
330 */
331 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
332
Pooja Jaind34698d2017-12-28 14:15:31 +0530333 /** Call supports the deflect feature. */
334 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
335
Tyler Gunn720c6642016-03-22 09:02:47 -0700336 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530337 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700338 //**********************************************************************************************
339
340 /**
341 * Indicates that the current device callback number should be shown.
342 *
343 * @hide
344 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700345 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700346
347 /**
348 * Whether the call is a generic conference, where we do not know the precise state of
349 * participants in the conference (eg. on CDMA).
350 *
351 * @hide
352 */
353 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
354
355 /**
356 * Connection is using high definition audio.
357 * @hide
358 */
359 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
360
361 /**
362 * Connection is using WIFI.
363 * @hide
364 */
365 public static final int PROPERTY_WIFI = 1<<3;
366
367 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368 * When set, indicates that the {@code Connection} does not actually exist locally for the
369 * {@link ConnectionService}.
370 * <p>
371 * Consider, for example, a scenario where a user has two devices with the same phone number.
372 * When a user places a call on one devices, the telephony stack can represent that call on the
373 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700374 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700375 * <p>
376 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
377 * external connections. Only those {@link InCallService}s which have the
378 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
379 * manifest will see external connections.
380 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382
Brad Ebinger15847072016-05-18 11:08:36 -0700383 /**
384 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
385 */
386 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700387
Hall Liu9f332c72016-07-14 15:37:37 -0700388 /**
389 * Indicates that the connection represents a downgraded IMS conference.
390 * @hide
391 */
392 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
393
Tyler Gunnf5035432017-01-09 09:43:12 -0800394 /**
395 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
396 * {@link ConnectionService}.
397 * <p>
398 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
399 */
400 public static final int PROPERTY_SELF_MANAGED = 1<<7;
401
Hall Liu95d55872017-01-25 17:12:49 -0800402 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800403 * Set by the framework to indicate that a connection has an active RTT session associated with
404 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800405 */
406 public static final int PROPERTY_IS_RTT = 1 << 8;
407
Eric Erfanian62706c52017-12-06 16:27:53 -0800408 /**
409 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000410 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800411 */
412 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
413
Tyler Gunn5bd90852018-09-21 09:37:07 -0700414 /**
415 * Set by the framework to indicate that the network has identified a Connection as an emergency
416 * call.
417 * @hide
418 */
419 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
420
Tyler Gunn96d6c402015-03-18 12:39:23 -0700421 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800422 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700423 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800424
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700425 /**
426 * Connection extra key used to store the last forwarded number associated with the current
427 * connection. Used to communicate to the user interface that the connection was forwarded via
428 * the specified number.
429 */
430 public static final String EXTRA_LAST_FORWARDED_NUMBER =
431 "android.telecom.extra.LAST_FORWARDED_NUMBER";
432
433 /**
434 * Connection extra key used to store a child number associated with the current connection.
435 * Used to communicate to the user interface that the connection was received via
436 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
437 * address.
438 */
439 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
440
441 /**
442 * Connection extra key used to store the subject for an incoming call. The user interface can
443 * query this extra and display its contents for incoming calls. Will only be used if the
444 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
445 */
446 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
447
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800448 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700449 * Boolean connection extra key set on a {@link Connection} in
450 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
451 * current active foreground call to be dropped.
452 */
453 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
454 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
455
456 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700457 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
458 * state to indicate the name of the third-party app which is responsible for the current
459 * foreground call.
460 * <p>
461 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
462 * is able to inform the user that answering the new incoming call will cause a call owned by
463 * another app to be dropped when the incoming call is answered.
464 */
465 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
466 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
467
468 /**
Hall Liu10208662016-06-15 17:55:00 -0700469 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700470 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700471 * @hide
472 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700473 public static final String EXTRA_DISABLE_ADD_CALL =
474 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700475
476 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700477 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
478 * original Connection ID associated with the connection. Used in
479 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
480 * connection/conference added via
481 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
482 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
483 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
484 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
485 * be a way to ensure that we don't add the connection again as a duplicate.
486 * <p>
487 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
488 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
489 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
490 * in a new {@link Connection} which it adds to Telecom via
491 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
492 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
493 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
494 * ID it originally referred to the connection as. Thus Telecom needs to know that the
495 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
496 * @hide
497 */
498 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
499 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
500
501 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800502 * Connection event used to inform Telecom that it should play the on hold tone. This is used
503 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700504 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800505 * @hide
506 */
507 public static final String EVENT_ON_HOLD_TONE_START =
508 "android.telecom.event.ON_HOLD_TONE_START";
509
510 /**
511 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
512 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700513 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800514 * @hide
515 */
516 public static final String EVENT_ON_HOLD_TONE_END =
517 "android.telecom.event.ON_HOLD_TONE_END";
518
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700519 /**
520 * Connection event used to inform {@link InCallService}s when pulling of an external call has
521 * failed. The user interface should inform the user of the error.
522 * <p>
523 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
524 * API is called on a {@link Call} with the properties
525 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
526 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
527 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700528 * <p>
529 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
530 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700531 */
532 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
533
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700534 /**
535 * Connection event used to inform {@link InCallService}s when the merging of two calls has
536 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700537 * <p>
538 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
539 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700540 */
541 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
542
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700543 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700544 * Connection event used to inform {@link InCallService}s when the process of merging a
545 * Connection into a conference has begun.
546 * <p>
547 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
548 * expected to be null when this connection event is used.
549 * @hide
550 */
551 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
552
553 /**
554 * Connection event used to inform {@link InCallService}s when the process of merging a
555 * Connection into a conference has completed.
556 * <p>
557 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
558 * expected to be null when this connection event is used.
559 * @hide
560 */
561 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
562
563 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700564 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
565 * the remote party.
566 * <p>
567 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
568 * call is being held locally on the device. When a capable {@link ConnectionService} receives
569 * signalling to indicate that the remote party has put the call on hold, it can send this
570 * connection event.
571 * @hide
572 */
573 public static final String EVENT_CALL_REMOTELY_HELD =
574 "android.telecom.event.CALL_REMOTELY_HELD";
575
576 /**
577 * Connection event used to inform {@link InCallService}s when a call which was remotely held
578 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
579 * <p>
580 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
581 * call is being held locally on the device. When a capable {@link ConnectionService} receives
582 * signalling to indicate that the remote party has taken the call off hold, it can send this
583 * connection event.
584 * @hide
585 */
586 public static final String EVENT_CALL_REMOTELY_UNHELD =
587 "android.telecom.event.CALL_REMOTELY_UNHELD";
588
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700589 /**
590 * Connection event used to inform an {@link InCallService} which initiated a call handover via
591 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
592 * successfully completed.
593 * @hide
594 */
595 public static final String EVENT_HANDOVER_COMPLETE =
596 "android.telecom.event.HANDOVER_COMPLETE";
597
598 /**
599 * Connection event used to inform an {@link InCallService} which initiated a call handover via
600 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
601 * to complete.
602 * @hide
603 */
604 public static final String EVENT_HANDOVER_FAILED =
605 "android.telecom.event.HANDOVER_FAILED";
606
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700607 // Flag controlling whether PII is emitted into the logs
608 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
609
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800610 /**
611 * Whether the given capabilities support the specified capability.
612 *
613 * @param capabilities A capability bit field.
614 * @param capability The capability to check capabilities for.
615 * @return Whether the specified capability is supported.
616 * @hide
617 */
618 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800619 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 }
621
622 /**
623 * Whether the capabilities of this {@code Connection} supports the specified capability.
624 *
625 * @param capability The capability to check capabilities for.
626 * @return Whether the specified capability is supported.
627 * @hide
628 */
629 public boolean can(int capability) {
630 return can(mConnectionCapabilities, capability);
631 }
632
633 /**
634 * Removes the specified capability from the set of capabilities of this {@code Connection}.
635 *
636 * @param capability The capability to remove from the set.
637 * @hide
638 */
639 public void removeCapability(int capability) {
640 mConnectionCapabilities &= ~capability;
641 }
642
643 /**
644 * Adds the specified capability to the set of capabilities of this {@code Connection}.
645 *
646 * @param capability The capability to add to the set.
647 * @hide
648 */
649 public void addCapability(int capability) {
650 mConnectionCapabilities |= capability;
651 }
652
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700653 /**
654 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
655 *
656 * @param capabilities A capability bit field.
657 * @return A human readable string representation.
658 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700660 return capabilitiesToStringInternal(capabilities, true /* isLong */);
661 }
662
663 /**
664 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
665 * string.
666 *
667 * @param capabilities A capability bit field.
668 * @return A human readable string representation.
669 * @hide
670 */
671 public static String capabilitiesToStringShort(int capabilities) {
672 return capabilitiesToStringInternal(capabilities, false /* isLong */);
673 }
674
675 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800676 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700677 builder.append("[");
678 if (isLong) {
679 builder.append("Capabilities:");
680 }
681
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700683 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800684 }
685 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700686 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800687 }
688 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700689 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800690 }
691 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700692 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800693 }
694 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700695 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800696 }
697 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700698 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800699 }
700 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700701 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800702 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700703 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700704 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700705 }
706 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700707 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700708 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700709 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700710 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800711 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700712 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700713 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700714 }
715 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700716 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700717 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700718 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800720 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800721 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700722 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800723 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500724 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500726 }
Rekha Kumar07366812015-03-24 16:42:31 -0700727 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700729 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700730 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700732 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700733 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700735 }
Bryce Lee81901682015-08-28 16:38:02 -0700736 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700738 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700739 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700741 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530742 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
743 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
744 }
Bryce Lee81901682015-08-28 16:38:02 -0700745
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800746 builder.append("]");
747 return builder.toString();
748 }
749
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700750 /**
751 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
752 *
753 * @param properties A property bit field.
754 * @return A human readable string representation.
755 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700756 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700757 return propertiesToStringInternal(properties, true /* isLong */);
758 }
759
760 /**
761 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
762 *
763 * @param properties A property bit field.
764 * @return A human readable string representation.
765 * @hide
766 */
767 public static String propertiesToStringShort(int properties) {
768 return propertiesToStringInternal(properties, false /* isLong */);
769 }
770
771 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700772 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700773 builder.append("[");
774 if (isLong) {
775 builder.append("Properties:");
776 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700777
Tyler Gunnf5035432017-01-09 09:43:12 -0800778 if (can(properties, PROPERTY_SELF_MANAGED)) {
779 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
780 }
781
Hall Liu25c7c4d2016-08-30 13:41:02 -0700782 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
783 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700784 }
785
786 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700787 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700788 }
789
790 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700791 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700792 }
793
794 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700795 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700796 }
797
798 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700799 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700800 }
801
Brad Ebinger15847072016-05-18 11:08:36 -0700802 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700803 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700804 }
805
Hall Liud4d2a8a2018-01-29 17:22:02 -0800806 if (can(properties, PROPERTY_IS_RTT)) {
807 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
808 }
809
Tyler Gunn5bd90852018-09-21 09:37:07 -0700810 if (can(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
811 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
812 }
813
Tyler Gunn720c6642016-03-22 09:02:47 -0700814 builder.append("]");
815 return builder.toString();
816 }
817
Sailesh Nepal091768c2014-06-30 15:15:23 -0700818 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700819 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700820 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700821 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700822 public void onCallerDisplayNameChanged(
823 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700824 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700825 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700826 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800827 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700828 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700829 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800830 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700831 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800832 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700833 public void onVideoProviderChanged(
834 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700835 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
836 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800837 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700838 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700839 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700840 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800841 public void onConferenceParticipantsChanged(Connection c,
842 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800843 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700844 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700845 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700846 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700847 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700848 /** @hide */
849 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800850 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800851 public void onRttInitiationSuccess(Connection c) {}
852 public void onRttInitiationFailure(Connection c, int reason) {}
853 public void onRttSessionRemotelyTerminated(Connection c) {}
854 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530855 /** @hide */
856 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800857 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700858 }
859
Tyler Gunnb702ef82015-05-29 11:51:53 -0700860 /**
Hall Liu95d55872017-01-25 17:12:49 -0800861 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800862 */
863 public static final class RttTextStream {
864 private static final int READ_BUFFER_SIZE = 1000;
865 private final InputStreamReader mPipeFromInCall;
866 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800867 private final ParcelFileDescriptor mFdFromInCall;
868 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800869 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
870
871 /**
872 * @hide
873 */
874 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800875 mFdFromInCall = fromInCall;
876 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800877 mPipeFromInCall = new InputStreamReader(
Hall Liua549fed2018-02-09 16:40:03 -0800878 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800879 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800880 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800881 }
882
883 /**
884 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
885 * RTT transmits text in real-time, this method should be called as often as text snippets
886 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800887 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800888 * This method is not thread-safe -- calling it from multiple threads simultaneously may
889 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800890 *
Hall Liu95d55872017-01-25 17:12:49 -0800891 * @param input The message to send to the in-call app.
892 */
893 public void write(String input) throws IOException {
894 mPipeToInCall.write(input);
895 mPipeToInCall.flush();
896 }
897
898
899 /**
900 * Reads a string from the in-call app, blocking if there is no data available. Returns
901 * {@code null} if the RTT conversation has been terminated and there is no further data
902 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800903 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800904 * This method is not thread-safe -- calling it from multiple threads simultaneously may
905 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800906 *
Hall Liu95d55872017-01-25 17:12:49 -0800907 * @return A string containing text entered by the user, or {@code null} if the
908 * conversation has been terminated or if there was an error while reading.
909 */
Hall Liuffa4a812017-03-02 16:11:00 -0800910 public String read() throws IOException {
911 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
912 if (numRead < 0) {
913 return null;
914 }
915 return new String(mReadBuffer, 0, numRead);
916 }
917
918 /**
919 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
920 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800921 *
Hall Liuffa4a812017-03-02 16:11:00 -0800922 * @return A string containing text entered by the user, or {@code null} if the user has
923 * not entered any new text yet.
924 */
925 public String readImmediately() throws IOException {
926 if (mPipeFromInCall.ready()) {
927 return read();
928 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800929 return null;
930 }
931 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800932
933 /** @hide */
934 public ParcelFileDescriptor getFdFromInCall() {
935 return mFdFromInCall;
936 }
937
938 /** @hide */
939 public ParcelFileDescriptor getFdToInCall() {
940 return mFdToInCall;
941 }
942 }
943
944 /**
945 * Provides constants to represent the results of responses to session modify requests sent via
946 * {@link Call#sendRttRequest()}
947 */
948 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700949 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800950 /**
951 * Session modify request was successful.
952 */
953 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
954
955 /**
956 * Session modify request failed.
957 */
958 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
959
960 /**
961 * Session modify request ignored due to invalid parameters.
962 */
963 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
964
965 /**
966 * Session modify request timed out.
967 */
968 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
969
970 /**
971 * Session modify request rejected by remote user.
972 */
973 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800974 }
975
976 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * Provides a means of controlling the video session associated with a {@link Connection}.
978 * <p>
979 * Implementations create a custom subclass of {@link VideoProvider} and the
980 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
981 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
982 * should set the {@link VideoProvider}.
983 * <p>
984 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
985 * {@link InCallService} implementations to issue requests related to the video session;
986 * it provides a means for the {@link ConnectionService} to report events and information
987 * related to the video session to Telecom and the {@link InCallService} implementations.
988 * <p>
989 * {@link InCallService} implementations interact with the {@link VideoProvider} via
990 * {@link android.telecom.InCallService.VideoCall}.
991 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 /**
994 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700995 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700996 */
997 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700998
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700999 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001000 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1001 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 */
1003 public static final int SESSION_EVENT_RX_RESUME = 2;
1004
1005 /**
1006 * Video transmission has begun. This occurs after a negotiated start of video transmission
1007 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 */
1010 public static final int SESSION_EVENT_TX_START = 3;
1011
1012 /**
1013 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1014 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 */
1017 public static final int SESSION_EVENT_TX_STOP = 4;
1018
1019 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001020 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * this as a cue to inform the user the camera is not available.
1022 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001023 */
1024 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1025
1026 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001027 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001028 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001029 * the camera has become available again.
1030 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 */
1032 public static final int SESSION_EVENT_CAMERA_READY = 6;
1033
1034 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001035 * Session event raised by Telecom when
1036 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1037 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1038 * @see #handleCallSessionEvent(int)
1039 */
1040 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1041
1042 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001044 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001045 */
1046 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1047
1048 /**
1049 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 */
1052 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1053
1054 /**
1055 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001056 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001057 */
1058 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1059
Rekha Kumar07366812015-03-24 16:42:31 -07001060 /**
1061 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001062 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001063 */
1064 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1065
1066 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001067 * Session modify request rejected by remote user.
1068 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001069 */
1070 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1071
Tyler Gunn75958422015-04-15 14:23:42 -07001072 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073 private static final int MSG_SET_CAMERA = 2;
1074 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1075 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1076 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1077 private static final int MSG_SET_ZOOM = 6;
1078 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1079 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1080 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001081 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001082 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001083 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001084
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001085 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1086 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1087 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1088 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1089 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1090 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001091 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1092 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001093 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1094
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001095 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001097
1098 /**
1099 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001100 *
1101 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1102 * load factor before resizing, 1 means we only expect a single thread to
1103 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001104 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001105 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1106 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107
1108 /**
1109 * Default handler used to consolidate binder method calls onto a single thread.
1110 */
1111 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001112 public VideoProviderHandler() {
1113 super();
1114 }
1115
1116 public VideoProviderHandler(Looper looper) {
1117 super(looper);
1118 }
1119
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001120 @Override
1121 public void handleMessage(Message msg) {
1122 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001123 case MSG_ADD_VIDEO_CALLBACK: {
1124 IBinder binder = (IBinder) msg.obj;
1125 IVideoCallback callback = IVideoCallback.Stub
1126 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001127 if (callback == null) {
1128 Log.w(this, "addVideoProvider - skipped; callback is null.");
1129 break;
1130 }
1131
Tyler Gunn75958422015-04-15 14:23:42 -07001132 if (mVideoCallbacks.containsKey(binder)) {
1133 Log.i(this, "addVideoProvider - skipped; already present.");
1134 break;
1135 }
1136 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001137 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001138 }
1139 case MSG_REMOVE_VIDEO_CALLBACK: {
1140 IBinder binder = (IBinder) msg.obj;
1141 IVideoCallback callback = IVideoCallback.Stub
1142 .asInterface((IBinder) msg.obj);
1143 if (!mVideoCallbacks.containsKey(binder)) {
1144 Log.i(this, "removeVideoProvider - skipped; not present.");
1145 break;
1146 }
1147 mVideoCallbacks.remove(binder);
1148 break;
1149 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001150 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001151 {
1152 SomeArgs args = (SomeArgs) msg.obj;
1153 try {
1154 onSetCamera((String) args.arg1);
1155 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001156 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001157 } finally {
1158 args.recycle();
1159 }
1160 }
1161 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001162 case MSG_SET_PREVIEW_SURFACE:
1163 onSetPreviewSurface((Surface) msg.obj);
1164 break;
1165 case MSG_SET_DISPLAY_SURFACE:
1166 onSetDisplaySurface((Surface) msg.obj);
1167 break;
1168 case MSG_SET_DEVICE_ORIENTATION:
1169 onSetDeviceOrientation(msg.arg1);
1170 break;
1171 case MSG_SET_ZOOM:
1172 onSetZoom((Float) msg.obj);
1173 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001174 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1175 SomeArgs args = (SomeArgs) msg.obj;
1176 try {
1177 onSendSessionModifyRequest((VideoProfile) args.arg1,
1178 (VideoProfile) args.arg2);
1179 } finally {
1180 args.recycle();
1181 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001182 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001183 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1185 onSendSessionModifyResponse((VideoProfile) msg.obj);
1186 break;
1187 case MSG_REQUEST_CAMERA_CAPABILITIES:
1188 onRequestCameraCapabilities();
1189 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001190 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1191 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001192 break;
1193 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001194 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001195 break;
1196 default:
1197 break;
1198 }
1199 }
1200 }
1201
1202 /**
1203 * IVideoProvider stub implementation.
1204 */
1205 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001206 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001207 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001208 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1209 }
1210
1211 public void removeVideoCallback(IBinder videoCallbackBinder) {
1212 mMessageHandler.obtainMessage(
1213 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001214 }
1215
Tyler Gunn159f35c2017-03-02 09:28:37 -08001216 public void setCamera(String cameraId, String callingPackageName,
1217 int targetSdkVersion) {
1218
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001219 SomeArgs args = SomeArgs.obtain();
1220 args.arg1 = cameraId;
1221 // Propagate the calling package; originally determined in
1222 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1223 // process.
1224 args.arg2 = callingPackageName;
1225 // Pass along the uid and pid of the calling app; this gets lost when we put the
1226 // message onto the handler. These are required for Telecom to perform a permission
1227 // check to see if the calling app is able to use the camera.
1228 args.argi1 = Binder.getCallingUid();
1229 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001230 // Pass along the target SDK version of the calling InCallService. This is used to
1231 // maintain backwards compatibility of the API for older callers.
1232 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001233 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001234 }
1235
1236 public void setPreviewSurface(Surface surface) {
1237 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1238 }
1239
1240 public void setDisplaySurface(Surface surface) {
1241 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1242 }
1243
1244 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001245 mMessageHandler.obtainMessage(
1246 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 }
1248
1249 public void setZoom(float value) {
1250 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1251 }
1252
Tyler Gunn45382162015-05-06 08:52:27 -07001253 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1254 SomeArgs args = SomeArgs.obtain();
1255 args.arg1 = fromProfile;
1256 args.arg2 = toProfile;
1257 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 }
1259
1260 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1261 mMessageHandler.obtainMessage(
1262 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1263 }
1264
1265 public void requestCameraCapabilities() {
1266 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1267 }
1268
1269 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001270 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 }
1272
Yorke Lee32f24732015-05-12 16:18:03 -07001273 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1275 }
1276 }
1277
1278 public VideoProvider() {
1279 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001280 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001281 }
1282
1283 /**
1284 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1285 *
1286 * @param looper The looper.
1287 * @hide
1288 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001289 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001290 public VideoProvider(Looper looper) {
1291 mBinder = new VideoProvider.VideoProviderBinder();
1292 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 }
1294
1295 /**
1296 * Returns binder object which can be used across IPC methods.
1297 * @hide
1298 */
1299 public final IVideoProvider getInterface() {
1300 return mBinder;
1301 }
1302
1303 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001304 * Sets the camera to be used for the outgoing video.
1305 * <p>
1306 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1307 * camera via
1308 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1309 * <p>
1310 * Sent from the {@link InCallService} via
1311 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001313 * @param cameraId The id of the camera (use ids as reported by
1314 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 */
1316 public abstract void onSetCamera(String cameraId);
1317
1318 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001319 * Sets the camera to be used for the outgoing video.
1320 * <p>
1321 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1322 * camera via
1323 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1324 * <p>
1325 * This prototype is used internally to ensure that the calling package name, UID and PID
1326 * are sent to Telecom so that can perform a camera permission check on the caller.
1327 * <p>
1328 * Sent from the {@link InCallService} via
1329 * {@link InCallService.VideoCall#setCamera(String)}.
1330 *
1331 * @param cameraId The id of the camera (use ids as reported by
1332 * {@link CameraManager#getCameraIdList()}).
1333 * @param callingPackageName The AppOpps package name of the caller.
1334 * @param callingUid The UID of the caller.
1335 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001336 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001337 * @hide
1338 */
1339 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001340 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001341
1342 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001343 * Sets the surface to be used for displaying a preview of what the user's camera is
1344 * currently capturing. When video transmission is enabled, this is the video signal which
1345 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001346 * <p>
1347 * Sent from the {@link InCallService} via
1348 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001350 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001351 */
1352 public abstract void onSetPreviewSurface(Surface surface);
1353
1354 /**
1355 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001356 * <p>
1357 * Sent from the {@link InCallService} via
1358 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001359 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001360 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001361 */
1362 public abstract void onSetDisplaySurface(Surface surface);
1363
1364 /**
1365 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1366 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001367 * <p>
1368 * Sent from the {@link InCallService} via
1369 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001370 *
1371 * @param rotation The device orientation, in degrees.
1372 */
1373 public abstract void onSetDeviceOrientation(int rotation);
1374
1375 /**
1376 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001377 * <p>
1378 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 *
1380 * @param value The camera zoom ratio.
1381 */
1382 public abstract void onSetZoom(float value);
1383
1384 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001385 * Issues a request to modify the properties of the current video session.
1386 * <p>
1387 * Example scenarios include: requesting an audio-only call to be upgraded to a
1388 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1389 * when the {@link InCallService} is no longer the foreground application.
1390 * <p>
1391 * If the {@link VideoProvider} determines a request to be invalid, it should call
1392 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1393 * invalid request back to the {@link InCallService}.
1394 * <p>
1395 * Where a request requires confirmation from the user of the peer device, the
1396 * {@link VideoProvider} must communicate the request to the peer device and handle the
1397 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1398 * is used to inform the {@link InCallService} of the result of the request.
1399 * <p>
1400 * Sent from the {@link InCallService} via
1401 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001403 * @param fromProfile The video profile prior to the request.
1404 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 */
Tyler Gunn45382162015-05-06 08:52:27 -07001406 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1407 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 /**
1410 * Provides a response to a request to change the current video session properties.
1411 * <p>
1412 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1413 * video call, could decline the request and keep the call as audio-only.
1414 * In such a scenario, the {@code responseProfile} would have a video state of
1415 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1416 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1417 * <p>
1418 * Sent from the {@link InCallService} via
1419 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1420 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1421 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001423 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 */
1425 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1426
1427 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1429 * <p>
1430 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1431 * camera via
1432 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1433 * <p>
1434 * Sent from the {@link InCallService} via
1435 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 */
1437 public abstract void onRequestCameraCapabilities();
1438
1439 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001440 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1441 * video component of the current {@link Connection}.
1442 * <p>
1443 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1444 * via {@link VideoProvider#setCallDataUsage(long)}.
1445 * <p>
1446 * Sent from the {@link InCallService} via
1447 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001449 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450
1451 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001452 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1453 * the peer device when the video signal is paused.
1454 * <p>
1455 * Sent from the {@link InCallService} via
1456 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 *
1458 * @param uri URI of image to display.
1459 */
Yorke Lee32f24732015-05-12 16:18:03 -07001460 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461
1462 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * Used to inform listening {@link InCallService} implementations when the
1464 * {@link VideoProvider} receives a session modification request.
1465 * <p>
1466 * Received by the {@link InCallService} via
1467 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001469 * @param videoProfile The requested video profile.
1470 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 */
1472 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001473 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001474 for (IVideoCallback callback : mVideoCallbacks.values()) {
1475 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001476 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001477 } catch (RemoteException ignored) {
1478 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001479 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 }
1481 }
1482 }
1483
1484 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001485 * Used to inform listening {@link InCallService} implementations when the
1486 * {@link VideoProvider} receives a response to a session modification request.
1487 * <p>
1488 * Received by the {@link InCallService} via
1489 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1490 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491 *
1492 * @param status Status of the session modify request. Valid values are
1493 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1494 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001495 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1496 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1497 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1498 * @param requestedProfile The original request which was sent to the peer device.
1499 * @param responseProfile The actual profile changes agreed to by the peer device.
1500 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001501 */
1502 public void receiveSessionModifyResponse(int status,
1503 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001504 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001505 for (IVideoCallback callback : mVideoCallbacks.values()) {
1506 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001507 callback.receiveSessionModifyResponse(status, requestedProfile,
1508 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001509 } catch (RemoteException ignored) {
1510 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001511 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 }
1513 }
1514 }
1515
1516 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001517 * Used to inform listening {@link InCallService} implementations when the
1518 * {@link VideoProvider} reports a call session event.
1519 * <p>
1520 * Received by the {@link InCallService} via
1521 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001523 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1524 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1525 * {@link VideoProvider#SESSION_EVENT_TX_START},
1526 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1527 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001528 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1529 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001530 */
1531 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001532 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001533 for (IVideoCallback callback : mVideoCallbacks.values()) {
1534 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001535 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001536 } catch (RemoteException ignored) {
1537 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001538 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001539 }
1540 }
1541 }
1542
1543 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001544 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1545 * peer's video have changed.
1546 * <p>
1547 * This could occur if, for example, the peer rotates their device, changing the aspect
1548 * ratio of the video, or if the user switches between the back and front cameras.
1549 * <p>
1550 * Received by the {@link InCallService} via
1551 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 *
1553 * @param width The updated peer video width.
1554 * @param height The updated peer video height.
1555 */
1556 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001557 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001558 for (IVideoCallback callback : mVideoCallbacks.values()) {
1559 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001560 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001561 } catch (RemoteException ignored) {
1562 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001563 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001564 }
1565 }
1566 }
1567
1568 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001569 * Used to inform listening {@link InCallService} implementations when the data usage of the
1570 * video associated with the current {@link Connection} has changed.
1571 * <p>
1572 * This could be in response to a preview request via
1573 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001574 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1575 * 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 -07001576 * <p>
1577 * Received by the {@link InCallService} via
1578 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001579 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001580 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1581 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 */
Yorke Lee32f24732015-05-12 16:18:03 -07001583 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001584 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001585 for (IVideoCallback callback : mVideoCallbacks.values()) {
1586 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001587 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001588 } catch (RemoteException ignored) {
1589 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001590 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 }
1592 }
1593 }
1594
1595 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001596 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001598 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001599 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1600 * @hide
1601 */
1602 public void changeCallDataUsage(long dataUsage) {
1603 setCallDataUsage(dataUsage);
1604 }
1605
1606 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001607 * Used to inform listening {@link InCallService} implementations when the capabilities of
1608 * the current camera have changed.
1609 * <p>
1610 * The {@link VideoProvider} should call this in response to
1611 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1612 * changed via {@link VideoProvider#onSetCamera(String)}.
1613 * <p>
1614 * Received by the {@link InCallService} via
1615 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1616 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001617 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001618 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001619 */
Yorke Lee400470f2015-05-12 13:31:25 -07001620 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001621 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001622 for (IVideoCallback callback : mVideoCallbacks.values()) {
1623 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001624 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001625 } catch (RemoteException ignored) {
1626 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001627 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 }
1629 }
1630 }
Rekha Kumar07366812015-03-24 16:42:31 -07001631
1632 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001633 * Used to inform listening {@link InCallService} implementations when the video quality
1634 * of the call has changed.
1635 * <p>
1636 * Received by the {@link InCallService} via
1637 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001638 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001639 * @param videoQuality The updated video quality. Valid values:
1640 * {@link VideoProfile#QUALITY_HIGH},
1641 * {@link VideoProfile#QUALITY_MEDIUM},
1642 * {@link VideoProfile#QUALITY_LOW},
1643 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001644 */
1645 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001646 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001647 for (IVideoCallback callback : mVideoCallbacks.values()) {
1648 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001649 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001650 } catch (RemoteException ignored) {
1651 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001652 }
Rekha Kumar07366812015-03-24 16:42:31 -07001653 }
1654 }
1655 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001656
1657 /**
1658 * Returns a string representation of a call session event.
1659 *
1660 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1661 * @return String representation of the call session event.
1662 * @hide
1663 */
1664 public static String sessionEventToString(int event) {
1665 switch (event) {
1666 case SESSION_EVENT_CAMERA_FAILURE:
1667 return SESSION_EVENT_CAMERA_FAILURE_STR;
1668 case SESSION_EVENT_CAMERA_READY:
1669 return SESSION_EVENT_CAMERA_READY_STR;
1670 case SESSION_EVENT_RX_PAUSE:
1671 return SESSION_EVENT_RX_PAUSE_STR;
1672 case SESSION_EVENT_RX_RESUME:
1673 return SESSION_EVENT_RX_RESUME_STR;
1674 case SESSION_EVENT_TX_START:
1675 return SESSION_EVENT_TX_START_STR;
1676 case SESSION_EVENT_TX_STOP:
1677 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001678 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1679 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001680 default:
1681 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1682 }
1683 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001684 }
1685
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001686 private final Listener mConnectionDeathListener = new Listener() {
1687 @Override
1688 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001689 if (mConferenceables.remove(c)) {
1690 fireOnConferenceableConnectionsChanged();
1691 }
1692 }
1693 };
1694
1695 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1696 @Override
1697 public void onDestroyed(Conference c) {
1698 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001699 fireOnConferenceableConnectionsChanged();
1700 }
1701 }
1702 };
1703
Jay Shrauner229e3822014-08-15 09:23:07 -07001704 /**
1705 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1706 * load factor before resizing, 1 means we only expect a single thread to
1707 * access the map so make only a single shard
1708 */
1709 private final Set<Listener> mListeners = Collections.newSetFromMap(
1710 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001711 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1712 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001713 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001714
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001715 // The internal telecom call ID associated with this connection.
1716 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001717 // The PhoneAccountHandle associated with this connection.
1718 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001719 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001720 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001721 private Uri mAddress;
1722 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001723 private String mCallerDisplayName;
1724 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001725 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001726 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001727 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001728 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001729 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001730 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001731 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001732 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001733 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001734 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001735 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001736 private Conference mConference;
1737 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001738 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001739 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001740
1741 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001742 * Tracks the key set for the extras bundle provided on the last invocation of
1743 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1744 * keys which were set previously but are no longer present in the replacement Bundle.
1745 */
1746 private Set<String> mPreviousExtraKeys;
1747
1748 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001749 * Create a new Connection.
1750 */
Santos Cordonf2951102014-07-20 19:06:29 -07001751 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001752
1753 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001754 * Returns the Telecom internal call ID associated with this connection. Should only be used
1755 * for debugging and tracing purposes.
1756 *
1757 * @return The Telecom call ID.
1758 * @hide
1759 */
1760 public final String getTelecomCallId() {
1761 return mTelecomCallId;
1762 }
1763
1764 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001765 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001766 */
Andrew Lee100e2932014-09-08 15:34:24 -07001767 public final Uri getAddress() {
1768 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001769 }
1770
1771 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001772 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001773 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001774 */
Andrew Lee100e2932014-09-08 15:34:24 -07001775 public final int getAddressPresentation() {
1776 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001777 }
1778
1779 /**
1780 * @return The caller display name (CNAP).
1781 */
1782 public final String getCallerDisplayName() {
1783 return mCallerDisplayName;
1784 }
1785
1786 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001787 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001788 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001789 */
1790 public final int getCallerDisplayNamePresentation() {
1791 return mCallerDisplayNamePresentation;
1792 }
1793
1794 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001796 */
1797 public final int getState() {
1798 return mState;
1799 }
1800
1801 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001802 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001803 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1804 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1805 * {@link VideoProfile#STATE_TX_ENABLED},
1806 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001807 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001808 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001809 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001810 */
1811 public final int getVideoState() {
1812 return mVideoState;
1813 }
1814
1815 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001816 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001817 * being routed by the system. This is {@code null} if this Connection
1818 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001819 * @deprecated Use {@link #getCallAudioState()} instead.
1820 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001821 */
Yorke Lee4af59352015-05-13 14:14:54 -07001822 @SystemApi
1823 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001824 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001825 if (mCallAudioState == null) {
1826 return null;
1827 }
Yorke Lee4af59352015-05-13 14:14:54 -07001828 return new AudioState(mCallAudioState);
1829 }
1830
1831 /**
1832 * @return The audio state of the connection, describing how its audio is currently
1833 * being routed by the system. This is {@code null} if this Connection
1834 * does not directly know about its audio state.
1835 */
1836 public final CallAudioState getCallAudioState() {
1837 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001838 }
1839
1840 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001841 * @return The conference that this connection is a part of. Null if it is not part of any
1842 * conference.
1843 */
1844 public final Conference getConference() {
1845 return mConference;
1846 }
1847
1848 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001849 * Returns whether this connection is requesting that the system play a ringback tone
1850 * on its behalf.
1851 */
Andrew Lee100e2932014-09-08 15:34:24 -07001852 public final boolean isRingbackRequested() {
1853 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001854 }
1855
1856 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001857 * @return True if the connection's audio mode is VOIP.
1858 */
1859 public final boolean getAudioModeIsVoip() {
1860 return mAudioModeIsVoip;
1861 }
1862
1863 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001864 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1865 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1866 * start time of the conference.
1867 *
1868 * @return The time at which the {@code Connnection} was connected.
1869 *
1870 * @hide
1871 */
1872 public final long getConnectTimeMillis() {
1873 return mConnectTimeMillis;
1874 }
1875
1876 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001877 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1878 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1879 * start time of the conference.
1880 *
1881 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1882 * changes do not impact the call duration.
1883 *
1884 * @return The time at which the {@link Connection} was connected.
1885 *
1886 * @hide
1887 */
1888 public final long getConnectElapsedTimeMillis() {
1889 return mConnectElapsedTimeMillis;
1890 }
1891
1892 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001893 * @return The status hints for this connection.
1894 */
1895 public final StatusHints getStatusHints() {
1896 return mStatusHints;
1897 }
1898
1899 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001900 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001901 * <p>
1902 * Extras should be updated using {@link #putExtras(Bundle)}.
1903 * <p>
1904 * Telecom or an {@link InCallService} can also update the extras via
1905 * {@link android.telecom.Call#putExtras(Bundle)}, and
1906 * {@link Call#removeExtras(List)}.
1907 * <p>
1908 * The connection is notified of changes to the extras made by Telecom or an
1909 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001910 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001911 * @return The extras associated with this connection.
1912 */
1913 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001914 Bundle extras = null;
1915 synchronized (mExtrasLock) {
1916 if (mExtras != null) {
1917 extras = new Bundle(mExtras);
1918 }
1919 }
1920 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001921 }
1922
1923 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001924 * Assign a listener to be notified of state changes.
1925 *
1926 * @param l A listener.
1927 * @return This Connection.
1928 *
1929 * @hide
1930 */
1931 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001932 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001933 return this;
1934 }
1935
1936 /**
1937 * Remove a previously assigned listener that was being notified of state changes.
1938 *
1939 * @param l A Listener.
1940 * @return This Connection.
1941 *
1942 * @hide
1943 */
1944 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001945 if (l != null) {
1946 mListeners.remove(l);
1947 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 return this;
1949 }
1950
1951 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001952 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001953 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001954 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001955 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001956 }
1957
1958 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001959 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1960 * ONLY for debugging purposes.
1961 *
1962 * @param callId The telecom call ID.
1963 * @hide
1964 */
1965 public void setTelecomCallId(String callId) {
1966 mTelecomCallId = callId;
1967 }
1968
1969 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001970 * Inform this Connection that the state of its audio output has been changed externally.
1971 *
1972 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001973 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001974 */
Yorke Lee4af59352015-05-13 14:14:54 -07001975 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001976 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001977 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001978 mCallAudioState = state;
1979 onAudioStateChanged(getAudioState());
1980 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001981 }
1982
1983 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001984 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001985 * @return A string representation of the value.
1986 */
1987 public static String stateToString(int state) {
1988 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001989 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001990 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001991 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001992 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001993 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001994 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001995 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001996 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001997 case STATE_PULLING_CALL:
1998 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001999 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002000 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002001 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002002 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002003 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 return "DISCONNECTED";
2005 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002006 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002007 return "UNKNOWN";
2008 }
2009 }
2010
2011 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002012 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002013 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002014 public final int getConnectionCapabilities() {
2015 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002016 }
2017
2018 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002019 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2020 */
2021 public final int getConnectionProperties() {
2022 return mConnectionProperties;
2023 }
2024
2025 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002026 * Returns the connection's supported audio routes.
2027 *
2028 * @hide
2029 */
2030 public final int getSupportedAudioRoutes() {
2031 return mSupportedAudioRoutes;
2032 }
2033
2034 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002035 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002036 *
Andrew Lee100e2932014-09-08 15:34:24 -07002037 * @param address The new address.
2038 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002039 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002040 */
Andrew Lee100e2932014-09-08 15:34:24 -07002041 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002042 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002043 Log.d(this, "setAddress %s", address);
2044 mAddress = address;
2045 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002046 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002047 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002048 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002049 }
2050
2051 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002052 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002053 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002054 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002055 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002056 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002057 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002058 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002059 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002060 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002061 mCallerDisplayName = callerDisplayName;
2062 mCallerDisplayNamePresentation = presentation;
2063 for (Listener l : mListeners) {
2064 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2065 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002066 }
2067
2068 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002069 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002070 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2071 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2072 * {@link VideoProfile#STATE_TX_ENABLED},
2073 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002074 *
2075 * @param videoState The new video state.
2076 */
2077 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002078 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002079 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002080 mVideoState = videoState;
2081 for (Listener l : mListeners) {
2082 l.onVideoStateChanged(this, mVideoState);
2083 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002084 }
2085
2086 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002087 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002088 * communicate).
2089 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002090 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002092 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002093 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 }
2095
2096 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002099 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002101 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002102 }
2103
2104 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002105 * Sets state to initializing (this Connection is not yet ready to be used).
2106 */
2107 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002108 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002109 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002110 }
2111
2112 /**
2113 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2114 */
2115 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002118 }
2119
2120 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002121 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002122 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002123 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002124 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002125 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 }
2127
2128 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002129 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2130 * device). Only applicable for {@link Connection}s with
2131 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2132 */
2133 public final void setPulling() {
2134 checkImmutable();
2135 setState(STATE_PULLING_CALL);
2136 }
2137
2138 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002139 * Sets state to be on hold.
2140 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002141 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002142 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002143 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002144 }
2145
2146 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002147 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002148 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002149 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002150 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002151 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002152 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002153 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002154 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002155 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002156 }
2157
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002158 public final VideoProvider getVideoProvider() {
2159 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002160 }
2161
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002162 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002163 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002165 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002166 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002167 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002168 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002169 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002170 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002171 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002172 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002173 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002174 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002175 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176 }
2177
2178 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002179 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2180 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2181 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2182 * to send an {@link #onPostDialContinue(boolean)} signal.
2183 *
2184 * @param remaining The DTMF character sequence remaining to be emitted once the
2185 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2186 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002187 */
2188 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002189 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002190 for (Listener l : mListeners) {
2191 l.onPostDialWait(this, remaining);
2192 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002193 }
2194
2195 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002196 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2197 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002198 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002199 *
2200 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002201 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002202 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002203 checkImmutable();
2204 for (Listener l : mListeners) {
2205 l.onPostDialChar(this, nextChar);
2206 }
2207 }
2208
2209 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002210 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002211 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002212 *
2213 * @param ringback Whether the ringback tone is to be played.
2214 */
Andrew Lee100e2932014-09-08 15:34:24 -07002215 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002216 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002217 if (mRingbackRequested != ringback) {
2218 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002219 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002220 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002221 }
2222 }
Ihab Awadf8358972014-05-28 16:46:42 -07002223 }
2224
2225 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002226 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002227 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002228 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002229 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002230 public final void setConnectionCapabilities(int connectionCapabilities) {
2231 checkImmutable();
2232 if (mConnectionCapabilities != connectionCapabilities) {
2233 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002234 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002235 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002236 }
2237 }
Santos Cordonb6939982014-06-04 20:20:58 -07002238 }
2239
2240 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002241 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2242 *
2243 * @param connectionProperties The new connection properties.
2244 */
2245 public final void setConnectionProperties(int connectionProperties) {
2246 checkImmutable();
2247 if (mConnectionProperties != connectionProperties) {
2248 mConnectionProperties = connectionProperties;
2249 for (Listener l : mListeners) {
2250 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2251 }
2252 }
2253 }
2254
2255 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002256 * Sets the supported audio routes.
2257 *
2258 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2259 * See {@link CallAudioState}
2260 * @hide
2261 */
2262 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2263 if ((supportedAudioRoutes
2264 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2265 throw new IllegalArgumentException(
2266 "supported audio routes must include either speaker or earpiece");
2267 }
2268
2269 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2270 mSupportedAudioRoutes = supportedAudioRoutes;
2271 for (Listener l : mListeners) {
2272 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2273 }
2274 }
2275 }
2276
2277 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002278 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002279 */
Evan Charlton36a71342014-07-19 16:31:02 -07002280 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002281 for (Listener l : mListeners) {
2282 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002283 }
Santos Cordonb6939982014-06-04 20:20:58 -07002284 }
2285
2286 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002287 * Requests that the framework use VOIP audio mode for this connection.
2288 *
2289 * @param isVoip True if the audio mode is VOIP.
2290 */
2291 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002292 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002293 mAudioModeIsVoip = isVoip;
2294 for (Listener l : mListeners) {
2295 l.onAudioModeIsVoipChanged(this, isVoip);
2296 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002297 }
2298
2299 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002300 * Sets the time at which a call became active on this Connection. This is set only
2301 * when a conference call becomes active on this connection.
2302 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002303 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2304 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002305 *
2306 * @hide
2307 */
2308 public final void setConnectTimeMillis(long connectTimeMillis) {
2309 mConnectTimeMillis = connectTimeMillis;
2310 }
2311
2312 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002313 * Sets the time at which a call became active on this Connection. This is set only
2314 * when a conference call becomes active on this connection.
2315 *
2316 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2317 * {@link SystemClock#elapsedRealtime()}.
2318 *
2319 * @hide
2320 */
Tyler Gunn17541392018-02-01 08:58:38 -08002321 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002322 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2323 }
2324
2325 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002326 * Sets the label and icon status to display in the in-call UI.
2327 *
2328 * @param statusHints The status label and icon to set.
2329 */
2330 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002331 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002332 mStatusHints = statusHints;
2333 for (Listener l : mListeners) {
2334 l.onStatusHintsChanged(this, statusHints);
2335 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002336 }
2337
2338 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002339 * Sets the connections with which this connection can be conferenced.
2340 *
2341 * @param conferenceableConnections The set of connections this connection can conference with.
2342 */
2343 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002344 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002345 clearConferenceableList();
2346 for (Connection c : conferenceableConnections) {
2347 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2348 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002349 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002350 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002351 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002352 }
2353 }
2354 fireOnConferenceableConnectionsChanged();
2355 }
2356
2357 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002358 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2359 * or conferences with which this connection can be conferenced.
2360 *
2361 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002362 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002363 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002364 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002365 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002366 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2367 // small amount of items here.
2368 if (!mConferenceables.contains(c)) {
2369 if (c instanceof Connection) {
2370 Connection connection = (Connection) c;
2371 connection.addConnectionListener(mConnectionDeathListener);
2372 } else if (c instanceof Conference) {
2373 Conference conference = (Conference) c;
2374 conference.addListener(mConferenceDeathListener);
2375 }
2376 mConferenceables.add(c);
2377 }
2378 }
2379 fireOnConferenceableConnectionsChanged();
2380 }
2381
2382 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002383 * @hide
2384 * Resets the cdma connection time.
2385 */
2386 public final void resetConnectionTime() {
2387 for (Listener l : mListeners) {
2388 l.onConnectionTimeReset(this);
2389 }
2390 }
2391
2392 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002393 * Returns the connections or conferences with which this connection can be conferenced.
2394 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002395 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002396 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002397 }
2398
Yorke Lee53463962015-08-04 16:07:19 -07002399 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002400 * @hide
2401 */
2402 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002403 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002404 if (mConnectionService != null) {
2405 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2406 "which is already associated with another ConnectionService.");
2407 } else {
2408 mConnectionService = connectionService;
2409 }
2410 }
2411
2412 /**
2413 * @hide
2414 */
2415 public final void unsetConnectionService(ConnectionService connectionService) {
2416 if (mConnectionService != connectionService) {
2417 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2418 "that does not belong to the ConnectionService.");
2419 } else {
2420 mConnectionService = null;
2421 }
2422 }
2423
2424 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002425 * @hide
2426 */
2427 public final ConnectionService getConnectionService() {
2428 return mConnectionService;
2429 }
2430
2431 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002432 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002433 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002434 *
2435 * @param conference The conference.
2436 * @return {@code true} if the conference was successfully set.
2437 * @hide
2438 */
2439 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002440 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002441 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002442 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002443 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002444 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2445 fireConferenceChanged();
2446 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002447 return true;
2448 }
2449 return false;
2450 }
2451
2452 /**
2453 * Resets the conference that this connection is a part of.
2454 * @hide
2455 */
2456 public final void resetConference() {
2457 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002458 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002459 mConference = null;
2460 fireConferenceChanged();
2461 }
2462 }
2463
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002464 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002465 * Set some extras that can be associated with this {@code Connection}.
2466 * <p>
2467 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2468 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2469 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002470 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2471 * {@link #removeExtras(String...)} methods to modify the extras.
2472 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002473 * 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 -07002474 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2475 *
2476 * @param extras The extras associated with this {@code Connection}.
2477 */
2478 public final void setExtras(@Nullable Bundle extras) {
2479 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002480
2481 // Add/replace any new or changed extras values.
2482 putExtras(extras);
2483
2484 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2485 // the current one and remove any keys that went away.
2486 if (mPreviousExtraKeys != null) {
2487 List<String> toRemove = new ArrayList<String>();
2488 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002489 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002490 toRemove.add(oldKey);
2491 }
2492 }
2493 if (!toRemove.isEmpty()) {
2494 removeExtras(toRemove);
2495 }
2496 }
2497
2498 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2499 // called we can see if the caller has removed any extras values.
2500 if (mPreviousExtraKeys == null) {
2501 mPreviousExtraKeys = new ArraySet<String>();
2502 }
2503 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002504 if (extras != null) {
2505 mPreviousExtraKeys.addAll(extras.keySet());
2506 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002507 }
2508
2509 /**
2510 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2511 * added.
2512 * <p>
2513 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2514 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2515 *
2516 * @param extras The extras to add.
2517 */
2518 public final void putExtras(@NonNull Bundle extras) {
2519 checkImmutable();
2520 if (extras == null) {
2521 return;
2522 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002523 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2524 // the listeners.
2525 Bundle listenerExtras;
2526 synchronized (mExtrasLock) {
2527 if (mExtras == null) {
2528 mExtras = new Bundle();
2529 }
2530 mExtras.putAll(extras);
2531 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002532 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002533 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002534 // Create a new clone of the extras for each listener so that they don't clobber
2535 // each other
2536 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002537 }
2538 }
2539
2540 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002541 * Adds a boolean extra to this {@code Connection}.
2542 *
2543 * @param key The extra key.
2544 * @param value The value.
2545 * @hide
2546 */
2547 public final void putExtra(String key, boolean value) {
2548 Bundle newExtras = new Bundle();
2549 newExtras.putBoolean(key, value);
2550 putExtras(newExtras);
2551 }
2552
2553 /**
2554 * Adds an integer extra to this {@code Connection}.
2555 *
2556 * @param key The extra key.
2557 * @param value The value.
2558 * @hide
2559 */
2560 public final void putExtra(String key, int value) {
2561 Bundle newExtras = new Bundle();
2562 newExtras.putInt(key, value);
2563 putExtras(newExtras);
2564 }
2565
2566 /**
2567 * Adds a string extra to this {@code Connection}.
2568 *
2569 * @param key The extra key.
2570 * @param value The value.
2571 * @hide
2572 */
2573 public final void putExtra(String key, String value) {
2574 Bundle newExtras = new Bundle();
2575 newExtras.putString(key, value);
2576 putExtras(newExtras);
2577 }
2578
2579 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002580 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002581 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002582 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002583 */
2584 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002585 synchronized (mExtrasLock) {
2586 if (mExtras != null) {
2587 for (String key : keys) {
2588 mExtras.remove(key);
2589 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002590 }
2591 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002592 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002593 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002594 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002595 }
2596 }
2597
2598 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002599 * Removes extras from this {@code Connection}.
2600 *
2601 * @param keys The keys of the extras to remove.
2602 */
2603 public final void removeExtras(String ... keys) {
2604 removeExtras(Arrays.asList(keys));
2605 }
2606
2607 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002608 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2609 * be change to the {@link #getCallAudioState()}.
2610 * <p>
2611 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2612 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2613 * <p>
2614 * See also {@link InCallService#setAudioRoute(int)}.
2615 *
2616 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2617 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2618 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2619 */
2620 public final void setAudioRoute(int route) {
2621 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002622 l.onAudioRouteChanged(this, route, null);
2623 }
2624 }
2625
2626 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002627 * Request audio routing to a specific bluetooth device. Calling this method may result in
2628 * the device routing audio to a different bluetooth device than the one specified if the
2629 * bluetooth stack is unable to route audio to the requested device.
2630 * A list of available devices can be obtained via
2631 * {@link CallAudioState#getSupportedBluetoothDevices()}
2632 *
2633 * <p>
2634 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2635 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2636 * <p>
Hall Liu15392832018-04-02 13:52:57 -07002637 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2638 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002639 */
Hall Liu15392832018-04-02 13:52:57 -07002640 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002641 for (Listener l : mListeners) {
Hall Liu15392832018-04-02 13:52:57 -07002642 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2643 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002644 }
2645 }
2646
2647 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002648 * Informs listeners that a previously requested RTT session via
2649 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002650 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002651 */
2652 public final void sendRttInitiationSuccess() {
2653 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2654 }
2655
2656 /**
2657 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002658 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002659 * has failed.
2660 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2661 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002662 */
2663 public final void sendRttInitiationFailure(int reason) {
2664 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2665 }
2666
2667 /**
2668 * Informs listeners that a currently active RTT session has been terminated by the remote
2669 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002670 */
2671 public final void sendRttSessionRemotelyTerminated() {
2672 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2673 }
2674
2675 /**
2676 * Informs listeners that the remote side of the call has requested an upgrade to include an
2677 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002678 */
2679 public final void sendRemoteRttRequest() {
2680 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2681 }
2682
2683 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002684 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002685 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002686 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002687 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2688 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002689 */
Yorke Lee4af59352015-05-13 14:14:54 -07002690 @SystemApi
2691 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002692 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002693
2694 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002695 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2696 *
2697 * @param state The new connection audio state.
2698 */
2699 public void onCallAudioStateChanged(CallAudioState state) {}
2700
2701 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002702 * Notifies this Connection of an internal state change. This method is called after the
2703 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002704 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002705 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002706 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002707 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002708
2709 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002710 * Notifies this Connection of a request to play a DTMF tone.
2711 *
2712 * @param c A DTMF character.
2713 */
Santos Cordonf2951102014-07-20 19:06:29 -07002714 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002715
2716 /**
2717 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2718 */
Santos Cordonf2951102014-07-20 19:06:29 -07002719 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002720
2721 /**
2722 * Notifies this Connection of a request to disconnect.
2723 */
Santos Cordonf2951102014-07-20 19:06:29 -07002724 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002725
2726 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002727 * Notifies this Connection of a request to disconnect a participant of the conference managed
2728 * by the connection.
2729 *
2730 * @param endpoint the {@link Uri} of the participant to disconnect.
2731 * @hide
2732 */
2733 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2734
2735 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002736 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002737 */
Santos Cordonf2951102014-07-20 19:06:29 -07002738 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002739
2740 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002741 * Notifies this Connection of a request to abort.
2742 */
Santos Cordonf2951102014-07-20 19:06:29 -07002743 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002744
2745 /**
2746 * Notifies this Connection of a request to hold.
2747 */
Santos Cordonf2951102014-07-20 19:06:29 -07002748 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002749
2750 /**
2751 * Notifies this Connection of a request to exit a hold state.
2752 */
Santos Cordonf2951102014-07-20 19:06:29 -07002753 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002754
2755 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002756 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002757 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002758 * <p>
2759 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2760 * the default dialer's {@link InCallService}.
2761 * <p>
2762 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2763 * Telecom framework may request that the call is answered in the following circumstances:
2764 * <ul>
2765 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2766 * <li>A car mode {@link InCallService} is in use which has declared
2767 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2768 * {@link InCallService} will be able to see calls from self-managed
2769 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2770 * behalf.</li>
2771 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002772 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002773 */
Santos Cordonf2951102014-07-20 19:06:29 -07002774 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002775
2776 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002777 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002778 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002779 * <p>
2780 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2781 * the default dialer's {@link InCallService}.
2782 * <p>
2783 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2784 * Telecom framework may request that the call is answered in the following circumstances:
2785 * <ul>
2786 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2787 * <li>A car mode {@link InCallService} is in use which has declared
2788 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2789 * {@link InCallService} will be able to see calls from self-managed
2790 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2791 * behalf.</li>
2792 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002793 */
2794 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002795 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002796 }
2797
2798 /**
2799 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302800 * a request to deflect.
2801 */
2802 public void onDeflect(Uri address) {}
2803
2804 /**
2805 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002806 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002807 * <p>
2808 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2809 * the default dialer's {@link InCallService}.
2810 * <p>
2811 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2812 * Telecom framework may request that the call is rejected in the following circumstances:
2813 * <ul>
2814 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2815 * <li>A car mode {@link InCallService} is in use which has declared
2816 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2817 * {@link InCallService} will be able to see calls from self-managed
2818 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2819 * behalf.</li>
2820 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002821 */
Santos Cordonf2951102014-07-20 19:06:29 -07002822 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002823
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002824 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002825 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2826 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002827 */
2828 public void onReject(String replyMessage) {}
2829
2830 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002831 * Notifies this Connection of a request to silence the ringer.
2832 * <p>
2833 * The ringer may be silenced by any of the following methods:
2834 * <ul>
2835 * <li>{@link TelecomManager#silenceRinger()}</li>
2836 * <li>The user presses the volume-down button while a call is ringing.</li>
2837 * </ul>
2838 * <p>
2839 * Self-managed {@link ConnectionService} implementations should override this method in their
2840 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2841 * your app set the ringtone as part of the incoming call {@link Notification} (see
2842 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2843 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2844 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2845 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002846 */
2847 public void onSilence() {}
2848
2849 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002850 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2851 */
Santos Cordonf2951102014-07-20 19:06:29 -07002852 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002853
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002854 /**
2855 * Notifies this Connection of a request to pull an external call to the local device.
2856 * <p>
2857 * The {@link InCallService} issues a request to pull an external call to the local device via
2858 * {@link Call#pullExternalCall()}.
2859 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002860 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2861 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002862 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002863 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002864 */
2865 public void onPullExternalCall() {}
2866
2867 /**
2868 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2869 * <p>
2870 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2871 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002872 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2873 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2874 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2875 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2876 * not aware of.
2877 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002878 * See also {@link Call#sendCallEvent(String, Bundle)}.
2879 *
2880 * @param event The call event.
2881 * @param extras Extras associated with the call event.
2882 */
2883 public void onCallEvent(String event, Bundle extras) {}
2884
Tyler Gunndee56a82016-03-23 16:06:34 -07002885 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002886 * Notifies this {@link Connection} that a handover has completed.
2887 * <p>
2888 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2889 * Bundle)} on the initiating side of the handover, and
2890 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2891 */
2892 public void onHandoverComplete() {}
2893
2894 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002895 * Notifies this {@link Connection} of a change to the extras made outside the
2896 * {@link ConnectionService}.
2897 * <p>
2898 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2899 * the {@link android.telecom.Call#putExtras(Bundle)} and
2900 * {@link Call#removeExtras(List)}.
2901 *
2902 * @param extras The new extras bundle.
2903 */
2904 public void onExtrasChanged(Bundle extras) {}
2905
Tyler Gunnf5035432017-01-09 09:43:12 -08002906 /**
2907 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2908 * displaying its incoming call user interface for the {@link Connection}.
2909 * <p>
2910 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2911 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2912 * should show its own incoming call user interface.
2913 * <p>
2914 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002915 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2916 * Telecom framework will display its own incoming call user interface to allow the user to
2917 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2918 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002919 * <p>
2920 * You should trigger the display of the incoming call user interface for your application by
2921 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002922 *
2923 * In your application code, you should create a {@link android.app.NotificationChannel} for
2924 * incoming call notifications from your app:
2925 * <pre><code>
2926 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2927 * NotificationManager.IMPORTANCE_MAX);
2928 * // other channel setup stuff goes here.
2929 *
2930 * // We'll use the default system ringtone for our incoming call notification channel. You can
2931 * // use your own audio resource here.
2932 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2933 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2934 * // Setting the AudioAttributes is important as it identifies the purpose of your
2935 * // notification sound.
2936 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2937 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2938 * .build());
2939 *
2940 * NotificationManager mgr = getSystemService(NotificationManager.class);
2941 * mgr.createNotificationChannel(channel);
2942 * </code></pre>
2943 * When it comes time to post a notification for your incoming call, ensure it uses your
2944 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002945 * <pre><code>
2946 * // Create an intent which triggers your fullscreen incoming call user interface.
2947 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2948 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2949 * intent.setClass(context, YourIncomingCallActivity.class);
2950 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2951 *
2952 * // Build the notification as an ongoing high priority item; this ensures it will show as
2953 * // a heads up notification which slides down over top of the current content.
2954 * final Notification.Builder builder = new Notification.Builder(context);
2955 * builder.setOngoing(true);
2956 * builder.setPriority(Notification.PRIORITY_HIGH);
2957 *
2958 * // Set notification content intent to take user to fullscreen UI if user taps on the
2959 * // notification body.
2960 * builder.setContentIntent(pendingIntent);
2961 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2962 * // manager deems it appropriate.
2963 * builder.setFullScreenIntent(pendingIntent, true);
2964 *
2965 * // Setup notification content.
2966 * builder.setSmallIcon( yourIconResourceId );
2967 * builder.setContentTitle("Your notification title");
2968 * builder.setContentText("Your notification content.");
2969 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002970 * // Set notification as insistent to cause your ringtone to loop.
2971 * Notification notification = builder.build();
2972 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002973 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002974 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002975 * NotificationManager notificationManager = mContext.getSystemService(
2976 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07002977 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08002978 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002979 */
2980 public void onShowIncomingCallUi() {}
2981
Hall Liub64ac4c2017-02-06 10:49:48 -08002982 /**
2983 * Notifies this {@link Connection} that the user has requested an RTT session.
2984 * The connection service should call {@link #sendRttInitiationSuccess} or
2985 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2986 * request, respectively.
2987 * @param rttTextStream The object that should be used to send text to or receive text from
2988 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002989 */
2990 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2991
2992 /**
2993 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2994 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002995 */
2996 public void onStopRtt() {}
2997
2998 /**
2999 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3000 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3001 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3002 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003003 * @param rttTextStream The object that should be used to send text to or receive text from
3004 * the in-call app.
3005 */
3006 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3007
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003008 static String toLogSafePhoneNumber(String number) {
3009 // For unknown number, log empty string.
3010 if (number == null) {
3011 return "";
3012 }
3013
3014 if (PII_DEBUG) {
3015 // When PII_DEBUG is true we emit PII.
3016 return number;
3017 }
3018
3019 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3020 // sanitized phone numbers.
3021 StringBuilder builder = new StringBuilder();
3022 for (int i = 0; i < number.length(); i++) {
3023 char c = number.charAt(i);
3024 if (c == '-' || c == '@' || c == '.') {
3025 builder.append(c);
3026 } else {
3027 builder.append('x');
3028 }
3029 }
3030 return builder.toString();
3031 }
3032
Ihab Awad542e0ea2014-05-16 10:22:16 -07003033 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003034 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003035 if (mState == STATE_DISCONNECTED && mState != state) {
3036 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003037 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003038 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003039 if (mState != state) {
3040 Log.d(this, "setState: %s", stateToString(state));
3041 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003042 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003043 for (Listener l : mListeners) {
3044 l.onStateChanged(this, state);
3045 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003046 }
3047 }
3048
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003049 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003050 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003051 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3052 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003053 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003054 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003055
3056 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003057 if (mImmutable) {
3058 throw new UnsupportedOperationException("Connection is immutable");
3059 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003060 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003061 }
3062
Evan Charltonbf11f982014-07-20 22:06:28 -07003063 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003064 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003065 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3066 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003067 * <p>
3068 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3069 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003070 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003071 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003072 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003073 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003074 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3075 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003076 }
3077
Evan Charltonbf11f982014-07-20 22:06:28 -07003078 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003079 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3080 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3081 * this should never be un-@hide-den.
3082 *
3083 * @hide
3084 */
3085 public void checkImmutable() {}
3086
3087 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003088 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3089 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3090 * that state. This connection should not be used for anything, and no other
3091 * {@code Connection}s should be attempted.
3092 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003093 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003094 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003095 * @return A {@code Connection} which indicates that the underlying connection should
3096 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003097 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003098 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003099 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003100 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003101
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003102 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003103 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003104 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003105 }
3106 }
3107
Santos Cordon823fd3c2014-08-07 18:35:18 -07003108 private final void fireConferenceChanged() {
3109 for (Listener l : mListeners) {
3110 l.onConferenceChanged(this, mConference);
3111 }
3112 }
3113
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003114 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003115 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003116 if (c instanceof Connection) {
3117 Connection connection = (Connection) c;
3118 connection.removeConnectionListener(mConnectionDeathListener);
3119 } else if (c instanceof Conference) {
3120 Conference conference = (Conference) c;
3121 conference.removeListener(mConferenceDeathListener);
3122 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003123 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003124 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003125 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003126
3127 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003128 * Handles a change to extras received from Telecom.
3129 *
3130 * @param extras The new extras.
3131 * @hide
3132 */
3133 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003134 Bundle b = null;
3135 synchronized (mExtrasLock) {
3136 mExtras = extras;
3137 if (mExtras != null) {
3138 b = new Bundle(mExtras);
3139 }
3140 }
3141 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003142 }
3143
3144 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003145 * Notifies listeners that the merge request failed.
3146 *
3147 * @hide
3148 */
3149 protected final void notifyConferenceMergeFailed() {
3150 for (Listener l : mListeners) {
3151 l.onConferenceMergeFailed(this);
3152 }
3153 }
3154
3155 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003156 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003157 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003158 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003159 * @hide
3160 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003161 protected final void updateConferenceParticipants(
3162 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003163 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003164 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003165 }
3166 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003167
3168 /**
3169 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003170 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003171 */
3172 protected void notifyConferenceStarted() {
3173 for (Listener l : mListeners) {
3174 l.onConferenceStarted();
3175 }
3176 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003177
3178 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003179 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3180 * be a part of a conference call.
3181 * @param isConferenceSupported {@code true} if the connection supports being part of a
3182 * conference call, {@code false} otherwise.
3183 * @hide
3184 */
3185 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3186 for (Listener l : mListeners) {
3187 l.onConferenceSupportedChanged(this, isConferenceSupported);
3188 }
3189 }
3190
3191 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303192 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3193 * changed due to an emergency call being redialed.
3194 * @param pHandle The new PhoneAccountHandle for this connection.
3195 * @hide
3196 */
3197 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3198 for (Listener l : mListeners) {
3199 l.onPhoneAccountChanged(this, pHandle);
3200 }
3201 }
3202
3203 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003204 * Sets the {@link PhoneAccountHandle} associated with this connection.
3205 *
3206 * @hide
3207 */
3208 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3209 if (mPhoneAccountHandle != phoneAccountHandle) {
3210 mPhoneAccountHandle = phoneAccountHandle;
3211 notifyPhoneAccountChanged(phoneAccountHandle);
3212 }
3213 }
3214
3215 /**
3216 * Returns the {@link PhoneAccountHandle} associated with this connection.
3217 *
3218 * @hide
3219 */
3220 public PhoneAccountHandle getPhoneAccountHandle() {
3221 return mPhoneAccountHandle;
3222 }
3223
3224 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003225 * Sends an event associated with this {@code Connection} with associated event extras to the
3226 * {@link InCallService}.
3227 * <p>
3228 * Connection events are used to communicate point in time information from a
3229 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3230 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3231 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3232 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3233 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3234 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3235 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3236 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3237 * <p>
3238 * Events are exposed to {@link InCallService} implementations via
3239 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3240 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003241 * 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 -07003242 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3243 * some events altogether.
3244 * <p>
3245 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3246 * conflicts between {@link ConnectionService} implementations. Further, custom
3247 * {@link ConnectionService} implementations shall not re-purpose events in the
3248 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3249 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3250 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3251 * {@code com.example.extra.MY_EXTRA}).
3252 * <p>
3253 * When defining events and the associated extras, it is important to keep their behavior
3254 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3255 * events/extras should me maintained to ensure backwards compatibility with older
3256 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003257 *
3258 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003259 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003260 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003261 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003262 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003263 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003264 }
3265 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003266}