blob: e2f5d0bba0b0a8da2925b9032540d0a80d0d0ea4 [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 Liua98f58b52017-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;
Wei Huang7f7f72e2018-05-30 19:21:36 +080038import android.telephony.ServiceState;
39import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Youming Yed6de26e2019-01-30 11:20:35 -080043import com.android.internal.os.SomeArgs;
44import com.android.internal.telecom.IVideoCallback;
45import com.android.internal.telecom.IVideoProvider;
46
Hall Liua549fed2018-02-09 16:40:03 -080047import java.io.FileInputStream;
48import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080049import java.io.IOException;
50import java.io.InputStreamReader;
51import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070052import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070053import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070054import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070055import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070056import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070057import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070058import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070059
60/**
Santos Cordon895d4b82015-06-25 16:41:48 -070061 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
62 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070063 * <p>
64 * Implementations create a custom subclass of {@code Connection} and return it to the framework
65 * as the return value of
66 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
67 * or
68 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
69 * Implementations are then responsible for updating the state of the {@code Connection}, and
70 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
71 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070072 * <p>
73 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
74 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
75 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
76 * {@code Connection} instance.
77 * <p>
78 * Basic call support requires overriding the following methods: {@link #onAnswer()},
79 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
80 * <p>
81 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
82 * {@link #onUnhold()} methods should be overridden to provide hold support for the
83 * {@code Connection}.
84 * <p>
85 * Where a {@code Connection} supports a variation of video calling (e.g. the
86 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
87 * to support answering a call as a video call.
88 * <p>
89 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
90 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
91 * support for pulling the external call.
92 * <p>
93 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
94 * overridden.
95 * <p>
96 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
97 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
98 * for example, call events from a {@link InCallService} are handled,
99 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
100 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
101 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
102 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700104public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * The connection is initializing. This is generally the first state for a {@code Connection}
108 * returned by a {@link ConnectionService}.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_INITIALIZING = 0;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * The connection is new and not connected.
114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 public static final int STATE_NEW = 1;
116
Santos Cordon895d4b82015-06-25 16:41:48 -0700117 /**
118 * An incoming connection is in the ringing state. During this state, the user's ringer or
119 * vibration feature will be activated.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_RINGING = 2;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * An outgoing connection is in the dialing state. In this state the other party has not yet
125 * answered the call and the user traditionally hears a ringback tone.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_DIALING = 3;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * A connection is active. Both parties are connected to the call and can actively communicate.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_ACTIVE = 4;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
135 * A connection is on hold.
136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final int STATE_HOLDING = 5;
138
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 /**
140 * A connection has been disconnected. This is the final state once the user has been
141 * disconnected from a call either locally, remotely or by an error in the service.
142 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700143 public static final int STATE_DISCONNECTED = 6;
144
Santos Cordon895d4b82015-06-25 16:41:48 -0700145 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700146 * The state of an external connection which is in the process of being pulled from a remote
147 * device to the local device.
148 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700149 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700150 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
151 */
152 public static final int STATE_PULLING_CALL = 7;
153
154 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700155 * Connection can currently be put on hold or unheld. This is distinct from
156 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
157 * it does not at the moment support the function. This can be true while the call is in the
158 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
159 * display a disabled 'hold' button.
160 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161 public static final int CAPABILITY_HOLD = 0x00000001;
162
163 /** Connection supports the hold feature. */
164 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
165
166 /**
167 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
168 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
169 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
170 * capability allows a merge button to be shown while the conference is in the foreground
171 * of the in-call UI.
172 * <p>
173 * This is only intended for use by a {@link Conference}.
174 */
175 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
176
177 /**
178 * Connections within a conference can be swapped between foreground and background.
179 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
180 * <p>
181 * This is only intended for use by a {@link Conference}.
182 */
183 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
184
185 /**
186 * @hide
187 */
188 public static final int CAPABILITY_UNUSED = 0x00000010;
189
190 /** Connection supports responding via text option. */
191 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
192
193 /** Connection can be muted. */
194 public static final int CAPABILITY_MUTE = 0x00000040;
195
196 /**
197 * Connection supports conference management. This capability only applies to
198 * {@link Conference}s which can have {@link Connection}s as children.
199 */
200 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211
212 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700215 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800217
218 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800220 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
222
223 /**
224 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 */
226 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
227
228 /**
229 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700230 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700231 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700232 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800233
234 /**
235 * Connection is able to be separated from its parent {@code Conference}, if any.
236 */
237 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
238
239 /**
240 * Connection is able to be individually disconnected when in a {@code Conference}.
241 */
242 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
243
244 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246 * @hide
247 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800249
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * @hide
253 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255
256 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 * @hide
259 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700260 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261
Tyler Gunn068085b2015-02-06 13:56:52 -0800262 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700263 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800264 * @hide
265 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700266 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Tyler Gunn96d6c402015-03-18 12:39:23 -0700268 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500269 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700270 * <p>
271 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
272 * place as soon as the device answers the call, but prior to it being connected. This is an
273 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500274 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700275 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700276 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700277 @TestApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700278 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800279
Rekha Kumar07366812015-03-24 16:42:31 -0700280 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700281 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800282 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
283 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
284 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700285 */
286 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
287
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700288 /**
289 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700290 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700291 */
292 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
293
Tyler Gunnd4091732015-06-29 09:15:37 -0700294 /**
295 * For a conference, indicates the conference will not have child connections.
296 * <p>
297 * An example of a conference with child connections is a GSM conference call, where the radio
298 * retains connections to the individual participants of the conference. Another example is an
299 * IMS conference call where conference event package functionality is supported; in this case
300 * the conference server ensures the radio is aware of the participants in the conference, which
301 * are represented by child connections.
302 * <p>
303 * An example of a conference with no child connections is an IMS conference call with no
304 * conference event package support. Such a conference is represented by the radio as a single
305 * connection to the IMS conference server.
306 * <p>
307 * Indicating whether a conference has children or not is important to help user interfaces
308 * visually represent a conference. A conference with no children, for example, will have the
309 * conference connection shown in the list of calls on a Bluetooth device, where if the
310 * conference has children, only the children will be shown in the list of calls on a Bluetooth
311 * device.
312 * @hide
313 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700314 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700315 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700316 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
317
Bryce Lee81901682015-08-28 16:38:02 -0700318 /**
319 * Indicates that the connection itself wants to handle any sort of reply response, rather than
320 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700321 */
322 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
323
Tyler Gunnf97a0092016-01-19 15:59:34 -0800324 /**
325 * When set, prevents a video call from being downgraded to an audio-only call.
326 * <p>
327 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
328 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
329 * downgraded from a video call back to a VideoState of
330 * {@link VideoProfile#STATE_AUDIO_ONLY}.
331 * <p>
332 * Intuitively, a call which can be downgraded to audio should also have local and remote
333 * video
334 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
335 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
336 */
337 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
338
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700339 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700340 * When set for an external connection, indicates that this {@code Connection} can be pulled
341 * from a remote device to the current device.
342 * <p>
343 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
344 * is set.
345 */
346 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
347
Pooja Jaind34698d2017-12-28 14:15:31 +0530348 /** Call supports the deflect feature. */
349 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
350
Tyler Gunn720c6642016-03-22 09:02:47 -0700351 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530352 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700353 //**********************************************************************************************
354
355 /**
356 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700357 * <p>
358 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700359 * @hide
360 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700361 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700362 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700363 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700364
365 /**
366 * Whether the call is a generic conference, where we do not know the precise state of
367 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700368 * <p>
369 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700370 * @hide
371 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700372 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700373 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700374 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
375
376 /**
377 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700378 * <p>
379 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
380 * implies something like AMR wideband, but the interpretation of when a call is considered high
381 * definition is left to the {@link ConnectionService} to decide.
382 * <p>
383 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700384 */
385 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
386
387 /**
388 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700389 * <p>
390 * Used to indicate that a call is taking place over WIFI versus a carrier network.
391 * <p>
392 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700393 */
394 public static final int PROPERTY_WIFI = 1<<3;
395
396 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700397 * When set, indicates that the {@code Connection} does not actually exist locally for the
398 * {@link ConnectionService}.
399 * <p>
400 * Consider, for example, a scenario where a user has two devices with the same phone number.
401 * When a user places a call on one devices, the telephony stack can represent that call on the
402 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700403 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700404 * <p>
405 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
406 * external connections. Only those {@link InCallService}s which have the
407 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
408 * manifest will see external connections.
409 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700410 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700411
Brad Ebinger15847072016-05-18 11:08:36 -0700412 /**
413 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
414 */
415 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700416
Hall Liu9f332c72016-07-14 15:37:37 -0700417 /**
418 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700419 * <p>
420 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
421 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700422 * @hide
423 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700424 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700425 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700426 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
427
Tyler Gunnf5035432017-01-09 09:43:12 -0800428 /**
429 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
430 * {@link ConnectionService}.
431 * <p>
432 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
433 */
434 public static final int PROPERTY_SELF_MANAGED = 1<<7;
435
Hall Liu95d55872017-01-25 17:12:49 -0800436 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800437 * Set by the framework to indicate that a connection has an active RTT session associated with
438 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800439 */
440 public static final int PROPERTY_IS_RTT = 1 << 8;
441
Eric Erfanian62706c52017-12-06 16:27:53 -0800442 /**
443 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700444 * <p>
445 * This is used for outgoing calls.
446 *
447 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800448 */
449 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
450
Tyler Gunn5bd90852018-09-21 09:37:07 -0700451 /**
452 * Set by the framework to indicate that the network has identified a Connection as an emergency
453 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700454 * <p>
455 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
456 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700457 */
458 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
459
Tyler Gunnac60f952019-05-31 07:23:16 -0700460 /**
461 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
462 * than the current one. Used in scenarios where the conference originator is the remote device
463 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700464 * <p>
465 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700466 * @hide
467 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700468 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700469 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700470 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
471
Tyler Gunn96d6c402015-03-18 12:39:23 -0700472 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700473 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700474 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800475
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700476 /**
477 * Connection extra key used to store the last forwarded number associated with the current
478 * connection. Used to communicate to the user interface that the connection was forwarded via
479 * the specified number.
480 */
481 public static final String EXTRA_LAST_FORWARDED_NUMBER =
482 "android.telecom.extra.LAST_FORWARDED_NUMBER";
483
484 /**
485 * Connection extra key used to store a child number associated with the current connection.
486 * Used to communicate to the user interface that the connection was received via
487 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
488 * address.
489 */
490 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
491
492 /**
493 * Connection extra key used to store the subject for an incoming call. The user interface can
494 * query this extra and display its contents for incoming calls. Will only be used if the
495 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
496 */
497 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
498
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800499 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700500 * Boolean connection extra key set on a {@link Connection} in
501 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
502 * current active foreground call to be dropped.
503 */
504 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
505 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
506
507 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700508 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
509 * state to indicate the name of the third-party app which is responsible for the current
510 * foreground call.
511 * <p>
512 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
513 * is able to inform the user that answering the new incoming call will cause a call owned by
514 * another app to be dropped when the incoming call is answered.
515 */
516 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
517 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
518
519 /**
Hall Liu10208662016-06-15 17:55:00 -0700520 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700521 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700522 * <p>
523 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
524 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700525 * @hide
526 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700527 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700528 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700529 public static final String EXTRA_DISABLE_ADD_CALL =
530 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700531
532 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700533 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
534 * original Connection ID associated with the connection. Used in
535 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
536 * connection/conference added via
537 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
538 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
539 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
540 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
541 * be a way to ensure that we don't add the connection again as a duplicate.
542 * <p>
543 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
544 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
545 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
546 * in a new {@link Connection} which it adds to Telecom via
547 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
548 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
549 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
550 * ID it originally referred to the connection as. Thus Telecom needs to know that the
551 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700552 * <p>
553 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
554 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700555 * @hide
556 */
557 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
558 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
559
560 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700561 * Boolean connection extra key set on the extras passed to
562 * {@link Connection#sendConnectionEvent} which indicates that audio is present
563 * on the RTT call when the extra value is true.
564 */
565 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
566 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
567
568 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800569 * Connection event used to inform Telecom that it should play the on hold tone. This is used
570 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700571 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800572 */
573 public static final String EVENT_ON_HOLD_TONE_START =
574 "android.telecom.event.ON_HOLD_TONE_START";
575
576 /**
577 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
578 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700579 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800580 */
581 public static final String EVENT_ON_HOLD_TONE_END =
582 "android.telecom.event.ON_HOLD_TONE_END";
583
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700584 /**
585 * Connection event used to inform {@link InCallService}s when pulling of an external call has
586 * failed. The user interface should inform the user of the error.
587 * <p>
588 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
589 * API is called on a {@link Call} with the properties
590 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
591 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
592 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700593 * <p>
594 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
595 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700596 */
597 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
598
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700599 /**
600 * Connection event used to inform {@link InCallService}s when the merging of two calls has
601 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700602 * <p>
603 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
604 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700605 */
606 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
607
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700608 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700609 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700610 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700611 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
612 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700613 */
614 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
615
616 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700617 * Connection event used to inform {@link InCallService}s when the process of merging a
618 * Connection into a conference has begun.
619 * <p>
620 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
621 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700622 */
623 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
624
625 /**
626 * Connection event used to inform {@link InCallService}s when the process of merging a
627 * Connection into a conference has completed.
628 * <p>
629 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
630 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700631 */
632 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
633
634 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700635 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
636 * the remote party.
637 * <p>
638 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
639 * call is being held locally on the device. When a capable {@link ConnectionService} receives
640 * signalling to indicate that the remote party has put the call on hold, it can send this
641 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700642 */
643 public static final String EVENT_CALL_REMOTELY_HELD =
644 "android.telecom.event.CALL_REMOTELY_HELD";
645
646 /**
647 * Connection event used to inform {@link InCallService}s when a call which was remotely held
648 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
649 * <p>
650 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
651 * call is being held locally on the device. When a capable {@link ConnectionService} receives
652 * signalling to indicate that the remote party has taken the call off hold, it can send this
653 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700654 */
655 public static final String EVENT_CALL_REMOTELY_UNHELD =
656 "android.telecom.event.CALL_REMOTELY_UNHELD";
657
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700658 /**
659 * Connection event used to inform an {@link InCallService} which initiated a call handover via
660 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
661 * successfully completed.
662 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700663 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
664 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700665 */
666 public static final String EVENT_HANDOVER_COMPLETE =
667 "android.telecom.event.HANDOVER_COMPLETE";
668
669 /**
670 * Connection event used to inform an {@link InCallService} which initiated a call handover via
671 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
672 * to complete.
673 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700674 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
675 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700676 */
677 public static final String EVENT_HANDOVER_FAILED =
678 "android.telecom.event.HANDOVER_FAILED";
679
shilub7ec9a02018-11-09 15:52:04 -0800680 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000681 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800682 */
683 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
684
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700685 /**
686 * Connection event used to inform an {@link InCallService} that the RTT audio indication
687 * has changed.
688 */
689 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
690 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
691
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700692 // Flag controlling whether PII is emitted into the logs
693 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
694
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800695 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700696 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
697 *
698 * @param capabilities A capability bit field.
699 * @return A human readable string representation.
700 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800701 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 return capabilitiesToStringInternal(capabilities, true /* isLong */);
703 }
704
705 /**
706 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
707 * string.
708 *
709 * @param capabilities A capability bit field.
710 * @return A human readable string representation.
711 * @hide
712 */
713 public static String capabilitiesToStringShort(int capabilities) {
714 return capabilitiesToStringInternal(capabilities, false /* isLong */);
715 }
716
717 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800718 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append("[");
720 if (isLong) {
721 builder.append("Capabilities:");
722 }
723
Tyler Gunnc63f9082019-10-15 13:19:26 -0700724 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700727 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800729 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700730 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800732 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700733 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700736 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700739 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700742 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800744 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700745 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700747 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700748 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700750 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700751 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
752 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700753 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800754 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700755 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700756 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700757 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700758 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700759 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700760 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700761 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
762 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700763 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800764 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700765 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
766 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700767 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800768 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700769 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700770 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500771 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700772 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700773 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700774 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700775 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700776 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700777 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700778 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
779 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700780 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700781 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700782 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
783 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700784 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700785 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700786 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700787 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700788 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700789 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530790 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
791 }
Bryce Lee81901682015-08-28 16:38:02 -0700792
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800793 builder.append("]");
794 return builder.toString();
795 }
796
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700797 /**
798 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
799 *
800 * @param properties A property bit field.
801 * @return A human readable string representation.
802 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700803 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700804 return propertiesToStringInternal(properties, true /* isLong */);
805 }
806
807 /**
808 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
809 *
810 * @param properties A property bit field.
811 * @return A human readable string representation.
812 * @hide
813 */
814 public static String propertiesToStringShort(int properties) {
815 return propertiesToStringInternal(properties, false /* isLong */);
816 }
817
818 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700819 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700820 builder.append("[");
821 if (isLong) {
822 builder.append("Properties:");
823 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700824
Tyler Gunnc63f9082019-10-15 13:19:26 -0700825 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800826 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
827 }
828
Tyler Gunnc63f9082019-10-15 13:19:26 -0700829 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700830 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700831 }
832
Tyler Gunnc63f9082019-10-15 13:19:26 -0700833 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700834 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700835 }
836
Tyler Gunnc63f9082019-10-15 13:19:26 -0700837 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700838 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700839 }
840
Tyler Gunnc63f9082019-10-15 13:19:26 -0700841 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700842 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700843 }
844
Tyler Gunnc63f9082019-10-15 13:19:26 -0700845 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700846 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700847 }
848
Tyler Gunnc63f9082019-10-15 13:19:26 -0700849 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700850 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700851 }
852
Tyler Gunnc63f9082019-10-15 13:19:26 -0700853 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800854 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
855 }
856
Tyler Gunnc63f9082019-10-15 13:19:26 -0700857 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
858 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700859 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
860 }
861
Tyler Gunnc63f9082019-10-15 13:19:26 -0700862 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700863 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
864 }
865
Tyler Gunn720c6642016-03-22 09:02:47 -0700866 builder.append("]");
867 return builder.toString();
868 }
869
Sailesh Nepal091768c2014-06-30 15:15:23 -0700870 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700871 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700872 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700873 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700874 public void onCallerDisplayNameChanged(
875 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700876 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700877 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700878 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800879 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700880 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700881 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800882 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700883 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800884 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 public void onVideoProviderChanged(
886 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700887 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
888 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800889 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700890 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700891 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700892 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700893 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700894 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700895 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800896 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800897 public void onRttInitiationSuccess(Connection c) {}
898 public void onRttInitiationFailure(Connection c, int reason) {}
899 public void onRttSessionRemotelyTerminated(Connection c) {}
900 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530901 /** @hide */
902 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800903 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700904 }
905
Tyler Gunnb702ef82015-05-29 11:51:53 -0700906 /**
Hall Liu95d55872017-01-25 17:12:49 -0800907 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800908 */
909 public static final class RttTextStream {
910 private static final int READ_BUFFER_SIZE = 1000;
911 private final InputStreamReader mPipeFromInCall;
912 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800913 private final ParcelFileDescriptor mFdFromInCall;
914 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700915
916 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800917 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
918
919 /**
920 * @hide
921 */
922 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800923 mFdFromInCall = fromInCall;
924 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700925 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700926
927 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800928 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700929 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800930 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800931 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800932 }
933
934 /**
935 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
936 * RTT transmits text in real-time, this method should be called as often as text snippets
937 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800938 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800939 * This method is not thread-safe -- calling it from multiple threads simultaneously may
940 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800941 *
Hall Liu95d55872017-01-25 17:12:49 -0800942 * @param input The message to send to the in-call app.
943 */
944 public void write(String input) throws IOException {
945 mPipeToInCall.write(input);
946 mPipeToInCall.flush();
947 }
948
949
950 /**
951 * Reads a string from the in-call app, blocking if there is no data available. Returns
952 * {@code null} if the RTT conversation has been terminated and there is no further data
953 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800954 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800955 * This method is not thread-safe -- calling it from multiple threads simultaneously may
956 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800957 *
Hall Liu95d55872017-01-25 17:12:49 -0800958 * @return A string containing text entered by the user, or {@code null} if the
959 * conversation has been terminated or if there was an error while reading.
960 */
Hall Liuffa4a812017-03-02 16:11:00 -0800961 public String read() throws IOException {
962 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
963 if (numRead < 0) {
964 return null;
965 }
966 return new String(mReadBuffer, 0, numRead);
967 }
968
969 /**
970 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
971 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800972 *
Hall Liuffa4a812017-03-02 16:11:00 -0800973 * @return A string containing text entered by the user, or {@code null} if the user has
974 * not entered any new text yet.
975 */
976 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700977 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800978 return read();
979 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800980 return null;
981 }
982 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800983
984 /** @hide */
985 public ParcelFileDescriptor getFdFromInCall() {
986 return mFdFromInCall;
987 }
988
989 /** @hide */
990 public ParcelFileDescriptor getFdToInCall() {
991 return mFdToInCall;
992 }
993 }
994
995 /**
996 * Provides constants to represent the results of responses to session modify requests sent via
997 * {@link Call#sendRttRequest()}
998 */
999 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001000 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001001 /**
1002 * Session modify request was successful.
1003 */
1004 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1005
1006 /**
1007 * Session modify request failed.
1008 */
1009 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1010
1011 /**
1012 * Session modify request ignored due to invalid parameters.
1013 */
1014 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1015
1016 /**
1017 * Session modify request timed out.
1018 */
1019 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1020
1021 /**
1022 * Session modify request rejected by remote user.
1023 */
1024 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001025 }
1026
1027 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001028 * Provides a means of controlling the video session associated with a {@link Connection}.
1029 * <p>
1030 * Implementations create a custom subclass of {@link VideoProvider} and the
1031 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1032 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1033 * should set the {@link VideoProvider}.
1034 * <p>
1035 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1036 * {@link InCallService} implementations to issue requests related to the video session;
1037 * it provides a means for the {@link ConnectionService} to report events and information
1038 * related to the video session to Telecom and the {@link InCallService} implementations.
1039 * <p>
1040 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1041 * {@link android.telecom.InCallService.VideoCall}.
1042 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 /**
1045 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001046 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001047 */
1048 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001049
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001051 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1052 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 */
1054 public static final int SESSION_EVENT_RX_RESUME = 2;
1055
1056 /**
1057 * Video transmission has begun. This occurs after a negotiated start of video transmission
1058 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001059 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 */
1061 public static final int SESSION_EVENT_TX_START = 3;
1062
1063 /**
1064 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1065 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001066 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001067 */
1068 public static final int SESSION_EVENT_TX_STOP = 4;
1069
1070 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001071 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001072 * this as a cue to inform the user the camera is not available.
1073 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 */
1075 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1076
1077 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001078 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001079 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001080 * the camera has become available again.
1081 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001082 */
1083 public static final int SESSION_EVENT_CAMERA_READY = 6;
1084
1085 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001086 * Session event raised by Telecom when
1087 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1088 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1089 * @see #handleCallSessionEvent(int)
1090 */
1091 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1092
1093 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001094 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001095 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 */
1097 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1098
1099 /**
1100 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001101 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 */
1103 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1104
1105 /**
1106 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001107 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 */
1109 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1110
Rekha Kumar07366812015-03-24 16:42:31 -07001111 /**
1112 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001113 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001114 */
1115 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1116
1117 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001118 * Session modify request rejected by remote user.
1119 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001120 */
1121 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1122
Tyler Gunn75958422015-04-15 14:23:42 -07001123 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 private static final int MSG_SET_CAMERA = 2;
1125 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1126 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1127 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1128 private static final int MSG_SET_ZOOM = 6;
1129 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1130 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1131 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001132 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001134 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001135
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001136 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1137 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1138 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1139 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1140 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1141 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001142 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1143 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001144 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1145
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001146 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001147 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001148
1149 /**
1150 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001151 *
1152 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1153 * load factor before resizing, 1 means we only expect a single thread to
1154 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001155 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001156 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1157 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001158
1159 /**
1160 * Default handler used to consolidate binder method calls onto a single thread.
1161 */
1162 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001163 public VideoProviderHandler() {
1164 super();
1165 }
1166
1167 public VideoProviderHandler(Looper looper) {
1168 super(looper);
1169 }
1170
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001171 @Override
1172 public void handleMessage(Message msg) {
1173 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001174 case MSG_ADD_VIDEO_CALLBACK: {
1175 IBinder binder = (IBinder) msg.obj;
1176 IVideoCallback callback = IVideoCallback.Stub
1177 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001178 if (callback == null) {
1179 Log.w(this, "addVideoProvider - skipped; callback is null.");
1180 break;
1181 }
1182
Tyler Gunn75958422015-04-15 14:23:42 -07001183 if (mVideoCallbacks.containsKey(binder)) {
1184 Log.i(this, "addVideoProvider - skipped; already present.");
1185 break;
1186 }
1187 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001188 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001189 }
1190 case MSG_REMOVE_VIDEO_CALLBACK: {
1191 IBinder binder = (IBinder) msg.obj;
1192 IVideoCallback callback = IVideoCallback.Stub
1193 .asInterface((IBinder) msg.obj);
1194 if (!mVideoCallbacks.containsKey(binder)) {
1195 Log.i(this, "removeVideoProvider - skipped; not present.");
1196 break;
1197 }
1198 mVideoCallbacks.remove(binder);
1199 break;
1200 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001202 {
1203 SomeArgs args = (SomeArgs) msg.obj;
1204 try {
1205 onSetCamera((String) args.arg1);
1206 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001207 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001208 } finally {
1209 args.recycle();
1210 }
1211 }
1212 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 case MSG_SET_PREVIEW_SURFACE:
1214 onSetPreviewSurface((Surface) msg.obj);
1215 break;
1216 case MSG_SET_DISPLAY_SURFACE:
1217 onSetDisplaySurface((Surface) msg.obj);
1218 break;
1219 case MSG_SET_DEVICE_ORIENTATION:
1220 onSetDeviceOrientation(msg.arg1);
1221 break;
1222 case MSG_SET_ZOOM:
1223 onSetZoom((Float) msg.obj);
1224 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001225 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1226 SomeArgs args = (SomeArgs) msg.obj;
1227 try {
1228 onSendSessionModifyRequest((VideoProfile) args.arg1,
1229 (VideoProfile) args.arg2);
1230 } finally {
1231 args.recycle();
1232 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001234 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001235 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1236 onSendSessionModifyResponse((VideoProfile) msg.obj);
1237 break;
1238 case MSG_REQUEST_CAMERA_CAPABILITIES:
1239 onRequestCameraCapabilities();
1240 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001241 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1242 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001243 break;
1244 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001245 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 break;
1247 default:
1248 break;
1249 }
1250 }
1251 }
1252
1253 /**
1254 * IVideoProvider stub implementation.
1255 */
1256 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001257 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001259 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1260 }
1261
1262 public void removeVideoCallback(IBinder videoCallbackBinder) {
1263 mMessageHandler.obtainMessage(
1264 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001265 }
1266
Tyler Gunn159f35c2017-03-02 09:28:37 -08001267 public void setCamera(String cameraId, String callingPackageName,
1268 int targetSdkVersion) {
1269
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001270 SomeArgs args = SomeArgs.obtain();
1271 args.arg1 = cameraId;
1272 // Propagate the calling package; originally determined in
1273 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1274 // process.
1275 args.arg2 = callingPackageName;
1276 // Pass along the uid and pid of the calling app; this gets lost when we put the
1277 // message onto the handler. These are required for Telecom to perform a permission
1278 // check to see if the calling app is able to use the camera.
1279 args.argi1 = Binder.getCallingUid();
1280 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001281 // Pass along the target SDK version of the calling InCallService. This is used to
1282 // maintain backwards compatibility of the API for older callers.
1283 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001284 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001285 }
1286
1287 public void setPreviewSurface(Surface surface) {
1288 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1289 }
1290
1291 public void setDisplaySurface(Surface surface) {
1292 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1293 }
1294
1295 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001296 mMessageHandler.obtainMessage(
1297 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001298 }
1299
1300 public void setZoom(float value) {
1301 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1302 }
1303
Tyler Gunn45382162015-05-06 08:52:27 -07001304 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1305 SomeArgs args = SomeArgs.obtain();
1306 args.arg1 = fromProfile;
1307 args.arg2 = toProfile;
1308 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001309 }
1310
1311 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1312 mMessageHandler.obtainMessage(
1313 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1314 }
1315
1316 public void requestCameraCapabilities() {
1317 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1318 }
1319
1320 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001321 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001322 }
1323
Yorke Lee32f24732015-05-12 16:18:03 -07001324 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1326 }
1327 }
1328
1329 public VideoProvider() {
1330 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001331 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001332 }
1333
1334 /**
1335 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1336 *
1337 * @param looper The looper.
1338 * @hide
1339 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001340 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001341 public VideoProvider(Looper looper) {
1342 mBinder = new VideoProvider.VideoProviderBinder();
1343 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001344 }
1345
1346 /**
1347 * Returns binder object which can be used across IPC methods.
1348 * @hide
1349 */
1350 public final IVideoProvider getInterface() {
1351 return mBinder;
1352 }
1353
1354 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001355 * Sets the camera to be used for the outgoing video.
1356 * <p>
1357 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1358 * camera via
1359 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1360 * <p>
1361 * Sent from the {@link InCallService} via
1362 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001363 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001364 * @param cameraId The id of the camera (use ids as reported by
1365 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366 */
1367 public abstract void onSetCamera(String cameraId);
1368
1369 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001370 * Sets the camera to be used for the outgoing video.
1371 * <p>
1372 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1373 * camera via
1374 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1375 * <p>
1376 * This prototype is used internally to ensure that the calling package name, UID and PID
1377 * are sent to Telecom so that can perform a camera permission check on the caller.
1378 * <p>
1379 * Sent from the {@link InCallService} via
1380 * {@link InCallService.VideoCall#setCamera(String)}.
1381 *
1382 * @param cameraId The id of the camera (use ids as reported by
1383 * {@link CameraManager#getCameraIdList()}).
1384 * @param callingPackageName The AppOpps package name of the caller.
1385 * @param callingUid The UID of the caller.
1386 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001387 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001388 * @hide
1389 */
1390 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001391 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001392
1393 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 * Sets the surface to be used for displaying a preview of what the user's camera is
1395 * currently capturing. When video transmission is enabled, this is the video signal which
1396 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * <p>
1398 * Sent from the {@link InCallService} via
1399 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001401 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 */
1403 public abstract void onSetPreviewSurface(Surface surface);
1404
1405 /**
1406 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001407 * <p>
1408 * Sent from the {@link InCallService} via
1409 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001410 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001411 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001412 */
1413 public abstract void onSetDisplaySurface(Surface surface);
1414
1415 /**
1416 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1417 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001418 * <p>
1419 * Sent from the {@link InCallService} via
1420 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001421 *
1422 * @param rotation The device orientation, in degrees.
1423 */
1424 public abstract void onSetDeviceOrientation(int rotation);
1425
1426 /**
1427 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * <p>
1429 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430 *
1431 * @param value The camera zoom ratio.
1432 */
1433 public abstract void onSetZoom(float value);
1434
1435 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001436 * Issues a request to modify the properties of the current video session.
1437 * <p>
1438 * Example scenarios include: requesting an audio-only call to be upgraded to a
1439 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1440 * when the {@link InCallService} is no longer the foreground application.
1441 * <p>
1442 * If the {@link VideoProvider} determines a request to be invalid, it should call
1443 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1444 * invalid request back to the {@link InCallService}.
1445 * <p>
1446 * Where a request requires confirmation from the user of the peer device, the
1447 * {@link VideoProvider} must communicate the request to the peer device and handle the
1448 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1449 * is used to inform the {@link InCallService} of the result of the request.
1450 * <p>
1451 * Sent from the {@link InCallService} via
1452 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001454 * @param fromProfile The video profile prior to the request.
1455 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 */
Tyler Gunn45382162015-05-06 08:52:27 -07001457 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1458 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 /**
1461 * Provides a response to a request to change the current video session properties.
1462 * <p>
1463 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1464 * video call, could decline the request and keep the call as audio-only.
1465 * In such a scenario, the {@code responseProfile} would have a video state of
1466 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1467 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1468 * <p>
1469 * Sent from the {@link InCallService} via
1470 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1471 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1472 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001474 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001475 */
1476 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1477
1478 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001479 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1480 * <p>
1481 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1482 * camera via
1483 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1484 * <p>
1485 * Sent from the {@link InCallService} via
1486 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 */
1488 public abstract void onRequestCameraCapabilities();
1489
1490 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001491 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1492 * video component of the current {@link Connection}.
1493 * <p>
1494 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1495 * via {@link VideoProvider#setCallDataUsage(long)}.
1496 * <p>
1497 * Sent from the {@link InCallService} via
1498 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001499 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001500 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001501
1502 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001503 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1504 * the peer device when the video signal is paused.
1505 * <p>
1506 * Sent from the {@link InCallService} via
1507 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 *
1509 * @param uri URI of image to display.
1510 */
Yorke Lee32f24732015-05-12 16:18:03 -07001511 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512
1513 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001514 * Used to inform listening {@link InCallService} implementations when the
1515 * {@link VideoProvider} receives a session modification request.
1516 * <p>
1517 * Received by the {@link InCallService} via
1518 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001519 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001520 * @param videoProfile The requested video profile.
1521 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 */
1523 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001524 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001525 for (IVideoCallback callback : mVideoCallbacks.values()) {
1526 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001527 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001528 } catch (RemoteException ignored) {
1529 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001530 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 }
1532 }
1533 }
1534
1535 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001536 * Used to inform listening {@link InCallService} implementations when the
1537 * {@link VideoProvider} receives a response to a session modification request.
1538 * <p>
1539 * Received by the {@link InCallService} via
1540 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1541 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 *
1543 * @param status Status of the session modify request. Valid values are
1544 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1545 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001546 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1547 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1548 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1549 * @param requestedProfile The original request which was sent to the peer device.
1550 * @param responseProfile The actual profile changes agreed to by the peer device.
1551 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 */
1553 public void receiveSessionModifyResponse(int status,
1554 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001555 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001556 for (IVideoCallback callback : mVideoCallbacks.values()) {
1557 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001558 callback.receiveSessionModifyResponse(status, requestedProfile,
1559 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001560 } catch (RemoteException ignored) {
1561 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001562 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001563 }
1564 }
1565 }
1566
1567 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001568 * Used to inform listening {@link InCallService} implementations when the
1569 * {@link VideoProvider} reports a call session event.
1570 * <p>
1571 * Received by the {@link InCallService} via
1572 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001573 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001574 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1575 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1576 * {@link VideoProvider#SESSION_EVENT_TX_START},
1577 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1578 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001579 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1580 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001581 */
1582 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001583 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001584 for (IVideoCallback callback : mVideoCallbacks.values()) {
1585 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001586 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001587 } catch (RemoteException ignored) {
1588 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001589 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001590 }
1591 }
1592 }
1593
1594 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001595 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1596 * peer's video have changed.
1597 * <p>
1598 * This could occur if, for example, the peer rotates their device, changing the aspect
1599 * ratio of the video, or if the user switches between the back and front cameras.
1600 * <p>
1601 * Received by the {@link InCallService} via
1602 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 *
1604 * @param width The updated peer video width.
1605 * @param height The updated peer video height.
1606 */
1607 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001608 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001609 for (IVideoCallback callback : mVideoCallbacks.values()) {
1610 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001611 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001612 } catch (RemoteException ignored) {
1613 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001614 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 }
1616 }
1617 }
1618
1619 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001620 * Used to inform listening {@link InCallService} implementations when the data usage of the
1621 * video associated with the current {@link Connection} has changed.
1622 * <p>
1623 * This could be in response to a preview request via
1624 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001625 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1626 * 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 -07001627 * <p>
1628 * Received by the {@link InCallService} via
1629 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001630 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001631 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1632 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 */
Yorke Lee32f24732015-05-12 16:18:03 -07001634 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001635 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001636 for (IVideoCallback callback : mVideoCallbacks.values()) {
1637 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001638 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001639 } catch (RemoteException ignored) {
1640 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001641 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001642 }
1643 }
1644 }
1645
1646 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001647 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001649 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001650 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1651 * @hide
1652 */
1653 public void changeCallDataUsage(long dataUsage) {
1654 setCallDataUsage(dataUsage);
1655 }
1656
1657 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001658 * Used to inform listening {@link InCallService} implementations when the capabilities of
1659 * the current camera have changed.
1660 * <p>
1661 * The {@link VideoProvider} should call this in response to
1662 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1663 * changed via {@link VideoProvider#onSetCamera(String)}.
1664 * <p>
1665 * Received by the {@link InCallService} via
1666 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1667 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001668 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001669 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001670 */
Yorke Lee400470f2015-05-12 13:31:25 -07001671 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001672 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001673 for (IVideoCallback callback : mVideoCallbacks.values()) {
1674 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001675 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001676 } catch (RemoteException ignored) {
1677 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001678 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001679 }
1680 }
1681 }
Rekha Kumar07366812015-03-24 16:42:31 -07001682
1683 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001684 * Used to inform listening {@link InCallService} implementations when the video quality
1685 * of the call has changed.
1686 * <p>
1687 * Received by the {@link InCallService} via
1688 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001689 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001690 * @param videoQuality The updated video quality. Valid values:
1691 * {@link VideoProfile#QUALITY_HIGH},
1692 * {@link VideoProfile#QUALITY_MEDIUM},
1693 * {@link VideoProfile#QUALITY_LOW},
1694 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001695 */
1696 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001697 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001698 for (IVideoCallback callback : mVideoCallbacks.values()) {
1699 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001700 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001701 } catch (RemoteException ignored) {
1702 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001703 }
Rekha Kumar07366812015-03-24 16:42:31 -07001704 }
1705 }
1706 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001707
1708 /**
1709 * Returns a string representation of a call session event.
1710 *
1711 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1712 * @return String representation of the call session event.
1713 * @hide
1714 */
1715 public static String sessionEventToString(int event) {
1716 switch (event) {
1717 case SESSION_EVENT_CAMERA_FAILURE:
1718 return SESSION_EVENT_CAMERA_FAILURE_STR;
1719 case SESSION_EVENT_CAMERA_READY:
1720 return SESSION_EVENT_CAMERA_READY_STR;
1721 case SESSION_EVENT_RX_PAUSE:
1722 return SESSION_EVENT_RX_PAUSE_STR;
1723 case SESSION_EVENT_RX_RESUME:
1724 return SESSION_EVENT_RX_RESUME_STR;
1725 case SESSION_EVENT_TX_START:
1726 return SESSION_EVENT_TX_START_STR;
1727 case SESSION_EVENT_TX_STOP:
1728 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001729 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1730 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001731 default:
1732 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1733 }
1734 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001735 }
1736
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001737 private final Listener mConnectionDeathListener = new Listener() {
1738 @Override
1739 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001740 if (mConferenceables.remove(c)) {
1741 fireOnConferenceableConnectionsChanged();
1742 }
1743 }
1744 };
1745
1746 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1747 @Override
1748 public void onDestroyed(Conference c) {
1749 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001750 fireOnConferenceableConnectionsChanged();
1751 }
1752 }
1753 };
1754
Jay Shrauner229e3822014-08-15 09:23:07 -07001755 /**
1756 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1757 * load factor before resizing, 1 means we only expect a single thread to
1758 * access the map so make only a single shard
1759 */
1760 private final Set<Listener> mListeners = Collections.newSetFromMap(
1761 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001762 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1763 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001764 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001765
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001766 // The internal telecom call ID associated with this connection.
1767 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001768 // The PhoneAccountHandle associated with this connection.
1769 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001770 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001771 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001772 private Uri mAddress;
1773 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001774 private String mCallerDisplayName;
1775 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001776 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001777 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001778 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001779 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001780 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001781 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001782 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001783 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001784 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001785 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001786 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001787 private Conference mConference;
1788 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001789 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001790 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001791 /**
1792 * The direction of the connection; used where an existing connection is created and we need to
1793 * communicate to Telecom whether its incoming or outgoing.
1794 */
1795 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001796
1797 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001798 * Tracks the key set for the extras bundle provided on the last invocation of
1799 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1800 * keys which were set previously but are no longer present in the replacement Bundle.
1801 */
1802 private Set<String> mPreviousExtraKeys;
1803
1804 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805 * Create a new Connection.
1806 */
Santos Cordonf2951102014-07-20 19:06:29 -07001807 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001808
1809 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001810 * Returns the Telecom internal call ID associated with this connection. Should only be used
1811 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001812 * <p>
1813 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1814 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001815 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001816 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001817 * @hide
1818 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001819 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001820 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001821 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001822 return mTelecomCallId;
1823 }
1824
1825 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001826 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001827 */
Andrew Lee100e2932014-09-08 15:34:24 -07001828 public final Uri getAddress() {
1829 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001830 }
1831
1832 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001833 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001834 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001835 */
Andrew Lee100e2932014-09-08 15:34:24 -07001836 public final int getAddressPresentation() {
1837 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001838 }
1839
1840 /**
1841 * @return The caller display name (CNAP).
1842 */
1843 public final String getCallerDisplayName() {
1844 return mCallerDisplayName;
1845 }
1846
1847 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001848 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001849 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001850 */
1851 public final int getCallerDisplayNamePresentation() {
1852 return mCallerDisplayNamePresentation;
1853 }
1854
1855 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001856 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001857 */
1858 public final int getState() {
1859 return mState;
1860 }
1861
1862 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001863 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001864 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1865 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1866 * {@link VideoProfile#STATE_TX_ENABLED},
1867 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001868 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001869 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001870 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001871 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001872 return mVideoState;
1873 }
1874
1875 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001876 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001877 * being routed by the system. This is {@code null} if this Connection
1878 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001879 * @deprecated Use {@link #getCallAudioState()} instead.
1880 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001881 */
Yorke Lee4af59352015-05-13 14:14:54 -07001882 @SystemApi
1883 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001884 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001885 if (mCallAudioState == null) {
1886 return null;
1887 }
Yorke Lee4af59352015-05-13 14:14:54 -07001888 return new AudioState(mCallAudioState);
1889 }
1890
1891 /**
1892 * @return The audio state of the connection, describing how its audio is currently
1893 * being routed by the system. This is {@code null} if this Connection
1894 * does not directly know about its audio state.
1895 */
1896 public final CallAudioState getCallAudioState() {
1897 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001898 }
1899
1900 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001901 * @return The conference that this connection is a part of. Null if it is not part of any
1902 * conference.
1903 */
1904 public final Conference getConference() {
1905 return mConference;
1906 }
1907
1908 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001909 * Returns whether this connection is requesting that the system play a ringback tone
1910 * on its behalf.
1911 */
Andrew Lee100e2932014-09-08 15:34:24 -07001912 public final boolean isRingbackRequested() {
1913 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001914 }
1915
1916 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001917 * @return True if the connection's audio mode is VOIP.
1918 */
1919 public final boolean getAudioModeIsVoip() {
1920 return mAudioModeIsVoip;
1921 }
1922
1923 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001924 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1925 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1926 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001927 * <p>
1928 * Note: This is an implementation detail specific to IMS conference calls over a mobile
1929 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07001930 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001931 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
1932 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07001933 *
1934 * @hide
1935 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001936 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001937 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07001938 public final long getConnectTimeMillis() {
1939 return mConnectTimeMillis;
1940 }
1941
1942 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001943 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1944 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1945 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001946 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001947 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1948 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001949 * <p>
1950 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001951 *
1952 * @return The time at which the {@link Connection} was connected.
1953 *
1954 * @hide
1955 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001956 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001957 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001958 public final long getConnectElapsedTimeMillis() {
1959 return mConnectElapsedTimeMillis;
1960 }
1961
1962 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001963 * @return The status hints for this connection.
1964 */
1965 public final StatusHints getStatusHints() {
1966 return mStatusHints;
1967 }
1968
1969 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001970 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001971 * <p>
1972 * Extras should be updated using {@link #putExtras(Bundle)}.
1973 * <p>
1974 * Telecom or an {@link InCallService} can also update the extras via
1975 * {@link android.telecom.Call#putExtras(Bundle)}, and
1976 * {@link Call#removeExtras(List)}.
1977 * <p>
1978 * The connection is notified of changes to the extras made by Telecom or an
1979 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001980 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001981 * @return The extras associated with this connection.
1982 */
1983 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001984 Bundle extras = null;
1985 synchronized (mExtrasLock) {
1986 if (mExtras != null) {
1987 extras = new Bundle(mExtras);
1988 }
1989 }
1990 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001991 }
1992
1993 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001994 * Assign a listener to be notified of state changes.
1995 *
1996 * @param l A listener.
1997 * @return This Connection.
1998 *
1999 * @hide
2000 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002001 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002002 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002003 return this;
2004 }
2005
2006 /**
2007 * Remove a previously assigned listener that was being notified of state changes.
2008 *
2009 * @param l A Listener.
2010 * @return This Connection.
2011 *
2012 * @hide
2013 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002014 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002015 if (l != null) {
2016 mListeners.remove(l);
2017 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002018 return this;
2019 }
2020
2021 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002022 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002023 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002024 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002025 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002026 }
2027
2028 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002029 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2030 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002031 * <p>
2032 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2033 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2034 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002035 *
2036 * @param callId The telecom call ID.
2037 * @hide
2038 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002039 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002040 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002041 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002042 mTelecomCallId = callId;
2043 }
2044
2045 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002046 * Inform this Connection that the state of its audio output has been changed externally.
2047 *
2048 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002049 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002050 */
Yorke Lee4af59352015-05-13 14:14:54 -07002051 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002052 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002053 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002054 mCallAudioState = state;
2055 onAudioStateChanged(getAudioState());
2056 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002057 }
2058
2059 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002060 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002061 * @return A string representation of the value.
2062 */
2063 public static String stateToString(int state) {
2064 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002065 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002066 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002067 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002068 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002069 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002070 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002071 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002072 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002073 case STATE_PULLING_CALL:
2074 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002075 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002076 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002077 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002078 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002079 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002080 return "DISCONNECTED";
2081 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002082 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002083 return "UNKNOWN";
2084 }
2085 }
2086
2087 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002088 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002089 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002090 public final int getConnectionCapabilities() {
2091 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002092 }
2093
2094 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002095 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2096 */
2097 public final int getConnectionProperties() {
2098 return mConnectionProperties;
2099 }
2100
2101 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002102 * Returns the connection's supported audio routes.
2103 *
2104 * @hide
2105 */
2106 public final int getSupportedAudioRoutes() {
2107 return mSupportedAudioRoutes;
2108 }
2109
2110 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002111 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002112 *
Andrew Lee100e2932014-09-08 15:34:24 -07002113 * @param address The new address.
2114 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002115 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116 */
Andrew Lee100e2932014-09-08 15:34:24 -07002117 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002119 Log.d(this, "setAddress %s", address);
2120 mAddress = address;
2121 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002122 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002123 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002124 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002125 }
2126
2127 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002128 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002129 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002130 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002131 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002132 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002133 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002134 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002135 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002136 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002137 mCallerDisplayName = callerDisplayName;
2138 mCallerDisplayNamePresentation = presentation;
2139 for (Listener l : mListeners) {
2140 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2141 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002142 }
2143
2144 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002145 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002146 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2147 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2148 * {@link VideoProfile#STATE_TX_ENABLED},
2149 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002150 *
2151 * @param videoState The new video state.
2152 */
2153 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002154 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002155 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002156 mVideoState = videoState;
2157 for (Listener l : mListeners) {
2158 l.onVideoStateChanged(this, mVideoState);
2159 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002160 }
2161
2162 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002163 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 * communicate).
2165 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002166 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002167 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002168 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002169 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002170 }
2171
2172 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002173 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002174 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002175 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002176 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002177 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002178 }
2179
2180 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002181 * Sets state to initializing (this Connection is not yet ready to be used).
2182 */
2183 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002184 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002185 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002186 }
2187
2188 /**
2189 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2190 */
2191 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002192 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002193 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002194 }
2195
2196 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002197 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002198 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002199 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002200 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002201 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002202 }
2203
2204 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002205 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2206 * device). Only applicable for {@link Connection}s with
2207 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2208 */
2209 public final void setPulling() {
2210 checkImmutable();
2211 setState(STATE_PULLING_CALL);
2212 }
2213
2214 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002215 * Sets state to be on hold.
2216 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002217 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002218 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002219 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002220 }
2221
2222 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002223 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002224 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002225 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002226 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002227 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002228 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002229 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002230 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002231 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002232 }
2233
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002234 public final VideoProvider getVideoProvider() {
2235 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002236 }
2237
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002238 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002239 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002240 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002241 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002242 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002243 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002244 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002245 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002246 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002247 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002248 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002249 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002250 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002251 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002252 }
2253
2254 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002255 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2256 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2257 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2258 * to send an {@link #onPostDialContinue(boolean)} signal.
2259 *
2260 * @param remaining The DTMF character sequence remaining to be emitted once the
2261 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2262 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002263 */
2264 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002265 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002266 for (Listener l : mListeners) {
2267 l.onPostDialWait(this, remaining);
2268 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002269 }
2270
2271 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002272 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2273 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002274 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002275 *
2276 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002277 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002278 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002279 checkImmutable();
2280 for (Listener l : mListeners) {
2281 l.onPostDialChar(this, nextChar);
2282 }
2283 }
2284
2285 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002286 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002287 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002288 *
2289 * @param ringback Whether the ringback tone is to be played.
2290 */
Andrew Lee100e2932014-09-08 15:34:24 -07002291 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002292 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002293 if (mRingbackRequested != ringback) {
2294 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002295 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002296 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002297 }
2298 }
Ihab Awadf8358972014-05-28 16:46:42 -07002299 }
2300
2301 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002302 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002303 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002304 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002305 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002306 public final void setConnectionCapabilities(int connectionCapabilities) {
2307 checkImmutable();
2308 if (mConnectionCapabilities != connectionCapabilities) {
2309 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002310 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002311 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002312 }
2313 }
Santos Cordonb6939982014-06-04 20:20:58 -07002314 }
2315
2316 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002317 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2318 *
2319 * @param connectionProperties The new connection properties.
2320 */
2321 public final void setConnectionProperties(int connectionProperties) {
2322 checkImmutable();
2323 if (mConnectionProperties != connectionProperties) {
2324 mConnectionProperties = connectionProperties;
2325 for (Listener l : mListeners) {
2326 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2327 }
2328 }
2329 }
2330
2331 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002332 * Sets the supported audio routes.
2333 *
2334 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2335 * See {@link CallAudioState}
2336 * @hide
2337 */
2338 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2339 if ((supportedAudioRoutes
2340 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2341 throw new IllegalArgumentException(
2342 "supported audio routes must include either speaker or earpiece");
2343 }
2344
2345 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2346 mSupportedAudioRoutes = supportedAudioRoutes;
2347 for (Listener l : mListeners) {
2348 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2349 }
2350 }
2351 }
2352
2353 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002354 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002355 */
Evan Charlton36a71342014-07-19 16:31:02 -07002356 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002357 for (Listener l : mListeners) {
2358 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002359 }
Santos Cordonb6939982014-06-04 20:20:58 -07002360 }
2361
2362 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002363 * Requests that the framework use VOIP audio mode for this connection.
2364 *
2365 * @param isVoip True if the audio mode is VOIP.
2366 */
2367 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002368 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002369 mAudioModeIsVoip = isVoip;
2370 for (Listener l : mListeners) {
2371 l.onAudioModeIsVoipChanged(this, isVoip);
2372 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002373 }
2374
2375 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002376 * Sets the time at which a call became active on this Connection. This is set only
2377 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002378 * <p>
2379 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002380 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002381 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2382 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002383 *
2384 * @hide
2385 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002386 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002387 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002388 public final void setConnectTimeMillis(long connectTimeMillis) {
2389 mConnectTimeMillis = connectTimeMillis;
2390 }
2391
2392 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002393 * Sets the time at which a call became active on this Connection. This is set only
2394 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002395 * <p>
2396 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002397 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2398 * {@link SystemClock#elapsedRealtime()}.
2399 *
2400 * @hide
2401 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002402 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002403 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002404 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002405 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2406 }
2407
2408 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002409 * Sets the label and icon status to display in the in-call UI.
2410 *
2411 * @param statusHints The status label and icon to set.
2412 */
2413 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002414 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002415 mStatusHints = statusHints;
2416 for (Listener l : mListeners) {
2417 l.onStatusHintsChanged(this, statusHints);
2418 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002419 }
2420
2421 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002422 * Sets the connections with which this connection can be conferenced.
2423 *
2424 * @param conferenceableConnections The set of connections this connection can conference with.
2425 */
2426 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002427 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002428 clearConferenceableList();
2429 for (Connection c : conferenceableConnections) {
2430 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2431 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002432 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002433 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002434 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002435 }
2436 }
2437 fireOnConferenceableConnectionsChanged();
2438 }
2439
2440 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002441 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2442 * or conferences with which this connection can be conferenced.
2443 *
2444 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002445 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002446 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002447 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002448 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002449 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2450 // small amount of items here.
2451 if (!mConferenceables.contains(c)) {
2452 if (c instanceof Connection) {
2453 Connection connection = (Connection) c;
2454 connection.addConnectionListener(mConnectionDeathListener);
2455 } else if (c instanceof Conference) {
2456 Conference conference = (Conference) c;
2457 conference.addListener(mConferenceDeathListener);
2458 }
2459 mConferenceables.add(c);
2460 }
2461 }
2462 fireOnConferenceableConnectionsChanged();
2463 }
2464
2465 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002466 * Resets the CDMA connection time.
2467 * <p>
2468 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002469 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002470 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002471 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002472 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002473 public final void resetConnectionTime() {
2474 for (Listener l : mListeners) {
2475 l.onConnectionTimeReset(this);
2476 }
2477 }
2478
2479 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002480 * Returns the connections or conferences with which this connection can be conferenced.
2481 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002482 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002483 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002484 }
2485
Yorke Lee53463962015-08-04 16:07:19 -07002486 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002487 * @hide
2488 */
2489 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002490 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002491 if (mConnectionService != null) {
2492 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2493 "which is already associated with another ConnectionService.");
2494 } else {
2495 mConnectionService = connectionService;
2496 }
2497 }
2498
2499 /**
2500 * @hide
2501 */
2502 public final void unsetConnectionService(ConnectionService connectionService) {
2503 if (mConnectionService != connectionService) {
2504 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2505 "that does not belong to the ConnectionService.");
2506 } else {
2507 mConnectionService = null;
2508 }
2509 }
2510
2511 /**
2512 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002513 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002514 *
2515 * @param conference The conference.
2516 * @return {@code true} if the conference was successfully set.
2517 * @hide
2518 */
2519 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002520 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002521 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002522 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002523 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002524 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2525 fireConferenceChanged();
2526 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002527 return true;
2528 }
2529 return false;
2530 }
2531
2532 /**
2533 * Resets the conference that this connection is a part of.
2534 * @hide
2535 */
2536 public final void resetConference() {
2537 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002538 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002539 mConference = null;
2540 fireConferenceChanged();
2541 }
2542 }
2543
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002544 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002545 * Set some extras that can be associated with this {@code Connection}.
2546 * <p>
2547 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2548 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2549 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002550 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2551 * {@link #removeExtras(String...)} methods to modify the extras.
2552 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002553 * 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 -07002554 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2555 *
2556 * @param extras The extras associated with this {@code Connection}.
2557 */
2558 public final void setExtras(@Nullable Bundle extras) {
2559 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002560
2561 // Add/replace any new or changed extras values.
2562 putExtras(extras);
2563
2564 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2565 // the current one and remove any keys that went away.
2566 if (mPreviousExtraKeys != null) {
2567 List<String> toRemove = new ArrayList<String>();
2568 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002569 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002570 toRemove.add(oldKey);
2571 }
2572 }
2573 if (!toRemove.isEmpty()) {
2574 removeExtras(toRemove);
2575 }
2576 }
2577
2578 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2579 // called we can see if the caller has removed any extras values.
2580 if (mPreviousExtraKeys == null) {
2581 mPreviousExtraKeys = new ArraySet<String>();
2582 }
2583 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002584 if (extras != null) {
2585 mPreviousExtraKeys.addAll(extras.keySet());
2586 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002587 }
2588
2589 /**
2590 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2591 * added.
2592 * <p>
2593 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2594 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2595 *
2596 * @param extras The extras to add.
2597 */
2598 public final void putExtras(@NonNull Bundle extras) {
2599 checkImmutable();
2600 if (extras == null) {
2601 return;
2602 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002603 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2604 // the listeners.
2605 Bundle listenerExtras;
2606 synchronized (mExtrasLock) {
2607 if (mExtras == null) {
2608 mExtras = new Bundle();
2609 }
2610 mExtras.putAll(extras);
2611 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002612 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002613 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002614 // Create a new clone of the extras for each listener so that they don't clobber
2615 // each other
2616 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002617 }
2618 }
2619
2620 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002621 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002622 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002623 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002624 */
2625 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002626 synchronized (mExtrasLock) {
2627 if (mExtras != null) {
2628 for (String key : keys) {
2629 mExtras.remove(key);
2630 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002631 }
2632 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002633 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002634 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002635 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002636 }
2637 }
2638
2639 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002640 * Removes extras from this {@code Connection}.
2641 *
2642 * @param keys The keys of the extras to remove.
2643 */
2644 public final void removeExtras(String ... keys) {
2645 removeExtras(Arrays.asList(keys));
2646 }
2647
2648 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002649 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2650 * be change to the {@link #getCallAudioState()}.
2651 * <p>
2652 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2653 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2654 * <p>
2655 * See also {@link InCallService#setAudioRoute(int)}.
2656 *
2657 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2658 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2659 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2660 */
2661 public final void setAudioRoute(int route) {
2662 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002663 l.onAudioRouteChanged(this, route, null);
2664 }
2665 }
2666
2667 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002668 * Request audio routing to a specific bluetooth device. Calling this method may result in
2669 * the device routing audio to a different bluetooth device than the one specified if the
2670 * bluetooth stack is unable to route audio to the requested device.
2671 * A list of available devices can be obtained via
2672 * {@link CallAudioState#getSupportedBluetoothDevices()}
2673 *
2674 * <p>
2675 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2676 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2677 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002678 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2679 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002680 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002681 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002682 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002683 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2684 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002685 }
2686 }
2687
2688 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002689 * Informs listeners that a previously requested RTT session via
2690 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002691 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002692 */
2693 public final void sendRttInitiationSuccess() {
2694 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2695 }
2696
2697 /**
2698 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002699 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002700 * has failed.
2701 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2702 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002703 */
2704 public final void sendRttInitiationFailure(int reason) {
2705 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2706 }
2707
2708 /**
2709 * Informs listeners that a currently active RTT session has been terminated by the remote
2710 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002711 */
2712 public final void sendRttSessionRemotelyTerminated() {
2713 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2714 }
2715
2716 /**
2717 * Informs listeners that the remote side of the call has requested an upgrade to include an
2718 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002719 */
2720 public final void sendRemoteRttRequest() {
2721 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2722 }
2723
2724 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002725 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002726 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002727 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002728 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2729 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002730 */
Yorke Lee4af59352015-05-13 14:14:54 -07002731 @SystemApi
2732 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002733 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002734
2735 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002736 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2737 *
2738 * @param state The new connection audio state.
2739 */
2740 public void onCallAudioStateChanged(CallAudioState state) {}
2741
2742 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002743 * Notifies this Connection of an internal state change. This method is called after the
2744 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002745 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002746 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002747 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002748 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002749
2750 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002751 * Notifies this Connection of a request to play a DTMF tone.
2752 *
2753 * @param c A DTMF character.
2754 */
Santos Cordonf2951102014-07-20 19:06:29 -07002755 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002756
2757 /**
2758 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2759 */
Santos Cordonf2951102014-07-20 19:06:29 -07002760 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002761
2762 /**
2763 * Notifies this Connection of a request to disconnect.
2764 */
Santos Cordonf2951102014-07-20 19:06:29 -07002765 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002766
2767 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002768 * Notifies this Connection of a request to disconnect a participant of the conference managed
2769 * by the connection.
2770 *
2771 * @param endpoint the {@link Uri} of the participant to disconnect.
2772 * @hide
2773 */
2774 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2775
2776 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002777 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002778 */
Santos Cordonf2951102014-07-20 19:06:29 -07002779 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002780
2781 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002782 * Notifies this Connection of a request to abort.
2783 */
Santos Cordonf2951102014-07-20 19:06:29 -07002784 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002785
2786 /**
2787 * Notifies this Connection of a request to hold.
2788 */
Santos Cordonf2951102014-07-20 19:06:29 -07002789 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002790
2791 /**
2792 * Notifies this Connection of a request to exit a hold state.
2793 */
Santos Cordonf2951102014-07-20 19:06:29 -07002794 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002795
2796 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002797 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002798 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002799 * <p>
2800 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2801 * the default dialer's {@link InCallService}.
2802 * <p>
2803 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2804 * Telecom framework may request that the call is answered in the following circumstances:
2805 * <ul>
2806 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2807 * <li>A car mode {@link InCallService} is in use which has declared
2808 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2809 * {@link InCallService} will be able to see calls from self-managed
2810 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2811 * behalf.</li>
2812 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002813 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002814 */
Santos Cordonf2951102014-07-20 19:06:29 -07002815 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002816
2817 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002818 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002819 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002820 * <p>
2821 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2822 * the default dialer's {@link InCallService}.
2823 * <p>
2824 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2825 * Telecom framework may request that the call is answered in the following circumstances:
2826 * <ul>
2827 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2828 * <li>A car mode {@link InCallService} is in use which has declared
2829 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2830 * {@link InCallService} will be able to see calls from self-managed
2831 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2832 * behalf.</li>
2833 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002834 */
2835 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002836 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002837 }
2838
2839 /**
2840 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302841 * a request to deflect.
2842 */
2843 public void onDeflect(Uri address) {}
2844
2845 /**
2846 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002847 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002848 * <p>
2849 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2850 * the default dialer's {@link InCallService}.
2851 * <p>
2852 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2853 * Telecom framework may request that the call is rejected in the following circumstances:
2854 * <ul>
2855 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2856 * <li>A car mode {@link InCallService} is in use which has declared
2857 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2858 * {@link InCallService} will be able to see calls from self-managed
2859 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2860 * behalf.</li>
2861 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002862 */
Santos Cordonf2951102014-07-20 19:06:29 -07002863 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002864
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002865 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002866 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2867 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002868 */
2869 public void onReject(String replyMessage) {}
2870
2871 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002872 * Notifies this Connection of a request to silence the ringer.
2873 * <p>
2874 * The ringer may be silenced by any of the following methods:
2875 * <ul>
2876 * <li>{@link TelecomManager#silenceRinger()}</li>
2877 * <li>The user presses the volume-down button while a call is ringing.</li>
2878 * </ul>
2879 * <p>
2880 * Self-managed {@link ConnectionService} implementations should override this method in their
2881 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2882 * your app set the ringtone as part of the incoming call {@link Notification} (see
2883 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2884 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2885 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2886 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002887 */
2888 public void onSilence() {}
2889
2890 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002891 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2892 */
Santos Cordonf2951102014-07-20 19:06:29 -07002893 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002894
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002895 /**
2896 * Notifies this Connection of a request to pull an external call to the local device.
2897 * <p>
2898 * The {@link InCallService} issues a request to pull an external call to the local device via
2899 * {@link Call#pullExternalCall()}.
2900 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002901 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2902 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002903 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002904 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002905 */
2906 public void onPullExternalCall() {}
2907
2908 /**
2909 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2910 * <p>
2911 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2912 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002913 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2914 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2915 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2916 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2917 * not aware of.
2918 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002919 * See also {@link Call#sendCallEvent(String, Bundle)}.
2920 *
2921 * @param event The call event.
2922 * @param extras Extras associated with the call event.
2923 */
2924 public void onCallEvent(String event, Bundle extras) {}
2925
Tyler Gunndee56a82016-03-23 16:06:34 -07002926 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002927 * Notifies this {@link Connection} that a handover has completed.
2928 * <p>
2929 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2930 * Bundle)} on the initiating side of the handover, and
2931 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2932 */
2933 public void onHandoverComplete() {}
2934
2935 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002936 * Notifies this {@link Connection} of a change to the extras made outside the
2937 * {@link ConnectionService}.
2938 * <p>
2939 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2940 * the {@link android.telecom.Call#putExtras(Bundle)} and
2941 * {@link Call#removeExtras(List)}.
2942 *
2943 * @param extras The new extras bundle.
2944 */
2945 public void onExtrasChanged(Bundle extras) {}
2946
Tyler Gunnf5035432017-01-09 09:43:12 -08002947 /**
2948 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2949 * displaying its incoming call user interface for the {@link Connection}.
2950 * <p>
2951 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2952 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2953 * should show its own incoming call user interface.
2954 * <p>
2955 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002956 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2957 * Telecom framework will display its own incoming call user interface to allow the user to
2958 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2959 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002960 * <p>
2961 * You should trigger the display of the incoming call user interface for your application by
2962 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002963 *
2964 * In your application code, you should create a {@link android.app.NotificationChannel} for
2965 * incoming call notifications from your app:
2966 * <pre><code>
2967 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2968 * NotificationManager.IMPORTANCE_MAX);
2969 * // other channel setup stuff goes here.
2970 *
2971 * // We'll use the default system ringtone for our incoming call notification channel. You can
2972 * // use your own audio resource here.
2973 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2974 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2975 * // Setting the AudioAttributes is important as it identifies the purpose of your
2976 * // notification sound.
2977 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2978 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2979 * .build());
2980 *
2981 * NotificationManager mgr = getSystemService(NotificationManager.class);
2982 * mgr.createNotificationChannel(channel);
2983 * </code></pre>
2984 * When it comes time to post a notification for your incoming call, ensure it uses your
2985 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002986 * <pre><code>
2987 * // Create an intent which triggers your fullscreen incoming call user interface.
2988 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2989 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2990 * intent.setClass(context, YourIncomingCallActivity.class);
2991 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2992 *
2993 * // Build the notification as an ongoing high priority item; this ensures it will show as
2994 * // a heads up notification which slides down over top of the current content.
2995 * final Notification.Builder builder = new Notification.Builder(context);
2996 * builder.setOngoing(true);
2997 * builder.setPriority(Notification.PRIORITY_HIGH);
2998 *
2999 * // Set notification content intent to take user to fullscreen UI if user taps on the
3000 * // notification body.
3001 * builder.setContentIntent(pendingIntent);
3002 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3003 * // manager deems it appropriate.
3004 * builder.setFullScreenIntent(pendingIntent, true);
3005 *
3006 * // Setup notification content.
3007 * builder.setSmallIcon( yourIconResourceId );
3008 * builder.setContentTitle("Your notification title");
3009 * builder.setContentText("Your notification content.");
3010 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003011 * // Set notification as insistent to cause your ringtone to loop.
3012 * Notification notification = builder.build();
3013 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003014 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003015 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003016 * NotificationManager notificationManager = mContext.getSystemService(
3017 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003018 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003019 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003020 */
3021 public void onShowIncomingCallUi() {}
3022
Hall Liub64ac4c2017-02-06 10:49:48 -08003023 /**
3024 * Notifies this {@link Connection} that the user has requested an RTT session.
3025 * The connection service should call {@link #sendRttInitiationSuccess} or
3026 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3027 * request, respectively.
3028 * @param rttTextStream The object that should be used to send text to or receive text from
3029 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003030 */
3031 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3032
3033 /**
3034 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3035 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003036 */
3037 public void onStopRtt() {}
3038
3039 /**
3040 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3041 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3042 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3043 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003044 * @param rttTextStream The object that should be used to send text to or receive text from
3045 * the in-call app.
3046 */
3047 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3048
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003049 static String toLogSafePhoneNumber(String number) {
3050 // For unknown number, log empty string.
3051 if (number == null) {
3052 return "";
3053 }
3054
3055 if (PII_DEBUG) {
3056 // When PII_DEBUG is true we emit PII.
3057 return number;
3058 }
3059
3060 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3061 // sanitized phone numbers.
3062 StringBuilder builder = new StringBuilder();
3063 for (int i = 0; i < number.length(); i++) {
3064 char c = number.charAt(i);
3065 if (c == '-' || c == '@' || c == '.') {
3066 builder.append(c);
3067 } else {
3068 builder.append('x');
3069 }
3070 }
3071 return builder.toString();
3072 }
3073
Ihab Awad542e0ea2014-05-16 10:22:16 -07003074 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003075 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003076 if (mState == STATE_DISCONNECTED && mState != state) {
3077 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003078 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003079 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003080 if (mState != state) {
3081 Log.d(this, "setState: %s", stateToString(state));
3082 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003083 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003084 for (Listener l : mListeners) {
3085 l.onStateChanged(this, state);
3086 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003087 }
3088 }
3089
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003090 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003091 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003092 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3093 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003094 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003095 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003096
3097 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003098 if (mImmutable) {
3099 throw new UnsupportedOperationException("Connection is immutable");
3100 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003101 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003102 }
3103
Evan Charltonbf11f982014-07-20 22:06:28 -07003104 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003105 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003106 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3107 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003108 * <p>
3109 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3110 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003111 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003112 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003113 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003114 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003115 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3116 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003117 }
3118
Evan Charltonbf11f982014-07-20 22:06:28 -07003119 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003120 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3121 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3122 * this should never be un-@hide-den.
3123 *
3124 * @hide
3125 */
3126 public void checkImmutable() {}
3127
3128 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003129 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3130 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3131 * that state. This connection should not be used for anything, and no other
3132 * {@code Connection}s should be attempted.
3133 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003134 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003135 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003136 * @return A {@code Connection} which indicates that the underlying connection should
3137 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003139 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003140 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003141 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003142
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003143 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003144 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003145 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003146 }
3147 }
3148
Santos Cordon823fd3c2014-08-07 18:35:18 -07003149 private final void fireConferenceChanged() {
3150 for (Listener l : mListeners) {
3151 l.onConferenceChanged(this, mConference);
3152 }
3153 }
3154
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003155 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003156 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003157 if (c instanceof Connection) {
3158 Connection connection = (Connection) c;
3159 connection.removeConnectionListener(mConnectionDeathListener);
3160 } else if (c instanceof Conference) {
3161 Conference conference = (Conference) c;
3162 conference.removeListener(mConferenceDeathListener);
3163 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003164 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003165 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003166 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003167
3168 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003169 * Handles a change to extras received from Telecom.
3170 *
3171 * @param extras The new extras.
3172 * @hide
3173 */
3174 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003175 Bundle b = null;
3176 synchronized (mExtrasLock) {
3177 mExtras = extras;
3178 if (mExtras != null) {
3179 b = new Bundle(mExtras);
3180 }
3181 }
3182 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003183 }
3184
3185 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003186 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3187 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003188 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003189 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003190 for (Listener l : mListeners) {
3191 l.onConferenceMergeFailed(this);
3192 }
3193 }
3194
3195 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303196 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3197 * changed due to an emergency call being redialed.
3198 * @param pHandle The new PhoneAccountHandle for this connection.
3199 * @hide
3200 */
3201 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3202 for (Listener l : mListeners) {
3203 l.onPhoneAccountChanged(this, pHandle);
3204 }
3205 }
3206
3207 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003208 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003209 * <p>
3210 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3211 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003212 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003213 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003214 * @hide
3215 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003216 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003217 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003218 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003219 if (mPhoneAccountHandle != phoneAccountHandle) {
3220 mPhoneAccountHandle = phoneAccountHandle;
3221 notifyPhoneAccountChanged(phoneAccountHandle);
3222 }
3223 }
3224
3225 /**
3226 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003227 * <p>
3228 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3229 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003230 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003231 * @return the phone account handle specified via
3232 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003233 * @hide
3234 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003235 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003236 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003237 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003238 return mPhoneAccountHandle;
3239 }
3240
3241 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003242 * Sends an event associated with this {@code Connection} with associated event extras to the
3243 * {@link InCallService}.
3244 * <p>
3245 * Connection events are used to communicate point in time information from a
3246 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3247 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3248 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3249 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3250 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3251 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3252 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3253 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3254 * <p>
3255 * Events are exposed to {@link InCallService} implementations via
3256 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3257 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003258 * 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 -07003259 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3260 * some events altogether.
3261 * <p>
3262 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3263 * conflicts between {@link ConnectionService} implementations. Further, custom
3264 * {@link ConnectionService} implementations shall not re-purpose events in the
3265 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3266 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3267 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3268 * {@code com.example.extra.MY_EXTRA}).
3269 * <p>
3270 * When defining events and the associated extras, it is important to keep their behavior
3271 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3272 * events/extras should me maintained to ensure backwards compatibility with older
3273 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003274 *
3275 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003276 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003277 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003278 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003279 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003280 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003281 }
3282 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003283
3284 /**
3285 * @return The direction of the call.
3286 * @hide
3287 */
3288 public final @Call.Details.CallDirection int getCallDirection() {
3289 return mCallDirection;
3290 }
3291
3292 /**
3293 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003294 * <p>
3295 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3296 * call direction.
3297 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003298 * @param callDirection The direction of this connection.
3299 * @hide
3300 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003301 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003302 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003303 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3304 mCallDirection = callDirection;
3305 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003306}