blob: 757030e29ca8e37954448c6623e1a7ff27d4c5f1 [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 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900617 * Connection event used to inform Telecom when a switch operation on a call has failed.
618 * <p>
619 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
620 * expected to be null when this connection event is used.
621 */
622 public static final String EVENT_CALL_SWITCH_FAILED =
623 "android.telecom.event.CALL_SWITCH_FAILED";
624
625 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700626 * Connection event used to inform {@link InCallService}s when the process of merging a
627 * Connection into a conference has begun.
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_START = "android.telecom.event.MERGE_START";
633
634 /**
635 * Connection event used to inform {@link InCallService}s when the process of merging a
636 * Connection into a conference has completed.
637 * <p>
638 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
639 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700640 */
641 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
642
643 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700644 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
645 * the remote party.
646 * <p>
647 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
648 * call is being held locally on the device. When a capable {@link ConnectionService} receives
649 * signalling to indicate that the remote party has put the call on hold, it can send this
650 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700651 */
652 public static final String EVENT_CALL_REMOTELY_HELD =
653 "android.telecom.event.CALL_REMOTELY_HELD";
654
655 /**
656 * Connection event used to inform {@link InCallService}s when a call which was remotely held
657 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
658 * <p>
659 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
660 * call is being held locally on the device. When a capable {@link ConnectionService} receives
661 * signalling to indicate that the remote party has taken the call off hold, it can send this
662 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700663 */
664 public static final String EVENT_CALL_REMOTELY_UNHELD =
665 "android.telecom.event.CALL_REMOTELY_UNHELD";
666
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700667 /**
668 * Connection event used to inform an {@link InCallService} which initiated a call handover via
669 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
670 * successfully completed.
671 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700672 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
673 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700674 */
675 public static final String EVENT_HANDOVER_COMPLETE =
676 "android.telecom.event.HANDOVER_COMPLETE";
677
678 /**
679 * Connection event used to inform an {@link InCallService} which initiated a call handover via
680 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
681 * to complete.
682 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700683 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
684 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700685 */
686 public static final String EVENT_HANDOVER_FAILED =
687 "android.telecom.event.HANDOVER_FAILED";
688
shilub7ec9a02018-11-09 15:52:04 -0800689 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000690 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800691 */
692 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
693
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700694 /**
695 * Connection event used to inform an {@link InCallService} that the RTT audio indication
696 * has changed.
697 */
698 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
699 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
700
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700701 // Flag controlling whether PII is emitted into the logs
702 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
703
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800704 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700705 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
706 *
707 * @param capabilities A capability bit field.
708 * @return A human readable string representation.
709 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800710 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 return capabilitiesToStringInternal(capabilities, true /* isLong */);
712 }
713
714 /**
715 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
716 * string.
717 *
718 * @param capabilities A capability bit field.
719 * @return A human readable string representation.
720 * @hide
721 */
722 public static String capabilitiesToStringShort(int capabilities) {
723 return capabilitiesToStringInternal(capabilities, false /* isLong */);
724 }
725
726 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800727 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append("[");
729 if (isLong) {
730 builder.append("Capabilities:");
731 }
732
Tyler Gunnc63f9082019-10-15 13:19:26 -0700733 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700736 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700739 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700742 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800744 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700745 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800747 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700748 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700751 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700752 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800753 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700754 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700755 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700756 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700757 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700758 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700759 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700760 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
761 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700762 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800763 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700764 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700765 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700766 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700767 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700768 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700769 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700770 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
771 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700772 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800773 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700774 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
775 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700776 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800777 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700778 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500780 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700781 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700782 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700783 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700784 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700785 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700786 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700787 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
788 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700789 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700790 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700791 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
792 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700793 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700794 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700795 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700796 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700797 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700798 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530799 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
800 }
Bryce Lee81901682015-08-28 16:38:02 -0700801
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800802 builder.append("]");
803 return builder.toString();
804 }
805
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700806 /**
807 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
808 *
809 * @param properties A property bit field.
810 * @return A human readable string representation.
811 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700812 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700813 return propertiesToStringInternal(properties, true /* isLong */);
814 }
815
816 /**
817 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
818 *
819 * @param properties A property bit field.
820 * @return A human readable string representation.
821 * @hide
822 */
823 public static String propertiesToStringShort(int properties) {
824 return propertiesToStringInternal(properties, false /* isLong */);
825 }
826
827 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700828 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700829 builder.append("[");
830 if (isLong) {
831 builder.append("Properties:");
832 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700833
Tyler Gunnc63f9082019-10-15 13:19:26 -0700834 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800835 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
836 }
837
Tyler Gunnc63f9082019-10-15 13:19:26 -0700838 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700839 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700840 }
841
Tyler Gunnc63f9082019-10-15 13:19:26 -0700842 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700843 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700844 }
845
Tyler Gunnc63f9082019-10-15 13:19:26 -0700846 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700847 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700848 }
849
Tyler Gunnc63f9082019-10-15 13:19:26 -0700850 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700851 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700852 }
853
Tyler Gunnc63f9082019-10-15 13:19:26 -0700854 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700855 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700856 }
857
Tyler Gunnc63f9082019-10-15 13:19:26 -0700858 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700859 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700860 }
861
Tyler Gunnc63f9082019-10-15 13:19:26 -0700862 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800863 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
864 }
865
Tyler Gunnc63f9082019-10-15 13:19:26 -0700866 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
867 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700868 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
869 }
870
Tyler Gunnc63f9082019-10-15 13:19:26 -0700871 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700872 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
873 }
874
Tyler Gunn720c6642016-03-22 09:02:47 -0700875 builder.append("]");
876 return builder.toString();
877 }
878
Sailesh Nepal091768c2014-06-30 15:15:23 -0700879 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700880 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700881 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700882 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700883 public void onCallerDisplayNameChanged(
884 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700885 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700886 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700887 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800888 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700889 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700890 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800891 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700892 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800893 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700894 public void onVideoProviderChanged(
895 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700896 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
897 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800898 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700899 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700900 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700901 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700902 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700903 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700904 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800905 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800906 public void onRttInitiationSuccess(Connection c) {}
907 public void onRttInitiationFailure(Connection c, int reason) {}
908 public void onRttSessionRemotelyTerminated(Connection c) {}
909 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530910 /** @hide */
911 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800912 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700913 }
914
Tyler Gunnb702ef82015-05-29 11:51:53 -0700915 /**
Hall Liu95d55872017-01-25 17:12:49 -0800916 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800917 */
918 public static final class RttTextStream {
919 private static final int READ_BUFFER_SIZE = 1000;
920 private final InputStreamReader mPipeFromInCall;
921 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800922 private final ParcelFileDescriptor mFdFromInCall;
923 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700924
925 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800926 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
927
928 /**
929 * @hide
930 */
931 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800932 mFdFromInCall = fromInCall;
933 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700934 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700935
936 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800937 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700938 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800939 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800940 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800941 }
942
943 /**
944 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
945 * RTT transmits text in real-time, this method should be called as often as text snippets
946 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800947 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800948 * This method is not thread-safe -- calling it from multiple threads simultaneously may
949 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800950 *
Hall Liu95d55872017-01-25 17:12:49 -0800951 * @param input The message to send to the in-call app.
952 */
953 public void write(String input) throws IOException {
954 mPipeToInCall.write(input);
955 mPipeToInCall.flush();
956 }
957
958
959 /**
960 * Reads a string from the in-call app, blocking if there is no data available. Returns
961 * {@code null} if the RTT conversation has been terminated and there is no further data
962 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800963 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800964 * This method is not thread-safe -- calling it from multiple threads simultaneously may
965 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800966 *
Hall Liu95d55872017-01-25 17:12:49 -0800967 * @return A string containing text entered by the user, or {@code null} if the
968 * conversation has been terminated or if there was an error while reading.
969 */
Hall Liuffa4a812017-03-02 16:11:00 -0800970 public String read() throws IOException {
971 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
972 if (numRead < 0) {
973 return null;
974 }
975 return new String(mReadBuffer, 0, numRead);
976 }
977
978 /**
979 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
980 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800981 *
Hall Liuffa4a812017-03-02 16:11:00 -0800982 * @return A string containing text entered by the user, or {@code null} if the user has
983 * not entered any new text yet.
984 */
985 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700986 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800987 return read();
988 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800989 return null;
990 }
991 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800992
993 /** @hide */
994 public ParcelFileDescriptor getFdFromInCall() {
995 return mFdFromInCall;
996 }
997
998 /** @hide */
999 public ParcelFileDescriptor getFdToInCall() {
1000 return mFdToInCall;
1001 }
1002 }
1003
1004 /**
1005 * Provides constants to represent the results of responses to session modify requests sent via
1006 * {@link Call#sendRttRequest()}
1007 */
1008 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001009 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001010 /**
1011 * Session modify request was successful.
1012 */
1013 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1014
1015 /**
1016 * Session modify request failed.
1017 */
1018 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1019
1020 /**
1021 * Session modify request ignored due to invalid parameters.
1022 */
1023 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1024
1025 /**
1026 * Session modify request timed out.
1027 */
1028 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1029
1030 /**
1031 * Session modify request rejected by remote user.
1032 */
1033 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001034 }
1035
1036 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001037 * Provides a means of controlling the video session associated with a {@link Connection}.
1038 * <p>
1039 * Implementations create a custom subclass of {@link VideoProvider} and the
1040 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1041 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1042 * should set the {@link VideoProvider}.
1043 * <p>
1044 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1045 * {@link InCallService} implementations to issue requests related to the video session;
1046 * it provides a means for the {@link ConnectionService} to report events and information
1047 * related to the video session to Telecom and the {@link InCallService} implementations.
1048 * <p>
1049 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1050 * {@link android.telecom.InCallService.VideoCall}.
1051 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 /**
1054 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001055 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 */
1057 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001058
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001060 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1061 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001062 */
1063 public static final int SESSION_EVENT_RX_RESUME = 2;
1064
1065 /**
1066 * Video transmission has begun. This occurs after a negotiated start of video transmission
1067 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001068 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 */
1070 public static final int SESSION_EVENT_TX_START = 3;
1071
1072 /**
1073 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1074 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001076 */
1077 public static final int SESSION_EVENT_TX_STOP = 4;
1078
1079 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001080 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001081 * this as a cue to inform the user the camera is not available.
1082 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 */
1084 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1085
1086 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001087 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001088 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001089 * the camera has become available again.
1090 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001091 */
1092 public static final int SESSION_EVENT_CAMERA_READY = 6;
1093
1094 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001095 * Session event raised by Telecom when
1096 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1097 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1098 * @see #handleCallSessionEvent(int)
1099 */
1100 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1101
1102 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001104 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 */
1106 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1107
1108 /**
1109 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001110 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 */
1112 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1113
1114 /**
1115 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001116 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001117 */
1118 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1119
Rekha Kumar07366812015-03-24 16:42:31 -07001120 /**
1121 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001122 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001123 */
1124 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1125
1126 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001127 * Session modify request rejected by remote user.
1128 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001129 */
1130 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1131
Tyler Gunn75958422015-04-15 14:23:42 -07001132 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 private static final int MSG_SET_CAMERA = 2;
1134 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1135 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1136 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1137 private static final int MSG_SET_ZOOM = 6;
1138 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1139 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1140 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001141 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001142 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001143 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001145 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1146 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1147 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1148 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1149 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1150 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001151 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1152 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001153 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1154
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001155 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001156 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001157
1158 /**
1159 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001160 *
1161 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1162 * load factor before resizing, 1 means we only expect a single thread to
1163 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001164 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001165 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1166 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167
1168 /**
1169 * Default handler used to consolidate binder method calls onto a single thread.
1170 */
1171 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001172 public VideoProviderHandler() {
1173 super();
1174 }
1175
1176 public VideoProviderHandler(Looper looper) {
1177 super(looper);
1178 }
1179
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 @Override
1181 public void handleMessage(Message msg) {
1182 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001183 case MSG_ADD_VIDEO_CALLBACK: {
1184 IBinder binder = (IBinder) msg.obj;
1185 IVideoCallback callback = IVideoCallback.Stub
1186 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001187 if (callback == null) {
1188 Log.w(this, "addVideoProvider - skipped; callback is null.");
1189 break;
1190 }
1191
Tyler Gunn75958422015-04-15 14:23:42 -07001192 if (mVideoCallbacks.containsKey(binder)) {
1193 Log.i(this, "addVideoProvider - skipped; already present.");
1194 break;
1195 }
1196 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001197 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001198 }
1199 case MSG_REMOVE_VIDEO_CALLBACK: {
1200 IBinder binder = (IBinder) msg.obj;
1201 IVideoCallback callback = IVideoCallback.Stub
1202 .asInterface((IBinder) msg.obj);
1203 if (!mVideoCallbacks.containsKey(binder)) {
1204 Log.i(this, "removeVideoProvider - skipped; not present.");
1205 break;
1206 }
1207 mVideoCallbacks.remove(binder);
1208 break;
1209 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001211 {
1212 SomeArgs args = (SomeArgs) msg.obj;
1213 try {
1214 onSetCamera((String) args.arg1);
1215 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001216 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001217 } finally {
1218 args.recycle();
1219 }
1220 }
1221 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001222 case MSG_SET_PREVIEW_SURFACE:
1223 onSetPreviewSurface((Surface) msg.obj);
1224 break;
1225 case MSG_SET_DISPLAY_SURFACE:
1226 onSetDisplaySurface((Surface) msg.obj);
1227 break;
1228 case MSG_SET_DEVICE_ORIENTATION:
1229 onSetDeviceOrientation(msg.arg1);
1230 break;
1231 case MSG_SET_ZOOM:
1232 onSetZoom((Float) msg.obj);
1233 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001234 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1235 SomeArgs args = (SomeArgs) msg.obj;
1236 try {
1237 onSendSessionModifyRequest((VideoProfile) args.arg1,
1238 (VideoProfile) args.arg2);
1239 } finally {
1240 args.recycle();
1241 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001242 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001243 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1245 onSendSessionModifyResponse((VideoProfile) msg.obj);
1246 break;
1247 case MSG_REQUEST_CAMERA_CAPABILITIES:
1248 onRequestCameraCapabilities();
1249 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001250 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1251 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001252 break;
1253 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001254 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 break;
1256 default:
1257 break;
1258 }
1259 }
1260 }
1261
1262 /**
1263 * IVideoProvider stub implementation.
1264 */
1265 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001266 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001268 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1269 }
1270
1271 public void removeVideoCallback(IBinder videoCallbackBinder) {
1272 mMessageHandler.obtainMessage(
1273 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 }
1275
Tyler Gunn159f35c2017-03-02 09:28:37 -08001276 public void setCamera(String cameraId, String callingPackageName,
1277 int targetSdkVersion) {
1278
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001279 SomeArgs args = SomeArgs.obtain();
1280 args.arg1 = cameraId;
1281 // Propagate the calling package; originally determined in
1282 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1283 // process.
1284 args.arg2 = callingPackageName;
1285 // Pass along the uid and pid of the calling app; this gets lost when we put the
1286 // message onto the handler. These are required for Telecom to perform a permission
1287 // check to see if the calling app is able to use the camera.
1288 args.argi1 = Binder.getCallingUid();
1289 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001290 // Pass along the target SDK version of the calling InCallService. This is used to
1291 // maintain backwards compatibility of the API for older callers.
1292 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001293 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 }
1295
1296 public void setPreviewSurface(Surface surface) {
1297 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1298 }
1299
1300 public void setDisplaySurface(Surface surface) {
1301 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1302 }
1303
1304 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001305 mMessageHandler.obtainMessage(
1306 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 }
1308
1309 public void setZoom(float value) {
1310 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1311 }
1312
Tyler Gunn45382162015-05-06 08:52:27 -07001313 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1314 SomeArgs args = SomeArgs.obtain();
1315 args.arg1 = fromProfile;
1316 args.arg2 = toProfile;
1317 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 }
1319
1320 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1321 mMessageHandler.obtainMessage(
1322 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1323 }
1324
1325 public void requestCameraCapabilities() {
1326 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1327 }
1328
1329 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001330 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 }
1332
Yorke Lee32f24732015-05-12 16:18:03 -07001333 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1335 }
1336 }
1337
1338 public VideoProvider() {
1339 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001340 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001341 }
1342
1343 /**
1344 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1345 *
1346 * @param looper The looper.
1347 * @hide
1348 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001349 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001350 public VideoProvider(Looper looper) {
1351 mBinder = new VideoProvider.VideoProviderBinder();
1352 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 }
1354
1355 /**
1356 * Returns binder object which can be used across IPC methods.
1357 * @hide
1358 */
1359 public final IVideoProvider getInterface() {
1360 return mBinder;
1361 }
1362
1363 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001364 * Sets the camera to be used for the outgoing video.
1365 * <p>
1366 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1367 * camera via
1368 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1369 * <p>
1370 * Sent from the {@link InCallService} via
1371 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001373 * @param cameraId The id of the camera (use ids as reported by
1374 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 */
1376 public abstract void onSetCamera(String cameraId);
1377
1378 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001379 * Sets the camera to be used for the outgoing video.
1380 * <p>
1381 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1382 * camera via
1383 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1384 * <p>
1385 * This prototype is used internally to ensure that the calling package name, UID and PID
1386 * are sent to Telecom so that can perform a camera permission check on the caller.
1387 * <p>
1388 * Sent from the {@link InCallService} via
1389 * {@link InCallService.VideoCall#setCamera(String)}.
1390 *
1391 * @param cameraId The id of the camera (use ids as reported by
1392 * {@link CameraManager#getCameraIdList()}).
1393 * @param callingPackageName The AppOpps package name of the caller.
1394 * @param callingUid The UID of the caller.
1395 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001396 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001397 * @hide
1398 */
1399 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001400 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001401
1402 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 * Sets the surface to be used for displaying a preview of what the user's camera is
1404 * currently capturing. When video transmission is enabled, this is the video signal which
1405 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001406 * <p>
1407 * Sent from the {@link InCallService} via
1408 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001410 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 */
1412 public abstract void onSetPreviewSurface(Surface surface);
1413
1414 /**
1415 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001416 * <p>
1417 * Sent from the {@link InCallService} via
1418 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001420 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001421 */
1422 public abstract void onSetDisplaySurface(Surface surface);
1423
1424 /**
1425 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1426 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001427 * <p>
1428 * Sent from the {@link InCallService} via
1429 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430 *
1431 * @param rotation The device orientation, in degrees.
1432 */
1433 public abstract void onSetDeviceOrientation(int rotation);
1434
1435 /**
1436 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001437 * <p>
1438 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001439 *
1440 * @param value The camera zoom ratio.
1441 */
1442 public abstract void onSetZoom(float value);
1443
1444 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001445 * Issues a request to modify the properties of the current video session.
1446 * <p>
1447 * Example scenarios include: requesting an audio-only call to be upgraded to a
1448 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1449 * when the {@link InCallService} is no longer the foreground application.
1450 * <p>
1451 * If the {@link VideoProvider} determines a request to be invalid, it should call
1452 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1453 * invalid request back to the {@link InCallService}.
1454 * <p>
1455 * Where a request requires confirmation from the user of the peer device, the
1456 * {@link VideoProvider} must communicate the request to the peer device and handle the
1457 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1458 * is used to inform the {@link InCallService} of the result of the request.
1459 * <p>
1460 * Sent from the {@link InCallService} via
1461 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * @param fromProfile The video profile prior to the request.
1464 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 */
Tyler Gunn45382162015-05-06 08:52:27 -07001466 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1467 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468
Tyler Gunnb702ef82015-05-29 11:51:53 -07001469 /**
1470 * Provides a response to a request to change the current video session properties.
1471 * <p>
1472 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1473 * video call, could decline the request and keep the call as audio-only.
1474 * In such a scenario, the {@code responseProfile} would have a video state of
1475 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1476 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1477 * <p>
1478 * Sent from the {@link InCallService} via
1479 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1480 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1481 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001483 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 */
1485 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1486
1487 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001488 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1489 * <p>
1490 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1491 * camera via
1492 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1493 * <p>
1494 * Sent from the {@link InCallService} via
1495 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 */
1497 public abstract void onRequestCameraCapabilities();
1498
1499 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001500 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1501 * video component of the current {@link Connection}.
1502 * <p>
1503 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1504 * via {@link VideoProvider#setCallDataUsage(long)}.
1505 * <p>
1506 * Sent from the {@link InCallService} via
1507 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001509 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001510
1511 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001512 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1513 * the peer device when the video signal is paused.
1514 * <p>
1515 * Sent from the {@link InCallService} via
1516 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001517 *
1518 * @param uri URI of image to display.
1519 */
Yorke Lee32f24732015-05-12 16:18:03 -07001520 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521
1522 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001523 * Used to inform listening {@link InCallService} implementations when the
1524 * {@link VideoProvider} receives a session modification request.
1525 * <p>
1526 * Received by the {@link InCallService} via
1527 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001529 * @param videoProfile The requested video profile.
1530 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 */
1532 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001533 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001534 for (IVideoCallback callback : mVideoCallbacks.values()) {
1535 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001536 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001537 } catch (RemoteException ignored) {
1538 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001539 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 }
1541 }
1542 }
1543
1544 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001545 * Used to inform listening {@link InCallService} implementations when the
1546 * {@link VideoProvider} receives a response to a session modification request.
1547 * <p>
1548 * Received by the {@link InCallService} via
1549 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1550 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 *
1552 * @param status Status of the session modify request. Valid values are
1553 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1554 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001555 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1556 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1557 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1558 * @param requestedProfile The original request which was sent to the peer device.
1559 * @param responseProfile The actual profile changes agreed to by the peer device.
1560 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001561 */
1562 public void receiveSessionModifyResponse(int status,
1563 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001564 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001565 for (IVideoCallback callback : mVideoCallbacks.values()) {
1566 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001567 callback.receiveSessionModifyResponse(status, requestedProfile,
1568 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001569 } catch (RemoteException ignored) {
1570 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001571 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001572 }
1573 }
1574 }
1575
1576 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001577 * Used to inform listening {@link InCallService} implementations when the
1578 * {@link VideoProvider} reports a call session event.
1579 * <p>
1580 * Received by the {@link InCallService} via
1581 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001583 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1584 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1585 * {@link VideoProvider#SESSION_EVENT_TX_START},
1586 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1587 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001588 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1589 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001590 */
1591 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001592 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001593 for (IVideoCallback callback : mVideoCallbacks.values()) {
1594 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001595 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001596 } catch (RemoteException ignored) {
1597 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001598 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 }
1600 }
1601 }
1602
1603 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1605 * peer's video have changed.
1606 * <p>
1607 * This could occur if, for example, the peer rotates their device, changing the aspect
1608 * ratio of the video, or if the user switches between the back and front cameras.
1609 * <p>
1610 * Received by the {@link InCallService} via
1611 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001612 *
1613 * @param width The updated peer video width.
1614 * @param height The updated peer video height.
1615 */
1616 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001617 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001618 for (IVideoCallback callback : mVideoCallbacks.values()) {
1619 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001620 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001621 } catch (RemoteException ignored) {
1622 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001623 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001624 }
1625 }
1626 }
1627
1628 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001629 * Used to inform listening {@link InCallService} implementations when the data usage of the
1630 * video associated with the current {@link Connection} has changed.
1631 * <p>
1632 * This could be in response to a preview request via
1633 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001634 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1635 * 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 -07001636 * <p>
1637 * Received by the {@link InCallService} via
1638 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001639 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001640 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1641 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001642 */
Yorke Lee32f24732015-05-12 16:18:03 -07001643 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001644 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001645 for (IVideoCallback callback : mVideoCallbacks.values()) {
1646 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001647 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001648 } catch (RemoteException ignored) {
1649 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001650 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001651 }
1652 }
1653 }
1654
1655 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001656 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001657 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001658 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001659 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1660 * @hide
1661 */
1662 public void changeCallDataUsage(long dataUsage) {
1663 setCallDataUsage(dataUsage);
1664 }
1665
1666 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001667 * Used to inform listening {@link InCallService} implementations when the capabilities of
1668 * the current camera have changed.
1669 * <p>
1670 * The {@link VideoProvider} should call this in response to
1671 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1672 * changed via {@link VideoProvider#onSetCamera(String)}.
1673 * <p>
1674 * Received by the {@link InCallService} via
1675 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1676 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001677 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001678 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001679 */
Yorke Lee400470f2015-05-12 13:31:25 -07001680 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001681 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001682 for (IVideoCallback callback : mVideoCallbacks.values()) {
1683 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001684 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001685 } catch (RemoteException ignored) {
1686 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001687 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001688 }
1689 }
1690 }
Rekha Kumar07366812015-03-24 16:42:31 -07001691
1692 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001693 * Used to inform listening {@link InCallService} implementations when the video quality
1694 * of the call has changed.
1695 * <p>
1696 * Received by the {@link InCallService} via
1697 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001698 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001699 * @param videoQuality The updated video quality. Valid values:
1700 * {@link VideoProfile#QUALITY_HIGH},
1701 * {@link VideoProfile#QUALITY_MEDIUM},
1702 * {@link VideoProfile#QUALITY_LOW},
1703 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001704 */
1705 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001706 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001707 for (IVideoCallback callback : mVideoCallbacks.values()) {
1708 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001709 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001710 } catch (RemoteException ignored) {
1711 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001712 }
Rekha Kumar07366812015-03-24 16:42:31 -07001713 }
1714 }
1715 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001716
1717 /**
1718 * Returns a string representation of a call session event.
1719 *
1720 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1721 * @return String representation of the call session event.
1722 * @hide
1723 */
1724 public static String sessionEventToString(int event) {
1725 switch (event) {
1726 case SESSION_EVENT_CAMERA_FAILURE:
1727 return SESSION_EVENT_CAMERA_FAILURE_STR;
1728 case SESSION_EVENT_CAMERA_READY:
1729 return SESSION_EVENT_CAMERA_READY_STR;
1730 case SESSION_EVENT_RX_PAUSE:
1731 return SESSION_EVENT_RX_PAUSE_STR;
1732 case SESSION_EVENT_RX_RESUME:
1733 return SESSION_EVENT_RX_RESUME_STR;
1734 case SESSION_EVENT_TX_START:
1735 return SESSION_EVENT_TX_START_STR;
1736 case SESSION_EVENT_TX_STOP:
1737 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001738 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1739 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001740 default:
1741 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1742 }
1743 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001744 }
1745
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001746 private final Listener mConnectionDeathListener = new Listener() {
1747 @Override
1748 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001749 if (mConferenceables.remove(c)) {
1750 fireOnConferenceableConnectionsChanged();
1751 }
1752 }
1753 };
1754
1755 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1756 @Override
1757 public void onDestroyed(Conference c) {
1758 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001759 fireOnConferenceableConnectionsChanged();
1760 }
1761 }
1762 };
1763
Jay Shrauner229e3822014-08-15 09:23:07 -07001764 /**
1765 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1766 * load factor before resizing, 1 means we only expect a single thread to
1767 * access the map so make only a single shard
1768 */
1769 private final Set<Listener> mListeners = Collections.newSetFromMap(
1770 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001771 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1772 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001773 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001774
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001775 // The internal telecom call ID associated with this connection.
1776 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001777 // The PhoneAccountHandle associated with this connection.
1778 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001779 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001780 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001781 private Uri mAddress;
1782 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001783 private String mCallerDisplayName;
1784 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001785 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001786 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001787 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001788 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001789 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001790 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001791 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001792 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001793 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001794 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001795 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001796 private Conference mConference;
1797 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001798 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001799 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001800 /**
1801 * The direction of the connection; used where an existing connection is created and we need to
1802 * communicate to Telecom whether its incoming or outgoing.
1803 */
1804 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805
1806 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001807 * Tracks the key set for the extras bundle provided on the last invocation of
1808 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1809 * keys which were set previously but are no longer present in the replacement Bundle.
1810 */
1811 private Set<String> mPreviousExtraKeys;
1812
1813 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001814 * Create a new Connection.
1815 */
Santos Cordonf2951102014-07-20 19:06:29 -07001816 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001817
1818 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001819 * Returns the Telecom internal call ID associated with this connection. Should only be used
1820 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001821 * <p>
1822 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1823 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001824 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001825 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001826 * @hide
1827 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001828 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001829 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001830 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001831 return mTelecomCallId;
1832 }
1833
1834 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001835 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001836 */
Andrew Lee100e2932014-09-08 15:34:24 -07001837 public final Uri getAddress() {
1838 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001839 }
1840
1841 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001842 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001843 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001844 */
Andrew Lee100e2932014-09-08 15:34:24 -07001845 public final int getAddressPresentation() {
1846 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001847 }
1848
1849 /**
1850 * @return The caller display name (CNAP).
1851 */
1852 public final String getCallerDisplayName() {
1853 return mCallerDisplayName;
1854 }
1855
1856 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001857 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001858 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001859 */
1860 public final int getCallerDisplayNamePresentation() {
1861 return mCallerDisplayNamePresentation;
1862 }
1863
1864 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001865 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001866 */
1867 public final int getState() {
1868 return mState;
1869 }
1870
1871 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001872 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001873 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1874 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1875 * {@link VideoProfile#STATE_TX_ENABLED},
1876 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001877 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001878 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001879 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001880 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001881 return mVideoState;
1882 }
1883
1884 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001885 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001886 * being routed by the system. This is {@code null} if this Connection
1887 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001888 * @deprecated Use {@link #getCallAudioState()} instead.
1889 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001890 */
Yorke Lee4af59352015-05-13 14:14:54 -07001891 @SystemApi
1892 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001893 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001894 if (mCallAudioState == null) {
1895 return null;
1896 }
Yorke Lee4af59352015-05-13 14:14:54 -07001897 return new AudioState(mCallAudioState);
1898 }
1899
1900 /**
1901 * @return The audio state of the connection, describing how its audio is currently
1902 * being routed by the system. This is {@code null} if this Connection
1903 * does not directly know about its audio state.
1904 */
1905 public final CallAudioState getCallAudioState() {
1906 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001907 }
1908
1909 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001910 * @return The conference that this connection is a part of. Null if it is not part of any
1911 * conference.
1912 */
1913 public final Conference getConference() {
1914 return mConference;
1915 }
1916
1917 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001918 * Returns whether this connection is requesting that the system play a ringback tone
1919 * on its behalf.
1920 */
Andrew Lee100e2932014-09-08 15:34:24 -07001921 public final boolean isRingbackRequested() {
1922 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001923 }
1924
1925 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001926 * @return True if the connection's audio mode is VOIP.
1927 */
1928 public final boolean getAudioModeIsVoip() {
1929 return mAudioModeIsVoip;
1930 }
1931
1932 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001933 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1934 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1935 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001936 * <p>
1937 * Note: This is an implementation detail specific to IMS conference calls over a mobile
1938 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07001939 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001940 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
1941 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07001942 *
1943 * @hide
1944 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001945 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001946 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07001947 public final long getConnectTimeMillis() {
1948 return mConnectTimeMillis;
1949 }
1950
1951 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001952 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1953 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1954 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001955 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001956 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1957 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001958 * <p>
1959 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001960 *
1961 * @return The time at which the {@link Connection} was connected.
1962 *
1963 * @hide
1964 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001965 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001966 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001967 public final long getConnectElapsedTimeMillis() {
1968 return mConnectElapsedTimeMillis;
1969 }
1970
1971 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001972 * @return The status hints for this connection.
1973 */
1974 public final StatusHints getStatusHints() {
1975 return mStatusHints;
1976 }
1977
1978 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001979 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001980 * <p>
1981 * Extras should be updated using {@link #putExtras(Bundle)}.
1982 * <p>
1983 * Telecom or an {@link InCallService} can also update the extras via
1984 * {@link android.telecom.Call#putExtras(Bundle)}, and
1985 * {@link Call#removeExtras(List)}.
1986 * <p>
1987 * The connection is notified of changes to the extras made by Telecom or an
1988 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001989 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001990 * @return The extras associated with this connection.
1991 */
1992 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001993 Bundle extras = null;
1994 synchronized (mExtrasLock) {
1995 if (mExtras != null) {
1996 extras = new Bundle(mExtras);
1997 }
1998 }
1999 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002000 }
2001
2002 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002003 * Assign a listener to be notified of state changes.
2004 *
2005 * @param l A listener.
2006 * @return This Connection.
2007 *
2008 * @hide
2009 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002010 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002011 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002012 return this;
2013 }
2014
2015 /**
2016 * Remove a previously assigned listener that was being notified of state changes.
2017 *
2018 * @param l A Listener.
2019 * @return This Connection.
2020 *
2021 * @hide
2022 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002023 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002024 if (l != null) {
2025 mListeners.remove(l);
2026 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002027 return this;
2028 }
2029
2030 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002031 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002032 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002033 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002034 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002035 }
2036
2037 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002038 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2039 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002040 * <p>
2041 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2042 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2043 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002044 *
2045 * @param callId The telecom call ID.
2046 * @hide
2047 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002048 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002049 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002050 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002051 mTelecomCallId = callId;
2052 }
2053
2054 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 * Inform this Connection that the state of its audio output has been changed externally.
2056 *
2057 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002058 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002059 */
Yorke Lee4af59352015-05-13 14:14:54 -07002060 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002061 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002062 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002063 mCallAudioState = state;
2064 onAudioStateChanged(getAudioState());
2065 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002066 }
2067
2068 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002069 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070 * @return A string representation of the value.
2071 */
2072 public static String stateToString(int state) {
2073 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002075 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002076 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002077 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002079 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002080 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002081 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002082 case STATE_PULLING_CALL:
2083 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002084 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002085 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002086 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002087 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002088 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002089 return "DISCONNECTED";
2090 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002091 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092 return "UNKNOWN";
2093 }
2094 }
2095
2096 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002098 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002099 public final int getConnectionCapabilities() {
2100 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002101 }
2102
2103 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002104 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2105 */
2106 public final int getConnectionProperties() {
2107 return mConnectionProperties;
2108 }
2109
2110 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002111 * Returns the connection's supported audio routes.
2112 *
2113 * @hide
2114 */
2115 public final int getSupportedAudioRoutes() {
2116 return mSupportedAudioRoutes;
2117 }
2118
2119 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002120 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002121 *
Andrew Lee100e2932014-09-08 15:34:24 -07002122 * @param address The new address.
2123 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002124 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002125 */
Andrew Lee100e2932014-09-08 15:34:24 -07002126 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002127 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002128 Log.d(this, "setAddress %s", address);
2129 mAddress = address;
2130 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002131 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002132 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002133 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002134 }
2135
2136 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002137 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002138 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002139 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002140 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002141 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002142 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002143 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002144 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002145 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002146 mCallerDisplayName = callerDisplayName;
2147 mCallerDisplayNamePresentation = presentation;
2148 for (Listener l : mListeners) {
2149 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2150 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002151 }
2152
2153 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002154 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002155 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2156 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2157 * {@link VideoProfile#STATE_TX_ENABLED},
2158 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002159 *
2160 * @param videoState The new video state.
2161 */
2162 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002163 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002164 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002165 mVideoState = videoState;
2166 for (Listener l : mListeners) {
2167 l.onVideoStateChanged(this, mVideoState);
2168 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002169 }
2170
2171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002172 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002173 * communicate).
2174 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002175 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002176 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002177 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002178 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002179 }
2180
2181 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002182 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002183 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002184 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002185 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002186 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002187 }
2188
2189 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002190 * Sets state to initializing (this Connection is not yet ready to be used).
2191 */
2192 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002193 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002194 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002195 }
2196
2197 /**
2198 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2199 */
2200 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002202 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002203 }
2204
2205 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002206 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002207 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002208 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002209 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002210 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002211 }
2212
2213 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002214 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2215 * device). Only applicable for {@link Connection}s with
2216 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2217 */
2218 public final void setPulling() {
2219 checkImmutable();
2220 setState(STATE_PULLING_CALL);
2221 }
2222
2223 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002224 * Sets state to be on hold.
2225 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002226 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002227 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002228 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002229 }
2230
2231 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002232 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002233 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002234 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002235 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002236 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002237 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002238 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002239 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002240 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002241 }
2242
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002243 public final VideoProvider getVideoProvider() {
2244 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002245 }
2246
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002247 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002248 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002249 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002250 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002251 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002252 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002253 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002254 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002255 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002256 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002257 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002258 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002259 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002260 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002261 }
2262
2263 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002264 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2265 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2266 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2267 * to send an {@link #onPostDialContinue(boolean)} signal.
2268 *
2269 * @param remaining The DTMF character sequence remaining to be emitted once the
2270 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2271 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002272 */
2273 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002274 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002275 for (Listener l : mListeners) {
2276 l.onPostDialWait(this, remaining);
2277 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002278 }
2279
2280 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002281 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2282 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002283 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002284 *
2285 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002286 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002287 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002288 checkImmutable();
2289 for (Listener l : mListeners) {
2290 l.onPostDialChar(this, nextChar);
2291 }
2292 }
2293
2294 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002295 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002296 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002297 *
2298 * @param ringback Whether the ringback tone is to be played.
2299 */
Andrew Lee100e2932014-09-08 15:34:24 -07002300 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002301 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002302 if (mRingbackRequested != ringback) {
2303 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002304 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002305 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002306 }
2307 }
Ihab Awadf8358972014-05-28 16:46:42 -07002308 }
2309
2310 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002311 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002312 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002313 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002314 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002315 public final void setConnectionCapabilities(int connectionCapabilities) {
2316 checkImmutable();
2317 if (mConnectionCapabilities != connectionCapabilities) {
2318 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002319 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002320 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002321 }
2322 }
Santos Cordonb6939982014-06-04 20:20:58 -07002323 }
2324
2325 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002326 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2327 *
2328 * @param connectionProperties The new connection properties.
2329 */
2330 public final void setConnectionProperties(int connectionProperties) {
2331 checkImmutable();
2332 if (mConnectionProperties != connectionProperties) {
2333 mConnectionProperties = connectionProperties;
2334 for (Listener l : mListeners) {
2335 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2336 }
2337 }
2338 }
2339
2340 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002341 * Sets the supported audio routes.
2342 *
2343 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2344 * See {@link CallAudioState}
2345 * @hide
2346 */
2347 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2348 if ((supportedAudioRoutes
2349 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2350 throw new IllegalArgumentException(
2351 "supported audio routes must include either speaker or earpiece");
2352 }
2353
2354 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2355 mSupportedAudioRoutes = supportedAudioRoutes;
2356 for (Listener l : mListeners) {
2357 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2358 }
2359 }
2360 }
2361
2362 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002363 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002364 */
Evan Charlton36a71342014-07-19 16:31:02 -07002365 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002366 for (Listener l : mListeners) {
2367 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002368 }
Santos Cordonb6939982014-06-04 20:20:58 -07002369 }
2370
2371 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002372 * Requests that the framework use VOIP audio mode for this connection.
2373 *
2374 * @param isVoip True if the audio mode is VOIP.
2375 */
2376 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002377 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002378 mAudioModeIsVoip = isVoip;
2379 for (Listener l : mListeners) {
2380 l.onAudioModeIsVoipChanged(this, isVoip);
2381 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002382 }
2383
2384 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002385 * Sets the time at which a call became active on this Connection. This is set only
2386 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002387 * <p>
2388 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002389 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002390 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2391 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002392 *
2393 * @hide
2394 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002395 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002396 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002397 public final void setConnectTimeMillis(long connectTimeMillis) {
2398 mConnectTimeMillis = connectTimeMillis;
2399 }
2400
2401 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002402 * Sets the time at which a call became active on this Connection. This is set only
2403 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002404 * <p>
2405 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002406 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2407 * {@link SystemClock#elapsedRealtime()}.
2408 *
2409 * @hide
2410 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002411 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002412 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002413 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002414 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2415 }
2416
2417 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002418 * Sets the label and icon status to display in the in-call UI.
2419 *
2420 * @param statusHints The status label and icon to set.
2421 */
2422 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002423 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002424 mStatusHints = statusHints;
2425 for (Listener l : mListeners) {
2426 l.onStatusHintsChanged(this, statusHints);
2427 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002428 }
2429
2430 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002431 * Sets the connections with which this connection can be conferenced.
2432 *
2433 * @param conferenceableConnections The set of connections this connection can conference with.
2434 */
2435 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002436 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002437 clearConferenceableList();
2438 for (Connection c : conferenceableConnections) {
2439 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2440 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002441 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002442 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002443 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002444 }
2445 }
2446 fireOnConferenceableConnectionsChanged();
2447 }
2448
2449 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002450 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2451 * or conferences with which this connection can be conferenced.
2452 *
2453 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002454 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002455 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002456 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002457 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002458 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2459 // small amount of items here.
2460 if (!mConferenceables.contains(c)) {
2461 if (c instanceof Connection) {
2462 Connection connection = (Connection) c;
2463 connection.addConnectionListener(mConnectionDeathListener);
2464 } else if (c instanceof Conference) {
2465 Conference conference = (Conference) c;
2466 conference.addListener(mConferenceDeathListener);
2467 }
2468 mConferenceables.add(c);
2469 }
2470 }
2471 fireOnConferenceableConnectionsChanged();
2472 }
2473
2474 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002475 * Resets the CDMA connection time.
2476 * <p>
2477 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002478 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002479 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002480 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002481 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002482 public final void resetConnectionTime() {
2483 for (Listener l : mListeners) {
2484 l.onConnectionTimeReset(this);
2485 }
2486 }
2487
2488 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002489 * Returns the connections or conferences with which this connection can be conferenced.
2490 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002491 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002492 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002493 }
2494
Yorke Lee53463962015-08-04 16:07:19 -07002495 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002496 * @hide
2497 */
2498 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002499 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002500 if (mConnectionService != null) {
2501 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2502 "which is already associated with another ConnectionService.");
2503 } else {
2504 mConnectionService = connectionService;
2505 }
2506 }
2507
2508 /**
2509 * @hide
2510 */
2511 public final void unsetConnectionService(ConnectionService connectionService) {
2512 if (mConnectionService != connectionService) {
2513 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2514 "that does not belong to the ConnectionService.");
2515 } else {
2516 mConnectionService = null;
2517 }
2518 }
2519
2520 /**
2521 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002522 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002523 *
2524 * @param conference The conference.
2525 * @return {@code true} if the conference was successfully set.
2526 * @hide
2527 */
2528 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002529 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002530 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002531 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002532 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002533 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2534 fireConferenceChanged();
2535 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002536 return true;
2537 }
2538 return false;
2539 }
2540
2541 /**
2542 * Resets the conference that this connection is a part of.
2543 * @hide
2544 */
2545 public final void resetConference() {
2546 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002547 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002548 mConference = null;
2549 fireConferenceChanged();
2550 }
2551 }
2552
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002553 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002554 * Set some extras that can be associated with this {@code Connection}.
2555 * <p>
2556 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2557 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2558 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002559 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2560 * {@link #removeExtras(String...)} methods to modify the extras.
2561 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002562 * 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 -07002563 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2564 *
2565 * @param extras The extras associated with this {@code Connection}.
2566 */
2567 public final void setExtras(@Nullable Bundle extras) {
2568 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002569
2570 // Add/replace any new or changed extras values.
2571 putExtras(extras);
2572
2573 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2574 // the current one and remove any keys that went away.
2575 if (mPreviousExtraKeys != null) {
2576 List<String> toRemove = new ArrayList<String>();
2577 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002578 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002579 toRemove.add(oldKey);
2580 }
2581 }
2582 if (!toRemove.isEmpty()) {
2583 removeExtras(toRemove);
2584 }
2585 }
2586
2587 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2588 // called we can see if the caller has removed any extras values.
2589 if (mPreviousExtraKeys == null) {
2590 mPreviousExtraKeys = new ArraySet<String>();
2591 }
2592 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002593 if (extras != null) {
2594 mPreviousExtraKeys.addAll(extras.keySet());
2595 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002596 }
2597
2598 /**
2599 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2600 * added.
2601 * <p>
2602 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2603 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2604 *
2605 * @param extras The extras to add.
2606 */
2607 public final void putExtras(@NonNull Bundle extras) {
2608 checkImmutable();
2609 if (extras == null) {
2610 return;
2611 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002612 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2613 // the listeners.
2614 Bundle listenerExtras;
2615 synchronized (mExtrasLock) {
2616 if (mExtras == null) {
2617 mExtras = new Bundle();
2618 }
2619 mExtras.putAll(extras);
2620 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002621 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002622 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002623 // Create a new clone of the extras for each listener so that they don't clobber
2624 // each other
2625 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002626 }
2627 }
2628
2629 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002630 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002631 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002632 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002633 */
2634 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002635 synchronized (mExtrasLock) {
2636 if (mExtras != null) {
2637 for (String key : keys) {
2638 mExtras.remove(key);
2639 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002640 }
2641 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002642 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002643 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002644 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002645 }
2646 }
2647
2648 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002649 * Removes extras from this {@code Connection}.
2650 *
2651 * @param keys The keys of the extras to remove.
2652 */
2653 public final void removeExtras(String ... keys) {
2654 removeExtras(Arrays.asList(keys));
2655 }
2656
2657 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002658 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2659 * be change to the {@link #getCallAudioState()}.
2660 * <p>
2661 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2662 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2663 * <p>
2664 * See also {@link InCallService#setAudioRoute(int)}.
2665 *
2666 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2667 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2668 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2669 */
2670 public final void setAudioRoute(int route) {
2671 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002672 l.onAudioRouteChanged(this, route, null);
2673 }
2674 }
2675
2676 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002677 * Request audio routing to a specific bluetooth device. Calling this method may result in
2678 * the device routing audio to a different bluetooth device than the one specified if the
2679 * bluetooth stack is unable to route audio to the requested device.
2680 * A list of available devices can be obtained via
2681 * {@link CallAudioState#getSupportedBluetoothDevices()}
2682 *
2683 * <p>
2684 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2685 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2686 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002687 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2688 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002689 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002690 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002691 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002692 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2693 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002694 }
2695 }
2696
2697 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002698 * Informs listeners that a previously requested RTT session via
2699 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002700 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002701 */
2702 public final void sendRttInitiationSuccess() {
2703 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2704 }
2705
2706 /**
2707 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002708 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002709 * has failed.
2710 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2711 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002712 */
2713 public final void sendRttInitiationFailure(int reason) {
2714 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2715 }
2716
2717 /**
2718 * Informs listeners that a currently active RTT session has been terminated by the remote
2719 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002720 */
2721 public final void sendRttSessionRemotelyTerminated() {
2722 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2723 }
2724
2725 /**
2726 * Informs listeners that the remote side of the call has requested an upgrade to include an
2727 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002728 */
2729 public final void sendRemoteRttRequest() {
2730 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2731 }
2732
2733 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002734 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002735 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002736 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002737 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2738 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002739 */
Yorke Lee4af59352015-05-13 14:14:54 -07002740 @SystemApi
2741 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002742 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002743
2744 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002745 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2746 *
2747 * @param state The new connection audio state.
2748 */
2749 public void onCallAudioStateChanged(CallAudioState state) {}
2750
2751 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002752 * Notifies this Connection of an internal state change. This method is called after the
2753 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002754 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002755 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002756 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002757 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002758
2759 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002760 * Notifies this Connection of a request to play a DTMF tone.
2761 *
2762 * @param c A DTMF character.
2763 */
Santos Cordonf2951102014-07-20 19:06:29 -07002764 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002765
2766 /**
2767 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2768 */
Santos Cordonf2951102014-07-20 19:06:29 -07002769 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002770
2771 /**
2772 * Notifies this Connection of a request to disconnect.
2773 */
Santos Cordonf2951102014-07-20 19:06:29 -07002774 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002775
2776 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002777 * Notifies this Connection of a request to disconnect a participant of the conference managed
2778 * by the connection.
2779 *
2780 * @param endpoint the {@link Uri} of the participant to disconnect.
2781 * @hide
2782 */
2783 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2784
2785 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002786 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002787 */
Santos Cordonf2951102014-07-20 19:06:29 -07002788 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002789
2790 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002791 * Notifies this Connection of a request to abort.
2792 */
Santos Cordonf2951102014-07-20 19:06:29 -07002793 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002794
2795 /**
2796 * Notifies this Connection of a request to hold.
2797 */
Santos Cordonf2951102014-07-20 19:06:29 -07002798 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002799
2800 /**
2801 * Notifies this Connection of a request to exit a hold state.
2802 */
Santos Cordonf2951102014-07-20 19:06:29 -07002803 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002804
2805 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002806 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002807 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002808 * <p>
2809 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2810 * the default dialer's {@link InCallService}.
2811 * <p>
2812 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2813 * Telecom framework may request that the call is answered in the following circumstances:
2814 * <ul>
2815 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2816 * <li>A car mode {@link InCallService} is in use which has declared
2817 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2818 * {@link InCallService} will be able to see calls from self-managed
2819 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2820 * behalf.</li>
2821 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002822 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002823 */
Santos Cordonf2951102014-07-20 19:06:29 -07002824 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002825
2826 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002827 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002828 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002829 * <p>
2830 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2831 * the default dialer's {@link InCallService}.
2832 * <p>
2833 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2834 * Telecom framework may request that the call is answered in the following circumstances:
2835 * <ul>
2836 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2837 * <li>A car mode {@link InCallService} is in use which has declared
2838 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2839 * {@link InCallService} will be able to see calls from self-managed
2840 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2841 * behalf.</li>
2842 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002843 */
2844 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002845 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002846 }
2847
2848 /**
2849 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302850 * a request to deflect.
2851 */
2852 public void onDeflect(Uri address) {}
2853
2854 /**
2855 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002856 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002857 * <p>
2858 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2859 * the default dialer's {@link InCallService}.
2860 * <p>
2861 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2862 * Telecom framework may request that the call is rejected in the following circumstances:
2863 * <ul>
2864 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2865 * <li>A car mode {@link InCallService} is in use which has declared
2866 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2867 * {@link InCallService} will be able to see calls from self-managed
2868 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2869 * behalf.</li>
2870 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002871 */
Santos Cordonf2951102014-07-20 19:06:29 -07002872 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002873
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002874 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002875 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2876 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002877 */
2878 public void onReject(String replyMessage) {}
2879
2880 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002881 * Notifies this Connection of a request to silence the ringer.
2882 * <p>
2883 * The ringer may be silenced by any of the following methods:
2884 * <ul>
2885 * <li>{@link TelecomManager#silenceRinger()}</li>
2886 * <li>The user presses the volume-down button while a call is ringing.</li>
2887 * </ul>
2888 * <p>
2889 * Self-managed {@link ConnectionService} implementations should override this method in their
2890 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2891 * your app set the ringtone as part of the incoming call {@link Notification} (see
2892 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2893 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2894 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2895 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002896 */
2897 public void onSilence() {}
2898
2899 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002900 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2901 */
Santos Cordonf2951102014-07-20 19:06:29 -07002902 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002903
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002904 /**
2905 * Notifies this Connection of a request to pull an external call to the local device.
2906 * <p>
2907 * The {@link InCallService} issues a request to pull an external call to the local device via
2908 * {@link Call#pullExternalCall()}.
2909 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002910 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2911 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002912 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002913 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002914 */
2915 public void onPullExternalCall() {}
2916
2917 /**
2918 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2919 * <p>
2920 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2921 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002922 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2923 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2924 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2925 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2926 * not aware of.
2927 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002928 * See also {@link Call#sendCallEvent(String, Bundle)}.
2929 *
2930 * @param event The call event.
2931 * @param extras Extras associated with the call event.
2932 */
2933 public void onCallEvent(String event, Bundle extras) {}
2934
Tyler Gunndee56a82016-03-23 16:06:34 -07002935 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002936 * Notifies this {@link Connection} that a handover has completed.
2937 * <p>
2938 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2939 * Bundle)} on the initiating side of the handover, and
2940 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2941 */
2942 public void onHandoverComplete() {}
2943
2944 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002945 * Notifies this {@link Connection} of a change to the extras made outside the
2946 * {@link ConnectionService}.
2947 * <p>
2948 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2949 * the {@link android.telecom.Call#putExtras(Bundle)} and
2950 * {@link Call#removeExtras(List)}.
2951 *
2952 * @param extras The new extras bundle.
2953 */
2954 public void onExtrasChanged(Bundle extras) {}
2955
Tyler Gunnf5035432017-01-09 09:43:12 -08002956 /**
2957 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2958 * displaying its incoming call user interface for the {@link Connection}.
2959 * <p>
2960 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2961 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2962 * should show its own incoming call user interface.
2963 * <p>
2964 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002965 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2966 * Telecom framework will display its own incoming call user interface to allow the user to
2967 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2968 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002969 * <p>
2970 * You should trigger the display of the incoming call user interface for your application by
2971 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002972 *
2973 * In your application code, you should create a {@link android.app.NotificationChannel} for
2974 * incoming call notifications from your app:
2975 * <pre><code>
2976 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2977 * NotificationManager.IMPORTANCE_MAX);
2978 * // other channel setup stuff goes here.
2979 *
2980 * // We'll use the default system ringtone for our incoming call notification channel. You can
2981 * // use your own audio resource here.
2982 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2983 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2984 * // Setting the AudioAttributes is important as it identifies the purpose of your
2985 * // notification sound.
2986 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2987 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2988 * .build());
2989 *
2990 * NotificationManager mgr = getSystemService(NotificationManager.class);
2991 * mgr.createNotificationChannel(channel);
2992 * </code></pre>
2993 * When it comes time to post a notification for your incoming call, ensure it uses your
2994 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002995 * <pre><code>
2996 * // Create an intent which triggers your fullscreen incoming call user interface.
2997 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2998 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2999 * intent.setClass(context, YourIncomingCallActivity.class);
3000 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3001 *
3002 * // Build the notification as an ongoing high priority item; this ensures it will show as
3003 * // a heads up notification which slides down over top of the current content.
3004 * final Notification.Builder builder = new Notification.Builder(context);
3005 * builder.setOngoing(true);
3006 * builder.setPriority(Notification.PRIORITY_HIGH);
3007 *
3008 * // Set notification content intent to take user to fullscreen UI if user taps on the
3009 * // notification body.
3010 * builder.setContentIntent(pendingIntent);
3011 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3012 * // manager deems it appropriate.
3013 * builder.setFullScreenIntent(pendingIntent, true);
3014 *
3015 * // Setup notification content.
3016 * builder.setSmallIcon( yourIconResourceId );
3017 * builder.setContentTitle("Your notification title");
3018 * builder.setContentText("Your notification content.");
3019 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003020 * // Set notification as insistent to cause your ringtone to loop.
3021 * Notification notification = builder.build();
3022 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003023 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003024 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003025 * NotificationManager notificationManager = mContext.getSystemService(
3026 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003027 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003028 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003029 */
3030 public void onShowIncomingCallUi() {}
3031
Hall Liub64ac4c2017-02-06 10:49:48 -08003032 /**
3033 * Notifies this {@link Connection} that the user has requested an RTT session.
3034 * The connection service should call {@link #sendRttInitiationSuccess} or
3035 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3036 * request, respectively.
3037 * @param rttTextStream The object that should be used to send text to or receive text from
3038 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003039 */
3040 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3041
3042 /**
3043 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3044 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003045 */
3046 public void onStopRtt() {}
3047
3048 /**
3049 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3050 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3051 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3052 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003053 * @param rttTextStream The object that should be used to send text to or receive text from
3054 * the in-call app.
3055 */
3056 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3057
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003058 static String toLogSafePhoneNumber(String number) {
3059 // For unknown number, log empty string.
3060 if (number == null) {
3061 return "";
3062 }
3063
3064 if (PII_DEBUG) {
3065 // When PII_DEBUG is true we emit PII.
3066 return number;
3067 }
3068
3069 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3070 // sanitized phone numbers.
3071 StringBuilder builder = new StringBuilder();
3072 for (int i = 0; i < number.length(); i++) {
3073 char c = number.charAt(i);
3074 if (c == '-' || c == '@' || c == '.') {
3075 builder.append(c);
3076 } else {
3077 builder.append('x');
3078 }
3079 }
3080 return builder.toString();
3081 }
3082
Ihab Awad542e0ea2014-05-16 10:22:16 -07003083 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003084 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003085 if (mState == STATE_DISCONNECTED && mState != state) {
3086 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003087 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003088 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003089 if (mState != state) {
3090 Log.d(this, "setState: %s", stateToString(state));
3091 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003092 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003093 for (Listener l : mListeners) {
3094 l.onStateChanged(this, state);
3095 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003096 }
3097 }
3098
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003099 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003100 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003101 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3102 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003103 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003104 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003105
3106 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003107 if (mImmutable) {
3108 throw new UnsupportedOperationException("Connection is immutable");
3109 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003110 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003111 }
3112
Evan Charltonbf11f982014-07-20 22:06:28 -07003113 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003114 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003115 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3116 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003117 * <p>
3118 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3119 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003120 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003121 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003122 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003123 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003124 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3125 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003126 }
3127
Evan Charltonbf11f982014-07-20 22:06:28 -07003128 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003129 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3130 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3131 * this should never be un-@hide-den.
3132 *
3133 * @hide
3134 */
3135 public void checkImmutable() {}
3136
3137 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003138 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3139 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3140 * that state. This connection should not be used for anything, and no other
3141 * {@code Connection}s should be attempted.
3142 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003143 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003144 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003145 * @return A {@code Connection} which indicates that the underlying connection should
3146 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003147 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003148 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003149 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003150 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003151
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003152 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003153 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003154 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003155 }
3156 }
3157
Santos Cordon823fd3c2014-08-07 18:35:18 -07003158 private final void fireConferenceChanged() {
3159 for (Listener l : mListeners) {
3160 l.onConferenceChanged(this, mConference);
3161 }
3162 }
3163
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003164 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003165 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003166 if (c instanceof Connection) {
3167 Connection connection = (Connection) c;
3168 connection.removeConnectionListener(mConnectionDeathListener);
3169 } else if (c instanceof Conference) {
3170 Conference conference = (Conference) c;
3171 conference.removeListener(mConferenceDeathListener);
3172 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003173 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003174 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003175 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003176
3177 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003178 * Handles a change to extras received from Telecom.
3179 *
3180 * @param extras The new extras.
3181 * @hide
3182 */
3183 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003184 Bundle b = null;
3185 synchronized (mExtrasLock) {
3186 mExtras = extras;
3187 if (mExtras != null) {
3188 b = new Bundle(mExtras);
3189 }
3190 }
3191 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003192 }
3193
3194 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003195 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3196 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003197 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003198 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003199 for (Listener l : mListeners) {
3200 l.onConferenceMergeFailed(this);
3201 }
3202 }
3203
3204 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303205 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3206 * changed due to an emergency call being redialed.
3207 * @param pHandle The new PhoneAccountHandle for this connection.
3208 * @hide
3209 */
3210 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3211 for (Listener l : mListeners) {
3212 l.onPhoneAccountChanged(this, pHandle);
3213 }
3214 }
3215
3216 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003217 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003218 * <p>
3219 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3220 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003221 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003222 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003223 * @hide
3224 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003225 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003226 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003227 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003228 if (mPhoneAccountHandle != phoneAccountHandle) {
3229 mPhoneAccountHandle = phoneAccountHandle;
3230 notifyPhoneAccountChanged(phoneAccountHandle);
3231 }
3232 }
3233
3234 /**
3235 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003236 * <p>
3237 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3238 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003239 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003240 * @return the phone account handle specified via
3241 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003242 * @hide
3243 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003244 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003245 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003246 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003247 return mPhoneAccountHandle;
3248 }
3249
3250 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003251 * Sends an event associated with this {@code Connection} with associated event extras to the
3252 * {@link InCallService}.
3253 * <p>
3254 * Connection events are used to communicate point in time information from a
3255 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3256 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3257 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3258 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3259 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3260 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3261 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3262 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3263 * <p>
3264 * Events are exposed to {@link InCallService} implementations via
3265 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3266 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003267 * 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 -07003268 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3269 * some events altogether.
3270 * <p>
3271 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3272 * conflicts between {@link ConnectionService} implementations. Further, custom
3273 * {@link ConnectionService} implementations shall not re-purpose events in the
3274 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3275 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3276 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3277 * {@code com.example.extra.MY_EXTRA}).
3278 * <p>
3279 * When defining events and the associated extras, it is important to keep their behavior
3280 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3281 * events/extras should me maintained to ensure backwards compatibility with older
3282 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003283 *
3284 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003285 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003286 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003287 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003288 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003289 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003290 }
3291 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003292
3293 /**
3294 * @return The direction of the call.
3295 * @hide
3296 */
3297 public final @Call.Details.CallDirection int getCallDirection() {
3298 return mCallDirection;
3299 }
3300
3301 /**
3302 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003303 * <p>
3304 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3305 * call direction.
3306 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003307 * @param callDirection The direction of this connection.
3308 * @hide
3309 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003310 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003311 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003312 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3313 mCallDirection = callDirection;
3314 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003315}