blob: 525b938b7632a9b98bb46157c107e7f4f413d447 [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;
Chen Xuf85cf992019-10-02 00:20:43 -070037import android.telephony.Annotation.RilRadioTechnology;
Wei Huang7f7f72e2018-05-30 19:21:36 +080038import android.telephony.ServiceState;
39import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Youming Yed6de26e2019-01-30 11:20:35 -080043import com.android.internal.os.SomeArgs;
44import com.android.internal.telecom.IVideoCallback;
45import com.android.internal.telecom.IVideoProvider;
46
Hall Liua549fed2018-02-09 16:40:03 -080047import java.io.FileInputStream;
48import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080049import java.io.IOException;
50import java.io.InputStreamReader;
51import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070052import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070053import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070054import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070055import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070056import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070057import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070058import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070059
60/**
Santos Cordon895d4b82015-06-25 16:41:48 -070061 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
62 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070063 * <p>
64 * Implementations create a custom subclass of {@code Connection} and return it to the framework
65 * as the return value of
66 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
67 * or
68 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
69 * Implementations are then responsible for updating the state of the {@code Connection}, and
70 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
71 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070072 * <p>
73 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
74 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
75 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
76 * {@code Connection} instance.
77 * <p>
78 * Basic call support requires overriding the following methods: {@link #onAnswer()},
79 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
80 * <p>
81 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
82 * {@link #onUnhold()} methods should be overridden to provide hold support for the
83 * {@code Connection}.
84 * <p>
85 * Where a {@code Connection} supports a variation of video calling (e.g. the
86 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
87 * to support answering a call as a video call.
88 * <p>
89 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
90 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
91 * support for pulling the external call.
92 * <p>
93 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
94 * overridden.
95 * <p>
96 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
97 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
98 * for example, call events from a {@link InCallService} are handled,
99 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
100 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
101 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
102 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700104public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * The connection is initializing. This is generally the first state for a {@code Connection}
108 * returned by a {@link ConnectionService}.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_INITIALIZING = 0;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * The connection is new and not connected.
114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 public static final int STATE_NEW = 1;
116
Santos Cordon895d4b82015-06-25 16:41:48 -0700117 /**
118 * An incoming connection is in the ringing state. During this state, the user's ringer or
119 * vibration feature will be activated.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_RINGING = 2;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * An outgoing connection is in the dialing state. In this state the other party has not yet
125 * answered the call and the user traditionally hears a ringback tone.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_DIALING = 3;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * A connection is active. Both parties are connected to the call and can actively communicate.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_ACTIVE = 4;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
135 * A connection is on hold.
136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final int STATE_HOLDING = 5;
138
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 /**
140 * A connection has been disconnected. This is the final state once the user has been
141 * disconnected from a call either locally, remotely or by an error in the service.
142 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700143 public static final int STATE_DISCONNECTED = 6;
144
Santos Cordon895d4b82015-06-25 16:41:48 -0700145 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700146 * The state of an external connection which is in the process of being pulled from a remote
147 * device to the local device.
148 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700149 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700150 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
151 */
152 public static final int STATE_PULLING_CALL = 7;
153
154 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700155 * Connection can currently be put on hold or unheld. This is distinct from
156 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
157 * it does not at the moment support the function. This can be true while the call is in the
158 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
159 * display a disabled 'hold' button.
160 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 public static final int CAPABILITY_HOLD = 0x00000001;
162
163 /** Connection supports the hold feature. */
164 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
165
166 /**
167 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
168 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
169 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
170 * capability allows a merge button to be shown while the conference is in the foreground
171 * of the in-call UI.
172 * <p>
173 * This is only intended for use by a {@link Conference}.
174 */
175 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
176
177 /**
178 * Connections within a conference can be swapped between foreground and background.
179 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
180 * <p>
181 * This is only intended for use by a {@link Conference}.
182 */
183 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
184
185 /**
186 * @hide
187 */
188 public static final int CAPABILITY_UNUSED = 0x00000010;
189
190 /** Connection supports responding via text option. */
191 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
192
193 /** Connection can be muted. */
194 public static final int CAPABILITY_MUTE = 0x00000040;
195
196 /**
197 * Connection supports conference management. This capability only applies to
198 * {@link Conference}s which can have {@link Connection}s as children.
199 */
200 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211
212 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700215 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217
218 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800220 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
222
223 /**
224 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 */
226 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
227
228 /**
229 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700230 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700231 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700232 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800233
234 /**
235 * Connection is able to be separated from its parent {@code Conference}, if any.
236 */
237 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
238
239 /**
240 * Connection is able to be individually disconnected when in a {@code Conference}.
241 */
242 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
243
244 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246 * @hide
247 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800249
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * @hide
253 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255
256 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 * @hide
259 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700260 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261
Tyler Gunn068085b2015-02-06 13:56:52 -0800262 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700263 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800264 * @hide
265 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700266 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Tyler Gunn96d6c402015-03-18 12:39:23 -0700268 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500269 * Speed up audio setup for MT call.
270 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700271 */
272 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800273
Rekha Kumar07366812015-03-24 16:42:31 -0700274 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700275 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800276 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
278 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700279 */
280 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
281
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700282 /**
283 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700284 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700285 */
286 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
287
Tyler Gunnd4091732015-06-29 09:15:37 -0700288 /**
289 * For a conference, indicates the conference will not have child connections.
290 * <p>
291 * An example of a conference with child connections is a GSM conference call, where the radio
292 * retains connections to the individual participants of the conference. Another example is an
293 * IMS conference call where conference event package functionality is supported; in this case
294 * the conference server ensures the radio is aware of the participants in the conference, which
295 * are represented by child connections.
296 * <p>
297 * An example of a conference with no child connections is an IMS conference call with no
298 * conference event package support. Such a conference is represented by the radio as a single
299 * connection to the IMS conference server.
300 * <p>
301 * Indicating whether a conference has children or not is important to help user interfaces
302 * visually represent a conference. A conference with no children, for example, will have the
303 * conference connection shown in the list of calls on a Bluetooth device, where if the
304 * conference has children, only the children will be shown in the list of calls on a Bluetooth
305 * device.
306 * @hide
307 */
308 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
309
Bryce Lee81901682015-08-28 16:38:02 -0700310 /**
311 * Indicates that the connection itself wants to handle any sort of reply response, rather than
312 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700313 */
314 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
315
Tyler Gunnf97a0092016-01-19 15:59:34 -0800316 /**
317 * When set, prevents a video call from being downgraded to an audio-only call.
318 * <p>
319 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
320 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
321 * downgraded from a video call back to a VideoState of
322 * {@link VideoProfile#STATE_AUDIO_ONLY}.
323 * <p>
324 * Intuitively, a call which can be downgraded to audio should also have local and remote
325 * video
326 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
327 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
328 */
329 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
330
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700331 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700332 * When set for an external connection, indicates that this {@code Connection} can be pulled
333 * from a remote device to the current device.
334 * <p>
335 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
336 * is set.
337 */
338 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
339
Pooja Jaind34698d2017-12-28 14:15:31 +0530340 /** Call supports the deflect feature. */
341 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
342
Tyler Gunn720c6642016-03-22 09:02:47 -0700343 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530344 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700345 //**********************************************************************************************
346
347 /**
348 * Indicates that the current device callback number should be shown.
349 *
350 * @hide
351 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700352 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700353
354 /**
355 * Whether the call is a generic conference, where we do not know the precise state of
356 * participants in the conference (eg. on CDMA).
357 *
358 * @hide
359 */
360 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
361
362 /**
363 * Connection is using high definition audio.
364 * @hide
365 */
366 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
367
368 /**
369 * Connection is using WIFI.
370 * @hide
371 */
372 public static final int PROPERTY_WIFI = 1<<3;
373
374 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700375 * When set, indicates that the {@code Connection} does not actually exist locally for the
376 * {@link ConnectionService}.
377 * <p>
378 * Consider, for example, a scenario where a user has two devices with the same phone number.
379 * When a user places a call on one devices, the telephony stack can represent that call on the
380 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382 * <p>
383 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
384 * external connections. Only those {@link InCallService}s which have the
385 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
386 * manifest will see external connections.
387 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700388 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700389
Brad Ebinger15847072016-05-18 11:08:36 -0700390 /**
391 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
392 */
393 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700394
Hall Liu9f332c72016-07-14 15:37:37 -0700395 /**
396 * Indicates that the connection represents a downgraded IMS conference.
397 * @hide
398 */
399 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
400
Tyler Gunnf5035432017-01-09 09:43:12 -0800401 /**
402 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
403 * {@link ConnectionService}.
404 * <p>
405 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
406 */
407 public static final int PROPERTY_SELF_MANAGED = 1<<7;
408
Hall Liu95d55872017-01-25 17:12:49 -0800409 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800410 * Set by the framework to indicate that a connection has an active RTT session associated with
411 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800412 */
413 public static final int PROPERTY_IS_RTT = 1 << 8;
414
Eric Erfanian62706c52017-12-06 16:27:53 -0800415 /**
416 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000417 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800418 */
419 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
420
Tyler Gunn5bd90852018-09-21 09:37:07 -0700421 /**
422 * Set by the framework to indicate that the network has identified a Connection as an emergency
423 * call.
424 * @hide
425 */
426 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
427
Tyler Gunnac60f952019-05-31 07:23:16 -0700428 /**
429 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
430 * than the current one. Used in scenarios where the conference originator is the remote device
431 * and the current device is a participant of that conference.
432 * @hide
433 */
434 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
435
Tyler Gunn96d6c402015-03-18 12:39:23 -0700436 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700437 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700438 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800439
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700440 /**
441 * Connection extra key used to store the last forwarded number associated with the current
442 * connection. Used to communicate to the user interface that the connection was forwarded via
443 * the specified number.
444 */
445 public static final String EXTRA_LAST_FORWARDED_NUMBER =
446 "android.telecom.extra.LAST_FORWARDED_NUMBER";
447
448 /**
449 * Connection extra key used to store a child number associated with the current connection.
450 * Used to communicate to the user interface that the connection was received via
451 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
452 * address.
453 */
454 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
455
456 /**
457 * Connection extra key used to store the subject for an incoming call. The user interface can
458 * query this extra and display its contents for incoming calls. Will only be used if the
459 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
460 */
461 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
462
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800463 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700464 * Boolean connection extra key set on a {@link Connection} in
465 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
466 * current active foreground call to be dropped.
467 */
468 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
469 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
470
471 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700472 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
473 * state to indicate the name of the third-party app which is responsible for the current
474 * foreground call.
475 * <p>
476 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
477 * is able to inform the user that answering the new incoming call will cause a call owned by
478 * another app to be dropped when the incoming call is answered.
479 */
480 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
481 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
482
483 /**
Hall Liu10208662016-06-15 17:55:00 -0700484 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700485 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700486 * @hide
487 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700488 public static final String EXTRA_DISABLE_ADD_CALL =
489 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700490
491 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700492 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
493 * original Connection ID associated with the connection. Used in
494 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
495 * connection/conference added via
496 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
497 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
498 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
499 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
500 * be a way to ensure that we don't add the connection again as a duplicate.
501 * <p>
502 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
503 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
504 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
505 * in a new {@link Connection} which it adds to Telecom via
506 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
507 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
508 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
509 * ID it originally referred to the connection as. Thus Telecom needs to know that the
510 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
511 * @hide
512 */
513 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
514 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
515
516 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700517 * Boolean connection extra key set on the extras passed to
518 * {@link Connection#sendConnectionEvent} which indicates that audio is present
519 * on the RTT call when the extra value is true.
520 */
521 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
522 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
523
524 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800525 * Connection event used to inform Telecom that it should play the on hold tone. This is used
526 * to play 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_START =
531 "android.telecom.event.ON_HOLD_TONE_START";
532
533 /**
534 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
535 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700536 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800537 * @hide
538 */
539 public static final String EVENT_ON_HOLD_TONE_END =
540 "android.telecom.event.ON_HOLD_TONE_END";
541
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700542 /**
543 * Connection event used to inform {@link InCallService}s when pulling of an external call has
544 * failed. The user interface should inform the user of the error.
545 * <p>
546 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
547 * API is called on a {@link Call} with the properties
548 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
549 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
550 * pull the external call due to an error condition.
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.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700554 */
555 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
556
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700557 /**
558 * Connection event used to inform {@link InCallService}s when the merging of two calls has
559 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700560 * <p>
561 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
562 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700563 */
564 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
565
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700566 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700567 * Connection event used to inform Telecom when a hold operation on a call has failed.
568 * Not intended for use by the UI at this time.
569 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
570 * expected to be null when this connection event is used.
571 * @hide
572 */
573 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
574
575 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700576 * Connection event used to inform {@link InCallService}s when the process of merging a
577 * Connection into a conference has begun.
578 * <p>
579 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
580 * expected to be null when this connection event is used.
581 * @hide
582 */
583 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
584
585 /**
586 * Connection event used to inform {@link InCallService}s when the process of merging a
587 * Connection into a conference has completed.
588 * <p>
589 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
590 * expected to be null when this connection event is used.
591 * @hide
592 */
593 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
594
595 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700596 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
597 * the remote party.
598 * <p>
599 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
600 * call is being held locally on the device. When a capable {@link ConnectionService} receives
601 * signalling to indicate that the remote party has put the call on hold, it can send this
602 * connection event.
603 * @hide
604 */
605 public static final String EVENT_CALL_REMOTELY_HELD =
606 "android.telecom.event.CALL_REMOTELY_HELD";
607
608 /**
609 * Connection event used to inform {@link InCallService}s when a call which was remotely held
610 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
611 * <p>
612 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
613 * call is being held locally on the device. When a capable {@link ConnectionService} receives
614 * signalling to indicate that the remote party has taken the call off hold, it can send this
615 * connection event.
616 * @hide
617 */
618 public static final String EVENT_CALL_REMOTELY_UNHELD =
619 "android.telecom.event.CALL_REMOTELY_UNHELD";
620
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700621 /**
622 * Connection event used to inform an {@link InCallService} which initiated a call handover via
623 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
624 * successfully completed.
625 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700626 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
627 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700628 */
629 public static final String EVENT_HANDOVER_COMPLETE =
630 "android.telecom.event.HANDOVER_COMPLETE";
631
632 /**
633 * Connection event used to inform an {@link InCallService} which initiated a call handover via
634 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
635 * to complete.
636 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700637 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
638 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700639 */
640 public static final String EVENT_HANDOVER_FAILED =
641 "android.telecom.event.HANDOVER_FAILED";
642
shilub7ec9a02018-11-09 15:52:04 -0800643 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000644 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800645 */
646 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
647
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700648 /**
649 * Connection event used to inform an {@link InCallService} that the RTT audio indication
650 * has changed.
651 */
652 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
653 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
654
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700655 // Flag controlling whether PII is emitted into the logs
656 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
657
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800658 /**
659 * Whether the given capabilities support the specified capability.
660 *
661 * @param capabilities A capability bit field.
662 * @param capability The capability to check capabilities for.
663 * @return Whether the specified capability is supported.
664 * @hide
665 */
666 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800667 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800668 }
669
670 /**
671 * Whether the capabilities of this {@code Connection} supports the specified capability.
672 *
673 * @param capability The capability to check capabilities for.
674 * @return Whether the specified capability is supported.
675 * @hide
676 */
677 public boolean can(int capability) {
678 return can(mConnectionCapabilities, capability);
679 }
680
681 /**
682 * Removes the specified capability from the set of capabilities of this {@code Connection}.
683 *
684 * @param capability The capability to remove from the set.
685 * @hide
686 */
687 public void removeCapability(int capability) {
688 mConnectionCapabilities &= ~capability;
689 }
690
691 /**
692 * Adds the specified capability to the set of capabilities of this {@code Connection}.
693 *
694 * @param capability The capability to add to the set.
695 * @hide
696 */
697 public void addCapability(int capability) {
698 mConnectionCapabilities |= capability;
699 }
700
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700701 /**
702 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
703 *
704 * @param capabilities A capability bit field.
705 * @return A human readable string representation.
706 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800707 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700708 return capabilitiesToStringInternal(capabilities, true /* isLong */);
709 }
710
711 /**
712 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
713 * string.
714 *
715 * @param capabilities A capability bit field.
716 * @return A human readable string representation.
717 * @hide
718 */
719 public static String capabilitiesToStringShort(int capabilities) {
720 return capabilitiesToStringInternal(capabilities, false /* isLong */);
721 }
722
723 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800724 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append("[");
726 if (isLong) {
727 builder.append("Capabilities:");
728 }
729
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800730 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800732 }
733 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 }
736 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 }
739 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 }
742 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800744 }
745 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800747 }
748 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700751 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700752 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700753 }
754 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700755 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700756 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700757 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700758 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800759 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700760 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700761 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700762 }
763 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700764 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700765 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700766 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700767 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800768 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800769 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700770 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800771 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500772 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700773 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500774 }
Rekha Kumar07366812015-03-24 16:42:31 -0700775 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700776 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700777 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700778 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700780 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700781 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700782 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700783 }
Bryce Lee81901682015-08-28 16:38:02 -0700784 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700785 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700786 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700787 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700788 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700789 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530790 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
791 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
792 }
Bryce Lee81901682015-08-28 16:38:02 -0700793
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800794 builder.append("]");
795 return builder.toString();
796 }
797
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700798 /**
799 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
800 *
801 * @param properties A property bit field.
802 * @return A human readable string representation.
803 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700804 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700805 return propertiesToStringInternal(properties, true /* isLong */);
806 }
807
808 /**
809 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
810 *
811 * @param properties A property bit field.
812 * @return A human readable string representation.
813 * @hide
814 */
815 public static String propertiesToStringShort(int properties) {
816 return propertiesToStringInternal(properties, false /* isLong */);
817 }
818
819 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700820 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700821 builder.append("[");
822 if (isLong) {
823 builder.append("Properties:");
824 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700825
Tyler Gunnf5035432017-01-09 09:43:12 -0800826 if (can(properties, PROPERTY_SELF_MANAGED)) {
827 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
828 }
829
Hall Liu25c7c4d2016-08-30 13:41:02 -0700830 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
831 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700832 }
833
834 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700835 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700836 }
837
838 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700839 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700840 }
841
842 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700843 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700844 }
845
846 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700847 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700848 }
849
Brad Ebinger15847072016-05-18 11:08:36 -0700850 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700851 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700852 }
853
Hall Liud4d2a8a2018-01-29 17:22:02 -0800854 if (can(properties, PROPERTY_IS_RTT)) {
855 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
856 }
857
Tyler Gunn5bd90852018-09-21 09:37:07 -0700858 if (can(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
859 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
860 }
861
Tyler Gunnac60f952019-05-31 07:23:16 -0700862 if (can(properties, PROPERTY_REMOTELY_HOSTED)) {
863 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
864 }
865
Tyler Gunn720c6642016-03-22 09:02:47 -0700866 builder.append("]");
867 return builder.toString();
868 }
869
Sailesh Nepal091768c2014-06-30 15:15:23 -0700870 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700871 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700872 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700873 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700874 public void onCallerDisplayNameChanged(
875 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700876 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700877 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700878 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800879 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700880 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700881 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800882 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700883 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800884 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 public void onVideoProviderChanged(
886 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700887 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
888 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800889 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700890 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700891 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700892 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800893 public void onConferenceParticipantsChanged(Connection c,
894 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800895 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700896 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700897 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700898 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700899 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700900 /** @hide */
901 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800902 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800903 public void onRttInitiationSuccess(Connection c) {}
904 public void onRttInitiationFailure(Connection c, int reason) {}
905 public void onRttSessionRemotelyTerminated(Connection c) {}
906 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530907 /** @hide */
908 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800909 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700910 }
911
Tyler Gunnb702ef82015-05-29 11:51:53 -0700912 /**
Hall Liu95d55872017-01-25 17:12:49 -0800913 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800914 */
915 public static final class RttTextStream {
916 private static final int READ_BUFFER_SIZE = 1000;
917 private final InputStreamReader mPipeFromInCall;
918 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800919 private final ParcelFileDescriptor mFdFromInCall;
920 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700921
922 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800923 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
924
925 /**
926 * @hide
927 */
928 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800929 mFdFromInCall = fromInCall;
930 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700931 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700932
933 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800934 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700935 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800936 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800937 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800938 }
939
940 /**
941 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
942 * RTT transmits text in real-time, this method should be called as often as text snippets
943 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800944 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800945 * This method is not thread-safe -- calling it from multiple threads simultaneously may
946 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800947 *
Hall Liu95d55872017-01-25 17:12:49 -0800948 * @param input The message to send to the in-call app.
949 */
950 public void write(String input) throws IOException {
951 mPipeToInCall.write(input);
952 mPipeToInCall.flush();
953 }
954
955
956 /**
957 * Reads a string from the in-call app, blocking if there is no data available. Returns
958 * {@code null} if the RTT conversation has been terminated and there is no further data
959 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800960 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800961 * This method is not thread-safe -- calling it from multiple threads simultaneously may
962 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800963 *
Hall Liu95d55872017-01-25 17:12:49 -0800964 * @return A string containing text entered by the user, or {@code null} if the
965 * conversation has been terminated or if there was an error while reading.
966 */
Hall Liuffa4a812017-03-02 16:11:00 -0800967 public String read() throws IOException {
968 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
969 if (numRead < 0) {
970 return null;
971 }
972 return new String(mReadBuffer, 0, numRead);
973 }
974
975 /**
976 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
977 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800978 *
Hall Liuffa4a812017-03-02 16:11:00 -0800979 * @return A string containing text entered by the user, or {@code null} if the user has
980 * not entered any new text yet.
981 */
982 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700983 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800984 return read();
985 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800986 return null;
987 }
988 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800989
990 /** @hide */
991 public ParcelFileDescriptor getFdFromInCall() {
992 return mFdFromInCall;
993 }
994
995 /** @hide */
996 public ParcelFileDescriptor getFdToInCall() {
997 return mFdToInCall;
998 }
999 }
1000
1001 /**
1002 * Provides constants to represent the results of responses to session modify requests sent via
1003 * {@link Call#sendRttRequest()}
1004 */
1005 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001006 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001007 /**
1008 * Session modify request was successful.
1009 */
1010 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1011
1012 /**
1013 * Session modify request failed.
1014 */
1015 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1016
1017 /**
1018 * Session modify request ignored due to invalid parameters.
1019 */
1020 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1021
1022 /**
1023 * Session modify request timed out.
1024 */
1025 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1026
1027 /**
1028 * Session modify request rejected by remote user.
1029 */
1030 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001031 }
1032
1033 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001034 * Provides a means of controlling the video session associated with a {@link Connection}.
1035 * <p>
1036 * Implementations create a custom subclass of {@link VideoProvider} and the
1037 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1038 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1039 * should set the {@link VideoProvider}.
1040 * <p>
1041 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1042 * {@link InCallService} implementations to issue requests related to the video session;
1043 * it provides a means for the {@link ConnectionService} to report events and information
1044 * related to the video session to Telecom and the {@link InCallService} implementations.
1045 * <p>
1046 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1047 * {@link android.telecom.InCallService.VideoCall}.
1048 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 /**
1051 * Video is not being received (no protocol pause was issued).
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_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001055
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001057 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1058 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059 */
1060 public static final int SESSION_EVENT_RX_RESUME = 2;
1061
1062 /**
1063 * Video transmission has begun. This occurs after a negotiated start of video transmission
1064 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001065 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 */
1067 public static final int SESSION_EVENT_TX_START = 3;
1068
1069 /**
1070 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1071 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001072 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073 */
1074 public static final int SESSION_EVENT_TX_STOP = 4;
1075
1076 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001077 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001078 * this as a cue to inform the user the camera is not available.
1079 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001080 */
1081 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1082
1083 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001084 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001085 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001086 * the camera has become available again.
1087 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 */
1089 public static final int SESSION_EVENT_CAMERA_READY = 6;
1090
1091 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001092 * Session event raised by Telecom when
1093 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1094 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1095 * @see #handleCallSessionEvent(int)
1096 */
1097 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1098
1099 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001100 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001101 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 */
1103 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1104
1105 /**
1106 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001107 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 */
1109 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1110
1111 /**
1112 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001113 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 */
1115 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1116
Rekha Kumar07366812015-03-24 16:42:31 -07001117 /**
1118 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001119 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001120 */
1121 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1122
1123 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001124 * Session modify request rejected by remote user.
1125 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001126 */
1127 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1128
Tyler Gunn75958422015-04-15 14:23:42 -07001129 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 private static final int MSG_SET_CAMERA = 2;
1131 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1132 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1133 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1134 private static final int MSG_SET_ZOOM = 6;
1135 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1136 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1137 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001138 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001139 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001140 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001142 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1143 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1144 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1145 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1146 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1147 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001148 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1149 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001150 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1151
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001152 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001154
1155 /**
1156 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001157 *
1158 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1159 * load factor before resizing, 1 means we only expect a single thread to
1160 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001161 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001162 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1163 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164
1165 /**
1166 * Default handler used to consolidate binder method calls onto a single thread.
1167 */
1168 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001169 public VideoProviderHandler() {
1170 super();
1171 }
1172
1173 public VideoProviderHandler(Looper looper) {
1174 super(looper);
1175 }
1176
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 @Override
1178 public void handleMessage(Message msg) {
1179 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001180 case MSG_ADD_VIDEO_CALLBACK: {
1181 IBinder binder = (IBinder) msg.obj;
1182 IVideoCallback callback = IVideoCallback.Stub
1183 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001184 if (callback == null) {
1185 Log.w(this, "addVideoProvider - skipped; callback is null.");
1186 break;
1187 }
1188
Tyler Gunn75958422015-04-15 14:23:42 -07001189 if (mVideoCallbacks.containsKey(binder)) {
1190 Log.i(this, "addVideoProvider - skipped; already present.");
1191 break;
1192 }
1193 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001194 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001195 }
1196 case MSG_REMOVE_VIDEO_CALLBACK: {
1197 IBinder binder = (IBinder) msg.obj;
1198 IVideoCallback callback = IVideoCallback.Stub
1199 .asInterface((IBinder) msg.obj);
1200 if (!mVideoCallbacks.containsKey(binder)) {
1201 Log.i(this, "removeVideoProvider - skipped; not present.");
1202 break;
1203 }
1204 mVideoCallbacks.remove(binder);
1205 break;
1206 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001207 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001208 {
1209 SomeArgs args = (SomeArgs) msg.obj;
1210 try {
1211 onSetCamera((String) args.arg1);
1212 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001213 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001214 } finally {
1215 args.recycle();
1216 }
1217 }
1218 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001219 case MSG_SET_PREVIEW_SURFACE:
1220 onSetPreviewSurface((Surface) msg.obj);
1221 break;
1222 case MSG_SET_DISPLAY_SURFACE:
1223 onSetDisplaySurface((Surface) msg.obj);
1224 break;
1225 case MSG_SET_DEVICE_ORIENTATION:
1226 onSetDeviceOrientation(msg.arg1);
1227 break;
1228 case MSG_SET_ZOOM:
1229 onSetZoom((Float) msg.obj);
1230 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001231 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1232 SomeArgs args = (SomeArgs) msg.obj;
1233 try {
1234 onSendSessionModifyRequest((VideoProfile) args.arg1,
1235 (VideoProfile) args.arg2);
1236 } finally {
1237 args.recycle();
1238 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001239 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001240 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001241 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1242 onSendSessionModifyResponse((VideoProfile) msg.obj);
1243 break;
1244 case MSG_REQUEST_CAMERA_CAPABILITIES:
1245 onRequestCameraCapabilities();
1246 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001247 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1248 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001249 break;
1250 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001251 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001252 break;
1253 default:
1254 break;
1255 }
1256 }
1257 }
1258
1259 /**
1260 * IVideoProvider stub implementation.
1261 */
1262 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001263 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001265 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1266 }
1267
1268 public void removeVideoCallback(IBinder videoCallbackBinder) {
1269 mMessageHandler.obtainMessage(
1270 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 }
1272
Tyler Gunn159f35c2017-03-02 09:28:37 -08001273 public void setCamera(String cameraId, String callingPackageName,
1274 int targetSdkVersion) {
1275
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001276 SomeArgs args = SomeArgs.obtain();
1277 args.arg1 = cameraId;
1278 // Propagate the calling package; originally determined in
1279 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1280 // process.
1281 args.arg2 = callingPackageName;
1282 // Pass along the uid and pid of the calling app; this gets lost when we put the
1283 // message onto the handler. These are required for Telecom to perform a permission
1284 // check to see if the calling app is able to use the camera.
1285 args.argi1 = Binder.getCallingUid();
1286 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001287 // Pass along the target SDK version of the calling InCallService. This is used to
1288 // maintain backwards compatibility of the API for older callers.
1289 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001290 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 }
1292
1293 public void setPreviewSurface(Surface surface) {
1294 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1295 }
1296
1297 public void setDisplaySurface(Surface surface) {
1298 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1299 }
1300
1301 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001302 mMessageHandler.obtainMessage(
1303 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 }
1305
1306 public void setZoom(float value) {
1307 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1308 }
1309
Tyler Gunn45382162015-05-06 08:52:27 -07001310 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1311 SomeArgs args = SomeArgs.obtain();
1312 args.arg1 = fromProfile;
1313 args.arg2 = toProfile;
1314 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 }
1316
1317 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1318 mMessageHandler.obtainMessage(
1319 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1320 }
1321
1322 public void requestCameraCapabilities() {
1323 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1324 }
1325
1326 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001327 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001328 }
1329
Yorke Lee32f24732015-05-12 16:18:03 -07001330 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1332 }
1333 }
1334
1335 public VideoProvider() {
1336 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001337 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001338 }
1339
1340 /**
1341 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1342 *
1343 * @param looper The looper.
1344 * @hide
1345 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001346 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001347 public VideoProvider(Looper looper) {
1348 mBinder = new VideoProvider.VideoProviderBinder();
1349 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 }
1351
1352 /**
1353 * Returns binder object which can be used across IPC methods.
1354 * @hide
1355 */
1356 public final IVideoProvider getInterface() {
1357 return mBinder;
1358 }
1359
1360 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001361 * Sets the camera to be used for the outgoing video.
1362 * <p>
1363 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1364 * camera via
1365 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1366 * <p>
1367 * Sent from the {@link InCallService} via
1368 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001369 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001370 * @param cameraId The id of the camera (use ids as reported by
1371 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 */
1373 public abstract void onSetCamera(String cameraId);
1374
1375 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001376 * Sets the camera to be used for the outgoing video.
1377 * <p>
1378 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1379 * camera via
1380 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1381 * <p>
1382 * This prototype is used internally to ensure that the calling package name, UID and PID
1383 * are sent to Telecom so that can perform a camera permission check on the caller.
1384 * <p>
1385 * Sent from the {@link InCallService} via
1386 * {@link InCallService.VideoCall#setCamera(String)}.
1387 *
1388 * @param cameraId The id of the camera (use ids as reported by
1389 * {@link CameraManager#getCameraIdList()}).
1390 * @param callingPackageName The AppOpps package name of the caller.
1391 * @param callingUid The UID of the caller.
1392 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001393 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001394 * @hide
1395 */
1396 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001397 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001398
1399 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 * Sets the surface to be used for displaying a preview of what the user's camera is
1401 * currently capturing. When video transmission is enabled, this is the video signal which
1402 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001403 * <p>
1404 * Sent from the {@link InCallService} via
1405 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001407 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408 */
1409 public abstract void onSetPreviewSurface(Surface surface);
1410
1411 /**
1412 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001413 * <p>
1414 * Sent from the {@link InCallService} via
1415 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001416 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001417 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 */
1419 public abstract void onSetDisplaySurface(Surface surface);
1420
1421 /**
1422 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1423 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001424 * <p>
1425 * Sent from the {@link InCallService} via
1426 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 *
1428 * @param rotation The device orientation, in degrees.
1429 */
1430 public abstract void onSetDeviceOrientation(int rotation);
1431
1432 /**
1433 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001434 * <p>
1435 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 *
1437 * @param value The camera zoom ratio.
1438 */
1439 public abstract void onSetZoom(float value);
1440
1441 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001442 * Issues a request to modify the properties of the current video session.
1443 * <p>
1444 * Example scenarios include: requesting an audio-only call to be upgraded to a
1445 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1446 * when the {@link InCallService} is no longer the foreground application.
1447 * <p>
1448 * If the {@link VideoProvider} determines a request to be invalid, it should call
1449 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1450 * invalid request back to the {@link InCallService}.
1451 * <p>
1452 * Where a request requires confirmation from the user of the peer device, the
1453 * {@link VideoProvider} must communicate the request to the peer device and handle the
1454 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1455 * is used to inform the {@link InCallService} of the result of the request.
1456 * <p>
1457 * Sent from the {@link InCallService} via
1458 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 * @param fromProfile The video profile prior to the request.
1461 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 */
Tyler Gunn45382162015-05-06 08:52:27 -07001463 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1464 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465
Tyler Gunnb702ef82015-05-29 11:51:53 -07001466 /**
1467 * Provides a response to a request to change the current video session properties.
1468 * <p>
1469 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1470 * video call, could decline the request and keep the call as audio-only.
1471 * In such a scenario, the {@code responseProfile} would have a video state of
1472 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1473 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1474 * <p>
1475 * Sent from the {@link InCallService} via
1476 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1477 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1478 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001480 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 */
1482 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1483
1484 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001485 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1486 * <p>
1487 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1488 * camera via
1489 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1490 * <p>
1491 * Sent from the {@link InCallService} via
1492 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 */
1494 public abstract void onRequestCameraCapabilities();
1495
1496 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001497 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1498 * video component of the current {@link Connection}.
1499 * <p>
1500 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1501 * via {@link VideoProvider#setCallDataUsage(long)}.
1502 * <p>
1503 * Sent from the {@link InCallService} via
1504 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001505 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001506 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001507
1508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001509 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1510 * the peer device when the video signal is paused.
1511 * <p>
1512 * Sent from the {@link InCallService} via
1513 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001514 *
1515 * @param uri URI of image to display.
1516 */
Yorke Lee32f24732015-05-12 16:18:03 -07001517 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001518
1519 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001520 * Used to inform listening {@link InCallService} implementations when the
1521 * {@link VideoProvider} receives a session modification request.
1522 * <p>
1523 * Received by the {@link InCallService} via
1524 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001526 * @param videoProfile The requested video profile.
1527 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 */
1529 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001530 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001531 for (IVideoCallback callback : mVideoCallbacks.values()) {
1532 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001533 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001534 } catch (RemoteException ignored) {
1535 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001536 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 }
1538 }
1539 }
1540
1541 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001542 * Used to inform listening {@link InCallService} implementations when the
1543 * {@link VideoProvider} receives a response to a session modification request.
1544 * <p>
1545 * Received by the {@link InCallService} via
1546 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1547 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 *
1549 * @param status Status of the session modify request. Valid values are
1550 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1551 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001552 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1553 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1554 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1555 * @param requestedProfile The original request which was sent to the peer device.
1556 * @param responseProfile The actual profile changes agreed to by the peer device.
1557 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 */
1559 public void receiveSessionModifyResponse(int status,
1560 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001561 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001562 for (IVideoCallback callback : mVideoCallbacks.values()) {
1563 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001564 callback.receiveSessionModifyResponse(status, requestedProfile,
1565 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001566 } catch (RemoteException ignored) {
1567 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001568 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 }
1570 }
1571 }
1572
1573 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001574 * Used to inform listening {@link InCallService} implementations when the
1575 * {@link VideoProvider} reports a call session event.
1576 * <p>
1577 * Received by the {@link InCallService} via
1578 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001579 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001580 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1581 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1582 * {@link VideoProvider#SESSION_EVENT_TX_START},
1583 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1584 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001585 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1586 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001587 */
1588 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001589 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001590 for (IVideoCallback callback : mVideoCallbacks.values()) {
1591 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001592 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001593 } catch (RemoteException ignored) {
1594 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001595 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001596 }
1597 }
1598 }
1599
1600 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001601 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1602 * peer's video have changed.
1603 * <p>
1604 * This could occur if, for example, the peer rotates their device, changing the aspect
1605 * ratio of the video, or if the user switches between the back and front cameras.
1606 * <p>
1607 * Received by the {@link InCallService} via
1608 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 *
1610 * @param width The updated peer video width.
1611 * @param height The updated peer video height.
1612 */
1613 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001614 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001615 for (IVideoCallback callback : mVideoCallbacks.values()) {
1616 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001617 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001618 } catch (RemoteException ignored) {
1619 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001620 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001621 }
1622 }
1623 }
1624
1625 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001626 * Used to inform listening {@link InCallService} implementations when the data usage of the
1627 * video associated with the current {@link Connection} has changed.
1628 * <p>
1629 * This could be in response to a preview request via
1630 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001631 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1632 * 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 -07001633 * <p>
1634 * Received by the {@link InCallService} via
1635 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001636 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001637 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1638 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001639 */
Yorke Lee32f24732015-05-12 16:18:03 -07001640 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001641 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001642 for (IVideoCallback callback : mVideoCallbacks.values()) {
1643 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001644 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001645 } catch (RemoteException ignored) {
1646 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001647 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 }
1649 }
1650 }
1651
1652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001653 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001655 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001656 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1657 * @hide
1658 */
1659 public void changeCallDataUsage(long dataUsage) {
1660 setCallDataUsage(dataUsage);
1661 }
1662
1663 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001664 * Used to inform listening {@link InCallService} implementations when the capabilities of
1665 * the current camera have changed.
1666 * <p>
1667 * The {@link VideoProvider} should call this in response to
1668 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1669 * changed via {@link VideoProvider#onSetCamera(String)}.
1670 * <p>
1671 * Received by the {@link InCallService} via
1672 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1673 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001674 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001675 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001676 */
Yorke Lee400470f2015-05-12 13:31:25 -07001677 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001678 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001679 for (IVideoCallback callback : mVideoCallbacks.values()) {
1680 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001681 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001682 } catch (RemoteException ignored) {
1683 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001684 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001685 }
1686 }
1687 }
Rekha Kumar07366812015-03-24 16:42:31 -07001688
1689 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001690 * Used to inform listening {@link InCallService} implementations when the video quality
1691 * of the call has changed.
1692 * <p>
1693 * Received by the {@link InCallService} via
1694 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001695 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001696 * @param videoQuality The updated video quality. Valid values:
1697 * {@link VideoProfile#QUALITY_HIGH},
1698 * {@link VideoProfile#QUALITY_MEDIUM},
1699 * {@link VideoProfile#QUALITY_LOW},
1700 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001701 */
1702 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001703 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001704 for (IVideoCallback callback : mVideoCallbacks.values()) {
1705 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001706 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001707 } catch (RemoteException ignored) {
1708 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001709 }
Rekha Kumar07366812015-03-24 16:42:31 -07001710 }
1711 }
1712 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001713
1714 /**
1715 * Returns a string representation of a call session event.
1716 *
1717 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1718 * @return String representation of the call session event.
1719 * @hide
1720 */
1721 public static String sessionEventToString(int event) {
1722 switch (event) {
1723 case SESSION_EVENT_CAMERA_FAILURE:
1724 return SESSION_EVENT_CAMERA_FAILURE_STR;
1725 case SESSION_EVENT_CAMERA_READY:
1726 return SESSION_EVENT_CAMERA_READY_STR;
1727 case SESSION_EVENT_RX_PAUSE:
1728 return SESSION_EVENT_RX_PAUSE_STR;
1729 case SESSION_EVENT_RX_RESUME:
1730 return SESSION_EVENT_RX_RESUME_STR;
1731 case SESSION_EVENT_TX_START:
1732 return SESSION_EVENT_TX_START_STR;
1733 case SESSION_EVENT_TX_STOP:
1734 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001735 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1736 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001737 default:
1738 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1739 }
1740 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001741 }
1742
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 private final Listener mConnectionDeathListener = new Listener() {
1744 @Override
1745 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001746 if (mConferenceables.remove(c)) {
1747 fireOnConferenceableConnectionsChanged();
1748 }
1749 }
1750 };
1751
1752 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1753 @Override
1754 public void onDestroyed(Conference c) {
1755 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001756 fireOnConferenceableConnectionsChanged();
1757 }
1758 }
1759 };
1760
Jay Shrauner229e3822014-08-15 09:23:07 -07001761 /**
1762 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1763 * load factor before resizing, 1 means we only expect a single thread to
1764 * access the map so make only a single shard
1765 */
1766 private final Set<Listener> mListeners = Collections.newSetFromMap(
1767 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001768 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1769 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001770 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001771
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001772 // The internal telecom call ID associated with this connection.
1773 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001774 // The PhoneAccountHandle associated with this connection.
1775 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001776 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001777 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001778 private Uri mAddress;
1779 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001780 private String mCallerDisplayName;
1781 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001782 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001783 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001784 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001785 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001786 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001787 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001788 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001789 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001790 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001791 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001792 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001793 private Conference mConference;
1794 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001795 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001796 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001797 /**
1798 * The direction of the connection; used where an existing connection is created and we need to
1799 * communicate to Telecom whether its incoming or outgoing.
1800 */
1801 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802
1803 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001804 * Tracks the key set for the extras bundle provided on the last invocation of
1805 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1806 * keys which were set previously but are no longer present in the replacement Bundle.
1807 */
1808 private Set<String> mPreviousExtraKeys;
1809
1810 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001811 * Create a new Connection.
1812 */
Santos Cordonf2951102014-07-20 19:06:29 -07001813 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001814
1815 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001816 * Returns the Telecom internal call ID associated with this connection. Should only be used
1817 * for debugging and tracing purposes.
1818 *
1819 * @return The Telecom call ID.
1820 * @hide
1821 */
1822 public final String getTelecomCallId() {
1823 return mTelecomCallId;
1824 }
1825
1826 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001827 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001828 */
Andrew Lee100e2932014-09-08 15:34:24 -07001829 public final Uri getAddress() {
1830 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001831 }
1832
1833 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001834 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001835 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001836 */
Andrew Lee100e2932014-09-08 15:34:24 -07001837 public final int getAddressPresentation() {
1838 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001839 }
1840
1841 /**
1842 * @return The caller display name (CNAP).
1843 */
1844 public final String getCallerDisplayName() {
1845 return mCallerDisplayName;
1846 }
1847
1848 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001849 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001850 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001851 */
1852 public final int getCallerDisplayNamePresentation() {
1853 return mCallerDisplayNamePresentation;
1854 }
1855
1856 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001857 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001858 */
1859 public final int getState() {
1860 return mState;
1861 }
1862
1863 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001864 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001865 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1866 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1867 * {@link VideoProfile#STATE_TX_ENABLED},
1868 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001869 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001870 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001871 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001872 */
1873 public final int getVideoState() {
1874 return mVideoState;
1875 }
1876
1877 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001878 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001879 * being routed by the system. This is {@code null} if this Connection
1880 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001881 * @deprecated Use {@link #getCallAudioState()} instead.
1882 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001883 */
Yorke Lee4af59352015-05-13 14:14:54 -07001884 @SystemApi
1885 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001886 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001887 if (mCallAudioState == null) {
1888 return null;
1889 }
Yorke Lee4af59352015-05-13 14:14:54 -07001890 return new AudioState(mCallAudioState);
1891 }
1892
1893 /**
1894 * @return The audio state of the connection, describing how its audio is currently
1895 * being routed by the system. This is {@code null} if this Connection
1896 * does not directly know about its audio state.
1897 */
1898 public final CallAudioState getCallAudioState() {
1899 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001900 }
1901
1902 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001903 * @return The conference that this connection is a part of. Null if it is not part of any
1904 * conference.
1905 */
1906 public final Conference getConference() {
1907 return mConference;
1908 }
1909
1910 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001911 * Returns whether this connection is requesting that the system play a ringback tone
1912 * on its behalf.
1913 */
Andrew Lee100e2932014-09-08 15:34:24 -07001914 public final boolean isRingbackRequested() {
1915 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001916 }
1917
1918 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001919 * @return True if the connection's audio mode is VOIP.
1920 */
1921 public final boolean getAudioModeIsVoip() {
1922 return mAudioModeIsVoip;
1923 }
1924
1925 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001926 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1927 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1928 * start time of the conference.
1929 *
1930 * @return The time at which the {@code Connnection} was connected.
1931 *
1932 * @hide
1933 */
1934 public final long getConnectTimeMillis() {
1935 return mConnectTimeMillis;
1936 }
1937
1938 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001939 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1940 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1941 * start time of the conference.
1942 *
1943 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1944 * changes do not impact the call duration.
1945 *
1946 * @return The time at which the {@link Connection} was connected.
1947 *
1948 * @hide
1949 */
1950 public final long getConnectElapsedTimeMillis() {
1951 return mConnectElapsedTimeMillis;
1952 }
1953
1954 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001955 * Returns RIL voice radio technology used for current connection.
1956 *
1957 * @return the RIL voice radio technology used for current connection,
1958 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1959 *
1960 * @hide
1961 */
Chen Xuf85cf992019-10-02 00:20:43 -07001962 public final @RilRadioTechnology int getCallRadioTech() {
Wei Huang7f7f72e2018-05-30 19:21:36 +08001963 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1964 Bundle extras = getExtras();
1965 if (extras != null) {
1966 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1967 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1968 }
1969 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1970 }
1971
1972 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001973 * @return The status hints for this connection.
1974 */
1975 public final StatusHints getStatusHints() {
1976 return mStatusHints;
1977 }
1978
1979 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001980 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001981 * <p>
1982 * Extras should be updated using {@link #putExtras(Bundle)}.
1983 * <p>
1984 * Telecom or an {@link InCallService} can also update the extras via
1985 * {@link android.telecom.Call#putExtras(Bundle)}, and
1986 * {@link Call#removeExtras(List)}.
1987 * <p>
1988 * The connection is notified of changes to the extras made by Telecom or an
1989 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001990 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001991 * @return The extras associated with this connection.
1992 */
1993 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001994 Bundle extras = null;
1995 synchronized (mExtrasLock) {
1996 if (mExtras != null) {
1997 extras = new Bundle(mExtras);
1998 }
1999 }
2000 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002001 }
2002
2003 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 * Assign a listener to be notified of state changes.
2005 *
2006 * @param l A listener.
2007 * @return This Connection.
2008 *
2009 * @hide
2010 */
2011 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002012 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002013 return this;
2014 }
2015
2016 /**
2017 * Remove a previously assigned listener that was being notified of state changes.
2018 *
2019 * @param l A Listener.
2020 * @return This Connection.
2021 *
2022 * @hide
2023 */
2024 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002025 if (l != null) {
2026 mListeners.remove(l);
2027 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002028 return this;
2029 }
2030
2031 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002032 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002033 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002034 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002035 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002036 }
2037
2038 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002039 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2040 * ONLY for debugging purposes.
2041 *
2042 * @param callId The telecom call ID.
2043 * @hide
2044 */
2045 public void setTelecomCallId(String callId) {
2046 mTelecomCallId = callId;
2047 }
2048
2049 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002050 * Inform this Connection that the state of its audio output has been changed externally.
2051 *
2052 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002053 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002054 */
Yorke Lee4af59352015-05-13 14:14:54 -07002055 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002056 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002057 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002058 mCallAudioState = state;
2059 onAudioStateChanged(getAudioState());
2060 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002061 }
2062
2063 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002064 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065 * @return A string representation of the value.
2066 */
2067 public static String stateToString(int state) {
2068 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002069 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002070 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002071 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002072 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002073 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002074 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002075 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002076 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002077 case STATE_PULLING_CALL:
2078 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002079 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002080 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002081 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002082 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002083 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084 return "DISCONNECTED";
2085 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002086 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 return "UNKNOWN";
2088 }
2089 }
2090
2091 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002092 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002093 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002094 public final int getConnectionCapabilities() {
2095 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002096 }
2097
2098 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002099 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2100 */
2101 public final int getConnectionProperties() {
2102 return mConnectionProperties;
2103 }
2104
2105 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002106 * Returns the connection's supported audio routes.
2107 *
2108 * @hide
2109 */
2110 public final int getSupportedAudioRoutes() {
2111 return mSupportedAudioRoutes;
2112 }
2113
2114 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002115 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116 *
Andrew Lee100e2932014-09-08 15:34:24 -07002117 * @param address The new address.
2118 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002119 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002120 */
Andrew Lee100e2932014-09-08 15:34:24 -07002121 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002122 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002123 Log.d(this, "setAddress %s", address);
2124 mAddress = address;
2125 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002126 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002127 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002128 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002129 }
2130
2131 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002132 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002133 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002134 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002135 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002136 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002137 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002138 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002139 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002140 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002141 mCallerDisplayName = callerDisplayName;
2142 mCallerDisplayNamePresentation = presentation;
2143 for (Listener l : mListeners) {
2144 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2145 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002146 }
2147
2148 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002149 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002150 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2151 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2152 * {@link VideoProfile#STATE_TX_ENABLED},
2153 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002154 *
2155 * @param videoState The new video state.
2156 */
2157 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002158 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002159 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002160 mVideoState = videoState;
2161 for (Listener l : mListeners) {
2162 l.onVideoStateChanged(this, mVideoState);
2163 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002164 }
2165
2166 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002167 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002168 * communicate).
2169 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002170 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002171 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002172 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002173 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002174 }
2175
2176 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002178 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002179 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002180 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002181 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002182 }
2183
2184 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002185 * Sets state to initializing (this Connection is not yet ready to be used).
2186 */
2187 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002188 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002189 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002190 }
2191
2192 /**
2193 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2194 */
2195 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002196 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002197 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002198 }
2199
2200 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002202 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002203 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002204 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002205 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002206 }
2207
2208 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002209 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2210 * device). Only applicable for {@link Connection}s with
2211 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2212 */
2213 public final void setPulling() {
2214 checkImmutable();
2215 setState(STATE_PULLING_CALL);
2216 }
2217
2218 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002219 * Sets state to be on hold.
2220 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002221 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002222 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002223 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002224 }
2225
2226 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002227 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002228 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002229 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002230 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002231 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002232 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002233 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002235 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002236 }
2237
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002238 public final VideoProvider getVideoProvider() {
2239 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002240 }
2241
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002242 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002243 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002245 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002246 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002247 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002248 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002249 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002250 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002251 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002252 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002253 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002254 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002255 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002256 }
2257
2258 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002259 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2260 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2261 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2262 * to send an {@link #onPostDialContinue(boolean)} signal.
2263 *
2264 * @param remaining The DTMF character sequence remaining to be emitted once the
2265 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2266 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002267 */
2268 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002269 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002270 for (Listener l : mListeners) {
2271 l.onPostDialWait(this, remaining);
2272 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002273 }
2274
2275 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002276 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2277 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002278 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002279 *
2280 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002281 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002282 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002283 checkImmutable();
2284 for (Listener l : mListeners) {
2285 l.onPostDialChar(this, nextChar);
2286 }
2287 }
2288
2289 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002290 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002291 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002292 *
2293 * @param ringback Whether the ringback tone is to be played.
2294 */
Andrew Lee100e2932014-09-08 15:34:24 -07002295 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002296 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002297 if (mRingbackRequested != ringback) {
2298 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002299 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002300 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002301 }
2302 }
Ihab Awadf8358972014-05-28 16:46:42 -07002303 }
2304
2305 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002306 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002307 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002308 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002309 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002310 public final void setConnectionCapabilities(int connectionCapabilities) {
2311 checkImmutable();
2312 if (mConnectionCapabilities != connectionCapabilities) {
2313 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002314 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002315 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002316 }
2317 }
Santos Cordonb6939982014-06-04 20:20:58 -07002318 }
2319
2320 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002321 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2322 *
2323 * @param connectionProperties The new connection properties.
2324 */
2325 public final void setConnectionProperties(int connectionProperties) {
2326 checkImmutable();
2327 if (mConnectionProperties != connectionProperties) {
2328 mConnectionProperties = connectionProperties;
2329 for (Listener l : mListeners) {
2330 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2331 }
2332 }
2333 }
2334
2335 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002336 * Sets the supported audio routes.
2337 *
2338 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2339 * See {@link CallAudioState}
2340 * @hide
2341 */
2342 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2343 if ((supportedAudioRoutes
2344 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2345 throw new IllegalArgumentException(
2346 "supported audio routes must include either speaker or earpiece");
2347 }
2348
2349 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2350 mSupportedAudioRoutes = supportedAudioRoutes;
2351 for (Listener l : mListeners) {
2352 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2353 }
2354 }
2355 }
2356
2357 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002358 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002359 */
Evan Charlton36a71342014-07-19 16:31:02 -07002360 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002361 for (Listener l : mListeners) {
2362 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002363 }
Santos Cordonb6939982014-06-04 20:20:58 -07002364 }
2365
2366 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002367 * Requests that the framework use VOIP audio mode for this connection.
2368 *
2369 * @param isVoip True if the audio mode is VOIP.
2370 */
2371 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002372 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002373 mAudioModeIsVoip = isVoip;
2374 for (Listener l : mListeners) {
2375 l.onAudioModeIsVoipChanged(this, isVoip);
2376 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002377 }
2378
2379 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002380 * Sets the time at which a call became active on this Connection. This is set only
2381 * when a conference call becomes active on this connection.
2382 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002383 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2384 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002385 *
2386 * @hide
2387 */
2388 public final void setConnectTimeMillis(long connectTimeMillis) {
2389 mConnectTimeMillis = connectTimeMillis;
2390 }
2391
2392 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002393 * Sets the time at which a call became active on this Connection. This is set only
2394 * when a conference call becomes active on this connection.
2395 *
2396 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2397 * {@link SystemClock#elapsedRealtime()}.
2398 *
2399 * @hide
2400 */
Tyler Gunn17541392018-02-01 08:58:38 -08002401 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002402 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2403 }
2404
2405 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002406 * Sets RIL voice radio technology used for current connection.
2407 *
2408 * @param vrat the RIL Voice Radio Technology used for current connection,
2409 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2410 *
2411 * @hide
2412 */
Chen Xuf85cf992019-10-02 00:20:43 -07002413 public final void setCallRadioTech(@RilRadioTechnology int vrat) {
Wei Huang7f7f72e2018-05-30 19:21:36 +08002414 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
2415 ServiceState.rilRadioTechnologyToNetworkType(vrat));
2416 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2417 // This action only covers non-IMS CS conference calls.
2418 // For IMS PS call conference call, it can be updated via its host connection
2419 // {@link #Listener.onExtrasChanged} event.
2420 if (getConference() != null) {
2421 getConference().setCallRadioTech(vrat);
2422 }
2423 }
2424
2425 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002426 * Sets the label and icon status to display in the in-call UI.
2427 *
2428 * @param statusHints The status label and icon to set.
2429 */
2430 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002431 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002432 mStatusHints = statusHints;
2433 for (Listener l : mListeners) {
2434 l.onStatusHintsChanged(this, statusHints);
2435 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002436 }
2437
2438 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002439 * Sets the connections with which this connection can be conferenced.
2440 *
2441 * @param conferenceableConnections The set of connections this connection can conference with.
2442 */
2443 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002444 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002445 clearConferenceableList();
2446 for (Connection c : conferenceableConnections) {
2447 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2448 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002449 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002450 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002451 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002452 }
2453 }
2454 fireOnConferenceableConnectionsChanged();
2455 }
2456
2457 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002458 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2459 * or conferences with which this connection can be conferenced.
2460 *
2461 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002462 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002463 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002464 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002465 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002466 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2467 // small amount of items here.
2468 if (!mConferenceables.contains(c)) {
2469 if (c instanceof Connection) {
2470 Connection connection = (Connection) c;
2471 connection.addConnectionListener(mConnectionDeathListener);
2472 } else if (c instanceof Conference) {
2473 Conference conference = (Conference) c;
2474 conference.addListener(mConferenceDeathListener);
2475 }
2476 mConferenceables.add(c);
2477 }
2478 }
2479 fireOnConferenceableConnectionsChanged();
2480 }
2481
2482 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002483 * @hide
2484 * Resets the cdma connection time.
2485 */
2486 public final void resetConnectionTime() {
2487 for (Listener l : mListeners) {
2488 l.onConnectionTimeReset(this);
2489 }
2490 }
2491
2492 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002493 * Returns the connections or conferences with which this connection can be conferenced.
2494 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002495 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002496 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002497 }
2498
Yorke Lee53463962015-08-04 16:07:19 -07002499 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002500 * @hide
2501 */
2502 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002503 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002504 if (mConnectionService != null) {
2505 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2506 "which is already associated with another ConnectionService.");
2507 } else {
2508 mConnectionService = connectionService;
2509 }
2510 }
2511
2512 /**
2513 * @hide
2514 */
2515 public final void unsetConnectionService(ConnectionService connectionService) {
2516 if (mConnectionService != connectionService) {
2517 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2518 "that does not belong to the ConnectionService.");
2519 } else {
2520 mConnectionService = null;
2521 }
2522 }
2523
2524 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002525 * @hide
2526 */
2527 public final ConnectionService getConnectionService() {
2528 return mConnectionService;
2529 }
2530
2531 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002532 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002533 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002534 *
2535 * @param conference The conference.
2536 * @return {@code true} if the conference was successfully set.
2537 * @hide
2538 */
2539 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002540 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002541 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002542 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002543 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002544 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2545 fireConferenceChanged();
2546 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002547 return true;
2548 }
2549 return false;
2550 }
2551
2552 /**
2553 * Resets the conference that this connection is a part of.
2554 * @hide
2555 */
2556 public final void resetConference() {
2557 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002558 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002559 mConference = null;
2560 fireConferenceChanged();
2561 }
2562 }
2563
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002564 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002565 * Set some extras that can be associated with this {@code Connection}.
2566 * <p>
2567 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2568 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2569 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002570 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2571 * {@link #removeExtras(String...)} methods to modify the extras.
2572 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002573 * 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 -07002574 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2575 *
2576 * @param extras The extras associated with this {@code Connection}.
2577 */
2578 public final void setExtras(@Nullable Bundle extras) {
2579 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002580
2581 // Add/replace any new or changed extras values.
2582 putExtras(extras);
2583
2584 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2585 // the current one and remove any keys that went away.
2586 if (mPreviousExtraKeys != null) {
2587 List<String> toRemove = new ArrayList<String>();
2588 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002589 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002590 toRemove.add(oldKey);
2591 }
2592 }
2593 if (!toRemove.isEmpty()) {
2594 removeExtras(toRemove);
2595 }
2596 }
2597
2598 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2599 // called we can see if the caller has removed any extras values.
2600 if (mPreviousExtraKeys == null) {
2601 mPreviousExtraKeys = new ArraySet<String>();
2602 }
2603 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002604 if (extras != null) {
2605 mPreviousExtraKeys.addAll(extras.keySet());
2606 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002607 }
2608
2609 /**
2610 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2611 * added.
2612 * <p>
2613 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2614 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2615 *
2616 * @param extras The extras to add.
2617 */
2618 public final void putExtras(@NonNull Bundle extras) {
2619 checkImmutable();
2620 if (extras == null) {
2621 return;
2622 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002623 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2624 // the listeners.
2625 Bundle listenerExtras;
2626 synchronized (mExtrasLock) {
2627 if (mExtras == null) {
2628 mExtras = new Bundle();
2629 }
2630 mExtras.putAll(extras);
2631 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002632 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002633 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002634 // Create a new clone of the extras for each listener so that they don't clobber
2635 // each other
2636 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002637 }
2638 }
2639
2640 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002641 * Adds a boolean extra to this {@code Connection}.
2642 *
2643 * @param key The extra key.
2644 * @param value The value.
2645 * @hide
2646 */
2647 public final void putExtra(String key, boolean value) {
2648 Bundle newExtras = new Bundle();
2649 newExtras.putBoolean(key, value);
2650 putExtras(newExtras);
2651 }
2652
2653 /**
2654 * Adds an integer extra to this {@code Connection}.
2655 *
2656 * @param key The extra key.
2657 * @param value The value.
2658 * @hide
2659 */
2660 public final void putExtra(String key, int value) {
2661 Bundle newExtras = new Bundle();
2662 newExtras.putInt(key, value);
2663 putExtras(newExtras);
2664 }
2665
2666 /**
2667 * Adds a string extra to this {@code Connection}.
2668 *
2669 * @param key The extra key.
2670 * @param value The value.
2671 * @hide
2672 */
2673 public final void putExtra(String key, String value) {
2674 Bundle newExtras = new Bundle();
2675 newExtras.putString(key, value);
2676 putExtras(newExtras);
2677 }
2678
2679 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002680 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002681 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002682 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002683 */
2684 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002685 synchronized (mExtrasLock) {
2686 if (mExtras != null) {
2687 for (String key : keys) {
2688 mExtras.remove(key);
2689 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002690 }
2691 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002692 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002693 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002694 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002695 }
2696 }
2697
2698 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002699 * Removes extras from this {@code Connection}.
2700 *
2701 * @param keys The keys of the extras to remove.
2702 */
2703 public final void removeExtras(String ... keys) {
2704 removeExtras(Arrays.asList(keys));
2705 }
2706
2707 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002708 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2709 * be change to the {@link #getCallAudioState()}.
2710 * <p>
2711 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2712 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2713 * <p>
2714 * See also {@link InCallService#setAudioRoute(int)}.
2715 *
2716 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2717 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2718 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2719 */
2720 public final void setAudioRoute(int route) {
2721 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002722 l.onAudioRouteChanged(this, route, null);
2723 }
2724 }
2725
2726 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002727 * Request audio routing to a specific bluetooth device. Calling this method may result in
2728 * the device routing audio to a different bluetooth device than the one specified if the
2729 * bluetooth stack is unable to route audio to the requested device.
2730 * A list of available devices can be obtained via
2731 * {@link CallAudioState#getSupportedBluetoothDevices()}
2732 *
2733 * <p>
2734 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2735 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2736 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002737 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2738 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002739 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002740 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002741 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002742 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2743 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002744 }
2745 }
2746
2747 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002748 * Informs listeners that a previously requested RTT session via
2749 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002750 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002751 */
2752 public final void sendRttInitiationSuccess() {
2753 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2754 }
2755
2756 /**
2757 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002758 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002759 * has failed.
2760 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2761 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002762 */
2763 public final void sendRttInitiationFailure(int reason) {
2764 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2765 }
2766
2767 /**
2768 * Informs listeners that a currently active RTT session has been terminated by the remote
2769 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002770 */
2771 public final void sendRttSessionRemotelyTerminated() {
2772 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2773 }
2774
2775 /**
2776 * Informs listeners that the remote side of the call has requested an upgrade to include an
2777 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002778 */
2779 public final void sendRemoteRttRequest() {
2780 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2781 }
2782
2783 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002784 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002785 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002786 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002787 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2788 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002789 */
Yorke Lee4af59352015-05-13 14:14:54 -07002790 @SystemApi
2791 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002792 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002793
2794 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002795 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2796 *
2797 * @param state The new connection audio state.
2798 */
2799 public void onCallAudioStateChanged(CallAudioState state) {}
2800
2801 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002802 * Notifies this Connection of an internal state change. This method is called after the
2803 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002804 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002805 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002806 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002807 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002808
2809 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002810 * Notifies this Connection of a request to play a DTMF tone.
2811 *
2812 * @param c A DTMF character.
2813 */
Santos Cordonf2951102014-07-20 19:06:29 -07002814 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002815
2816 /**
2817 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2818 */
Santos Cordonf2951102014-07-20 19:06:29 -07002819 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002820
2821 /**
2822 * Notifies this Connection of a request to disconnect.
2823 */
Santos Cordonf2951102014-07-20 19:06:29 -07002824 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002825
2826 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002827 * Notifies this Connection of a request to disconnect a participant of the conference managed
2828 * by the connection.
2829 *
2830 * @param endpoint the {@link Uri} of the participant to disconnect.
2831 * @hide
2832 */
2833 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2834
2835 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002836 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002837 */
Santos Cordonf2951102014-07-20 19:06:29 -07002838 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002839
2840 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002841 * Notifies this Connection of a request to abort.
2842 */
Santos Cordonf2951102014-07-20 19:06:29 -07002843 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002844
2845 /**
2846 * Notifies this Connection of a request to hold.
2847 */
Santos Cordonf2951102014-07-20 19:06:29 -07002848 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002849
2850 /**
2851 * Notifies this Connection of a request to exit a hold state.
2852 */
Santos Cordonf2951102014-07-20 19:06:29 -07002853 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002854
2855 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002856 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002857 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002858 * <p>
2859 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2860 * the default dialer's {@link InCallService}.
2861 * <p>
2862 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2863 * Telecom framework may request that the call is answered in the following circumstances:
2864 * <ul>
2865 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2866 * <li>A car mode {@link InCallService} is in use which has declared
2867 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2868 * {@link InCallService} will be able to see calls from self-managed
2869 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2870 * behalf.</li>
2871 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002872 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002873 */
Santos Cordonf2951102014-07-20 19:06:29 -07002874 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002875
2876 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002877 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002878 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002879 * <p>
2880 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2881 * the default dialer's {@link InCallService}.
2882 * <p>
2883 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2884 * Telecom framework may request that the call is answered in the following circumstances:
2885 * <ul>
2886 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2887 * <li>A car mode {@link InCallService} is in use which has declared
2888 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2889 * {@link InCallService} will be able to see calls from self-managed
2890 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2891 * behalf.</li>
2892 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002893 */
2894 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002895 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002896 }
2897
2898 /**
2899 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302900 * a request to deflect.
2901 */
2902 public void onDeflect(Uri address) {}
2903
2904 /**
2905 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002906 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002907 * <p>
2908 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2909 * the default dialer's {@link InCallService}.
2910 * <p>
2911 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2912 * Telecom framework may request that the call is rejected in the following circumstances:
2913 * <ul>
2914 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2915 * <li>A car mode {@link InCallService} is in use which has declared
2916 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2917 * {@link InCallService} will be able to see calls from self-managed
2918 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2919 * behalf.</li>
2920 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002921 */
Santos Cordonf2951102014-07-20 19:06:29 -07002922 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002923
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002924 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002925 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2926 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002927 */
2928 public void onReject(String replyMessage) {}
2929
2930 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002931 * Notifies this Connection of a request to silence the ringer.
2932 * <p>
2933 * The ringer may be silenced by any of the following methods:
2934 * <ul>
2935 * <li>{@link TelecomManager#silenceRinger()}</li>
2936 * <li>The user presses the volume-down button while a call is ringing.</li>
2937 * </ul>
2938 * <p>
2939 * Self-managed {@link ConnectionService} implementations should override this method in their
2940 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2941 * your app set the ringtone as part of the incoming call {@link Notification} (see
2942 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2943 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2944 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2945 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002946 */
2947 public void onSilence() {}
2948
2949 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002950 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2951 */
Santos Cordonf2951102014-07-20 19:06:29 -07002952 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002953
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002954 /**
2955 * Notifies this Connection of a request to pull an external call to the local device.
2956 * <p>
2957 * The {@link InCallService} issues a request to pull an external call to the local device via
2958 * {@link Call#pullExternalCall()}.
2959 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002960 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2961 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002962 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002963 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002964 */
2965 public void onPullExternalCall() {}
2966
2967 /**
2968 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2969 * <p>
2970 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2971 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002972 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2973 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2974 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2975 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2976 * not aware of.
2977 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002978 * See also {@link Call#sendCallEvent(String, Bundle)}.
2979 *
2980 * @param event The call event.
2981 * @param extras Extras associated with the call event.
2982 */
2983 public void onCallEvent(String event, Bundle extras) {}
2984
Tyler Gunndee56a82016-03-23 16:06:34 -07002985 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002986 * Notifies this {@link Connection} that a handover has completed.
2987 * <p>
2988 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2989 * Bundle)} on the initiating side of the handover, and
2990 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2991 */
2992 public void onHandoverComplete() {}
2993
2994 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002995 * Notifies this {@link Connection} of a change to the extras made outside the
2996 * {@link ConnectionService}.
2997 * <p>
2998 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2999 * the {@link android.telecom.Call#putExtras(Bundle)} and
3000 * {@link Call#removeExtras(List)}.
3001 *
3002 * @param extras The new extras bundle.
3003 */
3004 public void onExtrasChanged(Bundle extras) {}
3005
Tyler Gunnf5035432017-01-09 09:43:12 -08003006 /**
3007 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3008 * displaying its incoming call user interface for the {@link Connection}.
3009 * <p>
3010 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3011 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3012 * should show its own incoming call user interface.
3013 * <p>
3014 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003015 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3016 * Telecom framework will display its own incoming call user interface to allow the user to
3017 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3018 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003019 * <p>
3020 * You should trigger the display of the incoming call user interface for your application by
3021 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003022 *
3023 * In your application code, you should create a {@link android.app.NotificationChannel} for
3024 * incoming call notifications from your app:
3025 * <pre><code>
3026 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3027 * NotificationManager.IMPORTANCE_MAX);
3028 * // other channel setup stuff goes here.
3029 *
3030 * // We'll use the default system ringtone for our incoming call notification channel. You can
3031 * // use your own audio resource here.
3032 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3033 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3034 * // Setting the AudioAttributes is important as it identifies the purpose of your
3035 * // notification sound.
3036 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3037 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3038 * .build());
3039 *
3040 * NotificationManager mgr = getSystemService(NotificationManager.class);
3041 * mgr.createNotificationChannel(channel);
3042 * </code></pre>
3043 * When it comes time to post a notification for your incoming call, ensure it uses your
3044 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003045 * <pre><code>
3046 * // Create an intent which triggers your fullscreen incoming call user interface.
3047 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3048 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3049 * intent.setClass(context, YourIncomingCallActivity.class);
3050 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3051 *
3052 * // Build the notification as an ongoing high priority item; this ensures it will show as
3053 * // a heads up notification which slides down over top of the current content.
3054 * final Notification.Builder builder = new Notification.Builder(context);
3055 * builder.setOngoing(true);
3056 * builder.setPriority(Notification.PRIORITY_HIGH);
3057 *
3058 * // Set notification content intent to take user to fullscreen UI if user taps on the
3059 * // notification body.
3060 * builder.setContentIntent(pendingIntent);
3061 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3062 * // manager deems it appropriate.
3063 * builder.setFullScreenIntent(pendingIntent, true);
3064 *
3065 * // Setup notification content.
3066 * builder.setSmallIcon( yourIconResourceId );
3067 * builder.setContentTitle("Your notification title");
3068 * builder.setContentText("Your notification content.");
3069 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003070 * // Set notification as insistent to cause your ringtone to loop.
3071 * Notification notification = builder.build();
3072 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003073 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003074 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003075 * NotificationManager notificationManager = mContext.getSystemService(
3076 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003077 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003078 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003079 */
3080 public void onShowIncomingCallUi() {}
3081
Hall Liub64ac4c2017-02-06 10:49:48 -08003082 /**
3083 * Notifies this {@link Connection} that the user has requested an RTT session.
3084 * The connection service should call {@link #sendRttInitiationSuccess} or
3085 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3086 * request, respectively.
3087 * @param rttTextStream The object that should be used to send text to or receive text from
3088 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003089 */
3090 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3091
3092 /**
3093 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3094 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003095 */
3096 public void onStopRtt() {}
3097
3098 /**
3099 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3100 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3101 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3102 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003103 * @param rttTextStream The object that should be used to send text to or receive text from
3104 * the in-call app.
3105 */
3106 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3107
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003108 static String toLogSafePhoneNumber(String number) {
3109 // For unknown number, log empty string.
3110 if (number == null) {
3111 return "";
3112 }
3113
3114 if (PII_DEBUG) {
3115 // When PII_DEBUG is true we emit PII.
3116 return number;
3117 }
3118
3119 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3120 // sanitized phone numbers.
3121 StringBuilder builder = new StringBuilder();
3122 for (int i = 0; i < number.length(); i++) {
3123 char c = number.charAt(i);
3124 if (c == '-' || c == '@' || c == '.') {
3125 builder.append(c);
3126 } else {
3127 builder.append('x');
3128 }
3129 }
3130 return builder.toString();
3131 }
3132
Ihab Awad542e0ea2014-05-16 10:22:16 -07003133 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003134 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003135 if (mState == STATE_DISCONNECTED && mState != state) {
3136 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003137 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003138 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003139 if (mState != state) {
3140 Log.d(this, "setState: %s", stateToString(state));
3141 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003142 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003143 for (Listener l : mListeners) {
3144 l.onStateChanged(this, state);
3145 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003146 }
3147 }
3148
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003149 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003150 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003151 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3152 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003153 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003154 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003155
3156 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003157 if (mImmutable) {
3158 throw new UnsupportedOperationException("Connection is immutable");
3159 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003160 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003161 }
3162
Evan Charltonbf11f982014-07-20 22:06:28 -07003163 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003164 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003165 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3166 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003167 * <p>
3168 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3169 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003170 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003171 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003172 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003173 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003174 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3175 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003176 }
3177
Evan Charltonbf11f982014-07-20 22:06:28 -07003178 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003179 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3180 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3181 * this should never be un-@hide-den.
3182 *
3183 * @hide
3184 */
3185 public void checkImmutable() {}
3186
3187 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003188 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3189 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3190 * that state. This connection should not be used for anything, and no other
3191 * {@code Connection}s should be attempted.
3192 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003193 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003194 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003195 * @return A {@code Connection} which indicates that the underlying connection should
3196 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003197 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003198 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003199 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003200 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003201
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003202 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003203 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003204 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003205 }
3206 }
3207
Santos Cordon823fd3c2014-08-07 18:35:18 -07003208 private final void fireConferenceChanged() {
3209 for (Listener l : mListeners) {
3210 l.onConferenceChanged(this, mConference);
3211 }
3212 }
3213
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003214 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003215 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003216 if (c instanceof Connection) {
3217 Connection connection = (Connection) c;
3218 connection.removeConnectionListener(mConnectionDeathListener);
3219 } else if (c instanceof Conference) {
3220 Conference conference = (Conference) c;
3221 conference.removeListener(mConferenceDeathListener);
3222 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003223 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003224 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003225 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003226
3227 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003228 * Handles a change to extras received from Telecom.
3229 *
3230 * @param extras The new extras.
3231 * @hide
3232 */
3233 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003234 Bundle b = null;
3235 synchronized (mExtrasLock) {
3236 mExtras = extras;
3237 if (mExtras != null) {
3238 b = new Bundle(mExtras);
3239 }
3240 }
3241 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003242 }
3243
3244 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003245 * Notifies listeners that the merge request failed.
3246 *
3247 * @hide
3248 */
3249 protected final void notifyConferenceMergeFailed() {
3250 for (Listener l : mListeners) {
3251 l.onConferenceMergeFailed(this);
3252 }
3253 }
3254
3255 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003256 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003257 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003258 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003259 * @hide
3260 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003261 protected final void updateConferenceParticipants(
3262 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003263 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003264 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003265 }
3266 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003267
3268 /**
3269 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003270 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003271 */
3272 protected void notifyConferenceStarted() {
3273 for (Listener l : mListeners) {
3274 l.onConferenceStarted();
3275 }
3276 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003277
3278 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003279 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3280 * be a part of a conference call.
3281 * @param isConferenceSupported {@code true} if the connection supports being part of a
3282 * conference call, {@code false} otherwise.
3283 * @hide
3284 */
3285 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3286 for (Listener l : mListeners) {
3287 l.onConferenceSupportedChanged(this, isConferenceSupported);
3288 }
3289 }
3290
3291 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303292 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3293 * changed due to an emergency call being redialed.
3294 * @param pHandle The new PhoneAccountHandle for this connection.
3295 * @hide
3296 */
3297 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3298 for (Listener l : mListeners) {
3299 l.onPhoneAccountChanged(this, pHandle);
3300 }
3301 }
3302
3303 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003304 * Sets the {@link PhoneAccountHandle} associated with this connection.
3305 *
3306 * @hide
3307 */
3308 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3309 if (mPhoneAccountHandle != phoneAccountHandle) {
3310 mPhoneAccountHandle = phoneAccountHandle;
3311 notifyPhoneAccountChanged(phoneAccountHandle);
3312 }
3313 }
3314
3315 /**
3316 * Returns the {@link PhoneAccountHandle} associated with this connection.
3317 *
3318 * @hide
3319 */
3320 public PhoneAccountHandle getPhoneAccountHandle() {
3321 return mPhoneAccountHandle;
3322 }
3323
3324 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003325 * Sends an event associated with this {@code Connection} with associated event extras to the
3326 * {@link InCallService}.
3327 * <p>
3328 * Connection events are used to communicate point in time information from a
3329 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3330 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3331 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3332 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3333 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3334 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3335 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3336 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3337 * <p>
3338 * Events are exposed to {@link InCallService} implementations via
3339 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3340 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003341 * 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 -07003342 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3343 * some events altogether.
3344 * <p>
3345 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3346 * conflicts between {@link ConnectionService} implementations. Further, custom
3347 * {@link ConnectionService} implementations shall not re-purpose events in the
3348 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3349 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3350 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3351 * {@code com.example.extra.MY_EXTRA}).
3352 * <p>
3353 * When defining events and the associated extras, it is important to keep their behavior
3354 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3355 * events/extras should me maintained to ensure backwards compatibility with older
3356 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003357 *
3358 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003359 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003360 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003361 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003362 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003363 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003364 }
3365 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003366
3367 /**
3368 * @return The direction of the call.
3369 * @hide
3370 */
3371 public final @Call.Details.CallDirection int getCallDirection() {
3372 return mCallDirection;
3373 }
3374
3375 /**
3376 * Sets the direction of this connection.
3377 * @param callDirection The direction of this connection.
3378 * @hide
3379 */
3380 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3381 mCallDirection = callDirection;
3382 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003383}