blob: 86a16e732e376cea2e74c15df1d1a3eb6f94a002 [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
Alvin Dey2f37d772018-05-18 23:16:10 +0530420 /**
421 * Indicates whether the remote party supports RTT or not to the UI.
422 */
423
424 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x20000000;
425
Tyler Gunn720c6642016-03-22 09:02:47 -0700426 //**********************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530427 // Next CAPABILITY value: 0x40000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700428 //**********************************************************************************************
429
430 /**
431 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700432 * <p>
433 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700434 * @hide
435 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700436 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700437 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700438
439 /**
440 * Whether the call is a generic conference, where we do not know the precise state of
441 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700442 * <p>
443 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700444 * @hide
445 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700446 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700447 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
448
449 /**
450 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700451 * <p>
452 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
453 * implies something like AMR wideband, but the interpretation of when a call is considered high
454 * definition is left to the {@link ConnectionService} to decide.
455 * <p>
456 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700457 */
458 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
459
460 /**
461 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700462 * <p>
463 * Used to indicate that a call is taking place over WIFI versus a carrier network.
464 * <p>
465 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700466 */
467 public static final int PROPERTY_WIFI = 1<<3;
468
469 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700470 * When set, indicates that the {@code Connection} does not actually exist locally for the
471 * {@link ConnectionService}.
472 * <p>
473 * Consider, for example, a scenario where a user has two devices with the same phone number.
474 * When a user places a call on one devices, the telephony stack can represent that call on the
475 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700476 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700477 * <p>
478 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
479 * external connections. Only those {@link InCallService}s which have the
480 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
481 * manifest will see external connections.
482 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700483 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700484
Brad Ebinger15847072016-05-18 11:08:36 -0700485 /**
486 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
487 */
488 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700489
Hall Liu9f332c72016-07-14 15:37:37 -0700490 /**
491 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700492 * <p>
493 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
494 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700495 * @hide
496 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700497 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700498 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
499
Tyler Gunnf5035432017-01-09 09:43:12 -0800500 /**
501 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
502 * {@link ConnectionService}.
503 * <p>
504 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
505 */
506 public static final int PROPERTY_SELF_MANAGED = 1<<7;
507
Hall Liu95d55872017-01-25 17:12:49 -0800508 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800509 * Set by the framework to indicate that a connection has an active RTT session associated with
510 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800511 */
512 public static final int PROPERTY_IS_RTT = 1 << 8;
513
Eric Erfanian62706c52017-12-06 16:27:53 -0800514 /**
515 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700516 * <p>
517 * This is used for outgoing calls.
518 *
519 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800520 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800521 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800522
Tyler Gunn5bd90852018-09-21 09:37:07 -0700523 /**
524 * Set by the framework to indicate that the network has identified a Connection as an emergency
525 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700526 * <p>
527 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
528 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700529 */
530 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
531
Tyler Gunnac60f952019-05-31 07:23:16 -0700532 /**
533 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
534 * than the current one. Used in scenarios where the conference originator is the remote device
535 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700536 * <p>
537 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700538 * @hide
539 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700540 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700541 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
542
Ravi Paluri80aa2142019-12-02 11:57:37 +0530543 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700544 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530545 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700546 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530547 */
548 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
549
550
Tyler Gunn96d6c402015-03-18 12:39:23 -0700551 //**********************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530552 // Next PROPERTY value: 1<<13
Tyler Gunn96d6c402015-03-18 12:39:23 -0700553 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800554
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700555 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800556 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800557 */
allenwtsu2aca9892019-11-25 14:38:21 +0800558 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800559 /**
560 * Adaptive Multi-rate audio codec.
561 */
allenwtsu2aca9892019-11-25 14:38:21 +0800562 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800563 /**
564 * Adaptive Multi-rate wideband audio codec.
565 */
allenwtsu2aca9892019-11-25 14:38:21 +0800566 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800567 /**
568 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
569 */
allenwtsu2aca9892019-11-25 14:38:21 +0800570 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800571 /**
572 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
573 */
allenwtsu2aca9892019-11-25 14:38:21 +0800574 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800575 /**
576 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
577 */
allenwtsu2aca9892019-11-25 14:38:21 +0800578 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800579 /**
580 * Enhanced Variable Rate Wideband Codec. See RFC5188.
581 */
allenwtsu2aca9892019-11-25 14:38:21 +0800582 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800583 /**
584 * Enhanced Variable Rate Narrowband-Wideband Codec.
585 */
allenwtsu2aca9892019-11-25 14:38:21 +0800586 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800587 /**
588 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
589 */
allenwtsu2aca9892019-11-25 14:38:21 +0800590 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800591 /**
592 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
593 */
allenwtsu2aca9892019-11-25 14:38:21 +0800594 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800595 /**
596 * GSM Half Rate audio codec.
597 */
allenwtsu2aca9892019-11-25 14:38:21 +0800598 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800599 /**
600 * ITU-T G711U audio codec.
601 */
allenwtsu2aca9892019-11-25 14:38:21 +0800602 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800603 /**
604 * ITU-T G723 audio codec.
605 */
allenwtsu2aca9892019-11-25 14:38:21 +0800606 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800607 /**
608 * ITU-T G711A audio codec.
609 */
allenwtsu2aca9892019-11-25 14:38:21 +0800610 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800611 /**
612 * ITU-T G722 audio codec.
613 */
allenwtsu2aca9892019-11-25 14:38:21 +0800614 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800615 /**
616 * ITU-T G711AB audio codec.
617 */
allenwtsu2aca9892019-11-25 14:38:21 +0800618 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800619 /**
620 * ITU-T G729 audio codec.
621 */
allenwtsu2aca9892019-11-25 14:38:21 +0800622 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800623 /**
624 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
625 */
allenwtsu2aca9892019-11-25 14:38:21 +0800626 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800627 /**
628 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
629 */
allenwtsu2aca9892019-11-25 14:38:21 +0800630 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800631 /**
632 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
633 */
allenwtsu2aca9892019-11-25 14:38:21 +0800634 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800635 /**
636 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
637 */
allenwtsu2aca9892019-11-25 14:38:21 +0800638 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
639
Tyler Gunn1c687622019-12-20 11:08:13 -0800640 /**@hide*/
641 @Retention(RetentionPolicy.SOURCE)
642 @IntDef(prefix = "AUDIO_CODEC_", value = {
643 AUDIO_CODEC_NONE,
644 AUDIO_CODEC_AMR,
645 AUDIO_CODEC_AMR_WB,
646 AUDIO_CODEC_QCELP13K,
647 AUDIO_CODEC_EVRC,
648 AUDIO_CODEC_EVRC_B,
649 AUDIO_CODEC_EVRC_WB,
650 AUDIO_CODEC_EVRC_NW,
651 AUDIO_CODEC_GSM_EFR,
652 AUDIO_CODEC_GSM_FR,
653 AUDIO_CODEC_GSM_HR,
654 AUDIO_CODEC_G711U,
655 AUDIO_CODEC_G723,
656 AUDIO_CODEC_G711A,
657 AUDIO_CODEC_G722,
658 AUDIO_CODEC_G711AB,
659 AUDIO_CODEC_G729,
660 AUDIO_CODEC_EVS_NB,
661 AUDIO_CODEC_EVS_SWB,
662 AUDIO_CODEC_EVS_FB
663 })
664 public @interface AudioCodec {}
665
allenwtsu2aca9892019-11-25 14:38:21 +0800666 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700667 * Connection extra key used to store the last forwarded number associated with the current
668 * connection. Used to communicate to the user interface that the connection was forwarded via
669 * the specified number.
670 */
671 public static final String EXTRA_LAST_FORWARDED_NUMBER =
672 "android.telecom.extra.LAST_FORWARDED_NUMBER";
673
674 /**
675 * Connection extra key used to store a child number associated with the current connection.
676 * Used to communicate to the user interface that the connection was received via
677 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
678 * address.
679 */
680 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
681
682 /**
683 * Connection extra key used to store the subject for an incoming call. The user interface can
684 * query this extra and display its contents for incoming calls. Will only be used if the
685 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
686 */
687 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
688
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800689 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700690 * Boolean connection extra key set on a {@link Connection} in
691 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
692 * current active foreground call to be dropped.
693 */
694 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
695 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
696
697 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700698 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
699 * state to indicate the name of the third-party app which is responsible for the current
700 * foreground call.
701 * <p>
702 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
703 * is able to inform the user that answering the new incoming call will cause a call owned by
704 * another app to be dropped when the incoming call is answered.
705 */
706 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
707 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
708
709 /**
Hall Liu10208662016-06-15 17:55:00 -0700710 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700711 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700712 * <p>
713 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
714 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700715 * @hide
716 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700717 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700718 public static final String EXTRA_DISABLE_ADD_CALL =
719 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700720
721 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700722 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
723 * original Connection ID associated with the connection. Used in
724 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
725 * connection/conference added via
726 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
727 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
728 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
729 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
730 * be a way to ensure that we don't add the connection again as a duplicate.
731 * <p>
732 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
733 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
734 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
735 * in a new {@link Connection} which it adds to Telecom via
736 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
737 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
738 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
739 * ID it originally referred to the connection as. Thus Telecom needs to know that the
740 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700741 * <p>
742 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
743 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700744 * @hide
745 */
746 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
747 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
748
749 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700750 * Extra key set on a {@link Connection} when it was created via a remote connection service.
751 * For example, if a connection manager requests a remote connection service to create a call
752 * using one of the remote connection service's phone account handle, this extra will be set so
753 * that Telecom knows that the wrapped remote connection originated in a remote connection
754 * service. We stash this in the extras since connection managers will typically copy the
755 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
756 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
757 * @hide
758 */
759 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
760 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
761
762 /**
763 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
764 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
765 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
766 * {@link ConnectionService} with a means to know the package name of the requesting
767 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
768 * better visibility in Telecom of where a connection ultimately originated.
769 * @hide
770 */
771 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
772 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
773
774 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700775 * Boolean connection extra key set on the extras passed to
776 * {@link Connection#sendConnectionEvent} which indicates that audio is present
777 * on the RTT call when the extra value is true.
778 */
779 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
780 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
781
782 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800783 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
784 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800785 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800786 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800787 "android.telecom.extra.AUDIO_CODEC";
788
789 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800790 * Float connection extra key used to store the audio codec bitrate in kbps for the current
791 * {@link Connection}.
792 */
793 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
794 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
795
796 /**
797 * Float connection extra key used to store the audio codec bandwidth in khz for the current
798 * {@link Connection}.
799 */
800 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
801 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
802 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800803 * Connection event used to inform Telecom that it should play the on hold tone. This is used
804 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700805 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800806 */
807 public static final String EVENT_ON_HOLD_TONE_START =
808 "android.telecom.event.ON_HOLD_TONE_START";
809
810 /**
811 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
812 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700813 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800814 */
815 public static final String EVENT_ON_HOLD_TONE_END =
816 "android.telecom.event.ON_HOLD_TONE_END";
817
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700818 /**
819 * Connection event used to inform {@link InCallService}s when pulling of an external call has
820 * failed. The user interface should inform the user of the error.
821 * <p>
822 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
823 * API is called on a {@link Call} with the properties
824 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
825 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
826 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700827 * <p>
828 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
829 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700830 */
831 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
832
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700833 /**
834 * Connection event used to inform {@link InCallService}s when the merging of two calls has
835 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700836 * <p>
837 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
838 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700839 */
840 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
841
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700842 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700843 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700844 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700845 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
846 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700847 */
848 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
849
850 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900851 * Connection event used to inform Telecom when a switch operation on a call has failed.
852 * <p>
853 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
854 * expected to be null when this connection event is used.
855 */
856 public static final String EVENT_CALL_SWITCH_FAILED =
857 "android.telecom.event.CALL_SWITCH_FAILED";
858
859 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700860 * Connection event used to inform {@link InCallService}s when the process of merging a
861 * Connection into a conference has begun.
862 * <p>
863 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
864 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700865 */
866 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
867
868 /**
869 * Connection event used to inform {@link InCallService}s when the process of merging a
870 * Connection into a conference has completed.
871 * <p>
872 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
873 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700874 */
875 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
876
877 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700878 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
879 * the remote party.
880 * <p>
881 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
882 * call is being held locally on the device. When a capable {@link ConnectionService} receives
883 * signalling to indicate that the remote party has put the call on hold, it can send this
884 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700885 */
886 public static final String EVENT_CALL_REMOTELY_HELD =
887 "android.telecom.event.CALL_REMOTELY_HELD";
888
889 /**
890 * Connection event used to inform {@link InCallService}s when a call which was remotely held
891 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
892 * <p>
893 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
894 * call is being held locally on the device. When a capable {@link ConnectionService} receives
895 * signalling to indicate that the remote party has taken the call off hold, it can send this
896 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700897 */
898 public static final String EVENT_CALL_REMOTELY_UNHELD =
899 "android.telecom.event.CALL_REMOTELY_UNHELD";
900
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700901 /**
902 * Connection event used to inform an {@link InCallService} which initiated a call handover via
903 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
904 * successfully completed.
905 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700906 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
907 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700908 */
909 public static final String EVENT_HANDOVER_COMPLETE =
910 "android.telecom.event.HANDOVER_COMPLETE";
911
912 /**
913 * Connection event used to inform an {@link InCallService} which initiated a call handover via
914 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
915 * to complete.
916 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700917 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
918 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700919 */
920 public static final String EVENT_HANDOVER_FAILED =
921 "android.telecom.event.HANDOVER_FAILED";
922
shilub7ec9a02018-11-09 15:52:04 -0800923 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000924 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800925 */
926 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
927
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700928 /**
929 * Connection event used to inform an {@link InCallService} that the RTT audio indication
930 * has changed.
931 */
932 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
933 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
934
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700935 // Flag controlling whether PII is emitted into the logs
936 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
937
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800938 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700939 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
940 *
941 * @param capabilities A capability bit field.
942 * @return A human readable string representation.
943 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800944 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700945 return capabilitiesToStringInternal(capabilities, true /* isLong */);
946 }
947
948 /**
949 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
950 * string.
951 *
952 * @param capabilities A capability bit field.
953 * @return A human readable string representation.
954 * @hide
955 */
956 public static String capabilitiesToStringShort(int capabilities) {
957 return capabilitiesToStringInternal(capabilities, false /* isLong */);
958 }
959
960 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800961 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700962 builder.append("[");
963 if (isLong) {
964 builder.append("Capabilities:");
965 }
966
Tyler Gunnc63f9082019-10-15 13:19:26 -0700967 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700968 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800969 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700970 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700971 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800972 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700973 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700974 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700976 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700977 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800978 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700979 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700980 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800981 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700982 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700983 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800984 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700985 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700986 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800987 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700988 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700989 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700990 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700991 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700992 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700993 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700994 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
995 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700996 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700998 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700999 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001000 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001001 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001002 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001003 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001004 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1005 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001006 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001007 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001008 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1009 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001010 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001011 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001012 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001013 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001014 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001015 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001016 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001017 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001018 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001019 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001020 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001021 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1022 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001023 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001024 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001025 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1026 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001027 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001028 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001029 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001030 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001031 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001032 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301033 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1034 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301035 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1036 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1037 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301038 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1039 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1040 }
1041 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1042 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1043 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1044 }
Alvin Dey2f37d772018-05-18 23:16:10 +05301045 if ((capabilities & CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)
1046 == CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT) {
1047 builder.append(isLong ? " CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT" : " sup_rtt");
1048 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001049 builder.append("]");
1050 return builder.toString();
1051 }
1052
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001053 /**
1054 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1055 *
1056 * @param properties A property bit field.
1057 * @return A human readable string representation.
1058 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001059 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001060 return propertiesToStringInternal(properties, true /* isLong */);
1061 }
1062
1063 /**
1064 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1065 *
1066 * @param properties A property bit field.
1067 * @return A human readable string representation.
1068 * @hide
1069 */
1070 public static String propertiesToStringShort(int properties) {
1071 return propertiesToStringInternal(properties, false /* isLong */);
1072 }
1073
1074 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001075 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001076 builder.append("[");
1077 if (isLong) {
1078 builder.append("Properties:");
1079 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001080
Tyler Gunnc63f9082019-10-15 13:19:26 -07001081 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001082 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1083 }
1084
Tyler Gunnc63f9082019-10-15 13:19:26 -07001085 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001086 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001087 }
1088
Tyler Gunnc63f9082019-10-15 13:19:26 -07001089 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001090 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001091 }
1092
Tyler Gunnc63f9082019-10-15 13:19:26 -07001093 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001094 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001095 }
1096
Tyler Gunnc63f9082019-10-15 13:19:26 -07001097 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001098 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001099 }
1100
Tyler Gunnc63f9082019-10-15 13:19:26 -07001101 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001102 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001103 }
1104
Tyler Gunnc63f9082019-10-15 13:19:26 -07001105 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001106 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001107 }
1108
Tyler Gunnc63f9082019-10-15 13:19:26 -07001109 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001110 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1111 }
1112
Tyler Gunnc63f9082019-10-15 13:19:26 -07001113 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1114 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001115 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1116 }
1117
Tyler Gunnc63f9082019-10-15 13:19:26 -07001118 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001119 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1120 }
1121
Ravi Paluri80aa2142019-12-02 11:57:37 +05301122 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1123 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1124 }
1125
Tyler Gunn720c6642016-03-22 09:02:47 -07001126 builder.append("]");
1127 return builder.toString();
1128 }
1129
Sailesh Nepal091768c2014-06-30 15:15:23 -07001130 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001131 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001132 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001133 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001134 public void onCallerDisplayNameChanged(
1135 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001136 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001137 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001138 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001139 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001140 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001141 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001142 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001143 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001144 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001145 public void onVideoProviderChanged(
1146 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001147 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1148 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001149 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001150 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001151 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001152 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001153 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001154 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001155 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001156 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001157 public void onRttInitiationSuccess(Connection c) {}
1158 public void onRttInitiationFailure(Connection c, int reason) {}
1159 public void onRttSessionRemotelyTerminated(Connection c) {}
1160 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301161 /** @hide */
1162 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001163 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001164 }
1165
Tyler Gunnb702ef82015-05-29 11:51:53 -07001166 /**
Hall Liu95d55872017-01-25 17:12:49 -08001167 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001168 */
1169 public static final class RttTextStream {
1170 private static final int READ_BUFFER_SIZE = 1000;
1171 private final InputStreamReader mPipeFromInCall;
1172 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001173 private final ParcelFileDescriptor mFdFromInCall;
1174 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001175
1176 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001177 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1178
1179 /**
1180 * @hide
1181 */
1182 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001183 mFdFromInCall = fromInCall;
1184 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001185 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001186
1187 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001188 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001189 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001190 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001191 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001192 }
1193
1194 /**
1195 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1196 * RTT transmits text in real-time, this method should be called as often as text snippets
1197 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001198 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001199 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1200 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001201 *
Hall Liu95d55872017-01-25 17:12:49 -08001202 * @param input The message to send to the in-call app.
1203 */
1204 public void write(String input) throws IOException {
1205 mPipeToInCall.write(input);
1206 mPipeToInCall.flush();
1207 }
1208
1209
1210 /**
1211 * Reads a string from the in-call app, blocking if there is no data available. Returns
1212 * {@code null} if the RTT conversation has been terminated and there is no further data
1213 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001214 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001215 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1216 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001217 *
Hall Liu95d55872017-01-25 17:12:49 -08001218 * @return A string containing text entered by the user, or {@code null} if the
1219 * conversation has been terminated or if there was an error while reading.
1220 */
Hall Liuffa4a812017-03-02 16:11:00 -08001221 public String read() throws IOException {
1222 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1223 if (numRead < 0) {
1224 return null;
1225 }
1226 return new String(mReadBuffer, 0, numRead);
1227 }
1228
1229 /**
1230 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1231 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001232 *
Hall Liuffa4a812017-03-02 16:11:00 -08001233 * @return A string containing text entered by the user, or {@code null} if the user has
1234 * not entered any new text yet.
1235 */
1236 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001237 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001238 return read();
1239 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001240 return null;
1241 }
1242 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001243
1244 /** @hide */
1245 public ParcelFileDescriptor getFdFromInCall() {
1246 return mFdFromInCall;
1247 }
1248
1249 /** @hide */
1250 public ParcelFileDescriptor getFdToInCall() {
1251 return mFdToInCall;
1252 }
1253 }
1254
1255 /**
1256 * Provides constants to represent the results of responses to session modify requests sent via
1257 * {@link Call#sendRttRequest()}
1258 */
1259 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001260 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001261 /**
1262 * Session modify request was successful.
1263 */
1264 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1265
1266 /**
1267 * Session modify request failed.
1268 */
1269 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1270
1271 /**
1272 * Session modify request ignored due to invalid parameters.
1273 */
1274 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1275
1276 /**
1277 * Session modify request timed out.
1278 */
1279 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1280
1281 /**
1282 * Session modify request rejected by remote user.
1283 */
1284 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001285 }
1286
1287 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001288 * Provides a means of controlling the video session associated with a {@link Connection}.
1289 * <p>
1290 * Implementations create a custom subclass of {@link VideoProvider} and the
1291 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1292 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1293 * should set the {@link VideoProvider}.
1294 * <p>
1295 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1296 * {@link InCallService} implementations to issue requests related to the video session;
1297 * it provides a means for the {@link ConnectionService} to report events and information
1298 * related to the video session to Telecom and the {@link InCallService} implementations.
1299 * <p>
1300 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1301 * {@link android.telecom.InCallService.VideoCall}.
1302 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 /**
1305 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001306 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 */
1308 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001309
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001311 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1312 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 */
1314 public static final int SESSION_EVENT_RX_RESUME = 2;
1315
1316 /**
1317 * Video transmission has begun. This occurs after a negotiated start of video transmission
1318 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001319 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001320 */
1321 public static final int SESSION_EVENT_TX_START = 3;
1322
1323 /**
1324 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1325 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001326 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 */
1328 public static final int SESSION_EVENT_TX_STOP = 4;
1329
1330 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001331 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001332 * this as a cue to inform the user the camera is not available.
1333 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 */
1335 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1336
1337 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001338 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001339 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001340 * the camera has become available again.
1341 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 */
1343 public static final int SESSION_EVENT_CAMERA_READY = 6;
1344
1345 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001346 * Session event raised by Telecom when
1347 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1348 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1349 * @see #handleCallSessionEvent(int)
1350 */
1351 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1352
1353 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001354 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001355 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 */
1357 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1358
1359 /**
1360 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001361 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001362 */
1363 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1364
1365 /**
1366 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001367 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 */
1369 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1370
Rekha Kumar07366812015-03-24 16:42:31 -07001371 /**
1372 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001373 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001374 */
1375 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1376
1377 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001378 * Session modify request rejected by remote user.
1379 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001380 */
1381 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1382
Tyler Gunn75958422015-04-15 14:23:42 -07001383 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 private static final int MSG_SET_CAMERA = 2;
1385 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1386 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1387 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1388 private static final int MSG_SET_ZOOM = 6;
1389 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1390 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1391 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001392 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001394 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001396 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1397 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1398 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1399 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1400 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1401 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001402 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1403 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001404 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1405
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001406 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001407 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001408
1409 /**
1410 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001411 *
1412 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1413 * load factor before resizing, 1 means we only expect a single thread to
1414 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001415 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001416 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1417 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418
1419 /**
1420 * Default handler used to consolidate binder method calls onto a single thread.
1421 */
1422 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001423 public VideoProviderHandler() {
1424 super();
1425 }
1426
1427 public VideoProviderHandler(Looper looper) {
1428 super(looper);
1429 }
1430
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431 @Override
1432 public void handleMessage(Message msg) {
1433 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001434 case MSG_ADD_VIDEO_CALLBACK: {
1435 IBinder binder = (IBinder) msg.obj;
1436 IVideoCallback callback = IVideoCallback.Stub
1437 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001438 if (callback == null) {
1439 Log.w(this, "addVideoProvider - skipped; callback is null.");
1440 break;
1441 }
1442
Tyler Gunn75958422015-04-15 14:23:42 -07001443 if (mVideoCallbacks.containsKey(binder)) {
1444 Log.i(this, "addVideoProvider - skipped; already present.");
1445 break;
1446 }
1447 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001449 }
1450 case MSG_REMOVE_VIDEO_CALLBACK: {
1451 IBinder binder = (IBinder) msg.obj;
1452 IVideoCallback callback = IVideoCallback.Stub
1453 .asInterface((IBinder) msg.obj);
1454 if (!mVideoCallbacks.containsKey(binder)) {
1455 Log.i(this, "removeVideoProvider - skipped; not present.");
1456 break;
1457 }
1458 mVideoCallbacks.remove(binder);
1459 break;
1460 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001462 {
1463 SomeArgs args = (SomeArgs) msg.obj;
1464 try {
1465 onSetCamera((String) args.arg1);
1466 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001467 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001468 } finally {
1469 args.recycle();
1470 }
1471 }
1472 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 case MSG_SET_PREVIEW_SURFACE:
1474 onSetPreviewSurface((Surface) msg.obj);
1475 break;
1476 case MSG_SET_DISPLAY_SURFACE:
1477 onSetDisplaySurface((Surface) msg.obj);
1478 break;
1479 case MSG_SET_DEVICE_ORIENTATION:
1480 onSetDeviceOrientation(msg.arg1);
1481 break;
1482 case MSG_SET_ZOOM:
1483 onSetZoom((Float) msg.obj);
1484 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001485 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1486 SomeArgs args = (SomeArgs) msg.obj;
1487 try {
1488 onSendSessionModifyRequest((VideoProfile) args.arg1,
1489 (VideoProfile) args.arg2);
1490 } finally {
1491 args.recycle();
1492 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001494 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1496 onSendSessionModifyResponse((VideoProfile) msg.obj);
1497 break;
1498 case MSG_REQUEST_CAMERA_CAPABILITIES:
1499 onRequestCameraCapabilities();
1500 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1502 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 break;
1504 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001505 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001506 break;
1507 default:
1508 break;
1509 }
1510 }
1511 }
1512
1513 /**
1514 * IVideoProvider stub implementation.
1515 */
1516 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001517 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001518 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001519 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1520 }
1521
1522 public void removeVideoCallback(IBinder videoCallbackBinder) {
1523 mMessageHandler.obtainMessage(
1524 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 }
1526
Tyler Gunn159f35c2017-03-02 09:28:37 -08001527 public void setCamera(String cameraId, String callingPackageName,
1528 int targetSdkVersion) {
1529
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001530 SomeArgs args = SomeArgs.obtain();
1531 args.arg1 = cameraId;
1532 // Propagate the calling package; originally determined in
1533 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1534 // process.
1535 args.arg2 = callingPackageName;
1536 // Pass along the uid and pid of the calling app; this gets lost when we put the
1537 // message onto the handler. These are required for Telecom to perform a permission
1538 // check to see if the calling app is able to use the camera.
1539 args.argi1 = Binder.getCallingUid();
1540 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001541 // Pass along the target SDK version of the calling InCallService. This is used to
1542 // maintain backwards compatibility of the API for older callers.
1543 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001544 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 }
1546
1547 public void setPreviewSurface(Surface surface) {
1548 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1549 }
1550
1551 public void setDisplaySurface(Surface surface) {
1552 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1553 }
1554
1555 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001556 mMessageHandler.obtainMessage(
1557 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 }
1559
1560 public void setZoom(float value) {
1561 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1562 }
1563
Tyler Gunn45382162015-05-06 08:52:27 -07001564 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1565 SomeArgs args = SomeArgs.obtain();
1566 args.arg1 = fromProfile;
1567 args.arg2 = toProfile;
1568 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 }
1570
1571 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1572 mMessageHandler.obtainMessage(
1573 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1574 }
1575
1576 public void requestCameraCapabilities() {
1577 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1578 }
1579
1580 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001581 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 }
1583
Yorke Lee32f24732015-05-12 16:18:03 -07001584 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001585 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1586 }
1587 }
1588
1589 public VideoProvider() {
1590 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001591 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001592 }
1593
1594 /**
1595 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1596 *
1597 * @param looper The looper.
1598 * @hide
1599 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001600 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001601 public VideoProvider(Looper looper) {
1602 mBinder = new VideoProvider.VideoProviderBinder();
1603 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 }
1605
1606 /**
1607 * Returns binder object which can be used across IPC methods.
1608 * @hide
1609 */
1610 public final IVideoProvider getInterface() {
1611 return mBinder;
1612 }
1613
1614 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001615 * Sets the camera to be used for the outgoing video.
1616 * <p>
1617 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1618 * camera via
1619 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1620 * <p>
1621 * Sent from the {@link InCallService} via
1622 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001624 * @param cameraId The id of the camera (use ids as reported by
1625 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001626 */
1627 public abstract void onSetCamera(String cameraId);
1628
1629 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001630 * Sets the camera to be used for the outgoing video.
1631 * <p>
1632 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1633 * camera via
1634 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1635 * <p>
1636 * This prototype is used internally to ensure that the calling package name, UID and PID
1637 * are sent to Telecom so that can perform a camera permission check on the caller.
1638 * <p>
1639 * Sent from the {@link InCallService} via
1640 * {@link InCallService.VideoCall#setCamera(String)}.
1641 *
1642 * @param cameraId The id of the camera (use ids as reported by
1643 * {@link CameraManager#getCameraIdList()}).
1644 * @param callingPackageName The AppOpps package name of the caller.
1645 * @param callingUid The UID of the caller.
1646 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001647 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001648 * @hide
1649 */
1650 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001651 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001652
1653 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 * Sets the surface to be used for displaying a preview of what the user's camera is
1655 * currently capturing. When video transmission is enabled, this is the video signal which
1656 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001657 * <p>
1658 * Sent from the {@link InCallService} via
1659 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001660 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001661 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001662 */
1663 public abstract void onSetPreviewSurface(Surface surface);
1664
1665 /**
1666 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001667 * <p>
1668 * Sent from the {@link InCallService} via
1669 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001670 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001671 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001672 */
1673 public abstract void onSetDisplaySurface(Surface surface);
1674
1675 /**
1676 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1677 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001678 * <p>
1679 * Sent from the {@link InCallService} via
1680 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001681 *
1682 * @param rotation The device orientation, in degrees.
1683 */
1684 public abstract void onSetDeviceOrientation(int rotation);
1685
1686 /**
1687 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001688 * <p>
1689 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001690 *
1691 * @param value The camera zoom ratio.
1692 */
1693 public abstract void onSetZoom(float value);
1694
1695 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001696 * Issues a request to modify the properties of the current video session.
1697 * <p>
1698 * Example scenarios include: requesting an audio-only call to be upgraded to a
1699 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1700 * when the {@link InCallService} is no longer the foreground application.
1701 * <p>
1702 * If the {@link VideoProvider} determines a request to be invalid, it should call
1703 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1704 * invalid request back to the {@link InCallService}.
1705 * <p>
1706 * Where a request requires confirmation from the user of the peer device, the
1707 * {@link VideoProvider} must communicate the request to the peer device and handle the
1708 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1709 * is used to inform the {@link InCallService} of the result of the request.
1710 * <p>
1711 * Sent from the {@link InCallService} via
1712 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001713 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001714 * @param fromProfile The video profile prior to the request.
1715 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001716 */
Tyler Gunn45382162015-05-06 08:52:27 -07001717 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1718 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001719
Tyler Gunnb702ef82015-05-29 11:51:53 -07001720 /**
1721 * Provides a response to a request to change the current video session properties.
1722 * <p>
1723 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1724 * video call, could decline the request and keep the call as audio-only.
1725 * In such a scenario, the {@code responseProfile} would have a video state of
1726 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1727 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1728 * <p>
1729 * Sent from the {@link InCallService} via
1730 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1731 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1732 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001733 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001734 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001735 */
1736 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1737
1738 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001739 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1740 * <p>
1741 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1742 * camera via
1743 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1744 * <p>
1745 * Sent from the {@link InCallService} via
1746 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001747 */
1748 public abstract void onRequestCameraCapabilities();
1749
1750 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001751 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1752 * video component of the current {@link Connection}.
1753 * <p>
1754 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1755 * via {@link VideoProvider#setCallDataUsage(long)}.
1756 * <p>
1757 * Sent from the {@link InCallService} via
1758 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001759 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001760 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001761
1762 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001763 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1764 * the peer device when the video signal is paused.
1765 * <p>
1766 * Sent from the {@link InCallService} via
1767 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001768 *
1769 * @param uri URI of image to display.
1770 */
Yorke Lee32f24732015-05-12 16:18:03 -07001771 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001772
1773 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001774 * Used to inform listening {@link InCallService} implementations when the
1775 * {@link VideoProvider} receives a session modification request.
1776 * <p>
1777 * Received by the {@link InCallService} via
1778 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001779 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001780 * @param videoProfile The requested video profile.
1781 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001782 */
1783 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001784 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001785 for (IVideoCallback callback : mVideoCallbacks.values()) {
1786 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001787 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001788 } catch (RemoteException ignored) {
1789 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001790 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001791 }
1792 }
1793 }
1794
1795 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001796 * Used to inform listening {@link InCallService} implementations when the
1797 * {@link VideoProvider} receives a response to a session modification request.
1798 * <p>
1799 * Received by the {@link InCallService} via
1800 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1801 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001802 *
1803 * @param status Status of the session modify request. Valid values are
1804 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1805 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001806 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1807 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1808 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1809 * @param requestedProfile The original request which was sent to the peer device.
1810 * @param responseProfile The actual profile changes agreed to by the peer device.
1811 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001812 */
1813 public void receiveSessionModifyResponse(int status,
1814 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001815 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001816 for (IVideoCallback callback : mVideoCallbacks.values()) {
1817 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001818 callback.receiveSessionModifyResponse(status, requestedProfile,
1819 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001820 } catch (RemoteException ignored) {
1821 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001822 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001823 }
1824 }
1825 }
1826
1827 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001828 * Used to inform listening {@link InCallService} implementations when the
1829 * {@link VideoProvider} reports a call session event.
1830 * <p>
1831 * Received by the {@link InCallService} via
1832 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001833 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001834 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1835 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1836 * {@link VideoProvider#SESSION_EVENT_TX_START},
1837 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1838 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001839 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1840 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001841 */
1842 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001843 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001844 for (IVideoCallback callback : mVideoCallbacks.values()) {
1845 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001846 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001847 } catch (RemoteException ignored) {
1848 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001849 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001850 }
1851 }
1852 }
1853
1854 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001855 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1856 * peer's video have changed.
1857 * <p>
1858 * This could occur if, for example, the peer rotates their device, changing the aspect
1859 * ratio of the video, or if the user switches between the back and front cameras.
1860 * <p>
1861 * Received by the {@link InCallService} via
1862 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001863 *
1864 * @param width The updated peer video width.
1865 * @param height The updated peer video height.
1866 */
1867 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001868 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001869 for (IVideoCallback callback : mVideoCallbacks.values()) {
1870 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001871 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001872 } catch (RemoteException ignored) {
1873 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001874 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 }
1876 }
1877 }
1878
1879 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001880 * Used to inform listening {@link InCallService} implementations when the data usage of the
1881 * video associated with the current {@link Connection} has changed.
1882 * <p>
1883 * This could be in response to a preview request via
1884 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001885 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1886 * 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 -07001887 * <p>
1888 * Received by the {@link InCallService} via
1889 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001890 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001891 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1892 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001893 */
Yorke Lee32f24732015-05-12 16:18:03 -07001894 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001895 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001896 for (IVideoCallback callback : mVideoCallbacks.values()) {
1897 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001898 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001899 } catch (RemoteException ignored) {
1900 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001901 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001902 }
1903 }
1904 }
1905
1906 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001907 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001908 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001909 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001910 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1911 * @hide
1912 */
1913 public void changeCallDataUsage(long dataUsage) {
1914 setCallDataUsage(dataUsage);
1915 }
1916
1917 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001918 * Used to inform listening {@link InCallService} implementations when the capabilities of
1919 * the current camera have changed.
1920 * <p>
1921 * The {@link VideoProvider} should call this in response to
1922 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1923 * changed via {@link VideoProvider#onSetCamera(String)}.
1924 * <p>
1925 * Received by the {@link InCallService} via
1926 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1927 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001928 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001929 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001930 */
Yorke Lee400470f2015-05-12 13:31:25 -07001931 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001932 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001933 for (IVideoCallback callback : mVideoCallbacks.values()) {
1934 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001935 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001936 } catch (RemoteException ignored) {
1937 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001938 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001939 }
1940 }
1941 }
Rekha Kumar07366812015-03-24 16:42:31 -07001942
1943 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001944 * Used to inform listening {@link InCallService} implementations when the video quality
1945 * of the call has changed.
1946 * <p>
1947 * Received by the {@link InCallService} via
1948 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001949 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001950 * @param videoQuality The updated video quality. Valid values:
1951 * {@link VideoProfile#QUALITY_HIGH},
1952 * {@link VideoProfile#QUALITY_MEDIUM},
1953 * {@link VideoProfile#QUALITY_LOW},
1954 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001955 */
1956 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001957 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001958 for (IVideoCallback callback : mVideoCallbacks.values()) {
1959 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001960 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001961 } catch (RemoteException ignored) {
1962 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001963 }
Rekha Kumar07366812015-03-24 16:42:31 -07001964 }
1965 }
1966 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001967
1968 /**
1969 * Returns a string representation of a call session event.
1970 *
1971 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1972 * @return String representation of the call session event.
1973 * @hide
1974 */
1975 public static String sessionEventToString(int event) {
1976 switch (event) {
1977 case SESSION_EVENT_CAMERA_FAILURE:
1978 return SESSION_EVENT_CAMERA_FAILURE_STR;
1979 case SESSION_EVENT_CAMERA_READY:
1980 return SESSION_EVENT_CAMERA_READY_STR;
1981 case SESSION_EVENT_RX_PAUSE:
1982 return SESSION_EVENT_RX_PAUSE_STR;
1983 case SESSION_EVENT_RX_RESUME:
1984 return SESSION_EVENT_RX_RESUME_STR;
1985 case SESSION_EVENT_TX_START:
1986 return SESSION_EVENT_TX_START_STR;
1987 case SESSION_EVENT_TX_STOP:
1988 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001989 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1990 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001991 default:
1992 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1993 }
1994 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001995 }
1996
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001997 private final Listener mConnectionDeathListener = new Listener() {
1998 @Override
1999 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002000 if (mConferenceables.remove(c)) {
2001 fireOnConferenceableConnectionsChanged();
2002 }
2003 }
2004 };
2005
2006 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2007 @Override
2008 public void onDestroyed(Conference c) {
2009 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002010 fireOnConferenceableConnectionsChanged();
2011 }
2012 }
2013 };
2014
Jay Shrauner229e3822014-08-15 09:23:07 -07002015 /**
2016 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2017 * load factor before resizing, 1 means we only expect a single thread to
2018 * access the map so make only a single shard
2019 */
2020 private final Set<Listener> mListeners = Collections.newSetFromMap(
2021 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002022 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2023 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002024 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002025
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002026 // The internal telecom call ID associated with this connection.
2027 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002028 // The PhoneAccountHandle associated with this connection.
2029 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002030 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002031 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002032 private Uri mAddress;
2033 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002034 private String mCallerDisplayName;
2035 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002036 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002037 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002038 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002039 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002040 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002041 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002042 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002043 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002044 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002045 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002046 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002047 private Conference mConference;
2048 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002049 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002050 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002051 /**
2052 * The direction of the connection; used where an existing connection is created and we need to
2053 * communicate to Telecom whether its incoming or outgoing.
2054 */
2055 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002056
2057 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002058 * Tracks the key set for the extras bundle provided on the last invocation of
2059 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2060 * keys which were set previously but are no longer present in the replacement Bundle.
2061 */
2062 private Set<String> mPreviousExtraKeys;
2063
2064 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002065 * The verification status for an incoming call's phone number.
2066 */
2067 private @VerificationStatus int mCallerNumberVerificationStatus;
2068
2069
2070 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002071 * Create a new Connection.
2072 */
Santos Cordonf2951102014-07-20 19:06:29 -07002073 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002074
2075 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002076 * Returns the Telecom internal call ID associated with this connection. Should only be used
2077 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002078 * <p>
2079 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2080 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002081 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002082 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002083 * @hide
2084 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002085 @SystemApi
2086 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002087 return mTelecomCallId;
2088 }
2089
2090 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002091 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092 */
Andrew Lee100e2932014-09-08 15:34:24 -07002093 public final Uri getAddress() {
2094 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002095 }
2096
2097 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002098 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002099 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002100 */
Andrew Lee100e2932014-09-08 15:34:24 -07002101 public final int getAddressPresentation() {
2102 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002103 }
2104
2105 /**
2106 * @return The caller display name (CNAP).
2107 */
2108 public final String getCallerDisplayName() {
2109 return mCallerDisplayName;
2110 }
2111
2112 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002113 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002114 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002115 */
2116 public final int getCallerDisplayNamePresentation() {
2117 return mCallerDisplayNamePresentation;
2118 }
2119
2120 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002121 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002122 */
2123 public final int getState() {
2124 return mState;
2125 }
2126
2127 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002128 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002129 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2130 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2131 * {@link VideoProfile#STATE_TX_ENABLED},
2132 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002133 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002134 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002135 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002136 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002137 return mVideoState;
2138 }
2139
2140 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002141 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002142 * being routed by the system. This is {@code null} if this Connection
2143 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002144 * @deprecated Use {@link #getCallAudioState()} instead.
2145 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002146 */
Yorke Lee4af59352015-05-13 14:14:54 -07002147 @SystemApi
2148 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002149 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002150 if (mCallAudioState == null) {
2151 return null;
2152 }
Yorke Lee4af59352015-05-13 14:14:54 -07002153 return new AudioState(mCallAudioState);
2154 }
2155
2156 /**
2157 * @return The audio state of the connection, describing how its audio is currently
2158 * being routed by the system. This is {@code null} if this Connection
2159 * does not directly know about its audio state.
2160 */
2161 public final CallAudioState getCallAudioState() {
2162 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002163 }
2164
2165 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002166 * @return The conference that this connection is a part of. Null if it is not part of any
2167 * conference.
2168 */
2169 public final Conference getConference() {
2170 return mConference;
2171 }
2172
2173 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002174 * Returns whether this connection is requesting that the system play a ringback tone
2175 * on its behalf.
2176 */
Andrew Lee100e2932014-09-08 15:34:24 -07002177 public final boolean isRingbackRequested() {
2178 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002179 }
2180
2181 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002182 * @return True if the connection's audio mode is VOIP.
2183 */
2184 public final boolean getAudioModeIsVoip() {
2185 return mAudioModeIsVoip;
2186 }
2187
2188 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002189 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2190 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2191 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002192 * <p>
2193 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2194 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002195 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002196 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2197 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002198 *
2199 * @hide
2200 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002201 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002202 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002203 return mConnectTimeMillis;
2204 }
2205
2206 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002207 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2208 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002209 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002210 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002211 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2212 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002213 * <p>
2214 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002215 * <p>
2216 * The value returned is the same one set using
2217 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2218 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2219 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002220 *
2221 * @return The time at which the {@link Connection} was connected.
2222 *
2223 * @hide
2224 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002225 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002226 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002227 return mConnectElapsedTimeMillis;
2228 }
2229
2230 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002231 * @return The status hints for this connection.
2232 */
2233 public final StatusHints getStatusHints() {
2234 return mStatusHints;
2235 }
2236
2237 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002238 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002239 * <p>
2240 * Extras should be updated using {@link #putExtras(Bundle)}.
2241 * <p>
2242 * Telecom or an {@link InCallService} can also update the extras via
2243 * {@link android.telecom.Call#putExtras(Bundle)}, and
2244 * {@link Call#removeExtras(List)}.
2245 * <p>
2246 * The connection is notified of changes to the extras made by Telecom or an
2247 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002248 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002249 * @return The extras associated with this connection.
2250 */
2251 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002252 Bundle extras = null;
2253 synchronized (mExtrasLock) {
2254 if (mExtras != null) {
2255 extras = new Bundle(mExtras);
2256 }
2257 }
2258 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002259 }
2260
2261 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002262 * Assign a listener to be notified of state changes.
2263 *
2264 * @param l A listener.
2265 * @return This Connection.
2266 *
2267 * @hide
2268 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002269 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002270 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002271 return this;
2272 }
2273
2274 /**
2275 * Remove a previously assigned listener that was being notified of state changes.
2276 *
2277 * @param l A Listener.
2278 * @return This Connection.
2279 *
2280 * @hide
2281 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002282 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002283 if (l != null) {
2284 mListeners.remove(l);
2285 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002286 return this;
2287 }
2288
2289 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002290 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002291 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002292 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002293 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002294 }
2295
2296 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002297 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2298 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002299 * <p>
2300 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2301 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2302 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002303 *
2304 * @param callId The telecom call ID.
2305 * @hide
2306 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002307 @SystemApi
2308 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002309 mTelecomCallId = callId;
2310 }
2311
2312 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002313 * Inform this Connection that the state of its audio output has been changed externally.
2314 *
2315 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002316 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002317 */
Yorke Lee4af59352015-05-13 14:14:54 -07002318 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002319 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002320 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002321 mCallAudioState = state;
2322 onAudioStateChanged(getAudioState());
2323 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002324 }
2325
2326 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002327 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002328 * @return A string representation of the value.
2329 */
2330 public static String stateToString(int state) {
2331 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002332 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002333 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002334 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002335 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002336 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002337 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002338 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002339 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002340 case STATE_PULLING_CALL:
2341 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002342 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002343 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002344 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002345 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002346 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002347 return "DISCONNECTED";
2348 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002349 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002350 return "UNKNOWN";
2351 }
2352 }
2353
2354 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002355 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002356 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002357 public final int getConnectionCapabilities() {
2358 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002359 }
2360
2361 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002362 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2363 */
2364 public final int getConnectionProperties() {
2365 return mConnectionProperties;
2366 }
2367
2368 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002369 * Returns the connection's supported audio routes.
2370 *
2371 * @hide
2372 */
2373 public final int getSupportedAudioRoutes() {
2374 return mSupportedAudioRoutes;
2375 }
2376
2377 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002378 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002379 *
Andrew Lee100e2932014-09-08 15:34:24 -07002380 * @param address The new address.
2381 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002382 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002383 */
Andrew Lee100e2932014-09-08 15:34:24 -07002384 public final void setAddress(Uri address, int presentation) {
2385 Log.d(this, "setAddress %s", address);
2386 mAddress = address;
2387 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002388 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002389 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002390 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002391 }
2392
2393 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002394 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002395 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002396 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002397 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002398 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002399 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002400 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002401 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002402 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002403 mCallerDisplayName = callerDisplayName;
2404 mCallerDisplayNamePresentation = presentation;
2405 for (Listener l : mListeners) {
2406 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2407 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002408 }
2409
2410 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002411 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002412 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2413 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2414 * {@link VideoProfile#STATE_TX_ENABLED},
2415 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002416 *
2417 * @param videoState The new video state.
2418 */
2419 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002420 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002421 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002422 mVideoState = videoState;
2423 for (Listener l : mListeners) {
2424 l.onVideoStateChanged(this, mVideoState);
2425 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002426 }
2427
2428 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002429 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002430 * communicate).
2431 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002432 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002433 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002434 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002435 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002436 }
2437
2438 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002439 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002440 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002441 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002442 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002443 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002444 }
2445
2446 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002447 * Sets state to initializing (this Connection is not yet ready to be used).
2448 */
2449 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002450 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002451 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002452 }
2453
2454 /**
2455 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2456 */
2457 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002458 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002459 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002460 }
2461
2462 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002463 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002464 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002465 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002466 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002467 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002468 }
2469
2470 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002471 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2472 * device). Only applicable for {@link Connection}s with
2473 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2474 */
2475 public final void setPulling() {
2476 checkImmutable();
2477 setState(STATE_PULLING_CALL);
2478 }
2479
2480 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002481 * Sets state to be on hold.
2482 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002483 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002484 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002485 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002486 }
2487
2488 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002489 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002490 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002491 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002492 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002493 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002494 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002495 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002496 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002497 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002498 }
2499
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002500 public final VideoProvider getVideoProvider() {
2501 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002502 }
2503
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002504 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002505 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002506 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002507 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002508 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002509 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002510 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002511 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002512 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002513 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002514 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002515 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002516 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002517 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002518 }
2519
2520 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002521 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2522 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2523 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2524 * to send an {@link #onPostDialContinue(boolean)} signal.
2525 *
2526 * @param remaining The DTMF character sequence remaining to be emitted once the
2527 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2528 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002529 */
2530 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002531 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002532 for (Listener l : mListeners) {
2533 l.onPostDialWait(this, remaining);
2534 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002535 }
2536
2537 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002538 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2539 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002540 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002541 *
2542 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002543 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002544 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002545 checkImmutable();
2546 for (Listener l : mListeners) {
2547 l.onPostDialChar(this, nextChar);
2548 }
2549 }
2550
2551 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002552 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002553 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002554 *
2555 * @param ringback Whether the ringback tone is to be played.
2556 */
Andrew Lee100e2932014-09-08 15:34:24 -07002557 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002558 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002559 if (mRingbackRequested != ringback) {
2560 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002561 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002562 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002563 }
2564 }
Ihab Awadf8358972014-05-28 16:46:42 -07002565 }
2566
2567 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002568 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002569 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002570 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002571 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002572 public final void setConnectionCapabilities(int connectionCapabilities) {
2573 checkImmutable();
2574 if (mConnectionCapabilities != connectionCapabilities) {
2575 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002576 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002577 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002578 }
2579 }
Santos Cordonb6939982014-06-04 20:20:58 -07002580 }
2581
2582 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002583 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2584 *
2585 * @param connectionProperties The new connection properties.
2586 */
2587 public final void setConnectionProperties(int connectionProperties) {
2588 checkImmutable();
2589 if (mConnectionProperties != connectionProperties) {
2590 mConnectionProperties = connectionProperties;
2591 for (Listener l : mListeners) {
2592 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2593 }
2594 }
2595 }
2596
2597 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002598 * Sets the supported audio routes.
2599 *
2600 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2601 * See {@link CallAudioState}
2602 * @hide
2603 */
2604 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2605 if ((supportedAudioRoutes
2606 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2607 throw new IllegalArgumentException(
2608 "supported audio routes must include either speaker or earpiece");
2609 }
2610
2611 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2612 mSupportedAudioRoutes = supportedAudioRoutes;
2613 for (Listener l : mListeners) {
2614 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2615 }
2616 }
2617 }
2618
2619 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002620 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002621 */
Evan Charlton36a71342014-07-19 16:31:02 -07002622 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002623 for (Listener l : mListeners) {
2624 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002625 }
Santos Cordonb6939982014-06-04 20:20:58 -07002626 }
2627
2628 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002629 * Requests that the framework use VOIP audio mode for this connection.
2630 *
2631 * @param isVoip True if the audio mode is VOIP.
2632 */
2633 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002634 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002635 mAudioModeIsVoip = isVoip;
2636 for (Listener l : mListeners) {
2637 l.onAudioModeIsVoipChanged(this, isVoip);
2638 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002639 }
2640
2641 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002642 * Sets the time at which a call became active on this Connection. This is set only
2643 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002644 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002645 * This time corresponds to the date/time of connection and is stored in the call log in
2646 * {@link android.provider.CallLog.Calls#DATE}.
2647 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002648 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002649 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002650 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2651 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002652 *
2653 * @hide
2654 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002655 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002656 @RequiresPermission(MODIFY_PHONE_STATE)
2657 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002658 mConnectTimeMillis = connectTimeMillis;
2659 }
2660
2661 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002662 * Sets the time at which a call became active on this Connection. This is set only
2663 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002664 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002665 * This time is used to establish the duration of a call. It uses
2666 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2667 * time zone changes during a call. The difference between the current
2668 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2669 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2670 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002671 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002672 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002673 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2674 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002675 * @hide
2676 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002677 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002678 @RequiresPermission(MODIFY_PHONE_STATE)
2679 public final void setConnectionStartElapsedRealtimeMillis(
2680 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002681 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2682 }
2683
2684 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002685 * Sets the label and icon status to display in the in-call UI.
2686 *
2687 * @param statusHints The status label and icon to set.
2688 */
2689 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002690 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002691 mStatusHints = statusHints;
2692 for (Listener l : mListeners) {
2693 l.onStatusHintsChanged(this, statusHints);
2694 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002695 }
2696
2697 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002698 * Sets the connections with which this connection can be conferenced.
2699 *
2700 * @param conferenceableConnections The set of connections this connection can conference with.
2701 */
2702 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002703 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002704 clearConferenceableList();
2705 for (Connection c : conferenceableConnections) {
2706 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2707 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002708 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002709 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002710 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002711 }
2712 }
2713 fireOnConferenceableConnectionsChanged();
2714 }
2715
2716 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002717 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2718 * or conferences with which this connection can be conferenced.
2719 *
2720 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002721 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002722 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002723 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002724 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002725 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2726 // small amount of items here.
2727 if (!mConferenceables.contains(c)) {
2728 if (c instanceof Connection) {
2729 Connection connection = (Connection) c;
2730 connection.addConnectionListener(mConnectionDeathListener);
2731 } else if (c instanceof Conference) {
2732 Conference conference = (Conference) c;
2733 conference.addListener(mConferenceDeathListener);
2734 }
2735 mConferenceables.add(c);
2736 }
2737 }
2738 fireOnConferenceableConnectionsChanged();
2739 }
2740
2741 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002742 * Resets the CDMA connection time.
2743 * <p>
2744 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002745 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002746 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002747 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002748 public final void resetConnectionTime() {
2749 for (Listener l : mListeners) {
2750 l.onConnectionTimeReset(this);
2751 }
2752 }
2753
2754 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002755 * Returns the connections or conferences with which this connection can be conferenced.
2756 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002757 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002758 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002759 }
2760
Yorke Lee53463962015-08-04 16:07:19 -07002761 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002762 * @hide
2763 */
2764 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002765 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002766 if (mConnectionService != null) {
2767 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2768 "which is already associated with another ConnectionService.");
2769 } else {
2770 mConnectionService = connectionService;
2771 }
2772 }
2773
2774 /**
2775 * @hide
2776 */
2777 public final void unsetConnectionService(ConnectionService connectionService) {
2778 if (mConnectionService != connectionService) {
2779 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2780 "that does not belong to the ConnectionService.");
2781 } else {
2782 mConnectionService = null;
2783 }
2784 }
2785
2786 /**
2787 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002788 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002789 *
2790 * @param conference The conference.
2791 * @return {@code true} if the conference was successfully set.
2792 * @hide
2793 */
2794 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002795 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002796 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002797 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002798 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002799 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2800 fireConferenceChanged();
2801 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002802 return true;
2803 }
2804 return false;
2805 }
2806
2807 /**
2808 * Resets the conference that this connection is a part of.
2809 * @hide
2810 */
2811 public final void resetConference() {
2812 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002813 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002814 mConference = null;
2815 fireConferenceChanged();
2816 }
2817 }
2818
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002819 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002820 * Set some extras that can be associated with this {@code Connection}.
2821 * <p>
2822 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2823 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2824 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002825 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2826 * {@link #removeExtras(String...)} methods to modify the extras.
2827 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002828 * 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 -07002829 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2830 *
2831 * @param extras The extras associated with this {@code Connection}.
2832 */
2833 public final void setExtras(@Nullable Bundle extras) {
2834 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002835
2836 // Add/replace any new or changed extras values.
2837 putExtras(extras);
2838
2839 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2840 // the current one and remove any keys that went away.
2841 if (mPreviousExtraKeys != null) {
2842 List<String> toRemove = new ArrayList<String>();
2843 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002844 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002845 toRemove.add(oldKey);
2846 }
2847 }
2848 if (!toRemove.isEmpty()) {
2849 removeExtras(toRemove);
2850 }
2851 }
2852
2853 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2854 // called we can see if the caller has removed any extras values.
2855 if (mPreviousExtraKeys == null) {
2856 mPreviousExtraKeys = new ArraySet<String>();
2857 }
2858 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002859 if (extras != null) {
2860 mPreviousExtraKeys.addAll(extras.keySet());
2861 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002862 }
2863
2864 /**
2865 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2866 * added.
2867 * <p>
2868 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2869 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2870 *
2871 * @param extras The extras to add.
2872 */
2873 public final void putExtras(@NonNull Bundle extras) {
2874 checkImmutable();
2875 if (extras == null) {
2876 return;
2877 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002878 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2879 // the listeners.
2880 Bundle listenerExtras;
2881 synchronized (mExtrasLock) {
2882 if (mExtras == null) {
2883 mExtras = new Bundle();
2884 }
2885 mExtras.putAll(extras);
2886 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002887 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002888 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002889 // Create a new clone of the extras for each listener so that they don't clobber
2890 // each other
2891 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002892 }
2893 }
2894
2895 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002896 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002897 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002898 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002899 */
2900 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002901 synchronized (mExtrasLock) {
2902 if (mExtras != null) {
2903 for (String key : keys) {
2904 mExtras.remove(key);
2905 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002906 }
2907 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002908 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002909 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002910 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002911 }
2912 }
2913
2914 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002915 * Removes extras from this {@code Connection}.
2916 *
2917 * @param keys The keys of the extras to remove.
2918 */
2919 public final void removeExtras(String ... keys) {
2920 removeExtras(Arrays.asList(keys));
2921 }
2922
2923 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002924 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2925 * be change to the {@link #getCallAudioState()}.
2926 * <p>
2927 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2928 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2929 * <p>
2930 * See also {@link InCallService#setAudioRoute(int)}.
2931 *
2932 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2933 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2934 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2935 */
2936 public final void setAudioRoute(int route) {
2937 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002938 l.onAudioRouteChanged(this, route, null);
2939 }
2940 }
2941
2942 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002943 * Request audio routing to a specific bluetooth device. Calling this method may result in
2944 * the device routing audio to a different bluetooth device than the one specified if the
2945 * bluetooth stack is unable to route audio to the requested device.
2946 * A list of available devices can be obtained via
2947 * {@link CallAudioState#getSupportedBluetoothDevices()}
2948 *
2949 * <p>
2950 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2951 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2952 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002953 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2954 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002955 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002956 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002957 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002958 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2959 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002960 }
2961 }
2962
2963 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002964 * Informs listeners that a previously requested RTT session via
2965 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002966 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002967 */
2968 public final void sendRttInitiationSuccess() {
2969 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2970 }
2971
2972 /**
2973 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002974 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002975 * has failed.
2976 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2977 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002978 */
2979 public final void sendRttInitiationFailure(int reason) {
2980 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2981 }
2982
2983 /**
2984 * Informs listeners that a currently active RTT session has been terminated by the remote
2985 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002986 */
2987 public final void sendRttSessionRemotelyTerminated() {
2988 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2989 }
2990
2991 /**
2992 * Informs listeners that the remote side of the call has requested an upgrade to include an
2993 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002994 */
2995 public final void sendRemoteRttRequest() {
2996 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2997 }
2998
2999 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003000 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003001 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003002 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003003 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3004 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003005 */
Yorke Lee4af59352015-05-13 14:14:54 -07003006 @SystemApi
3007 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003008 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003009
3010 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003011 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3012 *
3013 * @param state The new connection audio state.
3014 */
3015 public void onCallAudioStateChanged(CallAudioState state) {}
3016
3017 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003018 * Notifies this Connection of an internal state change. This method is called after the
3019 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003020 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003021 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003022 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003023 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003024
3025 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003026 * Notifies this Connection of a request to play a DTMF tone.
3027 *
3028 * @param c A DTMF character.
3029 */
Santos Cordonf2951102014-07-20 19:06:29 -07003030 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003031
3032 /**
3033 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3034 */
Santos Cordonf2951102014-07-20 19:06:29 -07003035 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003036
3037 /**
3038 * Notifies this Connection of a request to disconnect.
3039 */
Santos Cordonf2951102014-07-20 19:06:29 -07003040 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003041
3042 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003043 * Notifies this Connection of a request to disconnect a participant of the conference managed
3044 * by the connection.
3045 *
3046 * @param endpoint the {@link Uri} of the participant to disconnect.
3047 * @hide
3048 */
3049 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3050
3051 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003052 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003053 */
Santos Cordonf2951102014-07-20 19:06:29 -07003054 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003055
3056 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003057 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303058 *
3059 * @param participants with which conference call will be formed.
3060 */
3061 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3062
3063 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003064 * Notifies this Connection of a request to abort.
3065 */
Santos Cordonf2951102014-07-20 19:06:29 -07003066 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003067
3068 /**
3069 * Notifies this Connection of a request to hold.
3070 */
Santos Cordonf2951102014-07-20 19:06:29 -07003071 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003072
3073 /**
3074 * Notifies this Connection of a request to exit a hold state.
3075 */
Santos Cordonf2951102014-07-20 19:06:29 -07003076 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003077
3078 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003079 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003080 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003081 * <p>
3082 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3083 * the default dialer's {@link InCallService}.
3084 * <p>
3085 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3086 * Telecom framework may request that the call is answered in the following circumstances:
3087 * <ul>
3088 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3089 * <li>A car mode {@link InCallService} is in use which has declared
3090 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3091 * {@link InCallService} will be able to see calls from self-managed
3092 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3093 * behalf.</li>
3094 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003095 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003096 */
Santos Cordonf2951102014-07-20 19:06:29 -07003097 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003098
3099 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003100 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003101 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003102 * <p>
3103 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3104 * the default dialer's {@link InCallService}.
3105 * <p>
3106 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3107 * Telecom framework may request that the call is answered in the following circumstances:
3108 * <ul>
3109 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3110 * <li>A car mode {@link InCallService} is in use which has declared
3111 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3112 * {@link InCallService} will be able to see calls from self-managed
3113 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3114 * behalf.</li>
3115 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003116 */
3117 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003118 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003119 }
3120
3121 /**
3122 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303123 * a request to deflect.
3124 */
3125 public void onDeflect(Uri address) {}
3126
3127 /**
3128 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003129 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003130 * <p>
3131 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3132 * the default dialer's {@link InCallService}.
3133 * <p>
3134 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3135 * Telecom framework may request that the call is rejected in the following circumstances:
3136 * <ul>
3137 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3138 * <li>A car mode {@link InCallService} is in use which has declared
3139 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3140 * {@link InCallService} will be able to see calls from self-managed
3141 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3142 * behalf.</li>
3143 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003144 */
Santos Cordonf2951102014-07-20 19:06:29 -07003145 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003146
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003147 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003148 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3149 * <p>
3150 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3151 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3152 * @param rejectReason the reason the user provided for rejecting the call.
3153 */
3154 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3155 // to be implemented by ConnectionService.
3156 }
3157
3158 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003159 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3160 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003161 */
3162 public void onReject(String replyMessage) {}
3163
3164 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303165 * Notifies this Connection, a request to transfer to a target number.
3166 * @param number the number to transfer this {@link Connection} to.
3167 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3168 * should wait until the transfer has successfully completed before disconnecting
3169 * the current {@link Connection}.
3170 * When {@code false}, the {@link ConnectionService} should signal the network to
3171 * perform the transfer, but should immediately disconnect the call regardless of
3172 * the outcome of the transfer.
3173 * @hide
3174 */
3175 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3176
3177 /**
3178 * Notifies this Connection, a request to transfer to another Connection.
3179 * @param otherConnection the {@link Connection} to transfer this call to.
3180 * @hide
3181 */
3182 public void onTransfer(@NonNull Connection otherConnection) {}
3183
3184 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003185 * Notifies this Connection of a request to silence the ringer.
3186 * <p>
3187 * The ringer may be silenced by any of the following methods:
3188 * <ul>
3189 * <li>{@link TelecomManager#silenceRinger()}</li>
3190 * <li>The user presses the volume-down button while a call is ringing.</li>
3191 * </ul>
3192 * <p>
3193 * Self-managed {@link ConnectionService} implementations should override this method in their
3194 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3195 * your app set the ringtone as part of the incoming call {@link Notification} (see
3196 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3197 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3198 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3199 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003200 */
3201 public void onSilence() {}
3202
3203 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003204 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3205 */
Santos Cordonf2951102014-07-20 19:06:29 -07003206 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003207
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003208 /**
3209 * Notifies this Connection of a request to pull an external call to the local device.
3210 * <p>
3211 * The {@link InCallService} issues a request to pull an external call to the local device via
3212 * {@link Call#pullExternalCall()}.
3213 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003214 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3215 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003216 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003217 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003218 */
3219 public void onPullExternalCall() {}
3220
3221 /**
3222 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3223 * <p>
3224 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3225 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003226 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3227 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3228 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3229 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3230 * not aware of.
3231 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003232 * See also {@link Call#sendCallEvent(String, Bundle)}.
3233 *
3234 * @param event The call event.
3235 * @param extras Extras associated with the call event.
3236 */
3237 public void onCallEvent(String event, Bundle extras) {}
3238
Tyler Gunndee56a82016-03-23 16:06:34 -07003239 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003240 * Notifies this {@link Connection} that a handover has completed.
3241 * <p>
3242 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3243 * Bundle)} on the initiating side of the handover, and
3244 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3245 */
3246 public void onHandoverComplete() {}
3247
3248 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003249 * Notifies this {@link Connection} of a change to the extras made outside the
3250 * {@link ConnectionService}.
3251 * <p>
3252 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3253 * the {@link android.telecom.Call#putExtras(Bundle)} and
3254 * {@link Call#removeExtras(List)}.
3255 *
3256 * @param extras The new extras bundle.
3257 */
3258 public void onExtrasChanged(Bundle extras) {}
3259
Tyler Gunnf5035432017-01-09 09:43:12 -08003260 /**
3261 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3262 * displaying its incoming call user interface for the {@link Connection}.
3263 * <p>
3264 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3265 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3266 * should show its own incoming call user interface.
3267 * <p>
3268 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003269 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3270 * Telecom framework will display its own incoming call user interface to allow the user to
3271 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3272 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003273 * <p>
3274 * You should trigger the display of the incoming call user interface for your application by
3275 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003276 *
3277 * In your application code, you should create a {@link android.app.NotificationChannel} for
3278 * incoming call notifications from your app:
3279 * <pre><code>
3280 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3281 * NotificationManager.IMPORTANCE_MAX);
3282 * // other channel setup stuff goes here.
3283 *
3284 * // We'll use the default system ringtone for our incoming call notification channel. You can
3285 * // use your own audio resource here.
3286 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3287 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3288 * // Setting the AudioAttributes is important as it identifies the purpose of your
3289 * // notification sound.
3290 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3291 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3292 * .build());
3293 *
3294 * NotificationManager mgr = getSystemService(NotificationManager.class);
3295 * mgr.createNotificationChannel(channel);
3296 * </code></pre>
3297 * When it comes time to post a notification for your incoming call, ensure it uses your
3298 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003299 * <pre><code>
3300 * // Create an intent which triggers your fullscreen incoming call user interface.
3301 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3302 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3303 * intent.setClass(context, YourIncomingCallActivity.class);
3304 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3305 *
3306 * // Build the notification as an ongoing high priority item; this ensures it will show as
3307 * // a heads up notification which slides down over top of the current content.
3308 * final Notification.Builder builder = new Notification.Builder(context);
3309 * builder.setOngoing(true);
3310 * builder.setPriority(Notification.PRIORITY_HIGH);
3311 *
3312 * // Set notification content intent to take user to fullscreen UI if user taps on the
3313 * // notification body.
3314 * builder.setContentIntent(pendingIntent);
3315 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3316 * // manager deems it appropriate.
3317 * builder.setFullScreenIntent(pendingIntent, true);
3318 *
3319 * // Setup notification content.
3320 * builder.setSmallIcon( yourIconResourceId );
3321 * builder.setContentTitle("Your notification title");
3322 * builder.setContentText("Your notification content.");
3323 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003324 * // Set notification as insistent to cause your ringtone to loop.
3325 * Notification notification = builder.build();
3326 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003327 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003328 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003329 * NotificationManager notificationManager = mContext.getSystemService(
3330 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003331 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003332 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003333 */
3334 public void onShowIncomingCallUi() {}
3335
Hall Liub64ac4c2017-02-06 10:49:48 -08003336 /**
3337 * Notifies this {@link Connection} that the user has requested an RTT session.
3338 * The connection service should call {@link #sendRttInitiationSuccess} or
3339 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3340 * request, respectively.
3341 * @param rttTextStream The object that should be used to send text to or receive text from
3342 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003343 */
3344 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3345
3346 /**
3347 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3348 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003349 */
3350 public void onStopRtt() {}
3351
3352 /**
3353 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3354 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3355 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3356 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003357 * @param rttTextStream The object that should be used to send text to or receive text from
3358 * the in-call app.
3359 */
3360 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3361
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003362 static String toLogSafePhoneNumber(String number) {
3363 // For unknown number, log empty string.
3364 if (number == null) {
3365 return "";
3366 }
3367
3368 if (PII_DEBUG) {
3369 // When PII_DEBUG is true we emit PII.
3370 return number;
3371 }
3372
3373 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3374 // sanitized phone numbers.
3375 StringBuilder builder = new StringBuilder();
3376 for (int i = 0; i < number.length(); i++) {
3377 char c = number.charAt(i);
3378 if (c == '-' || c == '@' || c == '.') {
3379 builder.append(c);
3380 } else {
3381 builder.append('x');
3382 }
3383 }
3384 return builder.toString();
3385 }
3386
Ihab Awad542e0ea2014-05-16 10:22:16 -07003387 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003388 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003389 if (mState == STATE_DISCONNECTED && mState != state) {
3390 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003391 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003392 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003393 if (mState != state) {
3394 Log.d(this, "setState: %s", stateToString(state));
3395 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003396 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003397 for (Listener l : mListeners) {
3398 l.onStateChanged(this, state);
3399 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003400 }
3401 }
3402
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003403 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003404 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003405 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3406 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003407 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003408 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003409
3410 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003411 if (mImmutable) {
3412 throw new UnsupportedOperationException("Connection is immutable");
3413 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003414 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003415 }
3416
Evan Charltonbf11f982014-07-20 22:06:28 -07003417 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003418 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003419 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3420 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003421 * <p>
3422 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3423 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003424 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003425 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003426 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003427 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003428 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3429 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003430 }
3431
Evan Charltonbf11f982014-07-20 22:06:28 -07003432 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003433 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3434 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3435 * this should never be un-@hide-den.
3436 *
3437 * @hide
3438 */
3439 public void checkImmutable() {}
3440
3441 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003442 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3443 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3444 * that state. This connection should not be used for anything, and no other
3445 * {@code Connection}s should be attempted.
3446 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003447 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003448 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003449 * @return A {@code Connection} which indicates that the underlying connection should
3450 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003451 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003452 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003453 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003454 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003455
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003456 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003457 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003458 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003459 }
3460 }
3461
Santos Cordon823fd3c2014-08-07 18:35:18 -07003462 private final void fireConferenceChanged() {
3463 for (Listener l : mListeners) {
3464 l.onConferenceChanged(this, mConference);
3465 }
3466 }
3467
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003468 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003469 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003470 if (c instanceof Connection) {
3471 Connection connection = (Connection) c;
3472 connection.removeConnectionListener(mConnectionDeathListener);
3473 } else if (c instanceof Conference) {
3474 Conference conference = (Conference) c;
3475 conference.removeListener(mConferenceDeathListener);
3476 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003477 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003478 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003479 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003480
3481 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003482 * Handles a change to extras received from Telecom.
3483 *
3484 * @param extras The new extras.
3485 * @hide
3486 */
3487 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003488 Bundle b = null;
3489 synchronized (mExtrasLock) {
3490 mExtras = extras;
3491 if (mExtras != null) {
3492 b = new Bundle(mExtras);
3493 }
3494 }
3495 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003496 }
3497
3498 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003499 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3500 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003501 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003502 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003503 for (Listener l : mListeners) {
3504 l.onConferenceMergeFailed(this);
3505 }
3506 }
3507
3508 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303509 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3510 * changed due to an emergency call being redialed.
3511 * @param pHandle The new PhoneAccountHandle for this connection.
3512 * @hide
3513 */
3514 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3515 for (Listener l : mListeners) {
3516 l.onPhoneAccountChanged(this, pHandle);
3517 }
3518 }
3519
3520 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003521 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003522 * <p>
3523 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3524 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003525 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003526 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003527 * @hide
3528 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003529 @SystemApi
3530 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003531 if (mPhoneAccountHandle != phoneAccountHandle) {
3532 mPhoneAccountHandle = phoneAccountHandle;
3533 notifyPhoneAccountChanged(phoneAccountHandle);
3534 }
3535 }
3536
3537 /**
3538 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003539 * <p>
3540 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3541 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003542 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003543 * @return the phone account handle specified via
3544 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003545 * @hide
3546 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003547 @SystemApi
3548 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003549 return mPhoneAccountHandle;
3550 }
3551
3552 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003553 * Sends an event associated with this {@code Connection} with associated event extras to the
3554 * {@link InCallService}.
3555 * <p>
3556 * Connection events are used to communicate point in time information from a
3557 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3558 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3559 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3560 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3561 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3562 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3563 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3564 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3565 * <p>
3566 * Events are exposed to {@link InCallService} implementations via
3567 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3568 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003569 * 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 -07003570 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3571 * some events altogether.
3572 * <p>
3573 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3574 * conflicts between {@link ConnectionService} implementations. Further, custom
3575 * {@link ConnectionService} implementations shall not re-purpose events in the
3576 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3577 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3578 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3579 * {@code com.example.extra.MY_EXTRA}).
3580 * <p>
3581 * When defining events and the associated extras, it is important to keep their behavior
3582 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3583 * events/extras should me maintained to ensure backwards compatibility with older
3584 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003585 *
3586 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003587 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003588 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003589 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003590 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003591 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003592 }
3593 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003594
3595 /**
3596 * @return The direction of the call.
3597 * @hide
3598 */
3599 public final @Call.Details.CallDirection int getCallDirection() {
3600 return mCallDirection;
3601 }
3602
3603 /**
3604 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003605 * <p>
3606 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3607 * call direction.
3608 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003609 * @param callDirection The direction of this connection.
3610 * @hide
3611 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003612 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003613 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3614 mCallDirection = callDirection;
3615 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003616
3617 /**
3618 * Gets the verification status for the phone number of an incoming call as identified in
3619 * ATIS-1000082.
3620 * @return the verification status.
3621 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003622 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003623 return mCallerNumberVerificationStatus;
3624 }
3625
3626 /**
3627 * Sets the verification status for the phone number of an incoming call as identified in
3628 * ATIS-1000082.
3629 * <p>
3630 * This property can only be set at the time of creation of a {@link Connection} being returned
3631 * by
3632 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3633 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003634 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003635 @VerificationStatus int callerNumberVerificationStatus) {
3636 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3637 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003638}