blob: 468c8fa9e30c7d81ea7e86d91c0415513cb4ba1e [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 Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.app.Notification;
Hall Liua98f58b2017-11-07 17:59:28 -080027import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070039import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Hall Liua549fed2018-02-09 16:40:03 -080043import java.io.FileInputStream;
44import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080045import java.io.IOException;
46import java.io.InputStreamReader;
47import java.io.OutputStreamWriter;
Hall Liu730a2592018-06-25 19:48:33 -070048import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070049import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070050import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070051import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070052import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070054import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
56/**
Santos Cordon895d4b82015-06-25 16:41:48 -070057 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
58 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070059 * <p>
60 * Implementations create a custom subclass of {@code Connection} and return it to the framework
61 * as the return value of
62 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
63 * or
64 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
65 * Implementations are then responsible for updating the state of the {@code Connection}, and
66 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
67 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070068 * <p>
69 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
70 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
71 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
72 * {@code Connection} instance.
73 * <p>
74 * Basic call support requires overriding the following methods: {@link #onAnswer()},
75 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
76 * <p>
77 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
78 * {@link #onUnhold()} methods should be overridden to provide hold support for the
79 * {@code Connection}.
80 * <p>
81 * Where a {@code Connection} supports a variation of video calling (e.g. the
82 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
83 * to support answering a call as a video call.
84 * <p>
85 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
86 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
87 * support for pulling the external call.
88 * <p>
89 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
90 * overridden.
91 * <p>
92 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
93 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
94 * for example, call events from a {@link InCallService} are handled,
95 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
96 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
97 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
98 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070099 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700100public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700101
Santos Cordon895d4b82015-06-25 16:41:48 -0700102 /**
103 * The connection is initializing. This is generally the first state for a {@code Connection}
104 * returned by a {@link ConnectionService}.
105 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 public static final int STATE_INITIALIZING = 0;
107
Santos Cordon895d4b82015-06-25 16:41:48 -0700108 /**
109 * The connection is new and not connected.
110 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700111 public static final int STATE_NEW = 1;
112
Santos Cordon895d4b82015-06-25 16:41:48 -0700113 /**
114 * An incoming connection is in the ringing state. During this state, the user's ringer or
115 * vibration feature will be activated.
116 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public static final int STATE_RINGING = 2;
118
Santos Cordon895d4b82015-06-25 16:41:48 -0700119 /**
120 * An outgoing connection is in the dialing state. In this state the other party has not yet
121 * answered the call and the user traditionally hears a ringback tone.
122 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700123 public static final int STATE_DIALING = 3;
124
Santos Cordon895d4b82015-06-25 16:41:48 -0700125 /**
126 * A connection is active. Both parties are connected to the call and can actively communicate.
127 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700128 public static final int STATE_ACTIVE = 4;
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * A connection is on hold.
132 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 public static final int STATE_HOLDING = 5;
134
Santos Cordon895d4b82015-06-25 16:41:48 -0700135 /**
136 * A connection has been disconnected. This is the final state once the user has been
137 * disconnected from a call either locally, remotely or by an error in the service.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_DISCONNECTED = 6;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700142 * The state of an external connection which is in the process of being pulled from a remote
143 * device to the local device.
144 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700145 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700146 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
147 */
148 public static final int STATE_PULLING_CALL = 7;
149
150 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700151 * Connection can currently be put on hold or unheld. This is distinct from
152 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
153 * it does not at the moment support the function. This can be true while the call is in the
154 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
155 * display a disabled 'hold' button.
156 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 public static final int CAPABILITY_HOLD = 0x00000001;
158
159 /** Connection supports the hold feature. */
160 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
161
162 /**
163 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
164 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
165 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
166 * capability allows a merge button to be shown while the conference is in the foreground
167 * of the in-call UI.
168 * <p>
169 * This is only intended for use by a {@link Conference}.
170 */
171 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
172
173 /**
174 * Connections within a conference can be swapped between foreground and background.
175 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
176 * <p>
177 * This is only intended for use by a {@link Conference}.
178 */
179 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
180
181 /**
182 * @hide
183 */
184 public static final int CAPABILITY_UNUSED = 0x00000010;
185
186 /** Connection supports responding via text option. */
187 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
188
189 /** Connection can be muted. */
190 public static final int CAPABILITY_MUTE = 0x00000040;
191
192 /**
193 * Connection supports conference management. This capability only applies to
194 * {@link Conference}s which can have {@link Connection}s as children.
195 */
196 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
197
198 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207
208 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700211 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213
214 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
218
219 /**
220 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700221 */
222 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
223
224 /**
225 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700227 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700228 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800229
230 /**
231 * Connection is able to be separated from its parent {@code Conference}, if any.
232 */
233 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
234
235 /**
236 * Connection is able to be individually disconnected when in a {@code Conference}.
237 */
238 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
239
240 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700241 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800242 * @hide
243 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248 * @hide
249 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251
252 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254 * @hide
255 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257
Tyler Gunn068085b2015-02-06 13:56:52 -0800258 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800260 * @hide
261 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700262 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800263
Tyler Gunn96d6c402015-03-18 12:39:23 -0700264 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500265 * Speed up audio setup for MT call.
266 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700267 */
268 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800269
Rekha Kumar07366812015-03-24 16:42:31 -0700270 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700271 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700272 */
273 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
274
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700275 /**
276 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700277 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700278 */
279 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
280
Tyler Gunnd4091732015-06-29 09:15:37 -0700281 /**
282 * For a conference, indicates the conference will not have child connections.
283 * <p>
284 * An example of a conference with child connections is a GSM conference call, where the radio
285 * retains connections to the individual participants of the conference. Another example is an
286 * IMS conference call where conference event package functionality is supported; in this case
287 * the conference server ensures the radio is aware of the participants in the conference, which
288 * are represented by child connections.
289 * <p>
290 * An example of a conference with no child connections is an IMS conference call with no
291 * conference event package support. Such a conference is represented by the radio as a single
292 * connection to the IMS conference server.
293 * <p>
294 * Indicating whether a conference has children or not is important to help user interfaces
295 * visually represent a conference. A conference with no children, for example, will have the
296 * conference connection shown in the list of calls on a Bluetooth device, where if the
297 * conference has children, only the children will be shown in the list of calls on a Bluetooth
298 * device.
299 * @hide
300 */
301 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
302
Bryce Lee81901682015-08-28 16:38:02 -0700303 /**
304 * Indicates that the connection itself wants to handle any sort of reply response, rather than
305 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700306 */
307 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
308
Tyler Gunnf97a0092016-01-19 15:59:34 -0800309 /**
310 * When set, prevents a video call from being downgraded to an audio-only call.
311 * <p>
312 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
313 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
314 * downgraded from a video call back to a VideoState of
315 * {@link VideoProfile#STATE_AUDIO_ONLY}.
316 * <p>
317 * Intuitively, a call which can be downgraded to audio should also have local and remote
318 * video
319 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
320 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
321 */
322 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
323
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700324 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700325 * When set for an external connection, indicates that this {@code Connection} can be pulled
326 * from a remote device to the current device.
327 * <p>
328 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
329 * is set.
330 */
331 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
332
Pooja Jaind34698d2017-12-28 14:15:31 +0530333 /** Call supports the deflect feature. */
334 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
335
Tyler Gunn720c6642016-03-22 09:02:47 -0700336 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530337 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700338 //**********************************************************************************************
339
340 /**
341 * Indicates that the current device callback number should be shown.
342 *
343 * @hide
344 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700345 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700346
347 /**
348 * Whether the call is a generic conference, where we do not know the precise state of
349 * participants in the conference (eg. on CDMA).
350 *
351 * @hide
352 */
353 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
354
355 /**
356 * Connection is using high definition audio.
357 * @hide
358 */
359 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
360
361 /**
362 * Connection is using WIFI.
363 * @hide
364 */
365 public static final int PROPERTY_WIFI = 1<<3;
366
367 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700368 * When set, indicates that the {@code Connection} does not actually exist locally for the
369 * {@link ConnectionService}.
370 * <p>
371 * Consider, for example, a scenario where a user has two devices with the same phone number.
372 * When a user places a call on one devices, the telephony stack can represent that call on the
373 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700374 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700375 * <p>
376 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
377 * external connections. Only those {@link InCallService}s which have the
378 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
379 * manifest will see external connections.
380 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700381 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382
Brad Ebinger15847072016-05-18 11:08:36 -0700383 /**
384 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
385 */
386 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700387
Hall Liu9f332c72016-07-14 15:37:37 -0700388 /**
389 * Indicates that the connection represents a downgraded IMS conference.
390 * @hide
391 */
392 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
393
Tyler Gunnf5035432017-01-09 09:43:12 -0800394 /**
395 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
396 * {@link ConnectionService}.
397 * <p>
398 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
399 */
400 public static final int PROPERTY_SELF_MANAGED = 1<<7;
401
Hall Liu95d55872017-01-25 17:12:49 -0800402 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800403 * Set by the framework to indicate that a connection has an active RTT session associated with
404 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800405 */
406 public static final int PROPERTY_IS_RTT = 1 << 8;
407
Eric Erfanian62706c52017-12-06 16:27:53 -0800408 /**
409 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000410 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800411 */
412 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
413
Tyler Gunn96d6c402015-03-18 12:39:23 -0700414 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800415 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700416 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800417
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700418 /**
419 * Connection extra key used to store the last forwarded number associated with the current
420 * connection. Used to communicate to the user interface that the connection was forwarded via
421 * the specified number.
422 */
423 public static final String EXTRA_LAST_FORWARDED_NUMBER =
424 "android.telecom.extra.LAST_FORWARDED_NUMBER";
425
426 /**
427 * Connection extra key used to store a child number associated with the current connection.
428 * Used to communicate to the user interface that the connection was received via
429 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
430 * address.
431 */
432 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
433
434 /**
435 * Connection extra key used to store the subject for an incoming call. The user interface can
436 * query this extra and display its contents for incoming calls. Will only be used if the
437 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
438 */
439 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
440
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800441 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700442 * Boolean connection extra key set on a {@link Connection} in
443 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
444 * current active foreground call to be dropped.
445 */
446 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
447 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
448
449 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700450 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
451 * state to indicate the name of the third-party app which is responsible for the current
452 * foreground call.
453 * <p>
454 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
455 * is able to inform the user that answering the new incoming call will cause a call owned by
456 * another app to be dropped when the incoming call is answered.
457 */
458 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
459 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
460
461 /**
Hall Liu10208662016-06-15 17:55:00 -0700462 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700463 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700464 * @hide
465 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700466 public static final String EXTRA_DISABLE_ADD_CALL =
467 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700468
469 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700470 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
471 * original Connection ID associated with the connection. Used in
472 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
473 * connection/conference added via
474 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
475 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
476 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
477 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
478 * be a way to ensure that we don't add the connection again as a duplicate.
479 * <p>
480 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
481 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
482 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
483 * in a new {@link Connection} which it adds to Telecom via
484 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
485 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
486 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
487 * ID it originally referred to the connection as. Thus Telecom needs to know that the
488 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
489 * @hide
490 */
491 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
492 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
493
494 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800495 * Connection event used to inform Telecom that it should play the on hold tone. This is used
496 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700497 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800498 * @hide
499 */
500 public static final String EVENT_ON_HOLD_TONE_START =
501 "android.telecom.event.ON_HOLD_TONE_START";
502
503 /**
504 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
505 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700506 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800507 * @hide
508 */
509 public static final String EVENT_ON_HOLD_TONE_END =
510 "android.telecom.event.ON_HOLD_TONE_END";
511
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700512 /**
513 * Connection event used to inform {@link InCallService}s when pulling of an external call has
514 * failed. The user interface should inform the user of the error.
515 * <p>
516 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
517 * API is called on a {@link Call} with the properties
518 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
519 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
520 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700521 * <p>
522 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
523 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700524 */
525 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
526
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700527 /**
528 * Connection event used to inform {@link InCallService}s when the merging of two calls has
529 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700530 * <p>
531 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
532 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700533 */
534 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
535
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700536 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700537 * Connection event used to inform {@link InCallService}s when the process of merging a
538 * Connection into a conference has begun.
539 * <p>
540 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
541 * expected to be null when this connection event is used.
542 * @hide
543 */
544 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
545
546 /**
547 * Connection event used to inform {@link InCallService}s when the process of merging a
548 * Connection into a conference has completed.
549 * <p>
550 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
551 * expected to be null when this connection event is used.
552 * @hide
553 */
554 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
555
556 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700557 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
558 * the remote party.
559 * <p>
560 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
561 * call is being held locally on the device. When a capable {@link ConnectionService} receives
562 * signalling to indicate that the remote party has put the call on hold, it can send this
563 * connection event.
564 * @hide
565 */
566 public static final String EVENT_CALL_REMOTELY_HELD =
567 "android.telecom.event.CALL_REMOTELY_HELD";
568
569 /**
570 * Connection event used to inform {@link InCallService}s when a call which was remotely held
571 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
572 * <p>
573 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
574 * call is being held locally on the device. When a capable {@link ConnectionService} receives
575 * signalling to indicate that the remote party has taken the call off hold, it can send this
576 * connection event.
577 * @hide
578 */
579 public static final String EVENT_CALL_REMOTELY_UNHELD =
580 "android.telecom.event.CALL_REMOTELY_UNHELD";
581
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700582 /**
583 * Connection event used to inform an {@link InCallService} which initiated a call handover via
584 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
585 * successfully completed.
586 * @hide
587 */
588 public static final String EVENT_HANDOVER_COMPLETE =
589 "android.telecom.event.HANDOVER_COMPLETE";
590
591 /**
592 * Connection event used to inform an {@link InCallService} which initiated a call handover via
593 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
594 * to complete.
595 * @hide
596 */
597 public static final String EVENT_HANDOVER_FAILED =
598 "android.telecom.event.HANDOVER_FAILED";
599
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 // Flag controlling whether PII is emitted into the logs
601 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
602
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 /**
604 * Whether the given capabilities support the specified capability.
605 *
606 * @param capabilities A capability bit field.
607 * @param capability The capability to check capabilities for.
608 * @return Whether the specified capability is supported.
609 * @hide
610 */
611 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800612 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800613 }
614
615 /**
616 * Whether the capabilities of this {@code Connection} supports the specified capability.
617 *
618 * @param capability The capability to check capabilities for.
619 * @return Whether the specified capability is supported.
620 * @hide
621 */
622 public boolean can(int capability) {
623 return can(mConnectionCapabilities, capability);
624 }
625
626 /**
627 * Removes the specified capability from the set of capabilities of this {@code Connection}.
628 *
629 * @param capability The capability to remove from the set.
630 * @hide
631 */
632 public void removeCapability(int capability) {
633 mConnectionCapabilities &= ~capability;
634 }
635
636 /**
637 * Adds the specified capability to the set of capabilities of this {@code Connection}.
638 *
639 * @param capability The capability to add to the set.
640 * @hide
641 */
642 public void addCapability(int capability) {
643 mConnectionCapabilities |= capability;
644 }
645
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700646 /**
647 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
648 *
649 * @param capabilities A capability bit field.
650 * @return A human readable string representation.
651 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800652 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700653 return capabilitiesToStringInternal(capabilities, true /* isLong */);
654 }
655
656 /**
657 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
658 * string.
659 *
660 * @param capabilities A capability bit field.
661 * @return A human readable string representation.
662 * @hide
663 */
664 public static String capabilitiesToStringShort(int capabilities) {
665 return capabilitiesToStringInternal(capabilities, false /* isLong */);
666 }
667
668 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800669 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700670 builder.append("[");
671 if (isLong) {
672 builder.append("Capabilities:");
673 }
674
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800675 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
684 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800686 }
687 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 }
690 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800692 }
693 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800695 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 }
699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700701 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700702 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800704 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700705 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700707 }
708 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700710 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700711 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800713 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800714 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800716 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500717 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500719 }
Rekha Kumar07366812015-03-24 16:42:31 -0700720 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700722 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700723 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700725 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700726 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700728 }
Bryce Lee81901682015-08-28 16:38:02 -0700729 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700730 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700731 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700732 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700733 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700734 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530735 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
736 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
737 }
Bryce Lee81901682015-08-28 16:38:02 -0700738
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800739 builder.append("]");
740 return builder.toString();
741 }
742
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700743 /**
744 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
745 *
746 * @param properties A property bit field.
747 * @return A human readable string representation.
748 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700749 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700750 return propertiesToStringInternal(properties, true /* isLong */);
751 }
752
753 /**
754 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
755 *
756 * @param properties A property bit field.
757 * @return A human readable string representation.
758 * @hide
759 */
760 public static String propertiesToStringShort(int properties) {
761 return propertiesToStringInternal(properties, false /* isLong */);
762 }
763
764 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700765 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700766 builder.append("[");
767 if (isLong) {
768 builder.append("Properties:");
769 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700770
Tyler Gunnf5035432017-01-09 09:43:12 -0800771 if (can(properties, PROPERTY_SELF_MANAGED)) {
772 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
773 }
774
Hall Liu25c7c4d2016-08-30 13:41:02 -0700775 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
776 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700777 }
778
779 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700780 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700781 }
782
783 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700784 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700785 }
786
787 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700788 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700789 }
790
791 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700792 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700793 }
794
Brad Ebinger15847072016-05-18 11:08:36 -0700795 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700796 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700797 }
798
Hall Liud4d2a8a2018-01-29 17:22:02 -0800799 if (can(properties, PROPERTY_IS_RTT)) {
800 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
801 }
802
Tyler Gunn720c6642016-03-22 09:02:47 -0700803 builder.append("]");
804 return builder.toString();
805 }
806
Sailesh Nepal091768c2014-06-30 15:15:23 -0700807 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700808 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700809 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700810 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700811 public void onCallerDisplayNameChanged(
812 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700813 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700814 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700815 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800816 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700817 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700818 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800819 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700820 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800821 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700822 public void onVideoProviderChanged(
823 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700824 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
825 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800826 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700827 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700828 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700829 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800830 public void onConferenceParticipantsChanged(Connection c,
831 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800832 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700833 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700834 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700835 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700836 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700837 /** @hide */
838 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b2017-11-07 17:59:28 -0800839 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800840 public void onRttInitiationSuccess(Connection c) {}
841 public void onRttInitiationFailure(Connection c, int reason) {}
842 public void onRttSessionRemotelyTerminated(Connection c) {}
843 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530844 /** @hide */
845 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700846 }
847
Tyler Gunnb702ef82015-05-29 11:51:53 -0700848 /**
Hall Liu95d55872017-01-25 17:12:49 -0800849 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800850 */
851 public static final class RttTextStream {
852 private static final int READ_BUFFER_SIZE = 1000;
853 private final InputStreamReader mPipeFromInCall;
854 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800855 private final ParcelFileDescriptor mFdFromInCall;
856 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700857
858 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800859 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
860
861 /**
862 * @hide
863 */
864 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800865 mFdFromInCall = fromInCall;
866 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700867 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700868
869 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800870 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700871 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800872 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800873 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800874 }
875
876 /**
877 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
878 * RTT transmits text in real-time, this method should be called as often as text snippets
879 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800880 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800881 * This method is not thread-safe -- calling it from multiple threads simultaneously may
882 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800883 *
Hall Liu95d55872017-01-25 17:12:49 -0800884 * @param input The message to send to the in-call app.
885 */
886 public void write(String input) throws IOException {
887 mPipeToInCall.write(input);
888 mPipeToInCall.flush();
889 }
890
891
892 /**
893 * Reads a string from the in-call app, blocking if there is no data available. Returns
894 * {@code null} if the RTT conversation has been terminated and there is no further data
895 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800896 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800897 * This method is not thread-safe -- calling it from multiple threads simultaneously may
898 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800899 *
Hall Liu95d55872017-01-25 17:12:49 -0800900 * @return A string containing text entered by the user, or {@code null} if the
901 * conversation has been terminated or if there was an error while reading.
902 */
Hall Liuffa4a812017-03-02 16:11:00 -0800903 public String read() throws IOException {
904 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
905 if (numRead < 0) {
906 return null;
907 }
908 return new String(mReadBuffer, 0, numRead);
909 }
910
911 /**
912 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
913 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800914 *
Hall Liuffa4a812017-03-02 16:11:00 -0800915 * @return A string containing text entered by the user, or {@code null} if the user has
916 * not entered any new text yet.
917 */
918 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700919 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800920 return read();
921 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800922 return null;
923 }
924 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800925
926 /** @hide */
927 public ParcelFileDescriptor getFdFromInCall() {
928 return mFdFromInCall;
929 }
930
931 /** @hide */
932 public ParcelFileDescriptor getFdToInCall() {
933 return mFdToInCall;
934 }
935 }
936
937 /**
938 * Provides constants to represent the results of responses to session modify requests sent via
939 * {@link Call#sendRttRequest()}
940 */
941 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700942 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800943 /**
944 * Session modify request was successful.
945 */
946 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
947
948 /**
949 * Session modify request failed.
950 */
951 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
952
953 /**
954 * Session modify request ignored due to invalid parameters.
955 */
956 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
957
958 /**
959 * Session modify request timed out.
960 */
961 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
962
963 /**
964 * Session modify request rejected by remote user.
965 */
966 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800967 }
968
969 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700970 * Provides a means of controlling the video session associated with a {@link Connection}.
971 * <p>
972 * Implementations create a custom subclass of {@link VideoProvider} and the
973 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
974 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
975 * should set the {@link VideoProvider}.
976 * <p>
977 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
978 * {@link InCallService} implementations to issue requests related to the video session;
979 * it provides a means for the {@link ConnectionService} to report events and information
980 * related to the video session to Telecom and the {@link InCallService} implementations.
981 * <p>
982 * {@link InCallService} implementations interact with the {@link VideoProvider} via
983 * {@link android.telecom.InCallService.VideoCall}.
984 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700985 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 /**
987 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 */
990 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700991
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700993 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
994 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995 */
996 public static final int SESSION_EVENT_RX_RESUME = 2;
997
998 /**
999 * Video transmission has begun. This occurs after a negotiated start of video transmission
1000 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001001 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 */
1003 public static final int SESSION_EVENT_TX_START = 3;
1004
1005 /**
1006 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1007 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 */
1010 public static final int SESSION_EVENT_TX_STOP = 4;
1011
1012 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001013 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001014 * this as a cue to inform the user the camera is not available.
1015 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 */
1017 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1018
1019 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001021 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001022 * the camera has become available again.
1023 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001024 */
1025 public static final int SESSION_EVENT_CAMERA_READY = 6;
1026
1027 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001028 * Session event raised by Telecom when
1029 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1030 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1031 * @see #handleCallSessionEvent(int)
1032 */
1033 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1034
1035 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001037 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 */
1039 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1040
1041 /**
1042 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 */
1045 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1046
1047 /**
1048 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 */
1051 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1052
Rekha Kumar07366812015-03-24 16:42:31 -07001053 /**
1054 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001055 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001056 */
1057 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1058
1059 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001060 * Session modify request rejected by remote user.
1061 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001062 */
1063 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1064
Tyler Gunn75958422015-04-15 14:23:42 -07001065 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066 private static final int MSG_SET_CAMERA = 2;
1067 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1068 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1069 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1070 private static final int MSG_SET_ZOOM = 6;
1071 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1072 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1073 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001074 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001076 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001078 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1079 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1080 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1081 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1082 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1083 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001084 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1085 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001086 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1087
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001088 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001090
1091 /**
1092 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001093 *
1094 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1095 * load factor before resizing, 1 means we only expect a single thread to
1096 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001097 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001098 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1099 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001100
1101 /**
1102 * Default handler used to consolidate binder method calls onto a single thread.
1103 */
1104 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001105 public VideoProviderHandler() {
1106 super();
1107 }
1108
1109 public VideoProviderHandler(Looper looper) {
1110 super(looper);
1111 }
1112
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 @Override
1114 public void handleMessage(Message msg) {
1115 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001116 case MSG_ADD_VIDEO_CALLBACK: {
1117 IBinder binder = (IBinder) msg.obj;
1118 IVideoCallback callback = IVideoCallback.Stub
1119 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001120 if (callback == null) {
1121 Log.w(this, "addVideoProvider - skipped; callback is null.");
1122 break;
1123 }
1124
Tyler Gunn75958422015-04-15 14:23:42 -07001125 if (mVideoCallbacks.containsKey(binder)) {
1126 Log.i(this, "addVideoProvider - skipped; already present.");
1127 break;
1128 }
1129 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001131 }
1132 case MSG_REMOVE_VIDEO_CALLBACK: {
1133 IBinder binder = (IBinder) msg.obj;
1134 IVideoCallback callback = IVideoCallback.Stub
1135 .asInterface((IBinder) msg.obj);
1136 if (!mVideoCallbacks.containsKey(binder)) {
1137 Log.i(this, "removeVideoProvider - skipped; not present.");
1138 break;
1139 }
1140 mVideoCallbacks.remove(binder);
1141 break;
1142 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001144 {
1145 SomeArgs args = (SomeArgs) msg.obj;
1146 try {
1147 onSetCamera((String) args.arg1);
1148 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001149 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001150 } finally {
1151 args.recycle();
1152 }
1153 }
1154 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001155 case MSG_SET_PREVIEW_SURFACE:
1156 onSetPreviewSurface((Surface) msg.obj);
1157 break;
1158 case MSG_SET_DISPLAY_SURFACE:
1159 onSetDisplaySurface((Surface) msg.obj);
1160 break;
1161 case MSG_SET_DEVICE_ORIENTATION:
1162 onSetDeviceOrientation(msg.arg1);
1163 break;
1164 case MSG_SET_ZOOM:
1165 onSetZoom((Float) msg.obj);
1166 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001167 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1168 SomeArgs args = (SomeArgs) msg.obj;
1169 try {
1170 onSendSessionModifyRequest((VideoProfile) args.arg1,
1171 (VideoProfile) args.arg2);
1172 } finally {
1173 args.recycle();
1174 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001176 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1178 onSendSessionModifyResponse((VideoProfile) msg.obj);
1179 break;
1180 case MSG_REQUEST_CAMERA_CAPABILITIES:
1181 onRequestCameraCapabilities();
1182 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001183 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1184 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001185 break;
1186 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001187 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001188 break;
1189 default:
1190 break;
1191 }
1192 }
1193 }
1194
1195 /**
1196 * IVideoProvider stub implementation.
1197 */
1198 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001199 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001200 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001201 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1202 }
1203
1204 public void removeVideoCallback(IBinder videoCallbackBinder) {
1205 mMessageHandler.obtainMessage(
1206 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001207 }
1208
Tyler Gunn159f35c2017-03-02 09:28:37 -08001209 public void setCamera(String cameraId, String callingPackageName,
1210 int targetSdkVersion) {
1211
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001212 SomeArgs args = SomeArgs.obtain();
1213 args.arg1 = cameraId;
1214 // Propagate the calling package; originally determined in
1215 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1216 // process.
1217 args.arg2 = callingPackageName;
1218 // Pass along the uid and pid of the calling app; this gets lost when we put the
1219 // message onto the handler. These are required for Telecom to perform a permission
1220 // check to see if the calling app is able to use the camera.
1221 args.argi1 = Binder.getCallingUid();
1222 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001223 // Pass along the target SDK version of the calling InCallService. This is used to
1224 // maintain backwards compatibility of the API for older callers.
1225 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001226 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001227 }
1228
1229 public void setPreviewSurface(Surface surface) {
1230 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1231 }
1232
1233 public void setDisplaySurface(Surface surface) {
1234 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1235 }
1236
1237 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001238 mMessageHandler.obtainMessage(
1239 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 }
1241
1242 public void setZoom(float value) {
1243 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1244 }
1245
Tyler Gunn45382162015-05-06 08:52:27 -07001246 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1247 SomeArgs args = SomeArgs.obtain();
1248 args.arg1 = fromProfile;
1249 args.arg2 = toProfile;
1250 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001251 }
1252
1253 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1254 mMessageHandler.obtainMessage(
1255 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1256 }
1257
1258 public void requestCameraCapabilities() {
1259 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1260 }
1261
1262 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001263 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 }
1265
Yorke Lee32f24732015-05-12 16:18:03 -07001266 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1268 }
1269 }
1270
1271 public VideoProvider() {
1272 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001273 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001274 }
1275
1276 /**
1277 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1278 *
1279 * @param looper The looper.
1280 * @hide
1281 */
1282 public VideoProvider(Looper looper) {
1283 mBinder = new VideoProvider.VideoProviderBinder();
1284 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001285 }
1286
1287 /**
1288 * Returns binder object which can be used across IPC methods.
1289 * @hide
1290 */
1291 public final IVideoProvider getInterface() {
1292 return mBinder;
1293 }
1294
1295 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001296 * Sets the camera to be used for the outgoing video.
1297 * <p>
1298 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1299 * camera via
1300 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1301 * <p>
1302 * Sent from the {@link InCallService} via
1303 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001305 * @param cameraId The id of the camera (use ids as reported by
1306 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 */
1308 public abstract void onSetCamera(String cameraId);
1309
1310 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001311 * Sets the camera to be used for the outgoing video.
1312 * <p>
1313 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1314 * camera via
1315 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1316 * <p>
1317 * This prototype is used internally to ensure that the calling package name, UID and PID
1318 * are sent to Telecom so that can perform a camera permission check on the caller.
1319 * <p>
1320 * Sent from the {@link InCallService} via
1321 * {@link InCallService.VideoCall#setCamera(String)}.
1322 *
1323 * @param cameraId The id of the camera (use ids as reported by
1324 * {@link CameraManager#getCameraIdList()}).
1325 * @param callingPackageName The AppOpps package name of the caller.
1326 * @param callingUid The UID of the caller.
1327 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001328 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001329 * @hide
1330 */
1331 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001332 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001333
1334 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 * Sets the surface to be used for displaying a preview of what the user's camera is
1336 * currently capturing. When video transmission is enabled, this is the video signal which
1337 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001338 * <p>
1339 * Sent from the {@link InCallService} via
1340 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001342 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001343 */
1344 public abstract void onSetPreviewSurface(Surface surface);
1345
1346 /**
1347 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * <p>
1349 * Sent from the {@link InCallService} via
1350 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001351 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001352 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 */
1354 public abstract void onSetDisplaySurface(Surface surface);
1355
1356 /**
1357 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1358 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001359 * <p>
1360 * Sent from the {@link InCallService} via
1361 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001362 *
1363 * @param rotation The device orientation, in degrees.
1364 */
1365 public abstract void onSetDeviceOrientation(int rotation);
1366
1367 /**
1368 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001369 * <p>
1370 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 *
1372 * @param value The camera zoom ratio.
1373 */
1374 public abstract void onSetZoom(float value);
1375
1376 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001377 * Issues a request to modify the properties of the current video session.
1378 * <p>
1379 * Example scenarios include: requesting an audio-only call to be upgraded to a
1380 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1381 * when the {@link InCallService} is no longer the foreground application.
1382 * <p>
1383 * If the {@link VideoProvider} determines a request to be invalid, it should call
1384 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1385 * invalid request back to the {@link InCallService}.
1386 * <p>
1387 * Where a request requires confirmation from the user of the peer device, the
1388 * {@link VideoProvider} must communicate the request to the peer device and handle the
1389 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1390 * is used to inform the {@link InCallService} of the result of the request.
1391 * <p>
1392 * Sent from the {@link InCallService} via
1393 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001395 * @param fromProfile The video profile prior to the request.
1396 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 */
Tyler Gunn45382162015-05-06 08:52:27 -07001398 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1399 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400
Tyler Gunnb702ef82015-05-29 11:51:53 -07001401 /**
1402 * Provides a response to a request to change the current video session properties.
1403 * <p>
1404 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1405 * video call, could decline the request and keep the call as audio-only.
1406 * In such a scenario, the {@code responseProfile} would have a video state of
1407 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1408 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1409 * <p>
1410 * Sent from the {@link InCallService} via
1411 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1412 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1413 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001415 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001416 */
1417 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1418
1419 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001420 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1421 * <p>
1422 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1423 * camera via
1424 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1425 * <p>
1426 * Sent from the {@link InCallService} via
1427 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001428 */
1429 public abstract void onRequestCameraCapabilities();
1430
1431 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001432 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1433 * video component of the current {@link Connection}.
1434 * <p>
1435 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1436 * via {@link VideoProvider#setCallDataUsage(long)}.
1437 * <p>
1438 * Sent from the {@link InCallService} via
1439 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001440 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001441 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442
1443 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001444 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1445 * the peer device when the video signal is paused.
1446 * <p>
1447 * Sent from the {@link InCallService} via
1448 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 *
1450 * @param uri URI of image to display.
1451 */
Yorke Lee32f24732015-05-12 16:18:03 -07001452 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001453
1454 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001455 * Used to inform listening {@link InCallService} implementations when the
1456 * {@link VideoProvider} receives a session modification request.
1457 * <p>
1458 * Received by the {@link InCallService} via
1459 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001461 * @param videoProfile The requested video profile.
1462 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001463 */
1464 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001465 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001466 for (IVideoCallback callback : mVideoCallbacks.values()) {
1467 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001468 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001469 } catch (RemoteException ignored) {
1470 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001471 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 }
1473 }
1474 }
1475
1476 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001477 * Used to inform listening {@link InCallService} implementations when the
1478 * {@link VideoProvider} receives a response to a session modification request.
1479 * <p>
1480 * Received by the {@link InCallService} via
1481 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1482 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 *
1484 * @param status Status of the session modify request. Valid values are
1485 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1486 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001487 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1488 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1489 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1490 * @param requestedProfile The original request which was sent to the peer device.
1491 * @param responseProfile The actual profile changes agreed to by the peer device.
1492 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 */
1494 public void receiveSessionModifyResponse(int status,
1495 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001496 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001497 for (IVideoCallback callback : mVideoCallbacks.values()) {
1498 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001499 callback.receiveSessionModifyResponse(status, requestedProfile,
1500 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001501 } catch (RemoteException ignored) {
1502 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001503 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001504 }
1505 }
1506 }
1507
1508 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001509 * Used to inform listening {@link InCallService} implementations when the
1510 * {@link VideoProvider} reports a call session event.
1511 * <p>
1512 * Received by the {@link InCallService} via
1513 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001514 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001515 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1516 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1517 * {@link VideoProvider#SESSION_EVENT_TX_START},
1518 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1519 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001520 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1521 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 */
1523 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001524 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001525 for (IVideoCallback callback : mVideoCallbacks.values()) {
1526 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001527 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001528 } catch (RemoteException ignored) {
1529 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001530 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 }
1532 }
1533 }
1534
1535 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001536 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1537 * peer's video have changed.
1538 * <p>
1539 * This could occur if, for example, the peer rotates their device, changing the aspect
1540 * ratio of the video, or if the user switches between the back and front cameras.
1541 * <p>
1542 * Received by the {@link InCallService} via
1543 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001544 *
1545 * @param width The updated peer video width.
1546 * @param height The updated peer video height.
1547 */
1548 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001549 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001550 for (IVideoCallback callback : mVideoCallbacks.values()) {
1551 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001552 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001553 } catch (RemoteException ignored) {
1554 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001555 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 }
1557 }
1558 }
1559
1560 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001561 * Used to inform listening {@link InCallService} implementations when the data usage of the
1562 * video associated with the current {@link Connection} has changed.
1563 * <p>
1564 * This could be in response to a preview request via
1565 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001566 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1567 * 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 -07001568 * <p>
1569 * Received by the {@link InCallService} via
1570 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001571 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001572 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1573 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001574 */
Yorke Lee32f24732015-05-12 16:18:03 -07001575 public void setCallDataUsage(long dataUsage) {
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.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001580 } catch (RemoteException ignored) {
1581 Log.w(this, "setCallDataUsage 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 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001590 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001591 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1592 * @hide
1593 */
1594 public void changeCallDataUsage(long dataUsage) {
1595 setCallDataUsage(dataUsage);
1596 }
1597
1598 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001599 * Used to inform listening {@link InCallService} implementations when the capabilities of
1600 * the current camera have changed.
1601 * <p>
1602 * The {@link VideoProvider} should call this in response to
1603 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1604 * changed via {@link VideoProvider#onSetCamera(String)}.
1605 * <p>
1606 * Received by the {@link InCallService} via
1607 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1608 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001609 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001610 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001611 */
Yorke Lee400470f2015-05-12 13:31:25 -07001612 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001613 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001614 for (IVideoCallback callback : mVideoCallbacks.values()) {
1615 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001616 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001617 } catch (RemoteException ignored) {
1618 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001619 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 }
1621 }
1622 }
Rekha Kumar07366812015-03-24 16:42:31 -07001623
1624 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001625 * Used to inform listening {@link InCallService} implementations when the video quality
1626 * of the call has changed.
1627 * <p>
1628 * Received by the {@link InCallService} via
1629 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001630 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001631 * @param videoQuality The updated video quality. Valid values:
1632 * {@link VideoProfile#QUALITY_HIGH},
1633 * {@link VideoProfile#QUALITY_MEDIUM},
1634 * {@link VideoProfile#QUALITY_LOW},
1635 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001636 */
1637 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001638 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001639 for (IVideoCallback callback : mVideoCallbacks.values()) {
1640 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001641 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001642 } catch (RemoteException ignored) {
1643 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001644 }
Rekha Kumar07366812015-03-24 16:42:31 -07001645 }
1646 }
1647 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001648
1649 /**
1650 * Returns a string representation of a call session event.
1651 *
1652 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1653 * @return String representation of the call session event.
1654 * @hide
1655 */
1656 public static String sessionEventToString(int event) {
1657 switch (event) {
1658 case SESSION_EVENT_CAMERA_FAILURE:
1659 return SESSION_EVENT_CAMERA_FAILURE_STR;
1660 case SESSION_EVENT_CAMERA_READY:
1661 return SESSION_EVENT_CAMERA_READY_STR;
1662 case SESSION_EVENT_RX_PAUSE:
1663 return SESSION_EVENT_RX_PAUSE_STR;
1664 case SESSION_EVENT_RX_RESUME:
1665 return SESSION_EVENT_RX_RESUME_STR;
1666 case SESSION_EVENT_TX_START:
1667 return SESSION_EVENT_TX_START_STR;
1668 case SESSION_EVENT_TX_STOP:
1669 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001670 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1671 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001672 default:
1673 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1674 }
1675 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001676 }
1677
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001678 private final Listener mConnectionDeathListener = new Listener() {
1679 @Override
1680 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001681 if (mConferenceables.remove(c)) {
1682 fireOnConferenceableConnectionsChanged();
1683 }
1684 }
1685 };
1686
1687 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1688 @Override
1689 public void onDestroyed(Conference c) {
1690 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001691 fireOnConferenceableConnectionsChanged();
1692 }
1693 }
1694 };
1695
Jay Shrauner229e3822014-08-15 09:23:07 -07001696 /**
1697 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1698 * load factor before resizing, 1 means we only expect a single thread to
1699 * access the map so make only a single shard
1700 */
1701 private final Set<Listener> mListeners = Collections.newSetFromMap(
1702 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001703 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1704 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001705 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001706
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001707 // The internal telecom call ID associated with this connection.
1708 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001709 // The PhoneAccountHandle associated with this connection.
1710 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001711 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001712 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001713 private Uri mAddress;
1714 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001715 private String mCallerDisplayName;
1716 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001717 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001718 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001719 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001720 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001721 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001722 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001723 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001724 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001725 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001726 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001727 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001728 private Conference mConference;
1729 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001730 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001731 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001732
1733 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001734 * Tracks the key set for the extras bundle provided on the last invocation of
1735 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1736 * keys which were set previously but are no longer present in the replacement Bundle.
1737 */
1738 private Set<String> mPreviousExtraKeys;
1739
1740 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001741 * Create a new Connection.
1742 */
Santos Cordonf2951102014-07-20 19:06:29 -07001743 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001744
1745 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001746 * Returns the Telecom internal call ID associated with this connection. Should only be used
1747 * for debugging and tracing purposes.
1748 *
1749 * @return The Telecom call ID.
1750 * @hide
1751 */
1752 public final String getTelecomCallId() {
1753 return mTelecomCallId;
1754 }
1755
1756 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001757 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001758 */
Andrew Lee100e2932014-09-08 15:34:24 -07001759 public final Uri getAddress() {
1760 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001761 }
1762
1763 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001764 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001765 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001766 */
Andrew Lee100e2932014-09-08 15:34:24 -07001767 public final int getAddressPresentation() {
1768 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001769 }
1770
1771 /**
1772 * @return The caller display name (CNAP).
1773 */
1774 public final String getCallerDisplayName() {
1775 return mCallerDisplayName;
1776 }
1777
1778 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001779 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001780 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001781 */
1782 public final int getCallerDisplayNamePresentation() {
1783 return mCallerDisplayNamePresentation;
1784 }
1785
1786 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001787 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001788 */
1789 public final int getState() {
1790 return mState;
1791 }
1792
1793 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001794 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001795 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1796 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1797 * {@link VideoProfile#STATE_TX_ENABLED},
1798 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001799 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001800 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001801 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001802 */
1803 public final int getVideoState() {
1804 return mVideoState;
1805 }
1806
1807 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001808 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001809 * being routed by the system. This is {@code null} if this Connection
1810 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001811 * @deprecated Use {@link #getCallAudioState()} instead.
1812 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001813 */
Yorke Lee4af59352015-05-13 14:14:54 -07001814 @SystemApi
1815 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001816 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001817 if (mCallAudioState == null) {
1818 return null;
1819 }
Yorke Lee4af59352015-05-13 14:14:54 -07001820 return new AudioState(mCallAudioState);
1821 }
1822
1823 /**
1824 * @return The audio state of the connection, describing how its audio is currently
1825 * being routed by the system. This is {@code null} if this Connection
1826 * does not directly know about its audio state.
1827 */
1828 public final CallAudioState getCallAudioState() {
1829 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001830 }
1831
1832 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001833 * @return The conference that this connection is a part of. Null if it is not part of any
1834 * conference.
1835 */
1836 public final Conference getConference() {
1837 return mConference;
1838 }
1839
1840 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001841 * Returns whether this connection is requesting that the system play a ringback tone
1842 * on its behalf.
1843 */
Andrew Lee100e2932014-09-08 15:34:24 -07001844 public final boolean isRingbackRequested() {
1845 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001846 }
1847
1848 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001849 * @return True if the connection's audio mode is VOIP.
1850 */
1851 public final boolean getAudioModeIsVoip() {
1852 return mAudioModeIsVoip;
1853 }
1854
1855 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001856 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1857 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1858 * start time of the conference.
1859 *
1860 * @return The time at which the {@code Connnection} was connected.
1861 *
1862 * @hide
1863 */
1864 public final long getConnectTimeMillis() {
1865 return mConnectTimeMillis;
1866 }
1867
1868 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001869 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1870 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1871 * start time of the conference.
1872 *
1873 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1874 * changes do not impact the call duration.
1875 *
1876 * @return The time at which the {@link Connection} was connected.
1877 *
1878 * @hide
1879 */
1880 public final long getConnectElapsedTimeMillis() {
1881 return mConnectElapsedTimeMillis;
1882 }
1883
1884 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001885 * @return The status hints for this connection.
1886 */
1887 public final StatusHints getStatusHints() {
1888 return mStatusHints;
1889 }
1890
1891 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001892 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001893 * <p>
1894 * Extras should be updated using {@link #putExtras(Bundle)}.
1895 * <p>
1896 * Telecom or an {@link InCallService} can also update the extras via
1897 * {@link android.telecom.Call#putExtras(Bundle)}, and
1898 * {@link Call#removeExtras(List)}.
1899 * <p>
1900 * The connection is notified of changes to the extras made by Telecom or an
1901 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001902 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001903 * @return The extras associated with this connection.
1904 */
1905 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001906 Bundle extras = null;
1907 synchronized (mExtrasLock) {
1908 if (mExtras != null) {
1909 extras = new Bundle(mExtras);
1910 }
1911 }
1912 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001913 }
1914
1915 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001916 * Assign a listener to be notified of state changes.
1917 *
1918 * @param l A listener.
1919 * @return This Connection.
1920 *
1921 * @hide
1922 */
1923 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001924 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001925 return this;
1926 }
1927
1928 /**
1929 * Remove a previously assigned listener that was being notified of state changes.
1930 *
1931 * @param l A Listener.
1932 * @return This Connection.
1933 *
1934 * @hide
1935 */
1936 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001937 if (l != null) {
1938 mListeners.remove(l);
1939 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001940 return this;
1941 }
1942
1943 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001944 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001945 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001946 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001947 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001948 }
1949
1950 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001951 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1952 * ONLY for debugging purposes.
1953 *
1954 * @param callId The telecom call ID.
1955 * @hide
1956 */
1957 public void setTelecomCallId(String callId) {
1958 mTelecomCallId = callId;
1959 }
1960
1961 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001962 * Inform this Connection that the state of its audio output has been changed externally.
1963 *
1964 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001965 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966 */
Yorke Lee4af59352015-05-13 14:14:54 -07001967 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001968 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001969 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001970 mCallAudioState = state;
1971 onAudioStateChanged(getAudioState());
1972 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001973 }
1974
1975 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001976 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001977 * @return A string representation of the value.
1978 */
1979 public static String stateToString(int state) {
1980 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001981 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001982 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001983 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001984 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001985 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001986 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001987 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001988 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001989 case STATE_PULLING_CALL:
1990 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001991 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001992 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001993 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001994 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001995 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001996 return "DISCONNECTED";
1997 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001998 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001999 return "UNKNOWN";
2000 }
2001 }
2002
2003 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002004 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002005 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002006 public final int getConnectionCapabilities() {
2007 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002008 }
2009
2010 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002011 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2012 */
2013 public final int getConnectionProperties() {
2014 return mConnectionProperties;
2015 }
2016
2017 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002018 * Returns the connection's supported audio routes.
2019 *
2020 * @hide
2021 */
2022 public final int getSupportedAudioRoutes() {
2023 return mSupportedAudioRoutes;
2024 }
2025
2026 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002027 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002028 *
Andrew Lee100e2932014-09-08 15:34:24 -07002029 * @param address The new address.
2030 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002031 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002032 */
Andrew Lee100e2932014-09-08 15:34:24 -07002033 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002034 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002035 Log.d(this, "setAddress %s", address);
2036 mAddress = address;
2037 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002038 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002039 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002040 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002041 }
2042
2043 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002044 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002045 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002046 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002047 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002048 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002049 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002050 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002051 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002052 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002053 mCallerDisplayName = callerDisplayName;
2054 mCallerDisplayNamePresentation = presentation;
2055 for (Listener l : mListeners) {
2056 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2057 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002058 }
2059
2060 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002061 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002062 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2063 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2064 * {@link VideoProfile#STATE_TX_ENABLED},
2065 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002066 *
2067 * @param videoState The new video state.
2068 */
2069 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002070 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002071 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002072 mVideoState = videoState;
2073 for (Listener l : mListeners) {
2074 l.onVideoStateChanged(this, mVideoState);
2075 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002076 }
2077
2078 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002079 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002080 * communicate).
2081 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002082 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002083 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002084 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002085 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002086 }
2087
2088 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002091 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002092 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002093 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 }
2095
2096 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002097 * Sets state to initializing (this Connection is not yet ready to be used).
2098 */
2099 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002101 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002102 }
2103
2104 /**
2105 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2106 */
2107 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002108 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002109 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002110 }
2111
2112 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002113 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002114 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002115 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002118 }
2119
2120 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002121 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2122 * device). Only applicable for {@link Connection}s with
2123 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2124 */
2125 public final void setPulling() {
2126 checkImmutable();
2127 setState(STATE_PULLING_CALL);
2128 }
2129
2130 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131 * Sets state to be on hold.
2132 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002133 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002134 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002135 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002136 }
2137
2138 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002139 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002140 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002142 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002143 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002144 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002145 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002146 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002147 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002148 }
2149
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002150 public final VideoProvider getVideoProvider() {
2151 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002152 }
2153
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002154 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002155 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002156 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002157 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002158 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002159 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002160 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002161 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002162 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002163 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002164 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002165 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002166 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002167 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002168 }
2169
2170 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002171 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2172 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2173 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2174 * to send an {@link #onPostDialContinue(boolean)} signal.
2175 *
2176 * @param remaining The DTMF character sequence remaining to be emitted once the
2177 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2178 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002179 */
2180 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002181 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002182 for (Listener l : mListeners) {
2183 l.onPostDialWait(this, remaining);
2184 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002185 }
2186
2187 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002188 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2189 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002190 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002191 *
2192 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002193 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002194 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002195 checkImmutable();
2196 for (Listener l : mListeners) {
2197 l.onPostDialChar(this, nextChar);
2198 }
2199 }
2200
2201 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002202 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002203 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002204 *
2205 * @param ringback Whether the ringback tone is to be played.
2206 */
Andrew Lee100e2932014-09-08 15:34:24 -07002207 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002208 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002209 if (mRingbackRequested != ringback) {
2210 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002211 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002212 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002213 }
2214 }
Ihab Awadf8358972014-05-28 16:46:42 -07002215 }
2216
2217 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002218 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002219 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002220 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002221 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002222 public final void setConnectionCapabilities(int connectionCapabilities) {
2223 checkImmutable();
2224 if (mConnectionCapabilities != connectionCapabilities) {
2225 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002226 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002227 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002228 }
2229 }
Santos Cordonb6939982014-06-04 20:20:58 -07002230 }
2231
2232 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002233 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2234 *
2235 * @param connectionProperties The new connection properties.
2236 */
2237 public final void setConnectionProperties(int connectionProperties) {
2238 checkImmutable();
2239 if (mConnectionProperties != connectionProperties) {
2240 mConnectionProperties = connectionProperties;
2241 for (Listener l : mListeners) {
2242 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2243 }
2244 }
2245 }
2246
2247 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002248 * Sets the supported audio routes.
2249 *
2250 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2251 * See {@link CallAudioState}
2252 * @hide
2253 */
2254 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2255 if ((supportedAudioRoutes
2256 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2257 throw new IllegalArgumentException(
2258 "supported audio routes must include either speaker or earpiece");
2259 }
2260
2261 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2262 mSupportedAudioRoutes = supportedAudioRoutes;
2263 for (Listener l : mListeners) {
2264 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2265 }
2266 }
2267 }
2268
2269 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002270 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002271 */
Evan Charlton36a71342014-07-19 16:31:02 -07002272 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002273 for (Listener l : mListeners) {
2274 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002275 }
Santos Cordonb6939982014-06-04 20:20:58 -07002276 }
2277
2278 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002279 * Requests that the framework use VOIP audio mode for this connection.
2280 *
2281 * @param isVoip True if the audio mode is VOIP.
2282 */
2283 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002284 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002285 mAudioModeIsVoip = isVoip;
2286 for (Listener l : mListeners) {
2287 l.onAudioModeIsVoipChanged(this, isVoip);
2288 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002289 }
2290
2291 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002292 * Sets the time at which a call became active on this Connection. This is set only
2293 * when a conference call becomes active on this connection.
2294 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002295 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2296 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002297 *
2298 * @hide
2299 */
2300 public final void setConnectTimeMillis(long connectTimeMillis) {
2301 mConnectTimeMillis = connectTimeMillis;
2302 }
2303
2304 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002305 * Sets the time at which a call became active on this Connection. This is set only
2306 * when a conference call becomes active on this connection.
2307 *
2308 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2309 * {@link SystemClock#elapsedRealtime()}.
2310 *
2311 * @hide
2312 */
Tyler Gunn17541392018-02-01 08:58:38 -08002313 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002314 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2315 }
2316
2317 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002318 * Sets the label and icon status to display in the in-call UI.
2319 *
2320 * @param statusHints The status label and icon to set.
2321 */
2322 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002323 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002324 mStatusHints = statusHints;
2325 for (Listener l : mListeners) {
2326 l.onStatusHintsChanged(this, statusHints);
2327 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002328 }
2329
2330 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002331 * Sets the connections with which this connection can be conferenced.
2332 *
2333 * @param conferenceableConnections The set of connections this connection can conference with.
2334 */
2335 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002336 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002337 clearConferenceableList();
2338 for (Connection c : conferenceableConnections) {
2339 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2340 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002341 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002342 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002343 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002344 }
2345 }
2346 fireOnConferenceableConnectionsChanged();
2347 }
2348
2349 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002350 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2351 * or conferences with which this connection can be conferenced.
2352 *
2353 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002354 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002355 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002356 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002357 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002358 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2359 // small amount of items here.
2360 if (!mConferenceables.contains(c)) {
2361 if (c instanceof Connection) {
2362 Connection connection = (Connection) c;
2363 connection.addConnectionListener(mConnectionDeathListener);
2364 } else if (c instanceof Conference) {
2365 Conference conference = (Conference) c;
2366 conference.addListener(mConferenceDeathListener);
2367 }
2368 mConferenceables.add(c);
2369 }
2370 }
2371 fireOnConferenceableConnectionsChanged();
2372 }
2373
2374 /**
2375 * Returns the connections or conferences with which this connection can be conferenced.
2376 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002377 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002378 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002379 }
2380
Yorke Lee53463962015-08-04 16:07:19 -07002381 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002382 * @hide
2383 */
2384 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002385 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002386 if (mConnectionService != null) {
2387 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2388 "which is already associated with another ConnectionService.");
2389 } else {
2390 mConnectionService = connectionService;
2391 }
2392 }
2393
2394 /**
2395 * @hide
2396 */
2397 public final void unsetConnectionService(ConnectionService connectionService) {
2398 if (mConnectionService != connectionService) {
2399 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2400 "that does not belong to the ConnectionService.");
2401 } else {
2402 mConnectionService = null;
2403 }
2404 }
2405
2406 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002407 * @hide
2408 */
2409 public final ConnectionService getConnectionService() {
2410 return mConnectionService;
2411 }
2412
2413 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002414 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002415 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002416 *
2417 * @param conference The conference.
2418 * @return {@code true} if the conference was successfully set.
2419 * @hide
2420 */
2421 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002422 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002424 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002425 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002426 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2427 fireConferenceChanged();
2428 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002429 return true;
2430 }
2431 return false;
2432 }
2433
2434 /**
2435 * Resets the conference that this connection is a part of.
2436 * @hide
2437 */
2438 public final void resetConference() {
2439 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002440 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002441 mConference = null;
2442 fireConferenceChanged();
2443 }
2444 }
2445
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002446 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002447 * Set some extras that can be associated with this {@code Connection}.
2448 * <p>
2449 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2450 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2451 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002452 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2453 * {@link #removeExtras(String...)} methods to modify the extras.
2454 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002455 * 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 -07002456 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2457 *
2458 * @param extras The extras associated with this {@code Connection}.
2459 */
2460 public final void setExtras(@Nullable Bundle extras) {
2461 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002462
2463 // Add/replace any new or changed extras values.
2464 putExtras(extras);
2465
2466 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2467 // the current one and remove any keys that went away.
2468 if (mPreviousExtraKeys != null) {
2469 List<String> toRemove = new ArrayList<String>();
2470 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002471 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002472 toRemove.add(oldKey);
2473 }
2474 }
2475 if (!toRemove.isEmpty()) {
2476 removeExtras(toRemove);
2477 }
2478 }
2479
2480 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2481 // called we can see if the caller has removed any extras values.
2482 if (mPreviousExtraKeys == null) {
2483 mPreviousExtraKeys = new ArraySet<String>();
2484 }
2485 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002486 if (extras != null) {
2487 mPreviousExtraKeys.addAll(extras.keySet());
2488 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002489 }
2490
2491 /**
2492 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2493 * added.
2494 * <p>
2495 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2496 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2497 *
2498 * @param extras The extras to add.
2499 */
2500 public final void putExtras(@NonNull Bundle extras) {
2501 checkImmutable();
2502 if (extras == null) {
2503 return;
2504 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002505 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2506 // the listeners.
2507 Bundle listenerExtras;
2508 synchronized (mExtrasLock) {
2509 if (mExtras == null) {
2510 mExtras = new Bundle();
2511 }
2512 mExtras.putAll(extras);
2513 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002514 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002515 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002516 // Create a new clone of the extras for each listener so that they don't clobber
2517 // each other
2518 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002519 }
2520 }
2521
2522 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002523 * Adds a boolean extra to this {@code Connection}.
2524 *
2525 * @param key The extra key.
2526 * @param value The value.
2527 * @hide
2528 */
2529 public final void putExtra(String key, boolean value) {
2530 Bundle newExtras = new Bundle();
2531 newExtras.putBoolean(key, value);
2532 putExtras(newExtras);
2533 }
2534
2535 /**
2536 * Adds an integer extra to this {@code Connection}.
2537 *
2538 * @param key The extra key.
2539 * @param value The value.
2540 * @hide
2541 */
2542 public final void putExtra(String key, int value) {
2543 Bundle newExtras = new Bundle();
2544 newExtras.putInt(key, value);
2545 putExtras(newExtras);
2546 }
2547
2548 /**
2549 * Adds a string extra to this {@code Connection}.
2550 *
2551 * @param key The extra key.
2552 * @param value The value.
2553 * @hide
2554 */
2555 public final void putExtra(String key, String value) {
2556 Bundle newExtras = new Bundle();
2557 newExtras.putString(key, value);
2558 putExtras(newExtras);
2559 }
2560
2561 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002562 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002563 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002564 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002565 */
2566 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002567 synchronized (mExtrasLock) {
2568 if (mExtras != null) {
2569 for (String key : keys) {
2570 mExtras.remove(key);
2571 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002572 }
2573 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002574 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002575 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002576 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002577 }
2578 }
2579
2580 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002581 * Removes extras from this {@code Connection}.
2582 *
2583 * @param keys The keys of the extras to remove.
2584 */
2585 public final void removeExtras(String ... keys) {
2586 removeExtras(Arrays.asList(keys));
2587 }
2588
2589 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002590 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2591 * be change to the {@link #getCallAudioState()}.
2592 * <p>
2593 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2594 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2595 * <p>
2596 * See also {@link InCallService#setAudioRoute(int)}.
2597 *
2598 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2599 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2600 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2601 */
2602 public final void setAudioRoute(int route) {
2603 for (Listener l : mListeners) {
Hall Liua98f58b2017-11-07 17:59:28 -08002604 l.onAudioRouteChanged(this, route, null);
2605 }
2606 }
2607
2608 /**
Hall Liua98f58b2017-11-07 17:59:28 -08002609 * Request audio routing to a specific bluetooth device. Calling this method may result in
2610 * the device routing audio to a different bluetooth device than the one specified if the
2611 * bluetooth stack is unable to route audio to the requested device.
2612 * A list of available devices can be obtained via
2613 * {@link CallAudioState#getSupportedBluetoothDevices()}
2614 *
2615 * <p>
2616 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2617 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2618 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002619 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2620 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b2017-11-07 17:59:28 -08002621 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002622 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b2017-11-07 17:59:28 -08002623 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002624 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2625 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002626 }
2627 }
2628
2629 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002630 * Informs listeners that a previously requested RTT session via
2631 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002632 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002633 */
2634 public final void sendRttInitiationSuccess() {
2635 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2636 }
2637
2638 /**
2639 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002640 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002641 * has failed.
2642 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2643 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002644 */
2645 public final void sendRttInitiationFailure(int reason) {
2646 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2647 }
2648
2649 /**
2650 * Informs listeners that a currently active RTT session has been terminated by the remote
2651 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002652 */
2653 public final void sendRttSessionRemotelyTerminated() {
2654 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2655 }
2656
2657 /**
2658 * Informs listeners that the remote side of the call has requested an upgrade to include an
2659 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002660 */
2661 public final void sendRemoteRttRequest() {
2662 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2663 }
2664
2665 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002666 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002667 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002668 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002669 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2670 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002671 */
Yorke Lee4af59352015-05-13 14:14:54 -07002672 @SystemApi
2673 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002674 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002675
2676 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002677 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2678 *
2679 * @param state The new connection audio state.
2680 */
2681 public void onCallAudioStateChanged(CallAudioState state) {}
2682
2683 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002684 * Notifies this Connection of an internal state change. This method is called after the
2685 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002686 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002687 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002688 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002689 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002690
2691 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002692 * Notifies this Connection of a request to play a DTMF tone.
2693 *
2694 * @param c A DTMF character.
2695 */
Santos Cordonf2951102014-07-20 19:06:29 -07002696 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002697
2698 /**
2699 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2700 */
Santos Cordonf2951102014-07-20 19:06:29 -07002701 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002702
2703 /**
2704 * Notifies this Connection of a request to disconnect.
2705 */
Santos Cordonf2951102014-07-20 19:06:29 -07002706 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002707
2708 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002709 * Notifies this Connection of a request to disconnect a participant of the conference managed
2710 * by the connection.
2711 *
2712 * @param endpoint the {@link Uri} of the participant to disconnect.
2713 * @hide
2714 */
2715 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2716
2717 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002718 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002719 */
Santos Cordonf2951102014-07-20 19:06:29 -07002720 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002721
2722 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002723 * Notifies this Connection of a request to abort.
2724 */
Santos Cordonf2951102014-07-20 19:06:29 -07002725 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002726
2727 /**
2728 * Notifies this Connection of a request to hold.
2729 */
Santos Cordonf2951102014-07-20 19:06:29 -07002730 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002731
2732 /**
2733 * Notifies this Connection of a request to exit a hold state.
2734 */
Santos Cordonf2951102014-07-20 19:06:29 -07002735 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002736
2737 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002738 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002739 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002740 * <p>
2741 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2742 * the default dialer's {@link InCallService}.
2743 * <p>
2744 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2745 * Telecom framework may request that the call is answered in the following circumstances:
2746 * <ul>
2747 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2748 * <li>A car mode {@link InCallService} is in use which has declared
2749 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2750 * {@link InCallService} will be able to see calls from self-managed
2751 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2752 * behalf.</li>
2753 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002754 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002755 */
Santos Cordonf2951102014-07-20 19:06:29 -07002756 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002757
2758 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002759 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002760 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002761 * <p>
2762 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2763 * the default dialer's {@link InCallService}.
2764 * <p>
2765 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2766 * Telecom framework may request that the call is answered in the following circumstances:
2767 * <ul>
2768 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2769 * <li>A car mode {@link InCallService} is in use which has declared
2770 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2771 * {@link InCallService} will be able to see calls from self-managed
2772 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2773 * behalf.</li>
2774 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002775 */
2776 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002777 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002778 }
2779
2780 /**
2781 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302782 * a request to deflect.
2783 */
2784 public void onDeflect(Uri address) {}
2785
2786 /**
2787 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002788 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002789 * <p>
2790 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2791 * the default dialer's {@link InCallService}.
2792 * <p>
2793 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2794 * Telecom framework may request that the call is rejected in the following circumstances:
2795 * <ul>
2796 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2797 * <li>A car mode {@link InCallService} is in use which has declared
2798 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2799 * {@link InCallService} will be able to see calls from self-managed
2800 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2801 * behalf.</li>
2802 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002803 */
Santos Cordonf2951102014-07-20 19:06:29 -07002804 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002805
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002806 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002807 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2808 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002809 */
2810 public void onReject(String replyMessage) {}
2811
2812 /**
Bryce Leecac50772015-11-17 15:13:29 -08002813 * Notifies the Connection of a request to silence the ringer.
2814 *
2815 * @hide
2816 */
2817 public void onSilence() {}
2818
2819 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002820 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2821 */
Santos Cordonf2951102014-07-20 19:06:29 -07002822 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002823
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002824 /**
2825 * Notifies this Connection of a request to pull an external call to the local device.
2826 * <p>
2827 * The {@link InCallService} issues a request to pull an external call to the local device via
2828 * {@link Call#pullExternalCall()}.
2829 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002830 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2831 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002832 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002833 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002834 */
2835 public void onPullExternalCall() {}
2836
2837 /**
2838 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2839 * <p>
2840 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2841 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002842 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2843 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2844 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2845 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2846 * not aware of.
2847 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002848 * See also {@link Call#sendCallEvent(String, Bundle)}.
2849 *
2850 * @param event The call event.
2851 * @param extras Extras associated with the call event.
2852 */
2853 public void onCallEvent(String event, Bundle extras) {}
2854
Tyler Gunndee56a82016-03-23 16:06:34 -07002855 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002856 * Notifies this {@link Connection} that a handover has completed.
2857 * <p>
2858 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2859 * Bundle)} on the initiating side of the handover, and
2860 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2861 */
2862 public void onHandoverComplete() {}
2863
2864 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002865 * Notifies this {@link Connection} of a change to the extras made outside the
2866 * {@link ConnectionService}.
2867 * <p>
2868 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2869 * the {@link android.telecom.Call#putExtras(Bundle)} and
2870 * {@link Call#removeExtras(List)}.
2871 *
2872 * @param extras The new extras bundle.
2873 */
2874 public void onExtrasChanged(Bundle extras) {}
2875
Tyler Gunnf5035432017-01-09 09:43:12 -08002876 /**
2877 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2878 * displaying its incoming call user interface for the {@link Connection}.
2879 * <p>
2880 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2881 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2882 * should show its own incoming call user interface.
2883 * <p>
2884 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002885 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2886 * Telecom framework will display its own incoming call user interface to allow the user to
2887 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2888 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002889 * <p>
2890 * You should trigger the display of the incoming call user interface for your application by
2891 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2892 * For example:
2893 * <pre><code>
2894 * // Create an intent which triggers your fullscreen incoming call user interface.
2895 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2896 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2897 * intent.setClass(context, YourIncomingCallActivity.class);
2898 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2899 *
2900 * // Build the notification as an ongoing high priority item; this ensures it will show as
2901 * // a heads up notification which slides down over top of the current content.
2902 * final Notification.Builder builder = new Notification.Builder(context);
2903 * builder.setOngoing(true);
2904 * builder.setPriority(Notification.PRIORITY_HIGH);
2905 *
2906 * // Set notification content intent to take user to fullscreen UI if user taps on the
2907 * // notification body.
2908 * builder.setContentIntent(pendingIntent);
2909 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2910 * // manager deems it appropriate.
2911 * builder.setFullScreenIntent(pendingIntent, true);
2912 *
2913 * // Setup notification content.
2914 * builder.setSmallIcon( yourIconResourceId );
2915 * builder.setContentTitle("Your notification title");
2916 * builder.setContentText("Your notification content.");
2917 *
2918 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2919 *
2920 * NotificationManager notificationManager = mContext.getSystemService(
2921 * NotificationManager.class);
2922 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2923 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002924 */
2925 public void onShowIncomingCallUi() {}
2926
Hall Liub64ac4c2017-02-06 10:49:48 -08002927 /**
2928 * Notifies this {@link Connection} that the user has requested an RTT session.
2929 * The connection service should call {@link #sendRttInitiationSuccess} or
2930 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2931 * request, respectively.
2932 * @param rttTextStream The object that should be used to send text to or receive text from
2933 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002934 */
2935 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2936
2937 /**
2938 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2939 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002940 */
2941 public void onStopRtt() {}
2942
2943 /**
2944 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2945 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2946 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2947 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002948 * @param rttTextStream The object that should be used to send text to or receive text from
2949 * the in-call app.
2950 */
2951 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2952
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002953 static String toLogSafePhoneNumber(String number) {
2954 // For unknown number, log empty string.
2955 if (number == null) {
2956 return "";
2957 }
2958
2959 if (PII_DEBUG) {
2960 // When PII_DEBUG is true we emit PII.
2961 return number;
2962 }
2963
2964 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2965 // sanitized phone numbers.
2966 StringBuilder builder = new StringBuilder();
2967 for (int i = 0; i < number.length(); i++) {
2968 char c = number.charAt(i);
2969 if (c == '-' || c == '@' || c == '.') {
2970 builder.append(c);
2971 } else {
2972 builder.append('x');
2973 }
2974 }
2975 return builder.toString();
2976 }
2977
Ihab Awad542e0ea2014-05-16 10:22:16 -07002978 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002979 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002980 if (mState == STATE_DISCONNECTED && mState != state) {
2981 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002982 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002983 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002984 if (mState != state) {
2985 Log.d(this, "setState: %s", stateToString(state));
2986 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002987 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002988 for (Listener l : mListeners) {
2989 l.onStateChanged(this, state);
2990 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002991 }
2992 }
2993
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002994 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002995 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002996 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2997 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002998 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002999 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003000
3001 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003002 if (mImmutable) {
3003 throw new UnsupportedOperationException("Connection is immutable");
3004 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003005 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003006 }
3007
Evan Charltonbf11f982014-07-20 22:06:28 -07003008 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003009 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003010 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3011 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003012 * <p>
3013 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3014 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003015 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003016 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003017 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003018 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003019 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3020 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003021 }
3022
Evan Charltonbf11f982014-07-20 22:06:28 -07003023 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003024 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3025 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3026 * this should never be un-@hide-den.
3027 *
3028 * @hide
3029 */
3030 public void checkImmutable() {}
3031
3032 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003033 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3034 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3035 * that state. This connection should not be used for anything, and no other
3036 * {@code Connection}s should be attempted.
3037 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003038 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003039 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003040 * @return A {@code Connection} which indicates that the underlying connection should
3041 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003042 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003043 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003044 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003045 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003046
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003047 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003048 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003049 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003050 }
3051 }
3052
Santos Cordon823fd3c2014-08-07 18:35:18 -07003053 private final void fireConferenceChanged() {
3054 for (Listener l : mListeners) {
3055 l.onConferenceChanged(this, mConference);
3056 }
3057 }
3058
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003059 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003060 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003061 if (c instanceof Connection) {
3062 Connection connection = (Connection) c;
3063 connection.removeConnectionListener(mConnectionDeathListener);
3064 } else if (c instanceof Conference) {
3065 Conference conference = (Conference) c;
3066 conference.removeListener(mConferenceDeathListener);
3067 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003068 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003069 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003070 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003071
3072 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003073 * Handles a change to extras received from Telecom.
3074 *
3075 * @param extras The new extras.
3076 * @hide
3077 */
3078 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003079 Bundle b = null;
3080 synchronized (mExtrasLock) {
3081 mExtras = extras;
3082 if (mExtras != null) {
3083 b = new Bundle(mExtras);
3084 }
3085 }
3086 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003087 }
3088
3089 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003090 * Notifies listeners that the merge request failed.
3091 *
3092 * @hide
3093 */
3094 protected final void notifyConferenceMergeFailed() {
3095 for (Listener l : mListeners) {
3096 l.onConferenceMergeFailed(this);
3097 }
3098 }
3099
3100 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003101 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003102 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003103 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003104 * @hide
3105 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003106 protected final void updateConferenceParticipants(
3107 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003108 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003109 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003110 }
3111 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003112
3113 /**
3114 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003115 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003116 */
3117 protected void notifyConferenceStarted() {
3118 for (Listener l : mListeners) {
3119 l.onConferenceStarted();
3120 }
3121 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003122
3123 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003124 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3125 * be a part of a conference call.
3126 * @param isConferenceSupported {@code true} if the connection supports being part of a
3127 * conference call, {@code false} otherwise.
3128 * @hide
3129 */
3130 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3131 for (Listener l : mListeners) {
3132 l.onConferenceSupportedChanged(this, isConferenceSupported);
3133 }
3134 }
3135
3136 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303137 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3138 * changed due to an emergency call being redialed.
3139 * @param pHandle The new PhoneAccountHandle for this connection.
3140 * @hide
3141 */
3142 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3143 for (Listener l : mListeners) {
3144 l.onPhoneAccountChanged(this, pHandle);
3145 }
3146 }
3147
3148 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003149 * Sets the {@link PhoneAccountHandle} associated with this connection.
3150 *
3151 * @hide
3152 */
3153 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3154 if (mPhoneAccountHandle != phoneAccountHandle) {
3155 mPhoneAccountHandle = phoneAccountHandle;
3156 notifyPhoneAccountChanged(phoneAccountHandle);
3157 }
3158 }
3159
3160 /**
3161 * Returns the {@link PhoneAccountHandle} associated with this connection.
3162 *
3163 * @hide
3164 */
3165 public PhoneAccountHandle getPhoneAccountHandle() {
3166 return mPhoneAccountHandle;
3167 }
3168
3169 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003170 * Sends an event associated with this {@code Connection} with associated event extras to the
3171 * {@link InCallService}.
3172 * <p>
3173 * Connection events are used to communicate point in time information from a
3174 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3175 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3176 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3177 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3178 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3179 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3180 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3181 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3182 * <p>
3183 * Events are exposed to {@link InCallService} implementations via
3184 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3185 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003186 * 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 -07003187 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3188 * some events altogether.
3189 * <p>
3190 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3191 * conflicts between {@link ConnectionService} implementations. Further, custom
3192 * {@link ConnectionService} implementations shall not re-purpose events in the
3193 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3194 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3195 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3196 * {@code com.example.extra.MY_EXTRA}).
3197 * <p>
3198 * When defining events and the associated extras, it is important to keep their behavior
3199 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3200 * events/extras should me maintained to ensure backwards compatibility with older
3201 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003202 *
3203 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003204 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003205 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003206 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003207 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003208 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003209 }
3210 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003211}