blob: 28e6596ce5bba7087d80456ffbb467160d1129f4 [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 Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070021import android.annotation.SystemApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010022import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080023import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080024import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080025import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080028import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import android.os.Handler;
31import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070032import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080034import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070036import android.os.SystemClock;
Wei Huang7f7f72e2018-05-30 19:21:36 +080037import android.telephony.ServiceState;
38import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070039import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041
Youming Yed6de26e2019-01-30 11:20:35 -080042import com.android.internal.os.SomeArgs;
43import com.android.internal.telecom.IVideoCallback;
44import com.android.internal.telecom.IVideoProvider;
45
Hall Liua549fed2018-02-09 16:40:03 -080046import java.io.FileInputStream;
47import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080048import java.io.IOException;
49import java.io.InputStreamReader;
50import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070051import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070052import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070053import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070055import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070056import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070057import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
59/**
Santos Cordon895d4b82015-06-25 16:41:48 -070060 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
61 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070062 * <p>
63 * Implementations create a custom subclass of {@code Connection} and return it to the framework
64 * as the return value of
65 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
66 * or
67 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
68 * Implementations are then responsible for updating the state of the {@code Connection}, and
69 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
70 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070071 * <p>
72 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
73 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
74 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
75 * {@code Connection} instance.
76 * <p>
77 * Basic call support requires overriding the following methods: {@link #onAnswer()},
78 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
79 * <p>
80 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
81 * {@link #onUnhold()} methods should be overridden to provide hold support for the
82 * {@code Connection}.
83 * <p>
84 * Where a {@code Connection} supports a variation of video calling (e.g. the
85 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
86 * to support answering a call as a video call.
87 * <p>
88 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
89 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
90 * support for pulling the external call.
91 * <p>
92 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
93 * overridden.
94 * <p>
95 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
96 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
97 * for example, call events from a {@link InCallService} are handled,
98 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
99 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
100 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
101 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700102 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700103public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700104
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 /**
106 * The connection is initializing. This is generally the first state for a {@code Connection}
107 * returned by a {@link ConnectionService}.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_INITIALIZING = 0;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * The connection is new and not connected.
113 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 public static final int STATE_NEW = 1;
115
Santos Cordon895d4b82015-06-25 16:41:48 -0700116 /**
117 * An incoming connection is in the ringing state. During this state, the user's ringer or
118 * vibration feature will be activated.
119 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700120 public static final int STATE_RINGING = 2;
121
Santos Cordon895d4b82015-06-25 16:41:48 -0700122 /**
123 * An outgoing connection is in the dialing state. In this state the other party has not yet
124 * answered the call and the user traditionally hears a ringback tone.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_DIALING = 3;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is active. Both parties are connected to the call and can actively communicate.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_ACTIVE = 4;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection is on hold.
135 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700136 public static final int STATE_HOLDING = 5;
137
Santos Cordon895d4b82015-06-25 16:41:48 -0700138 /**
139 * A connection has been disconnected. This is the final state once the user has been
140 * disconnected from a call either locally, remotely or by an error in the service.
141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 public static final int STATE_DISCONNECTED = 6;
143
Santos Cordon895d4b82015-06-25 16:41:48 -0700144 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * The state of an external connection which is in the process of being pulled from a remote
146 * device to the local device.
147 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700148 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700149 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
150 */
151 public static final int STATE_PULLING_CALL = 7;
152
153 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 * Connection can currently be put on hold or unheld. This is distinct from
155 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
156 * it does not at the moment support the function. This can be true while the call is in the
157 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
158 * display a disabled 'hold' button.
159 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800160 public static final int CAPABILITY_HOLD = 0x00000001;
161
162 /** Connection supports the hold feature. */
163 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
164
165 /**
166 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
167 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
168 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
169 * capability allows a merge button to be shown while the conference is in the foreground
170 * of the in-call UI.
171 * <p>
172 * This is only intended for use by a {@link Conference}.
173 */
174 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
175
176 /**
177 * Connections within a conference can be swapped between foreground and background.
178 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
179 * <p>
180 * This is only intended for use by a {@link Conference}.
181 */
182 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
183
184 /**
185 * @hide
186 */
187 public static final int CAPABILITY_UNUSED = 0x00000010;
188
189 /** Connection supports responding via text option. */
190 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
191
192 /** Connection can be muted. */
193 public static final int CAPABILITY_MUTE = 0x00000040;
194
195 /**
196 * Connection supports conference management. This capability only applies to
197 * {@link Conference}s which can have {@link Connection}s as children.
198 */
199 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210
211 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700214 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700218 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800219 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
221
222 /**
223 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
226
227 /**
228 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700229 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700230 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232
233 /**
234 * Connection is able to be separated from its parent {@code Conference}, if any.
235 */
236 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
237
238 /**
239 * Connection is able to be individually disconnected when in a {@code Conference}.
240 */
241 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
242
243 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245 * @hide
246 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 * @hide
252 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254
255 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257 * @hide
258 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260
Tyler Gunn068085b2015-02-06 13:56:52 -0800261 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700262 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800263 * @hide
264 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700265 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800266
Tyler Gunn96d6c402015-03-18 12:39:23 -0700267 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500268 * Speed up audio setup for MT call.
269 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700270 */
271 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800272
Rekha Kumar07366812015-03-24 16:42:31 -0700273 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800275 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
276 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
277 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700278 */
279 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
280
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700281 /**
282 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700283 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700284 */
285 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
286
Tyler Gunnd4091732015-06-29 09:15:37 -0700287 /**
288 * For a conference, indicates the conference will not have child connections.
289 * <p>
290 * An example of a conference with child connections is a GSM conference call, where the radio
291 * retains connections to the individual participants of the conference. Another example is an
292 * IMS conference call where conference event package functionality is supported; in this case
293 * the conference server ensures the radio is aware of the participants in the conference, which
294 * are represented by child connections.
295 * <p>
296 * An example of a conference with no child connections is an IMS conference call with no
297 * conference event package support. Such a conference is represented by the radio as a single
298 * connection to the IMS conference server.
299 * <p>
300 * Indicating whether a conference has children or not is important to help user interfaces
301 * visually represent a conference. A conference with no children, for example, will have the
302 * conference connection shown in the list of calls on a Bluetooth device, where if the
303 * conference has children, only the children will be shown in the list of calls on a Bluetooth
304 * device.
305 * @hide
306 */
307 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
308
Bryce Lee81901682015-08-28 16:38:02 -0700309 /**
310 * Indicates that the connection itself wants to handle any sort of reply response, rather than
311 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700312 */
313 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
314
Tyler Gunnf97a0092016-01-19 15:59:34 -0800315 /**
316 * When set, prevents a video call from being downgraded to an audio-only call.
317 * <p>
318 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
319 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
320 * downgraded from a video call back to a VideoState of
321 * {@link VideoProfile#STATE_AUDIO_ONLY}.
322 * <p>
323 * Intuitively, a call which can be downgraded to audio should also have local and remote
324 * video
325 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
326 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
327 */
328 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
329
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700330 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700331 * When set for an external connection, indicates that this {@code Connection} can be pulled
332 * from a remote device to the current device.
333 * <p>
334 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
335 * is set.
336 */
337 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
338
Pooja Jaind34698d2017-12-28 14:15:31 +0530339 /** Call supports the deflect feature. */
340 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
341
Tyler Gunn720c6642016-03-22 09:02:47 -0700342 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530343 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700344 //**********************************************************************************************
345
346 /**
347 * Indicates that the current device callback number should be shown.
348 *
349 * @hide
350 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700351 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700352
353 /**
354 * Whether the call is a generic conference, where we do not know the precise state of
355 * participants in the conference (eg. on CDMA).
356 *
357 * @hide
358 */
359 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
360
361 /**
362 * Connection is using high definition audio.
363 * @hide
364 */
365 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
366
367 /**
368 * Connection is using WIFI.
369 * @hide
370 */
371 public static final int PROPERTY_WIFI = 1<<3;
372
373 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700374 * When set, indicates that the {@code Connection} does not actually exist locally for the
375 * {@link ConnectionService}.
376 * <p>
377 * Consider, for example, a scenario where a user has two devices with the same phone number.
378 * When a user places a call on one devices, the telephony stack can represent that call on the
379 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700381 * <p>
382 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
383 * external connections. Only those {@link InCallService}s which have the
384 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
385 * manifest will see external connections.
386 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700387 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700388
Brad Ebinger15847072016-05-18 11:08:36 -0700389 /**
390 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
391 */
392 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700393
Hall Liu9f332c72016-07-14 15:37:37 -0700394 /**
395 * Indicates that the connection represents a downgraded IMS conference.
396 * @hide
397 */
398 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
399
Tyler Gunnf5035432017-01-09 09:43:12 -0800400 /**
401 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
402 * {@link ConnectionService}.
403 * <p>
404 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
405 */
406 public static final int PROPERTY_SELF_MANAGED = 1<<7;
407
Hall Liu95d55872017-01-25 17:12:49 -0800408 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800409 * Set by the framework to indicate that a connection has an active RTT session associated with
410 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800411 */
412 public static final int PROPERTY_IS_RTT = 1 << 8;
413
Eric Erfanian62706c52017-12-06 16:27:53 -0800414 /**
415 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000416 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800417 */
418 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
419
Tyler Gunn5bd90852018-09-21 09:37:07 -0700420 /**
421 * Set by the framework to indicate that the network has identified a Connection as an emergency
422 * call.
423 * @hide
424 */
425 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
426
Tyler Gunn96d6c402015-03-18 12:39:23 -0700427 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800428 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700429 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800430
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700431 /**
432 * Connection extra key used to store the last forwarded number associated with the current
433 * connection. Used to communicate to the user interface that the connection was forwarded via
434 * the specified number.
435 */
436 public static final String EXTRA_LAST_FORWARDED_NUMBER =
437 "android.telecom.extra.LAST_FORWARDED_NUMBER";
438
439 /**
440 * Connection extra key used to store a child number associated with the current connection.
441 * Used to communicate to the user interface that the connection was received via
442 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
443 * address.
444 */
445 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
446
447 /**
448 * Connection extra key used to store the subject for an incoming call. The user interface can
449 * query this extra and display its contents for incoming calls. Will only be used if the
450 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
451 */
452 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
453
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800454 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700455 * Boolean connection extra key set on a {@link Connection} in
456 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
457 * current active foreground call to be dropped.
458 */
459 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
460 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
461
462 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700463 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
464 * state to indicate the name of the third-party app which is responsible for the current
465 * foreground call.
466 * <p>
467 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
468 * is able to inform the user that answering the new incoming call will cause a call owned by
469 * another app to be dropped when the incoming call is answered.
470 */
471 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
472 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
473
474 /**
Hall Liu10208662016-06-15 17:55:00 -0700475 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700476 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700477 * @hide
478 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700479 public static final String EXTRA_DISABLE_ADD_CALL =
480 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700481
482 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700483 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
484 * original Connection ID associated with the connection. Used in
485 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
486 * connection/conference added via
487 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
488 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
489 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
490 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
491 * be a way to ensure that we don't add the connection again as a duplicate.
492 * <p>
493 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
494 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
495 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
496 * in a new {@link Connection} which it adds to Telecom via
497 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
498 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
499 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
500 * ID it originally referred to the connection as. Thus Telecom needs to know that the
501 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
502 * @hide
503 */
504 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
505 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
506
507 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700508 * Boolean connection extra key set on the extras passed to
509 * {@link Connection#sendConnectionEvent} which indicates that audio is present
510 * on the RTT call when the extra value is true.
511 */
512 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
513 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
514
515 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800516 * Connection event used to inform Telecom that it should play the on hold tone. This is used
517 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700518 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800519 * @hide
520 */
521 public static final String EVENT_ON_HOLD_TONE_START =
522 "android.telecom.event.ON_HOLD_TONE_START";
523
524 /**
525 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
526 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700527 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800528 * @hide
529 */
530 public static final String EVENT_ON_HOLD_TONE_END =
531 "android.telecom.event.ON_HOLD_TONE_END";
532
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700533 /**
534 * Connection event used to inform {@link InCallService}s when pulling of an external call has
535 * failed. The user interface should inform the user of the error.
536 * <p>
537 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
538 * API is called on a {@link Call} with the properties
539 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
540 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
541 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700542 * <p>
543 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
544 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700545 */
546 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
547
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700548 /**
549 * Connection event used to inform {@link InCallService}s when the merging of two calls has
550 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700551 * <p>
552 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
553 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700554 */
555 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
556
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700557 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700558 * Connection event used to inform Telecom when a hold operation on a call has failed.
559 * Not intended for use by the UI at this time.
560 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
561 * expected to be null when this connection event is used.
562 * @hide
563 */
564 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
565
566 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700567 * Connection event used to inform {@link InCallService}s when the process of merging a
568 * Connection into a conference has begun.
569 * <p>
570 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
571 * expected to be null when this connection event is used.
572 * @hide
573 */
574 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
575
576 /**
577 * Connection event used to inform {@link InCallService}s when the process of merging a
578 * Connection into a conference has completed.
579 * <p>
580 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
581 * expected to be null when this connection event is used.
582 * @hide
583 */
584 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
585
586 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700587 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
588 * the remote party.
589 * <p>
590 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
591 * call is being held locally on the device. When a capable {@link ConnectionService} receives
592 * signalling to indicate that the remote party has put the call on hold, it can send this
593 * connection event.
594 * @hide
595 */
596 public static final String EVENT_CALL_REMOTELY_HELD =
597 "android.telecom.event.CALL_REMOTELY_HELD";
598
599 /**
600 * Connection event used to inform {@link InCallService}s when a call which was remotely held
601 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
602 * <p>
603 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
604 * call is being held locally on the device. When a capable {@link ConnectionService} receives
605 * signalling to indicate that the remote party has taken the call off hold, it can send this
606 * connection event.
607 * @hide
608 */
609 public static final String EVENT_CALL_REMOTELY_UNHELD =
610 "android.telecom.event.CALL_REMOTELY_UNHELD";
611
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700612 /**
613 * Connection event used to inform an {@link InCallService} which initiated a call handover via
614 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
615 * successfully completed.
616 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700617 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
618 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700619 */
620 public static final String EVENT_HANDOVER_COMPLETE =
621 "android.telecom.event.HANDOVER_COMPLETE";
622
623 /**
624 * Connection event used to inform an {@link InCallService} which initiated a call handover via
625 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
626 * to complete.
627 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700628 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
629 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700630 */
631 public static final String EVENT_HANDOVER_FAILED =
632 "android.telecom.event.HANDOVER_FAILED";
633
shilub7ec9a02018-11-09 15:52:04 -0800634 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000635 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800636 */
637 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
638
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700639 /**
640 * Connection event used to inform an {@link InCallService} that the RTT audio indication
641 * has changed.
642 */
643 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
644 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
645
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700646 // Flag controlling whether PII is emitted into the logs
647 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
648
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 /**
650 * Whether the given capabilities support the specified capability.
651 *
652 * @param capabilities A capability bit field.
653 * @param capability The capability to check capabilities for.
654 * @return Whether the specified capability is supported.
655 * @hide
656 */
657 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800658 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800659 }
660
661 /**
662 * Whether the capabilities of this {@code Connection} supports the specified capability.
663 *
664 * @param capability The capability to check capabilities for.
665 * @return Whether the specified capability is supported.
666 * @hide
667 */
668 public boolean can(int capability) {
669 return can(mConnectionCapabilities, capability);
670 }
671
672 /**
673 * Removes the specified capability from the set of capabilities of this {@code Connection}.
674 *
675 * @param capability The capability to remove from the set.
676 * @hide
677 */
678 public void removeCapability(int capability) {
679 mConnectionCapabilities &= ~capability;
680 }
681
682 /**
683 * Adds the specified capability to the set of capabilities of this {@code Connection}.
684 *
685 * @param capability The capability to add to the set.
686 * @hide
687 */
688 public void addCapability(int capability) {
689 mConnectionCapabilities |= capability;
690 }
691
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700692 /**
693 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
694 *
695 * @param capabilities A capability bit field.
696 * @return A human readable string representation.
697 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800698 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 return capabilitiesToStringInternal(capabilities, true /* isLong */);
700 }
701
702 /**
703 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
704 * string.
705 *
706 * @param capabilities A capability bit field.
707 * @return A human readable string representation.
708 * @hide
709 */
710 public static String capabilitiesToStringShort(int capabilities) {
711 return capabilitiesToStringInternal(capabilities, false /* isLong */);
712 }
713
714 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800715 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700716 builder.append("[");
717 if (isLong) {
718 builder.append("Capabilities:");
719 }
720
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800721 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700722 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800723 }
724 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 }
727 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800729 }
730 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800732 }
733 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 }
736 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 }
739 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700742 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700744 }
745 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700747 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700748 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700751 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700752 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700753 }
754 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700755 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700756 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700757 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700758 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800759 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800760 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700761 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800762 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500763 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700764 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500765 }
Rekha Kumar07366812015-03-24 16:42:31 -0700766 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700767 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700768 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700769 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700770 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700771 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700772 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700773 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700774 }
Bryce Lee81901682015-08-28 16:38:02 -0700775 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700776 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700777 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700778 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700780 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530781 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
782 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
783 }
Bryce Lee81901682015-08-28 16:38:02 -0700784
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800785 builder.append("]");
786 return builder.toString();
787 }
788
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700789 /**
790 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
791 *
792 * @param properties A property bit field.
793 * @return A human readable string representation.
794 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700795 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700796 return propertiesToStringInternal(properties, true /* isLong */);
797 }
798
799 /**
800 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
801 *
802 * @param properties A property bit field.
803 * @return A human readable string representation.
804 * @hide
805 */
806 public static String propertiesToStringShort(int properties) {
807 return propertiesToStringInternal(properties, false /* isLong */);
808 }
809
810 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700811 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700812 builder.append("[");
813 if (isLong) {
814 builder.append("Properties:");
815 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700816
Tyler Gunnf5035432017-01-09 09:43:12 -0800817 if (can(properties, PROPERTY_SELF_MANAGED)) {
818 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
819 }
820
Hall Liu25c7c4d2016-08-30 13:41:02 -0700821 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
822 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700823 }
824
825 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700826 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700827 }
828
829 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700830 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700831 }
832
833 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700834 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700835 }
836
837 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700838 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700839 }
840
Brad Ebinger15847072016-05-18 11:08:36 -0700841 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700842 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700843 }
844
Hall Liud4d2a8a2018-01-29 17:22:02 -0800845 if (can(properties, PROPERTY_IS_RTT)) {
846 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
847 }
848
Tyler Gunn5bd90852018-09-21 09:37:07 -0700849 if (can(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
850 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
851 }
852
Tyler Gunn720c6642016-03-22 09:02:47 -0700853 builder.append("]");
854 return builder.toString();
855 }
856
Sailesh Nepal091768c2014-06-30 15:15:23 -0700857 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700858 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700859 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700860 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700861 public void onCallerDisplayNameChanged(
862 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700863 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700864 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700865 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800866 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700867 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700868 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800869 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700870 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800871 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 public void onVideoProviderChanged(
873 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700874 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
875 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800876 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700877 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700878 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700879 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800880 public void onConferenceParticipantsChanged(Connection c,
881 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800882 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700883 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700884 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700885 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700886 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700887 /** @hide */
888 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800889 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800890 public void onRttInitiationSuccess(Connection c) {}
891 public void onRttInitiationFailure(Connection c, int reason) {}
892 public void onRttSessionRemotelyTerminated(Connection c) {}
893 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530894 /** @hide */
895 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800896 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700897 }
898
Tyler Gunnb702ef82015-05-29 11:51:53 -0700899 /**
Hall Liu95d55872017-01-25 17:12:49 -0800900 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800901 */
902 public static final class RttTextStream {
903 private static final int READ_BUFFER_SIZE = 1000;
904 private final InputStreamReader mPipeFromInCall;
905 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800906 private final ParcelFileDescriptor mFdFromInCall;
907 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700908
909 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800910 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
911
912 /**
913 * @hide
914 */
915 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800916 mFdFromInCall = fromInCall;
917 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700918 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700919
920 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800921 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700922 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800923 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800924 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800925 }
926
927 /**
928 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
929 * RTT transmits text in real-time, this method should be called as often as text snippets
930 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800931 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800932 * This method is not thread-safe -- calling it from multiple threads simultaneously may
933 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800934 *
Hall Liu95d55872017-01-25 17:12:49 -0800935 * @param input The message to send to the in-call app.
936 */
937 public void write(String input) throws IOException {
938 mPipeToInCall.write(input);
939 mPipeToInCall.flush();
940 }
941
942
943 /**
944 * Reads a string from the in-call app, blocking if there is no data available. Returns
945 * {@code null} if the RTT conversation has been terminated and there is no further data
946 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800947 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800948 * This method is not thread-safe -- calling it from multiple threads simultaneously may
949 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800950 *
Hall Liu95d55872017-01-25 17:12:49 -0800951 * @return A string containing text entered by the user, or {@code null} if the
952 * conversation has been terminated or if there was an error while reading.
953 */
Hall Liuffa4a812017-03-02 16:11:00 -0800954 public String read() throws IOException {
955 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
956 if (numRead < 0) {
957 return null;
958 }
959 return new String(mReadBuffer, 0, numRead);
960 }
961
962 /**
963 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
964 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800965 *
Hall Liuffa4a812017-03-02 16:11:00 -0800966 * @return A string containing text entered by the user, or {@code null} if the user has
967 * not entered any new text yet.
968 */
969 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700970 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800971 return read();
972 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800973 return null;
974 }
975 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800976
977 /** @hide */
978 public ParcelFileDescriptor getFdFromInCall() {
979 return mFdFromInCall;
980 }
981
982 /** @hide */
983 public ParcelFileDescriptor getFdToInCall() {
984 return mFdToInCall;
985 }
986 }
987
988 /**
989 * Provides constants to represent the results of responses to session modify requests sent via
990 * {@link Call#sendRttRequest()}
991 */
992 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700993 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800994 /**
995 * Session modify request was successful.
996 */
997 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
998
999 /**
1000 * Session modify request failed.
1001 */
1002 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1003
1004 /**
1005 * Session modify request ignored due to invalid parameters.
1006 */
1007 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1008
1009 /**
1010 * Session modify request timed out.
1011 */
1012 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1013
1014 /**
1015 * Session modify request rejected by remote user.
1016 */
1017 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001018 }
1019
1020 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * Provides a means of controlling the video session associated with a {@link Connection}.
1022 * <p>
1023 * Implementations create a custom subclass of {@link VideoProvider} and the
1024 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1025 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1026 * should set the {@link VideoProvider}.
1027 * <p>
1028 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1029 * {@link InCallService} implementations to issue requests related to the video session;
1030 * it provides a means for the {@link ConnectionService} to report events and information
1031 * related to the video session to Telecom and the {@link InCallService} implementations.
1032 * <p>
1033 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1034 * {@link android.telecom.InCallService.VideoCall}.
1035 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001037 /**
1038 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001039 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001040 */
1041 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001042
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001044 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1045 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001046 */
1047 public static final int SESSION_EVENT_RX_RESUME = 2;
1048
1049 /**
1050 * Video transmission has begun. This occurs after a negotiated start of video transmission
1051 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001052 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 */
1054 public static final int SESSION_EVENT_TX_START = 3;
1055
1056 /**
1057 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1058 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001059 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 */
1061 public static final int SESSION_EVENT_TX_STOP = 4;
1062
1063 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001064 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001065 * this as a cue to inform the user the camera is not available.
1066 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001067 */
1068 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1069
1070 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001071 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001072 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001073 * the camera has become available again.
1074 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075 */
1076 public static final int SESSION_EVENT_CAMERA_READY = 6;
1077
1078 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001079 * Session event raised by Telecom when
1080 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1081 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1082 * @see #handleCallSessionEvent(int)
1083 */
1084 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1085
1086 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001087 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001088 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 */
1090 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1091
1092 /**
1093 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001094 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001095 */
1096 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1097
1098 /**
1099 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001100 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 */
1102 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1103
Rekha Kumar07366812015-03-24 16:42:31 -07001104 /**
1105 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001106 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001107 */
1108 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1109
1110 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001111 * Session modify request rejected by remote user.
1112 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001113 */
1114 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1115
Tyler Gunn75958422015-04-15 14:23:42 -07001116 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001117 private static final int MSG_SET_CAMERA = 2;
1118 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1119 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1120 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1121 private static final int MSG_SET_ZOOM = 6;
1122 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1123 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1124 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001125 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001127 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001129 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1130 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1131 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1132 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1133 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1134 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001135 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1136 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001137 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1138
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001139 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001141
1142 /**
1143 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001144 *
1145 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1146 * load factor before resizing, 1 means we only expect a single thread to
1147 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001148 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001149 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1150 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151
1152 /**
1153 * Default handler used to consolidate binder method calls onto a single thread.
1154 */
1155 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001156 public VideoProviderHandler() {
1157 super();
1158 }
1159
1160 public VideoProviderHandler(Looper looper) {
1161 super(looper);
1162 }
1163
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 @Override
1165 public void handleMessage(Message msg) {
1166 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001167 case MSG_ADD_VIDEO_CALLBACK: {
1168 IBinder binder = (IBinder) msg.obj;
1169 IVideoCallback callback = IVideoCallback.Stub
1170 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001171 if (callback == null) {
1172 Log.w(this, "addVideoProvider - skipped; callback is null.");
1173 break;
1174 }
1175
Tyler Gunn75958422015-04-15 14:23:42 -07001176 if (mVideoCallbacks.containsKey(binder)) {
1177 Log.i(this, "addVideoProvider - skipped; already present.");
1178 break;
1179 }
1180 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001181 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001182 }
1183 case MSG_REMOVE_VIDEO_CALLBACK: {
1184 IBinder binder = (IBinder) msg.obj;
1185 IVideoCallback callback = IVideoCallback.Stub
1186 .asInterface((IBinder) msg.obj);
1187 if (!mVideoCallbacks.containsKey(binder)) {
1188 Log.i(this, "removeVideoProvider - skipped; not present.");
1189 break;
1190 }
1191 mVideoCallbacks.remove(binder);
1192 break;
1193 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001194 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001195 {
1196 SomeArgs args = (SomeArgs) msg.obj;
1197 try {
1198 onSetCamera((String) args.arg1);
1199 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001200 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001201 } finally {
1202 args.recycle();
1203 }
1204 }
1205 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001206 case MSG_SET_PREVIEW_SURFACE:
1207 onSetPreviewSurface((Surface) msg.obj);
1208 break;
1209 case MSG_SET_DISPLAY_SURFACE:
1210 onSetDisplaySurface((Surface) msg.obj);
1211 break;
1212 case MSG_SET_DEVICE_ORIENTATION:
1213 onSetDeviceOrientation(msg.arg1);
1214 break;
1215 case MSG_SET_ZOOM:
1216 onSetZoom((Float) msg.obj);
1217 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001218 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1219 SomeArgs args = (SomeArgs) msg.obj;
1220 try {
1221 onSendSessionModifyRequest((VideoProfile) args.arg1,
1222 (VideoProfile) args.arg2);
1223 } finally {
1224 args.recycle();
1225 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001226 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001227 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1229 onSendSessionModifyResponse((VideoProfile) msg.obj);
1230 break;
1231 case MSG_REQUEST_CAMERA_CAPABILITIES:
1232 onRequestCameraCapabilities();
1233 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001234 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1235 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001236 break;
1237 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001238 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001239 break;
1240 default:
1241 break;
1242 }
1243 }
1244 }
1245
1246 /**
1247 * IVideoProvider stub implementation.
1248 */
1249 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001250 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001251 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001252 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1253 }
1254
1255 public void removeVideoCallback(IBinder videoCallbackBinder) {
1256 mMessageHandler.obtainMessage(
1257 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 }
1259
Tyler Gunn159f35c2017-03-02 09:28:37 -08001260 public void setCamera(String cameraId, String callingPackageName,
1261 int targetSdkVersion) {
1262
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001263 SomeArgs args = SomeArgs.obtain();
1264 args.arg1 = cameraId;
1265 // Propagate the calling package; originally determined in
1266 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1267 // process.
1268 args.arg2 = callingPackageName;
1269 // Pass along the uid and pid of the calling app; this gets lost when we put the
1270 // message onto the handler. These are required for Telecom to perform a permission
1271 // check to see if the calling app is able to use the camera.
1272 args.argi1 = Binder.getCallingUid();
1273 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001274 // Pass along the target SDK version of the calling InCallService. This is used to
1275 // maintain backwards compatibility of the API for older callers.
1276 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001277 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 }
1279
1280 public void setPreviewSurface(Surface surface) {
1281 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1282 }
1283
1284 public void setDisplaySurface(Surface surface) {
1285 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1286 }
1287
1288 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001289 mMessageHandler.obtainMessage(
1290 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 }
1292
1293 public void setZoom(float value) {
1294 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1295 }
1296
Tyler Gunn45382162015-05-06 08:52:27 -07001297 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1298 SomeArgs args = SomeArgs.obtain();
1299 args.arg1 = fromProfile;
1300 args.arg2 = toProfile;
1301 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 }
1303
1304 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1305 mMessageHandler.obtainMessage(
1306 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1307 }
1308
1309 public void requestCameraCapabilities() {
1310 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1311 }
1312
1313 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001314 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 }
1316
Yorke Lee32f24732015-05-12 16:18:03 -07001317 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1319 }
1320 }
1321
1322 public VideoProvider() {
1323 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001324 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001325 }
1326
1327 /**
1328 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1329 *
1330 * @param looper The looper.
1331 * @hide
1332 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001333 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001334 public VideoProvider(Looper looper) {
1335 mBinder = new VideoProvider.VideoProviderBinder();
1336 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 }
1338
1339 /**
1340 * Returns binder object which can be used across IPC methods.
1341 * @hide
1342 */
1343 public final IVideoProvider getInterface() {
1344 return mBinder;
1345 }
1346
1347 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * Sets the camera to be used for the outgoing video.
1349 * <p>
1350 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1351 * camera via
1352 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1353 * <p>
1354 * Sent from the {@link InCallService} via
1355 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001357 * @param cameraId The id of the camera (use ids as reported by
1358 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001359 */
1360 public abstract void onSetCamera(String cameraId);
1361
1362 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001363 * Sets the camera to be used for the outgoing video.
1364 * <p>
1365 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1366 * camera via
1367 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1368 * <p>
1369 * This prototype is used internally to ensure that the calling package name, UID and PID
1370 * are sent to Telecom so that can perform a camera permission check on the caller.
1371 * <p>
1372 * Sent from the {@link InCallService} via
1373 * {@link InCallService.VideoCall#setCamera(String)}.
1374 *
1375 * @param cameraId The id of the camera (use ids as reported by
1376 * {@link CameraManager#getCameraIdList()}).
1377 * @param callingPackageName The AppOpps package name of the caller.
1378 * @param callingUid The UID of the caller.
1379 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001380 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001381 * @hide
1382 */
1383 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001384 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001385
1386 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001387 * Sets the surface to be used for displaying a preview of what the user's camera is
1388 * currently capturing. When video transmission is enabled, this is the video signal which
1389 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001390 * <p>
1391 * Sent from the {@link InCallService} via
1392 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001394 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 */
1396 public abstract void onSetPreviewSurface(Surface surface);
1397
1398 /**
1399 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001400 * <p>
1401 * Sent from the {@link InCallService} via
1402 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001404 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 */
1406 public abstract void onSetDisplaySurface(Surface surface);
1407
1408 /**
1409 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1410 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001411 * <p>
1412 * Sent from the {@link InCallService} via
1413 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414 *
1415 * @param rotation The device orientation, in degrees.
1416 */
1417 public abstract void onSetDeviceOrientation(int rotation);
1418
1419 /**
1420 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001421 * <p>
1422 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001423 *
1424 * @param value The camera zoom ratio.
1425 */
1426 public abstract void onSetZoom(float value);
1427
1428 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001429 * Issues a request to modify the properties of the current video session.
1430 * <p>
1431 * Example scenarios include: requesting an audio-only call to be upgraded to a
1432 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1433 * when the {@link InCallService} is no longer the foreground application.
1434 * <p>
1435 * If the {@link VideoProvider} determines a request to be invalid, it should call
1436 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1437 * invalid request back to the {@link InCallService}.
1438 * <p>
1439 * Where a request requires confirmation from the user of the peer device, the
1440 * {@link VideoProvider} must communicate the request to the peer device and handle the
1441 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1442 * is used to inform the {@link InCallService} of the result of the request.
1443 * <p>
1444 * Sent from the {@link InCallService} via
1445 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001446 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001447 * @param fromProfile The video profile prior to the request.
1448 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 */
Tyler Gunn45382162015-05-06 08:52:27 -07001450 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1451 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452
Tyler Gunnb702ef82015-05-29 11:51:53 -07001453 /**
1454 * Provides a response to a request to change the current video session properties.
1455 * <p>
1456 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1457 * video call, could decline the request and keep the call as audio-only.
1458 * In such a scenario, the {@code responseProfile} would have a video state of
1459 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1460 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1461 * <p>
1462 * Sent from the {@link InCallService} via
1463 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1464 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1465 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001467 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 */
1469 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1470
1471 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001472 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1473 * <p>
1474 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1475 * camera via
1476 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1477 * <p>
1478 * Sent from the {@link InCallService} via
1479 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 */
1481 public abstract void onRequestCameraCapabilities();
1482
1483 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001484 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1485 * video component of the current {@link Connection}.
1486 * <p>
1487 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1488 * via {@link VideoProvider#setCallDataUsage(long)}.
1489 * <p>
1490 * Sent from the {@link InCallService} via
1491 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001493 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001494
1495 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001496 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1497 * the peer device when the video signal is paused.
1498 * <p>
1499 * Sent from the {@link InCallService} via
1500 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001501 *
1502 * @param uri URI of image to display.
1503 */
Yorke Lee32f24732015-05-12 16:18:03 -07001504 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001505
1506 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001507 * Used to inform listening {@link InCallService} implementations when the
1508 * {@link VideoProvider} receives a session modification request.
1509 * <p>
1510 * Received by the {@link InCallService} via
1511 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001513 * @param videoProfile The requested video profile.
1514 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 */
1516 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001517 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001518 for (IVideoCallback callback : mVideoCallbacks.values()) {
1519 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001520 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001521 } catch (RemoteException ignored) {
1522 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001523 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001524 }
1525 }
1526 }
1527
1528 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001529 * Used to inform listening {@link InCallService} implementations when the
1530 * {@link VideoProvider} receives a response to a session modification request.
1531 * <p>
1532 * Received by the {@link InCallService} via
1533 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1534 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001535 *
1536 * @param status Status of the session modify request. Valid values are
1537 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1538 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001539 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1540 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1541 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1542 * @param requestedProfile The original request which was sent to the peer device.
1543 * @param responseProfile The actual profile changes agreed to by the peer device.
1544 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 */
1546 public void receiveSessionModifyResponse(int status,
1547 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001548 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001549 for (IVideoCallback callback : mVideoCallbacks.values()) {
1550 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001551 callback.receiveSessionModifyResponse(status, requestedProfile,
1552 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001553 } catch (RemoteException ignored) {
1554 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001555 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 }
1557 }
1558 }
1559
1560 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001561 * Used to inform listening {@link InCallService} implementations when the
1562 * {@link VideoProvider} reports a call session event.
1563 * <p>
1564 * Received by the {@link InCallService} via
1565 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001567 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1568 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1569 * {@link VideoProvider#SESSION_EVENT_TX_START},
1570 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1571 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001572 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1573 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001574 */
1575 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001576 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001577 for (IVideoCallback callback : mVideoCallbacks.values()) {
1578 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001579 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001580 } catch (RemoteException ignored) {
1581 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001582 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001583 }
1584 }
1585 }
1586
1587 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001588 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1589 * peer's video have changed.
1590 * <p>
1591 * This could occur if, for example, the peer rotates their device, changing the aspect
1592 * ratio of the video, or if the user switches between the back and front cameras.
1593 * <p>
1594 * Received by the {@link InCallService} via
1595 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001596 *
1597 * @param width The updated peer video width.
1598 * @param height The updated peer video height.
1599 */
1600 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001601 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001602 for (IVideoCallback callback : mVideoCallbacks.values()) {
1603 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001604 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001605 } catch (RemoteException ignored) {
1606 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001607 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001608 }
1609 }
1610 }
1611
1612 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001613 * Used to inform listening {@link InCallService} implementations when the data usage of the
1614 * video associated with the current {@link Connection} has changed.
1615 * <p>
1616 * This could be in response to a preview request via
1617 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001618 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1619 * 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 -07001620 * <p>
1621 * Received by the {@link InCallService} via
1622 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001624 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1625 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001626 */
Yorke Lee32f24732015-05-12 16:18:03 -07001627 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001628 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001629 for (IVideoCallback callback : mVideoCallbacks.values()) {
1630 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001631 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001632 } catch (RemoteException ignored) {
1633 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001634 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001635 }
1636 }
1637 }
1638
1639 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001640 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001642 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001643 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1644 * @hide
1645 */
1646 public void changeCallDataUsage(long dataUsage) {
1647 setCallDataUsage(dataUsage);
1648 }
1649
1650 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001651 * Used to inform listening {@link InCallService} implementations when the capabilities of
1652 * the current camera have changed.
1653 * <p>
1654 * The {@link VideoProvider} should call this in response to
1655 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1656 * changed via {@link VideoProvider#onSetCamera(String)}.
1657 * <p>
1658 * Received by the {@link InCallService} via
1659 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1660 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001661 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001662 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001663 */
Yorke Lee400470f2015-05-12 13:31:25 -07001664 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001665 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001666 for (IVideoCallback callback : mVideoCallbacks.values()) {
1667 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001668 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001669 } catch (RemoteException ignored) {
1670 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001671 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001672 }
1673 }
1674 }
Rekha Kumar07366812015-03-24 16:42:31 -07001675
1676 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001677 * Used to inform listening {@link InCallService} implementations when the video quality
1678 * of the call has changed.
1679 * <p>
1680 * Received by the {@link InCallService} via
1681 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001682 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001683 * @param videoQuality The updated video quality. Valid values:
1684 * {@link VideoProfile#QUALITY_HIGH},
1685 * {@link VideoProfile#QUALITY_MEDIUM},
1686 * {@link VideoProfile#QUALITY_LOW},
1687 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001688 */
1689 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001690 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001691 for (IVideoCallback callback : mVideoCallbacks.values()) {
1692 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001693 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001694 } catch (RemoteException ignored) {
1695 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001696 }
Rekha Kumar07366812015-03-24 16:42:31 -07001697 }
1698 }
1699 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001700
1701 /**
1702 * Returns a string representation of a call session event.
1703 *
1704 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1705 * @return String representation of the call session event.
1706 * @hide
1707 */
1708 public static String sessionEventToString(int event) {
1709 switch (event) {
1710 case SESSION_EVENT_CAMERA_FAILURE:
1711 return SESSION_EVENT_CAMERA_FAILURE_STR;
1712 case SESSION_EVENT_CAMERA_READY:
1713 return SESSION_EVENT_CAMERA_READY_STR;
1714 case SESSION_EVENT_RX_PAUSE:
1715 return SESSION_EVENT_RX_PAUSE_STR;
1716 case SESSION_EVENT_RX_RESUME:
1717 return SESSION_EVENT_RX_RESUME_STR;
1718 case SESSION_EVENT_TX_START:
1719 return SESSION_EVENT_TX_START_STR;
1720 case SESSION_EVENT_TX_STOP:
1721 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001722 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1723 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001724 default:
1725 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1726 }
1727 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001728 }
1729
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001730 private final Listener mConnectionDeathListener = new Listener() {
1731 @Override
1732 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001733 if (mConferenceables.remove(c)) {
1734 fireOnConferenceableConnectionsChanged();
1735 }
1736 }
1737 };
1738
1739 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1740 @Override
1741 public void onDestroyed(Conference c) {
1742 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 fireOnConferenceableConnectionsChanged();
1744 }
1745 }
1746 };
1747
Jay Shrauner229e3822014-08-15 09:23:07 -07001748 /**
1749 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1750 * load factor before resizing, 1 means we only expect a single thread to
1751 * access the map so make only a single shard
1752 */
1753 private final Set<Listener> mListeners = Collections.newSetFromMap(
1754 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001755 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1756 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001757 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001758
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001759 // The internal telecom call ID associated with this connection.
1760 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001761 // The PhoneAccountHandle associated with this connection.
1762 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001763 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001764 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001765 private Uri mAddress;
1766 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001767 private String mCallerDisplayName;
1768 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001769 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001770 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001771 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001772 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001773 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001774 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001775 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001776 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001777 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001778 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001779 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001780 private Conference mConference;
1781 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001782 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001783 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001784
1785 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001786 * Tracks the key set for the extras bundle provided on the last invocation of
1787 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1788 * keys which were set previously but are no longer present in the replacement Bundle.
1789 */
1790 private Set<String> mPreviousExtraKeys;
1791
1792 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001793 * Create a new Connection.
1794 */
Santos Cordonf2951102014-07-20 19:06:29 -07001795 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001796
1797 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001798 * Returns the Telecom internal call ID associated with this connection. Should only be used
1799 * for debugging and tracing purposes.
1800 *
1801 * @return The Telecom call ID.
1802 * @hide
1803 */
1804 public final String getTelecomCallId() {
1805 return mTelecomCallId;
1806 }
1807
1808 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001809 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001810 */
Andrew Lee100e2932014-09-08 15:34:24 -07001811 public final Uri getAddress() {
1812 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001813 }
1814
1815 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001816 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001817 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001818 */
Andrew Lee100e2932014-09-08 15:34:24 -07001819 public final int getAddressPresentation() {
1820 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001821 }
1822
1823 /**
1824 * @return The caller display name (CNAP).
1825 */
1826 public final String getCallerDisplayName() {
1827 return mCallerDisplayName;
1828 }
1829
1830 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001831 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001832 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001833 */
1834 public final int getCallerDisplayNamePresentation() {
1835 return mCallerDisplayNamePresentation;
1836 }
1837
1838 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001839 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001840 */
1841 public final int getState() {
1842 return mState;
1843 }
1844
1845 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001846 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001847 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1848 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1849 * {@link VideoProfile#STATE_TX_ENABLED},
1850 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001851 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001852 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001853 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001854 */
1855 public final int getVideoState() {
1856 return mVideoState;
1857 }
1858
1859 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001860 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001861 * being routed by the system. This is {@code null} if this Connection
1862 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001863 * @deprecated Use {@link #getCallAudioState()} instead.
1864 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001865 */
Yorke Lee4af59352015-05-13 14:14:54 -07001866 @SystemApi
1867 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001868 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001869 if (mCallAudioState == null) {
1870 return null;
1871 }
Yorke Lee4af59352015-05-13 14:14:54 -07001872 return new AudioState(mCallAudioState);
1873 }
1874
1875 /**
1876 * @return The audio state of the connection, describing how its audio is currently
1877 * being routed by the system. This is {@code null} if this Connection
1878 * does not directly know about its audio state.
1879 */
1880 public final CallAudioState getCallAudioState() {
1881 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 }
1883
1884 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001885 * @return The conference that this connection is a part of. Null if it is not part of any
1886 * conference.
1887 */
1888 public final Conference getConference() {
1889 return mConference;
1890 }
1891
1892 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001893 * Returns whether this connection is requesting that the system play a ringback tone
1894 * on its behalf.
1895 */
Andrew Lee100e2932014-09-08 15:34:24 -07001896 public final boolean isRingbackRequested() {
1897 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001898 }
1899
1900 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001901 * @return True if the connection's audio mode is VOIP.
1902 */
1903 public final boolean getAudioModeIsVoip() {
1904 return mAudioModeIsVoip;
1905 }
1906
1907 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001908 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1909 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1910 * start time of the conference.
1911 *
1912 * @return The time at which the {@code Connnection} was connected.
1913 *
1914 * @hide
1915 */
1916 public final long getConnectTimeMillis() {
1917 return mConnectTimeMillis;
1918 }
1919
1920 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001921 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1922 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1923 * start time of the conference.
1924 *
1925 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1926 * changes do not impact the call duration.
1927 *
1928 * @return The time at which the {@link Connection} was connected.
1929 *
1930 * @hide
1931 */
1932 public final long getConnectElapsedTimeMillis() {
1933 return mConnectElapsedTimeMillis;
1934 }
1935
1936 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001937 * Returns RIL voice radio technology used for current connection.
1938 *
1939 * @return the RIL voice radio technology used for current connection,
1940 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1941 *
1942 * @hide
1943 */
1944 public final @ServiceState.RilRadioTechnology int getCallRadioTech() {
1945 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1946 Bundle extras = getExtras();
1947 if (extras != null) {
1948 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1949 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1950 }
1951 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1952 }
1953
1954 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001955 * @return The status hints for this connection.
1956 */
1957 public final StatusHints getStatusHints() {
1958 return mStatusHints;
1959 }
1960
1961 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001962 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001963 * <p>
1964 * Extras should be updated using {@link #putExtras(Bundle)}.
1965 * <p>
1966 * Telecom or an {@link InCallService} can also update the extras via
1967 * {@link android.telecom.Call#putExtras(Bundle)}, and
1968 * {@link Call#removeExtras(List)}.
1969 * <p>
1970 * The connection is notified of changes to the extras made by Telecom or an
1971 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001972 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001973 * @return The extras associated with this connection.
1974 */
1975 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001976 Bundle extras = null;
1977 synchronized (mExtrasLock) {
1978 if (mExtras != null) {
1979 extras = new Bundle(mExtras);
1980 }
1981 }
1982 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001983 }
1984
1985 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001986 * Assign a listener to be notified of state changes.
1987 *
1988 * @param l A listener.
1989 * @return This Connection.
1990 *
1991 * @hide
1992 */
1993 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001994 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001995 return this;
1996 }
1997
1998 /**
1999 * Remove a previously assigned listener that was being notified of state changes.
2000 *
2001 * @param l A Listener.
2002 * @return This Connection.
2003 *
2004 * @hide
2005 */
2006 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002007 if (l != null) {
2008 mListeners.remove(l);
2009 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002010 return this;
2011 }
2012
2013 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002014 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002015 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002016 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002017 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002018 }
2019
2020 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002021 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2022 * ONLY for debugging purposes.
2023 *
2024 * @param callId The telecom call ID.
2025 * @hide
2026 */
2027 public void setTelecomCallId(String callId) {
2028 mTelecomCallId = callId;
2029 }
2030
2031 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002032 * Inform this Connection that the state of its audio output has been changed externally.
2033 *
2034 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002035 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002036 */
Yorke Lee4af59352015-05-13 14:14:54 -07002037 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002038 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002039 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002040 mCallAudioState = state;
2041 onAudioStateChanged(getAudioState());
2042 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002043 }
2044
2045 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002046 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047 * @return A string representation of the value.
2048 */
2049 public static String stateToString(int state) {
2050 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002051 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002052 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002053 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002054 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002055 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002056 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002057 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002058 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002059 case STATE_PULLING_CALL:
2060 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002061 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002062 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002063 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002064 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002065 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002066 return "DISCONNECTED";
2067 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002068 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002069 return "UNKNOWN";
2070 }
2071 }
2072
2073 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002074 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002075 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002076 public final int getConnectionCapabilities() {
2077 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002078 }
2079
2080 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002081 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2082 */
2083 public final int getConnectionProperties() {
2084 return mConnectionProperties;
2085 }
2086
2087 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002088 * Returns the connection's supported audio routes.
2089 *
2090 * @hide
2091 */
2092 public final int getSupportedAudioRoutes() {
2093 return mSupportedAudioRoutes;
2094 }
2095
2096 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002097 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098 *
Andrew Lee100e2932014-09-08 15:34:24 -07002099 * @param address The new address.
2100 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002101 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002102 */
Andrew Lee100e2932014-09-08 15:34:24 -07002103 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002104 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002105 Log.d(this, "setAddress %s", address);
2106 mAddress = address;
2107 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002108 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002109 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002110 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111 }
2112
2113 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002114 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002115 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002116 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002117 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002118 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002119 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002120 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002121 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002122 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002123 mCallerDisplayName = callerDisplayName;
2124 mCallerDisplayNamePresentation = presentation;
2125 for (Listener l : mListeners) {
2126 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2127 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002128 }
2129
2130 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002131 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002132 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2133 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2134 * {@link VideoProfile#STATE_TX_ENABLED},
2135 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002136 *
2137 * @param videoState The new video state.
2138 */
2139 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002141 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002142 mVideoState = videoState;
2143 for (Listener l : mListeners) {
2144 l.onVideoStateChanged(this, mVideoState);
2145 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002146 }
2147
2148 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002149 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002150 * communicate).
2151 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002152 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002153 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002154 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002155 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002156 }
2157
2158 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002159 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002160 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002161 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002162 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002163 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 }
2165
2166 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002167 * Sets state to initializing (this Connection is not yet ready to be used).
2168 */
2169 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002171 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002172 }
2173
2174 /**
2175 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2176 */
2177 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002178 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002179 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002180 }
2181
2182 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002183 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002184 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002185 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002186 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002187 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002188 }
2189
2190 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002191 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2192 * device). Only applicable for {@link Connection}s with
2193 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2194 */
2195 public final void setPulling() {
2196 checkImmutable();
2197 setState(STATE_PULLING_CALL);
2198 }
2199
2200 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002201 * Sets state to be on hold.
2202 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002203 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002204 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002205 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002206 }
2207
2208 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002209 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002210 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002211 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002212 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002214 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002215 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002216 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002217 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002218 }
2219
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002220 public final VideoProvider getVideoProvider() {
2221 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002222 }
2223
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002224 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002225 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002226 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002227 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002228 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002229 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002230 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002231 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002232 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002233 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002234 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002235 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002236 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002237 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002238 }
2239
2240 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002241 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2242 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2243 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2244 * to send an {@link #onPostDialContinue(boolean)} signal.
2245 *
2246 * @param remaining The DTMF character sequence remaining to be emitted once the
2247 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2248 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002249 */
2250 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002251 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002252 for (Listener l : mListeners) {
2253 l.onPostDialWait(this, remaining);
2254 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002255 }
2256
2257 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002258 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2259 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002260 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002261 *
2262 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002263 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002264 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002265 checkImmutable();
2266 for (Listener l : mListeners) {
2267 l.onPostDialChar(this, nextChar);
2268 }
2269 }
2270
2271 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002272 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002273 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002274 *
2275 * @param ringback Whether the ringback tone is to be played.
2276 */
Andrew Lee100e2932014-09-08 15:34:24 -07002277 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002278 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002279 if (mRingbackRequested != ringback) {
2280 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002281 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002282 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002283 }
2284 }
Ihab Awadf8358972014-05-28 16:46:42 -07002285 }
2286
2287 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002288 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002289 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002290 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002291 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002292 public final void setConnectionCapabilities(int connectionCapabilities) {
2293 checkImmutable();
2294 if (mConnectionCapabilities != connectionCapabilities) {
2295 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002296 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002297 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002298 }
2299 }
Santos Cordonb6939982014-06-04 20:20:58 -07002300 }
2301
2302 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002303 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2304 *
2305 * @param connectionProperties The new connection properties.
2306 */
2307 public final void setConnectionProperties(int connectionProperties) {
2308 checkImmutable();
2309 if (mConnectionProperties != connectionProperties) {
2310 mConnectionProperties = connectionProperties;
2311 for (Listener l : mListeners) {
2312 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2313 }
2314 }
2315 }
2316
2317 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002318 * Sets the supported audio routes.
2319 *
2320 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2321 * See {@link CallAudioState}
2322 * @hide
2323 */
2324 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2325 if ((supportedAudioRoutes
2326 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2327 throw new IllegalArgumentException(
2328 "supported audio routes must include either speaker or earpiece");
2329 }
2330
2331 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2332 mSupportedAudioRoutes = supportedAudioRoutes;
2333 for (Listener l : mListeners) {
2334 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2335 }
2336 }
2337 }
2338
2339 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002340 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002341 */
Evan Charlton36a71342014-07-19 16:31:02 -07002342 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002343 for (Listener l : mListeners) {
2344 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002345 }
Santos Cordonb6939982014-06-04 20:20:58 -07002346 }
2347
2348 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002349 * Requests that the framework use VOIP audio mode for this connection.
2350 *
2351 * @param isVoip True if the audio mode is VOIP.
2352 */
2353 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002354 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002355 mAudioModeIsVoip = isVoip;
2356 for (Listener l : mListeners) {
2357 l.onAudioModeIsVoipChanged(this, isVoip);
2358 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002359 }
2360
2361 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002362 * Sets the time at which a call became active on this Connection. This is set only
2363 * when a conference call becomes active on this connection.
2364 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002365 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2366 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002367 *
2368 * @hide
2369 */
2370 public final void setConnectTimeMillis(long connectTimeMillis) {
2371 mConnectTimeMillis = connectTimeMillis;
2372 }
2373
2374 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002375 * Sets the time at which a call became active on this Connection. This is set only
2376 * when a conference call becomes active on this connection.
2377 *
2378 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2379 * {@link SystemClock#elapsedRealtime()}.
2380 *
2381 * @hide
2382 */
Tyler Gunn17541392018-02-01 08:58:38 -08002383 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002384 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2385 }
2386
2387 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002388 * Sets RIL voice radio technology used for current connection.
2389 *
2390 * @param vrat the RIL Voice Radio Technology used for current connection,
2391 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2392 *
2393 * @hide
2394 */
2395 public final void setCallRadioTech(@ServiceState.RilRadioTechnology int vrat) {
2396 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
2397 ServiceState.rilRadioTechnologyToNetworkType(vrat));
2398 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2399 // This action only covers non-IMS CS conference calls.
2400 // For IMS PS call conference call, it can be updated via its host connection
2401 // {@link #Listener.onExtrasChanged} event.
2402 if (getConference() != null) {
2403 getConference().setCallRadioTech(vrat);
2404 }
2405 }
2406
2407 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002408 * Sets the label and icon status to display in the in-call UI.
2409 *
2410 * @param statusHints The status label and icon to set.
2411 */
2412 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002413 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002414 mStatusHints = statusHints;
2415 for (Listener l : mListeners) {
2416 l.onStatusHintsChanged(this, statusHints);
2417 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002418 }
2419
2420 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002421 * Sets the connections with which this connection can be conferenced.
2422 *
2423 * @param conferenceableConnections The set of connections this connection can conference with.
2424 */
2425 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002426 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002427 clearConferenceableList();
2428 for (Connection c : conferenceableConnections) {
2429 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2430 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002431 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002432 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002433 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002434 }
2435 }
2436 fireOnConferenceableConnectionsChanged();
2437 }
2438
2439 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002440 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2441 * or conferences with which this connection can be conferenced.
2442 *
2443 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002444 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002445 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002446 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002447 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002448 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2449 // small amount of items here.
2450 if (!mConferenceables.contains(c)) {
2451 if (c instanceof Connection) {
2452 Connection connection = (Connection) c;
2453 connection.addConnectionListener(mConnectionDeathListener);
2454 } else if (c instanceof Conference) {
2455 Conference conference = (Conference) c;
2456 conference.addListener(mConferenceDeathListener);
2457 }
2458 mConferenceables.add(c);
2459 }
2460 }
2461 fireOnConferenceableConnectionsChanged();
2462 }
2463
2464 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002465 * @hide
2466 * Resets the cdma connection time.
2467 */
2468 public final void resetConnectionTime() {
2469 for (Listener l : mListeners) {
2470 l.onConnectionTimeReset(this);
2471 }
2472 }
2473
2474 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002475 * Returns the connections or conferences with which this connection can be conferenced.
2476 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002477 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002478 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002479 }
2480
Yorke Lee53463962015-08-04 16:07:19 -07002481 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002482 * @hide
2483 */
2484 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002485 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002486 if (mConnectionService != null) {
2487 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2488 "which is already associated with another ConnectionService.");
2489 } else {
2490 mConnectionService = connectionService;
2491 }
2492 }
2493
2494 /**
2495 * @hide
2496 */
2497 public final void unsetConnectionService(ConnectionService connectionService) {
2498 if (mConnectionService != connectionService) {
2499 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2500 "that does not belong to the ConnectionService.");
2501 } else {
2502 mConnectionService = null;
2503 }
2504 }
2505
2506 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002507 * @hide
2508 */
2509 public final ConnectionService getConnectionService() {
2510 return mConnectionService;
2511 }
2512
2513 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002514 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002515 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002516 *
2517 * @param conference The conference.
2518 * @return {@code true} if the conference was successfully set.
2519 * @hide
2520 */
2521 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002522 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002523 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002524 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002525 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002526 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2527 fireConferenceChanged();
2528 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002529 return true;
2530 }
2531 return false;
2532 }
2533
2534 /**
2535 * Resets the conference that this connection is a part of.
2536 * @hide
2537 */
2538 public final void resetConference() {
2539 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002540 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002541 mConference = null;
2542 fireConferenceChanged();
2543 }
2544 }
2545
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002546 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002547 * Set some extras that can be associated with this {@code Connection}.
2548 * <p>
2549 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2550 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2551 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002552 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2553 * {@link #removeExtras(String...)} methods to modify the extras.
2554 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002555 * 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 -07002556 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2557 *
2558 * @param extras The extras associated with this {@code Connection}.
2559 */
2560 public final void setExtras(@Nullable Bundle extras) {
2561 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002562
2563 // Add/replace any new or changed extras values.
2564 putExtras(extras);
2565
2566 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2567 // the current one and remove any keys that went away.
2568 if (mPreviousExtraKeys != null) {
2569 List<String> toRemove = new ArrayList<String>();
2570 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002571 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002572 toRemove.add(oldKey);
2573 }
2574 }
2575 if (!toRemove.isEmpty()) {
2576 removeExtras(toRemove);
2577 }
2578 }
2579
2580 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2581 // called we can see if the caller has removed any extras values.
2582 if (mPreviousExtraKeys == null) {
2583 mPreviousExtraKeys = new ArraySet<String>();
2584 }
2585 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002586 if (extras != null) {
2587 mPreviousExtraKeys.addAll(extras.keySet());
2588 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002589 }
2590
2591 /**
2592 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2593 * added.
2594 * <p>
2595 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2596 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2597 *
2598 * @param extras The extras to add.
2599 */
2600 public final void putExtras(@NonNull Bundle extras) {
2601 checkImmutable();
2602 if (extras == null) {
2603 return;
2604 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002605 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2606 // the listeners.
2607 Bundle listenerExtras;
2608 synchronized (mExtrasLock) {
2609 if (mExtras == null) {
2610 mExtras = new Bundle();
2611 }
2612 mExtras.putAll(extras);
2613 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002614 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002615 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002616 // Create a new clone of the extras for each listener so that they don't clobber
2617 // each other
2618 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002619 }
2620 }
2621
2622 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002623 * Adds a boolean extra to this {@code Connection}.
2624 *
2625 * @param key The extra key.
2626 * @param value The value.
2627 * @hide
2628 */
2629 public final void putExtra(String key, boolean value) {
2630 Bundle newExtras = new Bundle();
2631 newExtras.putBoolean(key, value);
2632 putExtras(newExtras);
2633 }
2634
2635 /**
2636 * Adds an integer extra to this {@code Connection}.
2637 *
2638 * @param key The extra key.
2639 * @param value The value.
2640 * @hide
2641 */
2642 public final void putExtra(String key, int value) {
2643 Bundle newExtras = new Bundle();
2644 newExtras.putInt(key, value);
2645 putExtras(newExtras);
2646 }
2647
2648 /**
2649 * Adds a string extra to this {@code Connection}.
2650 *
2651 * @param key The extra key.
2652 * @param value The value.
2653 * @hide
2654 */
2655 public final void putExtra(String key, String value) {
2656 Bundle newExtras = new Bundle();
2657 newExtras.putString(key, value);
2658 putExtras(newExtras);
2659 }
2660
2661 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002662 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002663 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002664 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002665 */
2666 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002667 synchronized (mExtrasLock) {
2668 if (mExtras != null) {
2669 for (String key : keys) {
2670 mExtras.remove(key);
2671 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002672 }
2673 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002674 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002675 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002676 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002677 }
2678 }
2679
2680 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002681 * Removes extras from this {@code Connection}.
2682 *
2683 * @param keys The keys of the extras to remove.
2684 */
2685 public final void removeExtras(String ... keys) {
2686 removeExtras(Arrays.asList(keys));
2687 }
2688
2689 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002690 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2691 * be change to the {@link #getCallAudioState()}.
2692 * <p>
2693 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2694 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2695 * <p>
2696 * See also {@link InCallService#setAudioRoute(int)}.
2697 *
2698 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2699 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2700 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2701 */
2702 public final void setAudioRoute(int route) {
2703 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002704 l.onAudioRouteChanged(this, route, null);
2705 }
2706 }
2707
2708 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002709 * Request audio routing to a specific bluetooth device. Calling this method may result in
2710 * the device routing audio to a different bluetooth device than the one specified if the
2711 * bluetooth stack is unable to route audio to the requested device.
2712 * A list of available devices can be obtained via
2713 * {@link CallAudioState#getSupportedBluetoothDevices()}
2714 *
2715 * <p>
2716 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2717 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2718 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002719 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2720 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002721 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002722 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002723 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002724 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2725 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002726 }
2727 }
2728
2729 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002730 * Informs listeners that a previously requested RTT session via
2731 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002732 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002733 */
2734 public final void sendRttInitiationSuccess() {
2735 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2736 }
2737
2738 /**
2739 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002740 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002741 * has failed.
2742 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2743 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002744 */
2745 public final void sendRttInitiationFailure(int reason) {
2746 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2747 }
2748
2749 /**
2750 * Informs listeners that a currently active RTT session has been terminated by the remote
2751 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002752 */
2753 public final void sendRttSessionRemotelyTerminated() {
2754 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2755 }
2756
2757 /**
2758 * Informs listeners that the remote side of the call has requested an upgrade to include an
2759 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002760 */
2761 public final void sendRemoteRttRequest() {
2762 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2763 }
2764
2765 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002766 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002767 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002768 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002769 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2770 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002771 */
Yorke Lee4af59352015-05-13 14:14:54 -07002772 @SystemApi
2773 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002774 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002775
2776 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002777 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2778 *
2779 * @param state The new connection audio state.
2780 */
2781 public void onCallAudioStateChanged(CallAudioState state) {}
2782
2783 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002784 * Notifies this Connection of an internal state change. This method is called after the
2785 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002786 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002787 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002788 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002789 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002790
2791 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002792 * Notifies this Connection of a request to play a DTMF tone.
2793 *
2794 * @param c A DTMF character.
2795 */
Santos Cordonf2951102014-07-20 19:06:29 -07002796 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002797
2798 /**
2799 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2800 */
Santos Cordonf2951102014-07-20 19:06:29 -07002801 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002802
2803 /**
2804 * Notifies this Connection of a request to disconnect.
2805 */
Santos Cordonf2951102014-07-20 19:06:29 -07002806 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002807
2808 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002809 * Notifies this Connection of a request to disconnect a participant of the conference managed
2810 * by the connection.
2811 *
2812 * @param endpoint the {@link Uri} of the participant to disconnect.
2813 * @hide
2814 */
2815 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2816
2817 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002818 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002819 */
Santos Cordonf2951102014-07-20 19:06:29 -07002820 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002821
2822 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002823 * Notifies this Connection of a request to abort.
2824 */
Santos Cordonf2951102014-07-20 19:06:29 -07002825 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002826
2827 /**
2828 * Notifies this Connection of a request to hold.
2829 */
Santos Cordonf2951102014-07-20 19:06:29 -07002830 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002831
2832 /**
2833 * Notifies this Connection of a request to exit a hold state.
2834 */
Santos Cordonf2951102014-07-20 19:06:29 -07002835 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002836
2837 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002838 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002839 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002840 * <p>
2841 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2842 * the default dialer's {@link InCallService}.
2843 * <p>
2844 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2845 * Telecom framework may request that the call is answered in the following circumstances:
2846 * <ul>
2847 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2848 * <li>A car mode {@link InCallService} is in use which has declared
2849 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2850 * {@link InCallService} will be able to see calls from self-managed
2851 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2852 * behalf.</li>
2853 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002854 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002855 */
Santos Cordonf2951102014-07-20 19:06:29 -07002856 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002857
2858 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002859 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002860 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002861 * <p>
2862 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2863 * the default dialer's {@link InCallService}.
2864 * <p>
2865 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2866 * Telecom framework may request that the call is answered in the following circumstances:
2867 * <ul>
2868 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2869 * <li>A car mode {@link InCallService} is in use which has declared
2870 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2871 * {@link InCallService} will be able to see calls from self-managed
2872 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2873 * behalf.</li>
2874 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002875 */
2876 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002877 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002878 }
2879
2880 /**
2881 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302882 * a request to deflect.
2883 */
2884 public void onDeflect(Uri address) {}
2885
2886 /**
2887 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002888 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002889 * <p>
2890 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2891 * the default dialer's {@link InCallService}.
2892 * <p>
2893 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2894 * Telecom framework may request that the call is rejected in the following circumstances:
2895 * <ul>
2896 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2897 * <li>A car mode {@link InCallService} is in use which has declared
2898 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2899 * {@link InCallService} will be able to see calls from self-managed
2900 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2901 * behalf.</li>
2902 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002903 */
Santos Cordonf2951102014-07-20 19:06:29 -07002904 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002905
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002906 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002907 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2908 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002909 */
2910 public void onReject(String replyMessage) {}
2911
2912 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002913 * Notifies this Connection of a request to silence the ringer.
2914 * <p>
2915 * The ringer may be silenced by any of the following methods:
2916 * <ul>
2917 * <li>{@link TelecomManager#silenceRinger()}</li>
2918 * <li>The user presses the volume-down button while a call is ringing.</li>
2919 * </ul>
2920 * <p>
2921 * Self-managed {@link ConnectionService} implementations should override this method in their
2922 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2923 * your app set the ringtone as part of the incoming call {@link Notification} (see
2924 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2925 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2926 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2927 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002928 */
2929 public void onSilence() {}
2930
2931 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002932 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2933 */
Santos Cordonf2951102014-07-20 19:06:29 -07002934 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002935
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002936 /**
2937 * Notifies this Connection of a request to pull an external call to the local device.
2938 * <p>
2939 * The {@link InCallService} issues a request to pull an external call to the local device via
2940 * {@link Call#pullExternalCall()}.
2941 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002942 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2943 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002944 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002945 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002946 */
2947 public void onPullExternalCall() {}
2948
2949 /**
2950 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2951 * <p>
2952 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2953 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002954 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2955 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2956 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2957 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2958 * not aware of.
2959 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002960 * See also {@link Call#sendCallEvent(String, Bundle)}.
2961 *
2962 * @param event The call event.
2963 * @param extras Extras associated with the call event.
2964 */
2965 public void onCallEvent(String event, Bundle extras) {}
2966
Tyler Gunndee56a82016-03-23 16:06:34 -07002967 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002968 * Notifies this {@link Connection} that a handover has completed.
2969 * <p>
2970 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2971 * Bundle)} on the initiating side of the handover, and
2972 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2973 */
2974 public void onHandoverComplete() {}
2975
2976 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002977 * Notifies this {@link Connection} of a change to the extras made outside the
2978 * {@link ConnectionService}.
2979 * <p>
2980 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2981 * the {@link android.telecom.Call#putExtras(Bundle)} and
2982 * {@link Call#removeExtras(List)}.
2983 *
2984 * @param extras The new extras bundle.
2985 */
2986 public void onExtrasChanged(Bundle extras) {}
2987
Tyler Gunnf5035432017-01-09 09:43:12 -08002988 /**
2989 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2990 * displaying its incoming call user interface for the {@link Connection}.
2991 * <p>
2992 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2993 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2994 * should show its own incoming call user interface.
2995 * <p>
2996 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002997 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2998 * Telecom framework will display its own incoming call user interface to allow the user to
2999 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3000 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003001 * <p>
3002 * You should trigger the display of the incoming call user interface for your application by
3003 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003004 *
3005 * In your application code, you should create a {@link android.app.NotificationChannel} for
3006 * incoming call notifications from your app:
3007 * <pre><code>
3008 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3009 * NotificationManager.IMPORTANCE_MAX);
3010 * // other channel setup stuff goes here.
3011 *
3012 * // We'll use the default system ringtone for our incoming call notification channel. You can
3013 * // use your own audio resource here.
3014 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3015 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3016 * // Setting the AudioAttributes is important as it identifies the purpose of your
3017 * // notification sound.
3018 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3019 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3020 * .build());
3021 *
3022 * NotificationManager mgr = getSystemService(NotificationManager.class);
3023 * mgr.createNotificationChannel(channel);
3024 * </code></pre>
3025 * When it comes time to post a notification for your incoming call, ensure it uses your
3026 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003027 * <pre><code>
3028 * // Create an intent which triggers your fullscreen incoming call user interface.
3029 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3030 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3031 * intent.setClass(context, YourIncomingCallActivity.class);
3032 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3033 *
3034 * // Build the notification as an ongoing high priority item; this ensures it will show as
3035 * // a heads up notification which slides down over top of the current content.
3036 * final Notification.Builder builder = new Notification.Builder(context);
3037 * builder.setOngoing(true);
3038 * builder.setPriority(Notification.PRIORITY_HIGH);
3039 *
3040 * // Set notification content intent to take user to fullscreen UI if user taps on the
3041 * // notification body.
3042 * builder.setContentIntent(pendingIntent);
3043 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3044 * // manager deems it appropriate.
3045 * builder.setFullScreenIntent(pendingIntent, true);
3046 *
3047 * // Setup notification content.
3048 * builder.setSmallIcon( yourIconResourceId );
3049 * builder.setContentTitle("Your notification title");
3050 * builder.setContentText("Your notification content.");
3051 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003052 * // Set notification as insistent to cause your ringtone to loop.
3053 * Notification notification = builder.build();
3054 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003055 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003056 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003057 * NotificationManager notificationManager = mContext.getSystemService(
3058 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003059 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003060 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003061 */
3062 public void onShowIncomingCallUi() {}
3063
Hall Liub64ac4c2017-02-06 10:49:48 -08003064 /**
3065 * Notifies this {@link Connection} that the user has requested an RTT session.
3066 * The connection service should call {@link #sendRttInitiationSuccess} or
3067 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3068 * request, respectively.
3069 * @param rttTextStream The object that should be used to send text to or receive text from
3070 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003071 */
3072 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3073
3074 /**
3075 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3076 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003077 */
3078 public void onStopRtt() {}
3079
3080 /**
3081 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3082 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3083 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3084 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003085 * @param rttTextStream The object that should be used to send text to or receive text from
3086 * the in-call app.
3087 */
3088 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3089
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003090 static String toLogSafePhoneNumber(String number) {
3091 // For unknown number, log empty string.
3092 if (number == null) {
3093 return "";
3094 }
3095
3096 if (PII_DEBUG) {
3097 // When PII_DEBUG is true we emit PII.
3098 return number;
3099 }
3100
3101 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3102 // sanitized phone numbers.
3103 StringBuilder builder = new StringBuilder();
3104 for (int i = 0; i < number.length(); i++) {
3105 char c = number.charAt(i);
3106 if (c == '-' || c == '@' || c == '.') {
3107 builder.append(c);
3108 } else {
3109 builder.append('x');
3110 }
3111 }
3112 return builder.toString();
3113 }
3114
Ihab Awad542e0ea2014-05-16 10:22:16 -07003115 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003116 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003117 if (mState == STATE_DISCONNECTED && mState != state) {
3118 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003119 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003120 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003121 if (mState != state) {
3122 Log.d(this, "setState: %s", stateToString(state));
3123 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003124 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003125 for (Listener l : mListeners) {
3126 l.onStateChanged(this, state);
3127 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003128 }
3129 }
3130
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003131 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003132 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003133 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3134 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003135 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003136 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003137
3138 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003139 if (mImmutable) {
3140 throw new UnsupportedOperationException("Connection is immutable");
3141 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003142 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003143 }
3144
Evan Charltonbf11f982014-07-20 22:06:28 -07003145 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003146 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003147 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3148 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003149 * <p>
3150 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3151 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003152 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003153 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003154 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003155 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003156 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3157 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003158 }
3159
Evan Charltonbf11f982014-07-20 22:06:28 -07003160 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003161 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3162 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3163 * this should never be un-@hide-den.
3164 *
3165 * @hide
3166 */
3167 public void checkImmutable() {}
3168
3169 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003170 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3171 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3172 * that state. This connection should not be used for anything, and no other
3173 * {@code Connection}s should be attempted.
3174 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003175 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003176 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003177 * @return A {@code Connection} which indicates that the underlying connection should
3178 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003179 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003180 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003181 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003182 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003183
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003184 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003185 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003186 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003187 }
3188 }
3189
Santos Cordon823fd3c2014-08-07 18:35:18 -07003190 private final void fireConferenceChanged() {
3191 for (Listener l : mListeners) {
3192 l.onConferenceChanged(this, mConference);
3193 }
3194 }
3195
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003196 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003197 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003198 if (c instanceof Connection) {
3199 Connection connection = (Connection) c;
3200 connection.removeConnectionListener(mConnectionDeathListener);
3201 } else if (c instanceof Conference) {
3202 Conference conference = (Conference) c;
3203 conference.removeListener(mConferenceDeathListener);
3204 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003205 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003206 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003207 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003208
3209 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003210 * Handles a change to extras received from Telecom.
3211 *
3212 * @param extras The new extras.
3213 * @hide
3214 */
3215 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003216 Bundle b = null;
3217 synchronized (mExtrasLock) {
3218 mExtras = extras;
3219 if (mExtras != null) {
3220 b = new Bundle(mExtras);
3221 }
3222 }
3223 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003224 }
3225
3226 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003227 * Notifies listeners that the merge request failed.
3228 *
3229 * @hide
3230 */
3231 protected final void notifyConferenceMergeFailed() {
3232 for (Listener l : mListeners) {
3233 l.onConferenceMergeFailed(this);
3234 }
3235 }
3236
3237 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003238 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003239 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003240 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003241 * @hide
3242 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003243 protected final void updateConferenceParticipants(
3244 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003245 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003246 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003247 }
3248 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003249
3250 /**
3251 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003252 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003253 */
3254 protected void notifyConferenceStarted() {
3255 for (Listener l : mListeners) {
3256 l.onConferenceStarted();
3257 }
3258 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003259
3260 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003261 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3262 * be a part of a conference call.
3263 * @param isConferenceSupported {@code true} if the connection supports being part of a
3264 * conference call, {@code false} otherwise.
3265 * @hide
3266 */
3267 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3268 for (Listener l : mListeners) {
3269 l.onConferenceSupportedChanged(this, isConferenceSupported);
3270 }
3271 }
3272
3273 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303274 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3275 * changed due to an emergency call being redialed.
3276 * @param pHandle The new PhoneAccountHandle for this connection.
3277 * @hide
3278 */
3279 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3280 for (Listener l : mListeners) {
3281 l.onPhoneAccountChanged(this, pHandle);
3282 }
3283 }
3284
3285 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003286 * Sets the {@link PhoneAccountHandle} associated with this connection.
3287 *
3288 * @hide
3289 */
3290 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3291 if (mPhoneAccountHandle != phoneAccountHandle) {
3292 mPhoneAccountHandle = phoneAccountHandle;
3293 notifyPhoneAccountChanged(phoneAccountHandle);
3294 }
3295 }
3296
3297 /**
3298 * Returns the {@link PhoneAccountHandle} associated with this connection.
3299 *
3300 * @hide
3301 */
3302 public PhoneAccountHandle getPhoneAccountHandle() {
3303 return mPhoneAccountHandle;
3304 }
3305
3306 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003307 * Sends an event associated with this {@code Connection} with associated event extras to the
3308 * {@link InCallService}.
3309 * <p>
3310 * Connection events are used to communicate point in time information from a
3311 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3312 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3313 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3314 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3315 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3316 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3317 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3318 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3319 * <p>
3320 * Events are exposed to {@link InCallService} implementations via
3321 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3322 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003323 * 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 -07003324 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3325 * some events altogether.
3326 * <p>
3327 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3328 * conflicts between {@link ConnectionService} implementations. Further, custom
3329 * {@link ConnectionService} implementations shall not re-purpose events in the
3330 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3331 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3332 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3333 * {@code com.example.extra.MY_EXTRA}).
3334 * <p>
3335 * When defining events and the associated extras, it is important to keep their behavior
3336 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3337 * events/extras should me maintained to ensure backwards compatibility with older
3338 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003339 *
3340 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003341 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003342 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003343 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003344 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003345 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003346 }
3347 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003348}