blob: 20abe773e41551205eb21d39d21bd0c6b11cee30 [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;
Mathew Inwood42346d12018-08-01 11:33:05 +010022import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080023import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080024import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080025import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070026import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080028import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import android.os.Handler;
31import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070032import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080034import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070036import android.os.SystemClock;
Chen Xuf85cf992019-10-02 00:20:43 -070037import android.telephony.Annotation.RilRadioTechnology;
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 Gunnd9da4772019-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 Gunnd9da4772019-10-15 13:19:26 -0700276 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700277 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800278
Rekha Kumar07366812015-03-24 16:42:31 -0700279 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700280 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800281 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
282 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
283 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700284 */
285 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
286
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700287 /**
288 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700289 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700290 */
291 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
292
Tyler Gunnd4091732015-06-29 09:15:37 -0700293 /**
294 * For a conference, indicates the conference will not have child connections.
295 * <p>
296 * An example of a conference with child connections is a GSM conference call, where the radio
297 * retains connections to the individual participants of the conference. Another example is an
298 * IMS conference call where conference event package functionality is supported; in this case
299 * the conference server ensures the radio is aware of the participants in the conference, which
300 * are represented by child connections.
301 * <p>
302 * An example of a conference with no child connections is an IMS conference call with no
303 * conference event package support. Such a conference is represented by the radio as a single
304 * connection to the IMS conference server.
305 * <p>
306 * Indicating whether a conference has children or not is important to help user interfaces
307 * visually represent a conference. A conference with no children, for example, will have the
308 * conference connection shown in the list of calls on a Bluetooth device, where if the
309 * conference has children, only the children will be shown in the list of calls on a Bluetooth
310 * device.
311 * @hide
312 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700313 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700314 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
315
Bryce Lee81901682015-08-28 16:38:02 -0700316 /**
317 * Indicates that the connection itself wants to handle any sort of reply response, rather than
318 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700319 */
320 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
321
Tyler Gunnf97a0092016-01-19 15:59:34 -0800322 /**
323 * When set, prevents a video call from being downgraded to an audio-only call.
324 * <p>
325 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
326 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
327 * downgraded from a video call back to a VideoState of
328 * {@link VideoProfile#STATE_AUDIO_ONLY}.
329 * <p>
330 * Intuitively, a call which can be downgraded to audio should also have local and remote
331 * video
332 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
333 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
334 */
335 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
336
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700337 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700338 * When set for an external connection, indicates that this {@code Connection} can be pulled
339 * from a remote device to the current device.
340 * <p>
341 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
342 * is set.
343 */
344 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
345
Pooja Jaind34698d2017-12-28 14:15:31 +0530346 /** Call supports the deflect feature. */
347 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
348
Tyler Gunn720c6642016-03-22 09:02:47 -0700349 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530350 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700351 //**********************************************************************************************
352
353 /**
354 * Indicates that the current device callback number should be shown.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700355 * <p>
356 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700357 * @hide
358 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700359 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700360 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700361
362 /**
363 * Whether the call is a generic conference, where we do not know the precise state of
364 * participants in the conference (eg. on CDMA).
Tyler Gunnd9da4772019-10-15 13:19:26 -0700365 * <p>
366 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700367 * @hide
368 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700369 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700370 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
371
372 /**
373 * Connection is using high definition audio.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700374 * <p>
375 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
376 * implies something like AMR wideband, but the interpretation of when a call is considered high
377 * definition is left to the {@link ConnectionService} to decide.
378 * <p>
379 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 */
381 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
382
383 /**
384 * Connection is using WIFI.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700385 * <p>
386 * Used to indicate that a call is taking place over WIFI versus a carrier network.
387 * <p>
388 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700389 */
390 public static final int PROPERTY_WIFI = 1<<3;
391
392 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700393 * When set, indicates that the {@code Connection} does not actually exist locally for the
394 * {@link ConnectionService}.
395 * <p>
396 * Consider, for example, a scenario where a user has two devices with the same phone number.
397 * When a user places a call on one devices, the telephony stack can represent that call on the
398 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700399 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700400 * <p>
401 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
402 * external connections. Only those {@link InCallService}s which have the
403 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
404 * manifest will see external connections.
405 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700406 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700407
Brad Ebinger15847072016-05-18 11:08:36 -0700408 /**
409 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
410 */
411 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700412
Hall Liu9f332c72016-07-14 15:37:37 -0700413 /**
414 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700415 * <p>
416 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
417 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700418 * @hide
419 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700420 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700421 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
422
Tyler Gunnf5035432017-01-09 09:43:12 -0800423 /**
424 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
425 * {@link ConnectionService}.
426 * <p>
427 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
428 */
429 public static final int PROPERTY_SELF_MANAGED = 1<<7;
430
Hall Liu95d55872017-01-25 17:12:49 -0800431 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800432 * Set by the framework to indicate that a connection has an active RTT session associated with
433 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800434 */
435 public static final int PROPERTY_IS_RTT = 1 << 8;
436
Eric Erfanian62706c52017-12-06 16:27:53 -0800437 /**
438 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000439 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800440 */
441 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
442
Tyler Gunn5bd90852018-09-21 09:37:07 -0700443 /**
444 * Set by the framework to indicate that the network has identified a Connection as an emergency
445 * call.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700446 * <p>
447 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
448 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700449 */
450 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
451
Tyler Gunnac60f952019-05-31 07:23:16 -0700452 /**
453 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
454 * than the current one. Used in scenarios where the conference originator is the remote device
455 * and the current device is a participant of that conference.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700456 * <p>
457 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700458 * @hide
459 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700460 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700461 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
462
Tyler Gunn96d6c402015-03-18 12:39:23 -0700463 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700464 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700465 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800466
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700467 /**
468 * Connection extra key used to store the last forwarded number associated with the current
469 * connection. Used to communicate to the user interface that the connection was forwarded via
470 * the specified number.
471 */
472 public static final String EXTRA_LAST_FORWARDED_NUMBER =
473 "android.telecom.extra.LAST_FORWARDED_NUMBER";
474
475 /**
476 * Connection extra key used to store a child number associated with the current connection.
477 * Used to communicate to the user interface that the connection was received via
478 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
479 * address.
480 */
481 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
482
483 /**
484 * Connection extra key used to store the subject for an incoming call. The user interface can
485 * query this extra and display its contents for incoming calls. Will only be used if the
486 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
487 */
488 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
489
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800490 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700491 * Boolean connection extra key set on a {@link Connection} in
492 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
493 * current active foreground call to be dropped.
494 */
495 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
496 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
497
498 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700499 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
500 * state to indicate the name of the third-party app which is responsible for the current
501 * foreground call.
502 * <p>
503 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
504 * is able to inform the user that answering the new incoming call will cause a call owned by
505 * another app to be dropped when the incoming call is answered.
506 */
507 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
508 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
509
510 /**
Hall Liu10208662016-06-15 17:55:00 -0700511 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700512 * additional call is disallowed.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700513 * <p>
514 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
515 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700516 * @hide
517 */
Tyler Gunnd9da4772019-10-15 13:19:26 -0700518 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700519 public static final String EXTRA_DISABLE_ADD_CALL =
520 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700521
522 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700523 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
524 * original Connection ID associated with the connection. Used in
525 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
526 * connection/conference added via
527 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
528 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
529 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
530 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
531 * be a way to ensure that we don't add the connection again as a duplicate.
532 * <p>
533 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
534 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
535 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
536 * in a new {@link Connection} which it adds to Telecom via
537 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
538 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
539 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
540 * ID it originally referred to the connection as. Thus Telecom needs to know that the
541 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700542 * <p>
543 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
544 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700545 * @hide
546 */
547 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
548 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
549
550 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700551 * Boolean connection extra key set on the extras passed to
552 * {@link Connection#sendConnectionEvent} which indicates that audio is present
553 * on the RTT call when the extra value is true.
554 */
555 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
556 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
557
558 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800559 * Connection event used to inform Telecom that it should play the on hold tone. This is used
560 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700561 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800562 */
563 public static final String EVENT_ON_HOLD_TONE_START =
564 "android.telecom.event.ON_HOLD_TONE_START";
565
566 /**
567 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
568 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700569 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800570 */
571 public static final String EVENT_ON_HOLD_TONE_END =
572 "android.telecom.event.ON_HOLD_TONE_END";
573
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700574 /**
575 * Connection event used to inform {@link InCallService}s when pulling of an external call has
576 * failed. The user interface should inform the user of the error.
577 * <p>
578 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
579 * API is called on a {@link Call} with the properties
580 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
581 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
582 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700583 * <p>
584 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
585 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700586 */
587 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
588
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700589 /**
590 * Connection event used to inform {@link InCallService}s when the merging of two calls has
591 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700592 * <p>
593 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
594 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700595 */
596 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
597
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700598 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700599 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnd9da4772019-10-15 13:19:26 -0700600 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700601 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
602 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700603 */
604 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
605
606 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700607 * Connection event used to inform {@link InCallService}s when the process of merging a
608 * Connection into a conference has begun.
609 * <p>
610 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
611 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700612 */
613 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
614
615 /**
616 * Connection event used to inform {@link InCallService}s when the process of merging a
617 * Connection into a conference has completed.
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.
Tyler Gunn78da7812017-05-09 14:34:57 -0700621 */
622 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
623
624 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700625 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
626 * the remote party.
627 * <p>
628 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
629 * call is being held locally on the device. When a capable {@link ConnectionService} receives
630 * signalling to indicate that the remote party has put the call on hold, it can send this
631 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700632 */
633 public static final String EVENT_CALL_REMOTELY_HELD =
634 "android.telecom.event.CALL_REMOTELY_HELD";
635
636 /**
637 * Connection event used to inform {@link InCallService}s when a call which was remotely held
638 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
639 * <p>
640 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
641 * call is being held locally on the device. When a capable {@link ConnectionService} receives
642 * signalling to indicate that the remote party has taken the call off hold, it can send this
643 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700644 */
645 public static final String EVENT_CALL_REMOTELY_UNHELD =
646 "android.telecom.event.CALL_REMOTELY_UNHELD";
647
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700648 /**
649 * Connection event used to inform an {@link InCallService} which initiated a call handover via
650 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
651 * successfully completed.
652 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700653 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
654 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700655 */
656 public static final String EVENT_HANDOVER_COMPLETE =
657 "android.telecom.event.HANDOVER_COMPLETE";
658
659 /**
660 * Connection event used to inform an {@link InCallService} which initiated a call handover via
661 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
662 * to complete.
663 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700664 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
665 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700666 */
667 public static final String EVENT_HANDOVER_FAILED =
668 "android.telecom.event.HANDOVER_FAILED";
669
shilub7ec9a02018-11-09 15:52:04 -0800670 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000671 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800672 */
673 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
674
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700675 /**
676 * Connection event used to inform an {@link InCallService} that the RTT audio indication
677 * has changed.
678 */
679 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
680 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
681
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 // Flag controlling whether PII is emitted into the logs
683 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
684
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700686 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
687 *
688 * @param capabilities A capability bit field.
689 * @return A human readable string representation.
690 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700692 return capabilitiesToStringInternal(capabilities, true /* isLong */);
693 }
694
695 /**
696 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
697 * string.
698 *
699 * @param capabilities A capability bit field.
700 * @return A human readable string representation.
701 * @hide
702 */
703 public static String capabilitiesToStringShort(int capabilities) {
704 return capabilitiesToStringInternal(capabilities, false /* isLong */);
705 }
706
707 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append("[");
710 if (isLong) {
711 builder.append("Capabilities:");
712 }
713
Tyler Gunnd9da4772019-10-15 13:19:26 -0700714 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800716 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700717 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700720 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800722 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700723 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800725 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700726 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800728 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700729 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700730 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800731 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700732 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700733 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800734 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700735 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700736 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700737 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700738 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700739 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700740 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700741 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
742 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800744 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700745 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700747 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700748 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700750 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700751 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
752 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700753 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800754 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700755 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
756 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700757 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800758 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700759 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700760 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500761 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700762 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700763 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700764 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700765 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700766 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700767 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700768 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
769 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700770 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700771 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700772 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
773 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700774 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700775 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700776 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700777 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700778 }
Tyler Gunnd9da4772019-10-15 13:19:26 -0700779 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530780 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
781 }
Bryce Lee81901682015-08-28 16:38:02 -0700782
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800783 builder.append("]");
784 return builder.toString();
785 }
786
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700787 /**
788 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
789 *
790 * @param properties A property bit field.
791 * @return A human readable string representation.
792 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700793 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700794 return propertiesToStringInternal(properties, true /* isLong */);
795 }
796
797 /**
798 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
799 *
800 * @param properties A property bit field.
801 * @return A human readable string representation.
802 * @hide
803 */
804 public static String propertiesToStringShort(int properties) {
805 return propertiesToStringInternal(properties, false /* isLong */);
806 }
807
808 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700809 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700810 builder.append("[");
811 if (isLong) {
812 builder.append("Properties:");
813 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700814
Tyler Gunnd9da4772019-10-15 13:19:26 -0700815 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800816 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
817 }
818
Tyler Gunnd9da4772019-10-15 13:19:26 -0700819 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700820 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700821 }
822
Tyler Gunnd9da4772019-10-15 13:19:26 -0700823 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700824 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700825 }
826
Tyler Gunnd9da4772019-10-15 13:19:26 -0700827 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700828 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700829 }
830
Tyler Gunnd9da4772019-10-15 13:19:26 -0700831 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700832 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700833 }
834
Tyler Gunnd9da4772019-10-15 13:19:26 -0700835 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700836 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700837 }
838
Tyler Gunnd9da4772019-10-15 13:19:26 -0700839 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700840 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700841 }
842
Tyler Gunnd9da4772019-10-15 13:19:26 -0700843 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800844 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
845 }
846
Tyler Gunnd9da4772019-10-15 13:19:26 -0700847 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
848 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700849 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
850 }
851
Tyler Gunnd9da4772019-10-15 13:19:26 -0700852 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700853 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
854 }
855
Tyler Gunn720c6642016-03-22 09:02:47 -0700856 builder.append("]");
857 return builder.toString();
858 }
859
Sailesh Nepal091768c2014-06-30 15:15:23 -0700860 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700861 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700862 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700863 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700864 public void onCallerDisplayNameChanged(
865 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700866 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700867 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700868 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800869 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700870 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700871 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800872 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700873 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800874 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700875 public void onVideoProviderChanged(
876 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700877 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
878 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800879 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700880 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700881 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700882 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700883 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700884 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700885 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800886 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800887 public void onRttInitiationSuccess(Connection c) {}
888 public void onRttInitiationFailure(Connection c, int reason) {}
889 public void onRttSessionRemotelyTerminated(Connection c) {}
890 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530891 /** @hide */
892 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800893 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700894 }
895
Tyler Gunnb702ef82015-05-29 11:51:53 -0700896 /**
Hall Liu95d55872017-01-25 17:12:49 -0800897 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800898 */
899 public static final class RttTextStream {
900 private static final int READ_BUFFER_SIZE = 1000;
901 private final InputStreamReader mPipeFromInCall;
902 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800903 private final ParcelFileDescriptor mFdFromInCall;
904 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700905
906 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800907 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
908
909 /**
910 * @hide
911 */
912 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800913 mFdFromInCall = fromInCall;
914 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700915 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700916
917 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800918 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700919 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800920 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800921 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800922 }
923
924 /**
925 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
926 * RTT transmits text in real-time, this method should be called as often as text snippets
927 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800928 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800929 * This method is not thread-safe -- calling it from multiple threads simultaneously may
930 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800931 *
Hall Liu95d55872017-01-25 17:12:49 -0800932 * @param input The message to send to the in-call app.
933 */
934 public void write(String input) throws IOException {
935 mPipeToInCall.write(input);
936 mPipeToInCall.flush();
937 }
938
939
940 /**
941 * Reads a string from the in-call app, blocking if there is no data available. Returns
942 * {@code null} if the RTT conversation has been terminated and there is no further data
943 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800944 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800945 * This method is not thread-safe -- calling it from multiple threads simultaneously may
946 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800947 *
Hall Liu95d55872017-01-25 17:12:49 -0800948 * @return A string containing text entered by the user, or {@code null} if the
949 * conversation has been terminated or if there was an error while reading.
950 */
Hall Liuffa4a812017-03-02 16:11:00 -0800951 public String read() throws IOException {
952 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
953 if (numRead < 0) {
954 return null;
955 }
956 return new String(mReadBuffer, 0, numRead);
957 }
958
959 /**
960 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
961 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800962 *
Hall Liuffa4a812017-03-02 16:11:00 -0800963 * @return A string containing text entered by the user, or {@code null} if the user has
964 * not entered any new text yet.
965 */
966 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700967 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800968 return read();
969 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800970 return null;
971 }
972 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800973
974 /** @hide */
975 public ParcelFileDescriptor getFdFromInCall() {
976 return mFdFromInCall;
977 }
978
979 /** @hide */
980 public ParcelFileDescriptor getFdToInCall() {
981 return mFdToInCall;
982 }
983 }
984
985 /**
986 * Provides constants to represent the results of responses to session modify requests sent via
987 * {@link Call#sendRttRequest()}
988 */
989 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700990 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800991 /**
992 * Session modify request was successful.
993 */
994 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
995
996 /**
997 * Session modify request failed.
998 */
999 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1000
1001 /**
1002 * Session modify request ignored due to invalid parameters.
1003 */
1004 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1005
1006 /**
1007 * Session modify request timed out.
1008 */
1009 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1010
1011 /**
1012 * Session modify request rejected by remote user.
1013 */
1014 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001015 }
1016
1017 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001018 * Provides a means of controlling the video session associated with a {@link Connection}.
1019 * <p>
1020 * Implementations create a custom subclass of {@link VideoProvider} and the
1021 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1022 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1023 * should set the {@link VideoProvider}.
1024 * <p>
1025 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1026 * {@link InCallService} implementations to issue requests related to the video session;
1027 * it provides a means for the {@link ConnectionService} to report events and information
1028 * related to the video session to Telecom and the {@link InCallService} implementations.
1029 * <p>
1030 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1031 * {@link android.telecom.InCallService.VideoCall}.
1032 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001033 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 /**
1035 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001036 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001037 */
1038 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001039
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001040 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001041 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1042 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 */
1044 public static final int SESSION_EVENT_RX_RESUME = 2;
1045
1046 /**
1047 * Video transmission has begun. This occurs after a negotiated start of video transmission
1048 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 */
1051 public static final int SESSION_EVENT_TX_START = 3;
1052
1053 /**
1054 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1055 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001056 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001057 */
1058 public static final int SESSION_EVENT_TX_STOP = 4;
1059
1060 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001061 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001062 * this as a cue to inform the user the camera is not available.
1063 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001064 */
1065 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1066
1067 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001068 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001069 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001070 * the camera has become available again.
1071 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 */
1073 public static final int SESSION_EVENT_CAMERA_READY = 6;
1074
1075 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001076 * Session event raised by Telecom when
1077 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1078 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1079 * @see #handleCallSessionEvent(int)
1080 */
1081 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1082
1083 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001084 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001085 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 */
1087 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1088
1089 /**
1090 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001091 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001092 */
1093 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1094
1095 /**
1096 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001097 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098 */
1099 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1100
Rekha Kumar07366812015-03-24 16:42:31 -07001101 /**
1102 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001103 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001104 */
1105 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1106
1107 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001108 * Session modify request rejected by remote user.
1109 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001110 */
1111 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1112
Tyler Gunn75958422015-04-15 14:23:42 -07001113 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 private static final int MSG_SET_CAMERA = 2;
1115 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1116 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1117 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1118 private static final int MSG_SET_ZOOM = 6;
1119 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1120 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1121 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001122 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001123 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001124 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001126 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1127 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1128 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1129 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1130 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1131 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001132 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1133 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001134 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1135
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001136 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001137 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001138
1139 /**
1140 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001141 *
1142 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1143 * load factor before resizing, 1 means we only expect a single thread to
1144 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001145 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001146 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1147 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148
1149 /**
1150 * Default handler used to consolidate binder method calls onto a single thread.
1151 */
1152 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001153 public VideoProviderHandler() {
1154 super();
1155 }
1156
1157 public VideoProviderHandler(Looper looper) {
1158 super(looper);
1159 }
1160
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 @Override
1162 public void handleMessage(Message msg) {
1163 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001164 case MSG_ADD_VIDEO_CALLBACK: {
1165 IBinder binder = (IBinder) msg.obj;
1166 IVideoCallback callback = IVideoCallback.Stub
1167 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001168 if (callback == null) {
1169 Log.w(this, "addVideoProvider - skipped; callback is null.");
1170 break;
1171 }
1172
Tyler Gunn75958422015-04-15 14:23:42 -07001173 if (mVideoCallbacks.containsKey(binder)) {
1174 Log.i(this, "addVideoProvider - skipped; already present.");
1175 break;
1176 }
1177 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001178 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001179 }
1180 case MSG_REMOVE_VIDEO_CALLBACK: {
1181 IBinder binder = (IBinder) msg.obj;
1182 IVideoCallback callback = IVideoCallback.Stub
1183 .asInterface((IBinder) msg.obj);
1184 if (!mVideoCallbacks.containsKey(binder)) {
1185 Log.i(this, "removeVideoProvider - skipped; not present.");
1186 break;
1187 }
1188 mVideoCallbacks.remove(binder);
1189 break;
1190 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001191 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001192 {
1193 SomeArgs args = (SomeArgs) msg.obj;
1194 try {
1195 onSetCamera((String) args.arg1);
1196 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001197 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001198 } finally {
1199 args.recycle();
1200 }
1201 }
1202 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001203 case MSG_SET_PREVIEW_SURFACE:
1204 onSetPreviewSurface((Surface) msg.obj);
1205 break;
1206 case MSG_SET_DISPLAY_SURFACE:
1207 onSetDisplaySurface((Surface) msg.obj);
1208 break;
1209 case MSG_SET_DEVICE_ORIENTATION:
1210 onSetDeviceOrientation(msg.arg1);
1211 break;
1212 case MSG_SET_ZOOM:
1213 onSetZoom((Float) msg.obj);
1214 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001215 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1216 SomeArgs args = (SomeArgs) msg.obj;
1217 try {
1218 onSendSessionModifyRequest((VideoProfile) args.arg1,
1219 (VideoProfile) args.arg2);
1220 } finally {
1221 args.recycle();
1222 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001224 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001225 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1226 onSendSessionModifyResponse((VideoProfile) msg.obj);
1227 break;
1228 case MSG_REQUEST_CAMERA_CAPABILITIES:
1229 onRequestCameraCapabilities();
1230 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001231 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1232 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001233 break;
1234 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001235 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001236 break;
1237 default:
1238 break;
1239 }
1240 }
1241 }
1242
1243 /**
1244 * IVideoProvider stub implementation.
1245 */
1246 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001247 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001249 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1250 }
1251
1252 public void removeVideoCallback(IBinder videoCallbackBinder) {
1253 mMessageHandler.obtainMessage(
1254 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 }
1256
Tyler Gunn159f35c2017-03-02 09:28:37 -08001257 public void setCamera(String cameraId, String callingPackageName,
1258 int targetSdkVersion) {
1259
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001260 SomeArgs args = SomeArgs.obtain();
1261 args.arg1 = cameraId;
1262 // Propagate the calling package; originally determined in
1263 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1264 // process.
1265 args.arg2 = callingPackageName;
1266 // Pass along the uid and pid of the calling app; this gets lost when we put the
1267 // message onto the handler. These are required for Telecom to perform a permission
1268 // check to see if the calling app is able to use the camera.
1269 args.argi1 = Binder.getCallingUid();
1270 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001271 // Pass along the target SDK version of the calling InCallService. This is used to
1272 // maintain backwards compatibility of the API for older callers.
1273 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001274 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 }
1276
1277 public void setPreviewSurface(Surface surface) {
1278 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1279 }
1280
1281 public void setDisplaySurface(Surface surface) {
1282 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1283 }
1284
1285 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001286 mMessageHandler.obtainMessage(
1287 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001288 }
1289
1290 public void setZoom(float value) {
1291 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1292 }
1293
Tyler Gunn45382162015-05-06 08:52:27 -07001294 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1295 SomeArgs args = SomeArgs.obtain();
1296 args.arg1 = fromProfile;
1297 args.arg2 = toProfile;
1298 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 }
1300
1301 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1302 mMessageHandler.obtainMessage(
1303 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1304 }
1305
1306 public void requestCameraCapabilities() {
1307 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1308 }
1309
1310 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001311 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 }
1313
Yorke Lee32f24732015-05-12 16:18:03 -07001314 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1316 }
1317 }
1318
1319 public VideoProvider() {
1320 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001321 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001322 }
1323
1324 /**
1325 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1326 *
1327 * @param looper The looper.
1328 * @hide
1329 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001330 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001331 public VideoProvider(Looper looper) {
1332 mBinder = new VideoProvider.VideoProviderBinder();
1333 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 }
1335
1336 /**
1337 * Returns binder object which can be used across IPC methods.
1338 * @hide
1339 */
1340 public final IVideoProvider getInterface() {
1341 return mBinder;
1342 }
1343
1344 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001345 * Sets the camera to be used for the outgoing video.
1346 * <p>
1347 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1348 * camera via
1349 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1350 * <p>
1351 * Sent from the {@link InCallService} via
1352 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001354 * @param cameraId The id of the camera (use ids as reported by
1355 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 */
1357 public abstract void onSetCamera(String cameraId);
1358
1359 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001360 * Sets the camera to be used for the outgoing video.
1361 * <p>
1362 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1363 * camera via
1364 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1365 * <p>
1366 * This prototype is used internally to ensure that the calling package name, UID and PID
1367 * are sent to Telecom so that can perform a camera permission check on the caller.
1368 * <p>
1369 * Sent from the {@link InCallService} via
1370 * {@link InCallService.VideoCall#setCamera(String)}.
1371 *
1372 * @param cameraId The id of the camera (use ids as reported by
1373 * {@link CameraManager#getCameraIdList()}).
1374 * @param callingPackageName The AppOpps package name of the caller.
1375 * @param callingUid The UID of the caller.
1376 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001377 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001378 * @hide
1379 */
1380 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001381 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001382
1383 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 * Sets the surface to be used for displaying a preview of what the user's camera is
1385 * currently capturing. When video transmission is enabled, this is the video signal which
1386 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001387 * <p>
1388 * Sent from the {@link InCallService} via
1389 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001391 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 */
1393 public abstract void onSetPreviewSurface(Surface surface);
1394
1395 /**
1396 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * <p>
1398 * Sent from the {@link InCallService} via
1399 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001401 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 */
1403 public abstract void onSetDisplaySurface(Surface surface);
1404
1405 /**
1406 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1407 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001408 * <p>
1409 * Sent from the {@link InCallService} via
1410 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 *
1412 * @param rotation The device orientation, in degrees.
1413 */
1414 public abstract void onSetDeviceOrientation(int rotation);
1415
1416 /**
1417 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001418 * <p>
1419 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420 *
1421 * @param value The camera zoom ratio.
1422 */
1423 public abstract void onSetZoom(float value);
1424
1425 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001426 * Issues a request to modify the properties of the current video session.
1427 * <p>
1428 * Example scenarios include: requesting an audio-only call to be upgraded to a
1429 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1430 * when the {@link InCallService} is no longer the foreground application.
1431 * <p>
1432 * If the {@link VideoProvider} determines a request to be invalid, it should call
1433 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1434 * invalid request back to the {@link InCallService}.
1435 * <p>
1436 * Where a request requires confirmation from the user of the peer device, the
1437 * {@link VideoProvider} must communicate the request to the peer device and handle the
1438 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1439 * is used to inform the {@link InCallService} of the result of the request.
1440 * <p>
1441 * Sent from the {@link InCallService} via
1442 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001443 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001444 * @param fromProfile The video profile prior to the request.
1445 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001446 */
Tyler Gunn45382162015-05-06 08:52:27 -07001447 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1448 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449
Tyler Gunnb702ef82015-05-29 11:51:53 -07001450 /**
1451 * Provides a response to a request to change the current video session properties.
1452 * <p>
1453 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1454 * video call, could decline the request and keep the call as audio-only.
1455 * In such a scenario, the {@code responseProfile} would have a video state of
1456 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1457 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1458 * <p>
1459 * Sent from the {@link InCallService} via
1460 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1461 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1462 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001463 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001464 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 */
1466 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1467
1468 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001469 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1470 * <p>
1471 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1472 * camera via
1473 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1474 * <p>
1475 * Sent from the {@link InCallService} via
1476 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 */
1478 public abstract void onRequestCameraCapabilities();
1479
1480 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001481 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1482 * video component of the current {@link Connection}.
1483 * <p>
1484 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1485 * via {@link VideoProvider#setCallDataUsage(long)}.
1486 * <p>
1487 * Sent from the {@link InCallService} via
1488 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001489 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001490 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491
1492 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001493 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1494 * the peer device when the video signal is paused.
1495 * <p>
1496 * Sent from the {@link InCallService} via
1497 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 *
1499 * @param uri URI of image to display.
1500 */
Yorke Lee32f24732015-05-12 16:18:03 -07001501 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502
1503 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001504 * Used to inform listening {@link InCallService} implementations when the
1505 * {@link VideoProvider} receives a session modification request.
1506 * <p>
1507 * Received by the {@link InCallService} via
1508 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001510 * @param videoProfile The requested video profile.
1511 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 */
1513 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001514 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001515 for (IVideoCallback callback : mVideoCallbacks.values()) {
1516 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001517 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001518 } catch (RemoteException ignored) {
1519 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001520 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 }
1522 }
1523 }
1524
1525 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001526 * Used to inform listening {@link InCallService} implementations when the
1527 * {@link VideoProvider} receives a response to a session modification request.
1528 * <p>
1529 * Received by the {@link InCallService} via
1530 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1531 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 *
1533 * @param status Status of the session modify request. Valid values are
1534 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1535 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001536 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1537 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1538 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1539 * @param requestedProfile The original request which was sent to the peer device.
1540 * @param responseProfile The actual profile changes agreed to by the peer device.
1541 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 */
1543 public void receiveSessionModifyResponse(int status,
1544 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001545 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001546 for (IVideoCallback callback : mVideoCallbacks.values()) {
1547 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001548 callback.receiveSessionModifyResponse(status, requestedProfile,
1549 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001550 } catch (RemoteException ignored) {
1551 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001552 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553 }
1554 }
1555 }
1556
1557 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001558 * Used to inform listening {@link InCallService} implementations when the
1559 * {@link VideoProvider} reports a call session event.
1560 * <p>
1561 * Received by the {@link InCallService} via
1562 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001563 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001564 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1565 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1566 * {@link VideoProvider#SESSION_EVENT_TX_START},
1567 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1568 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001569 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1570 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001571 */
1572 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001573 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001574 for (IVideoCallback callback : mVideoCallbacks.values()) {
1575 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001576 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001577 } catch (RemoteException ignored) {
1578 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001579 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001580 }
1581 }
1582 }
1583
1584 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001585 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1586 * peer's video have changed.
1587 * <p>
1588 * This could occur if, for example, the peer rotates their device, changing the aspect
1589 * ratio of the video, or if the user switches between the back and front cameras.
1590 * <p>
1591 * Received by the {@link InCallService} via
1592 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001593 *
1594 * @param width The updated peer video width.
1595 * @param height The updated peer video height.
1596 */
1597 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001598 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001599 for (IVideoCallback callback : mVideoCallbacks.values()) {
1600 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001601 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001602 } catch (RemoteException ignored) {
1603 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001604 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 }
1606 }
1607 }
1608
1609 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001610 * Used to inform listening {@link InCallService} implementations when the data usage of the
1611 * video associated with the current {@link Connection} has changed.
1612 * <p>
1613 * This could be in response to a preview request via
1614 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001615 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1616 * 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 -07001617 * <p>
1618 * Received by the {@link InCallService} via
1619 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001621 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1622 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 */
Yorke Lee32f24732015-05-12 16:18:03 -07001624 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001625 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001626 for (IVideoCallback callback : mVideoCallbacks.values()) {
1627 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001628 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001629 } catch (RemoteException ignored) {
1630 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001631 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001632 }
1633 }
1634 }
1635
1636 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001637 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001638 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001639 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001640 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1641 * @hide
1642 */
1643 public void changeCallDataUsage(long dataUsage) {
1644 setCallDataUsage(dataUsage);
1645 }
1646
1647 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001648 * Used to inform listening {@link InCallService} implementations when the capabilities of
1649 * the current camera have changed.
1650 * <p>
1651 * The {@link VideoProvider} should call this in response to
1652 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1653 * changed via {@link VideoProvider#onSetCamera(String)}.
1654 * <p>
1655 * Received by the {@link InCallService} via
1656 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1657 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001658 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001660 */
Yorke Lee400470f2015-05-12 13:31:25 -07001661 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001662 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001663 for (IVideoCallback callback : mVideoCallbacks.values()) {
1664 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001665 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001666 } catch (RemoteException ignored) {
1667 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001668 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001669 }
1670 }
1671 }
Rekha Kumar07366812015-03-24 16:42:31 -07001672
1673 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001674 * Used to inform listening {@link InCallService} implementations when the video quality
1675 * of the call has changed.
1676 * <p>
1677 * Received by the {@link InCallService} via
1678 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001679 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001680 * @param videoQuality The updated video quality. Valid values:
1681 * {@link VideoProfile#QUALITY_HIGH},
1682 * {@link VideoProfile#QUALITY_MEDIUM},
1683 * {@link VideoProfile#QUALITY_LOW},
1684 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001685 */
1686 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001687 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001688 for (IVideoCallback callback : mVideoCallbacks.values()) {
1689 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001690 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001691 } catch (RemoteException ignored) {
1692 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001693 }
Rekha Kumar07366812015-03-24 16:42:31 -07001694 }
1695 }
1696 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001697
1698 /**
1699 * Returns a string representation of a call session event.
1700 *
1701 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1702 * @return String representation of the call session event.
1703 * @hide
1704 */
1705 public static String sessionEventToString(int event) {
1706 switch (event) {
1707 case SESSION_EVENT_CAMERA_FAILURE:
1708 return SESSION_EVENT_CAMERA_FAILURE_STR;
1709 case SESSION_EVENT_CAMERA_READY:
1710 return SESSION_EVENT_CAMERA_READY_STR;
1711 case SESSION_EVENT_RX_PAUSE:
1712 return SESSION_EVENT_RX_PAUSE_STR;
1713 case SESSION_EVENT_RX_RESUME:
1714 return SESSION_EVENT_RX_RESUME_STR;
1715 case SESSION_EVENT_TX_START:
1716 return SESSION_EVENT_TX_START_STR;
1717 case SESSION_EVENT_TX_STOP:
1718 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001719 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1720 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001721 default:
1722 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1723 }
1724 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001725 }
1726
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001727 private final Listener mConnectionDeathListener = new Listener() {
1728 @Override
1729 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001730 if (mConferenceables.remove(c)) {
1731 fireOnConferenceableConnectionsChanged();
1732 }
1733 }
1734 };
1735
1736 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1737 @Override
1738 public void onDestroyed(Conference c) {
1739 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001740 fireOnConferenceableConnectionsChanged();
1741 }
1742 }
1743 };
1744
Jay Shrauner229e3822014-08-15 09:23:07 -07001745 /**
1746 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1747 * load factor before resizing, 1 means we only expect a single thread to
1748 * access the map so make only a single shard
1749 */
1750 private final Set<Listener> mListeners = Collections.newSetFromMap(
1751 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001752 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1753 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001754 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001755
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001756 // The internal telecom call ID associated with this connection.
1757 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001758 // The PhoneAccountHandle associated with this connection.
1759 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001760 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001761 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001762 private Uri mAddress;
1763 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001764 private String mCallerDisplayName;
1765 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001766 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001767 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001768 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001769 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001770 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001771 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001772 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001773 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001774 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001775 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001776 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001777 private Conference mConference;
1778 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001779 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001780 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001781 /**
1782 * The direction of the connection; used where an existing connection is created and we need to
1783 * communicate to Telecom whether its incoming or outgoing.
1784 */
1785 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786
1787 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001788 * Tracks the key set for the extras bundle provided on the last invocation of
1789 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1790 * keys which were set previously but are no longer present in the replacement Bundle.
1791 */
1792 private Set<String> mPreviousExtraKeys;
1793
1794 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795 * Create a new Connection.
1796 */
Santos Cordonf2951102014-07-20 19:06:29 -07001797 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001798
1799 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001800 * Returns the Telecom internal call ID associated with this connection. Should only be used
1801 * for debugging and tracing purposes.
Tyler Gunnd9da4772019-10-15 13:19:26 -07001802 * <p>
1803 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1804 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001805 *
Tyler Gunnd9da4772019-10-15 13:19:26 -07001806 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001807 * @hide
1808 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07001809 @SystemApi
1810 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001811 return mTelecomCallId;
1812 }
1813
1814 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001815 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001816 */
Andrew Lee100e2932014-09-08 15:34:24 -07001817 public final Uri getAddress() {
1818 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001819 }
1820
1821 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001822 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001823 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001824 */
Andrew Lee100e2932014-09-08 15:34:24 -07001825 public final int getAddressPresentation() {
1826 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001827 }
1828
1829 /**
1830 * @return The caller display name (CNAP).
1831 */
1832 public final String getCallerDisplayName() {
1833 return mCallerDisplayName;
1834 }
1835
1836 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001837 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001838 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001839 */
1840 public final int getCallerDisplayNamePresentation() {
1841 return mCallerDisplayNamePresentation;
1842 }
1843
1844 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001845 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001846 */
1847 public final int getState() {
1848 return mState;
1849 }
1850
1851 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001852 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001853 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1854 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1855 * {@link VideoProfile#STATE_TX_ENABLED},
1856 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001857 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001858 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001859 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07001860 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001861 return mVideoState;
1862 }
1863
1864 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001865 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001866 * being routed by the system. This is {@code null} if this Connection
1867 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001868 * @deprecated Use {@link #getCallAudioState()} instead.
1869 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001870 */
Yorke Lee4af59352015-05-13 14:14:54 -07001871 @SystemApi
1872 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001873 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001874 if (mCallAudioState == null) {
1875 return null;
1876 }
Yorke Lee4af59352015-05-13 14:14:54 -07001877 return new AudioState(mCallAudioState);
1878 }
1879
1880 /**
1881 * @return The audio state of the connection, describing how its audio is currently
1882 * being routed by the system. This is {@code null} if this Connection
1883 * does not directly know about its audio state.
1884 */
1885 public final CallAudioState getCallAudioState() {
1886 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001887 }
1888
1889 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001890 * @return The conference that this connection is a part of. Null if it is not part of any
1891 * conference.
1892 */
1893 public final Conference getConference() {
1894 return mConference;
1895 }
1896
1897 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001898 * Returns whether this connection is requesting that the system play a ringback tone
1899 * on its behalf.
1900 */
Andrew Lee100e2932014-09-08 15:34:24 -07001901 public final boolean isRingbackRequested() {
1902 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001903 }
1904
1905 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001906 * @return True if the connection's audio mode is VOIP.
1907 */
1908 public final boolean getAudioModeIsVoip() {
1909 return mAudioModeIsVoip;
1910 }
1911
1912 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001913 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1914 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1915 * start time of the conference.
Tyler Gunnd9da4772019-10-15 13:19:26 -07001916 * <p>
1917 * Note: This is an implementation detail specific to IMS conference calls over a mobile
1918 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07001919 *
Tyler Gunnd9da4772019-10-15 13:19:26 -07001920 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
1921 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07001922 *
1923 * @hide
1924 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07001925 @SystemApi
Roshan Piuse927ec02015-07-15 15:47:21 -07001926 public final long getConnectTimeMillis() {
1927 return mConnectTimeMillis;
1928 }
1929
1930 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001931 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1932 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1933 * start time of the conference.
Tyler Gunnd9da4772019-10-15 13:19:26 -07001934 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001935 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1936 * changes do not impact the call duration.
Tyler Gunnd9da4772019-10-15 13:19:26 -07001937 * <p>
1938 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001939 *
1940 * @return The time at which the {@link Connection} was connected.
1941 *
1942 * @hide
1943 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07001944 @SystemApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001945 public final long getConnectElapsedTimeMillis() {
1946 return mConnectElapsedTimeMillis;
1947 }
1948
1949 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001950 * Returns RIL voice radio technology used for current connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07001951 * <p>
1952 * Used by the Telephony {@link ConnectionService}.
Wei Huang7f7f72e2018-05-30 19:21:36 +08001953 *
1954 * @return the RIL voice radio technology used for current connection,
1955 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1956 *
1957 * @hide
1958 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07001959 @SystemApi
Chen Xuf85cf992019-10-02 00:20:43 -07001960 public final @RilRadioTechnology int getCallRadioTech() {
Wei Huang7f7f72e2018-05-30 19:21:36 +08001961 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1962 Bundle extras = getExtras();
1963 if (extras != null) {
1964 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1965 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1966 }
1967 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1968 }
1969
1970 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001971 * @return The status hints for this connection.
1972 */
1973 public final StatusHints getStatusHints() {
1974 return mStatusHints;
1975 }
1976
1977 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001978 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001979 * <p>
1980 * Extras should be updated using {@link #putExtras(Bundle)}.
1981 * <p>
1982 * Telecom or an {@link InCallService} can also update the extras via
1983 * {@link android.telecom.Call#putExtras(Bundle)}, and
1984 * {@link Call#removeExtras(List)}.
1985 * <p>
1986 * The connection is notified of changes to the extras made by Telecom or an
1987 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001988 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001989 * @return The extras associated with this connection.
1990 */
1991 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001992 Bundle extras = null;
1993 synchronized (mExtrasLock) {
1994 if (mExtras != null) {
1995 extras = new Bundle(mExtras);
1996 }
1997 }
1998 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001999 }
2000
2001 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002002 * Assign a listener to be notified of state changes.
2003 *
2004 * @param l A listener.
2005 * @return This Connection.
2006 *
2007 * @hide
2008 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002009 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002010 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002011 return this;
2012 }
2013
2014 /**
2015 * Remove a previously assigned listener that was being notified of state changes.
2016 *
2017 * @param l A Listener.
2018 * @return This Connection.
2019 *
2020 * @hide
2021 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002022 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002023 if (l != null) {
2024 mListeners.remove(l);
2025 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002026 return this;
2027 }
2028
2029 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002030 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002031 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002032 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002033 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002034 }
2035
2036 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002037 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2038 * ONLY for debugging purposes.
Tyler Gunnd9da4772019-10-15 13:19:26 -07002039 * <p>
2040 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2041 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2042 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002043 *
2044 * @param callId The telecom call ID.
2045 * @hide
2046 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07002047 @SystemApi
2048 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002049 mTelecomCallId = callId;
2050 }
2051
2052 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002053 * Inform this Connection that the state of its audio output has been changed externally.
2054 *
2055 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002056 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002057 */
Yorke Lee4af59352015-05-13 14:14:54 -07002058 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002059 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002060 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002061 mCallAudioState = state;
2062 onAudioStateChanged(getAudioState());
2063 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002064 }
2065
2066 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002067 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002068 * @return A string representation of the value.
2069 */
2070 public static String stateToString(int state) {
2071 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002072 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002073 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002075 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002076 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002077 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002079 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002080 case STATE_PULLING_CALL:
2081 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002082 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002083 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002084 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002085 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002086 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 return "DISCONNECTED";
2088 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002089 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 return "UNKNOWN";
2091 }
2092 }
2093
2094 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002095 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002096 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 public final int getConnectionCapabilities() {
2098 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002099 }
2100
2101 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002102 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2103 */
2104 public final int getConnectionProperties() {
2105 return mConnectionProperties;
2106 }
2107
2108 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002109 * Returns the connection's supported audio routes.
2110 *
2111 * @hide
2112 */
2113 public final int getSupportedAudioRoutes() {
2114 return mSupportedAudioRoutes;
2115 }
2116
2117 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002118 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002119 *
Andrew Lee100e2932014-09-08 15:34:24 -07002120 * @param address The new address.
2121 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002122 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002123 */
Andrew Lee100e2932014-09-08 15:34:24 -07002124 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002126 Log.d(this, "setAddress %s", address);
2127 mAddress = address;
2128 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002129 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002130 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002131 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002132 }
2133
2134 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002135 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002136 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002137 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002138 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002139 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002140 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002141 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002142 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002143 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002144 mCallerDisplayName = callerDisplayName;
2145 mCallerDisplayNamePresentation = presentation;
2146 for (Listener l : mListeners) {
2147 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2148 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002149 }
2150
2151 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002152 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002153 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2154 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2155 * {@link VideoProfile#STATE_TX_ENABLED},
2156 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002157 *
2158 * @param videoState The new video state.
2159 */
2160 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002161 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002162 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002163 mVideoState = videoState;
2164 for (Listener l : mListeners) {
2165 l.onVideoStateChanged(this, mVideoState);
2166 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002167 }
2168
2169 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002171 * communicate).
2172 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002173 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002174 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002175 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002176 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002177 }
2178
2179 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002180 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002181 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002182 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002183 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002184 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002185 }
2186
2187 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002188 * Sets state to initializing (this Connection is not yet ready to be used).
2189 */
2190 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002191 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002192 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002193 }
2194
2195 /**
2196 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2197 */
2198 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002199 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002200 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002201 }
2202
2203 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002204 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002205 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002206 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002207 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002208 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002209 }
2210
2211 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002212 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2213 * device). Only applicable for {@link Connection}s with
2214 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2215 */
2216 public final void setPulling() {
2217 checkImmutable();
2218 setState(STATE_PULLING_CALL);
2219 }
2220
2221 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002222 * Sets state to be on hold.
2223 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002224 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002225 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002226 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002227 }
2228
2229 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002230 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002231 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002232 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002233 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002234 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002235 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002236 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002237 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002238 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002239 }
2240
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002241 public final VideoProvider getVideoProvider() {
2242 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002243 }
2244
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002245 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002246 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002247 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002248 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002249 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002250 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002251 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002252 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002253 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002254 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002255 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002256 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002257 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002258 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002259 }
2260
2261 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002262 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2263 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2264 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2265 * to send an {@link #onPostDialContinue(boolean)} signal.
2266 *
2267 * @param remaining The DTMF character sequence remaining to be emitted once the
2268 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2269 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002270 */
2271 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002272 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002273 for (Listener l : mListeners) {
2274 l.onPostDialWait(this, remaining);
2275 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002276 }
2277
2278 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002279 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2280 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002281 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002282 *
2283 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002284 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002285 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002286 checkImmutable();
2287 for (Listener l : mListeners) {
2288 l.onPostDialChar(this, nextChar);
2289 }
2290 }
2291
2292 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002293 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002294 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002295 *
2296 * @param ringback Whether the ringback tone is to be played.
2297 */
Andrew Lee100e2932014-09-08 15:34:24 -07002298 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002299 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002300 if (mRingbackRequested != ringback) {
2301 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002302 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002303 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002304 }
2305 }
Ihab Awadf8358972014-05-28 16:46:42 -07002306 }
2307
2308 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002309 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002310 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002311 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002312 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002313 public final void setConnectionCapabilities(int connectionCapabilities) {
2314 checkImmutable();
2315 if (mConnectionCapabilities != connectionCapabilities) {
2316 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002317 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002318 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002319 }
2320 }
Santos Cordonb6939982014-06-04 20:20:58 -07002321 }
2322
2323 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002324 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2325 *
2326 * @param connectionProperties The new connection properties.
2327 */
2328 public final void setConnectionProperties(int connectionProperties) {
2329 checkImmutable();
2330 if (mConnectionProperties != connectionProperties) {
2331 mConnectionProperties = connectionProperties;
2332 for (Listener l : mListeners) {
2333 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2334 }
2335 }
2336 }
2337
2338 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002339 * Sets the supported audio routes.
2340 *
2341 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2342 * See {@link CallAudioState}
2343 * @hide
2344 */
2345 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2346 if ((supportedAudioRoutes
2347 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2348 throw new IllegalArgumentException(
2349 "supported audio routes must include either speaker or earpiece");
2350 }
2351
2352 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2353 mSupportedAudioRoutes = supportedAudioRoutes;
2354 for (Listener l : mListeners) {
2355 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2356 }
2357 }
2358 }
2359
2360 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002361 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002362 */
Evan Charlton36a71342014-07-19 16:31:02 -07002363 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002364 for (Listener l : mListeners) {
2365 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002366 }
Santos Cordonb6939982014-06-04 20:20:58 -07002367 }
2368
2369 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002370 * Requests that the framework use VOIP audio mode for this connection.
2371 *
2372 * @param isVoip True if the audio mode is VOIP.
2373 */
2374 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002375 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002376 mAudioModeIsVoip = isVoip;
2377 for (Listener l : mListeners) {
2378 l.onAudioModeIsVoipChanged(this, isVoip);
2379 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002380 }
2381
2382 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002383 * Sets the time at which a call became active on this Connection. This is set only
2384 * when a conference call becomes active on this connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07002385 * <p>
2386 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002387 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002388 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2389 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002390 *
2391 * @hide
2392 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07002393 @SystemApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002394 public final void setConnectTimeMillis(long connectTimeMillis) {
2395 mConnectTimeMillis = connectTimeMillis;
2396 }
2397
2398 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002399 * Sets the time at which a call became active on this Connection. This is set only
2400 * when a conference call becomes active on this connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07002401 * <p>
2402 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002403 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2404 * {@link SystemClock#elapsedRealtime()}.
2405 *
2406 * @hide
2407 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07002408 @SystemApi
Tyler Gunn17541392018-02-01 08:58:38 -08002409 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002410 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2411 }
2412
2413 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002414 * Sets RIL voice radio technology used for current connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07002415 * <p>
2416 * This property is set by the Telephony {@link ConnectionService}.
Wei Huang7f7f72e2018-05-30 19:21:36 +08002417 *
2418 * @param vrat the RIL Voice Radio Technology used for current connection,
2419 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2420 *
2421 * @hide
2422 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07002423 @SystemApi
Chen Xuf85cf992019-10-02 00:20:43 -07002424 public final void setCallRadioTech(@RilRadioTechnology int vrat) {
Tyler Gunnd9da4772019-10-15 13:19:26 -07002425 Bundle extras = getExtras();
2426 if (extras == null) {
2427 extras = new Bundle();
2428 }
2429 extras.putInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
Wei Huang7f7f72e2018-05-30 19:21:36 +08002430 ServiceState.rilRadioTechnologyToNetworkType(vrat));
Tyler Gunnd9da4772019-10-15 13:19:26 -07002431 putExtras(extras);
Wei Huang7f7f72e2018-05-30 19:21:36 +08002432 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2433 // This action only covers non-IMS CS conference calls.
2434 // For IMS PS call conference call, it can be updated via its host connection
2435 // {@link #Listener.onExtrasChanged} event.
2436 if (getConference() != null) {
2437 getConference().setCallRadioTech(vrat);
2438 }
2439 }
2440
2441 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002442 * Sets the label and icon status to display in the in-call UI.
2443 *
2444 * @param statusHints The status label and icon to set.
2445 */
2446 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002447 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002448 mStatusHints = statusHints;
2449 for (Listener l : mListeners) {
2450 l.onStatusHintsChanged(this, statusHints);
2451 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002452 }
2453
2454 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002455 * Sets the connections with which this connection can be conferenced.
2456 *
2457 * @param conferenceableConnections The set of connections this connection can conference with.
2458 */
2459 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002460 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002461 clearConferenceableList();
2462 for (Connection c : conferenceableConnections) {
2463 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2464 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002465 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002466 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002467 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002468 }
2469 }
2470 fireOnConferenceableConnectionsChanged();
2471 }
2472
2473 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002474 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2475 * or conferences with which this connection can be conferenced.
2476 *
2477 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002478 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002479 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002480 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002481 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002482 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2483 // small amount of items here.
2484 if (!mConferenceables.contains(c)) {
2485 if (c instanceof Connection) {
2486 Connection connection = (Connection) c;
2487 connection.addConnectionListener(mConnectionDeathListener);
2488 } else if (c instanceof Conference) {
2489 Conference conference = (Conference) c;
2490 conference.addListener(mConferenceDeathListener);
2491 }
2492 mConferenceables.add(c);
2493 }
2494 }
2495 fireOnConferenceableConnectionsChanged();
2496 }
2497
2498 /**
Tyler Gunnd9da4772019-10-15 13:19:26 -07002499 * Resets the CDMA connection time.
2500 * <p>
2501 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002502 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002503 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07002504 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002505 public final void resetConnectionTime() {
2506 for (Listener l : mListeners) {
2507 l.onConnectionTimeReset(this);
2508 }
2509 }
2510
2511 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002512 * Returns the connections or conferences with which this connection can be conferenced.
2513 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002514 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002515 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002516 }
2517
Yorke Lee53463962015-08-04 16:07:19 -07002518 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002519 * @hide
2520 */
2521 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002522 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002523 if (mConnectionService != null) {
2524 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2525 "which is already associated with another ConnectionService.");
2526 } else {
2527 mConnectionService = connectionService;
2528 }
2529 }
2530
2531 /**
2532 * @hide
2533 */
2534 public final void unsetConnectionService(ConnectionService connectionService) {
2535 if (mConnectionService != connectionService) {
2536 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2537 "that does not belong to the ConnectionService.");
2538 } else {
2539 mConnectionService = null;
2540 }
2541 }
2542
2543 /**
2544 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002545 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002546 *
2547 * @param conference The conference.
2548 * @return {@code true} if the conference was successfully set.
2549 * @hide
2550 */
2551 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002552 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002553 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002554 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002555 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002556 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2557 fireConferenceChanged();
2558 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002559 return true;
2560 }
2561 return false;
2562 }
2563
2564 /**
2565 * Resets the conference that this connection is a part of.
2566 * @hide
2567 */
2568 public final void resetConference() {
2569 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002570 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002571 mConference = null;
2572 fireConferenceChanged();
2573 }
2574 }
2575
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002576 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002577 * Set some extras that can be associated with this {@code Connection}.
2578 * <p>
2579 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2580 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2581 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002582 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2583 * {@link #removeExtras(String...)} methods to modify the extras.
2584 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002585 * 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 -07002586 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2587 *
2588 * @param extras The extras associated with this {@code Connection}.
2589 */
2590 public final void setExtras(@Nullable Bundle extras) {
2591 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002592
2593 // Add/replace any new or changed extras values.
2594 putExtras(extras);
2595
2596 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2597 // the current one and remove any keys that went away.
2598 if (mPreviousExtraKeys != null) {
2599 List<String> toRemove = new ArrayList<String>();
2600 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002601 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002602 toRemove.add(oldKey);
2603 }
2604 }
2605 if (!toRemove.isEmpty()) {
2606 removeExtras(toRemove);
2607 }
2608 }
2609
2610 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2611 // called we can see if the caller has removed any extras values.
2612 if (mPreviousExtraKeys == null) {
2613 mPreviousExtraKeys = new ArraySet<String>();
2614 }
2615 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002616 if (extras != null) {
2617 mPreviousExtraKeys.addAll(extras.keySet());
2618 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002619 }
2620
2621 /**
2622 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2623 * added.
2624 * <p>
2625 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2626 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2627 *
2628 * @param extras The extras to add.
2629 */
2630 public final void putExtras(@NonNull Bundle extras) {
2631 checkImmutable();
2632 if (extras == null) {
2633 return;
2634 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002635 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2636 // the listeners.
2637 Bundle listenerExtras;
2638 synchronized (mExtrasLock) {
2639 if (mExtras == null) {
2640 mExtras = new Bundle();
2641 }
2642 mExtras.putAll(extras);
2643 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002644 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002645 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002646 // Create a new clone of the extras for each listener so that they don't clobber
2647 // each other
2648 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002649 }
2650 }
2651
2652 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002653 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002654 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002655 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002656 */
2657 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002658 synchronized (mExtrasLock) {
2659 if (mExtras != null) {
2660 for (String key : keys) {
2661 mExtras.remove(key);
2662 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002663 }
2664 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002665 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002666 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002667 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002668 }
2669 }
2670
2671 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002672 * Removes extras from this {@code Connection}.
2673 *
2674 * @param keys The keys of the extras to remove.
2675 */
2676 public final void removeExtras(String ... keys) {
2677 removeExtras(Arrays.asList(keys));
2678 }
2679
2680 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002681 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2682 * be change to the {@link #getCallAudioState()}.
2683 * <p>
2684 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2685 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2686 * <p>
2687 * See also {@link InCallService#setAudioRoute(int)}.
2688 *
2689 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2690 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2691 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2692 */
2693 public final void setAudioRoute(int route) {
2694 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002695 l.onAudioRouteChanged(this, route, null);
2696 }
2697 }
2698
2699 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002700 * Request audio routing to a specific bluetooth device. Calling this method may result in
2701 * the device routing audio to a different bluetooth device than the one specified if the
2702 * bluetooth stack is unable to route audio to the requested device.
2703 * A list of available devices can be obtained via
2704 * {@link CallAudioState#getSupportedBluetoothDevices()}
2705 *
2706 * <p>
2707 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2708 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2709 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002710 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2711 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002712 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002713 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002714 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002715 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2716 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002717 }
2718 }
2719
2720 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002721 * Informs listeners that a previously requested RTT session via
2722 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002723 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002724 */
2725 public final void sendRttInitiationSuccess() {
2726 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2727 }
2728
2729 /**
2730 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002731 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002732 * has failed.
2733 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2734 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002735 */
2736 public final void sendRttInitiationFailure(int reason) {
2737 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2738 }
2739
2740 /**
2741 * Informs listeners that a currently active RTT session has been terminated by the remote
2742 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002743 */
2744 public final void sendRttSessionRemotelyTerminated() {
2745 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2746 }
2747
2748 /**
2749 * Informs listeners that the remote side of the call has requested an upgrade to include an
2750 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002751 */
2752 public final void sendRemoteRttRequest() {
2753 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2754 }
2755
2756 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002757 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002758 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002759 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002760 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2761 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002762 */
Yorke Lee4af59352015-05-13 14:14:54 -07002763 @SystemApi
2764 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002765 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002766
2767 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002768 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2769 *
2770 * @param state The new connection audio state.
2771 */
2772 public void onCallAudioStateChanged(CallAudioState state) {}
2773
2774 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002775 * Notifies this Connection of an internal state change. This method is called after the
2776 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002777 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002778 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002779 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002780 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002781
2782 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002783 * Notifies this Connection of a request to play a DTMF tone.
2784 *
2785 * @param c A DTMF character.
2786 */
Santos Cordonf2951102014-07-20 19:06:29 -07002787 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002788
2789 /**
2790 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2791 */
Santos Cordonf2951102014-07-20 19:06:29 -07002792 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002793
2794 /**
2795 * Notifies this Connection of a request to disconnect.
2796 */
Santos Cordonf2951102014-07-20 19:06:29 -07002797 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002798
2799 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002800 * Notifies this Connection of a request to disconnect a participant of the conference managed
2801 * by the connection.
2802 *
2803 * @param endpoint the {@link Uri} of the participant to disconnect.
2804 * @hide
2805 */
2806 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2807
2808 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002809 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002810 */
Santos Cordonf2951102014-07-20 19:06:29 -07002811 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002812
2813 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002814 * Notifies this Connection of a request to abort.
2815 */
Santos Cordonf2951102014-07-20 19:06:29 -07002816 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002817
2818 /**
2819 * Notifies this Connection of a request to hold.
2820 */
Santos Cordonf2951102014-07-20 19:06:29 -07002821 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002822
2823 /**
2824 * Notifies this Connection of a request to exit a hold state.
2825 */
Santos Cordonf2951102014-07-20 19:06:29 -07002826 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002827
2828 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002829 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002830 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002831 * <p>
2832 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2833 * the default dialer's {@link InCallService}.
2834 * <p>
2835 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2836 * Telecom framework may request that the call is answered in the following circumstances:
2837 * <ul>
2838 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2839 * <li>A car mode {@link InCallService} is in use which has declared
2840 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2841 * {@link InCallService} will be able to see calls from self-managed
2842 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2843 * behalf.</li>
2844 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002845 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002846 */
Santos Cordonf2951102014-07-20 19:06:29 -07002847 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002848
2849 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002850 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002851 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002852 * <p>
2853 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2854 * the default dialer's {@link InCallService}.
2855 * <p>
2856 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2857 * Telecom framework may request that the call is answered in the following circumstances:
2858 * <ul>
2859 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2860 * <li>A car mode {@link InCallService} is in use which has declared
2861 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2862 * {@link InCallService} will be able to see calls from self-managed
2863 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2864 * behalf.</li>
2865 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002866 */
2867 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002868 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002869 }
2870
2871 /**
2872 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302873 * a request to deflect.
2874 */
2875 public void onDeflect(Uri address) {}
2876
2877 /**
2878 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002879 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002880 * <p>
2881 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2882 * the default dialer's {@link InCallService}.
2883 * <p>
2884 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2885 * Telecom framework may request that the call is rejected in the following circumstances:
2886 * <ul>
2887 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2888 * <li>A car mode {@link InCallService} is in use which has declared
2889 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2890 * {@link InCallService} will be able to see calls from self-managed
2891 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2892 * behalf.</li>
2893 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002894 */
Santos Cordonf2951102014-07-20 19:06:29 -07002895 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002896
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002897 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002898 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2899 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002900 */
2901 public void onReject(String replyMessage) {}
2902
2903 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002904 * Notifies this Connection of a request to silence the ringer.
2905 * <p>
2906 * The ringer may be silenced by any of the following methods:
2907 * <ul>
2908 * <li>{@link TelecomManager#silenceRinger()}</li>
2909 * <li>The user presses the volume-down button while a call is ringing.</li>
2910 * </ul>
2911 * <p>
2912 * Self-managed {@link ConnectionService} implementations should override this method in their
2913 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2914 * your app set the ringtone as part of the incoming call {@link Notification} (see
2915 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2916 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2917 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2918 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002919 */
2920 public void onSilence() {}
2921
2922 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002923 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2924 */
Santos Cordonf2951102014-07-20 19:06:29 -07002925 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002926
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002927 /**
2928 * Notifies this Connection of a request to pull an external call to the local device.
2929 * <p>
2930 * The {@link InCallService} issues a request to pull an external call to the local device via
2931 * {@link Call#pullExternalCall()}.
2932 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002933 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2934 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002935 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002936 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002937 */
2938 public void onPullExternalCall() {}
2939
2940 /**
2941 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2942 * <p>
2943 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2944 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002945 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2946 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2947 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2948 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2949 * not aware of.
2950 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002951 * See also {@link Call#sendCallEvent(String, Bundle)}.
2952 *
2953 * @param event The call event.
2954 * @param extras Extras associated with the call event.
2955 */
2956 public void onCallEvent(String event, Bundle extras) {}
2957
Tyler Gunndee56a82016-03-23 16:06:34 -07002958 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002959 * Notifies this {@link Connection} that a handover has completed.
2960 * <p>
2961 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2962 * Bundle)} on the initiating side of the handover, and
2963 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2964 */
2965 public void onHandoverComplete() {}
2966
2967 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002968 * Notifies this {@link Connection} of a change to the extras made outside the
2969 * {@link ConnectionService}.
2970 * <p>
2971 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2972 * the {@link android.telecom.Call#putExtras(Bundle)} and
2973 * {@link Call#removeExtras(List)}.
2974 *
2975 * @param extras The new extras bundle.
2976 */
2977 public void onExtrasChanged(Bundle extras) {}
2978
Tyler Gunnf5035432017-01-09 09:43:12 -08002979 /**
2980 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2981 * displaying its incoming call user interface for the {@link Connection}.
2982 * <p>
2983 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2984 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2985 * should show its own incoming call user interface.
2986 * <p>
2987 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002988 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2989 * Telecom framework will display its own incoming call user interface to allow the user to
2990 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2991 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002992 * <p>
2993 * You should trigger the display of the incoming call user interface for your application by
2994 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002995 *
2996 * In your application code, you should create a {@link android.app.NotificationChannel} for
2997 * incoming call notifications from your app:
2998 * <pre><code>
2999 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3000 * NotificationManager.IMPORTANCE_MAX);
3001 * // other channel setup stuff goes here.
3002 *
3003 * // We'll use the default system ringtone for our incoming call notification channel. You can
3004 * // use your own audio resource here.
3005 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3006 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3007 * // Setting the AudioAttributes is important as it identifies the purpose of your
3008 * // notification sound.
3009 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3010 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3011 * .build());
3012 *
3013 * NotificationManager mgr = getSystemService(NotificationManager.class);
3014 * mgr.createNotificationChannel(channel);
3015 * </code></pre>
3016 * When it comes time to post a notification for your incoming call, ensure it uses your
3017 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003018 * <pre><code>
3019 * // Create an intent which triggers your fullscreen incoming call user interface.
3020 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3021 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3022 * intent.setClass(context, YourIncomingCallActivity.class);
3023 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3024 *
3025 * // Build the notification as an ongoing high priority item; this ensures it will show as
3026 * // a heads up notification which slides down over top of the current content.
3027 * final Notification.Builder builder = new Notification.Builder(context);
3028 * builder.setOngoing(true);
3029 * builder.setPriority(Notification.PRIORITY_HIGH);
3030 *
3031 * // Set notification content intent to take user to fullscreen UI if user taps on the
3032 * // notification body.
3033 * builder.setContentIntent(pendingIntent);
3034 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3035 * // manager deems it appropriate.
3036 * builder.setFullScreenIntent(pendingIntent, true);
3037 *
3038 * // Setup notification content.
3039 * builder.setSmallIcon( yourIconResourceId );
3040 * builder.setContentTitle("Your notification title");
3041 * builder.setContentText("Your notification content.");
3042 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003043 * // Set notification as insistent to cause your ringtone to loop.
3044 * Notification notification = builder.build();
3045 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003046 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003047 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003048 * NotificationManager notificationManager = mContext.getSystemService(
3049 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003050 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003051 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003052 */
3053 public void onShowIncomingCallUi() {}
3054
Hall Liub64ac4c2017-02-06 10:49:48 -08003055 /**
3056 * Notifies this {@link Connection} that the user has requested an RTT session.
3057 * The connection service should call {@link #sendRttInitiationSuccess} or
3058 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3059 * request, respectively.
3060 * @param rttTextStream The object that should be used to send text to or receive text from
3061 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003062 */
3063 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3064
3065 /**
3066 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3067 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003068 */
3069 public void onStopRtt() {}
3070
3071 /**
3072 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3073 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3074 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3075 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003076 * @param rttTextStream The object that should be used to send text to or receive text from
3077 * the in-call app.
3078 */
3079 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3080
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003081 static String toLogSafePhoneNumber(String number) {
3082 // For unknown number, log empty string.
3083 if (number == null) {
3084 return "";
3085 }
3086
3087 if (PII_DEBUG) {
3088 // When PII_DEBUG is true we emit PII.
3089 return number;
3090 }
3091
3092 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3093 // sanitized phone numbers.
3094 StringBuilder builder = new StringBuilder();
3095 for (int i = 0; i < number.length(); i++) {
3096 char c = number.charAt(i);
3097 if (c == '-' || c == '@' || c == '.') {
3098 builder.append(c);
3099 } else {
3100 builder.append('x');
3101 }
3102 }
3103 return builder.toString();
3104 }
3105
Ihab Awad542e0ea2014-05-16 10:22:16 -07003106 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003107 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003108 if (mState == STATE_DISCONNECTED && mState != state) {
3109 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003110 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003111 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003112 if (mState != state) {
3113 Log.d(this, "setState: %s", stateToString(state));
3114 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003115 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003116 for (Listener l : mListeners) {
3117 l.onStateChanged(this, state);
3118 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003119 }
3120 }
3121
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003122 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003123 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003124 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3125 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003126 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003127 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003128
3129 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003130 if (mImmutable) {
3131 throw new UnsupportedOperationException("Connection is immutable");
3132 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003133 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003134 }
3135
Evan Charltonbf11f982014-07-20 22:06:28 -07003136 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003137 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003138 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3139 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003140 * <p>
3141 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3142 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003143 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003144 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003145 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003146 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003147 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3148 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003149 }
3150
Evan Charltonbf11f982014-07-20 22:06:28 -07003151 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003152 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3153 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3154 * this should never be un-@hide-den.
3155 *
3156 * @hide
3157 */
3158 public void checkImmutable() {}
3159
3160 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003161 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3162 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3163 * that state. This connection should not be used for anything, and no other
3164 * {@code Connection}s should be attempted.
3165 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003166 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003167 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003168 * @return A {@code Connection} which indicates that the underlying connection should
3169 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003170 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003171 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003172 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003173 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003174
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003175 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003176 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003177 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003178 }
3179 }
3180
Santos Cordon823fd3c2014-08-07 18:35:18 -07003181 private final void fireConferenceChanged() {
3182 for (Listener l : mListeners) {
3183 l.onConferenceChanged(this, mConference);
3184 }
3185 }
3186
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003187 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003188 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003189 if (c instanceof Connection) {
3190 Connection connection = (Connection) c;
3191 connection.removeConnectionListener(mConnectionDeathListener);
3192 } else if (c instanceof Conference) {
3193 Conference conference = (Conference) c;
3194 conference.removeListener(mConferenceDeathListener);
3195 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003196 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003197 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003198 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003199
3200 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003201 * Handles a change to extras received from Telecom.
3202 *
3203 * @param extras The new extras.
3204 * @hide
3205 */
3206 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003207 Bundle b = null;
3208 synchronized (mExtrasLock) {
3209 mExtras = extras;
3210 if (mExtras != null) {
3211 b = new Bundle(mExtras);
3212 }
3213 }
3214 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003215 }
3216
3217 /**
Tyler Gunnd9da4772019-10-15 13:19:26 -07003218 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3219 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003220 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07003221 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003222 for (Listener l : mListeners) {
3223 l.onConferenceMergeFailed(this);
3224 }
3225 }
3226
3227 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303228 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3229 * changed due to an emergency call being redialed.
3230 * @param pHandle The new PhoneAccountHandle for this connection.
3231 * @hide
3232 */
3233 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3234 for (Listener l : mListeners) {
3235 l.onPhoneAccountChanged(this, pHandle);
3236 }
3237 }
3238
3239 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003240 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07003241 * <p>
3242 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3243 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003244 *
Tyler Gunnd9da4772019-10-15 13:19:26 -07003245 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003246 * @hide
3247 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07003248 @SystemApi
3249 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003250 if (mPhoneAccountHandle != phoneAccountHandle) {
3251 mPhoneAccountHandle = phoneAccountHandle;
3252 notifyPhoneAccountChanged(phoneAccountHandle);
3253 }
3254 }
3255
3256 /**
3257 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07003258 * <p>
3259 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3260 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003261 *
Tyler Gunnd9da4772019-10-15 13:19:26 -07003262 * @return the phone account handle specified via
3263 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003264 * @hide
3265 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07003266 @SystemApi
3267 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003268 return mPhoneAccountHandle;
3269 }
3270
3271 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003272 * Sends an event associated with this {@code Connection} with associated event extras to the
3273 * {@link InCallService}.
3274 * <p>
3275 * Connection events are used to communicate point in time information from a
3276 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3277 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3278 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3279 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3280 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3281 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3282 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3283 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3284 * <p>
3285 * Events are exposed to {@link InCallService} implementations via
3286 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3287 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003288 * 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 -07003289 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3290 * some events altogether.
3291 * <p>
3292 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3293 * conflicts between {@link ConnectionService} implementations. Further, custom
3294 * {@link ConnectionService} implementations shall not re-purpose events in the
3295 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3296 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3297 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3298 * {@code com.example.extra.MY_EXTRA}).
3299 * <p>
3300 * When defining events and the associated extras, it is important to keep their behavior
3301 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3302 * events/extras should me maintained to ensure backwards compatibility with older
3303 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003304 *
3305 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003306 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003307 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003308 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003309 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003310 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003311 }
3312 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003313
3314 /**
3315 * @return The direction of the call.
3316 * @hide
3317 */
3318 public final @Call.Details.CallDirection int getCallDirection() {
3319 return mCallDirection;
3320 }
3321
3322 /**
3323 * Sets the direction of this connection.
Tyler Gunnd9da4772019-10-15 13:19:26 -07003324 * <p>
3325 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3326 * call direction.
3327 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003328 * @param callDirection The direction of this connection.
3329 * @hide
3330 */
Tyler Gunnd9da4772019-10-15 13:19:26 -07003331 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003332 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3333 mCallDirection = callDirection;
3334 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003335}