blob: 52d560cbf7334d02b2371b1130f2e0b925c4d9f9 [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 Gunn159f35c2017-03-02 09:28:37 -080028import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080029import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000030import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080031import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070032import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080034import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070035import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Handler;
37import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070038import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080040import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070042import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080043import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070044import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070045import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046
Youming Yed6de26e2019-01-30 11:20:35 -080047import com.android.internal.os.SomeArgs;
48import com.android.internal.telecom.IVideoCallback;
49import com.android.internal.telecom.IVideoProvider;
50
Hall Liua549fed2018-02-09 16:40:03 -080051import java.io.FileInputStream;
52import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080053import java.io.IOException;
54import java.io.InputStreamReader;
55import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070056import java.lang.annotation.Retention;
57import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070058import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070059import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070060import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070061import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070062import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070063import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070064import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070065
66/**
Santos Cordon895d4b82015-06-25 16:41:48 -070067 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
68 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070069 * <p>
70 * Implementations create a custom subclass of {@code Connection} and return it to the framework
71 * as the return value of
72 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
73 * or
74 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
75 * Implementations are then responsible for updating the state of the {@code Connection}, and
76 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
77 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070078 * <p>
79 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
80 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
81 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
82 * {@code Connection} instance.
83 * <p>
84 * Basic call support requires overriding the following methods: {@link #onAnswer()},
85 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
86 * <p>
87 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
88 * {@link #onUnhold()} methods should be overridden to provide hold support for the
89 * {@code Connection}.
90 * <p>
91 * Where a {@code Connection} supports a variation of video calling (e.g. the
92 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
93 * to support answering a call as a video call.
94 * <p>
95 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
96 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
97 * support for pulling the external call.
98 * <p>
99 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
100 * overridden.
101 * <p>
102 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
103 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
104 * for example, call events from a {@link InCallService} are handled,
105 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
106 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
107 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
108 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700109 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700110public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700111
Tyler Gunn50d437f2021-01-12 16:34:59 -0800112 /**@hide*/
113 @Retention(RetentionPolicy.SOURCE)
114 @IntDef(prefix = "STATE_", value = {
115 STATE_INITIALIZING,
116 STATE_NEW,
117 STATE_RINGING,
118 STATE_DIALING,
119 STATE_ACTIVE,
120 STATE_HOLDING,
121 STATE_DISCONNECTED,
122 STATE_PULLING_CALL
123 })
124 public @interface ConnectionState {}
125
Santos Cordon895d4b82015-06-25 16:41:48 -0700126 /**
127 * The connection is initializing. This is generally the first state for a {@code Connection}
128 * returned by a {@link ConnectionService}.
129 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700130 public static final int STATE_INITIALIZING = 0;
131
Santos Cordon895d4b82015-06-25 16:41:48 -0700132 /**
133 * The connection is new and not connected.
134 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700135 public static final int STATE_NEW = 1;
136
Santos Cordon895d4b82015-06-25 16:41:48 -0700137 /**
138 * An incoming connection is in the ringing state. During this state, the user's ringer or
139 * vibration feature will be activated.
140 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 public static final int STATE_RINGING = 2;
142
Santos Cordon895d4b82015-06-25 16:41:48 -0700143 /**
144 * An outgoing connection is in the dialing state. In this state the other party has not yet
145 * answered the call and the user traditionally hears a ringback tone.
146 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700147 public static final int STATE_DIALING = 3;
148
Santos Cordon895d4b82015-06-25 16:41:48 -0700149 /**
150 * A connection is active. Both parties are connected to the call and can actively communicate.
151 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 public static final int STATE_ACTIVE = 4;
153
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 /**
155 * A connection is on hold.
156 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700157 public static final int STATE_HOLDING = 5;
158
Santos Cordon895d4b82015-06-25 16:41:48 -0700159 /**
160 * A connection has been disconnected. This is the final state once the user has been
161 * disconnected from a call either locally, remotely or by an error in the service.
162 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 public static final int STATE_DISCONNECTED = 6;
164
Santos Cordon895d4b82015-06-25 16:41:48 -0700165 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700166 * The state of an external connection which is in the process of being pulled from a remote
167 * device to the local device.
168 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700169 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700170 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
171 */
172 public static final int STATE_PULLING_CALL = 7;
173
174 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700175 * Indicates that the network could not perform verification.
176 */
177 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
178
179 /**
180 * Indicates that verification by the network passed. This indicates there is a high likelihood
181 * that the call originated from a valid source.
182 */
183 public static final int VERIFICATION_STATUS_PASSED = 1;
184
185 /**
186 * Indicates that verification by the network failed. This indicates there is a high likelihood
187 * that the call did not originate from a valid source.
188 */
189 public static final int VERIFICATION_STATUS_FAILED = 2;
190
191 /**@hide*/
192 @Retention(RetentionPolicy.SOURCE)
193 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
194 VERIFICATION_STATUS_NOT_VERIFIED,
195 VERIFICATION_STATUS_PASSED,
196 VERIFICATION_STATUS_FAILED
197 })
198 public @interface VerificationStatus {}
199
200 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700201 * Connection can currently be put on hold or unheld. This is distinct from
202 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
203 * it does not at the moment support the function. This can be true while the call is in the
204 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
205 * display a disabled 'hold' button.
206 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207 public static final int CAPABILITY_HOLD = 0x00000001;
208
209 /** Connection supports the hold feature. */
210 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
211
212 /**
213 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
214 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
215 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
216 * capability allows a merge button to be shown while the conference is in the foreground
217 * of the in-call UI.
218 * <p>
219 * This is only intended for use by a {@link Conference}.
220 */
221 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
222
223 /**
224 * Connections within a conference can be swapped between foreground and background.
225 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
226 * <p>
227 * This is only intended for use by a {@link Conference}.
228 */
229 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
230
231 /**
232 * @hide
233 */
234 public static final int CAPABILITY_UNUSED = 0x00000010;
235
236 /** Connection supports responding via text option. */
237 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
238
239 /** Connection can be muted. */
240 public static final int CAPABILITY_MUTE = 0x00000040;
241
242 /**
243 * Connection supports conference management. This capability only applies to
244 * {@link Conference}s which can have {@link Connection}s as children.
245 */
246 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
247
248 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800250 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800252
253 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800255 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800257
258 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700259 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800260 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700261 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263
264 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
268
269 /**
270 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700271 */
272 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
273
274 /**
275 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700277 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800279
280 /**
281 * Connection is able to be separated from its parent {@code Conference}, if any.
282 */
283 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
284
285 /**
286 * Connection is able to be individually disconnected when in a {@code Conference}.
287 */
288 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
289
290 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700291 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800292 * @hide
293 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700294 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800295
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700296 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700297 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700298 * @hide
299 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700300 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700301
302 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700303 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700304 * @hide
305 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700306 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700307
Tyler Gunn068085b2015-02-06 13:56:52 -0800308 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700309 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800310 * @hide
311 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700312 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800313
Tyler Gunn96d6c402015-03-18 12:39:23 -0700314 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500315 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700316 * <p>
317 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
318 * place as soon as the device answers the call, but prior to it being connected. This is an
319 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500320 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700321 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700322 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700323 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800324
Rekha Kumar07366812015-03-24 16:42:31 -0700325 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700326 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800327 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
328 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
329 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700330 */
331 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
332
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700333 /**
334 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700335 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700336 */
337 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
338
Tyler Gunnd4091732015-06-29 09:15:37 -0700339 /**
340 * For a conference, indicates the conference will not have child connections.
341 * <p>
342 * An example of a conference with child connections is a GSM conference call, where the radio
343 * retains connections to the individual participants of the conference. Another example is an
344 * IMS conference call where conference event package functionality is supported; in this case
345 * the conference server ensures the radio is aware of the participants in the conference, which
346 * are represented by child connections.
347 * <p>
348 * An example of a conference with no child connections is an IMS conference call with no
349 * conference event package support. Such a conference is represented by the radio as a single
350 * connection to the IMS conference server.
351 * <p>
352 * Indicating whether a conference has children or not is important to help user interfaces
353 * visually represent a conference. A conference with no children, for example, will have the
354 * conference connection shown in the list of calls on a Bluetooth device, where if the
355 * conference has children, only the children will be shown in the list of calls on a Bluetooth
356 * device.
357 * @hide
358 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700359 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700360 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
361
Bryce Lee81901682015-08-28 16:38:02 -0700362 /**
363 * Indicates that the connection itself wants to handle any sort of reply response, rather than
364 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700365 */
366 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
367
Tyler Gunnf97a0092016-01-19 15:59:34 -0800368 /**
369 * When set, prevents a video call from being downgraded to an audio-only call.
370 * <p>
371 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
372 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
373 * downgraded from a video call back to a VideoState of
374 * {@link VideoProfile#STATE_AUDIO_ONLY}.
375 * <p>
376 * Intuitively, a call which can be downgraded to audio should also have local and remote
377 * video
378 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
379 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
380 */
381 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
382
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700383 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700384 * When set for an external connection, indicates that this {@code Connection} can be pulled
385 * from a remote device to the current device.
386 * <p>
387 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
388 * is set.
389 */
390 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
391
Pooja Jaind34698d2017-12-28 14:15:31 +0530392 /** Call supports the deflect feature. */
393 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
394
Ravi Paluri404babb2020-01-23 19:02:44 +0530395 /**
396 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700397 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
398 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
399 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
400 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530401 */
402 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530403
404 /**
405 * Indicates that this {@code Connection} can be transferred to another
406 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700407 * Connection supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530408 * @hide
409 */
410 public static final int CAPABILITY_TRANSFER = 0x08000000;
411
412 /**
413 * Indicates that this {@code Connection} can be transferred to another
414 * ongoing {@code Connection}.
415 * Connection supports the consultative call transfer feature.
416 * @hide
417 */
418 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
419
Tyler Gunn720c6642016-03-22 09:02:47 -0700420 //**********************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530421 // Next CAPABILITY value: 0x20000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700422 //**********************************************************************************************
423
424 /**
425 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700426 * <p>
427 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700428 * @hide
429 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700430 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700431 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700432
433 /**
434 * Whether the call is a generic conference, where we do not know the precise state of
435 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700436 * <p>
437 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700438 * @hide
439 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700440 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700441 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
442
443 /**
444 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700445 * <p>
446 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
447 * implies something like AMR wideband, but the interpretation of when a call is considered high
448 * definition is left to the {@link ConnectionService} to decide.
449 * <p>
450 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700451 */
452 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
453
454 /**
455 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700456 * <p>
457 * Used to indicate that a call is taking place over WIFI versus a carrier network.
458 * <p>
459 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700460 */
461 public static final int PROPERTY_WIFI = 1<<3;
462
463 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700464 * When set, indicates that the {@code Connection} does not actually exist locally for the
465 * {@link ConnectionService}.
466 * <p>
467 * Consider, for example, a scenario where a user has two devices with the same phone number.
468 * When a user places a call on one devices, the telephony stack can represent that call on the
469 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700470 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700471 * <p>
472 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
473 * external connections. Only those {@link InCallService}s which have the
474 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
475 * manifest will see external connections.
476 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700477 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700478
Brad Ebinger15847072016-05-18 11:08:36 -0700479 /**
480 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
481 */
482 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700483
Hall Liu9f332c72016-07-14 15:37:37 -0700484 /**
485 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700486 * <p>
487 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
488 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700489 * @hide
490 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700491 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700492 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
493
Tyler Gunnf5035432017-01-09 09:43:12 -0800494 /**
495 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
496 * {@link ConnectionService}.
497 * <p>
498 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
499 */
500 public static final int PROPERTY_SELF_MANAGED = 1<<7;
501
Hall Liu95d55872017-01-25 17:12:49 -0800502 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800503 * Set by the framework to indicate that a connection has an active RTT session associated with
504 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800505 */
506 public static final int PROPERTY_IS_RTT = 1 << 8;
507
Eric Erfanian62706c52017-12-06 16:27:53 -0800508 /**
509 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700510 * <p>
511 * This is used for outgoing calls.
512 *
513 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800514 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800515 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800516
Tyler Gunn5bd90852018-09-21 09:37:07 -0700517 /**
518 * Set by the framework to indicate that the network has identified a Connection as an emergency
519 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700520 * <p>
521 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
522 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700523 */
524 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
525
Tyler Gunnac60f952019-05-31 07:23:16 -0700526 /**
527 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
528 * than the current one. Used in scenarios where the conference originator is the remote device
529 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700530 * <p>
531 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700532 * @hide
533 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700534 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700535 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
536
Ravi Paluri80aa2142019-12-02 11:57:37 +0530537 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700538 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530539 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700540 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530541 */
542 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
543
544
Tyler Gunn96d6c402015-03-18 12:39:23 -0700545 //**********************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530546 // Next PROPERTY value: 1<<13
Tyler Gunn96d6c402015-03-18 12:39:23 -0700547 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800548
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700549 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800550 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800551 */
allenwtsu2aca9892019-11-25 14:38:21 +0800552 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800553 /**
554 * Adaptive Multi-rate audio codec.
555 */
allenwtsu2aca9892019-11-25 14:38:21 +0800556 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800557 /**
558 * Adaptive Multi-rate wideband audio codec.
559 */
allenwtsu2aca9892019-11-25 14:38:21 +0800560 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800561 /**
562 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
563 */
allenwtsu2aca9892019-11-25 14:38:21 +0800564 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800565 /**
566 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
567 */
allenwtsu2aca9892019-11-25 14:38:21 +0800568 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800569 /**
570 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
571 */
allenwtsu2aca9892019-11-25 14:38:21 +0800572 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800573 /**
574 * Enhanced Variable Rate Wideband Codec. See RFC5188.
575 */
allenwtsu2aca9892019-11-25 14:38:21 +0800576 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800577 /**
578 * Enhanced Variable Rate Narrowband-Wideband Codec.
579 */
allenwtsu2aca9892019-11-25 14:38:21 +0800580 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800581 /**
582 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
583 */
allenwtsu2aca9892019-11-25 14:38:21 +0800584 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800585 /**
586 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
587 */
allenwtsu2aca9892019-11-25 14:38:21 +0800588 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800589 /**
590 * GSM Half Rate audio codec.
591 */
allenwtsu2aca9892019-11-25 14:38:21 +0800592 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800593 /**
594 * ITU-T G711U audio codec.
595 */
allenwtsu2aca9892019-11-25 14:38:21 +0800596 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800597 /**
598 * ITU-T G723 audio codec.
599 */
allenwtsu2aca9892019-11-25 14:38:21 +0800600 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800601 /**
602 * ITU-T G711A audio codec.
603 */
allenwtsu2aca9892019-11-25 14:38:21 +0800604 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800605 /**
606 * ITU-T G722 audio codec.
607 */
allenwtsu2aca9892019-11-25 14:38:21 +0800608 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800609 /**
610 * ITU-T G711AB audio codec.
611 */
allenwtsu2aca9892019-11-25 14:38:21 +0800612 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800613 /**
614 * ITU-T G729 audio codec.
615 */
allenwtsu2aca9892019-11-25 14:38:21 +0800616 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800617 /**
618 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
619 */
allenwtsu2aca9892019-11-25 14:38:21 +0800620 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800621 /**
622 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
623 */
allenwtsu2aca9892019-11-25 14:38:21 +0800624 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800625 /**
626 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
627 */
allenwtsu2aca9892019-11-25 14:38:21 +0800628 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800629 /**
630 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
631 */
allenwtsu2aca9892019-11-25 14:38:21 +0800632 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
633
Tyler Gunn1c687622019-12-20 11:08:13 -0800634 /**@hide*/
635 @Retention(RetentionPolicy.SOURCE)
636 @IntDef(prefix = "AUDIO_CODEC_", value = {
637 AUDIO_CODEC_NONE,
638 AUDIO_CODEC_AMR,
639 AUDIO_CODEC_AMR_WB,
640 AUDIO_CODEC_QCELP13K,
641 AUDIO_CODEC_EVRC,
642 AUDIO_CODEC_EVRC_B,
643 AUDIO_CODEC_EVRC_WB,
644 AUDIO_CODEC_EVRC_NW,
645 AUDIO_CODEC_GSM_EFR,
646 AUDIO_CODEC_GSM_FR,
647 AUDIO_CODEC_GSM_HR,
648 AUDIO_CODEC_G711U,
649 AUDIO_CODEC_G723,
650 AUDIO_CODEC_G711A,
651 AUDIO_CODEC_G722,
652 AUDIO_CODEC_G711AB,
653 AUDIO_CODEC_G729,
654 AUDIO_CODEC_EVS_NB,
655 AUDIO_CODEC_EVS_SWB,
656 AUDIO_CODEC_EVS_FB
657 })
658 public @interface AudioCodec {}
659
allenwtsu2aca9892019-11-25 14:38:21 +0800660 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700661 * Connection extra key used to store the last forwarded number associated with the current
662 * connection. Used to communicate to the user interface that the connection was forwarded via
663 * the specified number.
664 */
665 public static final String EXTRA_LAST_FORWARDED_NUMBER =
666 "android.telecom.extra.LAST_FORWARDED_NUMBER";
667
668 /**
669 * Connection extra key used to store a child number associated with the current connection.
670 * Used to communicate to the user interface that the connection was received via
671 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
672 * address.
673 */
674 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
675
676 /**
677 * Connection extra key used to store the subject for an incoming call. The user interface can
678 * query this extra and display its contents for incoming calls. Will only be used if the
679 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
680 */
681 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
682
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800683 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700684 * Boolean connection extra key set on a {@link Connection} in
685 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
686 * current active foreground call to be dropped.
687 */
688 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
689 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
690
691 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700692 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
693 * state to indicate the name of the third-party app which is responsible for the current
694 * foreground call.
695 * <p>
696 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
697 * is able to inform the user that answering the new incoming call will cause a call owned by
698 * another app to be dropped when the incoming call is answered.
699 */
700 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
701 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
702
703 /**
Hall Liu10208662016-06-15 17:55:00 -0700704 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700705 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700706 * <p>
707 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
708 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700709 * @hide
710 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700711 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700712 public static final String EXTRA_DISABLE_ADD_CALL =
713 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700714
715 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700716 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
717 * original Connection ID associated with the connection. Used in
718 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
719 * connection/conference added via
720 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
721 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
722 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
723 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
724 * be a way to ensure that we don't add the connection again as a duplicate.
725 * <p>
726 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
727 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
728 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
729 * in a new {@link Connection} which it adds to Telecom via
730 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
731 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
732 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
733 * ID it originally referred to the connection as. Thus Telecom needs to know that the
734 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700735 * <p>
736 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
737 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700738 * @hide
739 */
740 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
741 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
742
743 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700744 * Extra key set on a {@link Connection} when it was created via a remote connection service.
745 * For example, if a connection manager requests a remote connection service to create a call
746 * using one of the remote connection service's phone account handle, this extra will be set so
747 * that Telecom knows that the wrapped remote connection originated in a remote connection
748 * service. We stash this in the extras since connection managers will typically copy the
749 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
750 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
751 * @hide
752 */
753 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
754 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
755
756 /**
757 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
758 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
759 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
760 * {@link ConnectionService} with a means to know the package name of the requesting
761 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
762 * better visibility in Telecom of where a connection ultimately originated.
763 * @hide
764 */
765 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
766 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
767
768 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700769 * Boolean connection extra key set on the extras passed to
770 * {@link Connection#sendConnectionEvent} which indicates that audio is present
771 * on the RTT call when the extra value is true.
772 */
773 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
774 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
775
776 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800777 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
778 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800779 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800780 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800781 "android.telecom.extra.AUDIO_CODEC";
782
783 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800784 * Float connection extra key used to store the audio codec bitrate in kbps for the current
785 * {@link Connection}.
786 */
787 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
788 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
789
790 /**
791 * Float connection extra key used to store the audio codec bandwidth in khz for the current
792 * {@link Connection}.
793 */
794 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
795 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
796 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800797 * Connection event used to inform Telecom that it should play the on hold tone. This is used
798 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700799 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800800 */
801 public static final String EVENT_ON_HOLD_TONE_START =
802 "android.telecom.event.ON_HOLD_TONE_START";
803
804 /**
805 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
806 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700807 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800808 */
809 public static final String EVENT_ON_HOLD_TONE_END =
810 "android.telecom.event.ON_HOLD_TONE_END";
811
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700812 /**
813 * Connection event used to inform {@link InCallService}s when pulling of an external call has
814 * failed. The user interface should inform the user of the error.
815 * <p>
816 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
817 * API is called on a {@link Call} with the properties
818 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
819 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
820 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700821 * <p>
822 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
823 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700824 */
825 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
826
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700827 /**
828 * Connection event used to inform {@link InCallService}s when the merging of two calls has
829 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700830 * <p>
831 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
832 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700833 */
834 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
835
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700836 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700837 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700838 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700839 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
840 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700841 */
842 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
843
844 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900845 * Connection event used to inform Telecom when a switch operation on a call has failed.
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.
849 */
850 public static final String EVENT_CALL_SWITCH_FAILED =
851 "android.telecom.event.CALL_SWITCH_FAILED";
852
853 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700854 * Connection event used to inform {@link InCallService}s when the process of merging a
855 * Connection into a conference has begun.
856 * <p>
857 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
858 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700859 */
860 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
861
862 /**
863 * Connection event used to inform {@link InCallService}s when the process of merging a
864 * Connection into a conference has completed.
865 * <p>
866 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
867 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700868 */
869 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
870
871 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700872 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
873 * the remote party.
874 * <p>
875 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
876 * call is being held locally on the device. When a capable {@link ConnectionService} receives
877 * signalling to indicate that the remote party has put the call on hold, it can send this
878 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700879 */
880 public static final String EVENT_CALL_REMOTELY_HELD =
881 "android.telecom.event.CALL_REMOTELY_HELD";
882
883 /**
884 * Connection event used to inform {@link InCallService}s when a call which was remotely held
885 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
886 * <p>
887 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
888 * call is being held locally on the device. When a capable {@link ConnectionService} receives
889 * signalling to indicate that the remote party has taken the call off hold, it can send this
890 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700891 */
892 public static final String EVENT_CALL_REMOTELY_UNHELD =
893 "android.telecom.event.CALL_REMOTELY_UNHELD";
894
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700895 /**
896 * Connection event used to inform an {@link InCallService} which initiated a call handover via
897 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
898 * successfully completed.
899 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700900 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
901 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700902 */
903 public static final String EVENT_HANDOVER_COMPLETE =
904 "android.telecom.event.HANDOVER_COMPLETE";
905
906 /**
907 * Connection event used to inform an {@link InCallService} which initiated a call handover via
908 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
909 * to complete.
910 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700911 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
912 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700913 */
914 public static final String EVENT_HANDOVER_FAILED =
915 "android.telecom.event.HANDOVER_FAILED";
916
shilub7ec9a02018-11-09 15:52:04 -0800917 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000918 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800919 */
920 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
921
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700922 /**
923 * Connection event used to inform an {@link InCallService} that the RTT audio indication
924 * has changed.
925 */
926 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
927 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
928
Tyler Gunnd5821842021-02-05 11:12:57 -0800929 /**
930 * Connection event used to signal between the telephony {@link ConnectionService} and Telecom
931 * when device to device messages are sent/received.
932 * <p>
933 * Device to device messages originating from the network are sent by telephony using
934 * {@link Connection#sendConnectionEvent(String, Bundle)} and are routed up to any active
935 * {@link CallDiagnosticService} implementation which is active.
936 * <p>
937 * Likewise, if a {@link CallDiagnosticService} sends a message using
938 * {@link DiagnosticCall#sendDeviceToDeviceMessage(int, int)}, it will be routed to telephony
939 * via {@link Connection#onCallEvent(String, Bundle)}. The telephony stack will relay the
940 * message to the other device.
941 * @hide
942 */
943 @SystemApi
944 public static final String EVENT_DEVICE_TO_DEVICE_MESSAGE =
945 "android.telecom.event.DEVICE_TO_DEVICE_MESSAGE";
946
947 /**
948 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
949 * message type.
950 *
951 * See {@link DiagnosticCall} for more information.
952 * @hide
953 */
954 @SystemApi
955 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_TYPE =
956 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_TYPE";
957
958 /**
959 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
960 * message value.
961 * <p>
962 * See {@link DiagnosticCall} for more information.
963 * @hide
964 */
965 @SystemApi
966 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_VALUE =
967 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_VALUE";
968
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700969 // Flag controlling whether PII is emitted into the logs
970 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
971
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800972 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700973 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
974 *
975 * @param capabilities A capability bit field.
976 * @return A human readable string representation.
977 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800978 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700979 return capabilitiesToStringInternal(capabilities, true /* isLong */);
980 }
981
982 /**
983 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
984 * string.
985 *
986 * @param capabilities A capability bit field.
987 * @return A human readable string representation.
988 * @hide
989 */
990 public static String capabilitiesToStringShort(int capabilities) {
991 return capabilitiesToStringInternal(capabilities, false /* isLong */);
992 }
993
994 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800995 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700996 builder.append("[");
997 if (isLong) {
998 builder.append("Capabilities:");
999 }
1000
Tyler Gunnc63f9082019-10-15 13:19:26 -07001001 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001002 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001003 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001004 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001005 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001006 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001007 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001008 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001009 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001010 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001011 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001012 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001013 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -07001014 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001015 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001016 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001017 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001018 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001019 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001020 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001021 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001022 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001023 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001024 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001025 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001026 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001027 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001028 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
1029 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001030 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001031 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001032 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001033 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001034 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001035 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001036 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001037 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001038 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1039 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001040 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001041 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001042 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1043 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001044 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001045 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001046 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001047 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001048 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001049 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001050 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001051 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001052 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001053 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001054 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001055 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1056 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001057 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001058 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001059 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1060 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001061 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001062 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001063 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001064 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001065 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001066 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301067 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1068 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301069 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1070 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1071 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301072 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1073 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1074 }
1075 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1076 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1077 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1078 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 builder.append("]");
1080 return builder.toString();
1081 }
1082
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001083 /**
1084 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1085 *
1086 * @param properties A property bit field.
1087 * @return A human readable string representation.
1088 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001089 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001090 return propertiesToStringInternal(properties, true /* isLong */);
1091 }
1092
1093 /**
1094 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1095 *
1096 * @param properties A property bit field.
1097 * @return A human readable string representation.
1098 * @hide
1099 */
1100 public static String propertiesToStringShort(int properties) {
1101 return propertiesToStringInternal(properties, false /* isLong */);
1102 }
1103
1104 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001105 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001106 builder.append("[");
1107 if (isLong) {
1108 builder.append("Properties:");
1109 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001110
Tyler Gunnc63f9082019-10-15 13:19:26 -07001111 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001112 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1113 }
1114
Tyler Gunnc63f9082019-10-15 13:19:26 -07001115 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001116 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001117 }
1118
Tyler Gunnc63f9082019-10-15 13:19:26 -07001119 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001120 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001121 }
1122
Tyler Gunnc63f9082019-10-15 13:19:26 -07001123 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001124 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001125 }
1126
Tyler Gunnc63f9082019-10-15 13:19:26 -07001127 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001128 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001129 }
1130
Tyler Gunnc63f9082019-10-15 13:19:26 -07001131 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001132 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001133 }
1134
Tyler Gunnc63f9082019-10-15 13:19:26 -07001135 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001136 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001137 }
1138
Tyler Gunnc63f9082019-10-15 13:19:26 -07001139 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001140 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1141 }
1142
Tyler Gunnc63f9082019-10-15 13:19:26 -07001143 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1144 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001145 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1146 }
1147
Tyler Gunnc63f9082019-10-15 13:19:26 -07001148 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001149 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1150 }
1151
Ravi Paluri80aa2142019-12-02 11:57:37 +05301152 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1153 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1154 }
1155
Hall Liue0f787c2020-07-08 11:25:56 -07001156 if ((properties & PROPERTY_IS_DOWNGRADED_CONFERENCE) == PROPERTY_IS_DOWNGRADED_CONFERENCE) {
1157 builder.append(isLong ? " PROPERTY_IS_DOWNGRADED_CONFERENCE" : " dngrd_conf");
1158 }
1159
Tyler Gunn720c6642016-03-22 09:02:47 -07001160 builder.append("]");
1161 return builder.toString();
1162 }
1163
Sailesh Nepal091768c2014-06-30 15:15:23 -07001164 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001165 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001166 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001167 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001168 public void onCallerDisplayNameChanged(
1169 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001170 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001171 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001172 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001173 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001174 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001175 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001176 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001177 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001178 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 public void onVideoProviderChanged(
1180 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001181 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1182 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001183 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001184 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001185 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001186 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001187 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001188 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001189 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001190 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001191 public void onRttInitiationSuccess(Connection c) {}
1192 public void onRttInitiationFailure(Connection c, int reason) {}
1193 public void onRttSessionRemotelyTerminated(Connection c) {}
1194 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301195 /** @hide */
1196 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001197 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001198 }
1199
Tyler Gunnb702ef82015-05-29 11:51:53 -07001200 /**
Hall Liu95d55872017-01-25 17:12:49 -08001201 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001202 */
1203 public static final class RttTextStream {
1204 private static final int READ_BUFFER_SIZE = 1000;
1205 private final InputStreamReader mPipeFromInCall;
1206 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001207 private final ParcelFileDescriptor mFdFromInCall;
1208 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001209
1210 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001211 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1212
1213 /**
1214 * @hide
1215 */
1216 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001217 mFdFromInCall = fromInCall;
1218 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001219 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001220
1221 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001222 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001223 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001224 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001225 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001226 }
1227
1228 /**
1229 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1230 * RTT transmits text in real-time, this method should be called as often as text snippets
1231 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001232 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001233 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1234 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001235 *
Hall Liu95d55872017-01-25 17:12:49 -08001236 * @param input The message to send to the in-call app.
1237 */
1238 public void write(String input) throws IOException {
1239 mPipeToInCall.write(input);
1240 mPipeToInCall.flush();
1241 }
1242
1243
1244 /**
1245 * Reads a string from the in-call app, blocking if there is no data available. Returns
1246 * {@code null} if the RTT conversation has been terminated and there is no further data
1247 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001248 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001249 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1250 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001251 *
Hall Liu95d55872017-01-25 17:12:49 -08001252 * @return A string containing text entered by the user, or {@code null} if the
1253 * conversation has been terminated or if there was an error while reading.
1254 */
Hall Liuffa4a812017-03-02 16:11:00 -08001255 public String read() throws IOException {
1256 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1257 if (numRead < 0) {
1258 return null;
1259 }
1260 return new String(mReadBuffer, 0, numRead);
1261 }
1262
1263 /**
1264 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1265 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001266 *
Hall Liuffa4a812017-03-02 16:11:00 -08001267 * @return A string containing text entered by the user, or {@code null} if the user has
1268 * not entered any new text yet.
1269 */
1270 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001271 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001272 return read();
1273 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001274 return null;
1275 }
1276 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001277
1278 /** @hide */
1279 public ParcelFileDescriptor getFdFromInCall() {
1280 return mFdFromInCall;
1281 }
1282
1283 /** @hide */
1284 public ParcelFileDescriptor getFdToInCall() {
1285 return mFdToInCall;
1286 }
1287 }
1288
1289 /**
1290 * Provides constants to represent the results of responses to session modify requests sent via
1291 * {@link Call#sendRttRequest()}
1292 */
1293 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001294 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001295 /**
1296 * Session modify request was successful.
1297 */
1298 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1299
1300 /**
1301 * Session modify request failed.
1302 */
1303 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1304
1305 /**
1306 * Session modify request ignored due to invalid parameters.
1307 */
1308 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1309
1310 /**
1311 * Session modify request timed out.
1312 */
1313 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1314
1315 /**
1316 * Session modify request rejected by remote user.
1317 */
1318 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001319 }
1320
1321 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001322 * Provides a means of controlling the video session associated with a {@link Connection}.
1323 * <p>
1324 * Implementations create a custom subclass of {@link VideoProvider} and the
1325 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1326 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1327 * should set the {@link VideoProvider}.
1328 * <p>
1329 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1330 * {@link InCallService} implementations to issue requests related to the video session;
1331 * it provides a means for the {@link ConnectionService} to report events and information
1332 * related to the video session to Telecom and the {@link InCallService} implementations.
1333 * <p>
1334 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1335 * {@link android.telecom.InCallService.VideoCall}.
1336 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 /**
1339 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001340 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 */
1342 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001343
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001344 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001345 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1346 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 */
1348 public static final int SESSION_EVENT_RX_RESUME = 2;
1349
1350 /**
1351 * Video transmission has begun. This occurs after a negotiated start of video transmission
1352 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001353 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001354 */
1355 public static final int SESSION_EVENT_TX_START = 3;
1356
1357 /**
1358 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1359 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001360 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001361 */
1362 public static final int SESSION_EVENT_TX_STOP = 4;
1363
1364 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001365 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001366 * this as a cue to inform the user the camera is not available.
1367 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 */
1369 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1370
1371 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001372 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001373 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 * the camera has become available again.
1375 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 */
1377 public static final int SESSION_EVENT_CAMERA_READY = 6;
1378
1379 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001380 * Session event raised by Telecom when
1381 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1382 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1383 * @see #handleCallSessionEvent(int)
1384 */
1385 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1386
1387 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001389 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 */
1391 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1392
1393 /**
1394 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001395 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 */
1397 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1398
1399 /**
1400 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001401 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 */
1403 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1404
Rekha Kumar07366812015-03-24 16:42:31 -07001405 /**
1406 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001407 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001408 */
1409 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1410
1411 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001412 * Session modify request rejected by remote user.
1413 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001414 */
1415 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1416
Tyler Gunn75958422015-04-15 14:23:42 -07001417 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 private static final int MSG_SET_CAMERA = 2;
1419 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1420 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1421 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1422 private static final int MSG_SET_ZOOM = 6;
1423 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1424 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1425 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001426 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001428 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001429
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001430 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1431 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1432 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1433 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1434 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1435 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001436 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1437 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001438 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1439
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001440 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001442
1443 /**
1444 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001445 *
1446 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1447 * load factor before resizing, 1 means we only expect a single thread to
1448 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001449 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001450 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1451 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452
1453 /**
1454 * Default handler used to consolidate binder method calls onto a single thread.
1455 */
1456 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001457 public VideoProviderHandler() {
1458 super();
1459 }
1460
1461 public VideoProviderHandler(Looper looper) {
1462 super(looper);
1463 }
1464
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 @Override
1466 public void handleMessage(Message msg) {
1467 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001468 case MSG_ADD_VIDEO_CALLBACK: {
1469 IBinder binder = (IBinder) msg.obj;
1470 IVideoCallback callback = IVideoCallback.Stub
1471 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001472 if (callback == null) {
1473 Log.w(this, "addVideoProvider - skipped; callback is null.");
1474 break;
1475 }
1476
Tyler Gunn75958422015-04-15 14:23:42 -07001477 if (mVideoCallbacks.containsKey(binder)) {
1478 Log.i(this, "addVideoProvider - skipped; already present.");
1479 break;
1480 }
1481 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001483 }
1484 case MSG_REMOVE_VIDEO_CALLBACK: {
1485 IBinder binder = (IBinder) msg.obj;
1486 IVideoCallback callback = IVideoCallback.Stub
1487 .asInterface((IBinder) msg.obj);
1488 if (!mVideoCallbacks.containsKey(binder)) {
1489 Log.i(this, "removeVideoProvider - skipped; not present.");
1490 break;
1491 }
1492 mVideoCallbacks.remove(binder);
1493 break;
1494 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001496 {
1497 SomeArgs args = (SomeArgs) msg.obj;
1498 try {
1499 onSetCamera((String) args.arg1);
1500 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001501 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001502 } finally {
1503 args.recycle();
1504 }
1505 }
1506 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001507 case MSG_SET_PREVIEW_SURFACE:
1508 onSetPreviewSurface((Surface) msg.obj);
1509 break;
1510 case MSG_SET_DISPLAY_SURFACE:
1511 onSetDisplaySurface((Surface) msg.obj);
1512 break;
1513 case MSG_SET_DEVICE_ORIENTATION:
1514 onSetDeviceOrientation(msg.arg1);
1515 break;
1516 case MSG_SET_ZOOM:
1517 onSetZoom((Float) msg.obj);
1518 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001519 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1520 SomeArgs args = (SomeArgs) msg.obj;
1521 try {
1522 onSendSessionModifyRequest((VideoProfile) args.arg1,
1523 (VideoProfile) args.arg2);
1524 } finally {
1525 args.recycle();
1526 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001527 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001528 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001529 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1530 onSendSessionModifyResponse((VideoProfile) msg.obj);
1531 break;
1532 case MSG_REQUEST_CAMERA_CAPABILITIES:
1533 onRequestCameraCapabilities();
1534 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001535 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1536 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 break;
1538 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001539 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 break;
1541 default:
1542 break;
1543 }
1544 }
1545 }
1546
1547 /**
1548 * IVideoProvider stub implementation.
1549 */
1550 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001551 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001553 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1554 }
1555
1556 public void removeVideoCallback(IBinder videoCallbackBinder) {
1557 mMessageHandler.obtainMessage(
1558 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001559 }
1560
Tyler Gunn159f35c2017-03-02 09:28:37 -08001561 public void setCamera(String cameraId, String callingPackageName,
1562 int targetSdkVersion) {
1563
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001564 SomeArgs args = SomeArgs.obtain();
1565 args.arg1 = cameraId;
1566 // Propagate the calling package; originally determined in
1567 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1568 // process.
1569 args.arg2 = callingPackageName;
1570 // Pass along the uid and pid of the calling app; this gets lost when we put the
1571 // message onto the handler. These are required for Telecom to perform a permission
1572 // check to see if the calling app is able to use the camera.
1573 args.argi1 = Binder.getCallingUid();
1574 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001575 // Pass along the target SDK version of the calling InCallService. This is used to
1576 // maintain backwards compatibility of the API for older callers.
1577 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001578 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001579 }
1580
1581 public void setPreviewSurface(Surface surface) {
1582 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1583 }
1584
1585 public void setDisplaySurface(Surface surface) {
1586 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1587 }
1588
1589 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001590 mMessageHandler.obtainMessage(
1591 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001592 }
1593
1594 public void setZoom(float value) {
1595 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1596 }
1597
Tyler Gunn45382162015-05-06 08:52:27 -07001598 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1599 SomeArgs args = SomeArgs.obtain();
1600 args.arg1 = fromProfile;
1601 args.arg2 = toProfile;
1602 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 }
1604
1605 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1606 mMessageHandler.obtainMessage(
1607 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1608 }
1609
1610 public void requestCameraCapabilities() {
1611 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1612 }
1613
1614 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001615 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001616 }
1617
Yorke Lee32f24732015-05-12 16:18:03 -07001618 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001619 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1620 }
1621 }
1622
1623 public VideoProvider() {
1624 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001625 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001626 }
1627
1628 /**
1629 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1630 *
1631 * @param looper The looper.
1632 * @hide
1633 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001634 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001635 public VideoProvider(Looper looper) {
1636 mBinder = new VideoProvider.VideoProviderBinder();
1637 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001638 }
1639
1640 /**
1641 * Returns binder object which can be used across IPC methods.
1642 * @hide
1643 */
1644 public final IVideoProvider getInterface() {
1645 return mBinder;
1646 }
1647
1648 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001649 * Sets the camera to be used for the outgoing video.
1650 * <p>
1651 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1652 * camera via
1653 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1654 * <p>
1655 * Sent from the {@link InCallService} via
1656 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001657 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001658 * @param cameraId The id of the camera (use ids as reported by
1659 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001660 */
1661 public abstract void onSetCamera(String cameraId);
1662
1663 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001664 * Sets the camera to be used for the outgoing video.
1665 * <p>
1666 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1667 * camera via
1668 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1669 * <p>
1670 * This prototype is used internally to ensure that the calling package name, UID and PID
1671 * are sent to Telecom so that can perform a camera permission check on the caller.
1672 * <p>
1673 * Sent from the {@link InCallService} via
1674 * {@link InCallService.VideoCall#setCamera(String)}.
1675 *
1676 * @param cameraId The id of the camera (use ids as reported by
1677 * {@link CameraManager#getCameraIdList()}).
1678 * @param callingPackageName The AppOpps package name of the caller.
1679 * @param callingUid The UID of the caller.
1680 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001681 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001682 * @hide
1683 */
1684 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001685 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001686
1687 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001688 * Sets the surface to be used for displaying a preview of what the user's camera is
1689 * currently capturing. When video transmission is enabled, this is the video signal which
1690 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001691 * <p>
1692 * Sent from the {@link InCallService} via
1693 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001694 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001695 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 */
1697 public abstract void onSetPreviewSurface(Surface surface);
1698
1699 /**
1700 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001701 * <p>
1702 * Sent from the {@link InCallService} via
1703 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001704 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001705 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001706 */
1707 public abstract void onSetDisplaySurface(Surface surface);
1708
1709 /**
1710 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1711 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001712 * <p>
1713 * Sent from the {@link InCallService} via
1714 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001715 *
1716 * @param rotation The device orientation, in degrees.
1717 */
1718 public abstract void onSetDeviceOrientation(int rotation);
1719
1720 /**
Tyler Gunnc603b462021-06-14 17:24:40 -07001721 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001722 * <p>
1723 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001724 *
Tyler Gunnc603b462021-06-14 17:24:40 -07001725 * @param value The camera zoom ratio; for the current camera, should be a value in the
1726 * range defined by
1727 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001728 */
1729 public abstract void onSetZoom(float value);
1730
1731 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001732 * Issues a request to modify the properties of the current video session.
1733 * <p>
1734 * Example scenarios include: requesting an audio-only call to be upgraded to a
1735 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1736 * when the {@link InCallService} is no longer the foreground application.
1737 * <p>
1738 * If the {@link VideoProvider} determines a request to be invalid, it should call
1739 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1740 * invalid request back to the {@link InCallService}.
1741 * <p>
1742 * Where a request requires confirmation from the user of the peer device, the
1743 * {@link VideoProvider} must communicate the request to the peer device and handle the
1744 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1745 * is used to inform the {@link InCallService} of the result of the request.
1746 * <p>
1747 * Sent from the {@link InCallService} via
1748 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001749 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001750 * @param fromProfile The video profile prior to the request.
1751 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001752 */
Tyler Gunn45382162015-05-06 08:52:27 -07001753 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1754 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001755
Tyler Gunnb702ef82015-05-29 11:51:53 -07001756 /**
1757 * Provides a response to a request to change the current video session properties.
1758 * <p>
1759 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1760 * video call, could decline the request and keep the call as audio-only.
1761 * In such a scenario, the {@code responseProfile} would have a video state of
1762 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1763 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1764 * <p>
1765 * Sent from the {@link InCallService} via
1766 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1767 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1768 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001769 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001770 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001771 */
1772 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1773
1774 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001775 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1776 * <p>
1777 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1778 * camera via
1779 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1780 * <p>
1781 * Sent from the {@link InCallService} via
1782 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783 */
1784 public abstract void onRequestCameraCapabilities();
1785
1786 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001787 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1788 * video component of the current {@link Connection}.
1789 * <p>
1790 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1791 * via {@link VideoProvider#setCallDataUsage(long)}.
1792 * <p>
1793 * Sent from the {@link InCallService} via
1794 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001795 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001796 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001797
1798 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001799 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1800 * the peer device when the video signal is paused.
1801 * <p>
1802 * Sent from the {@link InCallService} via
1803 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001804 *
1805 * @param uri URI of image to display.
1806 */
Yorke Lee32f24732015-05-12 16:18:03 -07001807 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001808
1809 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001810 * Used to inform listening {@link InCallService} implementations when the
1811 * {@link VideoProvider} receives a session modification request.
1812 * <p>
1813 * Received by the {@link InCallService} via
1814 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001816 * @param videoProfile The requested video profile.
1817 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001818 */
1819 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001820 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001821 for (IVideoCallback callback : mVideoCallbacks.values()) {
1822 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001823 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001824 } catch (RemoteException ignored) {
1825 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001826 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001827 }
1828 }
1829 }
1830
1831 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001832 * Used to inform listening {@link InCallService} implementations when the
1833 * {@link VideoProvider} receives a response to a session modification request.
1834 * <p>
1835 * Received by the {@link InCallService} via
1836 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1837 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001838 *
1839 * @param status Status of the session modify request. Valid values are
1840 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1841 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001842 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1843 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1844 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1845 * @param requestedProfile The original request which was sent to the peer device.
1846 * @param responseProfile The actual profile changes agreed to by the peer device.
1847 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001848 */
1849 public void receiveSessionModifyResponse(int status,
1850 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001851 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001852 for (IVideoCallback callback : mVideoCallbacks.values()) {
1853 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001854 callback.receiveSessionModifyResponse(status, requestedProfile,
1855 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001856 } catch (RemoteException ignored) {
1857 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001858 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001859 }
1860 }
1861 }
1862
1863 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001864 * Used to inform listening {@link InCallService} implementations when the
1865 * {@link VideoProvider} reports a call session event.
1866 * <p>
1867 * Received by the {@link InCallService} via
1868 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001869 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001870 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1871 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1872 * {@link VideoProvider#SESSION_EVENT_TX_START},
1873 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1874 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001875 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1876 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 */
1878 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001879 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001880 for (IVideoCallback callback : mVideoCallbacks.values()) {
1881 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001882 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001883 } catch (RemoteException ignored) {
1884 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001885 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001886 }
1887 }
1888 }
1889
1890 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001891 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1892 * peer's video have changed.
1893 * <p>
1894 * This could occur if, for example, the peer rotates their device, changing the aspect
1895 * ratio of the video, or if the user switches between the back and front cameras.
1896 * <p>
1897 * Received by the {@link InCallService} via
1898 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001899 *
1900 * @param width The updated peer video width.
1901 * @param height The updated peer video height.
1902 */
1903 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001904 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001905 for (IVideoCallback callback : mVideoCallbacks.values()) {
1906 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001907 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001908 } catch (RemoteException ignored) {
1909 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001910 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001911 }
1912 }
1913 }
1914
1915 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001916 * Used to inform listening {@link InCallService} implementations when the data usage of the
1917 * video associated with the current {@link Connection} has changed.
1918 * <p>
1919 * This could be in response to a preview request via
1920 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001921 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1922 * 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 -07001923 * <p>
1924 * Received by the {@link InCallService} via
1925 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001926 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001927 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1928 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001929 */
Yorke Lee32f24732015-05-12 16:18:03 -07001930 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001931 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001932 for (IVideoCallback callback : mVideoCallbacks.values()) {
1933 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001934 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001935 } catch (RemoteException ignored) {
1936 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001937 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001938 }
1939 }
1940 }
1941
1942 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001943 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001944 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001945 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001946 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1947 * @hide
1948 */
1949 public void changeCallDataUsage(long dataUsage) {
1950 setCallDataUsage(dataUsage);
1951 }
1952
1953 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001954 * Used to inform listening {@link InCallService} implementations when the capabilities of
1955 * the current camera have changed.
1956 * <p>
1957 * The {@link VideoProvider} should call this in response to
1958 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1959 * changed via {@link VideoProvider#onSetCamera(String)}.
1960 * <p>
1961 * Received by the {@link InCallService} via
1962 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1963 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001964 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001965 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 */
Yorke Lee400470f2015-05-12 13:31:25 -07001967 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001968 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001969 for (IVideoCallback callback : mVideoCallbacks.values()) {
1970 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001971 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001972 } catch (RemoteException ignored) {
1973 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001974 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001975 }
1976 }
1977 }
Rekha Kumar07366812015-03-24 16:42:31 -07001978
1979 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001980 * Used to inform listening {@link InCallService} implementations when the video quality
1981 * of the call has changed.
1982 * <p>
1983 * Received by the {@link InCallService} via
1984 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001985 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001986 * @param videoQuality The updated video quality. Valid values:
1987 * {@link VideoProfile#QUALITY_HIGH},
1988 * {@link VideoProfile#QUALITY_MEDIUM},
1989 * {@link VideoProfile#QUALITY_LOW},
1990 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001991 */
1992 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001993 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001994 for (IVideoCallback callback : mVideoCallbacks.values()) {
1995 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001996 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001997 } catch (RemoteException ignored) {
1998 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001999 }
Rekha Kumar07366812015-03-24 16:42:31 -07002000 }
2001 }
2002 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002003
2004 /**
2005 * Returns a string representation of a call session event.
2006 *
2007 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
2008 * @return String representation of the call session event.
2009 * @hide
2010 */
2011 public static String sessionEventToString(int event) {
2012 switch (event) {
2013 case SESSION_EVENT_CAMERA_FAILURE:
2014 return SESSION_EVENT_CAMERA_FAILURE_STR;
2015 case SESSION_EVENT_CAMERA_READY:
2016 return SESSION_EVENT_CAMERA_READY_STR;
2017 case SESSION_EVENT_RX_PAUSE:
2018 return SESSION_EVENT_RX_PAUSE_STR;
2019 case SESSION_EVENT_RX_RESUME:
2020 return SESSION_EVENT_RX_RESUME_STR;
2021 case SESSION_EVENT_TX_START:
2022 return SESSION_EVENT_TX_START_STR;
2023 case SESSION_EVENT_TX_STOP:
2024 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08002025 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
2026 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002027 default:
2028 return SESSION_EVENT_UNKNOWN_STR + " " + event;
2029 }
2030 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002031 }
2032
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002033 private final Listener mConnectionDeathListener = new Listener() {
2034 @Override
2035 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002036 if (mConferenceables.remove(c)) {
2037 fireOnConferenceableConnectionsChanged();
2038 }
2039 }
2040 };
2041
2042 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2043 @Override
2044 public void onDestroyed(Conference c) {
2045 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002046 fireOnConferenceableConnectionsChanged();
2047 }
2048 }
2049 };
2050
Jay Shrauner229e3822014-08-15 09:23:07 -07002051 /**
2052 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2053 * load factor before resizing, 1 means we only expect a single thread to
2054 * access the map so make only a single shard
2055 */
2056 private final Set<Listener> mListeners = Collections.newSetFromMap(
2057 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002058 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2059 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002060 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002061
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002062 // The internal telecom call ID associated with this connection.
2063 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002064 // The PhoneAccountHandle associated with this connection.
2065 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002067 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002068 private Uri mAddress;
2069 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002070 private String mCallerDisplayName;
2071 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002072 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002073 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002074 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002075 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002076 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002077 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002078 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002079 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002080 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002081 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002082 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002083 private Conference mConference;
2084 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002085 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002086 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002087 /**
2088 * The direction of the connection; used where an existing connection is created and we need to
2089 * communicate to Telecom whether its incoming or outgoing.
2090 */
2091 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092
2093 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002094 * Tracks the key set for the extras bundle provided on the last invocation of
2095 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2096 * keys which were set previously but are no longer present in the replacement Bundle.
2097 */
2098 private Set<String> mPreviousExtraKeys;
2099
2100 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002101 * The verification status for an incoming call's phone number.
2102 */
2103 private @VerificationStatus int mCallerNumberVerificationStatus;
2104
2105
2106 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 * Create a new Connection.
2108 */
Santos Cordonf2951102014-07-20 19:06:29 -07002109 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002110
2111 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002112 * Returns the Telecom internal call ID associated with this connection. Should only be used
2113 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002114 * <p>
2115 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2116 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002117 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002118 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002119 * @hide
2120 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002121 @SystemApi
2122 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002123 return mTelecomCallId;
2124 }
2125
2126 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002127 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002128 */
Andrew Lee100e2932014-09-08 15:34:24 -07002129 public final Uri getAddress() {
2130 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131 }
2132
2133 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002134 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002135 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002136 */
Andrew Lee100e2932014-09-08 15:34:24 -07002137 public final int getAddressPresentation() {
2138 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002139 }
2140
2141 /**
2142 * @return The caller display name (CNAP).
2143 */
2144 public final String getCallerDisplayName() {
2145 return mCallerDisplayName;
2146 }
2147
2148 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002149 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002150 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002151 */
2152 public final int getCallerDisplayNamePresentation() {
2153 return mCallerDisplayNamePresentation;
2154 }
2155
2156 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002157 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002158 */
2159 public final int getState() {
2160 return mState;
2161 }
2162
2163 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002164 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002165 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2166 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2167 * {@link VideoProfile#STATE_TX_ENABLED},
2168 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002169 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002171 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002172 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002173 return mVideoState;
2174 }
2175
2176 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002178 * being routed by the system. This is {@code null} if this Connection
2179 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002180 * @deprecated Use {@link #getCallAudioState()} instead.
2181 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002182 */
Yorke Lee4af59352015-05-13 14:14:54 -07002183 @SystemApi
2184 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002185 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002186 if (mCallAudioState == null) {
2187 return null;
2188 }
Yorke Lee4af59352015-05-13 14:14:54 -07002189 return new AudioState(mCallAudioState);
2190 }
2191
2192 /**
2193 * @return The audio state of the connection, describing how its audio is currently
2194 * being routed by the system. This is {@code null} if this Connection
2195 * does not directly know about its audio state.
2196 */
2197 public final CallAudioState getCallAudioState() {
2198 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002199 }
2200
2201 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002202 * @return The conference that this connection is a part of. Null if it is not part of any
2203 * conference.
2204 */
2205 public final Conference getConference() {
2206 return mConference;
2207 }
2208
2209 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002210 * Returns whether this connection is requesting that the system play a ringback tone
2211 * on its behalf.
2212 */
Andrew Lee100e2932014-09-08 15:34:24 -07002213 public final boolean isRingbackRequested() {
2214 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002215 }
2216
2217 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002218 * @return True if the connection's audio mode is VOIP.
2219 */
2220 public final boolean getAudioModeIsVoip() {
2221 return mAudioModeIsVoip;
2222 }
2223
2224 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002225 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2226 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2227 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002228 * <p>
2229 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2230 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002231 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002232 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2233 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002234 *
2235 * @hide
2236 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002237 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002238 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002239 return mConnectTimeMillis;
2240 }
2241
2242 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002243 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2244 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002245 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002246 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002247 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2248 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002249 * <p>
2250 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002251 * <p>
2252 * The value returned is the same one set using
2253 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2254 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2255 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002256 *
2257 * @return The time at which the {@link Connection} was connected.
2258 *
2259 * @hide
2260 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002261 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002262 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002263 return mConnectElapsedTimeMillis;
2264 }
2265
2266 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002267 * @return The status hints for this connection.
2268 */
2269 public final StatusHints getStatusHints() {
2270 return mStatusHints;
2271 }
2272
2273 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002274 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002275 * <p>
2276 * Extras should be updated using {@link #putExtras(Bundle)}.
2277 * <p>
2278 * Telecom or an {@link InCallService} can also update the extras via
2279 * {@link android.telecom.Call#putExtras(Bundle)}, and
2280 * {@link Call#removeExtras(List)}.
2281 * <p>
2282 * The connection is notified of changes to the extras made by Telecom or an
2283 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002284 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002285 * @return The extras associated with this connection.
2286 */
2287 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002288 Bundle extras = null;
2289 synchronized (mExtrasLock) {
2290 if (mExtras != null) {
2291 extras = new Bundle(mExtras);
2292 }
2293 }
2294 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002295 }
2296
2297 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002298 * Assign a listener to be notified of state changes.
2299 *
2300 * @param l A listener.
2301 * @return This Connection.
2302 *
2303 * @hide
2304 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002305 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002306 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002307 return this;
2308 }
2309
2310 /**
2311 * Remove a previously assigned listener that was being notified of state changes.
2312 *
2313 * @param l A Listener.
2314 * @return This Connection.
2315 *
2316 * @hide
2317 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002318 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002319 if (l != null) {
2320 mListeners.remove(l);
2321 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002322 return this;
2323 }
2324
2325 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002326 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002327 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002328 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002329 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002330 }
2331
2332 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002333 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2334 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002335 * <p>
2336 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2337 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2338 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002339 *
2340 * @param callId The telecom call ID.
2341 * @hide
2342 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002343 @SystemApi
2344 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002345 mTelecomCallId = callId;
2346 }
2347
2348 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002349 * Inform this Connection that the state of its audio output has been changed externally.
2350 *
2351 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002352 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002353 */
Yorke Lee4af59352015-05-13 14:14:54 -07002354 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002355 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002356 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002357 mCallAudioState = state;
2358 onAudioStateChanged(getAudioState());
2359 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002360 }
2361
2362 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002363 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002364 * @return A string representation of the value.
2365 */
2366 public static String stateToString(int state) {
2367 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002368 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002369 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002370 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002371 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002372 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002373 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002374 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002375 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002376 case STATE_PULLING_CALL:
2377 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002378 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002379 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002380 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002381 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002382 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002383 return "DISCONNECTED";
2384 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002385 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002386 return "UNKNOWN";
2387 }
2388 }
2389
2390 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002391 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002392 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002393 public final int getConnectionCapabilities() {
2394 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002395 }
2396
2397 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002398 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2399 */
2400 public final int getConnectionProperties() {
2401 return mConnectionProperties;
2402 }
2403
2404 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002405 * Returns the connection's supported audio routes.
2406 *
2407 * @hide
2408 */
2409 public final int getSupportedAudioRoutes() {
2410 return mSupportedAudioRoutes;
2411 }
2412
2413 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002414 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002415 *
Andrew Lee100e2932014-09-08 15:34:24 -07002416 * @param address The new address.
2417 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002418 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002419 */
Andrew Lee100e2932014-09-08 15:34:24 -07002420 public final void setAddress(Uri address, int presentation) {
2421 Log.d(this, "setAddress %s", address);
2422 mAddress = address;
2423 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002424 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002425 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002426 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002427 }
2428
2429 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002430 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002431 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002432 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002433 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002434 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002435 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002436 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002437 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002438 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002439 mCallerDisplayName = callerDisplayName;
2440 mCallerDisplayNamePresentation = presentation;
2441 for (Listener l : mListeners) {
2442 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2443 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002444 }
2445
2446 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002447 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002448 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2449 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2450 * {@link VideoProfile#STATE_TX_ENABLED},
2451 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002452 *
2453 * @param videoState The new video state.
2454 */
2455 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002456 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002457 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002458 mVideoState = videoState;
2459 for (Listener l : mListeners) {
2460 l.onVideoStateChanged(this, mVideoState);
2461 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002462 }
2463
2464 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002465 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002466 * communicate).
2467 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002468 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002469 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002470 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002471 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002472 }
2473
2474 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002475 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002476 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002477 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002478 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002479 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002480 }
2481
2482 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002483 * Sets state to initializing (this Connection is not yet ready to be used).
2484 */
2485 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002486 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002487 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002488 }
2489
2490 /**
2491 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2492 */
2493 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002494 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002495 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002496 }
2497
2498 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002499 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002500 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002501 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002502 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002503 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002504 }
2505
2506 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002507 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2508 * device). Only applicable for {@link Connection}s with
2509 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2510 */
2511 public final void setPulling() {
2512 checkImmutable();
2513 setState(STATE_PULLING_CALL);
2514 }
2515
2516 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002517 * Sets state to be on hold.
2518 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002519 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002520 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002521 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002522 }
2523
2524 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002525 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002526 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002527 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002528 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002529 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002530 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002531 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002532 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002533 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002534 }
2535
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002536 public final VideoProvider getVideoProvider() {
2537 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002538 }
2539
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002540 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002541 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002542 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002543 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002544 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002545 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002546 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002547 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002548 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002549 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002550 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002551 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002552 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002553 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002554 }
2555
2556 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002557 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2558 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2559 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2560 * to send an {@link #onPostDialContinue(boolean)} signal.
2561 *
2562 * @param remaining The DTMF character sequence remaining to be emitted once the
2563 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2564 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002565 */
2566 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002567 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002568 for (Listener l : mListeners) {
2569 l.onPostDialWait(this, remaining);
2570 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002571 }
2572
2573 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002574 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2575 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002576 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002577 *
2578 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002579 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002580 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002581 checkImmutable();
2582 for (Listener l : mListeners) {
2583 l.onPostDialChar(this, nextChar);
2584 }
2585 }
2586
2587 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002588 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002589 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002590 *
2591 * @param ringback Whether the ringback tone is to be played.
2592 */
Andrew Lee100e2932014-09-08 15:34:24 -07002593 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002594 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002595 if (mRingbackRequested != ringback) {
2596 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002597 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002598 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002599 }
2600 }
Ihab Awadf8358972014-05-28 16:46:42 -07002601 }
2602
2603 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002604 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002605 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002606 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002607 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002608 public final void setConnectionCapabilities(int connectionCapabilities) {
2609 checkImmutable();
2610 if (mConnectionCapabilities != connectionCapabilities) {
2611 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002612 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002613 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002614 }
2615 }
Santos Cordonb6939982014-06-04 20:20:58 -07002616 }
2617
2618 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002619 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2620 *
2621 * @param connectionProperties The new connection properties.
2622 */
2623 public final void setConnectionProperties(int connectionProperties) {
2624 checkImmutable();
2625 if (mConnectionProperties != connectionProperties) {
2626 mConnectionProperties = connectionProperties;
2627 for (Listener l : mListeners) {
2628 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2629 }
2630 }
2631 }
2632
2633 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002634 * Sets the supported audio routes.
2635 *
2636 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2637 * See {@link CallAudioState}
2638 * @hide
2639 */
2640 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2641 if ((supportedAudioRoutes
2642 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2643 throw new IllegalArgumentException(
2644 "supported audio routes must include either speaker or earpiece");
2645 }
2646
2647 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2648 mSupportedAudioRoutes = supportedAudioRoutes;
2649 for (Listener l : mListeners) {
2650 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2651 }
2652 }
2653 }
2654
2655 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002656 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002657 */
Evan Charlton36a71342014-07-19 16:31:02 -07002658 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002659 for (Listener l : mListeners) {
2660 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002661 }
Santos Cordonb6939982014-06-04 20:20:58 -07002662 }
2663
2664 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002665 * Requests that the framework use VOIP audio mode for this connection.
2666 *
2667 * @param isVoip True if the audio mode is VOIP.
2668 */
2669 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002670 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002671 mAudioModeIsVoip = isVoip;
2672 for (Listener l : mListeners) {
2673 l.onAudioModeIsVoipChanged(this, isVoip);
2674 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002675 }
2676
2677 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002678 * Sets the time at which a call became active on this Connection. This is set only
2679 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002680 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002681 * This time corresponds to the date/time of connection and is stored in the call log in
2682 * {@link android.provider.CallLog.Calls#DATE}.
2683 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002684 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002685 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002686 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2687 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002688 *
2689 * @hide
2690 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002691 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002692 @RequiresPermission(MODIFY_PHONE_STATE)
2693 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002694 mConnectTimeMillis = connectTimeMillis;
2695 }
2696
2697 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002698 * Sets the time at which a call became active on this Connection. This is set only
2699 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002700 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002701 * This time is used to establish the duration of a call. It uses
2702 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2703 * time zone changes during a call. The difference between the current
2704 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2705 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2706 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002707 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002708 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002709 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2710 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002711 * @hide
2712 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002713 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002714 @RequiresPermission(MODIFY_PHONE_STATE)
2715 public final void setConnectionStartElapsedRealtimeMillis(
2716 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002717 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2718 }
2719
2720 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002721 * Sets the label and icon status to display in the in-call UI.
2722 *
2723 * @param statusHints The status label and icon to set.
2724 */
2725 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002726 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002727 mStatusHints = statusHints;
2728 for (Listener l : mListeners) {
2729 l.onStatusHintsChanged(this, statusHints);
2730 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002731 }
2732
2733 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002734 * Sets the connections with which this connection can be conferenced.
2735 *
2736 * @param conferenceableConnections The set of connections this connection can conference with.
2737 */
2738 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002739 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002740 clearConferenceableList();
2741 for (Connection c : conferenceableConnections) {
2742 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2743 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002744 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002745 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002746 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002747 }
2748 }
2749 fireOnConferenceableConnectionsChanged();
2750 }
2751
2752 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002753 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2754 * or conferences with which this connection can be conferenced.
2755 *
2756 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002757 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002758 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002759 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002760 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002761 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2762 // small amount of items here.
2763 if (!mConferenceables.contains(c)) {
2764 if (c instanceof Connection) {
2765 Connection connection = (Connection) c;
2766 connection.addConnectionListener(mConnectionDeathListener);
2767 } else if (c instanceof Conference) {
2768 Conference conference = (Conference) c;
2769 conference.addListener(mConferenceDeathListener);
2770 }
2771 mConferenceables.add(c);
2772 }
2773 }
2774 fireOnConferenceableConnectionsChanged();
2775 }
2776
2777 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002778 * Resets the CDMA connection time.
2779 * <p>
2780 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002781 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002782 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002783 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002784 public final void resetConnectionTime() {
2785 for (Listener l : mListeners) {
2786 l.onConnectionTimeReset(this);
2787 }
2788 }
2789
2790 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002791 * Returns the connections or conferences with which this connection can be conferenced.
2792 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002793 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002794 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002795 }
2796
Yorke Lee53463962015-08-04 16:07:19 -07002797 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002798 * @hide
2799 */
2800 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002801 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002802 if (mConnectionService != null) {
2803 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2804 "which is already associated with another ConnectionService.");
2805 } else {
2806 mConnectionService = connectionService;
2807 }
2808 }
2809
2810 /**
2811 * @hide
2812 */
2813 public final void unsetConnectionService(ConnectionService connectionService) {
2814 if (mConnectionService != connectionService) {
2815 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2816 "that does not belong to the ConnectionService.");
2817 } else {
2818 mConnectionService = null;
2819 }
2820 }
2821
2822 /**
2823 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002824 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002825 *
2826 * @param conference The conference.
2827 * @return {@code true} if the conference was successfully set.
2828 * @hide
2829 */
2830 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002831 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002832 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002833 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002834 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002835 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2836 fireConferenceChanged();
2837 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002838 return true;
2839 }
2840 return false;
2841 }
2842
2843 /**
2844 * Resets the conference that this connection is a part of.
2845 * @hide
2846 */
2847 public final void resetConference() {
2848 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002849 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002850 mConference = null;
2851 fireConferenceChanged();
2852 }
2853 }
2854
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002855 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002856 * Set some extras that can be associated with this {@code Connection}.
2857 * <p>
2858 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2859 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2860 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002861 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2862 * {@link #removeExtras(String...)} methods to modify the extras.
2863 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002864 * 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 -07002865 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2866 *
2867 * @param extras The extras associated with this {@code Connection}.
2868 */
2869 public final void setExtras(@Nullable Bundle extras) {
2870 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002871
2872 // Add/replace any new or changed extras values.
2873 putExtras(extras);
2874
2875 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2876 // the current one and remove any keys that went away.
2877 if (mPreviousExtraKeys != null) {
2878 List<String> toRemove = new ArrayList<String>();
2879 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002880 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002881 toRemove.add(oldKey);
2882 }
2883 }
2884 if (!toRemove.isEmpty()) {
2885 removeExtras(toRemove);
2886 }
2887 }
2888
2889 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2890 // called we can see if the caller has removed any extras values.
2891 if (mPreviousExtraKeys == null) {
2892 mPreviousExtraKeys = new ArraySet<String>();
2893 }
2894 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002895 if (extras != null) {
2896 mPreviousExtraKeys.addAll(extras.keySet());
2897 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002898 }
2899
2900 /**
2901 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2902 * added.
2903 * <p>
2904 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2905 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2906 *
2907 * @param extras The extras to add.
2908 */
2909 public final void putExtras(@NonNull Bundle extras) {
2910 checkImmutable();
2911 if (extras == null) {
2912 return;
2913 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002914 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2915 // the listeners.
2916 Bundle listenerExtras;
2917 synchronized (mExtrasLock) {
2918 if (mExtras == null) {
2919 mExtras = new Bundle();
2920 }
2921 mExtras.putAll(extras);
2922 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002923 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002924 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002925 // Create a new clone of the extras for each listener so that they don't clobber
2926 // each other
2927 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002928 }
2929 }
2930
2931 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002932 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002933 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002934 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002935 */
2936 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002937 synchronized (mExtrasLock) {
2938 if (mExtras != null) {
2939 for (String key : keys) {
2940 mExtras.remove(key);
2941 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002942 }
2943 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002944 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002945 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002946 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002947 }
2948 }
2949
2950 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002951 * Removes extras from this {@code Connection}.
2952 *
2953 * @param keys The keys of the extras to remove.
2954 */
2955 public final void removeExtras(String ... keys) {
2956 removeExtras(Arrays.asList(keys));
2957 }
2958
2959 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002960 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2961 * be change to the {@link #getCallAudioState()}.
2962 * <p>
2963 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2964 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2965 * <p>
2966 * See also {@link InCallService#setAudioRoute(int)}.
2967 *
2968 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2969 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2970 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2971 */
2972 public final void setAudioRoute(int route) {
2973 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002974 l.onAudioRouteChanged(this, route, null);
2975 }
2976 }
2977
2978 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002979 * Request audio routing to a specific bluetooth device. Calling this method may result in
2980 * the device routing audio to a different bluetooth device than the one specified if the
2981 * bluetooth stack is unable to route audio to the requested device.
2982 * A list of available devices can be obtained via
2983 * {@link CallAudioState#getSupportedBluetoothDevices()}
2984 *
2985 * <p>
2986 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2987 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2988 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002989 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2990 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002991 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002992 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002993 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002994 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2995 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002996 }
2997 }
2998
2999 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08003000 * Informs listeners that a previously requested RTT session via
3001 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08003002 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08003003 */
3004 public final void sendRttInitiationSuccess() {
3005 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
3006 }
3007
3008 /**
3009 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08003010 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08003011 * has failed.
3012 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
3013 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08003014 */
3015 public final void sendRttInitiationFailure(int reason) {
3016 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
3017 }
3018
3019 /**
3020 * Informs listeners that a currently active RTT session has been terminated by the remote
3021 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08003022 */
3023 public final void sendRttSessionRemotelyTerminated() {
3024 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
3025 }
3026
3027 /**
3028 * Informs listeners that the remote side of the call has requested an upgrade to include an
3029 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08003030 */
3031 public final void sendRemoteRttRequest() {
3032 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
3033 }
3034
3035 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003036 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003037 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003038 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003039 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3040 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003041 */
Yorke Lee4af59352015-05-13 14:14:54 -07003042 @SystemApi
3043 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003044 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003045
3046 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003047 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3048 *
3049 * @param state The new connection audio state.
3050 */
3051 public void onCallAudioStateChanged(CallAudioState state) {}
3052
3053 /**
Grace Jia4e8dc102021-01-19 14:58:01 -08003054 * Inform this Connection when it will or will not be tracked by an {@link InCallService} which
3055 * can provide an InCall UI.
3056 * This is primarily intended for use by Connections reported by self-managed
3057 * {@link ConnectionService} which typically maintain their own UI.
3058 *
3059 * @param isUsingAlternativeUi Indicates whether an InCallService that can provide InCall UI is
3060 * currently tracking the self-managed call.
3061 */
3062 public void onUsingAlternativeUi(boolean isUsingAlternativeUi) {}
3063
3064 /**
3065 * Inform this Conenection when it will or will not be tracked by an non-UI
3066 * {@link InCallService}.
3067 *
3068 * @param isTracked Indicates whether an non-UI InCallService is currently tracking the
3069 * self-managed call.
3070 */
3071 public void onTrackedByNonUiService(boolean isTracked) {}
3072
3073 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003074 * Notifies this Connection of an internal state change. This method is called after the
3075 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003076 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003077 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003078 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003079 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003080
3081 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003082 * Notifies this Connection of a request to play a DTMF tone.
3083 *
3084 * @param c A DTMF character.
3085 */
Santos Cordonf2951102014-07-20 19:06:29 -07003086 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003087
3088 /**
3089 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3090 */
Santos Cordonf2951102014-07-20 19:06:29 -07003091 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003092
3093 /**
3094 * Notifies this Connection of a request to disconnect.
3095 */
Santos Cordonf2951102014-07-20 19:06:29 -07003096 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003097
3098 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003099 * Notifies this Connection of a request to disconnect a participant of the conference managed
3100 * by the connection.
3101 *
3102 * @param endpoint the {@link Uri} of the participant to disconnect.
3103 * @hide
3104 */
3105 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3106
3107 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003108 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003109 */
Santos Cordonf2951102014-07-20 19:06:29 -07003110 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003111
3112 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003113 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303114 *
3115 * @param participants with which conference call will be formed.
3116 */
3117 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3118
3119 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003120 * Notifies this Connection of a request to abort.
3121 */
Santos Cordonf2951102014-07-20 19:06:29 -07003122 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003123
3124 /**
3125 * Notifies this Connection of a request to hold.
3126 */
Santos Cordonf2951102014-07-20 19:06:29 -07003127 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003128
3129 /**
3130 * Notifies this Connection of a request to exit a hold state.
3131 */
Santos Cordonf2951102014-07-20 19:06:29 -07003132 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003133
3134 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003135 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003136 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003137 * <p>
3138 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3139 * the default dialer's {@link InCallService}.
3140 * <p>
3141 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3142 * Telecom framework may request that the call is answered in the following circumstances:
3143 * <ul>
3144 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3145 * <li>A car mode {@link InCallService} is in use which has declared
3146 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3147 * {@link InCallService} will be able to see calls from self-managed
3148 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3149 * behalf.</li>
3150 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003151 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003152 */
Santos Cordonf2951102014-07-20 19:06:29 -07003153 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003154
3155 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003156 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003157 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003158 * <p>
3159 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3160 * the default dialer's {@link InCallService}.
3161 * <p>
3162 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3163 * Telecom framework may request that the call is answered in the following circumstances:
3164 * <ul>
3165 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3166 * <li>A car mode {@link InCallService} is in use which has declared
3167 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3168 * {@link InCallService} will be able to see calls from self-managed
3169 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3170 * behalf.</li>
3171 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003172 */
3173 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003174 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003175 }
3176
3177 /**
3178 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303179 * a request to deflect.
3180 */
3181 public void onDeflect(Uri address) {}
3182
3183 /**
3184 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003185 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003186 * <p>
3187 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3188 * the default dialer's {@link InCallService}.
3189 * <p>
3190 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3191 * Telecom framework may request that the call is rejected in the following circumstances:
3192 * <ul>
3193 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3194 * <li>A car mode {@link InCallService} is in use which has declared
3195 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3196 * {@link InCallService} will be able to see calls from self-managed
3197 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3198 * behalf.</li>
3199 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003200 */
Santos Cordonf2951102014-07-20 19:06:29 -07003201 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003202
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003203 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003204 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3205 * <p>
3206 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3207 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3208 * @param rejectReason the reason the user provided for rejecting the call.
3209 */
3210 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3211 // to be implemented by ConnectionService.
3212 }
3213
3214 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003215 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3216 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003217 */
3218 public void onReject(String replyMessage) {}
3219
3220 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303221 * Notifies this Connection, a request to transfer to a target number.
3222 * @param number the number to transfer this {@link Connection} to.
3223 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3224 * should wait until the transfer has successfully completed before disconnecting
3225 * the current {@link Connection}.
3226 * When {@code false}, the {@link ConnectionService} should signal the network to
3227 * perform the transfer, but should immediately disconnect the call regardless of
3228 * the outcome of the transfer.
3229 * @hide
3230 */
3231 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3232
3233 /**
3234 * Notifies this Connection, a request to transfer to another Connection.
3235 * @param otherConnection the {@link Connection} to transfer this call to.
3236 * @hide
3237 */
3238 public void onTransfer(@NonNull Connection otherConnection) {}
3239
3240 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003241 * Notifies this Connection of a request to silence the ringer.
3242 * <p>
3243 * The ringer may be silenced by any of the following methods:
3244 * <ul>
3245 * <li>{@link TelecomManager#silenceRinger()}</li>
3246 * <li>The user presses the volume-down button while a call is ringing.</li>
3247 * </ul>
3248 * <p>
3249 * Self-managed {@link ConnectionService} implementations should override this method in their
3250 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3251 * your app set the ringtone as part of the incoming call {@link Notification} (see
3252 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3253 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3254 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3255 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003256 */
3257 public void onSilence() {}
3258
3259 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003260 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3261 */
Santos Cordonf2951102014-07-20 19:06:29 -07003262 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003263
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003264 /**
3265 * Notifies this Connection of a request to pull an external call to the local device.
3266 * <p>
3267 * The {@link InCallService} issues a request to pull an external call to the local device via
3268 * {@link Call#pullExternalCall()}.
3269 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003270 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3271 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003272 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003273 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003274 */
3275 public void onPullExternalCall() {}
3276
3277 /**
3278 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3279 * <p>
3280 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3281 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003282 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3283 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3284 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3285 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3286 * not aware of.
3287 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003288 * See also {@link Call#sendCallEvent(String, Bundle)}.
3289 *
3290 * @param event The call event.
3291 * @param extras Extras associated with the call event.
3292 */
3293 public void onCallEvent(String event, Bundle extras) {}
3294
Tyler Gunndee56a82016-03-23 16:06:34 -07003295 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003296 * Notifies this {@link Connection} that a handover has completed.
3297 * <p>
3298 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3299 * Bundle)} on the initiating side of the handover, and
3300 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3301 */
3302 public void onHandoverComplete() {}
3303
3304 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003305 * Notifies this {@link Connection} of a change to the extras made outside the
3306 * {@link ConnectionService}.
3307 * <p>
3308 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3309 * the {@link android.telecom.Call#putExtras(Bundle)} and
3310 * {@link Call#removeExtras(List)}.
3311 *
3312 * @param extras The new extras bundle.
3313 */
3314 public void onExtrasChanged(Bundle extras) {}
3315
Tyler Gunnf5035432017-01-09 09:43:12 -08003316 /**
3317 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3318 * displaying its incoming call user interface for the {@link Connection}.
3319 * <p>
3320 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3321 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3322 * should show its own incoming call user interface.
3323 * <p>
3324 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003325 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3326 * Telecom framework will display its own incoming call user interface to allow the user to
3327 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3328 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003329 * <p>
3330 * You should trigger the display of the incoming call user interface for your application by
3331 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003332 *
3333 * In your application code, you should create a {@link android.app.NotificationChannel} for
3334 * incoming call notifications from your app:
3335 * <pre><code>
3336 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3337 * NotificationManager.IMPORTANCE_MAX);
3338 * // other channel setup stuff goes here.
3339 *
3340 * // We'll use the default system ringtone for our incoming call notification channel. You can
3341 * // use your own audio resource here.
3342 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3343 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3344 * // Setting the AudioAttributes is important as it identifies the purpose of your
3345 * // notification sound.
3346 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3347 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3348 * .build());
3349 *
3350 * NotificationManager mgr = getSystemService(NotificationManager.class);
3351 * mgr.createNotificationChannel(channel);
3352 * </code></pre>
3353 * When it comes time to post a notification for your incoming call, ensure it uses your
3354 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003355 * <pre><code>
3356 * // Create an intent which triggers your fullscreen incoming call user interface.
3357 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3358 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3359 * intent.setClass(context, YourIncomingCallActivity.class);
3360 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3361 *
3362 * // Build the notification as an ongoing high priority item; this ensures it will show as
3363 * // a heads up notification which slides down over top of the current content.
3364 * final Notification.Builder builder = new Notification.Builder(context);
3365 * builder.setOngoing(true);
3366 * builder.setPriority(Notification.PRIORITY_HIGH);
3367 *
3368 * // Set notification content intent to take user to fullscreen UI if user taps on the
3369 * // notification body.
3370 * builder.setContentIntent(pendingIntent);
3371 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3372 * // manager deems it appropriate.
3373 * builder.setFullScreenIntent(pendingIntent, true);
3374 *
3375 * // Setup notification content.
3376 * builder.setSmallIcon( yourIconResourceId );
3377 * builder.setContentTitle("Your notification title");
3378 * builder.setContentText("Your notification content.");
3379 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003380 * // Set notification as insistent to cause your ringtone to loop.
3381 * Notification notification = builder.build();
3382 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003383 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003384 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003385 * NotificationManager notificationManager = mContext.getSystemService(
3386 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003387 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003388 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003389 */
3390 public void onShowIncomingCallUi() {}
3391
Hall Liub64ac4c2017-02-06 10:49:48 -08003392 /**
3393 * Notifies this {@link Connection} that the user has requested an RTT session.
3394 * The connection service should call {@link #sendRttInitiationSuccess} or
3395 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3396 * request, respectively.
3397 * @param rttTextStream The object that should be used to send text to or receive text from
3398 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003399 */
3400 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3401
3402 /**
3403 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3404 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003405 */
3406 public void onStopRtt() {}
3407
3408 /**
3409 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3410 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3411 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3412 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003413 * @param rttTextStream The object that should be used to send text to or receive text from
3414 * the in-call app.
3415 */
3416 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3417
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003418 static String toLogSafePhoneNumber(String number) {
3419 // For unknown number, log empty string.
3420 if (number == null) {
3421 return "";
3422 }
3423
3424 if (PII_DEBUG) {
3425 // When PII_DEBUG is true we emit PII.
3426 return number;
3427 }
3428
3429 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3430 // sanitized phone numbers.
3431 StringBuilder builder = new StringBuilder();
3432 for (int i = 0; i < number.length(); i++) {
3433 char c = number.charAt(i);
3434 if (c == '-' || c == '@' || c == '.') {
3435 builder.append(c);
3436 } else {
3437 builder.append('x');
3438 }
3439 }
3440 return builder.toString();
3441 }
3442
Ihab Awad542e0ea2014-05-16 10:22:16 -07003443 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003444 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003445 if (mState == STATE_DISCONNECTED && mState != state) {
3446 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003447 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003448 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003449 if (mState != state) {
3450 Log.d(this, "setState: %s", stateToString(state));
3451 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003452 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003453 for (Listener l : mListeners) {
3454 l.onStateChanged(this, state);
3455 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003456 }
3457 }
3458
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003459 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003460 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003461 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3462 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003463 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003464 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003465
3466 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003467 if (mImmutable) {
3468 throw new UnsupportedOperationException("Connection is immutable");
3469 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003470 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003471 }
3472
Evan Charltonbf11f982014-07-20 22:06:28 -07003473 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003474 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003475 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3476 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003477 * <p>
3478 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3479 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003480 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003481 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003482 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003483 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003484 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3485 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003486 }
3487
Evan Charltonbf11f982014-07-20 22:06:28 -07003488 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003489 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3490 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3491 * this should never be un-@hide-den.
3492 *
3493 * @hide
3494 */
3495 public void checkImmutable() {}
3496
3497 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003498 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3499 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3500 * that state. This connection should not be used for anything, and no other
3501 * {@code Connection}s should be attempted.
3502 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003503 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003504 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003505 * @return A {@code Connection} which indicates that the underlying connection should
3506 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003507 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003508 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003509 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003510 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003511
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003512 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003513 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003514 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003515 }
3516 }
3517
Santos Cordon823fd3c2014-08-07 18:35:18 -07003518 private final void fireConferenceChanged() {
3519 for (Listener l : mListeners) {
3520 l.onConferenceChanged(this, mConference);
3521 }
3522 }
3523
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003524 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003525 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003526 if (c instanceof Connection) {
3527 Connection connection = (Connection) c;
3528 connection.removeConnectionListener(mConnectionDeathListener);
3529 } else if (c instanceof Conference) {
3530 Conference conference = (Conference) c;
3531 conference.removeListener(mConferenceDeathListener);
3532 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003533 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003534 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003535 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003536
3537 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003538 * Handles a change to extras received from Telecom.
3539 *
3540 * @param extras The new extras.
3541 * @hide
3542 */
3543 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003544 Bundle b = null;
3545 synchronized (mExtrasLock) {
3546 mExtras = extras;
3547 if (mExtras != null) {
3548 b = new Bundle(mExtras);
3549 }
3550 }
3551 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003552 }
3553
3554 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003555 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3556 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003557 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003558 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003559 for (Listener l : mListeners) {
3560 l.onConferenceMergeFailed(this);
3561 }
3562 }
3563
3564 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303565 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3566 * changed due to an emergency call being redialed.
3567 * @param pHandle The new PhoneAccountHandle for this connection.
3568 * @hide
3569 */
3570 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3571 for (Listener l : mListeners) {
3572 l.onPhoneAccountChanged(this, pHandle);
3573 }
3574 }
3575
3576 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003577 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003578 * <p>
3579 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3580 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003581 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003582 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003583 * @hide
3584 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003585 @SystemApi
3586 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003587 if (mPhoneAccountHandle != phoneAccountHandle) {
3588 mPhoneAccountHandle = phoneAccountHandle;
3589 notifyPhoneAccountChanged(phoneAccountHandle);
3590 }
3591 }
3592
3593 /**
3594 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003595 * <p>
3596 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3597 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003598 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003599 * @return the phone account handle specified via
3600 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003601 * @hide
3602 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003603 @SystemApi
3604 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003605 return mPhoneAccountHandle;
3606 }
3607
3608 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003609 * Sends an event associated with this {@code Connection} with associated event extras to the
3610 * {@link InCallService}.
3611 * <p>
3612 * Connection events are used to communicate point in time information from a
3613 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3614 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3615 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3616 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3617 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3618 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3619 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3620 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3621 * <p>
3622 * Events are exposed to {@link InCallService} implementations via
3623 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3624 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003625 * 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 -07003626 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3627 * some events altogether.
3628 * <p>
3629 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3630 * conflicts between {@link ConnectionService} implementations. Further, custom
3631 * {@link ConnectionService} implementations shall not re-purpose events in the
3632 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3633 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3634 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3635 * {@code com.example.extra.MY_EXTRA}).
3636 * <p>
3637 * When defining events and the associated extras, it is important to keep their behavior
3638 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3639 * events/extras should me maintained to ensure backwards compatibility with older
3640 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003641 *
3642 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003643 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003644 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003645 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003646 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003647 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003648 }
3649 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003650
3651 /**
3652 * @return The direction of the call.
3653 * @hide
3654 */
3655 public final @Call.Details.CallDirection int getCallDirection() {
3656 return mCallDirection;
3657 }
3658
3659 /**
3660 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003661 * <p>
3662 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3663 * call direction.
3664 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003665 * @param callDirection The direction of this connection.
3666 * @hide
3667 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003668 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003669 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3670 mCallDirection = callDirection;
3671 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003672
3673 /**
3674 * Gets the verification status for the phone number of an incoming call as identified in
3675 * ATIS-1000082.
3676 * @return the verification status.
3677 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003678 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003679 return mCallerNumberVerificationStatus;
3680 }
3681
3682 /**
3683 * Sets the verification status for the phone number of an incoming call as identified in
3684 * ATIS-1000082.
3685 * <p>
3686 * This property can only be set at the time of creation of a {@link Connection} being returned
3687 * by
3688 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3689 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003690 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003691 @VerificationStatus int callerNumberVerificationStatus) {
3692 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3693 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003694}