blob: fe813763e3c78bc4dc70fd2cb0a359b52c624ee3 [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 Gunnc9503d62020-01-27 10:30:51 -080019import static android.Manifest.permission.MODIFY_PHONE_STATE;
20
21import android.annotation.ElapsedRealtimeLong;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070022import android.annotation.IntDef;
Tyler Gunnc9503d62020-01-27 10:30:51 -080023import android.annotation.IntRange;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.annotation.Nullable;
Tyler Gunnc9503d62020-01-27 10:30:51 -080026import android.annotation.RequiresPermission;
Yorke Lee4af59352015-05-13 14:14:54 -070027import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070028import android.annotation.TestApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080029import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080030import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000031import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080032import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070033import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080035import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070036import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.Handler;
38import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070039import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080041import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070043import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080044import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070045import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070046import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070047
Youming Yed6de26e2019-01-30 11:20:35 -080048import com.android.internal.os.SomeArgs;
49import com.android.internal.telecom.IVideoCallback;
50import com.android.internal.telecom.IVideoProvider;
51
Hall Liua549fed2018-02-09 16:40:03 -080052import java.io.FileInputStream;
53import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080054import java.io.IOException;
55import java.io.InputStreamReader;
56import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070057import java.lang.annotation.Retention;
58import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070059import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070060import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070061import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070063import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070064import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070065import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070066
67/**
Santos Cordon895d4b82015-06-25 16:41:48 -070068 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
69 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070070 * <p>
71 * Implementations create a custom subclass of {@code Connection} and return it to the framework
72 * as the return value of
73 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
74 * or
75 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
76 * Implementations are then responsible for updating the state of the {@code Connection}, and
77 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
78 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070079 * <p>
80 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
81 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
82 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
83 * {@code Connection} instance.
84 * <p>
85 * Basic call support requires overriding the following methods: {@link #onAnswer()},
86 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
87 * <p>
88 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
89 * {@link #onUnhold()} methods should be overridden to provide hold support for the
90 * {@code Connection}.
91 * <p>
92 * Where a {@code Connection} supports a variation of video calling (e.g. the
93 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
94 * to support answering a call as a video call.
95 * <p>
96 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
97 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
98 * support for pulling the external call.
99 * <p>
100 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
101 * overridden.
102 * <p>
103 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
104 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
105 * for example, call events from a {@link InCallService} are handled,
106 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
107 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
108 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
109 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700110 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700111public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700112
Santos Cordon895d4b82015-06-25 16:41:48 -0700113 /**
114 * The connection is initializing. This is generally the first state for a {@code Connection}
115 * returned by a {@link ConnectionService}.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_INITIALIZING = 0;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * The connection is new and not connected.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_NEW = 1;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * An incoming connection is in the ringing state. During this state, the user's ringer or
126 * vibration feature will be activated.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_RINGING = 2;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * An outgoing connection is in the dialing state. In this state the other party has not yet
132 * answered the call and the user traditionally hears a ringback tone.
133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 public static final int STATE_DIALING = 3;
135
Santos Cordon895d4b82015-06-25 16:41:48 -0700136 /**
137 * A connection is active. Both parties are connected to the call and can actively communicate.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_ACTIVE = 4;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
142 * A connection is on hold.
143 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 public static final int STATE_HOLDING = 5;
145
Santos Cordon895d4b82015-06-25 16:41:48 -0700146 /**
147 * A connection has been disconnected. This is the final state once the user has been
148 * disconnected from a call either locally, remotely or by an error in the service.
149 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700150 public static final int STATE_DISCONNECTED = 6;
151
Santos Cordon895d4b82015-06-25 16:41:48 -0700152 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700153 * The state of an external connection which is in the process of being pulled from a remote
154 * device to the local device.
155 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700156 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700157 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
158 */
159 public static final int STATE_PULLING_CALL = 7;
160
161 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700162 * Indicates that the network could not perform verification.
163 */
164 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
165
166 /**
167 * Indicates that verification by the network passed. This indicates there is a high likelihood
168 * that the call originated from a valid source.
169 */
170 public static final int VERIFICATION_STATUS_PASSED = 1;
171
172 /**
173 * Indicates that verification by the network failed. This indicates there is a high likelihood
174 * that the call did not originate from a valid source.
175 */
176 public static final int VERIFICATION_STATUS_FAILED = 2;
177
178 /**@hide*/
179 @Retention(RetentionPolicy.SOURCE)
180 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
181 VERIFICATION_STATUS_NOT_VERIFIED,
182 VERIFICATION_STATUS_PASSED,
183 VERIFICATION_STATUS_FAILED
184 })
185 public @interface VerificationStatus {}
186
187 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700188 * Connection can currently be put on hold or unheld. This is distinct from
189 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
190 * it does not at the moment support the function. This can be true while the call is in the
191 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
192 * display a disabled 'hold' button.
193 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800194 public static final int CAPABILITY_HOLD = 0x00000001;
195
196 /** Connection supports the hold feature. */
197 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
198
199 /**
200 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
201 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
202 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
203 * capability allows a merge button to be shown while the conference is in the foreground
204 * of the in-call UI.
205 * <p>
206 * This is only intended for use by a {@link Conference}.
207 */
208 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
209
210 /**
211 * Connections within a conference can be swapped between foreground and background.
212 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
213 * <p>
214 * This is only intended for use by a {@link Conference}.
215 */
216 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
217
218 /**
219 * @hide
220 */
221 public static final int CAPABILITY_UNUSED = 0x00000010;
222
223 /** Connection supports responding via text option. */
224 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
225
226 /** Connection can be muted. */
227 public static final int CAPABILITY_MUTE = 0x00000040;
228
229 /**
230 * Connection supports conference management. This capability only applies to
231 * {@link Conference}s which can have {@link Connection}s as children.
232 */
233 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
234
235 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700236 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800237 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700238 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800239
240 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700243 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244
245 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700248 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800250
251 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800253 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
255
256 /**
257 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 */
259 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
260
261 /**
262 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700263 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700264 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266
267 /**
268 * Connection is able to be separated from its parent {@code Conference}, if any.
269 */
270 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
271
272 /**
273 * Connection is able to be individually disconnected when in a {@code Conference}.
274 */
275 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
276
277 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700278 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800279 * @hide
280 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700281 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800282
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700284 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700285 * @hide
286 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700287 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700288
289 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700290 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700291 * @hide
292 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700293 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700294
Tyler Gunn068085b2015-02-06 13:56:52 -0800295 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700296 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800297 * @hide
298 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700299 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800300
Tyler Gunn96d6c402015-03-18 12:39:23 -0700301 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700303 * <p>
304 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
305 * place as soon as the device answers the call, but prior to it being connected. This is an
306 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500307 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700308 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700309 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700310 @TestApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700311 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800312
Rekha Kumar07366812015-03-24 16:42:31 -0700313 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700314 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800315 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
316 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
317 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700318 */
319 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
320
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700321 /**
322 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700323 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700324 */
325 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
326
Tyler Gunnd4091732015-06-29 09:15:37 -0700327 /**
328 * For a conference, indicates the conference will not have child connections.
329 * <p>
330 * An example of a conference with child connections is a GSM conference call, where the radio
331 * retains connections to the individual participants of the conference. Another example is an
332 * IMS conference call where conference event package functionality is supported; in this case
333 * the conference server ensures the radio is aware of the participants in the conference, which
334 * are represented by child connections.
335 * <p>
336 * An example of a conference with no child connections is an IMS conference call with no
337 * conference event package support. Such a conference is represented by the radio as a single
338 * connection to the IMS conference server.
339 * <p>
340 * Indicating whether a conference has children or not is important to help user interfaces
341 * visually represent a conference. A conference with no children, for example, will have the
342 * conference connection shown in the list of calls on a Bluetooth device, where if the
343 * conference has children, only the children will be shown in the list of calls on a Bluetooth
344 * device.
345 * @hide
346 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700347 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700348 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700349 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
350
Bryce Lee81901682015-08-28 16:38:02 -0700351 /**
352 * Indicates that the connection itself wants to handle any sort of reply response, rather than
353 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700354 */
355 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
356
Tyler Gunnf97a0092016-01-19 15:59:34 -0800357 /**
358 * When set, prevents a video call from being downgraded to an audio-only call.
359 * <p>
360 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
361 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
362 * downgraded from a video call back to a VideoState of
363 * {@link VideoProfile#STATE_AUDIO_ONLY}.
364 * <p>
365 * Intuitively, a call which can be downgraded to audio should also have local and remote
366 * video
367 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
368 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
369 */
370 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
371
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700372 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700373 * When set for an external connection, indicates that this {@code Connection} can be pulled
374 * from a remote device to the current device.
375 * <p>
376 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
377 * is set.
378 */
379 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
380
Pooja Jaind34698d2017-12-28 14:15:31 +0530381 /** Call supports the deflect feature. */
382 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
383
Ravi Paluri404babb2020-01-23 19:02:44 +0530384 /**
385 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700386 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
387 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
388 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
389 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530390 */
391 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530392
393 /**
394 * Indicates that this {@code Connection} can be transferred to another
395 * number.
396 * Connection supports the blind and assured call transfer feature.
397 * @hide
398 */
399 public static final int CAPABILITY_TRANSFER = 0x08000000;
400
401 /**
402 * Indicates that this {@code Connection} can be transferred to another
403 * ongoing {@code Connection}.
404 * Connection supports the consultative call transfer feature.
405 * @hide
406 */
407 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
408
Tyler Gunn720c6642016-03-22 09:02:47 -0700409 //**********************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530410 // Next CAPABILITY value: 0x20000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700411 //**********************************************************************************************
412
413 /**
414 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700415 * <p>
416 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700417 * @hide
418 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700419 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700420 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700421 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700422
423 /**
424 * Whether the call is a generic conference, where we do not know the precise state of
425 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700426 * <p>
427 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700428 * @hide
429 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700430 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700431 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700432 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
433
434 /**
435 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700436 * <p>
437 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
438 * implies something like AMR wideband, but the interpretation of when a call is considered high
439 * definition is left to the {@link ConnectionService} to decide.
440 * <p>
441 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700442 */
443 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
444
445 /**
446 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700447 * <p>
448 * Used to indicate that a call is taking place over WIFI versus a carrier network.
449 * <p>
450 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700451 */
452 public static final int PROPERTY_WIFI = 1<<3;
453
454 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700455 * When set, indicates that the {@code Connection} does not actually exist locally for the
456 * {@link ConnectionService}.
457 * <p>
458 * Consider, for example, a scenario where a user has two devices with the same phone number.
459 * When a user places a call on one devices, the telephony stack can represent that call on the
460 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700461 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700462 * <p>
463 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
464 * external connections. Only those {@link InCallService}s which have the
465 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
466 * manifest will see external connections.
467 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700468 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700469
Brad Ebinger15847072016-05-18 11:08:36 -0700470 /**
471 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
472 */
473 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700474
Hall Liu9f332c72016-07-14 15:37:37 -0700475 /**
476 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700477 * <p>
478 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
479 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700480 * @hide
481 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700482 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700483 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700484 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
485
Tyler Gunnf5035432017-01-09 09:43:12 -0800486 /**
487 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
488 * {@link ConnectionService}.
489 * <p>
490 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
491 */
492 public static final int PROPERTY_SELF_MANAGED = 1<<7;
493
Hall Liu95d55872017-01-25 17:12:49 -0800494 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800495 * Set by the framework to indicate that a connection has an active RTT session associated with
496 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800497 */
498 public static final int PROPERTY_IS_RTT = 1 << 8;
499
Eric Erfanian62706c52017-12-06 16:27:53 -0800500 /**
501 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700502 * <p>
503 * This is used for outgoing calls.
504 *
505 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800506 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800507 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800508
Tyler Gunn5bd90852018-09-21 09:37:07 -0700509 /**
510 * Set by the framework to indicate that the network has identified a Connection as an emergency
511 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700512 * <p>
513 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
514 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700515 */
516 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
517
Tyler Gunnac60f952019-05-31 07:23:16 -0700518 /**
519 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
520 * than the current one. Used in scenarios where the conference originator is the remote device
521 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700522 * <p>
523 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700524 * @hide
525 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700526 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700527 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700528 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
529
Ravi Paluri80aa2142019-12-02 11:57:37 +0530530 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700531 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530532 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700533 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530534 */
535 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
536
537
Tyler Gunn96d6c402015-03-18 12:39:23 -0700538 //**********************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530539 // Next PROPERTY value: 1<<13
Tyler Gunn96d6c402015-03-18 12:39:23 -0700540 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800541
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700542 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800543 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800544 */
allenwtsu2aca9892019-11-25 14:38:21 +0800545 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800546 /**
547 * Adaptive Multi-rate audio codec.
548 */
allenwtsu2aca9892019-11-25 14:38:21 +0800549 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800550 /**
551 * Adaptive Multi-rate wideband audio codec.
552 */
allenwtsu2aca9892019-11-25 14:38:21 +0800553 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800554 /**
555 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
556 */
allenwtsu2aca9892019-11-25 14:38:21 +0800557 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800558 /**
559 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
560 */
allenwtsu2aca9892019-11-25 14:38:21 +0800561 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800562 /**
563 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
564 */
allenwtsu2aca9892019-11-25 14:38:21 +0800565 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800566 /**
567 * Enhanced Variable Rate Wideband Codec. See RFC5188.
568 */
allenwtsu2aca9892019-11-25 14:38:21 +0800569 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800570 /**
571 * Enhanced Variable Rate Narrowband-Wideband Codec.
572 */
allenwtsu2aca9892019-11-25 14:38:21 +0800573 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800574 /**
575 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
576 */
allenwtsu2aca9892019-11-25 14:38:21 +0800577 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800578 /**
579 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
580 */
allenwtsu2aca9892019-11-25 14:38:21 +0800581 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800582 /**
583 * GSM Half Rate audio codec.
584 */
allenwtsu2aca9892019-11-25 14:38:21 +0800585 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800586 /**
587 * ITU-T G711U audio codec.
588 */
allenwtsu2aca9892019-11-25 14:38:21 +0800589 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800590 /**
591 * ITU-T G723 audio codec.
592 */
allenwtsu2aca9892019-11-25 14:38:21 +0800593 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800594 /**
595 * ITU-T G711A audio codec.
596 */
allenwtsu2aca9892019-11-25 14:38:21 +0800597 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800598 /**
599 * ITU-T G722 audio codec.
600 */
allenwtsu2aca9892019-11-25 14:38:21 +0800601 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800602 /**
603 * ITU-T G711AB audio codec.
604 */
allenwtsu2aca9892019-11-25 14:38:21 +0800605 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800606 /**
607 * ITU-T G729 audio codec.
608 */
allenwtsu2aca9892019-11-25 14:38:21 +0800609 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800610 /**
611 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
612 */
allenwtsu2aca9892019-11-25 14:38:21 +0800613 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800614 /**
615 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
616 */
allenwtsu2aca9892019-11-25 14:38:21 +0800617 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800618 /**
619 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
620 */
allenwtsu2aca9892019-11-25 14:38:21 +0800621 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800622 /**
623 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
624 */
allenwtsu2aca9892019-11-25 14:38:21 +0800625 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
626
Tyler Gunn1c687622019-12-20 11:08:13 -0800627 /**@hide*/
628 @Retention(RetentionPolicy.SOURCE)
629 @IntDef(prefix = "AUDIO_CODEC_", value = {
630 AUDIO_CODEC_NONE,
631 AUDIO_CODEC_AMR,
632 AUDIO_CODEC_AMR_WB,
633 AUDIO_CODEC_QCELP13K,
634 AUDIO_CODEC_EVRC,
635 AUDIO_CODEC_EVRC_B,
636 AUDIO_CODEC_EVRC_WB,
637 AUDIO_CODEC_EVRC_NW,
638 AUDIO_CODEC_GSM_EFR,
639 AUDIO_CODEC_GSM_FR,
640 AUDIO_CODEC_GSM_HR,
641 AUDIO_CODEC_G711U,
642 AUDIO_CODEC_G723,
643 AUDIO_CODEC_G711A,
644 AUDIO_CODEC_G722,
645 AUDIO_CODEC_G711AB,
646 AUDIO_CODEC_G729,
647 AUDIO_CODEC_EVS_NB,
648 AUDIO_CODEC_EVS_SWB,
649 AUDIO_CODEC_EVS_FB
650 })
651 public @interface AudioCodec {}
652
allenwtsu2aca9892019-11-25 14:38:21 +0800653 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700654 * Connection extra key used to store the last forwarded number associated with the current
655 * connection. Used to communicate to the user interface that the connection was forwarded via
656 * the specified number.
657 */
658 public static final String EXTRA_LAST_FORWARDED_NUMBER =
659 "android.telecom.extra.LAST_FORWARDED_NUMBER";
660
661 /**
662 * Connection extra key used to store a child number associated with the current connection.
663 * Used to communicate to the user interface that the connection was received via
664 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
665 * address.
666 */
667 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
668
669 /**
670 * Connection extra key used to store the subject for an incoming call. The user interface can
671 * query this extra and display its contents for incoming calls. Will only be used if the
672 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
673 */
674 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
675
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800676 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700677 * Boolean connection extra key set on a {@link Connection} in
678 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
679 * current active foreground call to be dropped.
680 */
681 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
682 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
683
684 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700685 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
686 * state to indicate the name of the third-party app which is responsible for the current
687 * foreground call.
688 * <p>
689 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
690 * is able to inform the user that answering the new incoming call will cause a call owned by
691 * another app to be dropped when the incoming call is answered.
692 */
693 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
694 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
695
696 /**
Hall Liu10208662016-06-15 17:55:00 -0700697 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700698 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700699 * <p>
700 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
701 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700702 * @hide
703 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700704 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700705 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700706 public static final String EXTRA_DISABLE_ADD_CALL =
707 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700708
709 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700710 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
711 * original Connection ID associated with the connection. Used in
712 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
713 * connection/conference added via
714 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
715 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
716 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
717 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
718 * be a way to ensure that we don't add the connection again as a duplicate.
719 * <p>
720 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
721 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
722 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
723 * in a new {@link Connection} which it adds to Telecom via
724 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
725 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
726 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
727 * ID it originally referred to the connection as. Thus Telecom needs to know that the
728 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700729 * <p>
730 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
731 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700732 * @hide
733 */
734 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
735 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
736
737 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700738 * Extra key set on a {@link Connection} when it was created via a remote connection service.
739 * For example, if a connection manager requests a remote connection service to create a call
740 * using one of the remote connection service's phone account handle, this extra will be set so
741 * that Telecom knows that the wrapped remote connection originated in a remote connection
742 * service. We stash this in the extras since connection managers will typically copy the
743 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
744 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
745 * @hide
746 */
747 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
748 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
749
750 /**
751 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
752 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
753 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
754 * {@link ConnectionService} with a means to know the package name of the requesting
755 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
756 * better visibility in Telecom of where a connection ultimately originated.
757 * @hide
758 */
759 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
760 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
761
762 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700763 * Boolean connection extra key set on the extras passed to
764 * {@link Connection#sendConnectionEvent} which indicates that audio is present
765 * on the RTT call when the extra value is true.
766 */
767 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
768 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
769
770 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800771 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
772 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800773 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800774 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800775 "android.telecom.extra.AUDIO_CODEC";
776
777 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800778 * Connection event used to inform Telecom that it should play the on hold tone. This is used
779 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700780 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800781 */
782 public static final String EVENT_ON_HOLD_TONE_START =
783 "android.telecom.event.ON_HOLD_TONE_START";
784
785 /**
786 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
787 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700788 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800789 */
790 public static final String EVENT_ON_HOLD_TONE_END =
791 "android.telecom.event.ON_HOLD_TONE_END";
792
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700793 /**
794 * Connection event used to inform {@link InCallService}s when pulling of an external call has
795 * failed. The user interface should inform the user of the error.
796 * <p>
797 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
798 * API is called on a {@link Call} with the properties
799 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
800 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
801 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700802 * <p>
803 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
804 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700805 */
806 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
807
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700808 /**
809 * Connection event used to inform {@link InCallService}s when the merging of two calls has
810 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700811 * <p>
812 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
813 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700814 */
815 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
816
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700817 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700818 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700819 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700820 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
821 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700822 */
823 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
824
825 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900826 * Connection event used to inform Telecom when a switch operation on a call has failed.
827 * <p>
828 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
829 * expected to be null when this connection event is used.
830 */
831 public static final String EVENT_CALL_SWITCH_FAILED =
832 "android.telecom.event.CALL_SWITCH_FAILED";
833
834 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700835 * Connection event used to inform {@link InCallService}s when the process of merging a
836 * Connection into a conference has begun.
837 * <p>
838 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
839 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700840 */
841 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
842
843 /**
844 * Connection event used to inform {@link InCallService}s when the process of merging a
845 * Connection into a conference has completed.
846 * <p>
847 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
848 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700849 */
850 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
851
852 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700853 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
854 * the remote party.
855 * <p>
856 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
857 * call is being held locally on the device. When a capable {@link ConnectionService} receives
858 * signalling to indicate that the remote party has put the call on hold, it can send this
859 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700860 */
861 public static final String EVENT_CALL_REMOTELY_HELD =
862 "android.telecom.event.CALL_REMOTELY_HELD";
863
864 /**
865 * Connection event used to inform {@link InCallService}s when a call which was remotely held
866 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
867 * <p>
868 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
869 * call is being held locally on the device. When a capable {@link ConnectionService} receives
870 * signalling to indicate that the remote party has taken the call off hold, it can send this
871 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700872 */
873 public static final String EVENT_CALL_REMOTELY_UNHELD =
874 "android.telecom.event.CALL_REMOTELY_UNHELD";
875
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700876 /**
877 * Connection event used to inform an {@link InCallService} which initiated a call handover via
878 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
879 * successfully completed.
880 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700881 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
882 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700883 */
884 public static final String EVENT_HANDOVER_COMPLETE =
885 "android.telecom.event.HANDOVER_COMPLETE";
886
887 /**
888 * Connection event used to inform an {@link InCallService} which initiated a call handover via
889 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
890 * to complete.
891 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700892 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
893 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700894 */
895 public static final String EVENT_HANDOVER_FAILED =
896 "android.telecom.event.HANDOVER_FAILED";
897
shilub7ec9a02018-11-09 15:52:04 -0800898 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000899 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800900 */
901 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
902
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700903 /**
904 * Connection event used to inform an {@link InCallService} that the RTT audio indication
905 * has changed.
906 */
907 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
908 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
909
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700910 // Flag controlling whether PII is emitted into the logs
911 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
912
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800913 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700914 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
915 *
916 * @param capabilities A capability bit field.
917 * @return A human readable string representation.
918 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800919 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700920 return capabilitiesToStringInternal(capabilities, true /* isLong */);
921 }
922
923 /**
924 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
925 * string.
926 *
927 * @param capabilities A capability bit field.
928 * @return A human readable string representation.
929 * @hide
930 */
931 public static String capabilitiesToStringShort(int capabilities) {
932 return capabilitiesToStringInternal(capabilities, false /* isLong */);
933 }
934
935 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800936 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700937 builder.append("[");
938 if (isLong) {
939 builder.append("Capabilities:");
940 }
941
Tyler Gunnc63f9082019-10-15 13:19:26 -0700942 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700943 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800944 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700945 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700946 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800947 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700948 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700949 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800950 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700951 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700952 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800953 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700954 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700955 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800956 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700957 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700958 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800959 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700960 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700961 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800962 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700963 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700964 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700965 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700966 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700967 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700968 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700969 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
970 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700971 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800972 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700973 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700974 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700975 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700976 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700977 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700978 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700979 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
980 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700981 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800982 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700983 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
984 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700985 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800986 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700987 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700988 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500989 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700990 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700991 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700992 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700993 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700994 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700995 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700996 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
997 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700998 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700999 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001000 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1001 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001002 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001003 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001004 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001005 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001006 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001007 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301008 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1009 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301010 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1011 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1012 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301013 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1014 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1015 }
1016 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1017 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1018 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1019 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001020 builder.append("]");
1021 return builder.toString();
1022 }
1023
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001024 /**
1025 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1026 *
1027 * @param properties A property bit field.
1028 * @return A human readable string representation.
1029 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001030 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001031 return propertiesToStringInternal(properties, true /* isLong */);
1032 }
1033
1034 /**
1035 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1036 *
1037 * @param properties A property bit field.
1038 * @return A human readable string representation.
1039 * @hide
1040 */
1041 public static String propertiesToStringShort(int properties) {
1042 return propertiesToStringInternal(properties, false /* isLong */);
1043 }
1044
1045 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001046 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001047 builder.append("[");
1048 if (isLong) {
1049 builder.append("Properties:");
1050 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001051
Tyler Gunnc63f9082019-10-15 13:19:26 -07001052 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001053 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1054 }
1055
Tyler Gunnc63f9082019-10-15 13:19:26 -07001056 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001057 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001058 }
1059
Tyler Gunnc63f9082019-10-15 13:19:26 -07001060 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001061 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001062 }
1063
Tyler Gunnc63f9082019-10-15 13:19:26 -07001064 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001065 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001066 }
1067
Tyler Gunnc63f9082019-10-15 13:19:26 -07001068 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001069 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001070 }
1071
Tyler Gunnc63f9082019-10-15 13:19:26 -07001072 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001073 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001074 }
1075
Tyler Gunnc63f9082019-10-15 13:19:26 -07001076 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001077 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001078 }
1079
Tyler Gunnc63f9082019-10-15 13:19:26 -07001080 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001081 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1082 }
1083
Tyler Gunnc63f9082019-10-15 13:19:26 -07001084 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1085 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001086 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1087 }
1088
Tyler Gunnc63f9082019-10-15 13:19:26 -07001089 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001090 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1091 }
1092
Ravi Paluri80aa2142019-12-02 11:57:37 +05301093 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1094 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1095 }
1096
Tyler Gunn720c6642016-03-22 09:02:47 -07001097 builder.append("]");
1098 return builder.toString();
1099 }
1100
Sailesh Nepal091768c2014-06-30 15:15:23 -07001101 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001102 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001103 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001104 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001105 public void onCallerDisplayNameChanged(
1106 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001107 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001108 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001109 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001110 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001111 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001112 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001113 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001114 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001115 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 public void onVideoProviderChanged(
1117 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001118 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1119 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001120 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001121 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001122 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001123 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001124 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001125 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001126 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001127 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001128 public void onRttInitiationSuccess(Connection c) {}
1129 public void onRttInitiationFailure(Connection c, int reason) {}
1130 public void onRttSessionRemotelyTerminated(Connection c) {}
1131 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301132 /** @hide */
1133 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001134 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001135 }
1136
Tyler Gunnb702ef82015-05-29 11:51:53 -07001137 /**
Hall Liu95d55872017-01-25 17:12:49 -08001138 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001139 */
1140 public static final class RttTextStream {
1141 private static final int READ_BUFFER_SIZE = 1000;
1142 private final InputStreamReader mPipeFromInCall;
1143 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001144 private final ParcelFileDescriptor mFdFromInCall;
1145 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001146
1147 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001148 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1149
1150 /**
1151 * @hide
1152 */
1153 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001154 mFdFromInCall = fromInCall;
1155 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001156 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001157
1158 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001159 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001160 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001161 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001162 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001163 }
1164
1165 /**
1166 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1167 * RTT transmits text in real-time, this method should be called as often as text snippets
1168 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001169 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001170 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1171 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001172 *
Hall Liu95d55872017-01-25 17:12:49 -08001173 * @param input The message to send to the in-call app.
1174 */
1175 public void write(String input) throws IOException {
1176 mPipeToInCall.write(input);
1177 mPipeToInCall.flush();
1178 }
1179
1180
1181 /**
1182 * Reads a string from the in-call app, blocking if there is no data available. Returns
1183 * {@code null} if the RTT conversation has been terminated and there is no further data
1184 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001185 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001186 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1187 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001188 *
Hall Liu95d55872017-01-25 17:12:49 -08001189 * @return A string containing text entered by the user, or {@code null} if the
1190 * conversation has been terminated or if there was an error while reading.
1191 */
Hall Liuffa4a812017-03-02 16:11:00 -08001192 public String read() throws IOException {
1193 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1194 if (numRead < 0) {
1195 return null;
1196 }
1197 return new String(mReadBuffer, 0, numRead);
1198 }
1199
1200 /**
1201 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1202 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001203 *
Hall Liuffa4a812017-03-02 16:11:00 -08001204 * @return A string containing text entered by the user, or {@code null} if the user has
1205 * not entered any new text yet.
1206 */
1207 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001208 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001209 return read();
1210 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001211 return null;
1212 }
1213 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001214
1215 /** @hide */
1216 public ParcelFileDescriptor getFdFromInCall() {
1217 return mFdFromInCall;
1218 }
1219
1220 /** @hide */
1221 public ParcelFileDescriptor getFdToInCall() {
1222 return mFdToInCall;
1223 }
1224 }
1225
1226 /**
1227 * Provides constants to represent the results of responses to session modify requests sent via
1228 * {@link Call#sendRttRequest()}
1229 */
1230 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001231 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001232 /**
1233 * Session modify request was successful.
1234 */
1235 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1236
1237 /**
1238 * Session modify request failed.
1239 */
1240 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1241
1242 /**
1243 * Session modify request ignored due to invalid parameters.
1244 */
1245 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1246
1247 /**
1248 * Session modify request timed out.
1249 */
1250 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1251
1252 /**
1253 * Session modify request rejected by remote user.
1254 */
1255 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001256 }
1257
1258 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001259 * Provides a means of controlling the video session associated with a {@link Connection}.
1260 * <p>
1261 * Implementations create a custom subclass of {@link VideoProvider} and the
1262 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1263 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1264 * should set the {@link VideoProvider}.
1265 * <p>
1266 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1267 * {@link InCallService} implementations to issue requests related to the video session;
1268 * it provides a means for the {@link ConnectionService} to report events and information
1269 * related to the video session to Telecom and the {@link InCallService} implementations.
1270 * <p>
1271 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1272 * {@link android.telecom.InCallService.VideoCall}.
1273 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 /**
1276 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001277 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 */
1279 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001280
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001281 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1283 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 */
1285 public static final int SESSION_EVENT_RX_RESUME = 2;
1286
1287 /**
1288 * Video transmission has begun. This occurs after a negotiated start of video transmission
1289 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001290 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 */
1292 public static final int SESSION_EVENT_TX_START = 3;
1293
1294 /**
1295 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1296 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001297 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001298 */
1299 public static final int SESSION_EVENT_TX_STOP = 4;
1300
1301 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001302 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001303 * this as a cue to inform the user the camera is not available.
1304 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001305 */
1306 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1307
1308 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001309 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001310 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001311 * the camera has become available again.
1312 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 */
1314 public static final int SESSION_EVENT_CAMERA_READY = 6;
1315
1316 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001317 * Session event raised by Telecom when
1318 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1319 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1320 * @see #handleCallSessionEvent(int)
1321 */
1322 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1323
1324 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001326 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 */
1328 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1329
1330 /**
1331 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001332 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001333 */
1334 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1335
1336 /**
1337 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001338 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 */
1340 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1341
Rekha Kumar07366812015-03-24 16:42:31 -07001342 /**
1343 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001344 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001345 */
1346 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1347
1348 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001349 * Session modify request rejected by remote user.
1350 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001351 */
1352 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1353
Tyler Gunn75958422015-04-15 14:23:42 -07001354 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 private static final int MSG_SET_CAMERA = 2;
1356 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1357 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1358 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1359 private static final int MSG_SET_ZOOM = 6;
1360 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1361 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1362 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001363 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001364 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001365 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001367 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1368 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1369 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1370 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1371 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1372 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001373 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1374 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001375 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1376
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001377 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001379
1380 /**
1381 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001382 *
1383 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1384 * load factor before resizing, 1 means we only expect a single thread to
1385 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001386 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001387 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1388 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389
1390 /**
1391 * Default handler used to consolidate binder method calls onto a single thread.
1392 */
1393 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001394 public VideoProviderHandler() {
1395 super();
1396 }
1397
1398 public VideoProviderHandler(Looper looper) {
1399 super(looper);
1400 }
1401
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 @Override
1403 public void handleMessage(Message msg) {
1404 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001405 case MSG_ADD_VIDEO_CALLBACK: {
1406 IBinder binder = (IBinder) msg.obj;
1407 IVideoCallback callback = IVideoCallback.Stub
1408 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001409 if (callback == null) {
1410 Log.w(this, "addVideoProvider - skipped; callback is null.");
1411 break;
1412 }
1413
Tyler Gunn75958422015-04-15 14:23:42 -07001414 if (mVideoCallbacks.containsKey(binder)) {
1415 Log.i(this, "addVideoProvider - skipped; already present.");
1416 break;
1417 }
1418 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001420 }
1421 case MSG_REMOVE_VIDEO_CALLBACK: {
1422 IBinder binder = (IBinder) msg.obj;
1423 IVideoCallback callback = IVideoCallback.Stub
1424 .asInterface((IBinder) msg.obj);
1425 if (!mVideoCallbacks.containsKey(binder)) {
1426 Log.i(this, "removeVideoProvider - skipped; not present.");
1427 break;
1428 }
1429 mVideoCallbacks.remove(binder);
1430 break;
1431 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001433 {
1434 SomeArgs args = (SomeArgs) msg.obj;
1435 try {
1436 onSetCamera((String) args.arg1);
1437 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001438 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001439 } finally {
1440 args.recycle();
1441 }
1442 }
1443 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 case MSG_SET_PREVIEW_SURFACE:
1445 onSetPreviewSurface((Surface) msg.obj);
1446 break;
1447 case MSG_SET_DISPLAY_SURFACE:
1448 onSetDisplaySurface((Surface) msg.obj);
1449 break;
1450 case MSG_SET_DEVICE_ORIENTATION:
1451 onSetDeviceOrientation(msg.arg1);
1452 break;
1453 case MSG_SET_ZOOM:
1454 onSetZoom((Float) msg.obj);
1455 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001456 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1457 SomeArgs args = (SomeArgs) msg.obj;
1458 try {
1459 onSendSessionModifyRequest((VideoProfile) args.arg1,
1460 (VideoProfile) args.arg2);
1461 } finally {
1462 args.recycle();
1463 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001465 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1467 onSendSessionModifyResponse((VideoProfile) msg.obj);
1468 break;
1469 case MSG_REQUEST_CAMERA_CAPABILITIES:
1470 onRequestCameraCapabilities();
1471 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001472 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1473 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001474 break;
1475 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001476 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 break;
1478 default:
1479 break;
1480 }
1481 }
1482 }
1483
1484 /**
1485 * IVideoProvider stub implementation.
1486 */
1487 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001488 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001489 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001490 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1491 }
1492
1493 public void removeVideoCallback(IBinder videoCallbackBinder) {
1494 mMessageHandler.obtainMessage(
1495 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 }
1497
Tyler Gunn159f35c2017-03-02 09:28:37 -08001498 public void setCamera(String cameraId, String callingPackageName,
1499 int targetSdkVersion) {
1500
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001501 SomeArgs args = SomeArgs.obtain();
1502 args.arg1 = cameraId;
1503 // Propagate the calling package; originally determined in
1504 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1505 // process.
1506 args.arg2 = callingPackageName;
1507 // Pass along the uid and pid of the calling app; this gets lost when we put the
1508 // message onto the handler. These are required for Telecom to perform a permission
1509 // check to see if the calling app is able to use the camera.
1510 args.argi1 = Binder.getCallingUid();
1511 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001512 // Pass along the target SDK version of the calling InCallService. This is used to
1513 // maintain backwards compatibility of the API for older callers.
1514 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001515 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001516 }
1517
1518 public void setPreviewSurface(Surface surface) {
1519 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1520 }
1521
1522 public void setDisplaySurface(Surface surface) {
1523 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1524 }
1525
1526 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001527 mMessageHandler.obtainMessage(
1528 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001529 }
1530
1531 public void setZoom(float value) {
1532 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1533 }
1534
Tyler Gunn45382162015-05-06 08:52:27 -07001535 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1536 SomeArgs args = SomeArgs.obtain();
1537 args.arg1 = fromProfile;
1538 args.arg2 = toProfile;
1539 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 }
1541
1542 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1543 mMessageHandler.obtainMessage(
1544 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1545 }
1546
1547 public void requestCameraCapabilities() {
1548 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1549 }
1550
1551 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001552 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553 }
1554
Yorke Lee32f24732015-05-12 16:18:03 -07001555 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1557 }
1558 }
1559
1560 public VideoProvider() {
1561 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001562 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001563 }
1564
1565 /**
1566 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1567 *
1568 * @param looper The looper.
1569 * @hide
1570 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001571 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001572 public VideoProvider(Looper looper) {
1573 mBinder = new VideoProvider.VideoProviderBinder();
1574 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001575 }
1576
1577 /**
1578 * Returns binder object which can be used across IPC methods.
1579 * @hide
1580 */
1581 public final IVideoProvider getInterface() {
1582 return mBinder;
1583 }
1584
1585 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001586 * Sets the camera to be used for the outgoing video.
1587 * <p>
1588 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1589 * camera via
1590 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1591 * <p>
1592 * Sent from the {@link InCallService} via
1593 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001594 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001595 * @param cameraId The id of the camera (use ids as reported by
1596 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 */
1598 public abstract void onSetCamera(String cameraId);
1599
1600 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001601 * Sets the camera to be used for the outgoing video.
1602 * <p>
1603 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1604 * camera via
1605 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1606 * <p>
1607 * This prototype is used internally to ensure that the calling package name, UID and PID
1608 * are sent to Telecom so that can perform a camera permission check on the caller.
1609 * <p>
1610 * Sent from the {@link InCallService} via
1611 * {@link InCallService.VideoCall#setCamera(String)}.
1612 *
1613 * @param cameraId The id of the camera (use ids as reported by
1614 * {@link CameraManager#getCameraIdList()}).
1615 * @param callingPackageName The AppOpps package name of the caller.
1616 * @param callingUid The UID of the caller.
1617 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001618 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001619 * @hide
1620 */
1621 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001622 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001623
1624 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001625 * Sets the surface to be used for displaying a preview of what the user's camera is
1626 * currently capturing. When video transmission is enabled, this is the video signal which
1627 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001628 * <p>
1629 * Sent from the {@link InCallService} via
1630 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001631 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001632 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 */
1634 public abstract void onSetPreviewSurface(Surface surface);
1635
1636 /**
1637 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001638 * <p>
1639 * Sent from the {@link InCallService} via
1640 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001642 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001643 */
1644 public abstract void onSetDisplaySurface(Surface surface);
1645
1646 /**
1647 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1648 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001649 * <p>
1650 * Sent from the {@link InCallService} via
1651 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001652 *
1653 * @param rotation The device orientation, in degrees.
1654 */
1655 public abstract void onSetDeviceOrientation(int rotation);
1656
1657 /**
1658 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * <p>
1660 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001661 *
1662 * @param value The camera zoom ratio.
1663 */
1664 public abstract void onSetZoom(float value);
1665
1666 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001667 * Issues a request to modify the properties of the current video session.
1668 * <p>
1669 * Example scenarios include: requesting an audio-only call to be upgraded to a
1670 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1671 * when the {@link InCallService} is no longer the foreground application.
1672 * <p>
1673 * If the {@link VideoProvider} determines a request to be invalid, it should call
1674 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1675 * invalid request back to the {@link InCallService}.
1676 * <p>
1677 * Where a request requires confirmation from the user of the peer device, the
1678 * {@link VideoProvider} must communicate the request to the peer device and handle the
1679 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1680 * is used to inform the {@link InCallService} of the result of the request.
1681 * <p>
1682 * Sent from the {@link InCallService} via
1683 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001684 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001685 * @param fromProfile The video profile prior to the request.
1686 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 */
Tyler Gunn45382162015-05-06 08:52:27 -07001688 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1689 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001690
Tyler Gunnb702ef82015-05-29 11:51:53 -07001691 /**
1692 * Provides a response to a request to change the current video session properties.
1693 * <p>
1694 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1695 * video call, could decline the request and keep the call as audio-only.
1696 * In such a scenario, the {@code responseProfile} would have a video state of
1697 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1698 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1699 * <p>
1700 * Sent from the {@link InCallService} via
1701 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1702 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1703 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001704 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001705 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001706 */
1707 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1708
1709 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001710 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1711 * <p>
1712 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1713 * camera via
1714 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1715 * <p>
1716 * Sent from the {@link InCallService} via
1717 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001718 */
1719 public abstract void onRequestCameraCapabilities();
1720
1721 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001722 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1723 * video component of the current {@link Connection}.
1724 * <p>
1725 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1726 * via {@link VideoProvider#setCallDataUsage(long)}.
1727 * <p>
1728 * Sent from the {@link InCallService} via
1729 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001730 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001731 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001732
1733 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001734 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1735 * the peer device when the video signal is paused.
1736 * <p>
1737 * Sent from the {@link InCallService} via
1738 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001739 *
1740 * @param uri URI of image to display.
1741 */
Yorke Lee32f24732015-05-12 16:18:03 -07001742 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001743
1744 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001745 * Used to inform listening {@link InCallService} implementations when the
1746 * {@link VideoProvider} receives a session modification request.
1747 * <p>
1748 * Received by the {@link InCallService} via
1749 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001750 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001751 * @param videoProfile The requested video profile.
1752 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001753 */
1754 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001755 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001756 for (IVideoCallback callback : mVideoCallbacks.values()) {
1757 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001758 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001759 } catch (RemoteException ignored) {
1760 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001761 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001762 }
1763 }
1764 }
1765
1766 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001767 * Used to inform listening {@link InCallService} implementations when the
1768 * {@link VideoProvider} receives a response to a session modification request.
1769 * <p>
1770 * Received by the {@link InCallService} via
1771 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1772 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001773 *
1774 * @param status Status of the session modify request. Valid values are
1775 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1776 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001777 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1778 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1779 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1780 * @param requestedProfile The original request which was sent to the peer device.
1781 * @param responseProfile The actual profile changes agreed to by the peer device.
1782 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783 */
1784 public void receiveSessionModifyResponse(int status,
1785 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001786 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001787 for (IVideoCallback callback : mVideoCallbacks.values()) {
1788 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001789 callback.receiveSessionModifyResponse(status, requestedProfile,
1790 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001791 } catch (RemoteException ignored) {
1792 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001793 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001794 }
1795 }
1796 }
1797
1798 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001799 * Used to inform listening {@link InCallService} implementations when the
1800 * {@link VideoProvider} reports a call session event.
1801 * <p>
1802 * Received by the {@link InCallService} via
1803 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001804 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001805 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1806 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1807 * {@link VideoProvider#SESSION_EVENT_TX_START},
1808 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1809 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001810 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1811 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001812 */
1813 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001814 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001815 for (IVideoCallback callback : mVideoCallbacks.values()) {
1816 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001817 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001818 } catch (RemoteException ignored) {
1819 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001820 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001821 }
1822 }
1823 }
1824
1825 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001826 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1827 * peer's video have changed.
1828 * <p>
1829 * This could occur if, for example, the peer rotates their device, changing the aspect
1830 * ratio of the video, or if the user switches between the back and front cameras.
1831 * <p>
1832 * Received by the {@link InCallService} via
1833 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001834 *
1835 * @param width The updated peer video width.
1836 * @param height The updated peer video height.
1837 */
1838 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001839 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001840 for (IVideoCallback callback : mVideoCallbacks.values()) {
1841 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001842 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001843 } catch (RemoteException ignored) {
1844 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001845 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001846 }
1847 }
1848 }
1849
1850 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001851 * Used to inform listening {@link InCallService} implementations when the data usage of the
1852 * video associated with the current {@link Connection} has changed.
1853 * <p>
1854 * This could be in response to a preview request via
1855 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001856 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1857 * 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 -07001858 * <p>
1859 * Received by the {@link InCallService} via
1860 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001861 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001862 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1863 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001864 */
Yorke Lee32f24732015-05-12 16:18:03 -07001865 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001866 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001867 for (IVideoCallback callback : mVideoCallbacks.values()) {
1868 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001869 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001870 } catch (RemoteException ignored) {
1871 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001872 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001873 }
1874 }
1875 }
1876
1877 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001878 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001879 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001880 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001881 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1882 * @hide
1883 */
1884 public void changeCallDataUsage(long dataUsage) {
1885 setCallDataUsage(dataUsage);
1886 }
1887
1888 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001889 * Used to inform listening {@link InCallService} implementations when the capabilities of
1890 * the current camera have changed.
1891 * <p>
1892 * The {@link VideoProvider} should call this in response to
1893 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1894 * changed via {@link VideoProvider#onSetCamera(String)}.
1895 * <p>
1896 * Received by the {@link InCallService} via
1897 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1898 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001899 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001900 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001901 */
Yorke Lee400470f2015-05-12 13:31:25 -07001902 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001903 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001904 for (IVideoCallback callback : mVideoCallbacks.values()) {
1905 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001906 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001907 } catch (RemoteException ignored) {
1908 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001909 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001910 }
1911 }
1912 }
Rekha Kumar07366812015-03-24 16:42:31 -07001913
1914 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001915 * Used to inform listening {@link InCallService} implementations when the video quality
1916 * of the call has changed.
1917 * <p>
1918 * Received by the {@link InCallService} via
1919 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001920 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001921 * @param videoQuality The updated video quality. Valid values:
1922 * {@link VideoProfile#QUALITY_HIGH},
1923 * {@link VideoProfile#QUALITY_MEDIUM},
1924 * {@link VideoProfile#QUALITY_LOW},
1925 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001926 */
1927 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001928 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001929 for (IVideoCallback callback : mVideoCallbacks.values()) {
1930 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001931 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001932 } catch (RemoteException ignored) {
1933 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001934 }
Rekha Kumar07366812015-03-24 16:42:31 -07001935 }
1936 }
1937 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001938
1939 /**
1940 * Returns a string representation of a call session event.
1941 *
1942 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1943 * @return String representation of the call session event.
1944 * @hide
1945 */
1946 public static String sessionEventToString(int event) {
1947 switch (event) {
1948 case SESSION_EVENT_CAMERA_FAILURE:
1949 return SESSION_EVENT_CAMERA_FAILURE_STR;
1950 case SESSION_EVENT_CAMERA_READY:
1951 return SESSION_EVENT_CAMERA_READY_STR;
1952 case SESSION_EVENT_RX_PAUSE:
1953 return SESSION_EVENT_RX_PAUSE_STR;
1954 case SESSION_EVENT_RX_RESUME:
1955 return SESSION_EVENT_RX_RESUME_STR;
1956 case SESSION_EVENT_TX_START:
1957 return SESSION_EVENT_TX_START_STR;
1958 case SESSION_EVENT_TX_STOP:
1959 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001960 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1961 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001962 default:
1963 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1964 }
1965 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966 }
1967
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001968 private final Listener mConnectionDeathListener = new Listener() {
1969 @Override
1970 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001971 if (mConferenceables.remove(c)) {
1972 fireOnConferenceableConnectionsChanged();
1973 }
1974 }
1975 };
1976
1977 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1978 @Override
1979 public void onDestroyed(Conference c) {
1980 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001981 fireOnConferenceableConnectionsChanged();
1982 }
1983 }
1984 };
1985
Jay Shrauner229e3822014-08-15 09:23:07 -07001986 /**
1987 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1988 * load factor before resizing, 1 means we only expect a single thread to
1989 * access the map so make only a single shard
1990 */
1991 private final Set<Listener> mListeners = Collections.newSetFromMap(
1992 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001993 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1994 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001995 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001996
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001997 // The internal telecom call ID associated with this connection.
1998 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001999 // The PhoneAccountHandle associated with this connection.
2000 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002001 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002002 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002003 private Uri mAddress;
2004 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002005 private String mCallerDisplayName;
2006 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002007 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002008 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002009 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002010 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002011 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002012 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002013 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002014 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002015 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002016 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002017 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002018 private Conference mConference;
2019 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002020 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002021 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002022 /**
2023 * The direction of the connection; used where an existing connection is created and we need to
2024 * communicate to Telecom whether its incoming or outgoing.
2025 */
2026 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002027
2028 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002029 * Tracks the key set for the extras bundle provided on the last invocation of
2030 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2031 * keys which were set previously but are no longer present in the replacement Bundle.
2032 */
2033 private Set<String> mPreviousExtraKeys;
2034
2035 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002036 * The verification status for an incoming call's phone number.
2037 */
2038 private @VerificationStatus int mCallerNumberVerificationStatus;
2039
2040
2041 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002042 * Create a new Connection.
2043 */
Santos Cordonf2951102014-07-20 19:06:29 -07002044 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002045
2046 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002047 * Returns the Telecom internal call ID associated with this connection. Should only be used
2048 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002049 * <p>
2050 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2051 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002052 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002053 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002054 * @hide
2055 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002056 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002057 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002058 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002059 return mTelecomCallId;
2060 }
2061
2062 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002063 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002064 */
Andrew Lee100e2932014-09-08 15:34:24 -07002065 public final Uri getAddress() {
2066 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002067 }
2068
2069 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002070 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002071 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002072 */
Andrew Lee100e2932014-09-08 15:34:24 -07002073 public final int getAddressPresentation() {
2074 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002075 }
2076
2077 /**
2078 * @return The caller display name (CNAP).
2079 */
2080 public final String getCallerDisplayName() {
2081 return mCallerDisplayName;
2082 }
2083
2084 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002085 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002086 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002087 */
2088 public final int getCallerDisplayNamePresentation() {
2089 return mCallerDisplayNamePresentation;
2090 }
2091
2092 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002093 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 */
2095 public final int getState() {
2096 return mState;
2097 }
2098
2099 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002101 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2102 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2103 * {@link VideoProfile#STATE_TX_ENABLED},
2104 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002105 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002106 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002107 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002108 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002109 return mVideoState;
2110 }
2111
2112 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002113 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002114 * being routed by the system. This is {@code null} if this Connection
2115 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002116 * @deprecated Use {@link #getCallAudioState()} instead.
2117 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002118 */
Yorke Lee4af59352015-05-13 14:14:54 -07002119 @SystemApi
2120 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002121 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002122 if (mCallAudioState == null) {
2123 return null;
2124 }
Yorke Lee4af59352015-05-13 14:14:54 -07002125 return new AudioState(mCallAudioState);
2126 }
2127
2128 /**
2129 * @return The audio state of the connection, describing how its audio is currently
2130 * being routed by the system. This is {@code null} if this Connection
2131 * does not directly know about its audio state.
2132 */
2133 public final CallAudioState getCallAudioState() {
2134 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 }
2136
2137 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002138 * @return The conference that this connection is a part of. Null if it is not part of any
2139 * conference.
2140 */
2141 public final Conference getConference() {
2142 return mConference;
2143 }
2144
2145 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002146 * Returns whether this connection is requesting that the system play a ringback tone
2147 * on its behalf.
2148 */
Andrew Lee100e2932014-09-08 15:34:24 -07002149 public final boolean isRingbackRequested() {
2150 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002151 }
2152
2153 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002154 * @return True if the connection's audio mode is VOIP.
2155 */
2156 public final boolean getAudioModeIsVoip() {
2157 return mAudioModeIsVoip;
2158 }
2159
2160 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002161 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2162 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2163 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002164 * <p>
2165 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2166 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002167 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002168 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2169 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002170 *
2171 * @hide
2172 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002173 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002174 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002175 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002176 return mConnectTimeMillis;
2177 }
2178
2179 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002180 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2181 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002182 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002183 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002184 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2185 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002186 * <p>
2187 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002188 * <p>
2189 * The value returned is the same one set using
2190 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2191 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2192 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002193 *
2194 * @return The time at which the {@link Connection} was connected.
2195 *
2196 * @hide
2197 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002198 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002199 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002200 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002201 return mConnectElapsedTimeMillis;
2202 }
2203
2204 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002205 * @return The status hints for this connection.
2206 */
2207 public final StatusHints getStatusHints() {
2208 return mStatusHints;
2209 }
2210
2211 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002212 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002213 * <p>
2214 * Extras should be updated using {@link #putExtras(Bundle)}.
2215 * <p>
2216 * Telecom or an {@link InCallService} can also update the extras via
2217 * {@link android.telecom.Call#putExtras(Bundle)}, and
2218 * {@link Call#removeExtras(List)}.
2219 * <p>
2220 * The connection is notified of changes to the extras made by Telecom or an
2221 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002222 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002223 * @return The extras associated with this connection.
2224 */
2225 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002226 Bundle extras = null;
2227 synchronized (mExtrasLock) {
2228 if (mExtras != null) {
2229 extras = new Bundle(mExtras);
2230 }
2231 }
2232 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002233 }
2234
2235 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002236 * Assign a listener to be notified of state changes.
2237 *
2238 * @param l A listener.
2239 * @return This Connection.
2240 *
2241 * @hide
2242 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002243 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002244 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002245 return this;
2246 }
2247
2248 /**
2249 * Remove a previously assigned listener that was being notified of state changes.
2250 *
2251 * @param l A Listener.
2252 * @return This Connection.
2253 *
2254 * @hide
2255 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002256 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002257 if (l != null) {
2258 mListeners.remove(l);
2259 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002260 return this;
2261 }
2262
2263 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002264 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002265 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002266 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002267 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002268 }
2269
2270 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002271 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2272 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002273 * <p>
2274 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2275 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2276 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002277 *
2278 * @param callId The telecom call ID.
2279 * @hide
2280 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002281 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002282 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002283 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002284 mTelecomCallId = callId;
2285 }
2286
2287 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002288 * Inform this Connection that the state of its audio output has been changed externally.
2289 *
2290 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002291 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002292 */
Yorke Lee4af59352015-05-13 14:14:54 -07002293 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002294 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002295 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002296 mCallAudioState = state;
2297 onAudioStateChanged(getAudioState());
2298 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002299 }
2300
2301 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002302 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002303 * @return A string representation of the value.
2304 */
2305 public static String stateToString(int state) {
2306 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002307 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002308 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002309 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002310 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002311 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002312 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002313 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002314 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002315 case STATE_PULLING_CALL:
2316 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002317 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002318 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002319 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002320 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002321 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002322 return "DISCONNECTED";
2323 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002324 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002325 return "UNKNOWN";
2326 }
2327 }
2328
2329 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002330 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002331 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002332 public final int getConnectionCapabilities() {
2333 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002334 }
2335
2336 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002337 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2338 */
2339 public final int getConnectionProperties() {
2340 return mConnectionProperties;
2341 }
2342
2343 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002344 * Returns the connection's supported audio routes.
2345 *
2346 * @hide
2347 */
2348 public final int getSupportedAudioRoutes() {
2349 return mSupportedAudioRoutes;
2350 }
2351
2352 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002353 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002354 *
Andrew Lee100e2932014-09-08 15:34:24 -07002355 * @param address The new address.
2356 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002357 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002358 */
Andrew Lee100e2932014-09-08 15:34:24 -07002359 public final void setAddress(Uri address, int presentation) {
2360 Log.d(this, "setAddress %s", address);
2361 mAddress = address;
2362 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002363 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002364 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002365 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002366 }
2367
2368 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002369 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002370 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002371 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002372 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002373 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002374 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002375 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002376 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002377 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002378 mCallerDisplayName = callerDisplayName;
2379 mCallerDisplayNamePresentation = presentation;
2380 for (Listener l : mListeners) {
2381 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2382 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002383 }
2384
2385 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002386 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002387 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2388 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2389 * {@link VideoProfile#STATE_TX_ENABLED},
2390 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002391 *
2392 * @param videoState The new video state.
2393 */
2394 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002395 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002396 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002397 mVideoState = videoState;
2398 for (Listener l : mListeners) {
2399 l.onVideoStateChanged(this, mVideoState);
2400 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002401 }
2402
2403 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002404 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002405 * communicate).
2406 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002407 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002408 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002409 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002410 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002411 }
2412
2413 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002414 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002415 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002416 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002417 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002418 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002419 }
2420
2421 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002422 * Sets state to initializing (this Connection is not yet ready to be used).
2423 */
2424 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002425 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002426 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002427 }
2428
2429 /**
2430 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2431 */
2432 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002433 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002434 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002435 }
2436
2437 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002438 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002439 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002440 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002441 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002442 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002443 }
2444
2445 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002446 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2447 * device). Only applicable for {@link Connection}s with
2448 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2449 */
2450 public final void setPulling() {
2451 checkImmutable();
2452 setState(STATE_PULLING_CALL);
2453 }
2454
2455 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002456 * Sets state to be on hold.
2457 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002458 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002459 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002460 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002461 }
2462
2463 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002464 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002465 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002466 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002467 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002468 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002469 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002470 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002471 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002472 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002473 }
2474
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002475 public final VideoProvider getVideoProvider() {
2476 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002477 }
2478
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002479 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002480 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002481 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002482 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002483 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002484 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002485 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002486 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002487 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002488 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002489 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002490 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002491 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002492 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002493 }
2494
2495 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002496 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2497 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2498 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2499 * to send an {@link #onPostDialContinue(boolean)} signal.
2500 *
2501 * @param remaining The DTMF character sequence remaining to be emitted once the
2502 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2503 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002504 */
2505 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002506 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002507 for (Listener l : mListeners) {
2508 l.onPostDialWait(this, remaining);
2509 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002510 }
2511
2512 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002513 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2514 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002515 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002516 *
2517 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002518 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002519 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002520 checkImmutable();
2521 for (Listener l : mListeners) {
2522 l.onPostDialChar(this, nextChar);
2523 }
2524 }
2525
2526 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002527 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002528 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002529 *
2530 * @param ringback Whether the ringback tone is to be played.
2531 */
Andrew Lee100e2932014-09-08 15:34:24 -07002532 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002533 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002534 if (mRingbackRequested != ringback) {
2535 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002536 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002537 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002538 }
2539 }
Ihab Awadf8358972014-05-28 16:46:42 -07002540 }
2541
2542 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002543 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002544 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002545 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002546 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002547 public final void setConnectionCapabilities(int connectionCapabilities) {
2548 checkImmutable();
2549 if (mConnectionCapabilities != connectionCapabilities) {
2550 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002551 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002552 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002553 }
2554 }
Santos Cordonb6939982014-06-04 20:20:58 -07002555 }
2556
2557 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002558 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2559 *
2560 * @param connectionProperties The new connection properties.
2561 */
2562 public final void setConnectionProperties(int connectionProperties) {
2563 checkImmutable();
2564 if (mConnectionProperties != connectionProperties) {
2565 mConnectionProperties = connectionProperties;
2566 for (Listener l : mListeners) {
2567 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2568 }
2569 }
2570 }
2571
2572 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002573 * Sets the supported audio routes.
2574 *
2575 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2576 * See {@link CallAudioState}
2577 * @hide
2578 */
2579 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2580 if ((supportedAudioRoutes
2581 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2582 throw new IllegalArgumentException(
2583 "supported audio routes must include either speaker or earpiece");
2584 }
2585
2586 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2587 mSupportedAudioRoutes = supportedAudioRoutes;
2588 for (Listener l : mListeners) {
2589 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2590 }
2591 }
2592 }
2593
2594 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002595 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002596 */
Evan Charlton36a71342014-07-19 16:31:02 -07002597 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002598 for (Listener l : mListeners) {
2599 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002600 }
Santos Cordonb6939982014-06-04 20:20:58 -07002601 }
2602
2603 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002604 * Requests that the framework use VOIP audio mode for this connection.
2605 *
2606 * @param isVoip True if the audio mode is VOIP.
2607 */
2608 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002609 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002610 mAudioModeIsVoip = isVoip;
2611 for (Listener l : mListeners) {
2612 l.onAudioModeIsVoipChanged(this, isVoip);
2613 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002614 }
2615
2616 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002617 * Sets the time at which a call became active on this Connection. This is set only
2618 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002619 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002620 * This time corresponds to the date/time of connection and is stored in the call log in
2621 * {@link android.provider.CallLog.Calls#DATE}.
2622 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002623 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002624 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002625 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2626 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002627 *
2628 * @hide
2629 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002630 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002631 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002632 @RequiresPermission(MODIFY_PHONE_STATE)
2633 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002634 mConnectTimeMillis = connectTimeMillis;
2635 }
2636
2637 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002638 * Sets the time at which a call became active on this Connection. This is set only
2639 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002640 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002641 * This time is used to establish the duration of a call. It uses
2642 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2643 * time zone changes during a call. The difference between the current
2644 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2645 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2646 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002647 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002648 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002649 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2650 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002651 * @hide
2652 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002653 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002654 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002655 @RequiresPermission(MODIFY_PHONE_STATE)
2656 public final void setConnectionStartElapsedRealtimeMillis(
2657 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002658 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2659 }
2660
2661 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002662 * Sets the label and icon status to display in the in-call UI.
2663 *
2664 * @param statusHints The status label and icon to set.
2665 */
2666 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002667 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002668 mStatusHints = statusHints;
2669 for (Listener l : mListeners) {
2670 l.onStatusHintsChanged(this, statusHints);
2671 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002672 }
2673
2674 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002675 * Sets the connections with which this connection can be conferenced.
2676 *
2677 * @param conferenceableConnections The set of connections this connection can conference with.
2678 */
2679 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002680 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002681 clearConferenceableList();
2682 for (Connection c : conferenceableConnections) {
2683 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2684 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002685 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002686 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002687 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002688 }
2689 }
2690 fireOnConferenceableConnectionsChanged();
2691 }
2692
2693 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002694 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2695 * or conferences with which this connection can be conferenced.
2696 *
2697 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002698 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002699 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002700 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002701 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002702 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2703 // small amount of items here.
2704 if (!mConferenceables.contains(c)) {
2705 if (c instanceof Connection) {
2706 Connection connection = (Connection) c;
2707 connection.addConnectionListener(mConnectionDeathListener);
2708 } else if (c instanceof Conference) {
2709 Conference conference = (Conference) c;
2710 conference.addListener(mConferenceDeathListener);
2711 }
2712 mConferenceables.add(c);
2713 }
2714 }
2715 fireOnConferenceableConnectionsChanged();
2716 }
2717
2718 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002719 * Resets the CDMA connection time.
2720 * <p>
2721 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002722 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002723 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002724 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002725 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002726 public final void resetConnectionTime() {
2727 for (Listener l : mListeners) {
2728 l.onConnectionTimeReset(this);
2729 }
2730 }
2731
2732 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002733 * Returns the connections or conferences with which this connection can be conferenced.
2734 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002735 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002736 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002737 }
2738
Yorke Lee53463962015-08-04 16:07:19 -07002739 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002740 * @hide
2741 */
2742 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002743 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002744 if (mConnectionService != null) {
2745 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2746 "which is already associated with another ConnectionService.");
2747 } else {
2748 mConnectionService = connectionService;
2749 }
2750 }
2751
2752 /**
2753 * @hide
2754 */
2755 public final void unsetConnectionService(ConnectionService connectionService) {
2756 if (mConnectionService != connectionService) {
2757 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2758 "that does not belong to the ConnectionService.");
2759 } else {
2760 mConnectionService = null;
2761 }
2762 }
2763
2764 /**
2765 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002766 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002767 *
2768 * @param conference The conference.
2769 * @return {@code true} if the conference was successfully set.
2770 * @hide
2771 */
2772 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002773 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002774 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002775 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002776 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002777 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2778 fireConferenceChanged();
2779 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002780 return true;
2781 }
2782 return false;
2783 }
2784
2785 /**
2786 * Resets the conference that this connection is a part of.
2787 * @hide
2788 */
2789 public final void resetConference() {
2790 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002791 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002792 mConference = null;
2793 fireConferenceChanged();
2794 }
2795 }
2796
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002797 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002798 * Set some extras that can be associated with this {@code Connection}.
2799 * <p>
2800 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2801 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2802 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002803 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2804 * {@link #removeExtras(String...)} methods to modify the extras.
2805 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002806 * 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 -07002807 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2808 *
2809 * @param extras The extras associated with this {@code Connection}.
2810 */
2811 public final void setExtras(@Nullable Bundle extras) {
2812 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002813
2814 // Add/replace any new or changed extras values.
2815 putExtras(extras);
2816
2817 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2818 // the current one and remove any keys that went away.
2819 if (mPreviousExtraKeys != null) {
2820 List<String> toRemove = new ArrayList<String>();
2821 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002822 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002823 toRemove.add(oldKey);
2824 }
2825 }
2826 if (!toRemove.isEmpty()) {
2827 removeExtras(toRemove);
2828 }
2829 }
2830
2831 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2832 // called we can see if the caller has removed any extras values.
2833 if (mPreviousExtraKeys == null) {
2834 mPreviousExtraKeys = new ArraySet<String>();
2835 }
2836 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002837 if (extras != null) {
2838 mPreviousExtraKeys.addAll(extras.keySet());
2839 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002840 }
2841
2842 /**
2843 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2844 * added.
2845 * <p>
2846 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2847 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2848 *
2849 * @param extras The extras to add.
2850 */
2851 public final void putExtras(@NonNull Bundle extras) {
2852 checkImmutable();
2853 if (extras == null) {
2854 return;
2855 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002856 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2857 // the listeners.
2858 Bundle listenerExtras;
2859 synchronized (mExtrasLock) {
2860 if (mExtras == null) {
2861 mExtras = new Bundle();
2862 }
2863 mExtras.putAll(extras);
2864 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002865 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002866 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002867 // Create a new clone of the extras for each listener so that they don't clobber
2868 // each other
2869 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002870 }
2871 }
2872
2873 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002874 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002875 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002876 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002877 */
2878 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002879 synchronized (mExtrasLock) {
2880 if (mExtras != null) {
2881 for (String key : keys) {
2882 mExtras.remove(key);
2883 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002884 }
2885 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002886 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002887 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002888 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002889 }
2890 }
2891
2892 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002893 * Removes extras from this {@code Connection}.
2894 *
2895 * @param keys The keys of the extras to remove.
2896 */
2897 public final void removeExtras(String ... keys) {
2898 removeExtras(Arrays.asList(keys));
2899 }
2900
2901 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002902 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2903 * be change to the {@link #getCallAudioState()}.
2904 * <p>
2905 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2906 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2907 * <p>
2908 * See also {@link InCallService#setAudioRoute(int)}.
2909 *
2910 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2911 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2912 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2913 */
2914 public final void setAudioRoute(int route) {
2915 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002916 l.onAudioRouteChanged(this, route, null);
2917 }
2918 }
2919
2920 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002921 * Request audio routing to a specific bluetooth device. Calling this method may result in
2922 * the device routing audio to a different bluetooth device than the one specified if the
2923 * bluetooth stack is unable to route audio to the requested device.
2924 * A list of available devices can be obtained via
2925 * {@link CallAudioState#getSupportedBluetoothDevices()}
2926 *
2927 * <p>
2928 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2929 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2930 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002931 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2932 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002933 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002934 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002935 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002936 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2937 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002938 }
2939 }
2940
2941 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002942 * Informs listeners that a previously requested RTT session via
2943 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002944 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002945 */
2946 public final void sendRttInitiationSuccess() {
2947 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2948 }
2949
2950 /**
2951 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002952 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002953 * has failed.
2954 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2955 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002956 */
2957 public final void sendRttInitiationFailure(int reason) {
2958 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2959 }
2960
2961 /**
2962 * Informs listeners that a currently active RTT session has been terminated by the remote
2963 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002964 */
2965 public final void sendRttSessionRemotelyTerminated() {
2966 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2967 }
2968
2969 /**
2970 * Informs listeners that the remote side of the call has requested an upgrade to include an
2971 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002972 */
2973 public final void sendRemoteRttRequest() {
2974 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2975 }
2976
2977 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002978 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002979 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002980 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002981 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2982 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002983 */
Yorke Lee4af59352015-05-13 14:14:54 -07002984 @SystemApi
2985 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002986 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002987
2988 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002989 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2990 *
2991 * @param state The new connection audio state.
2992 */
2993 public void onCallAudioStateChanged(CallAudioState state) {}
2994
2995 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002996 * Notifies this Connection of an internal state change. This method is called after the
2997 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002998 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002999 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003000 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003001 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003002
3003 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003004 * Notifies this Connection of a request to play a DTMF tone.
3005 *
3006 * @param c A DTMF character.
3007 */
Santos Cordonf2951102014-07-20 19:06:29 -07003008 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003009
3010 /**
3011 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3012 */
Santos Cordonf2951102014-07-20 19:06:29 -07003013 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003014
3015 /**
3016 * Notifies this Connection of a request to disconnect.
3017 */
Santos Cordonf2951102014-07-20 19:06:29 -07003018 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003019
3020 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003021 * Notifies this Connection of a request to disconnect a participant of the conference managed
3022 * by the connection.
3023 *
3024 * @param endpoint the {@link Uri} of the participant to disconnect.
3025 * @hide
3026 */
3027 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3028
3029 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003030 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003031 */
Santos Cordonf2951102014-07-20 19:06:29 -07003032 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003033
3034 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003035 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303036 *
3037 * @param participants with which conference call will be formed.
3038 */
3039 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3040
3041 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003042 * Notifies this Connection of a request to abort.
3043 */
Santos Cordonf2951102014-07-20 19:06:29 -07003044 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003045
3046 /**
3047 * Notifies this Connection of a request to hold.
3048 */
Santos Cordonf2951102014-07-20 19:06:29 -07003049 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003050
3051 /**
3052 * Notifies this Connection of a request to exit a hold state.
3053 */
Santos Cordonf2951102014-07-20 19:06:29 -07003054 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003055
3056 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003057 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003058 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003059 * <p>
3060 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3061 * the default dialer's {@link InCallService}.
3062 * <p>
3063 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3064 * Telecom framework may request that the call is answered in the following circumstances:
3065 * <ul>
3066 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3067 * <li>A car mode {@link InCallService} is in use which has declared
3068 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3069 * {@link InCallService} will be able to see calls from self-managed
3070 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3071 * behalf.</li>
3072 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003073 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003074 */
Santos Cordonf2951102014-07-20 19:06:29 -07003075 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003076
3077 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003078 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003079 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003080 * <p>
3081 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3082 * the default dialer's {@link InCallService}.
3083 * <p>
3084 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3085 * Telecom framework may request that the call is answered in the following circumstances:
3086 * <ul>
3087 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3088 * <li>A car mode {@link InCallService} is in use which has declared
3089 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3090 * {@link InCallService} will be able to see calls from self-managed
3091 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3092 * behalf.</li>
3093 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003094 */
3095 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003096 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003097 }
3098
3099 /**
3100 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303101 * a request to deflect.
3102 */
3103 public void onDeflect(Uri address) {}
3104
3105 /**
3106 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003107 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003108 * <p>
3109 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3110 * the default dialer's {@link InCallService}.
3111 * <p>
3112 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3113 * Telecom framework may request that the call is rejected in the following circumstances:
3114 * <ul>
3115 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3116 * <li>A car mode {@link InCallService} is in use which has declared
3117 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3118 * {@link InCallService} will be able to see calls from self-managed
3119 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3120 * behalf.</li>
3121 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003122 */
Santos Cordonf2951102014-07-20 19:06:29 -07003123 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003124
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003125 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003126 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3127 * <p>
3128 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3129 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3130 * @param rejectReason the reason the user provided for rejecting the call.
3131 */
3132 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3133 // to be implemented by ConnectionService.
3134 }
3135
3136 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003137 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3138 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003139 */
3140 public void onReject(String replyMessage) {}
3141
3142 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303143 * Notifies this Connection, a request to transfer to a target number.
3144 * @param number the number to transfer this {@link Connection} to.
3145 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3146 * should wait until the transfer has successfully completed before disconnecting
3147 * the current {@link Connection}.
3148 * When {@code false}, the {@link ConnectionService} should signal the network to
3149 * perform the transfer, but should immediately disconnect the call regardless of
3150 * the outcome of the transfer.
3151 * @hide
3152 */
3153 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3154
3155 /**
3156 * Notifies this Connection, a request to transfer to another Connection.
3157 * @param otherConnection the {@link Connection} to transfer this call to.
3158 * @hide
3159 */
3160 public void onTransfer(@NonNull Connection otherConnection) {}
3161
3162 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003163 * Notifies this Connection of a request to silence the ringer.
3164 * <p>
3165 * The ringer may be silenced by any of the following methods:
3166 * <ul>
3167 * <li>{@link TelecomManager#silenceRinger()}</li>
3168 * <li>The user presses the volume-down button while a call is ringing.</li>
3169 * </ul>
3170 * <p>
3171 * Self-managed {@link ConnectionService} implementations should override this method in their
3172 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3173 * your app set the ringtone as part of the incoming call {@link Notification} (see
3174 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3175 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3176 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3177 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003178 */
3179 public void onSilence() {}
3180
3181 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003182 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3183 */
Santos Cordonf2951102014-07-20 19:06:29 -07003184 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003185
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003186 /**
3187 * Notifies this Connection of a request to pull an external call to the local device.
3188 * <p>
3189 * The {@link InCallService} issues a request to pull an external call to the local device via
3190 * {@link Call#pullExternalCall()}.
3191 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003192 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3193 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003194 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003195 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003196 */
3197 public void onPullExternalCall() {}
3198
3199 /**
3200 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3201 * <p>
3202 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3203 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003204 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3205 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3206 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3207 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3208 * not aware of.
3209 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003210 * See also {@link Call#sendCallEvent(String, Bundle)}.
3211 *
3212 * @param event The call event.
3213 * @param extras Extras associated with the call event.
3214 */
3215 public void onCallEvent(String event, Bundle extras) {}
3216
Tyler Gunndee56a82016-03-23 16:06:34 -07003217 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003218 * Notifies this {@link Connection} that a handover has completed.
3219 * <p>
3220 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3221 * Bundle)} on the initiating side of the handover, and
3222 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3223 */
3224 public void onHandoverComplete() {}
3225
3226 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003227 * Notifies this {@link Connection} of a change to the extras made outside the
3228 * {@link ConnectionService}.
3229 * <p>
3230 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3231 * the {@link android.telecom.Call#putExtras(Bundle)} and
3232 * {@link Call#removeExtras(List)}.
3233 *
3234 * @param extras The new extras bundle.
3235 */
3236 public void onExtrasChanged(Bundle extras) {}
3237
Tyler Gunnf5035432017-01-09 09:43:12 -08003238 /**
3239 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3240 * displaying its incoming call user interface for the {@link Connection}.
3241 * <p>
3242 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3243 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3244 * should show its own incoming call user interface.
3245 * <p>
3246 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003247 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3248 * Telecom framework will display its own incoming call user interface to allow the user to
3249 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3250 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003251 * <p>
3252 * You should trigger the display of the incoming call user interface for your application by
3253 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003254 *
3255 * In your application code, you should create a {@link android.app.NotificationChannel} for
3256 * incoming call notifications from your app:
3257 * <pre><code>
3258 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3259 * NotificationManager.IMPORTANCE_MAX);
3260 * // other channel setup stuff goes here.
3261 *
3262 * // We'll use the default system ringtone for our incoming call notification channel. You can
3263 * // use your own audio resource here.
3264 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3265 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3266 * // Setting the AudioAttributes is important as it identifies the purpose of your
3267 * // notification sound.
3268 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3269 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3270 * .build());
3271 *
3272 * NotificationManager mgr = getSystemService(NotificationManager.class);
3273 * mgr.createNotificationChannel(channel);
3274 * </code></pre>
3275 * When it comes time to post a notification for your incoming call, ensure it uses your
3276 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003277 * <pre><code>
3278 * // Create an intent which triggers your fullscreen incoming call user interface.
3279 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3280 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3281 * intent.setClass(context, YourIncomingCallActivity.class);
3282 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3283 *
3284 * // Build the notification as an ongoing high priority item; this ensures it will show as
3285 * // a heads up notification which slides down over top of the current content.
3286 * final Notification.Builder builder = new Notification.Builder(context);
3287 * builder.setOngoing(true);
3288 * builder.setPriority(Notification.PRIORITY_HIGH);
3289 *
3290 * // Set notification content intent to take user to fullscreen UI if user taps on the
3291 * // notification body.
3292 * builder.setContentIntent(pendingIntent);
3293 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3294 * // manager deems it appropriate.
3295 * builder.setFullScreenIntent(pendingIntent, true);
3296 *
3297 * // Setup notification content.
3298 * builder.setSmallIcon( yourIconResourceId );
3299 * builder.setContentTitle("Your notification title");
3300 * builder.setContentText("Your notification content.");
3301 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003302 * // Set notification as insistent to cause your ringtone to loop.
3303 * Notification notification = builder.build();
3304 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003305 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003306 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003307 * NotificationManager notificationManager = mContext.getSystemService(
3308 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003309 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003310 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003311 */
3312 public void onShowIncomingCallUi() {}
3313
Hall Liub64ac4c2017-02-06 10:49:48 -08003314 /**
3315 * Notifies this {@link Connection} that the user has requested an RTT session.
3316 * The connection service should call {@link #sendRttInitiationSuccess} or
3317 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3318 * request, respectively.
3319 * @param rttTextStream The object that should be used to send text to or receive text from
3320 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003321 */
3322 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3323
3324 /**
3325 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3326 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003327 */
3328 public void onStopRtt() {}
3329
3330 /**
3331 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3332 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3333 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3334 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003335 * @param rttTextStream The object that should be used to send text to or receive text from
3336 * the in-call app.
3337 */
3338 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3339
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003340 static String toLogSafePhoneNumber(String number) {
3341 // For unknown number, log empty string.
3342 if (number == null) {
3343 return "";
3344 }
3345
3346 if (PII_DEBUG) {
3347 // When PII_DEBUG is true we emit PII.
3348 return number;
3349 }
3350
3351 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3352 // sanitized phone numbers.
3353 StringBuilder builder = new StringBuilder();
3354 for (int i = 0; i < number.length(); i++) {
3355 char c = number.charAt(i);
3356 if (c == '-' || c == '@' || c == '.') {
3357 builder.append(c);
3358 } else {
3359 builder.append('x');
3360 }
3361 }
3362 return builder.toString();
3363 }
3364
Ihab Awad542e0ea2014-05-16 10:22:16 -07003365 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003366 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003367 if (mState == STATE_DISCONNECTED && mState != state) {
3368 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003369 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003370 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003371 if (mState != state) {
3372 Log.d(this, "setState: %s", stateToString(state));
3373 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003374 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003375 for (Listener l : mListeners) {
3376 l.onStateChanged(this, state);
3377 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003378 }
3379 }
3380
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003381 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003382 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003383 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3384 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003385 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003386 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003387
3388 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003389 if (mImmutable) {
3390 throw new UnsupportedOperationException("Connection is immutable");
3391 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003392 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003393 }
3394
Evan Charltonbf11f982014-07-20 22:06:28 -07003395 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003396 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003397 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3398 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003399 * <p>
3400 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3401 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003402 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003403 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003404 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003405 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003406 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3407 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003408 }
3409
Evan Charltonbf11f982014-07-20 22:06:28 -07003410 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003411 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3412 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3413 * this should never be un-@hide-den.
3414 *
3415 * @hide
3416 */
3417 public void checkImmutable() {}
3418
3419 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003420 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3421 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3422 * that state. This connection should not be used for anything, and no other
3423 * {@code Connection}s should be attempted.
3424 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003425 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003426 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003427 * @return A {@code Connection} which indicates that the underlying connection should
3428 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003429 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003430 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003431 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003432 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003433
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003434 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003435 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003436 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003437 }
3438 }
3439
Santos Cordon823fd3c2014-08-07 18:35:18 -07003440 private final void fireConferenceChanged() {
3441 for (Listener l : mListeners) {
3442 l.onConferenceChanged(this, mConference);
3443 }
3444 }
3445
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003446 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003447 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003448 if (c instanceof Connection) {
3449 Connection connection = (Connection) c;
3450 connection.removeConnectionListener(mConnectionDeathListener);
3451 } else if (c instanceof Conference) {
3452 Conference conference = (Conference) c;
3453 conference.removeListener(mConferenceDeathListener);
3454 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003455 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003456 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003457 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003458
3459 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003460 * Handles a change to extras received from Telecom.
3461 *
3462 * @param extras The new extras.
3463 * @hide
3464 */
3465 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003466 Bundle b = null;
3467 synchronized (mExtrasLock) {
3468 mExtras = extras;
3469 if (mExtras != null) {
3470 b = new Bundle(mExtras);
3471 }
3472 }
3473 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003474 }
3475
3476 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003477 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3478 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003479 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003480 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003481 for (Listener l : mListeners) {
3482 l.onConferenceMergeFailed(this);
3483 }
3484 }
3485
3486 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303487 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3488 * changed due to an emergency call being redialed.
3489 * @param pHandle The new PhoneAccountHandle for this connection.
3490 * @hide
3491 */
3492 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3493 for (Listener l : mListeners) {
3494 l.onPhoneAccountChanged(this, pHandle);
3495 }
3496 }
3497
3498 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003499 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003500 * <p>
3501 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3502 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003503 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003504 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003505 * @hide
3506 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003507 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003508 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003509 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003510 if (mPhoneAccountHandle != phoneAccountHandle) {
3511 mPhoneAccountHandle = phoneAccountHandle;
3512 notifyPhoneAccountChanged(phoneAccountHandle);
3513 }
3514 }
3515
3516 /**
3517 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003518 * <p>
3519 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3520 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003521 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003522 * @return the phone account handle specified via
3523 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003524 * @hide
3525 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003526 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003527 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003528 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003529 return mPhoneAccountHandle;
3530 }
3531
3532 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003533 * Sends an event associated with this {@code Connection} with associated event extras to the
3534 * {@link InCallService}.
3535 * <p>
3536 * Connection events are used to communicate point in time information from a
3537 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3538 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3539 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3540 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3541 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3542 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3543 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3544 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3545 * <p>
3546 * Events are exposed to {@link InCallService} implementations via
3547 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3548 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003549 * 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 -07003550 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3551 * some events altogether.
3552 * <p>
3553 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3554 * conflicts between {@link ConnectionService} implementations. Further, custom
3555 * {@link ConnectionService} implementations shall not re-purpose events in the
3556 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3557 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3558 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3559 * {@code com.example.extra.MY_EXTRA}).
3560 * <p>
3561 * When defining events and the associated extras, it is important to keep their behavior
3562 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3563 * events/extras should me maintained to ensure backwards compatibility with older
3564 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003565 *
3566 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003567 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003568 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003569 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003570 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003571 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003572 }
3573 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003574
3575 /**
3576 * @return The direction of the call.
3577 * @hide
3578 */
3579 public final @Call.Details.CallDirection int getCallDirection() {
3580 return mCallDirection;
3581 }
3582
3583 /**
3584 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003585 * <p>
3586 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3587 * call direction.
3588 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003589 * @param callDirection The direction of this connection.
3590 * @hide
3591 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003592 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003593 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003594 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3595 mCallDirection = callDirection;
3596 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003597
3598 /**
3599 * Gets the verification status for the phone number of an incoming call as identified in
3600 * ATIS-1000082.
3601 * @return the verification status.
3602 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003603 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003604 return mCallerNumberVerificationStatus;
3605 }
3606
3607 /**
3608 * Sets the verification status for the phone number of an incoming call as identified in
3609 * ATIS-1000082.
3610 * <p>
3611 * This property can only be set at the time of creation of a {@link Connection} being returned
3612 * by
3613 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3614 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003615 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003616 @VerificationStatus int callerNumberVerificationStatus) {
3617 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3618 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003619}