blob: 4c22ba9715b0a356ab4d91235d69637792859c4e [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070021import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070022import android.annotation.TestApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010023import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080024import android.app.Notification;
Hall Liua98f58b2017-11-07 17:59:28 -080025import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070027import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080029import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070030import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Handler;
32import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070033import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080035import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070037import android.os.SystemClock;
Chen Xub6d13192019-10-02 00:20:43 -070038import android.telephony.Annotation.RilRadioTechnology;
Wei Huang7f7f72e2018-05-30 19:21:36 +080039import android.telephony.ServiceState;
40import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070041import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
Youming Yed6de26e2019-01-30 11:20:35 -080044import com.android.internal.os.SomeArgs;
45import com.android.internal.telecom.IVideoCallback;
46import com.android.internal.telecom.IVideoProvider;
47
Hall Liua549fed2018-02-09 16:40:03 -080048import java.io.FileInputStream;
49import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080050import java.io.IOException;
51import java.io.InputStreamReader;
52import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070053import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070054import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070055import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070056import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070057import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070058import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070059import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070060
61/**
Santos Cordon895d4b82015-06-25 16:41:48 -070062 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
63 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070064 * <p>
65 * Implementations create a custom subclass of {@code Connection} and return it to the framework
66 * as the return value of
67 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
68 * or
69 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
70 * Implementations are then responsible for updating the state of the {@code Connection}, and
71 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
72 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070073 * <p>
74 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
75 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
76 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
77 * {@code Connection} instance.
78 * <p>
79 * Basic call support requires overriding the following methods: {@link #onAnswer()},
80 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
81 * <p>
82 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
83 * {@link #onUnhold()} methods should be overridden to provide hold support for the
84 * {@code Connection}.
85 * <p>
86 * Where a {@code Connection} supports a variation of video calling (e.g. the
87 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
88 * to support answering a call as a video call.
89 * <p>
90 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
91 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
92 * support for pulling the external call.
93 * <p>
94 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
95 * overridden.
96 * <p>
97 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
98 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
99 * for example, call events from a {@link InCallService} are handled,
100 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
101 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
102 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
103 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700104 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700105public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700106
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 /**
108 * The connection is initializing. This is generally the first state for a {@code Connection}
109 * returned by a {@link ConnectionService}.
110 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700111 public static final int STATE_INITIALIZING = 0;
112
Santos Cordon895d4b82015-06-25 16:41:48 -0700113 /**
114 * The connection is new and not connected.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_NEW = 1;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * An incoming connection is in the ringing state. During this state, the user's ringer or
120 * vibration feature will be activated.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_RINGING = 2;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * An outgoing connection is in the dialing state. In this state the other party has not yet
126 * answered the call and the user traditionally hears a ringback tone.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_DIALING = 3;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * A connection is active. Both parties are connected to the call and can actively communicate.
132 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 public static final int STATE_ACTIVE = 4;
134
Santos Cordon895d4b82015-06-25 16:41:48 -0700135 /**
136 * A connection is on hold.
137 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 public static final int STATE_HOLDING = 5;
139
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 /**
141 * A connection has been disconnected. This is the final state once the user has been
142 * disconnected from a call either locally, remotely or by an error in the service.
143 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 public static final int STATE_DISCONNECTED = 6;
145
Santos Cordon895d4b82015-06-25 16:41:48 -0700146 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700147 * The state of an external connection which is in the process of being pulled from a remote
148 * device to the local device.
149 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700150 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700151 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
152 */
153 public static final int STATE_PULLING_CALL = 7;
154
155 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700156 * Connection can currently be put on hold or unheld. This is distinct from
157 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
158 * it does not at the moment support the function. This can be true while the call is in the
159 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
160 * display a disabled 'hold' button.
161 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 public static final int CAPABILITY_HOLD = 0x00000001;
163
164 /** Connection supports the hold feature. */
165 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
166
167 /**
168 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
169 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
170 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
171 * capability allows a merge button to be shown while the conference is in the foreground
172 * of the in-call UI.
173 * <p>
174 * This is only intended for use by a {@link Conference}.
175 */
176 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
177
178 /**
179 * Connections within a conference can be swapped between foreground and background.
180 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
181 * <p>
182 * This is only intended for use by a {@link Conference}.
183 */
184 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
185
186 /**
187 * @hide
188 */
189 public static final int CAPABILITY_UNUSED = 0x00000010;
190
191 /** Connection supports responding via text option. */
192 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
193
194 /** Connection can be muted. */
195 public static final int CAPABILITY_MUTE = 0x00000040;
196
197 /**
198 * Connection supports conference management. This capability only applies to
199 * {@link Conference}s which can have {@link Connection}s as children.
200 */
201 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
202
203 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207
208 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212
213 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800215 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700216 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800218
219 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800221 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700222 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
223
224 /**
225 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 */
227 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
228
229 /**
230 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700232 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700233 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800234
235 /**
236 * Connection is able to be separated from its parent {@code Conference}, if any.
237 */
238 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
239
240 /**
241 * Connection is able to be individually disconnected when in a {@code Conference}.
242 */
243 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
244
245 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247 * @hide
248 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800250
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * @hide
254 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256
257 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700259 * @hide
260 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700261 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262
Tyler Gunn068085b2015-02-06 13:56:52 -0800263 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700264 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800265 * @hide
266 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700267 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800268
Tyler Gunn96d6c402015-03-18 12:39:23 -0700269 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500270 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700271 * <p>
272 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
273 * place as soon as the device answers the call, but prior to it being connected. This is an
274 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500275 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700276 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700277 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700278 @TestApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700279 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800280
Rekha Kumar07366812015-03-24 16:42:31 -0700281 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700282 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800283 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
284 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
285 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700286 */
287 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
288
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700289 /**
290 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700291 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700292 */
293 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
294
Tyler Gunnd4091732015-06-29 09:15:37 -0700295 /**
296 * For a conference, indicates the conference will not have child connections.
297 * <p>
298 * An example of a conference with child connections is a GSM conference call, where the radio
299 * retains connections to the individual participants of the conference. Another example is an
300 * IMS conference call where conference event package functionality is supported; in this case
301 * the conference server ensures the radio is aware of the participants in the conference, which
302 * are represented by child connections.
303 * <p>
304 * An example of a conference with no child connections is an IMS conference call with no
305 * conference event package support. Such a conference is represented by the radio as a single
306 * connection to the IMS conference server.
307 * <p>
308 * Indicating whether a conference has children or not is important to help user interfaces
309 * visually represent a conference. A conference with no children, for example, will have the
310 * conference connection shown in the list of calls on a Bluetooth device, where if the
311 * conference has children, only the children will be shown in the list of calls on a Bluetooth
312 * device.
313 * @hide
314 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700315 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700316 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700317 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
318
Bryce Lee81901682015-08-28 16:38:02 -0700319 /**
320 * Indicates that the connection itself wants to handle any sort of reply response, rather than
321 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700322 */
323 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
324
Tyler Gunnf97a0092016-01-19 15:59:34 -0800325 /**
326 * When set, prevents a video call from being downgraded to an audio-only call.
327 * <p>
328 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
329 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
330 * downgraded from a video call back to a VideoState of
331 * {@link VideoProfile#STATE_AUDIO_ONLY}.
332 * <p>
333 * Intuitively, a call which can be downgraded to audio should also have local and remote
334 * video
335 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
336 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
337 */
338 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
339
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700340 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700341 * When set for an external connection, indicates that this {@code Connection} can be pulled
342 * from a remote device to the current device.
343 * <p>
344 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
345 * is set.
346 */
347 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
348
Pooja Jaind34698d2017-12-28 14:15:31 +0530349 /** Call supports the deflect feature. */
350 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
351
Tyler Gunn720c6642016-03-22 09:02:47 -0700352 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530353 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700354 //**********************************************************************************************
355
356 /**
357 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700358 * <p>
359 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700360 * @hide
361 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700362 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700363 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700364 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700365
366 /**
367 * Whether the call is a generic conference, where we do not know the precise state of
368 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700369 * <p>
370 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700371 * @hide
372 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700373 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700374 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700375 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
376
377 /**
378 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700379 * <p>
380 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
381 * implies something like AMR wideband, but the interpretation of when a call is considered high
382 * definition is left to the {@link ConnectionService} to decide.
383 * <p>
384 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700385 */
386 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
387
388 /**
389 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700390 * <p>
391 * Used to indicate that a call is taking place over WIFI versus a carrier network.
392 * <p>
393 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700394 */
395 public static final int PROPERTY_WIFI = 1<<3;
396
397 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700398 * When set, indicates that the {@code Connection} does not actually exist locally for the
399 * {@link ConnectionService}.
400 * <p>
401 * Consider, for example, a scenario where a user has two devices with the same phone number.
402 * When a user places a call on one devices, the telephony stack can represent that call on the
403 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700404 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700405 * <p>
406 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
407 * external connections. Only those {@link InCallService}s which have the
408 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
409 * manifest will see external connections.
410 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700411 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700412
Brad Ebinger15847072016-05-18 11:08:36 -0700413 /**
414 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
415 */
416 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700417
Hall Liu9f332c72016-07-14 15:37:37 -0700418 /**
419 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700420 * <p>
421 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
422 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700423 * @hide
424 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700425 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700426 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700427 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
428
Tyler Gunnf5035432017-01-09 09:43:12 -0800429 /**
430 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
431 * {@link ConnectionService}.
432 * <p>
433 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
434 */
435 public static final int PROPERTY_SELF_MANAGED = 1<<7;
436
Hall Liu95d55872017-01-25 17:12:49 -0800437 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800438 * Set by the framework to indicate that a connection has an active RTT session associated with
439 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800440 */
441 public static final int PROPERTY_IS_RTT = 1 << 8;
442
Eric Erfanian62706c52017-12-06 16:27:53 -0800443 /**
444 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700445 * <p>
446 * This is used for outgoing calls.
447 *
448 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800449 */
450 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
451
Tyler Gunn5bd90852018-09-21 09:37:07 -0700452 /**
453 * Set by the framework to indicate that the network has identified a Connection as an emergency
454 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700455 * <p>
456 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
457 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700458 */
459 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
460
Tyler Gunnac60f952019-05-31 07:23:16 -0700461 /**
462 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
463 * than the current one. Used in scenarios where the conference originator is the remote device
464 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700465 * <p>
466 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700467 * @hide
468 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700469 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700470 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700471 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
472
Tyler Gunn96d6c402015-03-18 12:39:23 -0700473 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700474 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700475 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800476
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700477 /**
478 * Connection extra key used to store the last forwarded number associated with the current
479 * connection. Used to communicate to the user interface that the connection was forwarded via
480 * the specified number.
481 */
482 public static final String EXTRA_LAST_FORWARDED_NUMBER =
483 "android.telecom.extra.LAST_FORWARDED_NUMBER";
484
485 /**
486 * Connection extra key used to store a child number associated with the current connection.
487 * Used to communicate to the user interface that the connection was received via
488 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
489 * address.
490 */
491 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
492
493 /**
494 * Connection extra key used to store the subject for an incoming call. The user interface can
495 * query this extra and display its contents for incoming calls. Will only be used if the
496 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
497 */
498 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
499
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800500 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700501 * Boolean connection extra key set on a {@link Connection} in
502 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
503 * current active foreground call to be dropped.
504 */
505 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
506 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
507
508 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700509 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
510 * state to indicate the name of the third-party app which is responsible for the current
511 * foreground call.
512 * <p>
513 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
514 * is able to inform the user that answering the new incoming call will cause a call owned by
515 * another app to be dropped when the incoming call is answered.
516 */
517 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
518 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
519
520 /**
Hall Liu10208662016-06-15 17:55:00 -0700521 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700522 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700523 * <p>
524 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
525 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700526 * @hide
527 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700528 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700529 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700530 public static final String EXTRA_DISABLE_ADD_CALL =
531 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700532
533 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700534 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
535 * original Connection ID associated with the connection. Used in
536 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
537 * connection/conference added via
538 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
539 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
540 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
541 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
542 * be a way to ensure that we don't add the connection again as a duplicate.
543 * <p>
544 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
545 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
546 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
547 * in a new {@link Connection} which it adds to Telecom via
548 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
549 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
550 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
551 * ID it originally referred to the connection as. Thus Telecom needs to know that the
552 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700553 * <p>
554 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
555 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700556 * @hide
557 */
558 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
559 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
560
561 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700562 * Boolean connection extra key set on the extras passed to
563 * {@link Connection#sendConnectionEvent} which indicates that audio is present
564 * on the RTT call when the extra value is true.
565 */
566 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
567 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
568
569 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800570 * Connection event used to inform Telecom that it should play the on hold tone. This is used
571 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700572 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800573 */
574 public static final String EVENT_ON_HOLD_TONE_START =
575 "android.telecom.event.ON_HOLD_TONE_START";
576
577 /**
578 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
579 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700580 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800581 */
582 public static final String EVENT_ON_HOLD_TONE_END =
583 "android.telecom.event.ON_HOLD_TONE_END";
584
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700585 /**
586 * Connection event used to inform {@link InCallService}s when pulling of an external call has
587 * failed. The user interface should inform the user of the error.
588 * <p>
589 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
590 * API is called on a {@link Call} with the properties
591 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
592 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
593 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700594 * <p>
595 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
596 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700597 */
598 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
599
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700600 /**
601 * Connection event used to inform {@link InCallService}s when the merging of two calls has
602 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700603 * <p>
604 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
605 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700606 */
607 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
608
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700609 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700610 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700611 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700612 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
613 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700614 */
615 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
616
617 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700618 * Connection event used to inform {@link InCallService}s when the process of merging a
619 * Connection into a conference has begun.
620 * <p>
621 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
622 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700623 */
624 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
625
626 /**
627 * Connection event used to inform {@link InCallService}s when the process of merging a
628 * Connection into a conference has completed.
629 * <p>
630 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
631 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700632 */
633 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
634
635 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700636 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
637 * the remote party.
638 * <p>
639 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
640 * call is being held locally on the device. When a capable {@link ConnectionService} receives
641 * signalling to indicate that the remote party has put the call on hold, it can send this
642 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700643 */
644 public static final String EVENT_CALL_REMOTELY_HELD =
645 "android.telecom.event.CALL_REMOTELY_HELD";
646
647 /**
648 * Connection event used to inform {@link InCallService}s when a call which was remotely held
649 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
650 * <p>
651 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
652 * call is being held locally on the device. When a capable {@link ConnectionService} receives
653 * signalling to indicate that the remote party has taken the call off hold, it can send this
654 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700655 */
656 public static final String EVENT_CALL_REMOTELY_UNHELD =
657 "android.telecom.event.CALL_REMOTELY_UNHELD";
658
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700659 /**
660 * Connection event used to inform an {@link InCallService} which initiated a call handover via
661 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
662 * successfully completed.
663 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700664 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
665 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700666 */
667 public static final String EVENT_HANDOVER_COMPLETE =
668 "android.telecom.event.HANDOVER_COMPLETE";
669
670 /**
671 * Connection event used to inform an {@link InCallService} which initiated a call handover via
672 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
673 * to complete.
674 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700675 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
676 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700677 */
678 public static final String EVENT_HANDOVER_FAILED =
679 "android.telecom.event.HANDOVER_FAILED";
680
shilub7ec9a02018-11-09 15:52:04 -0800681 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000682 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800683 */
684 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
685
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700686 /**
687 * Connection event used to inform an {@link InCallService} that the RTT audio indication
688 * has changed.
689 */
690 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
691 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
692
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700693 // Flag controlling whether PII is emitted into the logs
694 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
695
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800696 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700697 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
698 *
699 * @param capabilities A capability bit field.
700 * @return A human readable string representation.
701 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800702 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 return capabilitiesToStringInternal(capabilities, true /* isLong */);
704 }
705
706 /**
707 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
708 * string.
709 *
710 * @param capabilities A capability bit field.
711 * @return A human readable string representation.
712 * @hide
713 */
714 public static String capabilitiesToStringShort(int capabilities) {
715 return capabilitiesToStringInternal(capabilities, false /* isLong */);
716 }
717
718 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append("[");
721 if (isLong) {
722 builder.append("Capabilities:");
723 }
724
Tyler Gunnc63f9082019-10-15 13:19:26 -0700725 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700726 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800727 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700728 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700729 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800730 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700731 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700732 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800733 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700734 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700735 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800736 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700737 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700738 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800739 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700740 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700741 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800742 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700743 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700744 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800745 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700746 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700747 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700748 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700749 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700750 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700751 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700752 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
753 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700754 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800755 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700756 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700757 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700758 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700759 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700760 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700761 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700762 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
763 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700764 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800765 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700766 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
767 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700768 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800769 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700770 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700771 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500772 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700773 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700774 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700775 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700776 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700777 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700778 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700779 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
780 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700781 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700782 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700783 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
784 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700785 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700786 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700787 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700788 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700789 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700790 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530791 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
792 }
Bryce Lee81901682015-08-28 16:38:02 -0700793
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800794 builder.append("]");
795 return builder.toString();
796 }
797
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700798 /**
799 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
800 *
801 * @param properties A property bit field.
802 * @return A human readable string representation.
803 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700804 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700805 return propertiesToStringInternal(properties, true /* isLong */);
806 }
807
808 /**
809 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
810 *
811 * @param properties A property bit field.
812 * @return A human readable string representation.
813 * @hide
814 */
815 public static String propertiesToStringShort(int properties) {
816 return propertiesToStringInternal(properties, false /* isLong */);
817 }
818
819 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700820 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700821 builder.append("[");
822 if (isLong) {
823 builder.append("Properties:");
824 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700825
Tyler Gunnc63f9082019-10-15 13:19:26 -0700826 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800827 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
828 }
829
Tyler Gunnc63f9082019-10-15 13:19:26 -0700830 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700831 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700832 }
833
Tyler Gunnc63f9082019-10-15 13:19:26 -0700834 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700835 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700836 }
837
Tyler Gunnc63f9082019-10-15 13:19:26 -0700838 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700839 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700840 }
841
Tyler Gunnc63f9082019-10-15 13:19:26 -0700842 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700843 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700844 }
845
Tyler Gunnc63f9082019-10-15 13:19:26 -0700846 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700847 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700848 }
849
Tyler Gunnc63f9082019-10-15 13:19:26 -0700850 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700851 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700852 }
853
Tyler Gunnc63f9082019-10-15 13:19:26 -0700854 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800855 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
856 }
857
Tyler Gunnc63f9082019-10-15 13:19:26 -0700858 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
859 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700860 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
861 }
862
Tyler Gunnc63f9082019-10-15 13:19:26 -0700863 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700864 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
865 }
866
Tyler Gunn720c6642016-03-22 09:02:47 -0700867 builder.append("]");
868 return builder.toString();
869 }
870
Sailesh Nepal091768c2014-06-30 15:15:23 -0700871 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700872 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700873 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700874 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700875 public void onCallerDisplayNameChanged(
876 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700877 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700878 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700879 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800880 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700881 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700882 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800883 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700884 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800885 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700886 public void onVideoProviderChanged(
887 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700888 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
889 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800890 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700891 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700892 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700893 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700894 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700895 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700896 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b2017-11-07 17:59:28 -0800897 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800898 public void onRttInitiationSuccess(Connection c) {}
899 public void onRttInitiationFailure(Connection c, int reason) {}
900 public void onRttSessionRemotelyTerminated(Connection c) {}
901 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530902 /** @hide */
903 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800904 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700905 }
906
Tyler Gunnb702ef82015-05-29 11:51:53 -0700907 /**
Hall Liu95d55872017-01-25 17:12:49 -0800908 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800909 */
910 public static final class RttTextStream {
911 private static final int READ_BUFFER_SIZE = 1000;
912 private final InputStreamReader mPipeFromInCall;
913 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800914 private final ParcelFileDescriptor mFdFromInCall;
915 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700916
917 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800918 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
919
920 /**
921 * @hide
922 */
923 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800924 mFdFromInCall = fromInCall;
925 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700926 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700927
928 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800929 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700930 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800931 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800932 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800933 }
934
935 /**
936 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
937 * RTT transmits text in real-time, this method should be called as often as text snippets
938 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800939 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800940 * This method is not thread-safe -- calling it from multiple threads simultaneously may
941 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800942 *
Hall Liu95d55872017-01-25 17:12:49 -0800943 * @param input The message to send to the in-call app.
944 */
945 public void write(String input) throws IOException {
946 mPipeToInCall.write(input);
947 mPipeToInCall.flush();
948 }
949
950
951 /**
952 * Reads a string from the in-call app, blocking if there is no data available. Returns
953 * {@code null} if the RTT conversation has been terminated and there is no further data
954 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800955 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800956 * This method is not thread-safe -- calling it from multiple threads simultaneously may
957 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800958 *
Hall Liu95d55872017-01-25 17:12:49 -0800959 * @return A string containing text entered by the user, or {@code null} if the
960 * conversation has been terminated or if there was an error while reading.
961 */
Hall Liuffa4a812017-03-02 16:11:00 -0800962 public String read() throws IOException {
963 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
964 if (numRead < 0) {
965 return null;
966 }
967 return new String(mReadBuffer, 0, numRead);
968 }
969
970 /**
971 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
972 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800973 *
Hall Liuffa4a812017-03-02 16:11:00 -0800974 * @return A string containing text entered by the user, or {@code null} if the user has
975 * not entered any new text yet.
976 */
977 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700978 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800979 return read();
980 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800981 return null;
982 }
983 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800984
985 /** @hide */
986 public ParcelFileDescriptor getFdFromInCall() {
987 return mFdFromInCall;
988 }
989
990 /** @hide */
991 public ParcelFileDescriptor getFdToInCall() {
992 return mFdToInCall;
993 }
994 }
995
996 /**
997 * Provides constants to represent the results of responses to session modify requests sent via
998 * {@link Call#sendRttRequest()}
999 */
1000 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001001 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001002 /**
1003 * Session modify request was successful.
1004 */
1005 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1006
1007 /**
1008 * Session modify request failed.
1009 */
1010 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1011
1012 /**
1013 * Session modify request ignored due to invalid parameters.
1014 */
1015 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1016
1017 /**
1018 * Session modify request timed out.
1019 */
1020 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1021
1022 /**
1023 * Session modify request rejected by remote user.
1024 */
1025 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001026 }
1027
1028 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001029 * Provides a means of controlling the video session associated with a {@link Connection}.
1030 * <p>
1031 * Implementations create a custom subclass of {@link VideoProvider} and the
1032 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1033 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1034 * should set the {@link VideoProvider}.
1035 * <p>
1036 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1037 * {@link InCallService} implementations to issue requests related to the video session;
1038 * it provides a means for the {@link ConnectionService} to report events and information
1039 * related to the video session to Telecom and the {@link InCallService} implementations.
1040 * <p>
1041 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1042 * {@link android.telecom.InCallService.VideoCall}.
1043 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001045 /**
1046 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001047 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 */
1049 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001050
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001052 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1053 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 */
1055 public static final int SESSION_EVENT_RX_RESUME = 2;
1056
1057 /**
1058 * Video transmission has begun. This occurs after a negotiated start of video transmission
1059 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001060 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061 */
1062 public static final int SESSION_EVENT_TX_START = 3;
1063
1064 /**
1065 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1066 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001067 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 */
1069 public static final int SESSION_EVENT_TX_STOP = 4;
1070
1071 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001072 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001073 * this as a cue to inform the user the camera is not available.
1074 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075 */
1076 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1077
1078 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001079 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001080 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001081 * the camera has become available again.
1082 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 */
1084 public static final int SESSION_EVENT_CAMERA_READY = 6;
1085
1086 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001087 * Session event raised by Telecom when
1088 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1089 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1090 * @see #handleCallSessionEvent(int)
1091 */
1092 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1093
1094 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001095 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001096 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 */
1098 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1099
1100 /**
1101 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001102 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 */
1104 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1105
1106 /**
1107 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001108 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 */
1110 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1111
Rekha Kumar07366812015-03-24 16:42:31 -07001112 /**
1113 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001114 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001115 */
1116 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1117
1118 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001119 * Session modify request rejected by remote user.
1120 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001121 */
1122 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1123
Tyler Gunn75958422015-04-15 14:23:42 -07001124 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 private static final int MSG_SET_CAMERA = 2;
1126 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1127 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1128 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1129 private static final int MSG_SET_ZOOM = 6;
1130 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1131 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1132 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001133 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001135 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001137 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1138 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1139 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1140 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1141 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1142 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001143 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1144 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001145 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1146
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001147 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001149
1150 /**
1151 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001152 *
1153 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1154 * load factor before resizing, 1 means we only expect a single thread to
1155 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001156 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001157 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1158 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001159
1160 /**
1161 * Default handler used to consolidate binder method calls onto a single thread.
1162 */
1163 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001164 public VideoProviderHandler() {
1165 super();
1166 }
1167
1168 public VideoProviderHandler(Looper looper) {
1169 super(looper);
1170 }
1171
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 @Override
1173 public void handleMessage(Message msg) {
1174 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001175 case MSG_ADD_VIDEO_CALLBACK: {
1176 IBinder binder = (IBinder) msg.obj;
1177 IVideoCallback callback = IVideoCallback.Stub
1178 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001179 if (callback == null) {
1180 Log.w(this, "addVideoProvider - skipped; callback is null.");
1181 break;
1182 }
1183
Tyler Gunn75958422015-04-15 14:23:42 -07001184 if (mVideoCallbacks.containsKey(binder)) {
1185 Log.i(this, "addVideoProvider - skipped; already present.");
1186 break;
1187 }
1188 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001189 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001190 }
1191 case MSG_REMOVE_VIDEO_CALLBACK: {
1192 IBinder binder = (IBinder) msg.obj;
1193 IVideoCallback callback = IVideoCallback.Stub
1194 .asInterface((IBinder) msg.obj);
1195 if (!mVideoCallbacks.containsKey(binder)) {
1196 Log.i(this, "removeVideoProvider - skipped; not present.");
1197 break;
1198 }
1199 mVideoCallbacks.remove(binder);
1200 break;
1201 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001203 {
1204 SomeArgs args = (SomeArgs) msg.obj;
1205 try {
1206 onSetCamera((String) args.arg1);
1207 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001208 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001209 } finally {
1210 args.recycle();
1211 }
1212 }
1213 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001214 case MSG_SET_PREVIEW_SURFACE:
1215 onSetPreviewSurface((Surface) msg.obj);
1216 break;
1217 case MSG_SET_DISPLAY_SURFACE:
1218 onSetDisplaySurface((Surface) msg.obj);
1219 break;
1220 case MSG_SET_DEVICE_ORIENTATION:
1221 onSetDeviceOrientation(msg.arg1);
1222 break;
1223 case MSG_SET_ZOOM:
1224 onSetZoom((Float) msg.obj);
1225 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001226 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1227 SomeArgs args = (SomeArgs) msg.obj;
1228 try {
1229 onSendSessionModifyRequest((VideoProfile) args.arg1,
1230 (VideoProfile) args.arg2);
1231 } finally {
1232 args.recycle();
1233 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001234 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001235 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001236 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1237 onSendSessionModifyResponse((VideoProfile) msg.obj);
1238 break;
1239 case MSG_REQUEST_CAMERA_CAPABILITIES:
1240 onRequestCameraCapabilities();
1241 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001242 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1243 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 break;
1245 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001246 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 break;
1248 default:
1249 break;
1250 }
1251 }
1252 }
1253
1254 /**
1255 * IVideoProvider stub implementation.
1256 */
1257 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001258 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001259 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001260 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1261 }
1262
1263 public void removeVideoCallback(IBinder videoCallbackBinder) {
1264 mMessageHandler.obtainMessage(
1265 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001266 }
1267
Tyler Gunn159f35c2017-03-02 09:28:37 -08001268 public void setCamera(String cameraId, String callingPackageName,
1269 int targetSdkVersion) {
1270
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001271 SomeArgs args = SomeArgs.obtain();
1272 args.arg1 = cameraId;
1273 // Propagate the calling package; originally determined in
1274 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1275 // process.
1276 args.arg2 = callingPackageName;
1277 // Pass along the uid and pid of the calling app; this gets lost when we put the
1278 // message onto the handler. These are required for Telecom to perform a permission
1279 // check to see if the calling app is able to use the camera.
1280 args.argi1 = Binder.getCallingUid();
1281 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001282 // Pass along the target SDK version of the calling InCallService. This is used to
1283 // maintain backwards compatibility of the API for older callers.
1284 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001285 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001286 }
1287
1288 public void setPreviewSurface(Surface surface) {
1289 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1290 }
1291
1292 public void setDisplaySurface(Surface surface) {
1293 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1294 }
1295
1296 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001297 mMessageHandler.obtainMessage(
1298 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 }
1300
1301 public void setZoom(float value) {
1302 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1303 }
1304
Tyler Gunn45382162015-05-06 08:52:27 -07001305 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1306 SomeArgs args = SomeArgs.obtain();
1307 args.arg1 = fromProfile;
1308 args.arg2 = toProfile;
1309 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 }
1311
1312 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1313 mMessageHandler.obtainMessage(
1314 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1315 }
1316
1317 public void requestCameraCapabilities() {
1318 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1319 }
1320
1321 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001322 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001323 }
1324
Yorke Lee32f24732015-05-12 16:18:03 -07001325 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1327 }
1328 }
1329
1330 public VideoProvider() {
1331 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001332 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001333 }
1334
1335 /**
1336 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1337 *
1338 * @param looper The looper.
1339 * @hide
1340 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001341 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001342 public VideoProvider(Looper looper) {
1343 mBinder = new VideoProvider.VideoProviderBinder();
1344 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001345 }
1346
1347 /**
1348 * Returns binder object which can be used across IPC methods.
1349 * @hide
1350 */
1351 public final IVideoProvider getInterface() {
1352 return mBinder;
1353 }
1354
1355 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001356 * Sets the camera to be used for the outgoing video.
1357 * <p>
1358 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1359 * camera via
1360 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1361 * <p>
1362 * Sent from the {@link InCallService} via
1363 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001364 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001365 * @param cameraId The id of the camera (use ids as reported by
1366 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 */
1368 public abstract void onSetCamera(String cameraId);
1369
1370 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001371 * Sets the camera to be used for the outgoing video.
1372 * <p>
1373 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1374 * camera via
1375 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1376 * <p>
1377 * This prototype is used internally to ensure that the calling package name, UID and PID
1378 * are sent to Telecom so that can perform a camera permission check on the caller.
1379 * <p>
1380 * Sent from the {@link InCallService} via
1381 * {@link InCallService.VideoCall#setCamera(String)}.
1382 *
1383 * @param cameraId The id of the camera (use ids as reported by
1384 * {@link CameraManager#getCameraIdList()}).
1385 * @param callingPackageName The AppOpps package name of the caller.
1386 * @param callingUid The UID of the caller.
1387 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001388 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001389 * @hide
1390 */
1391 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001392 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001393
1394 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 * Sets the surface to be used for displaying a preview of what the user's camera is
1396 * currently capturing. When video transmission is enabled, this is the video signal which
1397 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001398 * <p>
1399 * Sent from the {@link InCallService} via
1400 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001402 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 */
1404 public abstract void onSetPreviewSurface(Surface surface);
1405
1406 /**
1407 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001408 * <p>
1409 * Sent from the {@link InCallService} via
1410 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001412 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001413 */
1414 public abstract void onSetDisplaySurface(Surface surface);
1415
1416 /**
1417 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1418 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001419 * <p>
1420 * Sent from the {@link InCallService} via
1421 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 *
1423 * @param rotation The device orientation, in degrees.
1424 */
1425 public abstract void onSetDeviceOrientation(int rotation);
1426
1427 /**
1428 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001429 * <p>
1430 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431 *
1432 * @param value The camera zoom ratio.
1433 */
1434 public abstract void onSetZoom(float value);
1435
1436 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001437 * Issues a request to modify the properties of the current video session.
1438 * <p>
1439 * Example scenarios include: requesting an audio-only call to be upgraded to a
1440 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1441 * when the {@link InCallService} is no longer the foreground application.
1442 * <p>
1443 * If the {@link VideoProvider} determines a request to be invalid, it should call
1444 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1445 * invalid request back to the {@link InCallService}.
1446 * <p>
1447 * Where a request requires confirmation from the user of the peer device, the
1448 * {@link VideoProvider} must communicate the request to the peer device and handle the
1449 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1450 * is used to inform the {@link InCallService} of the result of the request.
1451 * <p>
1452 * Sent from the {@link InCallService} via
1453 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001455 * @param fromProfile The video profile prior to the request.
1456 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 */
Tyler Gunn45382162015-05-06 08:52:27 -07001458 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1459 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460
Tyler Gunnb702ef82015-05-29 11:51:53 -07001461 /**
1462 * Provides a response to a request to change the current video session properties.
1463 * <p>
1464 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1465 * video call, could decline the request and keep the call as audio-only.
1466 * In such a scenario, the {@code responseProfile} would have a video state of
1467 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1468 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1469 * <p>
1470 * Sent from the {@link InCallService} via
1471 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1472 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1473 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001474 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001475 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001476 */
1477 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1478
1479 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001480 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1481 * <p>
1482 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1483 * camera via
1484 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1485 * <p>
1486 * Sent from the {@link InCallService} via
1487 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 */
1489 public abstract void onRequestCameraCapabilities();
1490
1491 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001492 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1493 * video component of the current {@link Connection}.
1494 * <p>
1495 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1496 * via {@link VideoProvider#setCallDataUsage(long)}.
1497 * <p>
1498 * Sent from the {@link InCallService} via
1499 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001501 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502
1503 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001504 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1505 * the peer device when the video signal is paused.
1506 * <p>
1507 * Sent from the {@link InCallService} via
1508 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 *
1510 * @param uri URI of image to display.
1511 */
Yorke Lee32f24732015-05-12 16:18:03 -07001512 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001513
1514 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001515 * Used to inform listening {@link InCallService} implementations when the
1516 * {@link VideoProvider} receives a session modification request.
1517 * <p>
1518 * Received by the {@link InCallService} via
1519 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001520 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001521 * @param videoProfile The requested video profile.
1522 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001523 */
1524 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001525 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001526 for (IVideoCallback callback : mVideoCallbacks.values()) {
1527 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001528 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001529 } catch (RemoteException ignored) {
1530 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001531 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 }
1533 }
1534 }
1535
1536 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001537 * Used to inform listening {@link InCallService} implementations when the
1538 * {@link VideoProvider} receives a response to a session modification request.
1539 * <p>
1540 * Received by the {@link InCallService} via
1541 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1542 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001543 *
1544 * @param status Status of the session modify request. Valid values are
1545 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1546 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001547 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1548 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1549 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1550 * @param requestedProfile The original request which was sent to the peer device.
1551 * @param responseProfile The actual profile changes agreed to by the peer device.
1552 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553 */
1554 public void receiveSessionModifyResponse(int status,
1555 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001556 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001557 for (IVideoCallback callback : mVideoCallbacks.values()) {
1558 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001559 callback.receiveSessionModifyResponse(status, requestedProfile,
1560 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001561 } catch (RemoteException ignored) {
1562 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001563 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001564 }
1565 }
1566 }
1567
1568 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001569 * Used to inform listening {@link InCallService} implementations when the
1570 * {@link VideoProvider} reports a call session event.
1571 * <p>
1572 * Received by the {@link InCallService} via
1573 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001574 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001575 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1576 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1577 * {@link VideoProvider#SESSION_EVENT_TX_START},
1578 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1579 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001580 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1581 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 */
1583 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001584 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001585 for (IVideoCallback callback : mVideoCallbacks.values()) {
1586 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001587 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001588 } catch (RemoteException ignored) {
1589 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001590 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 }
1592 }
1593 }
1594
1595 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001596 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1597 * peer's video have changed.
1598 * <p>
1599 * This could occur if, for example, the peer rotates their device, changing the aspect
1600 * ratio of the video, or if the user switches between the back and front cameras.
1601 * <p>
1602 * Received by the {@link InCallService} via
1603 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 *
1605 * @param width The updated peer video width.
1606 * @param height The updated peer video height.
1607 */
1608 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001609 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001610 for (IVideoCallback callback : mVideoCallbacks.values()) {
1611 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001612 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001613 } catch (RemoteException ignored) {
1614 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001615 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001616 }
1617 }
1618 }
1619
1620 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001621 * Used to inform listening {@link InCallService} implementations when the data usage of the
1622 * video associated with the current {@link Connection} has changed.
1623 * <p>
1624 * This could be in response to a preview request via
1625 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001626 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1627 * 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 -07001628 * <p>
1629 * Received by the {@link InCallService} via
1630 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001631 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001632 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1633 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001634 */
Yorke Lee32f24732015-05-12 16:18:03 -07001635 public void setCallDataUsage(long dataUsage) {
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.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001640 } catch (RemoteException ignored) {
1641 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001642 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001643 }
1644 }
1645 }
1646
1647 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001648 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001650 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001651 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1652 * @hide
1653 */
1654 public void changeCallDataUsage(long dataUsage) {
1655 setCallDataUsage(dataUsage);
1656 }
1657
1658 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * Used to inform listening {@link InCallService} implementations when the capabilities of
1660 * the current camera have changed.
1661 * <p>
1662 * The {@link VideoProvider} should call this in response to
1663 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1664 * changed via {@link VideoProvider#onSetCamera(String)}.
1665 * <p>
1666 * Received by the {@link InCallService} via
1667 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1668 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001669 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001670 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001671 */
Yorke Lee400470f2015-05-12 13:31:25 -07001672 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001673 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001674 for (IVideoCallback callback : mVideoCallbacks.values()) {
1675 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001676 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001677 } catch (RemoteException ignored) {
1678 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001679 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001680 }
1681 }
1682 }
Rekha Kumar07366812015-03-24 16:42:31 -07001683
1684 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001685 * Used to inform listening {@link InCallService} implementations when the video quality
1686 * of the call has changed.
1687 * <p>
1688 * Received by the {@link InCallService} via
1689 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001690 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001691 * @param videoQuality The updated video quality. Valid values:
1692 * {@link VideoProfile#QUALITY_HIGH},
1693 * {@link VideoProfile#QUALITY_MEDIUM},
1694 * {@link VideoProfile#QUALITY_LOW},
1695 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001696 */
1697 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001698 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001699 for (IVideoCallback callback : mVideoCallbacks.values()) {
1700 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001701 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001702 } catch (RemoteException ignored) {
1703 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001704 }
Rekha Kumar07366812015-03-24 16:42:31 -07001705 }
1706 }
1707 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001708
1709 /**
1710 * Returns a string representation of a call session event.
1711 *
1712 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1713 * @return String representation of the call session event.
1714 * @hide
1715 */
1716 public static String sessionEventToString(int event) {
1717 switch (event) {
1718 case SESSION_EVENT_CAMERA_FAILURE:
1719 return SESSION_EVENT_CAMERA_FAILURE_STR;
1720 case SESSION_EVENT_CAMERA_READY:
1721 return SESSION_EVENT_CAMERA_READY_STR;
1722 case SESSION_EVENT_RX_PAUSE:
1723 return SESSION_EVENT_RX_PAUSE_STR;
1724 case SESSION_EVENT_RX_RESUME:
1725 return SESSION_EVENT_RX_RESUME_STR;
1726 case SESSION_EVENT_TX_START:
1727 return SESSION_EVENT_TX_START_STR;
1728 case SESSION_EVENT_TX_STOP:
1729 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001730 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1731 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001732 default:
1733 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1734 }
1735 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736 }
1737
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001738 private final Listener mConnectionDeathListener = new Listener() {
1739 @Override
1740 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001741 if (mConferenceables.remove(c)) {
1742 fireOnConferenceableConnectionsChanged();
1743 }
1744 }
1745 };
1746
1747 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1748 @Override
1749 public void onDestroyed(Conference c) {
1750 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001751 fireOnConferenceableConnectionsChanged();
1752 }
1753 }
1754 };
1755
Jay Shrauner229e3822014-08-15 09:23:07 -07001756 /**
1757 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1758 * load factor before resizing, 1 means we only expect a single thread to
1759 * access the map so make only a single shard
1760 */
1761 private final Set<Listener> mListeners = Collections.newSetFromMap(
1762 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001763 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1764 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001765 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001766
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001767 // The internal telecom call ID associated with this connection.
1768 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001769 // The PhoneAccountHandle associated with this connection.
1770 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001771 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001772 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001773 private Uri mAddress;
1774 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001775 private String mCallerDisplayName;
1776 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001777 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001778 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001779 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001780 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001781 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001782 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001783 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001784 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001785 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001786 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001787 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001788 private Conference mConference;
1789 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001790 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001791 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001792 /**
1793 * The direction of the connection; used where an existing connection is created and we need to
1794 * communicate to Telecom whether its incoming or outgoing.
1795 */
1796 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001797
1798 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001799 * Tracks the key set for the extras bundle provided on the last invocation of
1800 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1801 * keys which were set previously but are no longer present in the replacement Bundle.
1802 */
1803 private Set<String> mPreviousExtraKeys;
1804
1805 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001806 * Create a new Connection.
1807 */
Santos Cordonf2951102014-07-20 19:06:29 -07001808 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001809
1810 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001811 * Returns the Telecom internal call ID associated with this connection. Should only be used
1812 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001813 * <p>
1814 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1815 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001816 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001817 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001818 * @hide
1819 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001820 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001821 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001822 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001823 return mTelecomCallId;
1824 }
1825
1826 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001827 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001828 */
Andrew Lee100e2932014-09-08 15:34:24 -07001829 public final Uri getAddress() {
1830 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001831 }
1832
1833 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001834 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001835 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001836 */
Andrew Lee100e2932014-09-08 15:34:24 -07001837 public final int getAddressPresentation() {
1838 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001839 }
1840
1841 /**
1842 * @return The caller display name (CNAP).
1843 */
1844 public final String getCallerDisplayName() {
1845 return mCallerDisplayName;
1846 }
1847
1848 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001849 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001850 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001851 */
1852 public final int getCallerDisplayNamePresentation() {
1853 return mCallerDisplayNamePresentation;
1854 }
1855
1856 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001857 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001858 */
1859 public final int getState() {
1860 return mState;
1861 }
1862
1863 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001864 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001865 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1866 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1867 * {@link VideoProfile#STATE_TX_ENABLED},
1868 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001869 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001870 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001871 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001872 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001873 return mVideoState;
1874 }
1875
1876 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001877 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001878 * being routed by the system. This is {@code null} if this Connection
1879 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001880 * @deprecated Use {@link #getCallAudioState()} instead.
1881 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 */
Yorke Lee4af59352015-05-13 14:14:54 -07001883 @SystemApi
1884 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001885 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001886 if (mCallAudioState == null) {
1887 return null;
1888 }
Yorke Lee4af59352015-05-13 14:14:54 -07001889 return new AudioState(mCallAudioState);
1890 }
1891
1892 /**
1893 * @return The audio state of the connection, describing how its audio is currently
1894 * being routed by the system. This is {@code null} if this Connection
1895 * does not directly know about its audio state.
1896 */
1897 public final CallAudioState getCallAudioState() {
1898 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001899 }
1900
1901 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001902 * @return The conference that this connection is a part of. Null if it is not part of any
1903 * conference.
1904 */
1905 public final Conference getConference() {
1906 return mConference;
1907 }
1908
1909 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001910 * Returns whether this connection is requesting that the system play a ringback tone
1911 * on its behalf.
1912 */
Andrew Lee100e2932014-09-08 15:34:24 -07001913 public final boolean isRingbackRequested() {
1914 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001915 }
1916
1917 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001918 * @return True if the connection's audio mode is VOIP.
1919 */
1920 public final boolean getAudioModeIsVoip() {
1921 return mAudioModeIsVoip;
1922 }
1923
1924 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001925 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1926 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1927 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001928 * <p>
1929 * Note: This is an implementation detail specific to IMS conference calls over a mobile
1930 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07001931 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001932 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
1933 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07001934 *
1935 * @hide
1936 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001937 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001938 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07001939 public final long getConnectTimeMillis() {
1940 return mConnectTimeMillis;
1941 }
1942
1943 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001944 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1945 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1946 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001947 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001948 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1949 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001950 * <p>
1951 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001952 *
1953 * @return The time at which the {@link Connection} was connected.
1954 *
1955 * @hide
1956 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001957 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001958 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001959 public final long getConnectElapsedTimeMillis() {
1960 return mConnectElapsedTimeMillis;
1961 }
1962
1963 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001964 * @return The status hints for this connection.
1965 */
1966 public final StatusHints getStatusHints() {
1967 return mStatusHints;
1968 }
1969
1970 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001971 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001972 * <p>
1973 * Extras should be updated using {@link #putExtras(Bundle)}.
1974 * <p>
1975 * Telecom or an {@link InCallService} can also update the extras via
1976 * {@link android.telecom.Call#putExtras(Bundle)}, and
1977 * {@link Call#removeExtras(List)}.
1978 * <p>
1979 * The connection is notified of changes to the extras made by Telecom or an
1980 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001981 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001982 * @return The extras associated with this connection.
1983 */
1984 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001985 Bundle extras = null;
1986 synchronized (mExtrasLock) {
1987 if (mExtras != null) {
1988 extras = new Bundle(mExtras);
1989 }
1990 }
1991 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001992 }
1993
1994 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001995 * Assign a listener to be notified of state changes.
1996 *
1997 * @param l A listener.
1998 * @return This Connection.
1999 *
2000 * @hide
2001 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002002 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002003 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 return this;
2005 }
2006
2007 /**
2008 * Remove a previously assigned listener that was being notified of state changes.
2009 *
2010 * @param l A Listener.
2011 * @return This Connection.
2012 *
2013 * @hide
2014 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002015 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002016 if (l != null) {
2017 mListeners.remove(l);
2018 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002019 return this;
2020 }
2021
2022 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002023 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002024 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002025 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002026 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002027 }
2028
2029 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002030 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2031 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002032 * <p>
2033 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2034 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2035 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002036 *
2037 * @param callId The telecom call ID.
2038 * @hide
2039 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002040 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002041 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002042 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002043 mTelecomCallId = callId;
2044 }
2045
2046 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047 * Inform this Connection that the state of its audio output has been changed externally.
2048 *
2049 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002050 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002051 */
Yorke Lee4af59352015-05-13 14:14:54 -07002052 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002053 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002054 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002055 mCallAudioState = state;
2056 onAudioStateChanged(getAudioState());
2057 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002058 }
2059
2060 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002061 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002062 * @return A string representation of the value.
2063 */
2064 public static String stateToString(int state) {
2065 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002067 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002068 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002069 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002070 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002071 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002072 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002073 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002074 case STATE_PULLING_CALL:
2075 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002076 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002077 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002079 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002080 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002081 return "DISCONNECTED";
2082 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002083 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084 return "UNKNOWN";
2085 }
2086 }
2087
2088 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002090 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 public final int getConnectionCapabilities() {
2092 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002093 }
2094
2095 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002096 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2097 */
2098 public final int getConnectionProperties() {
2099 return mConnectionProperties;
2100 }
2101
2102 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002103 * Returns the connection's supported audio routes.
2104 *
2105 * @hide
2106 */
2107 public final int getSupportedAudioRoutes() {
2108 return mSupportedAudioRoutes;
2109 }
2110
2111 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002112 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002113 *
Andrew Lee100e2932014-09-08 15:34:24 -07002114 * @param address The new address.
2115 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002116 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002117 */
Andrew Lee100e2932014-09-08 15:34:24 -07002118 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002119 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002120 Log.d(this, "setAddress %s", address);
2121 mAddress = address;
2122 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002123 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002124 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002125 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 }
2127
2128 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002129 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002130 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002131 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002132 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002133 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002134 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002135 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002136 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002137 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002138 mCallerDisplayName = callerDisplayName;
2139 mCallerDisplayNamePresentation = presentation;
2140 for (Listener l : mListeners) {
2141 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2142 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002143 }
2144
2145 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002146 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002147 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2148 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2149 * {@link VideoProfile#STATE_TX_ENABLED},
2150 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002151 *
2152 * @param videoState The new video state.
2153 */
2154 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002155 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002156 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002157 mVideoState = videoState;
2158 for (Listener l : mListeners) {
2159 l.onVideoStateChanged(this, mVideoState);
2160 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002161 }
2162
2163 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002164 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002165 * communicate).
2166 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002167 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002168 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002169 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002170 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002171 }
2172
2173 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002174 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002175 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002176 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002177 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002178 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002179 }
2180
2181 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002182 * Sets state to initializing (this Connection is not yet ready to be used).
2183 */
2184 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002185 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002186 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002187 }
2188
2189 /**
2190 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2191 */
2192 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002193 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002194 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002195 }
2196
2197 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002198 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002199 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002200 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002202 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002203 }
2204
2205 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002206 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2207 * device). Only applicable for {@link Connection}s with
2208 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2209 */
2210 public final void setPulling() {
2211 checkImmutable();
2212 setState(STATE_PULLING_CALL);
2213 }
2214
2215 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002216 * Sets state to be on hold.
2217 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002218 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002219 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002220 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002221 }
2222
2223 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002224 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002225 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002226 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002227 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002228 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002229 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002230 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002231 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002232 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002233 }
2234
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002235 public final VideoProvider getVideoProvider() {
2236 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002237 }
2238
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002239 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002240 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002241 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002242 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002243 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002245 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002246 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002247 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002248 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002249 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002250 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002251 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002252 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002253 }
2254
2255 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002256 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2257 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2258 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2259 * to send an {@link #onPostDialContinue(boolean)} signal.
2260 *
2261 * @param remaining The DTMF character sequence remaining to be emitted once the
2262 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2263 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002264 */
2265 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002266 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002267 for (Listener l : mListeners) {
2268 l.onPostDialWait(this, remaining);
2269 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002270 }
2271
2272 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002273 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2274 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002275 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002276 *
2277 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002278 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002279 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002280 checkImmutable();
2281 for (Listener l : mListeners) {
2282 l.onPostDialChar(this, nextChar);
2283 }
2284 }
2285
2286 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002287 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002288 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002289 *
2290 * @param ringback Whether the ringback tone is to be played.
2291 */
Andrew Lee100e2932014-09-08 15:34:24 -07002292 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002293 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002294 if (mRingbackRequested != ringback) {
2295 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002296 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002297 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002298 }
2299 }
Ihab Awadf8358972014-05-28 16:46:42 -07002300 }
2301
2302 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002303 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002304 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002305 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002306 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002307 public final void setConnectionCapabilities(int connectionCapabilities) {
2308 checkImmutable();
2309 if (mConnectionCapabilities != connectionCapabilities) {
2310 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002311 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002312 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002313 }
2314 }
Santos Cordonb6939982014-06-04 20:20:58 -07002315 }
2316
2317 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002318 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2319 *
2320 * @param connectionProperties The new connection properties.
2321 */
2322 public final void setConnectionProperties(int connectionProperties) {
2323 checkImmutable();
2324 if (mConnectionProperties != connectionProperties) {
2325 mConnectionProperties = connectionProperties;
2326 for (Listener l : mListeners) {
2327 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2328 }
2329 }
2330 }
2331
2332 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002333 * Sets the supported audio routes.
2334 *
2335 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2336 * See {@link CallAudioState}
2337 * @hide
2338 */
2339 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2340 if ((supportedAudioRoutes
2341 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2342 throw new IllegalArgumentException(
2343 "supported audio routes must include either speaker or earpiece");
2344 }
2345
2346 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2347 mSupportedAudioRoutes = supportedAudioRoutes;
2348 for (Listener l : mListeners) {
2349 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2350 }
2351 }
2352 }
2353
2354 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002355 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002356 */
Evan Charlton36a71342014-07-19 16:31:02 -07002357 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002358 for (Listener l : mListeners) {
2359 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002360 }
Santos Cordonb6939982014-06-04 20:20:58 -07002361 }
2362
2363 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002364 * Requests that the framework use VOIP audio mode for this connection.
2365 *
2366 * @param isVoip True if the audio mode is VOIP.
2367 */
2368 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002369 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002370 mAudioModeIsVoip = isVoip;
2371 for (Listener l : mListeners) {
2372 l.onAudioModeIsVoipChanged(this, isVoip);
2373 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002374 }
2375
2376 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002377 * Sets the time at which a call became active on this Connection. This is set only
2378 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002379 * <p>
2380 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002381 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002382 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2383 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002384 *
2385 * @hide
2386 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002387 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002388 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002389 public final void setConnectTimeMillis(long connectTimeMillis) {
2390 mConnectTimeMillis = connectTimeMillis;
2391 }
2392
2393 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002394 * Sets the time at which a call became active on this Connection. This is set only
2395 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002396 * <p>
2397 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002398 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2399 * {@link SystemClock#elapsedRealtime()}.
2400 *
2401 * @hide
2402 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002403 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002404 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002405 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002406 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2407 }
2408
2409 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002410 * Sets the label and icon status to display in the in-call UI.
2411 *
2412 * @param statusHints The status label and icon to set.
2413 */
2414 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002415 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002416 mStatusHints = statusHints;
2417 for (Listener l : mListeners) {
2418 l.onStatusHintsChanged(this, statusHints);
2419 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002420 }
2421
2422 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002423 * Sets the connections with which this connection can be conferenced.
2424 *
2425 * @param conferenceableConnections The set of connections this connection can conference with.
2426 */
2427 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002428 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002429 clearConferenceableList();
2430 for (Connection c : conferenceableConnections) {
2431 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2432 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002433 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002434 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002435 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002436 }
2437 }
2438 fireOnConferenceableConnectionsChanged();
2439 }
2440
2441 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002442 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2443 * or conferences with which this connection can be conferenced.
2444 *
2445 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002446 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002447 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002448 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002449 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002450 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2451 // small amount of items here.
2452 if (!mConferenceables.contains(c)) {
2453 if (c instanceof Connection) {
2454 Connection connection = (Connection) c;
2455 connection.addConnectionListener(mConnectionDeathListener);
2456 } else if (c instanceof Conference) {
2457 Conference conference = (Conference) c;
2458 conference.addListener(mConferenceDeathListener);
2459 }
2460 mConferenceables.add(c);
2461 }
2462 }
2463 fireOnConferenceableConnectionsChanged();
2464 }
2465
2466 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002467 * Resets the CDMA connection time.
2468 * <p>
2469 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002470 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002471 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002472 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002473 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002474 public final void resetConnectionTime() {
2475 for (Listener l : mListeners) {
2476 l.onConnectionTimeReset(this);
2477 }
2478 }
2479
2480 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002481 * Returns the connections or conferences with which this connection can be conferenced.
2482 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002483 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002484 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002485 }
2486
Yorke Lee53463962015-08-04 16:07:19 -07002487 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002488 * @hide
2489 */
2490 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002491 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002492 if (mConnectionService != null) {
2493 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2494 "which is already associated with another ConnectionService.");
2495 } else {
2496 mConnectionService = connectionService;
2497 }
2498 }
2499
2500 /**
2501 * @hide
2502 */
2503 public final void unsetConnectionService(ConnectionService connectionService) {
2504 if (mConnectionService != connectionService) {
2505 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2506 "that does not belong to the ConnectionService.");
2507 } else {
2508 mConnectionService = null;
2509 }
2510 }
2511
2512 /**
2513 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002514 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002515 *
2516 * @param conference The conference.
2517 * @return {@code true} if the conference was successfully set.
2518 * @hide
2519 */
2520 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002521 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002522 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002523 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002524 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002525 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2526 fireConferenceChanged();
2527 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002528 return true;
2529 }
2530 return false;
2531 }
2532
2533 /**
2534 * Resets the conference that this connection is a part of.
2535 * @hide
2536 */
2537 public final void resetConference() {
2538 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002539 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002540 mConference = null;
2541 fireConferenceChanged();
2542 }
2543 }
2544
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002545 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002546 * Set some extras that can be associated with this {@code Connection}.
2547 * <p>
2548 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2549 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2550 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002551 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2552 * {@link #removeExtras(String...)} methods to modify the extras.
2553 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002554 * 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 -07002555 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2556 *
2557 * @param extras The extras associated with this {@code Connection}.
2558 */
2559 public final void setExtras(@Nullable Bundle extras) {
2560 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002561
2562 // Add/replace any new or changed extras values.
2563 putExtras(extras);
2564
2565 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2566 // the current one and remove any keys that went away.
2567 if (mPreviousExtraKeys != null) {
2568 List<String> toRemove = new ArrayList<String>();
2569 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002570 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002571 toRemove.add(oldKey);
2572 }
2573 }
2574 if (!toRemove.isEmpty()) {
2575 removeExtras(toRemove);
2576 }
2577 }
2578
2579 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2580 // called we can see if the caller has removed any extras values.
2581 if (mPreviousExtraKeys == null) {
2582 mPreviousExtraKeys = new ArraySet<String>();
2583 }
2584 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002585 if (extras != null) {
2586 mPreviousExtraKeys.addAll(extras.keySet());
2587 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002588 }
2589
2590 /**
2591 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2592 * added.
2593 * <p>
2594 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2595 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2596 *
2597 * @param extras The extras to add.
2598 */
2599 public final void putExtras(@NonNull Bundle extras) {
2600 checkImmutable();
2601 if (extras == null) {
2602 return;
2603 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002604 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2605 // the listeners.
2606 Bundle listenerExtras;
2607 synchronized (mExtrasLock) {
2608 if (mExtras == null) {
2609 mExtras = new Bundle();
2610 }
2611 mExtras.putAll(extras);
2612 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002613 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002614 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002615 // Create a new clone of the extras for each listener so that they don't clobber
2616 // each other
2617 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002618 }
2619 }
2620
2621 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002622 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002623 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002624 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002625 */
2626 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002627 synchronized (mExtrasLock) {
2628 if (mExtras != null) {
2629 for (String key : keys) {
2630 mExtras.remove(key);
2631 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002632 }
2633 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002634 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002635 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002636 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002637 }
2638 }
2639
2640 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002641 * Removes extras from this {@code Connection}.
2642 *
2643 * @param keys The keys of the extras to remove.
2644 */
2645 public final void removeExtras(String ... keys) {
2646 removeExtras(Arrays.asList(keys));
2647 }
2648
2649 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002650 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2651 * be change to the {@link #getCallAudioState()}.
2652 * <p>
2653 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2654 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2655 * <p>
2656 * See also {@link InCallService#setAudioRoute(int)}.
2657 *
2658 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2659 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2660 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2661 */
2662 public final void setAudioRoute(int route) {
2663 for (Listener l : mListeners) {
Hall Liua98f58b2017-11-07 17:59:28 -08002664 l.onAudioRouteChanged(this, route, null);
2665 }
2666 }
2667
2668 /**
Hall Liua98f58b2017-11-07 17:59:28 -08002669 * Request audio routing to a specific bluetooth device. Calling this method may result in
2670 * the device routing audio to a different bluetooth device than the one specified if the
2671 * bluetooth stack is unable to route audio to the requested device.
2672 * A list of available devices can be obtained via
2673 * {@link CallAudioState#getSupportedBluetoothDevices()}
2674 *
2675 * <p>
2676 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2677 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2678 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002679 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2680 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b2017-11-07 17:59:28 -08002681 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002682 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b2017-11-07 17:59:28 -08002683 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002684 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2685 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002686 }
2687 }
2688
2689 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002690 * Informs listeners that a previously requested RTT session via
2691 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002692 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002693 */
2694 public final void sendRttInitiationSuccess() {
2695 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2696 }
2697
2698 /**
2699 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002700 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002701 * has failed.
2702 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2703 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002704 */
2705 public final void sendRttInitiationFailure(int reason) {
2706 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2707 }
2708
2709 /**
2710 * Informs listeners that a currently active RTT session has been terminated by the remote
2711 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002712 */
2713 public final void sendRttSessionRemotelyTerminated() {
2714 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2715 }
2716
2717 /**
2718 * Informs listeners that the remote side of the call has requested an upgrade to include an
2719 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002720 */
2721 public final void sendRemoteRttRequest() {
2722 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2723 }
2724
2725 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002726 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002727 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002728 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002729 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2730 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002731 */
Yorke Lee4af59352015-05-13 14:14:54 -07002732 @SystemApi
2733 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002734 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002735
2736 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002737 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2738 *
2739 * @param state The new connection audio state.
2740 */
2741 public void onCallAudioStateChanged(CallAudioState state) {}
2742
2743 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002744 * Notifies this Connection of an internal state change. This method is called after the
2745 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002746 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002747 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002748 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002749 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002750
2751 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002752 * Notifies this Connection of a request to play a DTMF tone.
2753 *
2754 * @param c A DTMF character.
2755 */
Santos Cordonf2951102014-07-20 19:06:29 -07002756 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002757
2758 /**
2759 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2760 */
Santos Cordonf2951102014-07-20 19:06:29 -07002761 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002762
2763 /**
2764 * Notifies this Connection of a request to disconnect.
2765 */
Santos Cordonf2951102014-07-20 19:06:29 -07002766 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002767
2768 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002769 * Notifies this Connection of a request to disconnect a participant of the conference managed
2770 * by the connection.
2771 *
2772 * @param endpoint the {@link Uri} of the participant to disconnect.
2773 * @hide
2774 */
2775 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2776
2777 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002778 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002779 */
Santos Cordonf2951102014-07-20 19:06:29 -07002780 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002781
2782 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002783 * Notifies this Connection of a request to abort.
2784 */
Santos Cordonf2951102014-07-20 19:06:29 -07002785 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002786
2787 /**
2788 * Notifies this Connection of a request to hold.
2789 */
Santos Cordonf2951102014-07-20 19:06:29 -07002790 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002791
2792 /**
2793 * Notifies this Connection of a request to exit a hold state.
2794 */
Santos Cordonf2951102014-07-20 19:06:29 -07002795 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002796
2797 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002798 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002799 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002800 * <p>
2801 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2802 * the default dialer's {@link InCallService}.
2803 * <p>
2804 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2805 * Telecom framework may request that the call is answered in the following circumstances:
2806 * <ul>
2807 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2808 * <li>A car mode {@link InCallService} is in use which has declared
2809 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2810 * {@link InCallService} will be able to see calls from self-managed
2811 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2812 * behalf.</li>
2813 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002814 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002815 */
Santos Cordonf2951102014-07-20 19:06:29 -07002816 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002817
2818 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002819 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002820 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002821 * <p>
2822 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2823 * the default dialer's {@link InCallService}.
2824 * <p>
2825 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2826 * Telecom framework may request that the call is answered in the following circumstances:
2827 * <ul>
2828 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2829 * <li>A car mode {@link InCallService} is in use which has declared
2830 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2831 * {@link InCallService} will be able to see calls from self-managed
2832 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2833 * behalf.</li>
2834 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002835 */
2836 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002837 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002838 }
2839
2840 /**
2841 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302842 * a request to deflect.
2843 */
2844 public void onDeflect(Uri address) {}
2845
2846 /**
2847 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002848 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002849 * <p>
2850 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2851 * the default dialer's {@link InCallService}.
2852 * <p>
2853 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2854 * Telecom framework may request that the call is rejected in the following circumstances:
2855 * <ul>
2856 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2857 * <li>A car mode {@link InCallService} is in use which has declared
2858 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2859 * {@link InCallService} will be able to see calls from self-managed
2860 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2861 * behalf.</li>
2862 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002863 */
Santos Cordonf2951102014-07-20 19:06:29 -07002864 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002865
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002866 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002867 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2868 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002869 */
2870 public void onReject(String replyMessage) {}
2871
2872 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002873 * Notifies this Connection of a request to silence the ringer.
2874 * <p>
2875 * The ringer may be silenced by any of the following methods:
2876 * <ul>
2877 * <li>{@link TelecomManager#silenceRinger()}</li>
2878 * <li>The user presses the volume-down button while a call is ringing.</li>
2879 * </ul>
2880 * <p>
2881 * Self-managed {@link ConnectionService} implementations should override this method in their
2882 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2883 * your app set the ringtone as part of the incoming call {@link Notification} (see
2884 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2885 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2886 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2887 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002888 */
2889 public void onSilence() {}
2890
2891 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002892 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2893 */
Santos Cordonf2951102014-07-20 19:06:29 -07002894 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002895
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002896 /**
2897 * Notifies this Connection of a request to pull an external call to the local device.
2898 * <p>
2899 * The {@link InCallService} issues a request to pull an external call to the local device via
2900 * {@link Call#pullExternalCall()}.
2901 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002902 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2903 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002904 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002905 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002906 */
2907 public void onPullExternalCall() {}
2908
2909 /**
2910 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2911 * <p>
2912 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2913 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002914 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2915 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2916 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2917 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2918 * not aware of.
2919 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002920 * See also {@link Call#sendCallEvent(String, Bundle)}.
2921 *
2922 * @param event The call event.
2923 * @param extras Extras associated with the call event.
2924 */
2925 public void onCallEvent(String event, Bundle extras) {}
2926
Tyler Gunndee56a82016-03-23 16:06:34 -07002927 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002928 * Notifies this {@link Connection} that a handover has completed.
2929 * <p>
2930 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2931 * Bundle)} on the initiating side of the handover, and
2932 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2933 */
2934 public void onHandoverComplete() {}
2935
2936 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002937 * Notifies this {@link Connection} of a change to the extras made outside the
2938 * {@link ConnectionService}.
2939 * <p>
2940 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2941 * the {@link android.telecom.Call#putExtras(Bundle)} and
2942 * {@link Call#removeExtras(List)}.
2943 *
2944 * @param extras The new extras bundle.
2945 */
2946 public void onExtrasChanged(Bundle extras) {}
2947
Tyler Gunnf5035432017-01-09 09:43:12 -08002948 /**
2949 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2950 * displaying its incoming call user interface for the {@link Connection}.
2951 * <p>
2952 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2953 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2954 * should show its own incoming call user interface.
2955 * <p>
2956 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002957 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2958 * Telecom framework will display its own incoming call user interface to allow the user to
2959 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2960 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002961 * <p>
2962 * You should trigger the display of the incoming call user interface for your application by
2963 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002964 *
2965 * In your application code, you should create a {@link android.app.NotificationChannel} for
2966 * incoming call notifications from your app:
2967 * <pre><code>
2968 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2969 * NotificationManager.IMPORTANCE_MAX);
2970 * // other channel setup stuff goes here.
2971 *
2972 * // We'll use the default system ringtone for our incoming call notification channel. You can
2973 * // use your own audio resource here.
2974 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2975 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2976 * // Setting the AudioAttributes is important as it identifies the purpose of your
2977 * // notification sound.
2978 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2979 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2980 * .build());
2981 *
2982 * NotificationManager mgr = getSystemService(NotificationManager.class);
2983 * mgr.createNotificationChannel(channel);
2984 * </code></pre>
2985 * When it comes time to post a notification for your incoming call, ensure it uses your
2986 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002987 * <pre><code>
2988 * // Create an intent which triggers your fullscreen incoming call user interface.
2989 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2990 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2991 * intent.setClass(context, YourIncomingCallActivity.class);
2992 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2993 *
2994 * // Build the notification as an ongoing high priority item; this ensures it will show as
2995 * // a heads up notification which slides down over top of the current content.
2996 * final Notification.Builder builder = new Notification.Builder(context);
2997 * builder.setOngoing(true);
2998 * builder.setPriority(Notification.PRIORITY_HIGH);
2999 *
3000 * // Set notification content intent to take user to fullscreen UI if user taps on the
3001 * // notification body.
3002 * builder.setContentIntent(pendingIntent);
3003 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3004 * // manager deems it appropriate.
3005 * builder.setFullScreenIntent(pendingIntent, true);
3006 *
3007 * // Setup notification content.
3008 * builder.setSmallIcon( yourIconResourceId );
3009 * builder.setContentTitle("Your notification title");
3010 * builder.setContentText("Your notification content.");
3011 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003012 * // Set notification as insistent to cause your ringtone to loop.
3013 * Notification notification = builder.build();
3014 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003015 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003016 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003017 * NotificationManager notificationManager = mContext.getSystemService(
3018 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003019 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003020 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003021 */
3022 public void onShowIncomingCallUi() {}
3023
Hall Liub64ac4c2017-02-06 10:49:48 -08003024 /**
3025 * Notifies this {@link Connection} that the user has requested an RTT session.
3026 * The connection service should call {@link #sendRttInitiationSuccess} or
3027 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3028 * request, respectively.
3029 * @param rttTextStream The object that should be used to send text to or receive text from
3030 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003031 */
3032 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3033
3034 /**
3035 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3036 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003037 */
3038 public void onStopRtt() {}
3039
3040 /**
3041 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3042 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3043 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3044 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003045 * @param rttTextStream The object that should be used to send text to or receive text from
3046 * the in-call app.
3047 */
3048 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3049
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003050 static String toLogSafePhoneNumber(String number) {
3051 // For unknown number, log empty string.
3052 if (number == null) {
3053 return "";
3054 }
3055
3056 if (PII_DEBUG) {
3057 // When PII_DEBUG is true we emit PII.
3058 return number;
3059 }
3060
3061 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3062 // sanitized phone numbers.
3063 StringBuilder builder = new StringBuilder();
3064 for (int i = 0; i < number.length(); i++) {
3065 char c = number.charAt(i);
3066 if (c == '-' || c == '@' || c == '.') {
3067 builder.append(c);
3068 } else {
3069 builder.append('x');
3070 }
3071 }
3072 return builder.toString();
3073 }
3074
Ihab Awad542e0ea2014-05-16 10:22:16 -07003075 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003076 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003077 if (mState == STATE_DISCONNECTED && mState != state) {
3078 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003079 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003080 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003081 if (mState != state) {
3082 Log.d(this, "setState: %s", stateToString(state));
3083 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003084 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003085 for (Listener l : mListeners) {
3086 l.onStateChanged(this, state);
3087 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003088 }
3089 }
3090
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003091 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003092 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003093 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3094 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003095 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003096 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003097
3098 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003099 if (mImmutable) {
3100 throw new UnsupportedOperationException("Connection is immutable");
3101 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003102 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003103 }
3104
Evan Charltonbf11f982014-07-20 22:06:28 -07003105 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003106 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003107 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3108 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003109 * <p>
3110 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3111 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003112 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003113 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003114 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003115 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003116 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3117 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003118 }
3119
Evan Charltonbf11f982014-07-20 22:06:28 -07003120 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003121 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3122 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3123 * this should never be un-@hide-den.
3124 *
3125 * @hide
3126 */
3127 public void checkImmutable() {}
3128
3129 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003130 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3131 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3132 * that state. This connection should not be used for anything, and no other
3133 * {@code Connection}s should be attempted.
3134 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003135 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003136 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003137 * @return A {@code Connection} which indicates that the underlying connection should
3138 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003139 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003140 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003141 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003142 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003143
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003144 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003145 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003146 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003147 }
3148 }
3149
Santos Cordon823fd3c2014-08-07 18:35:18 -07003150 private final void fireConferenceChanged() {
3151 for (Listener l : mListeners) {
3152 l.onConferenceChanged(this, mConference);
3153 }
3154 }
3155
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003156 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003157 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003158 if (c instanceof Connection) {
3159 Connection connection = (Connection) c;
3160 connection.removeConnectionListener(mConnectionDeathListener);
3161 } else if (c instanceof Conference) {
3162 Conference conference = (Conference) c;
3163 conference.removeListener(mConferenceDeathListener);
3164 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003165 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003166 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003167 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003168
3169 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003170 * Handles a change to extras received from Telecom.
3171 *
3172 * @param extras The new extras.
3173 * @hide
3174 */
3175 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003176 Bundle b = null;
3177 synchronized (mExtrasLock) {
3178 mExtras = extras;
3179 if (mExtras != null) {
3180 b = new Bundle(mExtras);
3181 }
3182 }
3183 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003184 }
3185
3186 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003187 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3188 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003189 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003190 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003191 for (Listener l : mListeners) {
3192 l.onConferenceMergeFailed(this);
3193 }
3194 }
3195
3196 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303197 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3198 * changed due to an emergency call being redialed.
3199 * @param pHandle The new PhoneAccountHandle for this connection.
3200 * @hide
3201 */
3202 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3203 for (Listener l : mListeners) {
3204 l.onPhoneAccountChanged(this, pHandle);
3205 }
3206 }
3207
3208 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003209 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003210 * <p>
3211 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3212 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003213 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003214 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003215 * @hide
3216 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003217 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003218 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003219 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003220 if (mPhoneAccountHandle != phoneAccountHandle) {
3221 mPhoneAccountHandle = phoneAccountHandle;
3222 notifyPhoneAccountChanged(phoneAccountHandle);
3223 }
3224 }
3225
3226 /**
3227 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003228 * <p>
3229 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3230 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003231 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003232 * @return the phone account handle specified via
3233 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003234 * @hide
3235 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003236 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003237 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003238 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003239 return mPhoneAccountHandle;
3240 }
3241
3242 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003243 * Sends an event associated with this {@code Connection} with associated event extras to the
3244 * {@link InCallService}.
3245 * <p>
3246 * Connection events are used to communicate point in time information from a
3247 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3248 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3249 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3250 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3251 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3252 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3253 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3254 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3255 * <p>
3256 * Events are exposed to {@link InCallService} implementations via
3257 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3258 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003259 * 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 -07003260 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3261 * some events altogether.
3262 * <p>
3263 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3264 * conflicts between {@link ConnectionService} implementations. Further, custom
3265 * {@link ConnectionService} implementations shall not re-purpose events in the
3266 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3267 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3268 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3269 * {@code com.example.extra.MY_EXTRA}).
3270 * <p>
3271 * When defining events and the associated extras, it is important to keep their behavior
3272 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3273 * events/extras should me maintained to ensure backwards compatibility with older
3274 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003275 *
3276 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003277 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003278 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003279 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003280 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003281 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003282 }
3283 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003284
3285 /**
3286 * @return The direction of the call.
3287 * @hide
3288 */
3289 public final @Call.Details.CallDirection int getCallDirection() {
3290 return mCallDirection;
3291 }
3292
3293 /**
3294 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003295 * <p>
3296 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3297 * call direction.
3298 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003299 * @param callDirection The direction of this connection.
3300 * @hide
3301 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003302 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003303 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003304 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3305 mCallDirection = callDirection;
3306 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003307}