blob: c06327995bc0e6de576511d32d8b0af7a23c29c0 [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 Gunnd57d76c2019-09-24 14:53:23 -070019import android.annotation.IntDef;
Tyler Gunndee56a82016-03-23 16:06:34 -070020import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070021import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070022import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070023import android.annotation.TestApi;
Austin Wanga63a2c02019-12-19 06:38:19 +000024import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080025import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080026import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070028import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080030import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070031import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.os.Handler;
33import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070034import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080036import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070038import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080039import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Youming Yed6de26e2019-01-30 11:20:35 -080043import com.android.internal.os.SomeArgs;
44import com.android.internal.telecom.IVideoCallback;
45import com.android.internal.telecom.IVideoProvider;
46
Hall Liua549fed2018-02-09 16:40:03 -080047import java.io.FileInputStream;
48import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080049import java.io.IOException;
50import java.io.InputStreamReader;
51import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070052import java.lang.annotation.Retention;
53import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070054import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070055import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070056import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070057import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070058import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070059import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070060import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070061
62/**
Santos Cordon895d4b82015-06-25 16:41:48 -070063 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
64 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070065 * <p>
66 * Implementations create a custom subclass of {@code Connection} and return it to the framework
67 * as the return value of
68 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
69 * or
70 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
71 * Implementations are then responsible for updating the state of the {@code Connection}, and
72 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
73 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070074 * <p>
75 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
76 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
77 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
78 * {@code Connection} instance.
79 * <p>
80 * Basic call support requires overriding the following methods: {@link #onAnswer()},
81 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
82 * <p>
83 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
84 * {@link #onUnhold()} methods should be overridden to provide hold support for the
85 * {@code Connection}.
86 * <p>
87 * Where a {@code Connection} supports a variation of video calling (e.g. the
88 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
89 * to support answering a call as a video call.
90 * <p>
91 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
92 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
93 * support for pulling the external call.
94 * <p>
95 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
96 * overridden.
97 * <p>
98 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
99 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
100 * for example, call events from a {@link InCallService} are handled,
101 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
102 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
103 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
104 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700106public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * The connection is initializing. This is generally the first state for a {@code Connection}
110 * returned by a {@link ConnectionService}.
111 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 public static final int STATE_INITIALIZING = 0;
113
Santos Cordon895d4b82015-06-25 16:41:48 -0700114 /**
115 * The connection is new and not connected.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_NEW = 1;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * An incoming connection is in the ringing state. During this state, the user's ringer or
121 * vibration feature will be activated.
122 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 public static final int STATE_RINGING = 2;
124
Santos Cordon895d4b82015-06-25 16:41:48 -0700125 /**
126 * An outgoing connection is in the dialing state. In this state the other party has not yet
127 * answered the call and the user traditionally hears a ringback tone.
128 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700129 public static final int STATE_DIALING = 3;
130
Santos Cordon895d4b82015-06-25 16:41:48 -0700131 /**
132 * A connection is active. Both parties are connected to the call and can actively communicate.
133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 public static final int STATE_ACTIVE = 4;
135
Santos Cordon895d4b82015-06-25 16:41:48 -0700136 /**
137 * A connection is on hold.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_HOLDING = 5;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
142 * A connection has been disconnected. This is the final state once the user has been
143 * disconnected from a call either locally, remotely or by an error in the service.
144 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700145 public static final int STATE_DISCONNECTED = 6;
146
Santos Cordon895d4b82015-06-25 16:41:48 -0700147 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700148 * The state of an external connection which is in the process of being pulled from a remote
149 * device to the local device.
150 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700151 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700152 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
153 */
154 public static final int STATE_PULLING_CALL = 7;
155
156 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700157 * Indicates that the network could not perform verification.
158 */
159 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
160
161 /**
162 * Indicates that verification by the network passed. This indicates there is a high likelihood
163 * that the call originated from a valid source.
164 */
165 public static final int VERIFICATION_STATUS_PASSED = 1;
166
167 /**
168 * Indicates that verification by the network failed. This indicates there is a high likelihood
169 * that the call did not originate from a valid source.
170 */
171 public static final int VERIFICATION_STATUS_FAILED = 2;
172
173 /**@hide*/
174 @Retention(RetentionPolicy.SOURCE)
175 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
176 VERIFICATION_STATUS_NOT_VERIFIED,
177 VERIFICATION_STATUS_PASSED,
178 VERIFICATION_STATUS_FAILED
179 })
180 public @interface VerificationStatus {}
181
182 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700183 * Connection can currently be put on hold or unheld. This is distinct from
184 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
185 * it does not at the moment support the function. This can be true while the call is in the
186 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
187 * display a disabled 'hold' button.
188 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 public static final int CAPABILITY_HOLD = 0x00000001;
190
191 /** Connection supports the hold feature. */
192 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
193
194 /**
195 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
196 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
197 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
198 * capability allows a merge button to be shown while the conference is in the foreground
199 * of the in-call UI.
200 * <p>
201 * This is only intended for use by a {@link Conference}.
202 */
203 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
204
205 /**
206 * Connections within a conference can be swapped between foreground and background.
207 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
208 * <p>
209 * This is only intended for use by a {@link Conference}.
210 */
211 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
212
213 /**
214 * @hide
215 */
216 public static final int CAPABILITY_UNUSED = 0x00000010;
217
218 /** Connection supports responding via text option. */
219 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
220
221 /** Connection can be muted. */
222 public static final int CAPABILITY_MUTE = 0x00000040;
223
224 /**
225 * Connection supports conference management. This capability only applies to
226 * {@link Conference}s which can have {@link Connection}s as children.
227 */
228 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
229
230 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700233 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234
235 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700236 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800237 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700238 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800239
240 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700241 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700243 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245
246 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
250
251 /**
252 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 */
254 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
255
256 /**
257 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700259 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261
262 /**
263 * Connection is able to be separated from its parent {@code Conference}, if any.
264 */
265 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
266
267 /**
268 * Connection is able to be individually disconnected when in a {@code Conference}.
269 */
270 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
271
272 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700273 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 * @hide
275 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700276 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700279 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 * @hide
281 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700282 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283
284 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700285 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700286 * @hide
287 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700288 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289
Tyler Gunn068085b2015-02-06 13:56:52 -0800290 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700291 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800292 * @hide
293 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700294 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800295
Tyler Gunn96d6c402015-03-18 12:39:23 -0700296 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500297 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700298 * <p>
299 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
300 * place as soon as the device answers the call, but prior to it being connected. This is an
301 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700303 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700304 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700305 @TestApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700306 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800307
Rekha Kumar07366812015-03-24 16:42:31 -0700308 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700309 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800310 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
311 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
312 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700313 */
314 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
315
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700316 /**
317 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700318 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700319 */
320 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
321
Tyler Gunnd4091732015-06-29 09:15:37 -0700322 /**
323 * For a conference, indicates the conference will not have child connections.
324 * <p>
325 * An example of a conference with child connections is a GSM conference call, where the radio
326 * retains connections to the individual participants of the conference. Another example is an
327 * IMS conference call where conference event package functionality is supported; in this case
328 * the conference server ensures the radio is aware of the participants in the conference, which
329 * are represented by child connections.
330 * <p>
331 * An example of a conference with no child connections is an IMS conference call with no
332 * conference event package support. Such a conference is represented by the radio as a single
333 * connection to the IMS conference server.
334 * <p>
335 * Indicating whether a conference has children or not is important to help user interfaces
336 * visually represent a conference. A conference with no children, for example, will have the
337 * conference connection shown in the list of calls on a Bluetooth device, where if the
338 * conference has children, only the children will be shown in the list of calls on a Bluetooth
339 * device.
340 * @hide
341 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700342 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700343 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700344 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
345
Bryce Lee81901682015-08-28 16:38:02 -0700346 /**
347 * Indicates that the connection itself wants to handle any sort of reply response, rather than
348 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700349 */
350 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
351
Tyler Gunnf97a0092016-01-19 15:59:34 -0800352 /**
353 * When set, prevents a video call from being downgraded to an audio-only call.
354 * <p>
355 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
356 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
357 * downgraded from a video call back to a VideoState of
358 * {@link VideoProfile#STATE_AUDIO_ONLY}.
359 * <p>
360 * Intuitively, a call which can be downgraded to audio should also have local and remote
361 * video
362 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
363 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
364 */
365 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
366
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700368 * When set for an external connection, indicates that this {@code Connection} can be pulled
369 * from a remote device to the current device.
370 * <p>
371 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
372 * is set.
373 */
374 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
375
Pooja Jaind34698d2017-12-28 14:15:31 +0530376 /** Call supports the deflect feature. */
377 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
378
Tyler Gunn720c6642016-03-22 09:02:47 -0700379 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530380 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 //**********************************************************************************************
382
383 /**
384 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700385 * <p>
386 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700387 * @hide
388 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700389 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700390 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700391 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700392
393 /**
394 * Whether the call is a generic conference, where we do not know the precise state of
395 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700396 * <p>
397 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700398 * @hide
399 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700400 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700401 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
403
404 /**
405 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700406 * <p>
407 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
408 * implies something like AMR wideband, but the interpretation of when a call is considered high
409 * definition is left to the {@link ConnectionService} to decide.
410 * <p>
411 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700412 */
413 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
414
415 /**
416 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700417 * <p>
418 * Used to indicate that a call is taking place over WIFI versus a carrier network.
419 * <p>
420 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700421 */
422 public static final int PROPERTY_WIFI = 1<<3;
423
424 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700425 * When set, indicates that the {@code Connection} does not actually exist locally for the
426 * {@link ConnectionService}.
427 * <p>
428 * Consider, for example, a scenario where a user has two devices with the same phone number.
429 * When a user places a call on one devices, the telephony stack can represent that call on the
430 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700431 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700432 * <p>
433 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
434 * external connections. Only those {@link InCallService}s which have the
435 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
436 * manifest will see external connections.
437 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700438 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700439
Brad Ebinger15847072016-05-18 11:08:36 -0700440 /**
441 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
442 */
443 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700444
Hall Liu9f332c72016-07-14 15:37:37 -0700445 /**
446 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700447 * <p>
448 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
449 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700450 * @hide
451 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700452 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700453 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700454 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
455
Tyler Gunnf5035432017-01-09 09:43:12 -0800456 /**
457 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
458 * {@link ConnectionService}.
459 * <p>
460 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
461 */
462 public static final int PROPERTY_SELF_MANAGED = 1<<7;
463
Hall Liu95d55872017-01-25 17:12:49 -0800464 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800465 * Set by the framework to indicate that a connection has an active RTT session associated with
466 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800467 */
468 public static final int PROPERTY_IS_RTT = 1 << 8;
469
Eric Erfanian62706c52017-12-06 16:27:53 -0800470 /**
471 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700472 * <p>
473 * This is used for outgoing calls.
474 *
475 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800476 */
477 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
478
Tyler Gunn5bd90852018-09-21 09:37:07 -0700479 /**
480 * Set by the framework to indicate that the network has identified a Connection as an emergency
481 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700482 * <p>
483 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
484 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700485 */
486 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
487
Tyler Gunnac60f952019-05-31 07:23:16 -0700488 /**
489 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
490 * than the current one. Used in scenarios where the conference originator is the remote device
491 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700492 * <p>
493 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700494 * @hide
495 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700496 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700497 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700498 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
499
Tyler Gunn96d6c402015-03-18 12:39:23 -0700500 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700501 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700502 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800503
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700504 /**
allenwtsu2aca9892019-11-25 14:38:21 +0800505 * Define IMS Audio Codec
506 */
507 // Current audio codec is NONE
508 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
509 // Current audio codec is AMR
510 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
511 // Current audio codec is AMR_WB
512 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
513 // Current audio codec is QCELP13K
514 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
515 // Current audio codec is EVRC
516 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
517 // Current audio codec is EVRC_B
518 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
519 // Current audio codec is EVRC_WB
520 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
521 // Current audio codec is EVRC_NW
522 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
523 // Current audio codec is GSM_EFR
524 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
525 // Current audio codec is GSM_FR
526 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
527 // Current audio codec is GSM_HR
528 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
529 // Current audio codec is G711U
530 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
531 // Current audio codec is G723
532 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
533 // Current audio codec is G711A
534 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
535 // Current audio codec is G722
536 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
537 // Current audio codec is G711AB
538 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
539 // Current audio codec is G729
540 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
541 // Current audio codec is EVS_NB
542 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
543 // Current audio codec is EVS_WB
544 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
545 // Current audio codec is EVS_SWB
546 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
547 // Current audio codec is EVS_FB
548 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
549
550 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700551 * Connection extra key used to store the last forwarded number associated with the current
552 * connection. Used to communicate to the user interface that the connection was forwarded via
553 * the specified number.
554 */
555 public static final String EXTRA_LAST_FORWARDED_NUMBER =
556 "android.telecom.extra.LAST_FORWARDED_NUMBER";
557
558 /**
559 * Connection extra key used to store a child number associated with the current connection.
560 * Used to communicate to the user interface that the connection was received via
561 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
562 * address.
563 */
564 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
565
566 /**
567 * Connection extra key used to store the subject for an incoming call. The user interface can
568 * query this extra and display its contents for incoming calls. Will only be used if the
569 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
570 */
571 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
572
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800573 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700574 * Boolean connection extra key set on a {@link Connection} in
575 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
576 * current active foreground call to be dropped.
577 */
578 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
579 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
580
581 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700582 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
583 * state to indicate the name of the third-party app which is responsible for the current
584 * foreground call.
585 * <p>
586 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
587 * is able to inform the user that answering the new incoming call will cause a call owned by
588 * another app to be dropped when the incoming call is answered.
589 */
590 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
591 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
592
593 /**
Hall Liu10208662016-06-15 17:55:00 -0700594 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700595 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700596 * <p>
597 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
598 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700599 * @hide
600 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700601 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700602 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700603 public static final String EXTRA_DISABLE_ADD_CALL =
604 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700605
606 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700607 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
608 * original Connection ID associated with the connection. Used in
609 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
610 * connection/conference added via
611 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
612 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
613 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
614 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
615 * be a way to ensure that we don't add the connection again as a duplicate.
616 * <p>
617 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
618 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
619 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
620 * in a new {@link Connection} which it adds to Telecom via
621 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
622 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
623 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
624 * ID it originally referred to the connection as. Thus Telecom needs to know that the
625 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700626 * <p>
627 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
628 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700629 * @hide
630 */
631 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
632 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
633
634 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700635 * Boolean connection extra key set on the extras passed to
636 * {@link Connection#sendConnectionEvent} which indicates that audio is present
637 * on the RTT call when the extra value is true.
638 */
639 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
640 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
641
642 /**
allenwtsu2aca9892019-11-25 14:38:21 +0800643 * The audio codec in use for the current {@link Connection}, if known. Valid values include
644 * {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
645 */
646 public static final String EXTRA_AUDIO_CODEC =
647 "android.telecom.extra.AUDIO_CODEC";
648
649 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800650 * Connection event used to inform Telecom that it should play the on hold tone. This is used
651 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700652 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800653 */
654 public static final String EVENT_ON_HOLD_TONE_START =
655 "android.telecom.event.ON_HOLD_TONE_START";
656
657 /**
658 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
659 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700660 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800661 */
662 public static final String EVENT_ON_HOLD_TONE_END =
663 "android.telecom.event.ON_HOLD_TONE_END";
664
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700665 /**
666 * Connection event used to inform {@link InCallService}s when pulling of an external call has
667 * failed. The user interface should inform the user of the error.
668 * <p>
669 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
670 * API is called on a {@link Call} with the properties
671 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
672 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
673 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700674 * <p>
675 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
676 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700677 */
678 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
679
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700680 /**
681 * Connection event used to inform {@link InCallService}s when the merging of two calls has
682 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700683 * <p>
684 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
685 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700686 */
687 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
688
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700689 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700690 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700691 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700692 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
693 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700694 */
695 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
696
697 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700698 * Connection event used to inform {@link InCallService}s when the process of merging a
699 * Connection into a conference has begun.
700 * <p>
701 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
702 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700703 */
704 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
705
706 /**
707 * Connection event used to inform {@link InCallService}s when the process of merging a
708 * Connection into a conference has completed.
709 * <p>
710 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
711 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700712 */
713 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
714
715 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700716 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
717 * the remote party.
718 * <p>
719 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
720 * call is being held locally on the device. When a capable {@link ConnectionService} receives
721 * signalling to indicate that the remote party has put the call on hold, it can send this
722 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700723 */
724 public static final String EVENT_CALL_REMOTELY_HELD =
725 "android.telecom.event.CALL_REMOTELY_HELD";
726
727 /**
728 * Connection event used to inform {@link InCallService}s when a call which was remotely held
729 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
730 * <p>
731 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
732 * call is being held locally on the device. When a capable {@link ConnectionService} receives
733 * signalling to indicate that the remote party has taken the call off hold, it can send this
734 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700735 */
736 public static final String EVENT_CALL_REMOTELY_UNHELD =
737 "android.telecom.event.CALL_REMOTELY_UNHELD";
738
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700739 /**
740 * Connection event used to inform an {@link InCallService} which initiated a call handover via
741 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
742 * successfully completed.
743 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700744 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
745 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700746 */
747 public static final String EVENT_HANDOVER_COMPLETE =
748 "android.telecom.event.HANDOVER_COMPLETE";
749
750 /**
751 * Connection event used to inform an {@link InCallService} which initiated a call handover via
752 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
753 * to complete.
754 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700755 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
756 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700757 */
758 public static final String EVENT_HANDOVER_FAILED =
759 "android.telecom.event.HANDOVER_FAILED";
760
shilub7ec9a02018-11-09 15:52:04 -0800761 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000762 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800763 */
764 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
765
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700766 /**
767 * Connection event used to inform an {@link InCallService} that the RTT audio indication
768 * has changed.
769 */
770 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
771 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
772
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 // Flag controlling whether PII is emitted into the logs
774 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
775
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800776 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700777 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
778 *
779 * @param capabilities A capability bit field.
780 * @return A human readable string representation.
781 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800782 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 return capabilitiesToStringInternal(capabilities, true /* isLong */);
784 }
785
786 /**
787 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
788 * string.
789 *
790 * @param capabilities A capability bit field.
791 * @return A human readable string representation.
792 * @hide
793 */
794 public static String capabilitiesToStringShort(int capabilities) {
795 return capabilitiesToStringInternal(capabilities, false /* isLong */);
796 }
797
798 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800799 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700800 builder.append("[");
801 if (isLong) {
802 builder.append("Capabilities:");
803 }
804
Tyler Gunnc63f9082019-10-15 13:19:26 -0700805 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700806 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800807 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700808 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700809 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800810 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700811 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700812 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800813 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700814 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700815 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700817 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700818 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800819 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700820 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700821 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800822 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700823 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700824 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800825 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700826 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700827 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700828 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700829 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700830 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700831 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700832 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
833 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700834 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800835 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700836 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700837 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700838 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700839 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700840 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700841 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700842 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
843 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700844 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800845 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700846 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
847 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700848 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800849 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700850 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700851 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500852 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700853 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700854 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700855 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700856 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700857 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700858 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700859 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
860 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700861 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700862 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700863 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
864 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700865 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700866 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700867 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700868 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700869 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700870 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530871 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
872 }
Bryce Lee81901682015-08-28 16:38:02 -0700873
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800874 builder.append("]");
875 return builder.toString();
876 }
877
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700878 /**
879 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
880 *
881 * @param properties A property bit field.
882 * @return A human readable string representation.
883 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700884 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700885 return propertiesToStringInternal(properties, true /* isLong */);
886 }
887
888 /**
889 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
890 *
891 * @param properties A property bit field.
892 * @return A human readable string representation.
893 * @hide
894 */
895 public static String propertiesToStringShort(int properties) {
896 return propertiesToStringInternal(properties, false /* isLong */);
897 }
898
899 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700900 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700901 builder.append("[");
902 if (isLong) {
903 builder.append("Properties:");
904 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700905
Tyler Gunnc63f9082019-10-15 13:19:26 -0700906 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800907 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
908 }
909
Tyler Gunnc63f9082019-10-15 13:19:26 -0700910 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700911 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700912 }
913
Tyler Gunnc63f9082019-10-15 13:19:26 -0700914 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700915 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700916 }
917
Tyler Gunnc63f9082019-10-15 13:19:26 -0700918 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700919 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700920 }
921
Tyler Gunnc63f9082019-10-15 13:19:26 -0700922 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700923 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700924 }
925
Tyler Gunnc63f9082019-10-15 13:19:26 -0700926 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700927 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700928 }
929
Tyler Gunnc63f9082019-10-15 13:19:26 -0700930 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700931 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700932 }
933
Tyler Gunnc63f9082019-10-15 13:19:26 -0700934 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800935 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
936 }
937
Tyler Gunnc63f9082019-10-15 13:19:26 -0700938 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
939 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700940 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
941 }
942
Tyler Gunnc63f9082019-10-15 13:19:26 -0700943 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700944 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
945 }
946
Tyler Gunn720c6642016-03-22 09:02:47 -0700947 builder.append("]");
948 return builder.toString();
949 }
950
Sailesh Nepal091768c2014-06-30 15:15:23 -0700951 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700952 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700953 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700954 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700955 public void onCallerDisplayNameChanged(
956 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700957 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700958 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700959 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800960 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700961 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700962 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800963 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700964 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800965 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 public void onVideoProviderChanged(
967 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700968 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
969 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800970 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700971 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700972 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700973 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700974 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700975 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700976 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800977 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800978 public void onRttInitiationSuccess(Connection c) {}
979 public void onRttInitiationFailure(Connection c, int reason) {}
980 public void onRttSessionRemotelyTerminated(Connection c) {}
981 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530982 /** @hide */
983 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800984 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700985 }
986
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 /**
Hall Liu95d55872017-01-25 17:12:49 -0800988 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800989 */
990 public static final class RttTextStream {
991 private static final int READ_BUFFER_SIZE = 1000;
992 private final InputStreamReader mPipeFromInCall;
993 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800994 private final ParcelFileDescriptor mFdFromInCall;
995 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700996
997 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800998 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
999
1000 /**
1001 * @hide
1002 */
1003 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001004 mFdFromInCall = fromInCall;
1005 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001006 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001007
1008 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001009 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001010 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001011 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001012 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001013 }
1014
1015 /**
1016 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1017 * RTT transmits text in real-time, this method should be called as often as text snippets
1018 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001019 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001020 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1021 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001022 *
Hall Liu95d55872017-01-25 17:12:49 -08001023 * @param input The message to send to the in-call app.
1024 */
1025 public void write(String input) throws IOException {
1026 mPipeToInCall.write(input);
1027 mPipeToInCall.flush();
1028 }
1029
1030
1031 /**
1032 * Reads a string from the in-call app, blocking if there is no data available. Returns
1033 * {@code null} if the RTT conversation has been terminated and there is no further data
1034 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001035 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001036 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1037 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001038 *
Hall Liu95d55872017-01-25 17:12:49 -08001039 * @return A string containing text entered by the user, or {@code null} if the
1040 * conversation has been terminated or if there was an error while reading.
1041 */
Hall Liuffa4a812017-03-02 16:11:00 -08001042 public String read() throws IOException {
1043 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1044 if (numRead < 0) {
1045 return null;
1046 }
1047 return new String(mReadBuffer, 0, numRead);
1048 }
1049
1050 /**
1051 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1052 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001053 *
Hall Liuffa4a812017-03-02 16:11:00 -08001054 * @return A string containing text entered by the user, or {@code null} if the user has
1055 * not entered any new text yet.
1056 */
1057 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001058 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001059 return read();
1060 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001061 return null;
1062 }
1063 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001064
1065 /** @hide */
1066 public ParcelFileDescriptor getFdFromInCall() {
1067 return mFdFromInCall;
1068 }
1069
1070 /** @hide */
1071 public ParcelFileDescriptor getFdToInCall() {
1072 return mFdToInCall;
1073 }
1074 }
1075
1076 /**
1077 * Provides constants to represent the results of responses to session modify requests sent via
1078 * {@link Call#sendRttRequest()}
1079 */
1080 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001081 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001082 /**
1083 * Session modify request was successful.
1084 */
1085 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1086
1087 /**
1088 * Session modify request failed.
1089 */
1090 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1091
1092 /**
1093 * Session modify request ignored due to invalid parameters.
1094 */
1095 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1096
1097 /**
1098 * Session modify request timed out.
1099 */
1100 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1101
1102 /**
1103 * Session modify request rejected by remote user.
1104 */
1105 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001106 }
1107
1108 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001109 * Provides a means of controlling the video session associated with a {@link Connection}.
1110 * <p>
1111 * Implementations create a custom subclass of {@link VideoProvider} and the
1112 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1113 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1114 * should set the {@link VideoProvider}.
1115 * <p>
1116 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1117 * {@link InCallService} implementations to issue requests related to the video session;
1118 * it provides a means for the {@link ConnectionService} to report events and information
1119 * related to the video session to Telecom and the {@link InCallService} implementations.
1120 * <p>
1121 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1122 * {@link android.telecom.InCallService.VideoCall}.
1123 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 /**
1126 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001127 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 */
1129 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001130
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001132 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1133 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 */
1135 public static final int SESSION_EVENT_RX_RESUME = 2;
1136
1137 /**
1138 * Video transmission has begun. This occurs after a negotiated start of video transmission
1139 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001140 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 */
1142 public static final int SESSION_EVENT_TX_START = 3;
1143
1144 /**
1145 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1146 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001147 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 */
1149 public static final int SESSION_EVENT_TX_STOP = 4;
1150
1151 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001152 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001153 * this as a cue to inform the user the camera is not available.
1154 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001155 */
1156 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1157
1158 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001159 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001160 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001161 * the camera has become available again.
1162 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 */
1164 public static final int SESSION_EVENT_CAMERA_READY = 6;
1165
1166 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001167 * Session event raised by Telecom when
1168 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1169 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1170 * @see #handleCallSessionEvent(int)
1171 */
1172 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1173
1174 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001176 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 */
1178 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1179
1180 /**
1181 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001182 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001183 */
1184 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1185
1186 /**
1187 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001188 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001189 */
1190 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1191
Rekha Kumar07366812015-03-24 16:42:31 -07001192 /**
1193 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001194 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001195 */
1196 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1197
1198 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001199 * Session modify request rejected by remote user.
1200 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001201 */
1202 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1203
Tyler Gunn75958422015-04-15 14:23:42 -07001204 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001205 private static final int MSG_SET_CAMERA = 2;
1206 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1207 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1208 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1209 private static final int MSG_SET_ZOOM = 6;
1210 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1211 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1212 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001213 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001214 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001215 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001216
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001217 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1218 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1219 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1220 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1221 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1222 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001223 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1224 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001225 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1226
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001227 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001229
1230 /**
1231 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001232 *
1233 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1234 * load factor before resizing, 1 means we only expect a single thread to
1235 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001236 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001237 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1238 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001239
1240 /**
1241 * Default handler used to consolidate binder method calls onto a single thread.
1242 */
1243 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001244 public VideoProviderHandler() {
1245 super();
1246 }
1247
1248 public VideoProviderHandler(Looper looper) {
1249 super(looper);
1250 }
1251
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001252 @Override
1253 public void handleMessage(Message msg) {
1254 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001255 case MSG_ADD_VIDEO_CALLBACK: {
1256 IBinder binder = (IBinder) msg.obj;
1257 IVideoCallback callback = IVideoCallback.Stub
1258 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001259 if (callback == null) {
1260 Log.w(this, "addVideoProvider - skipped; callback is null.");
1261 break;
1262 }
1263
Tyler Gunn75958422015-04-15 14:23:42 -07001264 if (mVideoCallbacks.containsKey(binder)) {
1265 Log.i(this, "addVideoProvider - skipped; already present.");
1266 break;
1267 }
1268 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001270 }
1271 case MSG_REMOVE_VIDEO_CALLBACK: {
1272 IBinder binder = (IBinder) msg.obj;
1273 IVideoCallback callback = IVideoCallback.Stub
1274 .asInterface((IBinder) msg.obj);
1275 if (!mVideoCallbacks.containsKey(binder)) {
1276 Log.i(this, "removeVideoProvider - skipped; not present.");
1277 break;
1278 }
1279 mVideoCallbacks.remove(binder);
1280 break;
1281 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001282 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001283 {
1284 SomeArgs args = (SomeArgs) msg.obj;
1285 try {
1286 onSetCamera((String) args.arg1);
1287 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001288 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001289 } finally {
1290 args.recycle();
1291 }
1292 }
1293 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 case MSG_SET_PREVIEW_SURFACE:
1295 onSetPreviewSurface((Surface) msg.obj);
1296 break;
1297 case MSG_SET_DISPLAY_SURFACE:
1298 onSetDisplaySurface((Surface) msg.obj);
1299 break;
1300 case MSG_SET_DEVICE_ORIENTATION:
1301 onSetDeviceOrientation(msg.arg1);
1302 break;
1303 case MSG_SET_ZOOM:
1304 onSetZoom((Float) msg.obj);
1305 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001306 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1307 SomeArgs args = (SomeArgs) msg.obj;
1308 try {
1309 onSendSessionModifyRequest((VideoProfile) args.arg1,
1310 (VideoProfile) args.arg2);
1311 } finally {
1312 args.recycle();
1313 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001315 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1317 onSendSessionModifyResponse((VideoProfile) msg.obj);
1318 break;
1319 case MSG_REQUEST_CAMERA_CAPABILITIES:
1320 onRequestCameraCapabilities();
1321 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001322 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1323 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 break;
1325 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001326 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 break;
1328 default:
1329 break;
1330 }
1331 }
1332 }
1333
1334 /**
1335 * IVideoProvider stub implementation.
1336 */
1337 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001338 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001340 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1341 }
1342
1343 public void removeVideoCallback(IBinder videoCallbackBinder) {
1344 mMessageHandler.obtainMessage(
1345 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 }
1347
Tyler Gunn159f35c2017-03-02 09:28:37 -08001348 public void setCamera(String cameraId, String callingPackageName,
1349 int targetSdkVersion) {
1350
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001351 SomeArgs args = SomeArgs.obtain();
1352 args.arg1 = cameraId;
1353 // Propagate the calling package; originally determined in
1354 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1355 // process.
1356 args.arg2 = callingPackageName;
1357 // Pass along the uid and pid of the calling app; this gets lost when we put the
1358 // message onto the handler. These are required for Telecom to perform a permission
1359 // check to see if the calling app is able to use the camera.
1360 args.argi1 = Binder.getCallingUid();
1361 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001362 // Pass along the target SDK version of the calling InCallService. This is used to
1363 // maintain backwards compatibility of the API for older callers.
1364 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001365 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366 }
1367
1368 public void setPreviewSurface(Surface surface) {
1369 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1370 }
1371
1372 public void setDisplaySurface(Surface surface) {
1373 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1374 }
1375
1376 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001377 mMessageHandler.obtainMessage(
1378 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 }
1380
1381 public void setZoom(float value) {
1382 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1383 }
1384
Tyler Gunn45382162015-05-06 08:52:27 -07001385 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1386 SomeArgs args = SomeArgs.obtain();
1387 args.arg1 = fromProfile;
1388 args.arg2 = toProfile;
1389 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 }
1391
1392 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1393 mMessageHandler.obtainMessage(
1394 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1395 }
1396
1397 public void requestCameraCapabilities() {
1398 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1399 }
1400
1401 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001402 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 }
1404
Yorke Lee32f24732015-05-12 16:18:03 -07001405 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1407 }
1408 }
1409
1410 public VideoProvider() {
1411 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001412 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001413 }
1414
1415 /**
1416 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1417 *
1418 * @param looper The looper.
1419 * @hide
1420 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001421 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001422 public VideoProvider(Looper looper) {
1423 mBinder = new VideoProvider.VideoProviderBinder();
1424 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001425 }
1426
1427 /**
1428 * Returns binder object which can be used across IPC methods.
1429 * @hide
1430 */
1431 public final IVideoProvider getInterface() {
1432 return mBinder;
1433 }
1434
1435 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001436 * Sets the camera to be used for the outgoing video.
1437 * <p>
1438 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1439 * camera via
1440 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1441 * <p>
1442 * Sent from the {@link InCallService} via
1443 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001445 * @param cameraId The id of the camera (use ids as reported by
1446 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001447 */
1448 public abstract void onSetCamera(String cameraId);
1449
1450 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001451 * Sets the camera to be used for the outgoing video.
1452 * <p>
1453 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1454 * camera via
1455 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1456 * <p>
1457 * This prototype is used internally to ensure that the calling package name, UID and PID
1458 * are sent to Telecom so that can perform a camera permission check on the caller.
1459 * <p>
1460 * Sent from the {@link InCallService} via
1461 * {@link InCallService.VideoCall#setCamera(String)}.
1462 *
1463 * @param cameraId The id of the camera (use ids as reported by
1464 * {@link CameraManager#getCameraIdList()}).
1465 * @param callingPackageName The AppOpps package name of the caller.
1466 * @param callingUid The UID of the caller.
1467 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001468 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001469 * @hide
1470 */
1471 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001472 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001473
1474 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001475 * Sets the surface to be used for displaying a preview of what the user's camera is
1476 * currently capturing. When video transmission is enabled, this is the video signal which
1477 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001478 * <p>
1479 * Sent from the {@link InCallService} via
1480 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001482 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 */
1484 public abstract void onSetPreviewSurface(Surface surface);
1485
1486 /**
1487 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001488 * <p>
1489 * Sent from the {@link InCallService} via
1490 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001492 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 */
1494 public abstract void onSetDisplaySurface(Surface surface);
1495
1496 /**
1497 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1498 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001499 * <p>
1500 * Sent from the {@link InCallService} via
1501 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502 *
1503 * @param rotation The device orientation, in degrees.
1504 */
1505 public abstract void onSetDeviceOrientation(int rotation);
1506
1507 /**
1508 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001509 * <p>
1510 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511 *
1512 * @param value The camera zoom ratio.
1513 */
1514 public abstract void onSetZoom(float value);
1515
1516 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001517 * Issues a request to modify the properties of the current video session.
1518 * <p>
1519 * Example scenarios include: requesting an audio-only call to be upgraded to a
1520 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1521 * when the {@link InCallService} is no longer the foreground application.
1522 * <p>
1523 * If the {@link VideoProvider} determines a request to be invalid, it should call
1524 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1525 * invalid request back to the {@link InCallService}.
1526 * <p>
1527 * Where a request requires confirmation from the user of the peer device, the
1528 * {@link VideoProvider} must communicate the request to the peer device and handle the
1529 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1530 * is used to inform the {@link InCallService} of the result of the request.
1531 * <p>
1532 * Sent from the {@link InCallService} via
1533 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001534 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001535 * @param fromProfile The video profile prior to the request.
1536 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 */
Tyler Gunn45382162015-05-06 08:52:27 -07001538 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1539 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540
Tyler Gunnb702ef82015-05-29 11:51:53 -07001541 /**
1542 * Provides a response to a request to change the current video session properties.
1543 * <p>
1544 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1545 * video call, could decline the request and keep the call as audio-only.
1546 * In such a scenario, the {@code responseProfile} would have a video state of
1547 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1548 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1549 * <p>
1550 * Sent from the {@link InCallService} via
1551 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1552 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1553 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001554 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001555 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 */
1557 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1558
1559 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001560 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1561 * <p>
1562 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1563 * camera via
1564 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1565 * <p>
1566 * Sent from the {@link InCallService} via
1567 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 */
1569 public abstract void onRequestCameraCapabilities();
1570
1571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001572 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1573 * video component of the current {@link Connection}.
1574 * <p>
1575 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1576 * via {@link VideoProvider#setCallDataUsage(long)}.
1577 * <p>
1578 * Sent from the {@link InCallService} via
1579 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001580 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001581 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582
1583 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001584 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1585 * the peer device when the video signal is paused.
1586 * <p>
1587 * Sent from the {@link InCallService} via
1588 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 *
1590 * @param uri URI of image to display.
1591 */
Yorke Lee32f24732015-05-12 16:18:03 -07001592 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001593
1594 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001595 * Used to inform listening {@link InCallService} implementations when the
1596 * {@link VideoProvider} receives a session modification request.
1597 * <p>
1598 * Received by the {@link InCallService} via
1599 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001601 * @param videoProfile The requested video profile.
1602 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 */
1604 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001605 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001606 for (IVideoCallback callback : mVideoCallbacks.values()) {
1607 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001608 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001609 } catch (RemoteException ignored) {
1610 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001611 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001612 }
1613 }
1614 }
1615
1616 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001617 * Used to inform listening {@link InCallService} implementations when the
1618 * {@link VideoProvider} receives a response to a session modification request.
1619 * <p>
1620 * Received by the {@link InCallService} via
1621 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1622 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 *
1624 * @param status Status of the session modify request. Valid values are
1625 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1626 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001627 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1628 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1629 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1630 * @param requestedProfile The original request which was sent to the peer device.
1631 * @param responseProfile The actual profile changes agreed to by the peer device.
1632 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 */
1634 public void receiveSessionModifyResponse(int status,
1635 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001636 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001637 for (IVideoCallback callback : mVideoCallbacks.values()) {
1638 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001639 callback.receiveSessionModifyResponse(status, requestedProfile,
1640 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001641 } catch (RemoteException ignored) {
1642 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001643 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001644 }
1645 }
1646 }
1647
1648 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001649 * Used to inform listening {@link InCallService} implementations when the
1650 * {@link VideoProvider} reports a call session event.
1651 * <p>
1652 * Received by the {@link InCallService} via
1653 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001655 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1656 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1657 * {@link VideoProvider#SESSION_EVENT_TX_START},
1658 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1659 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001660 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1661 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001662 */
1663 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001664 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001665 for (IVideoCallback callback : mVideoCallbacks.values()) {
1666 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001667 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001668 } catch (RemoteException ignored) {
1669 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001670 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001671 }
1672 }
1673 }
1674
1675 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001676 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1677 * peer's video have changed.
1678 * <p>
1679 * This could occur if, for example, the peer rotates their device, changing the aspect
1680 * ratio of the video, or if the user switches between the back and front cameras.
1681 * <p>
1682 * Received by the {@link InCallService} via
1683 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001684 *
1685 * @param width The updated peer video width.
1686 * @param height The updated peer video height.
1687 */
1688 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001689 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001690 for (IVideoCallback callback : mVideoCallbacks.values()) {
1691 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001692 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001693 } catch (RemoteException ignored) {
1694 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001695 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 }
1697 }
1698 }
1699
1700 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001701 * Used to inform listening {@link InCallService} implementations when the data usage of the
1702 * video associated with the current {@link Connection} has changed.
1703 * <p>
1704 * This could be in response to a preview request via
1705 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001706 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1707 * 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 -07001708 * <p>
1709 * Received by the {@link InCallService} via
1710 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001711 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001712 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1713 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001714 */
Yorke Lee32f24732015-05-12 16:18:03 -07001715 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001716 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001717 for (IVideoCallback callback : mVideoCallbacks.values()) {
1718 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001719 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001720 } catch (RemoteException ignored) {
1721 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001722 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001723 }
1724 }
1725 }
1726
1727 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001728 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001729 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001730 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001731 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1732 * @hide
1733 */
1734 public void changeCallDataUsage(long dataUsage) {
1735 setCallDataUsage(dataUsage);
1736 }
1737
1738 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001739 * Used to inform listening {@link InCallService} implementations when the capabilities of
1740 * the current camera have changed.
1741 * <p>
1742 * The {@link VideoProvider} should call this in response to
1743 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1744 * changed via {@link VideoProvider#onSetCamera(String)}.
1745 * <p>
1746 * Received by the {@link InCallService} via
1747 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1748 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001749 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001750 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001751 */
Yorke Lee400470f2015-05-12 13:31:25 -07001752 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001753 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001754 for (IVideoCallback callback : mVideoCallbacks.values()) {
1755 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001756 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001757 } catch (RemoteException ignored) {
1758 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001759 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001760 }
1761 }
1762 }
Rekha Kumar07366812015-03-24 16:42:31 -07001763
1764 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001765 * Used to inform listening {@link InCallService} implementations when the video quality
1766 * of the call has changed.
1767 * <p>
1768 * Received by the {@link InCallService} via
1769 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001770 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001771 * @param videoQuality The updated video quality. Valid values:
1772 * {@link VideoProfile#QUALITY_HIGH},
1773 * {@link VideoProfile#QUALITY_MEDIUM},
1774 * {@link VideoProfile#QUALITY_LOW},
1775 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001776 */
1777 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001778 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001779 for (IVideoCallback callback : mVideoCallbacks.values()) {
1780 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001781 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001782 } catch (RemoteException ignored) {
1783 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001784 }
Rekha Kumar07366812015-03-24 16:42:31 -07001785 }
1786 }
1787 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001788
1789 /**
1790 * Returns a string representation of a call session event.
1791 *
1792 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1793 * @return String representation of the call session event.
1794 * @hide
1795 */
1796 public static String sessionEventToString(int event) {
1797 switch (event) {
1798 case SESSION_EVENT_CAMERA_FAILURE:
1799 return SESSION_EVENT_CAMERA_FAILURE_STR;
1800 case SESSION_EVENT_CAMERA_READY:
1801 return SESSION_EVENT_CAMERA_READY_STR;
1802 case SESSION_EVENT_RX_PAUSE:
1803 return SESSION_EVENT_RX_PAUSE_STR;
1804 case SESSION_EVENT_RX_RESUME:
1805 return SESSION_EVENT_RX_RESUME_STR;
1806 case SESSION_EVENT_TX_START:
1807 return SESSION_EVENT_TX_START_STR;
1808 case SESSION_EVENT_TX_STOP:
1809 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001810 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1811 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001812 default:
1813 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1814 }
1815 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001816 }
1817
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001818 private final Listener mConnectionDeathListener = new Listener() {
1819 @Override
1820 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001821 if (mConferenceables.remove(c)) {
1822 fireOnConferenceableConnectionsChanged();
1823 }
1824 }
1825 };
1826
1827 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1828 @Override
1829 public void onDestroyed(Conference c) {
1830 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001831 fireOnConferenceableConnectionsChanged();
1832 }
1833 }
1834 };
1835
Jay Shrauner229e3822014-08-15 09:23:07 -07001836 /**
1837 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1838 * load factor before resizing, 1 means we only expect a single thread to
1839 * access the map so make only a single shard
1840 */
1841 private final Set<Listener> mListeners = Collections.newSetFromMap(
1842 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001843 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1844 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001845 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001846
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001847 // The internal telecom call ID associated with this connection.
1848 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001849 // The PhoneAccountHandle associated with this connection.
1850 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001851 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001852 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001853 private Uri mAddress;
1854 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001855 private String mCallerDisplayName;
1856 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001857 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001858 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001859 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001860 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001861 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001862 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001863 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001864 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001865 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001866 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001867 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001868 private Conference mConference;
1869 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001870 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001871 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001872 /**
1873 * The direction of the connection; used where an existing connection is created and we need to
1874 * communicate to Telecom whether its incoming or outgoing.
1875 */
1876 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001877
1878 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001879 * Tracks the key set for the extras bundle provided on the last invocation of
1880 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1881 * keys which were set previously but are no longer present in the replacement Bundle.
1882 */
1883 private Set<String> mPreviousExtraKeys;
1884
1885 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001886 * The verification status for an incoming call's phone number.
1887 */
1888 private @VerificationStatus int mCallerNumberVerificationStatus;
1889
1890
1891 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001892 * Create a new Connection.
1893 */
Santos Cordonf2951102014-07-20 19:06:29 -07001894 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001895
1896 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001897 * Returns the Telecom internal call ID associated with this connection. Should only be used
1898 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001899 * <p>
1900 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1901 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001902 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001903 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001904 * @hide
1905 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001906 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001907 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001908 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001909 return mTelecomCallId;
1910 }
1911
1912 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001913 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914 */
Andrew Lee100e2932014-09-08 15:34:24 -07001915 public final Uri getAddress() {
1916 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001917 }
1918
1919 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001920 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001921 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001922 */
Andrew Lee100e2932014-09-08 15:34:24 -07001923 public final int getAddressPresentation() {
1924 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001925 }
1926
1927 /**
1928 * @return The caller display name (CNAP).
1929 */
1930 public final String getCallerDisplayName() {
1931 return mCallerDisplayName;
1932 }
1933
1934 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001935 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001936 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001937 */
1938 public final int getCallerDisplayNamePresentation() {
1939 return mCallerDisplayNamePresentation;
1940 }
1941
1942 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001943 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001944 */
1945 public final int getState() {
1946 return mState;
1947 }
1948
1949 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001950 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001951 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1952 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1953 * {@link VideoProfile#STATE_TX_ENABLED},
1954 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001955 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001956 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001957 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001958 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001959 return mVideoState;
1960 }
1961
1962 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001963 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001964 * being routed by the system. This is {@code null} if this Connection
1965 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001966 * @deprecated Use {@link #getCallAudioState()} instead.
1967 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001968 */
Yorke Lee4af59352015-05-13 14:14:54 -07001969 @SystemApi
1970 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001971 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001972 if (mCallAudioState == null) {
1973 return null;
1974 }
Yorke Lee4af59352015-05-13 14:14:54 -07001975 return new AudioState(mCallAudioState);
1976 }
1977
1978 /**
1979 * @return The audio state of the connection, describing how its audio is currently
1980 * being routed by the system. This is {@code null} if this Connection
1981 * does not directly know about its audio state.
1982 */
1983 public final CallAudioState getCallAudioState() {
1984 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001985 }
1986
1987 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001988 * @return The conference that this connection is a part of. Null if it is not part of any
1989 * conference.
1990 */
1991 public final Conference getConference() {
1992 return mConference;
1993 }
1994
1995 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001996 * Returns whether this connection is requesting that the system play a ringback tone
1997 * on its behalf.
1998 */
Andrew Lee100e2932014-09-08 15:34:24 -07001999 public final boolean isRingbackRequested() {
2000 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002001 }
2002
2003 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002004 * @return True if the connection's audio mode is VOIP.
2005 */
2006 public final boolean getAudioModeIsVoip() {
2007 return mAudioModeIsVoip;
2008 }
2009
2010 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002011 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2012 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2013 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002014 * <p>
2015 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2016 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002017 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002018 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2019 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002020 *
2021 * @hide
2022 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002023 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002024 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002025 public final long getConnectTimeMillis() {
2026 return mConnectTimeMillis;
2027 }
2028
2029 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002030 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2031 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2032 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002033 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002034 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2035 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002036 * <p>
2037 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002038 *
2039 * @return The time at which the {@link Connection} was connected.
2040 *
2041 * @hide
2042 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002043 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002044 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002045 public final long getConnectElapsedTimeMillis() {
2046 return mConnectElapsedTimeMillis;
2047 }
2048
2049 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002050 * @return The status hints for this connection.
2051 */
2052 public final StatusHints getStatusHints() {
2053 return mStatusHints;
2054 }
2055
2056 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002057 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002058 * <p>
2059 * Extras should be updated using {@link #putExtras(Bundle)}.
2060 * <p>
2061 * Telecom or an {@link InCallService} can also update the extras via
2062 * {@link android.telecom.Call#putExtras(Bundle)}, and
2063 * {@link Call#removeExtras(List)}.
2064 * <p>
2065 * The connection is notified of changes to the extras made by Telecom or an
2066 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002067 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002068 * @return The extras associated with this connection.
2069 */
2070 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002071 Bundle extras = null;
2072 synchronized (mExtrasLock) {
2073 if (mExtras != null) {
2074 extras = new Bundle(mExtras);
2075 }
2076 }
2077 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002078 }
2079
2080 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002081 * Assign a listener to be notified of state changes.
2082 *
2083 * @param l A listener.
2084 * @return This Connection.
2085 *
2086 * @hide
2087 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002088 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002089 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 return this;
2091 }
2092
2093 /**
2094 * Remove a previously assigned listener that was being notified of state changes.
2095 *
2096 * @param l A Listener.
2097 * @return This Connection.
2098 *
2099 * @hide
2100 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002101 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002102 if (l != null) {
2103 mListeners.remove(l);
2104 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002105 return this;
2106 }
2107
2108 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002109 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002110 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002111 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002112 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002113 }
2114
2115 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002116 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2117 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002118 * <p>
2119 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2120 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2121 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002122 *
2123 * @param callId The telecom call ID.
2124 * @hide
2125 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002126 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002127 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002128 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002129 mTelecomCallId = callId;
2130 }
2131
2132 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002133 * Inform this Connection that the state of its audio output has been changed externally.
2134 *
2135 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002136 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002137 */
Yorke Lee4af59352015-05-13 14:14:54 -07002138 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002139 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002140 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002141 mCallAudioState = state;
2142 onAudioStateChanged(getAudioState());
2143 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002144 }
2145
2146 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002147 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002148 * @return A string representation of the value.
2149 */
2150 public static String stateToString(int state) {
2151 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002152 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002153 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002154 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002155 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002156 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002157 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002158 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002159 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002160 case STATE_PULLING_CALL:
2161 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002162 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002163 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002164 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002165 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002166 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002167 return "DISCONNECTED";
2168 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002169 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002170 return "UNKNOWN";
2171 }
2172 }
2173
2174 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002175 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002176 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 public final int getConnectionCapabilities() {
2178 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002179 }
2180
2181 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002182 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2183 */
2184 public final int getConnectionProperties() {
2185 return mConnectionProperties;
2186 }
2187
2188 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002189 * Returns the connection's supported audio routes.
2190 *
2191 * @hide
2192 */
2193 public final int getSupportedAudioRoutes() {
2194 return mSupportedAudioRoutes;
2195 }
2196
2197 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002198 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002199 *
Andrew Lee100e2932014-09-08 15:34:24 -07002200 * @param address The new address.
2201 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002202 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002203 */
Andrew Lee100e2932014-09-08 15:34:24 -07002204 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002205 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002206 Log.d(this, "setAddress %s", address);
2207 mAddress = address;
2208 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002209 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002210 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002211 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002212 }
2213
2214 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002215 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002216 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002217 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002218 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002219 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002220 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002221 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002222 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002223 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002224 mCallerDisplayName = callerDisplayName;
2225 mCallerDisplayNamePresentation = presentation;
2226 for (Listener l : mListeners) {
2227 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2228 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002229 }
2230
2231 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002232 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002233 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2234 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2235 * {@link VideoProfile#STATE_TX_ENABLED},
2236 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002237 *
2238 * @param videoState The new video state.
2239 */
2240 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002241 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002242 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002243 mVideoState = videoState;
2244 for (Listener l : mListeners) {
2245 l.onVideoStateChanged(this, mVideoState);
2246 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002247 }
2248
2249 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002250 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002251 * communicate).
2252 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002253 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002254 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002255 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002256 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002257 }
2258
2259 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002260 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002261 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002262 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002263 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002264 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002265 }
2266
2267 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002268 * Sets state to initializing (this Connection is not yet ready to be used).
2269 */
2270 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002271 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002272 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002273 }
2274
2275 /**
2276 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2277 */
2278 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002279 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002280 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002281 }
2282
2283 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002284 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002285 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002286 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002287 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002288 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002289 }
2290
2291 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002292 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2293 * device). Only applicable for {@link Connection}s with
2294 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2295 */
2296 public final void setPulling() {
2297 checkImmutable();
2298 setState(STATE_PULLING_CALL);
2299 }
2300
2301 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002302 * Sets state to be on hold.
2303 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002304 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002305 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002306 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002307 }
2308
2309 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002310 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002311 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002312 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002313 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002314 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002315 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002316 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002317 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002318 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002319 }
2320
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002321 public final VideoProvider getVideoProvider() {
2322 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002323 }
2324
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002325 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002326 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002327 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002328 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002329 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002330 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002331 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002332 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002333 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002334 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002335 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002336 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002337 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002338 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002339 }
2340
2341 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002342 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2343 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2344 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2345 * to send an {@link #onPostDialContinue(boolean)} signal.
2346 *
2347 * @param remaining The DTMF character sequence remaining to be emitted once the
2348 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2349 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002350 */
2351 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002352 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002353 for (Listener l : mListeners) {
2354 l.onPostDialWait(this, remaining);
2355 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002356 }
2357
2358 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002359 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2360 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002361 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002362 *
2363 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002364 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002365 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002366 checkImmutable();
2367 for (Listener l : mListeners) {
2368 l.onPostDialChar(this, nextChar);
2369 }
2370 }
2371
2372 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002373 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002374 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002375 *
2376 * @param ringback Whether the ringback tone is to be played.
2377 */
Andrew Lee100e2932014-09-08 15:34:24 -07002378 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002379 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002380 if (mRingbackRequested != ringback) {
2381 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002382 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002383 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002384 }
2385 }
Ihab Awadf8358972014-05-28 16:46:42 -07002386 }
2387
2388 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002389 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002390 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002391 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002392 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002393 public final void setConnectionCapabilities(int connectionCapabilities) {
2394 checkImmutable();
2395 if (mConnectionCapabilities != connectionCapabilities) {
2396 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002397 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002398 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002399 }
2400 }
Santos Cordonb6939982014-06-04 20:20:58 -07002401 }
2402
2403 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002404 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2405 *
2406 * @param connectionProperties The new connection properties.
2407 */
2408 public final void setConnectionProperties(int connectionProperties) {
2409 checkImmutable();
2410 if (mConnectionProperties != connectionProperties) {
2411 mConnectionProperties = connectionProperties;
2412 for (Listener l : mListeners) {
2413 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2414 }
2415 }
2416 }
2417
2418 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002419 * Sets the supported audio routes.
2420 *
2421 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2422 * See {@link CallAudioState}
2423 * @hide
2424 */
2425 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2426 if ((supportedAudioRoutes
2427 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2428 throw new IllegalArgumentException(
2429 "supported audio routes must include either speaker or earpiece");
2430 }
2431
2432 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2433 mSupportedAudioRoutes = supportedAudioRoutes;
2434 for (Listener l : mListeners) {
2435 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2436 }
2437 }
2438 }
2439
2440 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002441 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002442 */
Evan Charlton36a71342014-07-19 16:31:02 -07002443 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002444 for (Listener l : mListeners) {
2445 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002446 }
Santos Cordonb6939982014-06-04 20:20:58 -07002447 }
2448
2449 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002450 * Requests that the framework use VOIP audio mode for this connection.
2451 *
2452 * @param isVoip True if the audio mode is VOIP.
2453 */
2454 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002455 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002456 mAudioModeIsVoip = isVoip;
2457 for (Listener l : mListeners) {
2458 l.onAudioModeIsVoipChanged(this, isVoip);
2459 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002460 }
2461
2462 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002463 * Sets the time at which a call became active on this Connection. This is set only
2464 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002465 * <p>
2466 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002467 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002468 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2469 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002470 *
2471 * @hide
2472 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002473 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002474 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002475 public final void setConnectTimeMillis(long connectTimeMillis) {
2476 mConnectTimeMillis = connectTimeMillis;
2477 }
2478
2479 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002480 * Sets the time at which a call became active on this Connection. This is set only
2481 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002482 * <p>
2483 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002484 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2485 * {@link SystemClock#elapsedRealtime()}.
2486 *
2487 * @hide
2488 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002489 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002490 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002491 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002492 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2493 }
2494
2495 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002496 * Sets the label and icon status to display in the in-call UI.
2497 *
2498 * @param statusHints The status label and icon to set.
2499 */
2500 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002501 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002502 mStatusHints = statusHints;
2503 for (Listener l : mListeners) {
2504 l.onStatusHintsChanged(this, statusHints);
2505 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002506 }
2507
2508 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002509 * Sets the connections with which this connection can be conferenced.
2510 *
2511 * @param conferenceableConnections The set of connections this connection can conference with.
2512 */
2513 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002514 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002515 clearConferenceableList();
2516 for (Connection c : conferenceableConnections) {
2517 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2518 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002519 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002520 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002521 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002522 }
2523 }
2524 fireOnConferenceableConnectionsChanged();
2525 }
2526
2527 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002528 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2529 * or conferences with which this connection can be conferenced.
2530 *
2531 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002532 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002533 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002534 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002535 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002536 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2537 // small amount of items here.
2538 if (!mConferenceables.contains(c)) {
2539 if (c instanceof Connection) {
2540 Connection connection = (Connection) c;
2541 connection.addConnectionListener(mConnectionDeathListener);
2542 } else if (c instanceof Conference) {
2543 Conference conference = (Conference) c;
2544 conference.addListener(mConferenceDeathListener);
2545 }
2546 mConferenceables.add(c);
2547 }
2548 }
2549 fireOnConferenceableConnectionsChanged();
2550 }
2551
2552 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002553 * Resets the CDMA connection time.
2554 * <p>
2555 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002556 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002557 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002558 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002559 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002560 public final void resetConnectionTime() {
2561 for (Listener l : mListeners) {
2562 l.onConnectionTimeReset(this);
2563 }
2564 }
2565
2566 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002567 * Returns the connections or conferences with which this connection can be conferenced.
2568 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002569 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002570 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002571 }
2572
Yorke Lee53463962015-08-04 16:07:19 -07002573 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002574 * @hide
2575 */
2576 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002577 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002578 if (mConnectionService != null) {
2579 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2580 "which is already associated with another ConnectionService.");
2581 } else {
2582 mConnectionService = connectionService;
2583 }
2584 }
2585
2586 /**
2587 * @hide
2588 */
2589 public final void unsetConnectionService(ConnectionService connectionService) {
2590 if (mConnectionService != connectionService) {
2591 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2592 "that does not belong to the ConnectionService.");
2593 } else {
2594 mConnectionService = null;
2595 }
2596 }
2597
2598 /**
2599 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002600 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002601 *
2602 * @param conference The conference.
2603 * @return {@code true} if the conference was successfully set.
2604 * @hide
2605 */
2606 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002607 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002608 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002609 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002610 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002611 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2612 fireConferenceChanged();
2613 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002614 return true;
2615 }
2616 return false;
2617 }
2618
2619 /**
2620 * Resets the conference that this connection is a part of.
2621 * @hide
2622 */
2623 public final void resetConference() {
2624 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002625 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002626 mConference = null;
2627 fireConferenceChanged();
2628 }
2629 }
2630
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002631 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002632 * Set some extras that can be associated with this {@code Connection}.
2633 * <p>
2634 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2635 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2636 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002637 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2638 * {@link #removeExtras(String...)} methods to modify the extras.
2639 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002640 * 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 -07002641 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2642 *
2643 * @param extras The extras associated with this {@code Connection}.
2644 */
2645 public final void setExtras(@Nullable Bundle extras) {
2646 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002647
2648 // Add/replace any new or changed extras values.
2649 putExtras(extras);
2650
2651 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2652 // the current one and remove any keys that went away.
2653 if (mPreviousExtraKeys != null) {
2654 List<String> toRemove = new ArrayList<String>();
2655 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002656 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002657 toRemove.add(oldKey);
2658 }
2659 }
2660 if (!toRemove.isEmpty()) {
2661 removeExtras(toRemove);
2662 }
2663 }
2664
2665 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2666 // called we can see if the caller has removed any extras values.
2667 if (mPreviousExtraKeys == null) {
2668 mPreviousExtraKeys = new ArraySet<String>();
2669 }
2670 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002671 if (extras != null) {
2672 mPreviousExtraKeys.addAll(extras.keySet());
2673 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002674 }
2675
2676 /**
2677 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2678 * added.
2679 * <p>
2680 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2681 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2682 *
2683 * @param extras The extras to add.
2684 */
2685 public final void putExtras(@NonNull Bundle extras) {
2686 checkImmutable();
2687 if (extras == null) {
2688 return;
2689 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002690 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2691 // the listeners.
2692 Bundle listenerExtras;
2693 synchronized (mExtrasLock) {
2694 if (mExtras == null) {
2695 mExtras = new Bundle();
2696 }
2697 mExtras.putAll(extras);
2698 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002699 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002700 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002701 // Create a new clone of the extras for each listener so that they don't clobber
2702 // each other
2703 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002704 }
2705 }
2706
2707 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002708 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002709 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002710 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002711 */
2712 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002713 synchronized (mExtrasLock) {
2714 if (mExtras != null) {
2715 for (String key : keys) {
2716 mExtras.remove(key);
2717 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002718 }
2719 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002720 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002721 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002722 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002723 }
2724 }
2725
2726 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002727 * Removes extras from this {@code Connection}.
2728 *
2729 * @param keys The keys of the extras to remove.
2730 */
2731 public final void removeExtras(String ... keys) {
2732 removeExtras(Arrays.asList(keys));
2733 }
2734
2735 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002736 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2737 * be change to the {@link #getCallAudioState()}.
2738 * <p>
2739 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2740 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2741 * <p>
2742 * See also {@link InCallService#setAudioRoute(int)}.
2743 *
2744 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2745 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2746 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2747 */
2748 public final void setAudioRoute(int route) {
2749 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002750 l.onAudioRouteChanged(this, route, null);
2751 }
2752 }
2753
2754 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002755 * Request audio routing to a specific bluetooth device. Calling this method may result in
2756 * the device routing audio to a different bluetooth device than the one specified if the
2757 * bluetooth stack is unable to route audio to the requested device.
2758 * A list of available devices can be obtained via
2759 * {@link CallAudioState#getSupportedBluetoothDevices()}
2760 *
2761 * <p>
2762 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2763 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2764 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002765 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2766 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002767 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002768 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002769 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002770 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2771 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002772 }
2773 }
2774
2775 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002776 * Informs listeners that a previously requested RTT session via
2777 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002778 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002779 */
2780 public final void sendRttInitiationSuccess() {
2781 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2782 }
2783
2784 /**
2785 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002786 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002787 * has failed.
2788 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2789 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002790 */
2791 public final void sendRttInitiationFailure(int reason) {
2792 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2793 }
2794
2795 /**
2796 * Informs listeners that a currently active RTT session has been terminated by the remote
2797 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002798 */
2799 public final void sendRttSessionRemotelyTerminated() {
2800 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2801 }
2802
2803 /**
2804 * Informs listeners that the remote side of the call has requested an upgrade to include an
2805 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002806 */
2807 public final void sendRemoteRttRequest() {
2808 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2809 }
2810
2811 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002812 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002813 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002814 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002815 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2816 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002817 */
Yorke Lee4af59352015-05-13 14:14:54 -07002818 @SystemApi
2819 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002820 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002821
2822 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002823 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2824 *
2825 * @param state The new connection audio state.
2826 */
2827 public void onCallAudioStateChanged(CallAudioState state) {}
2828
2829 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002830 * Notifies this Connection of an internal state change. This method is called after the
2831 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002832 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002833 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002834 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002835 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002836
2837 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002838 * Notifies this Connection of a request to play a DTMF tone.
2839 *
2840 * @param c A DTMF character.
2841 */
Santos Cordonf2951102014-07-20 19:06:29 -07002842 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002843
2844 /**
2845 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2846 */
Santos Cordonf2951102014-07-20 19:06:29 -07002847 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002848
2849 /**
2850 * Notifies this Connection of a request to disconnect.
2851 */
Santos Cordonf2951102014-07-20 19:06:29 -07002852 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002853
2854 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002855 * Notifies this Connection of a request to disconnect a participant of the conference managed
2856 * by the connection.
2857 *
2858 * @param endpoint the {@link Uri} of the participant to disconnect.
2859 * @hide
2860 */
2861 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2862
2863 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002864 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002865 */
Santos Cordonf2951102014-07-20 19:06:29 -07002866 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002867
2868 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002869 * Notifies this Connection of a request to abort.
2870 */
Santos Cordonf2951102014-07-20 19:06:29 -07002871 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002872
2873 /**
2874 * Notifies this Connection of a request to hold.
2875 */
Santos Cordonf2951102014-07-20 19:06:29 -07002876 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002877
2878 /**
2879 * Notifies this Connection of a request to exit a hold state.
2880 */
Santos Cordonf2951102014-07-20 19:06:29 -07002881 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002882
2883 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002884 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002885 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002886 * <p>
2887 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2888 * the default dialer's {@link InCallService}.
2889 * <p>
2890 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2891 * Telecom framework may request that the call is answered in the following circumstances:
2892 * <ul>
2893 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2894 * <li>A car mode {@link InCallService} is in use which has declared
2895 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2896 * {@link InCallService} will be able to see calls from self-managed
2897 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2898 * behalf.</li>
2899 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002900 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002901 */
Santos Cordonf2951102014-07-20 19:06:29 -07002902 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002903
2904 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002905 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002906 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002907 * <p>
2908 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2909 * the default dialer's {@link InCallService}.
2910 * <p>
2911 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2912 * Telecom framework may request that the call is answered in the following circumstances:
2913 * <ul>
2914 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2915 * <li>A car mode {@link InCallService} is in use which has declared
2916 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2917 * {@link InCallService} will be able to see calls from self-managed
2918 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2919 * behalf.</li>
2920 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002921 */
2922 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002923 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002924 }
2925
2926 /**
2927 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302928 * a request to deflect.
2929 */
2930 public void onDeflect(Uri address) {}
2931
2932 /**
2933 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002934 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002935 * <p>
2936 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2937 * the default dialer's {@link InCallService}.
2938 * <p>
2939 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2940 * Telecom framework may request that the call is rejected in the following circumstances:
2941 * <ul>
2942 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2943 * <li>A car mode {@link InCallService} is in use which has declared
2944 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2945 * {@link InCallService} will be able to see calls from self-managed
2946 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2947 * behalf.</li>
2948 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002949 */
Santos Cordonf2951102014-07-20 19:06:29 -07002950 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002951
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002952 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002953 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2954 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002955 */
2956 public void onReject(String replyMessage) {}
2957
2958 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002959 * Notifies this Connection of a request to silence the ringer.
2960 * <p>
2961 * The ringer may be silenced by any of the following methods:
2962 * <ul>
2963 * <li>{@link TelecomManager#silenceRinger()}</li>
2964 * <li>The user presses the volume-down button while a call is ringing.</li>
2965 * </ul>
2966 * <p>
2967 * Self-managed {@link ConnectionService} implementations should override this method in their
2968 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2969 * your app set the ringtone as part of the incoming call {@link Notification} (see
2970 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2971 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2972 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2973 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002974 */
2975 public void onSilence() {}
2976
2977 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002978 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2979 */
Santos Cordonf2951102014-07-20 19:06:29 -07002980 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002981
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002982 /**
2983 * Notifies this Connection of a request to pull an external call to the local device.
2984 * <p>
2985 * The {@link InCallService} issues a request to pull an external call to the local device via
2986 * {@link Call#pullExternalCall()}.
2987 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002988 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2989 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002990 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002991 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002992 */
2993 public void onPullExternalCall() {}
2994
2995 /**
2996 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2997 * <p>
2998 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2999 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003000 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3001 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3002 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3003 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3004 * not aware of.
3005 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003006 * See also {@link Call#sendCallEvent(String, Bundle)}.
3007 *
3008 * @param event The call event.
3009 * @param extras Extras associated with the call event.
3010 */
3011 public void onCallEvent(String event, Bundle extras) {}
3012
Tyler Gunndee56a82016-03-23 16:06:34 -07003013 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003014 * Notifies this {@link Connection} that a handover has completed.
3015 * <p>
3016 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3017 * Bundle)} on the initiating side of the handover, and
3018 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3019 */
3020 public void onHandoverComplete() {}
3021
3022 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003023 * Notifies this {@link Connection} of a change to the extras made outside the
3024 * {@link ConnectionService}.
3025 * <p>
3026 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3027 * the {@link android.telecom.Call#putExtras(Bundle)} and
3028 * {@link Call#removeExtras(List)}.
3029 *
3030 * @param extras The new extras bundle.
3031 */
3032 public void onExtrasChanged(Bundle extras) {}
3033
Tyler Gunnf5035432017-01-09 09:43:12 -08003034 /**
3035 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3036 * displaying its incoming call user interface for the {@link Connection}.
3037 * <p>
3038 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3039 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3040 * should show its own incoming call user interface.
3041 * <p>
3042 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003043 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3044 * Telecom framework will display its own incoming call user interface to allow the user to
3045 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3046 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003047 * <p>
3048 * You should trigger the display of the incoming call user interface for your application by
3049 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003050 *
3051 * In your application code, you should create a {@link android.app.NotificationChannel} for
3052 * incoming call notifications from your app:
3053 * <pre><code>
3054 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3055 * NotificationManager.IMPORTANCE_MAX);
3056 * // other channel setup stuff goes here.
3057 *
3058 * // We'll use the default system ringtone for our incoming call notification channel. You can
3059 * // use your own audio resource here.
3060 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3061 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3062 * // Setting the AudioAttributes is important as it identifies the purpose of your
3063 * // notification sound.
3064 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3065 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3066 * .build());
3067 *
3068 * NotificationManager mgr = getSystemService(NotificationManager.class);
3069 * mgr.createNotificationChannel(channel);
3070 * </code></pre>
3071 * When it comes time to post a notification for your incoming call, ensure it uses your
3072 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003073 * <pre><code>
3074 * // Create an intent which triggers your fullscreen incoming call user interface.
3075 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3076 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3077 * intent.setClass(context, YourIncomingCallActivity.class);
3078 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3079 *
3080 * // Build the notification as an ongoing high priority item; this ensures it will show as
3081 * // a heads up notification which slides down over top of the current content.
3082 * final Notification.Builder builder = new Notification.Builder(context);
3083 * builder.setOngoing(true);
3084 * builder.setPriority(Notification.PRIORITY_HIGH);
3085 *
3086 * // Set notification content intent to take user to fullscreen UI if user taps on the
3087 * // notification body.
3088 * builder.setContentIntent(pendingIntent);
3089 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3090 * // manager deems it appropriate.
3091 * builder.setFullScreenIntent(pendingIntent, true);
3092 *
3093 * // Setup notification content.
3094 * builder.setSmallIcon( yourIconResourceId );
3095 * builder.setContentTitle("Your notification title");
3096 * builder.setContentText("Your notification content.");
3097 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003098 * // Set notification as insistent to cause your ringtone to loop.
3099 * Notification notification = builder.build();
3100 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003101 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003102 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003103 * NotificationManager notificationManager = mContext.getSystemService(
3104 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003105 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003106 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003107 */
3108 public void onShowIncomingCallUi() {}
3109
Hall Liub64ac4c2017-02-06 10:49:48 -08003110 /**
3111 * Notifies this {@link Connection} that the user has requested an RTT session.
3112 * The connection service should call {@link #sendRttInitiationSuccess} or
3113 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3114 * request, respectively.
3115 * @param rttTextStream The object that should be used to send text to or receive text from
3116 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003117 */
3118 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3119
3120 /**
3121 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3122 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003123 */
3124 public void onStopRtt() {}
3125
3126 /**
3127 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3128 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3129 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3130 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003131 * @param rttTextStream The object that should be used to send text to or receive text from
3132 * the in-call app.
3133 */
3134 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3135
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003136 static String toLogSafePhoneNumber(String number) {
3137 // For unknown number, log empty string.
3138 if (number == null) {
3139 return "";
3140 }
3141
3142 if (PII_DEBUG) {
3143 // When PII_DEBUG is true we emit PII.
3144 return number;
3145 }
3146
3147 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3148 // sanitized phone numbers.
3149 StringBuilder builder = new StringBuilder();
3150 for (int i = 0; i < number.length(); i++) {
3151 char c = number.charAt(i);
3152 if (c == '-' || c == '@' || c == '.') {
3153 builder.append(c);
3154 } else {
3155 builder.append('x');
3156 }
3157 }
3158 return builder.toString();
3159 }
3160
Ihab Awad542e0ea2014-05-16 10:22:16 -07003161 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003162 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003163 if (mState == STATE_DISCONNECTED && mState != state) {
3164 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003165 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003166 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003167 if (mState != state) {
3168 Log.d(this, "setState: %s", stateToString(state));
3169 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003170 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003171 for (Listener l : mListeners) {
3172 l.onStateChanged(this, state);
3173 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003174 }
3175 }
3176
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003177 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003178 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003179 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3180 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003181 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003182 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003183
3184 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003185 if (mImmutable) {
3186 throw new UnsupportedOperationException("Connection is immutable");
3187 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003188 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003189 }
3190
Evan Charltonbf11f982014-07-20 22:06:28 -07003191 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003192 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003193 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3194 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003195 * <p>
3196 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3197 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003198 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003199 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003200 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003201 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003202 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3203 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003204 }
3205
Evan Charltonbf11f982014-07-20 22:06:28 -07003206 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003207 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3208 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3209 * this should never be un-@hide-den.
3210 *
3211 * @hide
3212 */
3213 public void checkImmutable() {}
3214
3215 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003216 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3217 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3218 * that state. This connection should not be used for anything, and no other
3219 * {@code Connection}s should be attempted.
3220 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003221 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003222 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003223 * @return A {@code Connection} which indicates that the underlying connection should
3224 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003225 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003226 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003227 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003228 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003229
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003230 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003231 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003232 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003233 }
3234 }
3235
Santos Cordon823fd3c2014-08-07 18:35:18 -07003236 private final void fireConferenceChanged() {
3237 for (Listener l : mListeners) {
3238 l.onConferenceChanged(this, mConference);
3239 }
3240 }
3241
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003242 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003243 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003244 if (c instanceof Connection) {
3245 Connection connection = (Connection) c;
3246 connection.removeConnectionListener(mConnectionDeathListener);
3247 } else if (c instanceof Conference) {
3248 Conference conference = (Conference) c;
3249 conference.removeListener(mConferenceDeathListener);
3250 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003251 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003252 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003253 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003254
3255 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003256 * Handles a change to extras received from Telecom.
3257 *
3258 * @param extras The new extras.
3259 * @hide
3260 */
3261 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003262 Bundle b = null;
3263 synchronized (mExtrasLock) {
3264 mExtras = extras;
3265 if (mExtras != null) {
3266 b = new Bundle(mExtras);
3267 }
3268 }
3269 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003270 }
3271
3272 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003273 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3274 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003275 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003276 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003277 for (Listener l : mListeners) {
3278 l.onConferenceMergeFailed(this);
3279 }
3280 }
3281
3282 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303283 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3284 * changed due to an emergency call being redialed.
3285 * @param pHandle The new PhoneAccountHandle for this connection.
3286 * @hide
3287 */
3288 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3289 for (Listener l : mListeners) {
3290 l.onPhoneAccountChanged(this, pHandle);
3291 }
3292 }
3293
3294 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003295 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003296 * <p>
3297 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3298 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003299 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003300 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003301 * @hide
3302 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003303 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003304 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003305 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003306 if (mPhoneAccountHandle != phoneAccountHandle) {
3307 mPhoneAccountHandle = phoneAccountHandle;
3308 notifyPhoneAccountChanged(phoneAccountHandle);
3309 }
3310 }
3311
3312 /**
3313 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003314 * <p>
3315 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3316 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003317 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003318 * @return the phone account handle specified via
3319 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003320 * @hide
3321 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003322 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003323 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003324 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003325 return mPhoneAccountHandle;
3326 }
3327
3328 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003329 * Sends an event associated with this {@code Connection} with associated event extras to the
3330 * {@link InCallService}.
3331 * <p>
3332 * Connection events are used to communicate point in time information from a
3333 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3334 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3335 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3336 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3337 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3338 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3339 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3340 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3341 * <p>
3342 * Events are exposed to {@link InCallService} implementations via
3343 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3344 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003345 * 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 -07003346 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3347 * some events altogether.
3348 * <p>
3349 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3350 * conflicts between {@link ConnectionService} implementations. Further, custom
3351 * {@link ConnectionService} implementations shall not re-purpose events in the
3352 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3353 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3354 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3355 * {@code com.example.extra.MY_EXTRA}).
3356 * <p>
3357 * When defining events and the associated extras, it is important to keep their behavior
3358 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3359 * events/extras should me maintained to ensure backwards compatibility with older
3360 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003361 *
3362 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003363 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003364 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003365 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003366 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003367 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003368 }
3369 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003370
3371 /**
3372 * @return The direction of the call.
3373 * @hide
3374 */
3375 public final @Call.Details.CallDirection int getCallDirection() {
3376 return mCallDirection;
3377 }
3378
3379 /**
3380 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003381 * <p>
3382 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3383 * call direction.
3384 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003385 * @param callDirection The direction of this connection.
3386 * @hide
3387 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003388 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003389 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003390 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3391 mCallDirection = callDirection;
3392 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003393
3394 /**
3395 * Gets the verification status for the phone number of an incoming call as identified in
3396 * ATIS-1000082.
3397 * @return the verification status.
3398 */
3399 public @VerificationStatus int getCallerNumberVerificationStatus() {
3400 return mCallerNumberVerificationStatus;
3401 }
3402
3403 /**
3404 * Sets the verification status for the phone number of an incoming call as identified in
3405 * ATIS-1000082.
3406 * <p>
3407 * This property can only be set at the time of creation of a {@link Connection} being returned
3408 * by
3409 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3410 */
3411 public void setCallerNumberVerificationStatus(
3412 @VerificationStatus int callerNumberVerificationStatus) {
3413 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3414 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003415}