blob: ae20aed2d3c71a0e46b6511238c7e2373f999820 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070021import android.annotation.SystemApi;
Tyler Gunn5567d742019-10-31 13:04:37 -070022import android.annotation.TestApi;
Mathew Inwood42346d12018-08-01 11:33:05 +010023import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080024import android.app.Notification;
Hall Liua98f58b2017-11-07 17:59:28 -080025import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070027import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080029import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070030import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Handler;
32import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070033import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080035import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070037import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080038import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070039import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070041
Youming Yed6de26e2019-01-30 11:20:35 -080042import com.android.internal.os.SomeArgs;
43import com.android.internal.telecom.IVideoCallback;
44import com.android.internal.telecom.IVideoProvider;
45
Hall Liua549fed2018-02-09 16:40:03 -080046import java.io.FileInputStream;
47import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080048import java.io.IOException;
49import java.io.InputStreamReader;
50import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070051import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070052import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070053import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070055import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070056import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070057import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
59/**
Santos Cordon895d4b82015-06-25 16:41:48 -070060 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
61 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070062 * <p>
63 * Implementations create a custom subclass of {@code Connection} and return it to the framework
64 * as the return value of
65 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
66 * or
67 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
68 * Implementations are then responsible for updating the state of the {@code Connection}, and
69 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
70 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070071 * <p>
72 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
73 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
74 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
75 * {@code Connection} instance.
76 * <p>
77 * Basic call support requires overriding the following methods: {@link #onAnswer()},
78 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
79 * <p>
80 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
81 * {@link #onUnhold()} methods should be overridden to provide hold support for the
82 * {@code Connection}.
83 * <p>
84 * Where a {@code Connection} supports a variation of video calling (e.g. the
85 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
86 * to support answering a call as a video call.
87 * <p>
88 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
89 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
90 * support for pulling the external call.
91 * <p>
92 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
93 * overridden.
94 * <p>
95 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
96 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
97 * for example, call events from a {@link InCallService} are handled,
98 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
99 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
100 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
101 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700102 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700103public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700104
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 /**
106 * The connection is initializing. This is generally the first state for a {@code Connection}
107 * returned by a {@link ConnectionService}.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_INITIALIZING = 0;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * The connection is new and not connected.
113 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 public static final int STATE_NEW = 1;
115
Santos Cordon895d4b82015-06-25 16:41:48 -0700116 /**
117 * An incoming connection is in the ringing state. During this state, the user's ringer or
118 * vibration feature will be activated.
119 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700120 public static final int STATE_RINGING = 2;
121
Santos Cordon895d4b82015-06-25 16:41:48 -0700122 /**
123 * An outgoing connection is in the dialing state. In this state the other party has not yet
124 * answered the call and the user traditionally hears a ringback tone.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_DIALING = 3;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is active. Both parties are connected to the call and can actively communicate.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_ACTIVE = 4;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection is on hold.
135 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700136 public static final int STATE_HOLDING = 5;
137
Santos Cordon895d4b82015-06-25 16:41:48 -0700138 /**
139 * A connection has been disconnected. This is the final state once the user has been
140 * disconnected from a call either locally, remotely or by an error in the service.
141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 public static final int STATE_DISCONNECTED = 6;
143
Santos Cordon895d4b82015-06-25 16:41:48 -0700144 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * The state of an external connection which is in the process of being pulled from a remote
146 * device to the local device.
147 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700148 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700149 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
150 */
151 public static final int STATE_PULLING_CALL = 7;
152
153 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 * Connection can currently be put on hold or unheld. This is distinct from
155 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
156 * it does not at the moment support the function. This can be true while the call is in the
157 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
158 * display a disabled 'hold' button.
159 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800160 public static final int CAPABILITY_HOLD = 0x00000001;
161
162 /** Connection supports the hold feature. */
163 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
164
165 /**
166 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
167 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
168 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
169 * capability allows a merge button to be shown while the conference is in the foreground
170 * of the in-call UI.
171 * <p>
172 * This is only intended for use by a {@link Conference}.
173 */
174 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
175
176 /**
177 * Connections within a conference can be swapped between foreground and background.
178 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
179 * <p>
180 * This is only intended for use by a {@link Conference}.
181 */
182 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
183
184 /**
185 * @hide
186 */
187 public static final int CAPABILITY_UNUSED = 0x00000010;
188
189 /** Connection supports responding via text option. */
190 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
191
192 /** Connection can be muted. */
193 public static final int CAPABILITY_MUTE = 0x00000040;
194
195 /**
196 * Connection supports conference management. This capability only applies to
197 * {@link Conference}s which can have {@link Connection}s as children.
198 */
199 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210
211 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700214 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700218 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800219 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
221
222 /**
223 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
226
227 /**
228 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700229 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700230 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232
233 /**
234 * Connection is able to be separated from its parent {@code Conference}, if any.
235 */
236 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
237
238 /**
239 * Connection is able to be individually disconnected when in a {@code Conference}.
240 */
241 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
242
243 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245 * @hide
246 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 * @hide
252 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254
255 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257 * @hide
258 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260
Tyler Gunn068085b2015-02-06 13:56:52 -0800261 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700262 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800263 * @hide
264 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700265 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800266
Tyler Gunn96d6c402015-03-18 12:39:23 -0700267 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500268 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700269 * <p>
270 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
271 * place as soon as the device answers the call, but prior to it being connected. This is an
272 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500273 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700274 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700275 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700276 @TestApi
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 Gunnc63f9082019-10-15 13:19:26 -0700313 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700314 @TestApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700315 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
316
Bryce Lee81901682015-08-28 16:38:02 -0700317 /**
318 * Indicates that the connection itself wants to handle any sort of reply response, rather than
319 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700320 */
321 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
322
Tyler Gunnf97a0092016-01-19 15:59:34 -0800323 /**
324 * When set, prevents a video call from being downgraded to an audio-only call.
325 * <p>
326 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
327 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
328 * downgraded from a video call back to a VideoState of
329 * {@link VideoProfile#STATE_AUDIO_ONLY}.
330 * <p>
331 * Intuitively, a call which can be downgraded to audio should also have local and remote
332 * video
333 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
334 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
335 */
336 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
337
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700338 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700339 * When set for an external connection, indicates that this {@code Connection} can be pulled
340 * from a remote device to the current device.
341 * <p>
342 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
343 * is set.
344 */
345 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
346
Pooja Jaind34698d2017-12-28 14:15:31 +0530347 /** Call supports the deflect feature. */
348 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
349
Tyler Gunn720c6642016-03-22 09:02:47 -0700350 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530351 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700352 //**********************************************************************************************
353
354 /**
355 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700356 * <p>
357 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700358 * @hide
359 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700360 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700361 @TestApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700362 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700363
364 /**
365 * Whether the call is a generic conference, where we do not know the precise state of
366 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700367 * <p>
368 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700369 * @hide
370 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700371 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700372 @TestApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700373 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
374
375 /**
376 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700377 * <p>
378 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
379 * implies something like AMR wideband, but the interpretation of when a call is considered high
380 * definition is left to the {@link ConnectionService} to decide.
381 * <p>
382 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700383 */
384 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
385
386 /**
387 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700388 * <p>
389 * Used to indicate that a call is taking place over WIFI versus a carrier network.
390 * <p>
391 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700392 */
393 public static final int PROPERTY_WIFI = 1<<3;
394
395 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700396 * When set, indicates that the {@code Connection} does not actually exist locally for the
397 * {@link ConnectionService}.
398 * <p>
399 * Consider, for example, a scenario where a user has two devices with the same phone number.
400 * When a user places a call on one devices, the telephony stack can represent that call on the
401 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700403 * <p>
404 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
405 * external connections. Only those {@link InCallService}s which have the
406 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
407 * manifest will see external connections.
408 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700409 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700410
Brad Ebinger15847072016-05-18 11:08:36 -0700411 /**
412 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
413 */
414 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700415
Hall Liu9f332c72016-07-14 15:37:37 -0700416 /**
417 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700418 * <p>
419 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
420 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700421 * @hide
422 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700423 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700424 @TestApi
Hall Liu9f332c72016-07-14 15:37:37 -0700425 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
426
Tyler Gunnf5035432017-01-09 09:43:12 -0800427 /**
428 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
429 * {@link ConnectionService}.
430 * <p>
431 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
432 */
433 public static final int PROPERTY_SELF_MANAGED = 1<<7;
434
Hall Liu95d55872017-01-25 17:12:49 -0800435 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800436 * Set by the framework to indicate that a connection has an active RTT session associated with
437 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800438 */
439 public static final int PROPERTY_IS_RTT = 1 << 8;
440
Eric Erfanian62706c52017-12-06 16:27:53 -0800441 /**
442 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700443 * <p>
444 * This is used for outgoing calls.
445 *
446 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800447 */
448 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
449
Tyler Gunn5bd90852018-09-21 09:37:07 -0700450 /**
451 * Set by the framework to indicate that the network has identified a Connection as an emergency
452 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700453 * <p>
454 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
455 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700456 */
457 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
458
Tyler Gunnac60f952019-05-31 07:23:16 -0700459 /**
460 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
461 * than the current one. Used in scenarios where the conference originator is the remote device
462 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700463 * <p>
464 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700465 * @hide
466 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700467 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700468 @TestApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700469 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
470
Tyler Gunn96d6c402015-03-18 12:39:23 -0700471 //**********************************************************************************************
Tyler Gunnac60f952019-05-31 07:23:16 -0700472 // Next PROPERTY value: 1<<12
Tyler Gunn96d6c402015-03-18 12:39:23 -0700473 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800474
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700475 /**
allenwtsu2aca9892019-11-25 14:38:21 +0800476 * Define IMS Audio Codec
477 */
478 // Current audio codec is NONE
479 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
480 // Current audio codec is AMR
481 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
482 // Current audio codec is AMR_WB
483 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
484 // Current audio codec is QCELP13K
485 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
486 // Current audio codec is EVRC
487 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
488 // Current audio codec is EVRC_B
489 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
490 // Current audio codec is EVRC_WB
491 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
492 // Current audio codec is EVRC_NW
493 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
494 // Current audio codec is GSM_EFR
495 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
496 // Current audio codec is GSM_FR
497 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
498 // Current audio codec is GSM_HR
499 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
500 // Current audio codec is G711U
501 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
502 // Current audio codec is G723
503 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
504 // Current audio codec is G711A
505 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
506 // Current audio codec is G722
507 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
508 // Current audio codec is G711AB
509 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
510 // Current audio codec is G729
511 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
512 // Current audio codec is EVS_NB
513 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
514 // Current audio codec is EVS_WB
515 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
516 // Current audio codec is EVS_SWB
517 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
518 // Current audio codec is EVS_FB
519 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
520
521 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700522 * Connection extra key used to store the last forwarded number associated with the current
523 * connection. Used to communicate to the user interface that the connection was forwarded via
524 * the specified number.
525 */
526 public static final String EXTRA_LAST_FORWARDED_NUMBER =
527 "android.telecom.extra.LAST_FORWARDED_NUMBER";
528
529 /**
530 * Connection extra key used to store a child number associated with the current connection.
531 * Used to communicate to the user interface that the connection was received via
532 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
533 * address.
534 */
535 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
536
537 /**
538 * Connection extra key used to store the subject for an incoming call. The user interface can
539 * query this extra and display its contents for incoming calls. Will only be used if the
540 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
541 */
542 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
543
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800544 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700545 * Boolean connection extra key set on a {@link Connection} in
546 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
547 * current active foreground call to be dropped.
548 */
549 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
550 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
551
552 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700553 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
554 * state to indicate the name of the third-party app which is responsible for the current
555 * foreground call.
556 * <p>
557 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
558 * is able to inform the user that answering the new incoming call will cause a call owned by
559 * another app to be dropped when the incoming call is answered.
560 */
561 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
562 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
563
564 /**
Hall Liu10208662016-06-15 17:55:00 -0700565 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700566 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700567 * <p>
568 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
569 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700570 * @hide
571 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700572 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -0700573 @TestApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700574 public static final String EXTRA_DISABLE_ADD_CALL =
575 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700576
577 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700578 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
579 * original Connection ID associated with the connection. Used in
580 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
581 * connection/conference added via
582 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
583 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
584 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
585 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
586 * be a way to ensure that we don't add the connection again as a duplicate.
587 * <p>
588 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
589 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
590 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
591 * in a new {@link Connection} which it adds to Telecom via
592 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
593 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
594 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
595 * ID it originally referred to the connection as. Thus Telecom needs to know that the
596 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700597 * <p>
598 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
599 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700600 * @hide
601 */
602 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
603 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
604
605 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700606 * Boolean connection extra key set on the extras passed to
607 * {@link Connection#sendConnectionEvent} which indicates that audio is present
608 * on the RTT call when the extra value is true.
609 */
610 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
611 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
612
613 /**
allenwtsu2aca9892019-11-25 14:38:21 +0800614 * The audio codec in use for the current {@link Connection}, if known. Valid values include
615 * {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
616 */
617 public static final String EXTRA_AUDIO_CODEC =
618 "android.telecom.extra.AUDIO_CODEC";
619
620 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800621 * Connection event used to inform Telecom that it should play the on hold tone. This is used
622 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700623 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800624 */
625 public static final String EVENT_ON_HOLD_TONE_START =
626 "android.telecom.event.ON_HOLD_TONE_START";
627
628 /**
629 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
630 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700631 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800632 */
633 public static final String EVENT_ON_HOLD_TONE_END =
634 "android.telecom.event.ON_HOLD_TONE_END";
635
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700636 /**
637 * Connection event used to inform {@link InCallService}s when pulling of an external call has
638 * failed. The user interface should inform the user of the error.
639 * <p>
640 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
641 * API is called on a {@link Call} with the properties
642 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
643 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
644 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700645 * <p>
646 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
647 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700648 */
649 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
650
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700651 /**
652 * Connection event used to inform {@link InCallService}s when the merging of two calls has
653 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700654 * <p>
655 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
656 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700657 */
658 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
659
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700660 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700661 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700662 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700663 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
664 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700665 */
666 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
667
668 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700669 * Connection event used to inform {@link InCallService}s when the process of merging a
670 * Connection into a conference has begun.
671 * <p>
672 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
673 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700674 */
675 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
676
677 /**
678 * Connection event used to inform {@link InCallService}s when the process of merging a
679 * Connection into a conference has completed.
680 * <p>
681 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
682 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700683 */
684 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
685
686 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700687 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
688 * the remote party.
689 * <p>
690 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
691 * call is being held locally on the device. When a capable {@link ConnectionService} receives
692 * signalling to indicate that the remote party has put the call on hold, it can send this
693 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700694 */
695 public static final String EVENT_CALL_REMOTELY_HELD =
696 "android.telecom.event.CALL_REMOTELY_HELD";
697
698 /**
699 * Connection event used to inform {@link InCallService}s when a call which was remotely held
700 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
701 * <p>
702 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
703 * call is being held locally on the device. When a capable {@link ConnectionService} receives
704 * signalling to indicate that the remote party has taken the call off hold, it can send this
705 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700706 */
707 public static final String EVENT_CALL_REMOTELY_UNHELD =
708 "android.telecom.event.CALL_REMOTELY_UNHELD";
709
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700710 /**
711 * Connection event used to inform an {@link InCallService} which initiated a call handover via
712 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
713 * successfully completed.
714 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700715 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
716 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700717 */
718 public static final String EVENT_HANDOVER_COMPLETE =
719 "android.telecom.event.HANDOVER_COMPLETE";
720
721 /**
722 * Connection event used to inform an {@link InCallService} which initiated a call handover via
723 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
724 * to complete.
725 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700726 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
727 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700728 */
729 public static final String EVENT_HANDOVER_FAILED =
730 "android.telecom.event.HANDOVER_FAILED";
731
shilub7ec9a02018-11-09 15:52:04 -0800732 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000733 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800734 */
735 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
736
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700737 /**
738 * Connection event used to inform an {@link InCallService} that the RTT audio indication
739 * has changed.
740 */
741 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
742 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
743
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700744 // Flag controlling whether PII is emitted into the logs
745 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
746
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800747 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700748 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
749 *
750 * @param capabilities A capability bit field.
751 * @return A human readable string representation.
752 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800753 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700754 return capabilitiesToStringInternal(capabilities, true /* isLong */);
755 }
756
757 /**
758 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
759 * string.
760 *
761 * @param capabilities A capability bit field.
762 * @return A human readable string representation.
763 * @hide
764 */
765 public static String capabilitiesToStringShort(int capabilities) {
766 return capabilitiesToStringInternal(capabilities, false /* isLong */);
767 }
768
769 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800770 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700771 builder.append("[");
772 if (isLong) {
773 builder.append("Capabilities:");
774 }
775
Tyler Gunnc63f9082019-10-15 13:19:26 -0700776 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700777 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800778 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700779 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700780 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800781 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700782 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800784 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700785 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700786 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800787 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700788 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700789 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800790 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700791 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700792 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800793 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700794 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700795 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800796 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700797 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700798 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700799 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700800 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700801 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700802 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700803 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
804 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700805 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700807 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700808 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700809 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700810 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700811 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700812 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700813 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
814 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700815 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700817 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
818 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700819 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800820 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700821 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700822 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500823 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700824 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700825 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700826 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700827 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700828 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700829 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700830 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
831 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700832 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700833 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700834 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
835 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700836 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700837 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700838 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700839 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700840 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700841 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +0530842 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
843 }
Bryce Lee81901682015-08-28 16:38:02 -0700844
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800845 builder.append("]");
846 return builder.toString();
847 }
848
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700849 /**
850 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
851 *
852 * @param properties A property bit field.
853 * @return A human readable string representation.
854 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700855 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700856 return propertiesToStringInternal(properties, true /* isLong */);
857 }
858
859 /**
860 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
861 *
862 * @param properties A property bit field.
863 * @return A human readable string representation.
864 * @hide
865 */
866 public static String propertiesToStringShort(int properties) {
867 return propertiesToStringInternal(properties, false /* isLong */);
868 }
869
870 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700871 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700872 builder.append("[");
873 if (isLong) {
874 builder.append("Properties:");
875 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700876
Tyler Gunnc63f9082019-10-15 13:19:26 -0700877 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -0800878 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
879 }
880
Tyler Gunnc63f9082019-10-15 13:19:26 -0700881 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -0700882 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700883 }
884
Tyler Gunnc63f9082019-10-15 13:19:26 -0700885 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700886 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700887 }
888
Tyler Gunnc63f9082019-10-15 13:19:26 -0700889 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -0700890 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700891 }
892
Tyler Gunnc63f9082019-10-15 13:19:26 -0700893 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700894 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700895 }
896
Tyler Gunnc63f9082019-10-15 13:19:26 -0700897 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700898 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700899 }
900
Tyler Gunnc63f9082019-10-15 13:19:26 -0700901 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -0700902 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700903 }
904
Tyler Gunnc63f9082019-10-15 13:19:26 -0700905 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -0800906 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
907 }
908
Tyler Gunnc63f9082019-10-15 13:19:26 -0700909 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
910 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -0700911 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
912 }
913
Tyler Gunnc63f9082019-10-15 13:19:26 -0700914 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -0700915 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
916 }
917
Tyler Gunn720c6642016-03-22 09:02:47 -0700918 builder.append("]");
919 return builder.toString();
920 }
921
Sailesh Nepal091768c2014-06-30 15:15:23 -0700922 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -0700923 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700924 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700925 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700926 public void onCallerDisplayNameChanged(
927 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700928 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700929 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700930 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800931 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700932 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700933 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800934 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700935 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800936 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700937 public void onVideoProviderChanged(
938 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700939 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
940 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800941 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700942 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700943 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -0700944 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700945 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700946 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700947 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b2017-11-07 17:59:28 -0800948 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800949 public void onRttInitiationSuccess(Connection c) {}
950 public void onRttInitiationFailure(Connection c, int reason) {}
951 public void onRttSessionRemotelyTerminated(Connection c) {}
952 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530953 /** @hide */
954 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800955 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700956 }
957
Tyler Gunnb702ef82015-05-29 11:51:53 -0700958 /**
Hall Liu95d55872017-01-25 17:12:49 -0800959 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800960 */
961 public static final class RttTextStream {
962 private static final int READ_BUFFER_SIZE = 1000;
963 private final InputStreamReader mPipeFromInCall;
964 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800965 private final ParcelFileDescriptor mFdFromInCall;
966 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700967
968 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800969 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
970
971 /**
972 * @hide
973 */
974 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800975 mFdFromInCall = fromInCall;
976 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700977 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700978
979 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800980 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700981 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800982 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800983 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800984 }
985
986 /**
987 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
988 * RTT transmits text in real-time, this method should be called as often as text snippets
989 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800990 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800991 * This method is not thread-safe -- calling it from multiple threads simultaneously may
992 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800993 *
Hall Liu95d55872017-01-25 17:12:49 -0800994 * @param input The message to send to the in-call app.
995 */
996 public void write(String input) throws IOException {
997 mPipeToInCall.write(input);
998 mPipeToInCall.flush();
999 }
1000
1001
1002 /**
1003 * Reads a string from the in-call app, blocking if there is no data available. Returns
1004 * {@code null} if the RTT conversation has been terminated and there is no further data
1005 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001006 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001007 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1008 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001009 *
Hall Liu95d55872017-01-25 17:12:49 -08001010 * @return A string containing text entered by the user, or {@code null} if the
1011 * conversation has been terminated or if there was an error while reading.
1012 */
Hall Liuffa4a812017-03-02 16:11:00 -08001013 public String read() throws IOException {
1014 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1015 if (numRead < 0) {
1016 return null;
1017 }
1018 return new String(mReadBuffer, 0, numRead);
1019 }
1020
1021 /**
1022 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1023 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001024 *
Hall Liuffa4a812017-03-02 16:11:00 -08001025 * @return A string containing text entered by the user, or {@code null} if the user has
1026 * not entered any new text yet.
1027 */
1028 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001029 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001030 return read();
1031 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001032 return null;
1033 }
1034 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001035
1036 /** @hide */
1037 public ParcelFileDescriptor getFdFromInCall() {
1038 return mFdFromInCall;
1039 }
1040
1041 /** @hide */
1042 public ParcelFileDescriptor getFdToInCall() {
1043 return mFdToInCall;
1044 }
1045 }
1046
1047 /**
1048 * Provides constants to represent the results of responses to session modify requests sent via
1049 * {@link Call#sendRttRequest()}
1050 */
1051 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001052 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001053 /**
1054 * Session modify request was successful.
1055 */
1056 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1057
1058 /**
1059 * Session modify request failed.
1060 */
1061 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1062
1063 /**
1064 * Session modify request ignored due to invalid parameters.
1065 */
1066 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1067
1068 /**
1069 * Session modify request timed out.
1070 */
1071 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1072
1073 /**
1074 * Session modify request rejected by remote user.
1075 */
1076 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001077 }
1078
1079 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001080 * Provides a means of controlling the video session associated with a {@link Connection}.
1081 * <p>
1082 * Implementations create a custom subclass of {@link VideoProvider} and the
1083 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1084 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1085 * should set the {@link VideoProvider}.
1086 * <p>
1087 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1088 * {@link InCallService} implementations to issue requests related to the video session;
1089 * it provides a means for the {@link ConnectionService} to report events and information
1090 * related to the video session to Telecom and the {@link InCallService} implementations.
1091 * <p>
1092 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1093 * {@link android.telecom.InCallService.VideoCall}.
1094 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001095 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001096 /**
1097 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001098 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001099 */
1100 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001101
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001103 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1104 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 */
1106 public static final int SESSION_EVENT_RX_RESUME = 2;
1107
1108 /**
1109 * Video transmission has begun. This occurs after a negotiated start of video transmission
1110 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001111 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001112 */
1113 public static final int SESSION_EVENT_TX_START = 3;
1114
1115 /**
1116 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1117 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001118 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001119 */
1120 public static final int SESSION_EVENT_TX_STOP = 4;
1121
1122 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001123 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001124 * this as a cue to inform the user the camera is not available.
1125 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 */
1127 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1128
1129 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001130 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001131 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001132 * the camera has become available again.
1133 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 */
1135 public static final int SESSION_EVENT_CAMERA_READY = 6;
1136
1137 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001138 * Session event raised by Telecom when
1139 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1140 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1141 * @see #handleCallSessionEvent(int)
1142 */
1143 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1144
1145 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001147 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 */
1149 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1150
1151 /**
1152 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001153 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 */
1155 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1156
1157 /**
1158 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001159 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001160 */
1161 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1162
Rekha Kumar07366812015-03-24 16:42:31 -07001163 /**
1164 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001165 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001166 */
1167 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1168
1169 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001170 * Session modify request rejected by remote user.
1171 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001172 */
1173 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1174
Tyler Gunn75958422015-04-15 14:23:42 -07001175 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001176 private static final int MSG_SET_CAMERA = 2;
1177 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1178 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1179 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1180 private static final int MSG_SET_ZOOM = 6;
1181 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1182 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1183 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001184 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001185 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001186 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001187
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001188 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1189 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1190 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1191 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1192 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1193 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001194 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1195 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001196 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1197
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001198 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001199 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001200
1201 /**
1202 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001203 *
1204 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1205 * load factor before resizing, 1 means we only expect a single thread to
1206 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001207 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001208 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1209 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210
1211 /**
1212 * Default handler used to consolidate binder method calls onto a single thread.
1213 */
1214 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001215 public VideoProviderHandler() {
1216 super();
1217 }
1218
1219 public VideoProviderHandler(Looper looper) {
1220 super(looper);
1221 }
1222
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 @Override
1224 public void handleMessage(Message msg) {
1225 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001226 case MSG_ADD_VIDEO_CALLBACK: {
1227 IBinder binder = (IBinder) msg.obj;
1228 IVideoCallback callback = IVideoCallback.Stub
1229 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001230 if (callback == null) {
1231 Log.w(this, "addVideoProvider - skipped; callback is null.");
1232 break;
1233 }
1234
Tyler Gunn75958422015-04-15 14:23:42 -07001235 if (mVideoCallbacks.containsKey(binder)) {
1236 Log.i(this, "addVideoProvider - skipped; already present.");
1237 break;
1238 }
1239 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001241 }
1242 case MSG_REMOVE_VIDEO_CALLBACK: {
1243 IBinder binder = (IBinder) msg.obj;
1244 IVideoCallback callback = IVideoCallback.Stub
1245 .asInterface((IBinder) msg.obj);
1246 if (!mVideoCallbacks.containsKey(binder)) {
1247 Log.i(this, "removeVideoProvider - skipped; not present.");
1248 break;
1249 }
1250 mVideoCallbacks.remove(binder);
1251 break;
1252 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001254 {
1255 SomeArgs args = (SomeArgs) msg.obj;
1256 try {
1257 onSetCamera((String) args.arg1);
1258 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001259 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001260 } finally {
1261 args.recycle();
1262 }
1263 }
1264 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001265 case MSG_SET_PREVIEW_SURFACE:
1266 onSetPreviewSurface((Surface) msg.obj);
1267 break;
1268 case MSG_SET_DISPLAY_SURFACE:
1269 onSetDisplaySurface((Surface) msg.obj);
1270 break;
1271 case MSG_SET_DEVICE_ORIENTATION:
1272 onSetDeviceOrientation(msg.arg1);
1273 break;
1274 case MSG_SET_ZOOM:
1275 onSetZoom((Float) msg.obj);
1276 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001277 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1278 SomeArgs args = (SomeArgs) msg.obj;
1279 try {
1280 onSendSessionModifyRequest((VideoProfile) args.arg1,
1281 (VideoProfile) args.arg2);
1282 } finally {
1283 args.recycle();
1284 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001285 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001286 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1288 onSendSessionModifyResponse((VideoProfile) msg.obj);
1289 break;
1290 case MSG_REQUEST_CAMERA_CAPABILITIES:
1291 onRequestCameraCapabilities();
1292 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001293 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1294 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295 break;
1296 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001297 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001298 break;
1299 default:
1300 break;
1301 }
1302 }
1303 }
1304
1305 /**
1306 * IVideoProvider stub implementation.
1307 */
1308 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001309 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001311 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1312 }
1313
1314 public void removeVideoCallback(IBinder videoCallbackBinder) {
1315 mMessageHandler.obtainMessage(
1316 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001317 }
1318
Tyler Gunn159f35c2017-03-02 09:28:37 -08001319 public void setCamera(String cameraId, String callingPackageName,
1320 int targetSdkVersion) {
1321
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001322 SomeArgs args = SomeArgs.obtain();
1323 args.arg1 = cameraId;
1324 // Propagate the calling package; originally determined in
1325 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1326 // process.
1327 args.arg2 = callingPackageName;
1328 // Pass along the uid and pid of the calling app; this gets lost when we put the
1329 // message onto the handler. These are required for Telecom to perform a permission
1330 // check to see if the calling app is able to use the camera.
1331 args.argi1 = Binder.getCallingUid();
1332 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001333 // Pass along the target SDK version of the calling InCallService. This is used to
1334 // maintain backwards compatibility of the API for older callers.
1335 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001336 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 }
1338
1339 public void setPreviewSurface(Surface surface) {
1340 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1341 }
1342
1343 public void setDisplaySurface(Surface surface) {
1344 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1345 }
1346
1347 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001348 mMessageHandler.obtainMessage(
1349 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 }
1351
1352 public void setZoom(float value) {
1353 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1354 }
1355
Tyler Gunn45382162015-05-06 08:52:27 -07001356 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1357 SomeArgs args = SomeArgs.obtain();
1358 args.arg1 = fromProfile;
1359 args.arg2 = toProfile;
1360 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001361 }
1362
1363 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1364 mMessageHandler.obtainMessage(
1365 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1366 }
1367
1368 public void requestCameraCapabilities() {
1369 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1370 }
1371
1372 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001373 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001374 }
1375
Yorke Lee32f24732015-05-12 16:18:03 -07001376 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1378 }
1379 }
1380
1381 public VideoProvider() {
1382 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001383 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001384 }
1385
1386 /**
1387 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1388 *
1389 * @param looper The looper.
1390 * @hide
1391 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001392 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001393 public VideoProvider(Looper looper) {
1394 mBinder = new VideoProvider.VideoProviderBinder();
1395 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 }
1397
1398 /**
1399 * Returns binder object which can be used across IPC methods.
1400 * @hide
1401 */
1402 public final IVideoProvider getInterface() {
1403 return mBinder;
1404 }
1405
1406 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001407 * Sets the camera to be used for the outgoing video.
1408 * <p>
1409 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1410 * camera via
1411 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1412 * <p>
1413 * Sent from the {@link InCallService} via
1414 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001415 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001416 * @param cameraId The id of the camera (use ids as reported by
1417 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 */
1419 public abstract void onSetCamera(String cameraId);
1420
1421 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001422 * Sets the camera to be used for the outgoing video.
1423 * <p>
1424 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1425 * camera via
1426 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1427 * <p>
1428 * This prototype is used internally to ensure that the calling package name, UID and PID
1429 * are sent to Telecom so that can perform a camera permission check on the caller.
1430 * <p>
1431 * Sent from the {@link InCallService} via
1432 * {@link InCallService.VideoCall#setCamera(String)}.
1433 *
1434 * @param cameraId The id of the camera (use ids as reported by
1435 * {@link CameraManager#getCameraIdList()}).
1436 * @param callingPackageName The AppOpps package name of the caller.
1437 * @param callingUid The UID of the caller.
1438 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001439 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001440 * @hide
1441 */
1442 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001443 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001444
1445 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001446 * Sets the surface to be used for displaying a preview of what the user's camera is
1447 * currently capturing. When video transmission is enabled, this is the video signal which
1448 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001449 * <p>
1450 * Sent from the {@link InCallService} via
1451 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001453 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 */
1455 public abstract void onSetPreviewSurface(Surface surface);
1456
1457 /**
1458 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001459 * <p>
1460 * Sent from the {@link InCallService} via
1461 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 */
1465 public abstract void onSetDisplaySurface(Surface surface);
1466
1467 /**
1468 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1469 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001470 * <p>
1471 * Sent from the {@link InCallService} via
1472 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 *
1474 * @param rotation The device orientation, in degrees.
1475 */
1476 public abstract void onSetDeviceOrientation(int rotation);
1477
1478 /**
1479 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001480 * <p>
1481 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 *
1483 * @param value The camera zoom ratio.
1484 */
1485 public abstract void onSetZoom(float value);
1486
1487 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001488 * Issues a request to modify the properties of the current video session.
1489 * <p>
1490 * Example scenarios include: requesting an audio-only call to be upgraded to a
1491 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1492 * when the {@link InCallService} is no longer the foreground application.
1493 * <p>
1494 * If the {@link VideoProvider} determines a request to be invalid, it should call
1495 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1496 * invalid request back to the {@link InCallService}.
1497 * <p>
1498 * Where a request requires confirmation from the user of the peer device, the
1499 * {@link VideoProvider} must communicate the request to the peer device and handle the
1500 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1501 * is used to inform the {@link InCallService} of the result of the request.
1502 * <p>
1503 * Sent from the {@link InCallService} via
1504 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001505 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001506 * @param fromProfile The video profile prior to the request.
1507 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 */
Tyler Gunn45382162015-05-06 08:52:27 -07001509 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1510 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511
Tyler Gunnb702ef82015-05-29 11:51:53 -07001512 /**
1513 * Provides a response to a request to change the current video session properties.
1514 * <p>
1515 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1516 * video call, could decline the request and keep the call as audio-only.
1517 * In such a scenario, the {@code responseProfile} would have a video state of
1518 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1519 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1520 * <p>
1521 * Sent from the {@link InCallService} via
1522 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1523 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1524 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001526 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001527 */
1528 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1529
1530 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001531 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1532 * <p>
1533 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1534 * camera via
1535 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1536 * <p>
1537 * Sent from the {@link InCallService} via
1538 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001539 */
1540 public abstract void onRequestCameraCapabilities();
1541
1542 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001543 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1544 * video component of the current {@link Connection}.
1545 * <p>
1546 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1547 * via {@link VideoProvider#setCallDataUsage(long)}.
1548 * <p>
1549 * Sent from the {@link InCallService} via
1550 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001552 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553
1554 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001555 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1556 * the peer device when the video signal is paused.
1557 * <p>
1558 * Sent from the {@link InCallService} via
1559 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 *
1561 * @param uri URI of image to display.
1562 */
Yorke Lee32f24732015-05-12 16:18:03 -07001563 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001564
1565 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001566 * Used to inform listening {@link InCallService} implementations when the
1567 * {@link VideoProvider} receives a session modification request.
1568 * <p>
1569 * Received by the {@link InCallService} via
1570 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001571 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001572 * @param videoProfile The requested video profile.
1573 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001574 */
1575 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001576 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001577 for (IVideoCallback callback : mVideoCallbacks.values()) {
1578 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001579 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001580 } catch (RemoteException ignored) {
1581 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001582 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001583 }
1584 }
1585 }
1586
1587 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001588 * Used to inform listening {@link InCallService} implementations when the
1589 * {@link VideoProvider} receives a response to a session modification request.
1590 * <p>
1591 * Received by the {@link InCallService} via
1592 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1593 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001594 *
1595 * @param status Status of the session modify request. Valid values are
1596 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1597 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001598 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1599 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1600 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1601 * @param requestedProfile The original request which was sent to the peer device.
1602 * @param responseProfile The actual profile changes agreed to by the peer device.
1603 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 */
1605 public void receiveSessionModifyResponse(int status,
1606 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001607 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001608 for (IVideoCallback callback : mVideoCallbacks.values()) {
1609 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001610 callback.receiveSessionModifyResponse(status, requestedProfile,
1611 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001612 } catch (RemoteException ignored) {
1613 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001614 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 }
1616 }
1617 }
1618
1619 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001620 * Used to inform listening {@link InCallService} implementations when the
1621 * {@link VideoProvider} reports a call session event.
1622 * <p>
1623 * Received by the {@link InCallService} via
1624 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001625 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001626 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1627 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1628 * {@link VideoProvider#SESSION_EVENT_TX_START},
1629 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1630 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001631 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1632 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 */
1634 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001635 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001636 for (IVideoCallback callback : mVideoCallbacks.values()) {
1637 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001638 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001639 } catch (RemoteException ignored) {
1640 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001641 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001642 }
1643 }
1644 }
1645
1646 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001647 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1648 * peer's video have changed.
1649 * <p>
1650 * This could occur if, for example, the peer rotates their device, changing the aspect
1651 * ratio of the video, or if the user switches between the back and front cameras.
1652 * <p>
1653 * Received by the {@link InCallService} via
1654 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001655 *
1656 * @param width The updated peer video width.
1657 * @param height The updated peer video height.
1658 */
1659 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001660 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001661 for (IVideoCallback callback : mVideoCallbacks.values()) {
1662 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001663 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001664 } catch (RemoteException ignored) {
1665 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001666 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001667 }
1668 }
1669 }
1670
1671 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001672 * Used to inform listening {@link InCallService} implementations when the data usage of the
1673 * video associated with the current {@link Connection} has changed.
1674 * <p>
1675 * This could be in response to a preview request via
1676 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001677 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1678 * 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 -07001679 * <p>
1680 * Received by the {@link InCallService} via
1681 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001682 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001683 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1684 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001685 */
Yorke Lee32f24732015-05-12 16:18:03 -07001686 public void setCallDataUsage(long dataUsage) {
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.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001691 } catch (RemoteException ignored) {
1692 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001693 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001694 }
1695 }
1696 }
1697
1698 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001699 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001701 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001702 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1703 * @hide
1704 */
1705 public void changeCallDataUsage(long dataUsage) {
1706 setCallDataUsage(dataUsage);
1707 }
1708
1709 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001710 * Used to inform listening {@link InCallService} implementations when the capabilities of
1711 * the current camera have changed.
1712 * <p>
1713 * The {@link VideoProvider} should call this in response to
1714 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1715 * changed via {@link VideoProvider#onSetCamera(String)}.
1716 * <p>
1717 * Received by the {@link InCallService} via
1718 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1719 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001720 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001721 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001722 */
Yorke Lee400470f2015-05-12 13:31:25 -07001723 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001724 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001725 for (IVideoCallback callback : mVideoCallbacks.values()) {
1726 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001727 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001728 } catch (RemoteException ignored) {
1729 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001730 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 }
1732 }
1733 }
Rekha Kumar07366812015-03-24 16:42:31 -07001734
1735 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001736 * Used to inform listening {@link InCallService} implementations when the video quality
1737 * of the call has changed.
1738 * <p>
1739 * Received by the {@link InCallService} via
1740 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001741 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001742 * @param videoQuality The updated video quality. Valid values:
1743 * {@link VideoProfile#QUALITY_HIGH},
1744 * {@link VideoProfile#QUALITY_MEDIUM},
1745 * {@link VideoProfile#QUALITY_LOW},
1746 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001747 */
1748 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001749 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001750 for (IVideoCallback callback : mVideoCallbacks.values()) {
1751 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001752 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001753 } catch (RemoteException ignored) {
1754 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001755 }
Rekha Kumar07366812015-03-24 16:42:31 -07001756 }
1757 }
1758 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001759
1760 /**
1761 * Returns a string representation of a call session event.
1762 *
1763 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1764 * @return String representation of the call session event.
1765 * @hide
1766 */
1767 public static String sessionEventToString(int event) {
1768 switch (event) {
1769 case SESSION_EVENT_CAMERA_FAILURE:
1770 return SESSION_EVENT_CAMERA_FAILURE_STR;
1771 case SESSION_EVENT_CAMERA_READY:
1772 return SESSION_EVENT_CAMERA_READY_STR;
1773 case SESSION_EVENT_RX_PAUSE:
1774 return SESSION_EVENT_RX_PAUSE_STR;
1775 case SESSION_EVENT_RX_RESUME:
1776 return SESSION_EVENT_RX_RESUME_STR;
1777 case SESSION_EVENT_TX_START:
1778 return SESSION_EVENT_TX_START_STR;
1779 case SESSION_EVENT_TX_STOP:
1780 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001781 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1782 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001783 default:
1784 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1785 }
1786 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001787 }
1788
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001789 private final Listener mConnectionDeathListener = new Listener() {
1790 @Override
1791 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001792 if (mConferenceables.remove(c)) {
1793 fireOnConferenceableConnectionsChanged();
1794 }
1795 }
1796 };
1797
1798 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1799 @Override
1800 public void onDestroyed(Conference c) {
1801 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001802 fireOnConferenceableConnectionsChanged();
1803 }
1804 }
1805 };
1806
Jay Shrauner229e3822014-08-15 09:23:07 -07001807 /**
1808 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1809 * load factor before resizing, 1 means we only expect a single thread to
1810 * access the map so make only a single shard
1811 */
1812 private final Set<Listener> mListeners = Collections.newSetFromMap(
1813 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001814 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1815 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001816 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001817
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001818 // The internal telecom call ID associated with this connection.
1819 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001820 // The PhoneAccountHandle associated with this connection.
1821 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001822 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001823 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001824 private Uri mAddress;
1825 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001826 private String mCallerDisplayName;
1827 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001828 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001829 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001830 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001831 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001832 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001833 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001834 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001835 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001836 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001837 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001838 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001839 private Conference mConference;
1840 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001841 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001842 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07001843 /**
1844 * The direction of the connection; used where an existing connection is created and we need to
1845 * communicate to Telecom whether its incoming or outgoing.
1846 */
1847 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001848
1849 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001850 * Tracks the key set for the extras bundle provided on the last invocation of
1851 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1852 * keys which were set previously but are no longer present in the replacement Bundle.
1853 */
1854 private Set<String> mPreviousExtraKeys;
1855
1856 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001857 * Create a new Connection.
1858 */
Santos Cordonf2951102014-07-20 19:06:29 -07001859 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001860
1861 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001862 * Returns the Telecom internal call ID associated with this connection. Should only be used
1863 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001864 * <p>
1865 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
1866 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001867 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001868 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001869 * @hide
1870 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001871 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001872 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07001873 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001874 return mTelecomCallId;
1875 }
1876
1877 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001878 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001879 */
Andrew Lee100e2932014-09-08 15:34:24 -07001880 public final Uri getAddress() {
1881 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001882 }
1883
1884 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001885 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001886 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001887 */
Andrew Lee100e2932014-09-08 15:34:24 -07001888 public final int getAddressPresentation() {
1889 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001890 }
1891
1892 /**
1893 * @return The caller display name (CNAP).
1894 */
1895 public final String getCallerDisplayName() {
1896 return mCallerDisplayName;
1897 }
1898
1899 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001900 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001901 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001902 */
1903 public final int getCallerDisplayNamePresentation() {
1904 return mCallerDisplayNamePresentation;
1905 }
1906
1907 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001908 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001909 */
1910 public final int getState() {
1911 return mState;
1912 }
1913
1914 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001915 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001916 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1917 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1918 * {@link VideoProfile#STATE_TX_ENABLED},
1919 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001920 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001921 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001922 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001923 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001924 return mVideoState;
1925 }
1926
1927 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001928 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001929 * being routed by the system. This is {@code null} if this Connection
1930 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001931 * @deprecated Use {@link #getCallAudioState()} instead.
1932 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001933 */
Yorke Lee4af59352015-05-13 14:14:54 -07001934 @SystemApi
1935 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001936 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001937 if (mCallAudioState == null) {
1938 return null;
1939 }
Yorke Lee4af59352015-05-13 14:14:54 -07001940 return new AudioState(mCallAudioState);
1941 }
1942
1943 /**
1944 * @return The audio state of the connection, describing how its audio is currently
1945 * being routed by the system. This is {@code null} if this Connection
1946 * does not directly know about its audio state.
1947 */
1948 public final CallAudioState getCallAudioState() {
1949 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001950 }
1951
1952 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001953 * @return The conference that this connection is a part of. Null if it is not part of any
1954 * conference.
1955 */
1956 public final Conference getConference() {
1957 return mConference;
1958 }
1959
1960 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001961 * Returns whether this connection is requesting that the system play a ringback tone
1962 * on its behalf.
1963 */
Andrew Lee100e2932014-09-08 15:34:24 -07001964 public final boolean isRingbackRequested() {
1965 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001966 }
1967
1968 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001969 * @return True if the connection's audio mode is VOIP.
1970 */
1971 public final boolean getAudioModeIsVoip() {
1972 return mAudioModeIsVoip;
1973 }
1974
1975 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001976 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1977 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1978 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001979 * <p>
1980 * Note: This is an implementation detail specific to IMS conference calls over a mobile
1981 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07001982 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07001983 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
1984 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07001985 *
1986 * @hide
1987 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07001988 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07001989 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07001990 public final long getConnectTimeMillis() {
1991 return mConnectTimeMillis;
1992 }
1993
1994 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001995 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1996 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1997 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07001998 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001999 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2000 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002001 * <p>
2002 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002003 *
2004 * @return The time at which the {@link Connection} was connected.
2005 *
2006 * @hide
2007 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002008 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002009 @TestApi
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002010 public final long getConnectElapsedTimeMillis() {
2011 return mConnectElapsedTimeMillis;
2012 }
2013
2014 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002015 * @return The status hints for this connection.
2016 */
2017 public final StatusHints getStatusHints() {
2018 return mStatusHints;
2019 }
2020
2021 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002022 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002023 * <p>
2024 * Extras should be updated using {@link #putExtras(Bundle)}.
2025 * <p>
2026 * Telecom or an {@link InCallService} can also update the extras via
2027 * {@link android.telecom.Call#putExtras(Bundle)}, and
2028 * {@link Call#removeExtras(List)}.
2029 * <p>
2030 * The connection is notified of changes to the extras made by Telecom or an
2031 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002032 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002033 * @return The extras associated with this connection.
2034 */
2035 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002036 Bundle extras = null;
2037 synchronized (mExtrasLock) {
2038 if (mExtras != null) {
2039 extras = new Bundle(mExtras);
2040 }
2041 }
2042 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002043 }
2044
2045 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002046 * Assign a listener to be notified of state changes.
2047 *
2048 * @param l A listener.
2049 * @return This Connection.
2050 *
2051 * @hide
2052 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002053 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002054 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 return this;
2056 }
2057
2058 /**
2059 * Remove a previously assigned listener that was being notified of state changes.
2060 *
2061 * @param l A Listener.
2062 * @return This Connection.
2063 *
2064 * @hide
2065 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002066 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002067 if (l != null) {
2068 mListeners.remove(l);
2069 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070 return this;
2071 }
2072
2073 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002074 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002075 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002076 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002077 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002078 }
2079
2080 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002081 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2082 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002083 * <p>
2084 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2085 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2086 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002087 *
2088 * @param callId The telecom call ID.
2089 * @hide
2090 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002091 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002092 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07002093 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002094 mTelecomCallId = callId;
2095 }
2096
2097 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098 * Inform this Connection that the state of its audio output has been changed externally.
2099 *
2100 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002101 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002102 */
Yorke Lee4af59352015-05-13 14:14:54 -07002103 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002104 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002105 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002106 mCallAudioState = state;
2107 onAudioStateChanged(getAudioState());
2108 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002109 }
2110
2111 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002112 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002113 * @return A string representation of the value.
2114 */
2115 public static String stateToString(int state) {
2116 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002118 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002119 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002120 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002121 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002122 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002123 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002124 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002125 case STATE_PULLING_CALL:
2126 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002127 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002128 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002129 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002130 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002132 return "DISCONNECTED";
2133 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002134 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 return "UNKNOWN";
2136 }
2137 }
2138
2139 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002141 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002142 public final int getConnectionCapabilities() {
2143 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002144 }
2145
2146 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002147 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2148 */
2149 public final int getConnectionProperties() {
2150 return mConnectionProperties;
2151 }
2152
2153 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002154 * Returns the connection's supported audio routes.
2155 *
2156 * @hide
2157 */
2158 public final int getSupportedAudioRoutes() {
2159 return mSupportedAudioRoutes;
2160 }
2161
2162 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002163 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 *
Andrew Lee100e2932014-09-08 15:34:24 -07002165 * @param address The new address.
2166 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002167 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002168 */
Andrew Lee100e2932014-09-08 15:34:24 -07002169 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002171 Log.d(this, "setAddress %s", address);
2172 mAddress = address;
2173 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002174 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002175 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002176 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002177 }
2178
2179 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002180 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002181 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002182 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002183 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002184 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002185 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002186 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002187 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002188 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002189 mCallerDisplayName = callerDisplayName;
2190 mCallerDisplayNamePresentation = presentation;
2191 for (Listener l : mListeners) {
2192 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2193 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002194 }
2195
2196 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002197 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002198 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2199 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2200 * {@link VideoProfile#STATE_TX_ENABLED},
2201 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002202 *
2203 * @param videoState The new video state.
2204 */
2205 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002206 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002207 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002208 mVideoState = videoState;
2209 for (Listener l : mListeners) {
2210 l.onVideoStateChanged(this, mVideoState);
2211 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002212 }
2213
2214 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002215 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002216 * communicate).
2217 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002218 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002219 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002220 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002221 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002222 }
2223
2224 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002225 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002226 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002227 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002228 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002229 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002230 }
2231
2232 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002233 * Sets state to initializing (this Connection is not yet ready to be used).
2234 */
2235 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002236 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002237 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002238 }
2239
2240 /**
2241 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2242 */
2243 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002244 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002245 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002246 }
2247
2248 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002249 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002250 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002251 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002252 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002253 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002254 }
2255
2256 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002257 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2258 * device). Only applicable for {@link Connection}s with
2259 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2260 */
2261 public final void setPulling() {
2262 checkImmutable();
2263 setState(STATE_PULLING_CALL);
2264 }
2265
2266 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002267 * Sets state to be on hold.
2268 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002269 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002270 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002271 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002272 }
2273
2274 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002275 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002276 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002277 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002278 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002279 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002280 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002281 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002282 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002283 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002284 }
2285
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002286 public final VideoProvider getVideoProvider() {
2287 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002288 }
2289
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002290 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002291 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002292 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002293 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002294 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002295 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002296 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002297 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002298 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002299 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002300 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002301 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002302 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002303 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002304 }
2305
2306 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002307 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2308 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2309 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2310 * to send an {@link #onPostDialContinue(boolean)} signal.
2311 *
2312 * @param remaining The DTMF character sequence remaining to be emitted once the
2313 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2314 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002315 */
2316 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002317 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002318 for (Listener l : mListeners) {
2319 l.onPostDialWait(this, remaining);
2320 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002321 }
2322
2323 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002324 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2325 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002326 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002327 *
2328 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002329 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002330 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002331 checkImmutable();
2332 for (Listener l : mListeners) {
2333 l.onPostDialChar(this, nextChar);
2334 }
2335 }
2336
2337 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002338 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002339 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002340 *
2341 * @param ringback Whether the ringback tone is to be played.
2342 */
Andrew Lee100e2932014-09-08 15:34:24 -07002343 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002344 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002345 if (mRingbackRequested != ringback) {
2346 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002347 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002348 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002349 }
2350 }
Ihab Awadf8358972014-05-28 16:46:42 -07002351 }
2352
2353 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002354 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002355 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002356 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002357 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002358 public final void setConnectionCapabilities(int connectionCapabilities) {
2359 checkImmutable();
2360 if (mConnectionCapabilities != connectionCapabilities) {
2361 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002362 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002363 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002364 }
2365 }
Santos Cordonb6939982014-06-04 20:20:58 -07002366 }
2367
2368 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002369 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2370 *
2371 * @param connectionProperties The new connection properties.
2372 */
2373 public final void setConnectionProperties(int connectionProperties) {
2374 checkImmutable();
2375 if (mConnectionProperties != connectionProperties) {
2376 mConnectionProperties = connectionProperties;
2377 for (Listener l : mListeners) {
2378 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2379 }
2380 }
2381 }
2382
2383 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002384 * Sets the supported audio routes.
2385 *
2386 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2387 * See {@link CallAudioState}
2388 * @hide
2389 */
2390 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2391 if ((supportedAudioRoutes
2392 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2393 throw new IllegalArgumentException(
2394 "supported audio routes must include either speaker or earpiece");
2395 }
2396
2397 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2398 mSupportedAudioRoutes = supportedAudioRoutes;
2399 for (Listener l : mListeners) {
2400 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2401 }
2402 }
2403 }
2404
2405 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002406 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002407 */
Evan Charlton36a71342014-07-19 16:31:02 -07002408 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002409 for (Listener l : mListeners) {
2410 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002411 }
Santos Cordonb6939982014-06-04 20:20:58 -07002412 }
2413
2414 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002415 * Requests that the framework use VOIP audio mode for this connection.
2416 *
2417 * @param isVoip True if the audio mode is VOIP.
2418 */
2419 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002420 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002421 mAudioModeIsVoip = isVoip;
2422 for (Listener l : mListeners) {
2423 l.onAudioModeIsVoipChanged(this, isVoip);
2424 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002425 }
2426
2427 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002428 * Sets the time at which a call became active on this Connection. This is set only
2429 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002430 * <p>
2431 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002432 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002433 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2434 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002435 *
2436 * @hide
2437 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002438 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002439 @TestApi
Roshan Piuse927ec02015-07-15 15:47:21 -07002440 public final void setConnectTimeMillis(long connectTimeMillis) {
2441 mConnectTimeMillis = connectTimeMillis;
2442 }
2443
2444 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002445 * Sets the time at which a call became active on this Connection. This is set only
2446 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002447 * <p>
2448 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002449 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2450 * {@link SystemClock#elapsedRealtime()}.
2451 *
2452 * @hide
2453 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002454 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002455 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -08002456 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002457 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2458 }
2459
2460 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002461 * Sets the label and icon status to display in the in-call UI.
2462 *
2463 * @param statusHints The status label and icon to set.
2464 */
2465 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002466 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002467 mStatusHints = statusHints;
2468 for (Listener l : mListeners) {
2469 l.onStatusHintsChanged(this, statusHints);
2470 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002471 }
2472
2473 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002474 * Sets the connections with which this connection can be conferenced.
2475 *
2476 * @param conferenceableConnections The set of connections this connection can conference with.
2477 */
2478 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002479 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002480 clearConferenceableList();
2481 for (Connection c : conferenceableConnections) {
2482 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2483 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002484 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002485 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002486 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002487 }
2488 }
2489 fireOnConferenceableConnectionsChanged();
2490 }
2491
2492 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002493 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2494 * or conferences with which this connection can be conferenced.
2495 *
2496 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002497 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002498 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002499 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002500 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002501 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2502 // small amount of items here.
2503 if (!mConferenceables.contains(c)) {
2504 if (c instanceof Connection) {
2505 Connection connection = (Connection) c;
2506 connection.addConnectionListener(mConnectionDeathListener);
2507 } else if (c instanceof Conference) {
2508 Conference conference = (Conference) c;
2509 conference.addListener(mConferenceDeathListener);
2510 }
2511 mConferenceables.add(c);
2512 }
2513 }
2514 fireOnConferenceableConnectionsChanged();
2515 }
2516
2517 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002518 * Resets the CDMA connection time.
2519 * <p>
2520 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002521 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002522 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002523 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07002524 @TestApi
Mengjun Leng25707742017-07-04 11:10:37 +08002525 public final void resetConnectionTime() {
2526 for (Listener l : mListeners) {
2527 l.onConnectionTimeReset(this);
2528 }
2529 }
2530
2531 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002532 * Returns the connections or conferences with which this connection can be conferenced.
2533 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002534 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002535 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002536 }
2537
Yorke Lee53463962015-08-04 16:07:19 -07002538 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002539 * @hide
2540 */
2541 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002542 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002543 if (mConnectionService != null) {
2544 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2545 "which is already associated with another ConnectionService.");
2546 } else {
2547 mConnectionService = connectionService;
2548 }
2549 }
2550
2551 /**
2552 * @hide
2553 */
2554 public final void unsetConnectionService(ConnectionService connectionService) {
2555 if (mConnectionService != connectionService) {
2556 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2557 "that does not belong to the ConnectionService.");
2558 } else {
2559 mConnectionService = null;
2560 }
2561 }
2562
2563 /**
2564 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002565 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002566 *
2567 * @param conference The conference.
2568 * @return {@code true} if the conference was successfully set.
2569 * @hide
2570 */
2571 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002572 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002573 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002574 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002575 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002576 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2577 fireConferenceChanged();
2578 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002579 return true;
2580 }
2581 return false;
2582 }
2583
2584 /**
2585 * Resets the conference that this connection is a part of.
2586 * @hide
2587 */
2588 public final void resetConference() {
2589 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002590 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002591 mConference = null;
2592 fireConferenceChanged();
2593 }
2594 }
2595
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002596 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002597 * Set some extras that can be associated with this {@code Connection}.
2598 * <p>
2599 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2600 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2601 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002602 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2603 * {@link #removeExtras(String...)} methods to modify the extras.
2604 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002605 * 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 -07002606 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2607 *
2608 * @param extras The extras associated with this {@code Connection}.
2609 */
2610 public final void setExtras(@Nullable Bundle extras) {
2611 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002612
2613 // Add/replace any new or changed extras values.
2614 putExtras(extras);
2615
2616 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2617 // the current one and remove any keys that went away.
2618 if (mPreviousExtraKeys != null) {
2619 List<String> toRemove = new ArrayList<String>();
2620 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002621 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002622 toRemove.add(oldKey);
2623 }
2624 }
2625 if (!toRemove.isEmpty()) {
2626 removeExtras(toRemove);
2627 }
2628 }
2629
2630 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2631 // called we can see if the caller has removed any extras values.
2632 if (mPreviousExtraKeys == null) {
2633 mPreviousExtraKeys = new ArraySet<String>();
2634 }
2635 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002636 if (extras != null) {
2637 mPreviousExtraKeys.addAll(extras.keySet());
2638 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002639 }
2640
2641 /**
2642 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2643 * added.
2644 * <p>
2645 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2646 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2647 *
2648 * @param extras The extras to add.
2649 */
2650 public final void putExtras(@NonNull Bundle extras) {
2651 checkImmutable();
2652 if (extras == null) {
2653 return;
2654 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002655 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2656 // the listeners.
2657 Bundle listenerExtras;
2658 synchronized (mExtrasLock) {
2659 if (mExtras == null) {
2660 mExtras = new Bundle();
2661 }
2662 mExtras.putAll(extras);
2663 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002664 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002665 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002666 // Create a new clone of the extras for each listener so that they don't clobber
2667 // each other
2668 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002669 }
2670 }
2671
2672 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002673 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002674 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002675 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002676 */
2677 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002678 synchronized (mExtrasLock) {
2679 if (mExtras != null) {
2680 for (String key : keys) {
2681 mExtras.remove(key);
2682 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002683 }
2684 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002685 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002686 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002687 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002688 }
2689 }
2690
2691 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002692 * Removes extras from this {@code Connection}.
2693 *
2694 * @param keys The keys of the extras to remove.
2695 */
2696 public final void removeExtras(String ... keys) {
2697 removeExtras(Arrays.asList(keys));
2698 }
2699
2700 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002701 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2702 * be change to the {@link #getCallAudioState()}.
2703 * <p>
2704 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2705 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2706 * <p>
2707 * See also {@link InCallService#setAudioRoute(int)}.
2708 *
2709 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2710 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2711 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2712 */
2713 public final void setAudioRoute(int route) {
2714 for (Listener l : mListeners) {
Hall Liua98f58b2017-11-07 17:59:28 -08002715 l.onAudioRouteChanged(this, route, null);
2716 }
2717 }
2718
2719 /**
Hall Liua98f58b2017-11-07 17:59:28 -08002720 * Request audio routing to a specific bluetooth device. Calling this method may result in
2721 * the device routing audio to a different bluetooth device than the one specified if the
2722 * bluetooth stack is unable to route audio to the requested device.
2723 * A list of available devices can be obtained via
2724 * {@link CallAudioState#getSupportedBluetoothDevices()}
2725 *
2726 * <p>
2727 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2728 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2729 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002730 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2731 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b2017-11-07 17:59:28 -08002732 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002733 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b2017-11-07 17:59:28 -08002734 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002735 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2736 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002737 }
2738 }
2739
2740 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002741 * Informs listeners that a previously requested RTT session via
2742 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002743 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002744 */
2745 public final void sendRttInitiationSuccess() {
2746 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2747 }
2748
2749 /**
2750 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002751 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002752 * has failed.
2753 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2754 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002755 */
2756 public final void sendRttInitiationFailure(int reason) {
2757 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2758 }
2759
2760 /**
2761 * Informs listeners that a currently active RTT session has been terminated by the remote
2762 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002763 */
2764 public final void sendRttSessionRemotelyTerminated() {
2765 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2766 }
2767
2768 /**
2769 * Informs listeners that the remote side of the call has requested an upgrade to include an
2770 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002771 */
2772 public final void sendRemoteRttRequest() {
2773 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2774 }
2775
2776 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002777 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002778 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002779 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002780 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2781 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002782 */
Yorke Lee4af59352015-05-13 14:14:54 -07002783 @SystemApi
2784 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002785 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002786
2787 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002788 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2789 *
2790 * @param state The new connection audio state.
2791 */
2792 public void onCallAudioStateChanged(CallAudioState state) {}
2793
2794 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002795 * Notifies this Connection of an internal state change. This method is called after the
2796 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002797 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002798 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002799 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002800 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002801
2802 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002803 * Notifies this Connection of a request to play a DTMF tone.
2804 *
2805 * @param c A DTMF character.
2806 */
Santos Cordonf2951102014-07-20 19:06:29 -07002807 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002808
2809 /**
2810 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2811 */
Santos Cordonf2951102014-07-20 19:06:29 -07002812 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002813
2814 /**
2815 * Notifies this Connection of a request to disconnect.
2816 */
Santos Cordonf2951102014-07-20 19:06:29 -07002817 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002818
2819 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002820 * Notifies this Connection of a request to disconnect a participant of the conference managed
2821 * by the connection.
2822 *
2823 * @param endpoint the {@link Uri} of the participant to disconnect.
2824 * @hide
2825 */
2826 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2827
2828 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002829 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002830 */
Santos Cordonf2951102014-07-20 19:06:29 -07002831 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002832
2833 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002834 * Notifies this Connection of a request to abort.
2835 */
Santos Cordonf2951102014-07-20 19:06:29 -07002836 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002837
2838 /**
2839 * Notifies this Connection of a request to hold.
2840 */
Santos Cordonf2951102014-07-20 19:06:29 -07002841 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002842
2843 /**
2844 * Notifies this Connection of a request to exit a hold state.
2845 */
Santos Cordonf2951102014-07-20 19:06:29 -07002846 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002847
2848 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002849 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002850 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002851 * <p>
2852 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2853 * the default dialer's {@link InCallService}.
2854 * <p>
2855 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2856 * Telecom framework may request that the call is answered in the following circumstances:
2857 * <ul>
2858 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2859 * <li>A car mode {@link InCallService} is in use which has declared
2860 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2861 * {@link InCallService} will be able to see calls from self-managed
2862 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2863 * behalf.</li>
2864 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002865 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002866 */
Santos Cordonf2951102014-07-20 19:06:29 -07002867 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002868
2869 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002870 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002871 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002872 * <p>
2873 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2874 * the default dialer's {@link InCallService}.
2875 * <p>
2876 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2877 * Telecom framework may request that the call is answered in the following circumstances:
2878 * <ul>
2879 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2880 * <li>A car mode {@link InCallService} is in use which has declared
2881 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2882 * {@link InCallService} will be able to see calls from self-managed
2883 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2884 * behalf.</li>
2885 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002886 */
2887 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002888 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002889 }
2890
2891 /**
2892 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302893 * a request to deflect.
2894 */
2895 public void onDeflect(Uri address) {}
2896
2897 /**
2898 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002899 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002900 * <p>
2901 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2902 * the default dialer's {@link InCallService}.
2903 * <p>
2904 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2905 * Telecom framework may request that the call is rejected in the following circumstances:
2906 * <ul>
2907 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2908 * <li>A car mode {@link InCallService} is in use which has declared
2909 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2910 * {@link InCallService} will be able to see calls from self-managed
2911 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2912 * behalf.</li>
2913 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002914 */
Santos Cordonf2951102014-07-20 19:06:29 -07002915 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002916
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002917 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002918 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2919 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002920 */
2921 public void onReject(String replyMessage) {}
2922
2923 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002924 * Notifies this Connection of a request to silence the ringer.
2925 * <p>
2926 * The ringer may be silenced by any of the following methods:
2927 * <ul>
2928 * <li>{@link TelecomManager#silenceRinger()}</li>
2929 * <li>The user presses the volume-down button while a call is ringing.</li>
2930 * </ul>
2931 * <p>
2932 * Self-managed {@link ConnectionService} implementations should override this method in their
2933 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2934 * your app set the ringtone as part of the incoming call {@link Notification} (see
2935 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2936 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2937 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2938 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002939 */
2940 public void onSilence() {}
2941
2942 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002943 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2944 */
Santos Cordonf2951102014-07-20 19:06:29 -07002945 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002946
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002947 /**
2948 * Notifies this Connection of a request to pull an external call to the local device.
2949 * <p>
2950 * The {@link InCallService} issues a request to pull an external call to the local device via
2951 * {@link Call#pullExternalCall()}.
2952 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002953 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2954 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002955 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002956 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002957 */
2958 public void onPullExternalCall() {}
2959
2960 /**
2961 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2962 * <p>
2963 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2964 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002965 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2966 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2967 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2968 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2969 * not aware of.
2970 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002971 * See also {@link Call#sendCallEvent(String, Bundle)}.
2972 *
2973 * @param event The call event.
2974 * @param extras Extras associated with the call event.
2975 */
2976 public void onCallEvent(String event, Bundle extras) {}
2977
Tyler Gunndee56a82016-03-23 16:06:34 -07002978 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002979 * Notifies this {@link Connection} that a handover has completed.
2980 * <p>
2981 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2982 * Bundle)} on the initiating side of the handover, and
2983 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2984 */
2985 public void onHandoverComplete() {}
2986
2987 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002988 * Notifies this {@link Connection} of a change to the extras made outside the
2989 * {@link ConnectionService}.
2990 * <p>
2991 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2992 * the {@link android.telecom.Call#putExtras(Bundle)} and
2993 * {@link Call#removeExtras(List)}.
2994 *
2995 * @param extras The new extras bundle.
2996 */
2997 public void onExtrasChanged(Bundle extras) {}
2998
Tyler Gunnf5035432017-01-09 09:43:12 -08002999 /**
3000 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3001 * displaying its incoming call user interface for the {@link Connection}.
3002 * <p>
3003 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3004 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3005 * should show its own incoming call user interface.
3006 * <p>
3007 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003008 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3009 * Telecom framework will display its own incoming call user interface to allow the user to
3010 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3011 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003012 * <p>
3013 * You should trigger the display of the incoming call user interface for your application by
3014 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003015 *
3016 * In your application code, you should create a {@link android.app.NotificationChannel} for
3017 * incoming call notifications from your app:
3018 * <pre><code>
3019 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3020 * NotificationManager.IMPORTANCE_MAX);
3021 * // other channel setup stuff goes here.
3022 *
3023 * // We'll use the default system ringtone for our incoming call notification channel. You can
3024 * // use your own audio resource here.
3025 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3026 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3027 * // Setting the AudioAttributes is important as it identifies the purpose of your
3028 * // notification sound.
3029 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3030 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3031 * .build());
3032 *
3033 * NotificationManager mgr = getSystemService(NotificationManager.class);
3034 * mgr.createNotificationChannel(channel);
3035 * </code></pre>
3036 * When it comes time to post a notification for your incoming call, ensure it uses your
3037 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003038 * <pre><code>
3039 * // Create an intent which triggers your fullscreen incoming call user interface.
3040 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3041 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3042 * intent.setClass(context, YourIncomingCallActivity.class);
3043 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3044 *
3045 * // Build the notification as an ongoing high priority item; this ensures it will show as
3046 * // a heads up notification which slides down over top of the current content.
3047 * final Notification.Builder builder = new Notification.Builder(context);
3048 * builder.setOngoing(true);
3049 * builder.setPriority(Notification.PRIORITY_HIGH);
3050 *
3051 * // Set notification content intent to take user to fullscreen UI if user taps on the
3052 * // notification body.
3053 * builder.setContentIntent(pendingIntent);
3054 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3055 * // manager deems it appropriate.
3056 * builder.setFullScreenIntent(pendingIntent, true);
3057 *
3058 * // Setup notification content.
3059 * builder.setSmallIcon( yourIconResourceId );
3060 * builder.setContentTitle("Your notification title");
3061 * builder.setContentText("Your notification content.");
3062 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003063 * // Set notification as insistent to cause your ringtone to loop.
3064 * Notification notification = builder.build();
3065 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003066 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003067 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003068 * NotificationManager notificationManager = mContext.getSystemService(
3069 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003070 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003071 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003072 */
3073 public void onShowIncomingCallUi() {}
3074
Hall Liub64ac4c2017-02-06 10:49:48 -08003075 /**
3076 * Notifies this {@link Connection} that the user has requested an RTT session.
3077 * The connection service should call {@link #sendRttInitiationSuccess} or
3078 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3079 * request, respectively.
3080 * @param rttTextStream The object that should be used to send text to or receive text from
3081 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003082 */
3083 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3084
3085 /**
3086 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3087 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003088 */
3089 public void onStopRtt() {}
3090
3091 /**
3092 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3093 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3094 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3095 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003096 * @param rttTextStream The object that should be used to send text to or receive text from
3097 * the in-call app.
3098 */
3099 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3100
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003101 static String toLogSafePhoneNumber(String number) {
3102 // For unknown number, log empty string.
3103 if (number == null) {
3104 return "";
3105 }
3106
3107 if (PII_DEBUG) {
3108 // When PII_DEBUG is true we emit PII.
3109 return number;
3110 }
3111
3112 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3113 // sanitized phone numbers.
3114 StringBuilder builder = new StringBuilder();
3115 for (int i = 0; i < number.length(); i++) {
3116 char c = number.charAt(i);
3117 if (c == '-' || c == '@' || c == '.') {
3118 builder.append(c);
3119 } else {
3120 builder.append('x');
3121 }
3122 }
3123 return builder.toString();
3124 }
3125
Ihab Awad542e0ea2014-05-16 10:22:16 -07003126 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003127 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003128 if (mState == STATE_DISCONNECTED && mState != state) {
3129 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003130 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003131 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003132 if (mState != state) {
3133 Log.d(this, "setState: %s", stateToString(state));
3134 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003135 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003136 for (Listener l : mListeners) {
3137 l.onStateChanged(this, state);
3138 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003139 }
3140 }
3141
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003142 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003143 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003144 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3145 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003146 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003147 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003148
3149 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003150 if (mImmutable) {
3151 throw new UnsupportedOperationException("Connection is immutable");
3152 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003153 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003154 }
3155
Evan Charltonbf11f982014-07-20 22:06:28 -07003156 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003157 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003158 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3159 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003160 * <p>
3161 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3162 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003163 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003164 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003165 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003166 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003167 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3168 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003169 }
3170
Evan Charltonbf11f982014-07-20 22:06:28 -07003171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003172 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3173 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3174 * this should never be un-@hide-den.
3175 *
3176 * @hide
3177 */
3178 public void checkImmutable() {}
3179
3180 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003181 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3182 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3183 * that state. This connection should not be used for anything, and no other
3184 * {@code Connection}s should be attempted.
3185 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003186 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003187 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003188 * @return A {@code Connection} which indicates that the underlying connection should
3189 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003190 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003191 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003192 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003193 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003194
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003195 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003196 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003197 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003198 }
3199 }
3200
Santos Cordon823fd3c2014-08-07 18:35:18 -07003201 private final void fireConferenceChanged() {
3202 for (Listener l : mListeners) {
3203 l.onConferenceChanged(this, mConference);
3204 }
3205 }
3206
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003207 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003208 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003209 if (c instanceof Connection) {
3210 Connection connection = (Connection) c;
3211 connection.removeConnectionListener(mConnectionDeathListener);
3212 } else if (c instanceof Conference) {
3213 Conference conference = (Conference) c;
3214 conference.removeListener(mConferenceDeathListener);
3215 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003216 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003217 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003218 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003219
3220 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003221 * Handles a change to extras received from Telecom.
3222 *
3223 * @param extras The new extras.
3224 * @hide
3225 */
3226 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003227 Bundle b = null;
3228 synchronized (mExtrasLock) {
3229 mExtras = extras;
3230 if (mExtras != null) {
3231 b = new Bundle(mExtras);
3232 }
3233 }
3234 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003235 }
3236
3237 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003238 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3239 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003240 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003241 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003242 for (Listener l : mListeners) {
3243 l.onConferenceMergeFailed(this);
3244 }
3245 }
3246
3247 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303248 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3249 * changed due to an emergency call being redialed.
3250 * @param pHandle The new PhoneAccountHandle for this connection.
3251 * @hide
3252 */
3253 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3254 for (Listener l : mListeners) {
3255 l.onPhoneAccountChanged(this, pHandle);
3256 }
3257 }
3258
3259 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003260 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003261 * <p>
3262 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3263 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003264 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003265 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003266 * @hide
3267 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003268 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003269 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003270 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003271 if (mPhoneAccountHandle != phoneAccountHandle) {
3272 mPhoneAccountHandle = phoneAccountHandle;
3273 notifyPhoneAccountChanged(phoneAccountHandle);
3274 }
3275 }
3276
3277 /**
3278 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003279 * <p>
3280 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3281 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003282 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003283 * @return the phone account handle specified via
3284 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003285 * @hide
3286 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003287 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003288 @TestApi
Tyler Gunnc63f9082019-10-15 13:19:26 -07003289 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003290 return mPhoneAccountHandle;
3291 }
3292
3293 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003294 * Sends an event associated with this {@code Connection} with associated event extras to the
3295 * {@link InCallService}.
3296 * <p>
3297 * Connection events are used to communicate point in time information from a
3298 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3299 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3300 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3301 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3302 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3303 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3304 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3305 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3306 * <p>
3307 * Events are exposed to {@link InCallService} implementations via
3308 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3309 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003310 * 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 -07003311 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3312 * some events altogether.
3313 * <p>
3314 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3315 * conflicts between {@link ConnectionService} implementations. Further, custom
3316 * {@link ConnectionService} implementations shall not re-purpose events in the
3317 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3318 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3319 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3320 * {@code com.example.extra.MY_EXTRA}).
3321 * <p>
3322 * When defining events and the associated extras, it is important to keep their behavior
3323 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3324 * events/extras should me maintained to ensure backwards compatibility with older
3325 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003326 *
3327 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003328 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003329 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003330 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003331 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003332 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003333 }
3334 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003335
3336 /**
3337 * @return The direction of the call.
3338 * @hide
3339 */
3340 public final @Call.Details.CallDirection int getCallDirection() {
3341 return mCallDirection;
3342 }
3343
3344 /**
3345 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003346 * <p>
3347 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3348 * call direction.
3349 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003350 * @param callDirection The direction of this connection.
3351 * @hide
3352 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003353 @SystemApi
Tyler Gunn5567d742019-10-31 13:04:37 -07003354 @TestApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003355 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3356 mCallDirection = callDirection;
3357 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003358}