blob: d71fde28480cede3735c489ab1096677795b6379 [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;
Hall Liuffa4a812017-03-02 16:11:00 -080026import android.annotation.TestApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080028import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080029import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070030import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070031import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080032import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070033import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Handler;
35import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070036import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080038import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070040import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070041import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
Hall Liu95d55872017-01-25 17:12:49 -080044import java.io.IOException;
45import java.io.InputStreamReader;
46import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070047import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070048import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070050import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070052import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053
54/**
Santos Cordon895d4b82015-06-25 16:41:48 -070055 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
56 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070057 * <p>
58 * Implementations create a custom subclass of {@code Connection} and return it to the framework
59 * as the return value of
60 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
61 * or
62 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
63 * Implementations are then responsible for updating the state of the {@code Connection}, and
64 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
65 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070066 * <p>
67 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
68 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
69 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
70 * {@code Connection} instance.
71 * <p>
72 * Basic call support requires overriding the following methods: {@link #onAnswer()},
73 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
74 * <p>
75 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
76 * {@link #onUnhold()} methods should be overridden to provide hold support for the
77 * {@code Connection}.
78 * <p>
79 * Where a {@code Connection} supports a variation of video calling (e.g. the
80 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
81 * to support answering a call as a video call.
82 * <p>
83 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
84 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
85 * support for pulling the external call.
86 * <p>
87 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
88 * overridden.
89 * <p>
90 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
91 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
92 * for example, call events from a {@link InCallService} are handled,
93 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
94 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
95 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
96 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070097 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070098public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070099
Santos Cordon895d4b82015-06-25 16:41:48 -0700100 /**
101 * The connection is initializing. This is generally the first state for a {@code Connection}
102 * returned by a {@link ConnectionService}.
103 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 public static final int STATE_INITIALIZING = 0;
105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * The connection is new and not connected.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_NEW = 1;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * An incoming connection is in the ringing state. During this state, the user's ringer or
113 * vibration feature will be activated.
114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 public static final int STATE_RINGING = 2;
116
Santos Cordon895d4b82015-06-25 16:41:48 -0700117 /**
118 * An outgoing connection is in the dialing state. In this state the other party has not yet
119 * answered the call and the user traditionally hears a ringback tone.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_DIALING = 3;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * A connection is active. Both parties are connected to the call and can actively communicate.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_ACTIVE = 4;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is on hold.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_HOLDING = 5;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection has been disconnected. This is the final state once the user has been
135 * disconnected from a call either locally, remotely or by an error in the service.
136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final int STATE_DISCONNECTED = 6;
138
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700140 * The state of an external connection which is in the process of being pulled from a remote
141 * device to the local device.
142 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700143 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700144 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
145 */
146 public static final int STATE_PULLING_CALL = 7;
147
148 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700149 * Connection can currently be put on hold or unheld. This is distinct from
150 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
151 * it does not at the moment support the function. This can be true while the call is in the
152 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
153 * display a disabled 'hold' button.
154 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 public static final int CAPABILITY_HOLD = 0x00000001;
156
157 /** Connection supports the hold feature. */
158 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
159
160 /**
161 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
162 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
163 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
164 * capability allows a merge button to be shown while the conference is in the foreground
165 * of the in-call UI.
166 * <p>
167 * This is only intended for use by a {@link Conference}.
168 */
169 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
170
171 /**
172 * Connections within a conference can be swapped between foreground and background.
173 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
174 * <p>
175 * This is only intended for use by a {@link Conference}.
176 */
177 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
178
179 /**
180 * @hide
181 */
182 public static final int CAPABILITY_UNUSED = 0x00000010;
183
184 /** Connection supports responding via text option. */
185 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
186
187 /** Connection can be muted. */
188 public static final int CAPABILITY_MUTE = 0x00000040;
189
190 /**
191 * Connection supports conference management. This capability only applies to
192 * {@link Conference}s which can have {@link Connection}s as children.
193 */
194 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
195
196 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211
212 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
216
217 /**
218 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 */
220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
221
222 /**
223 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800227
228 /**
229 * Connection is able to be separated from its parent {@code Conference}, if any.
230 */
231 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
232
233 /**
234 * Connection is able to be individually disconnected when in a {@code Conference}.
235 */
236 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
237
238 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800240 * @hide
241 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700242 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 * @hide
247 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249
250 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * @hide
253 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255
Tyler Gunn068085b2015-02-06 13:56:52 -0800256 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800258 * @hide
259 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700260 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800261
Tyler Gunn96d6c402015-03-18 12:39:23 -0700262 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500263 * Speed up audio setup for MT call.
264 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700265 */
266 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Rekha Kumar07366812015-03-24 16:42:31 -0700268 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700269 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700270 */
271 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
272
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700273 /**
274 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700275 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700276 */
277 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
278
Tyler Gunnd4091732015-06-29 09:15:37 -0700279 /**
280 * For a conference, indicates the conference will not have child connections.
281 * <p>
282 * An example of a conference with child connections is a GSM conference call, where the radio
283 * retains connections to the individual participants of the conference. Another example is an
284 * IMS conference call where conference event package functionality is supported; in this case
285 * the conference server ensures the radio is aware of the participants in the conference, which
286 * are represented by child connections.
287 * <p>
288 * An example of a conference with no child connections is an IMS conference call with no
289 * conference event package support. Such a conference is represented by the radio as a single
290 * connection to the IMS conference server.
291 * <p>
292 * Indicating whether a conference has children or not is important to help user interfaces
293 * visually represent a conference. A conference with no children, for example, will have the
294 * conference connection shown in the list of calls on a Bluetooth device, where if the
295 * conference has children, only the children will be shown in the list of calls on a Bluetooth
296 * device.
297 * @hide
298 */
299 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
300
Bryce Lee81901682015-08-28 16:38:02 -0700301 /**
302 * Indicates that the connection itself wants to handle any sort of reply response, rather than
303 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700304 */
305 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
306
Tyler Gunnf97a0092016-01-19 15:59:34 -0800307 /**
308 * When set, prevents a video call from being downgraded to an audio-only call.
309 * <p>
310 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
311 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
312 * downgraded from a video call back to a VideoState of
313 * {@link VideoProfile#STATE_AUDIO_ONLY}.
314 * <p>
315 * Intuitively, a call which can be downgraded to audio should also have local and remote
316 * video
317 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
318 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
319 */
320 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
321
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700323 * When set for an external connection, indicates that this {@code Connection} can be pulled
324 * from a remote device to the current device.
325 * <p>
326 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
327 * is set.
328 */
329 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
330
331 //**********************************************************************************************
332 // Next CAPABILITY value: 0x02000000
333 //**********************************************************************************************
334
335 /**
336 * Indicates that the current device callback number should be shown.
337 *
338 * @hide
339 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700340 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700341
342 /**
343 * Whether the call is a generic conference, where we do not know the precise state of
344 * participants in the conference (eg. on CDMA).
345 *
346 * @hide
347 */
348 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
349
350 /**
351 * Connection is using high definition audio.
352 * @hide
353 */
354 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
355
356 /**
357 * Connection is using WIFI.
358 * @hide
359 */
360 public static final int PROPERTY_WIFI = 1<<3;
361
362 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700363 * When set, indicates that the {@code Connection} does not actually exist locally for the
364 * {@link ConnectionService}.
365 * <p>
366 * Consider, for example, a scenario where a user has two devices with the same phone number.
367 * When a user places a call on one devices, the telephony stack can represent that call on the
368 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700369 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700370 * <p>
371 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
372 * external connections. Only those {@link InCallService}s which have the
373 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
374 * manifest will see external connections.
375 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700376 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700377
Brad Ebinger15847072016-05-18 11:08:36 -0700378 /**
379 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
380 */
381 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700382
Hall Liu9f332c72016-07-14 15:37:37 -0700383 /**
384 * Indicates that the connection represents a downgraded IMS conference.
385 * @hide
386 */
387 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
388
Tyler Gunnf5035432017-01-09 09:43:12 -0800389 /**
390 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
391 * {@link ConnectionService}.
392 * <p>
393 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
394 */
395 public static final int PROPERTY_SELF_MANAGED = 1<<7;
396
Hall Liu95d55872017-01-25 17:12:49 -0800397 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800398 * Set by the framework to indicate that a connection has an active RTT session associated with
399 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800400 * @hide
401 */
Hall Liuffa4a812017-03-02 16:11:00 -0800402 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800403 public static final int PROPERTY_IS_RTT = 1 << 8;
404
Eric Erfanianec881872017-12-06 16:27:53 -0800405 /**
406 * Set by the framework to indicate that a connection is using assisted dialing.
407 * @hide
408 */
409 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
410
Tyler Gunn96d6c402015-03-18 12:39:23 -0700411 //**********************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800412 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700413 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800414
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700415 /**
416 * Connection extra key used to store the last forwarded number associated with the current
417 * connection. Used to communicate to the user interface that the connection was forwarded via
418 * the specified number.
419 */
420 public static final String EXTRA_LAST_FORWARDED_NUMBER =
421 "android.telecom.extra.LAST_FORWARDED_NUMBER";
422
423 /**
424 * Connection extra key used to store a child number associated with the current connection.
425 * Used to communicate to the user interface that the connection was received via
426 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
427 * address.
428 */
429 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
430
431 /**
432 * Connection extra key used to store the subject for an incoming call. The user interface can
433 * query this extra and display its contents for incoming calls. Will only be used if the
434 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
435 */
436 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
437
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800438 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700439 * Boolean connection extra key set on a {@link Connection} in
440 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
441 * current active foreground call to be dropped.
442 */
443 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
444 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
445
446 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700447 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
448 * state to indicate the name of the third-party app which is responsible for the current
449 * foreground call.
450 * <p>
451 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
452 * is able to inform the user that answering the new incoming call will cause a call owned by
453 * another app to be dropped when the incoming call is answered.
454 */
455 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
456 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
457
458 /**
Hall Liu10208662016-06-15 17:55:00 -0700459 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700460 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700461 * @hide
462 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700463 public static final String EXTRA_DISABLE_ADD_CALL =
464 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700465
466 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700467 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
468 * original Connection ID associated with the connection. Used in
469 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
470 * connection/conference added via
471 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
472 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
473 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
474 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
475 * be a way to ensure that we don't add the connection again as a duplicate.
476 * <p>
477 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
478 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
479 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
480 * in a new {@link Connection} which it adds to Telecom via
481 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
482 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
483 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
484 * ID it originally referred to the connection as. Thus Telecom needs to know that the
485 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
486 * @hide
487 */
488 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
489 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
490
491 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800492 * Connection event used to inform Telecom that it should play the on hold tone. This is used
493 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700494 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800495 * @hide
496 */
497 public static final String EVENT_ON_HOLD_TONE_START =
498 "android.telecom.event.ON_HOLD_TONE_START";
499
500 /**
501 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
502 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700503 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800504 * @hide
505 */
506 public static final String EVENT_ON_HOLD_TONE_END =
507 "android.telecom.event.ON_HOLD_TONE_END";
508
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700509 /**
510 * Connection event used to inform {@link InCallService}s when pulling of an external call has
511 * failed. The user interface should inform the user of the error.
512 * <p>
513 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
514 * API is called on a {@link Call} with the properties
515 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
516 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
517 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700518 * <p>
519 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
520 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700521 */
522 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
523
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700524 /**
525 * Connection event used to inform {@link InCallService}s when the merging of two calls has
526 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700527 * <p>
528 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
529 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700530 */
531 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
532
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700533 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700534 * Connection event used to inform {@link InCallService}s when the process of merging a
535 * Connection into a conference has begun.
536 * <p>
537 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
538 * expected to be null when this connection event is used.
539 * @hide
540 */
541 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
542
543 /**
544 * Connection event used to inform {@link InCallService}s when the process of merging a
545 * Connection into a conference has completed.
546 * <p>
547 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
548 * expected to be null when this connection event is used.
549 * @hide
550 */
551 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
552
553 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700554 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
555 * the remote party.
556 * <p>
557 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
558 * call is being held locally on the device. When a capable {@link ConnectionService} receives
559 * signalling to indicate that the remote party has put the call on hold, it can send this
560 * connection event.
561 * @hide
562 */
563 public static final String EVENT_CALL_REMOTELY_HELD =
564 "android.telecom.event.CALL_REMOTELY_HELD";
565
566 /**
567 * Connection event used to inform {@link InCallService}s when a call which was remotely held
568 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
569 * <p>
570 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
571 * call is being held locally on the device. When a capable {@link ConnectionService} receives
572 * signalling to indicate that the remote party has taken the call off hold, it can send this
573 * connection event.
574 * @hide
575 */
576 public static final String EVENT_CALL_REMOTELY_UNHELD =
577 "android.telecom.event.CALL_REMOTELY_UNHELD";
578
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700579 /**
580 * Connection event used to inform an {@link InCallService} which initiated a call handover via
581 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
582 * successfully completed.
583 * @hide
584 */
585 public static final String EVENT_HANDOVER_COMPLETE =
586 "android.telecom.event.HANDOVER_COMPLETE";
587
588 /**
589 * Connection event used to inform an {@link InCallService} which initiated a call handover via
590 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
591 * to complete.
592 * @hide
593 */
594 public static final String EVENT_HANDOVER_FAILED =
595 "android.telecom.event.HANDOVER_FAILED";
596
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 // Flag controlling whether PII is emitted into the logs
598 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
599
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800600 /**
601 * Whether the given capabilities support the specified capability.
602 *
603 * @param capabilities A capability bit field.
604 * @param capability The capability to check capabilities for.
605 * @return Whether the specified capability is supported.
606 * @hide
607 */
608 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800609 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800610 }
611
612 /**
613 * Whether the capabilities of this {@code Connection} supports the specified capability.
614 *
615 * @param capability The capability to check capabilities for.
616 * @return Whether the specified capability is supported.
617 * @hide
618 */
619 public boolean can(int capability) {
620 return can(mConnectionCapabilities, capability);
621 }
622
623 /**
624 * Removes the specified capability from the set of capabilities of this {@code Connection}.
625 *
626 * @param capability The capability to remove from the set.
627 * @hide
628 */
629 public void removeCapability(int capability) {
630 mConnectionCapabilities &= ~capability;
631 }
632
633 /**
634 * Adds the specified capability to the set of capabilities of this {@code Connection}.
635 *
636 * @param capability The capability to add to the set.
637 * @hide
638 */
639 public void addCapability(int capability) {
640 mConnectionCapabilities |= capability;
641 }
642
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700643 /**
644 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
645 *
646 * @param capabilities A capability bit field.
647 * @return A human readable string representation.
648 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700650 return capabilitiesToStringInternal(capabilities, true /* isLong */);
651 }
652
653 /**
654 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
655 * string.
656 *
657 * @param capabilities A capability bit field.
658 * @return A human readable string representation.
659 * @hide
660 */
661 public static String capabilitiesToStringShort(int capabilities) {
662 return capabilitiesToStringInternal(capabilities, false /* isLong */);
663 }
664
665 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800666 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append("[");
668 if (isLong) {
669 builder.append("Capabilities:");
670 }
671
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800672 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700673 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 }
675 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
684 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800686 }
687 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 }
690 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800692 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700693 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 }
696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800701 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700702 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700704 }
705 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700707 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700708 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800710 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800711 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800713 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500714 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500716 }
Rekha Kumar07366812015-03-24 16:42:31 -0700717 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700719 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700720 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700722 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700723 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700725 }
Bryce Lee81901682015-08-28 16:38:02 -0700726 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700728 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700729 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700730 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700731 }
Bryce Lee81901682015-08-28 16:38:02 -0700732
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800733 builder.append("]");
734 return builder.toString();
735 }
736
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700737 /**
738 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
739 *
740 * @param properties A property bit field.
741 * @return A human readable string representation.
742 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700743 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700744 return propertiesToStringInternal(properties, true /* isLong */);
745 }
746
747 /**
748 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
749 *
750 * @param properties A property bit field.
751 * @return A human readable string representation.
752 * @hide
753 */
754 public static String propertiesToStringShort(int properties) {
755 return propertiesToStringInternal(properties, false /* isLong */);
756 }
757
758 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700759 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700760 builder.append("[");
761 if (isLong) {
762 builder.append("Properties:");
763 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700764
Tyler Gunnf5035432017-01-09 09:43:12 -0800765 if (can(properties, PROPERTY_SELF_MANAGED)) {
766 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
767 }
768
Hall Liu25c7c4d2016-08-30 13:41:02 -0700769 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
770 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700771 }
772
773 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700774 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700775 }
776
777 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700778 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700779 }
780
781 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700782 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700783 }
784
785 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700786 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700787 }
788
Brad Ebinger15847072016-05-18 11:08:36 -0700789 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700790 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700791 }
792
Tyler Gunn720c6642016-03-22 09:02:47 -0700793 builder.append("]");
794 return builder.toString();
795 }
796
Sailesh Nepal091768c2014-06-30 15:15:23 -0700797 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700798 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700799 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700800 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700801 public void onCallerDisplayNameChanged(
802 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700803 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700804 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700805 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800806 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700807 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700808 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800809 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700810 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800811 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 public void onVideoProviderChanged(
813 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700814 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
815 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800816 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700817 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700818 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700819 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800820 public void onConferenceParticipantsChanged(Connection c,
821 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800822 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700823 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700824 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700825 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700826 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700827 /** @hide */
828 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800829 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800830 public void onRttInitiationSuccess(Connection c) {}
831 public void onRttInitiationFailure(Connection c, int reason) {}
832 public void onRttSessionRemotelyTerminated(Connection c) {}
833 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530834 /** @hide */
835 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700836 }
837
Tyler Gunnb702ef82015-05-29 11:51:53 -0700838 /**
Hall Liu95d55872017-01-25 17:12:49 -0800839 * Provides methods to read and write RTT data to/from the in-call app.
840 * @hide
841 */
Hall Liuffa4a812017-03-02 16:11:00 -0800842 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800843 public static final class RttTextStream {
844 private static final int READ_BUFFER_SIZE = 1000;
845 private final InputStreamReader mPipeFromInCall;
846 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800847 private final ParcelFileDescriptor mFdFromInCall;
848 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800849 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
850
851 /**
852 * @hide
853 */
854 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800855 mFdFromInCall = fromInCall;
856 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800857 mPipeFromInCall = new InputStreamReader(
858 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
859 mPipeToInCall = new OutputStreamWriter(
860 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
861 }
862
863 /**
864 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
865 * RTT transmits text in real-time, this method should be called as often as text snippets
866 * are received from the remote user, even if it is only one character.
867 *
868 * This method is not thread-safe -- calling it from multiple threads simultaneously may
869 * lead to interleaved text.
870 * @param input The message to send to the in-call app.
871 */
872 public void write(String input) throws IOException {
873 mPipeToInCall.write(input);
874 mPipeToInCall.flush();
875 }
876
877
878 /**
879 * Reads a string from the in-call app, blocking if there is no data available. Returns
880 * {@code null} if the RTT conversation has been terminated and there is no further data
881 * to read.
882 *
883 * This method is not thread-safe -- calling it from multiple threads simultaneously may
884 * lead to interleaved text.
885 * @return A string containing text entered by the user, or {@code null} if the
886 * conversation has been terminated or if there was an error while reading.
887 */
Hall Liuffa4a812017-03-02 16:11:00 -0800888 public String read() throws IOException {
889 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
890 if (numRead < 0) {
891 return null;
892 }
893 return new String(mReadBuffer, 0, numRead);
894 }
895
896 /**
897 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
898 * be read.
899 * @return A string containing text entered by the user, or {@code null} if the user has
900 * not entered any new text yet.
901 */
902 public String readImmediately() throws IOException {
903 if (mPipeFromInCall.ready()) {
904 return read();
905 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800906 return null;
907 }
908 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800909
910 /** @hide */
911 public ParcelFileDescriptor getFdFromInCall() {
912 return mFdFromInCall;
913 }
914
915 /** @hide */
916 public ParcelFileDescriptor getFdToInCall() {
917 return mFdToInCall;
918 }
919 }
920
921 /**
922 * Provides constants to represent the results of responses to session modify requests sent via
923 * {@link Call#sendRttRequest()}
924 */
925 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700926 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800927 /**
928 * Session modify request was successful.
929 */
930 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
931
932 /**
933 * Session modify request failed.
934 */
935 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
936
937 /**
938 * Session modify request ignored due to invalid parameters.
939 */
940 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
941
942 /**
943 * Session modify request timed out.
944 */
945 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
946
947 /**
948 * Session modify request rejected by remote user.
949 */
950 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800951 }
952
953 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700954 * Provides a means of controlling the video session associated with a {@link Connection}.
955 * <p>
956 * Implementations create a custom subclass of {@link VideoProvider} and the
957 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
958 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
959 * should set the {@link VideoProvider}.
960 * <p>
961 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
962 * {@link InCallService} implementations to issue requests related to the video session;
963 * it provides a means for the {@link ConnectionService} to report events and information
964 * related to the video session to Telecom and the {@link InCallService} implementations.
965 * <p>
966 * {@link InCallService} implementations interact with the {@link VideoProvider} via
967 * {@link android.telecom.InCallService.VideoCall}.
968 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700969 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 /**
971 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700972 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 */
974 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700975
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
978 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 */
980 public static final int SESSION_EVENT_RX_RESUME = 2;
981
982 /**
983 * Video transmission has begun. This occurs after a negotiated start of video transmission
984 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700985 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 */
987 public static final int SESSION_EVENT_TX_START = 3;
988
989 /**
990 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
991 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700992 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 */
994 public static final int SESSION_EVENT_TX_STOP = 4;
995
996 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800997 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700998 * this as a cue to inform the user the camera is not available.
999 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000 */
1001 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1002
1003 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001004 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001005 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * the camera has become available again.
1007 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008 */
1009 public static final int SESSION_EVENT_CAMERA_READY = 6;
1010
1011 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001012 * Session event raised by Telecom when
1013 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1014 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1015 * @see #handleCallSessionEvent(int)
1016 */
1017 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1018
1019 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 */
1023 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1024
1025 /**
1026 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001027 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001028 */
1029 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1030
1031 /**
1032 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 */
1035 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1036
Rekha Kumar07366812015-03-24 16:42:31 -07001037 /**
1038 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001039 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001040 */
1041 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1042
1043 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001044 * Session modify request rejected by remote user.
1045 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001046 */
1047 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1048
Tyler Gunn75958422015-04-15 14:23:42 -07001049 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 private static final int MSG_SET_CAMERA = 2;
1051 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1052 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1053 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1054 private static final int MSG_SET_ZOOM = 6;
1055 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1056 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1057 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001058 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001059 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001060 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001062 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1063 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1064 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1065 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1066 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1067 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001068 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1069 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001070 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1071
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001072 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001074
1075 /**
1076 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001077 *
1078 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1079 * load factor before resizing, 1 means we only expect a single thread to
1080 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001081 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001082 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1083 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001084
1085 /**
1086 * Default handler used to consolidate binder method calls onto a single thread.
1087 */
1088 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001089 public VideoProviderHandler() {
1090 super();
1091 }
1092
1093 public VideoProviderHandler(Looper looper) {
1094 super(looper);
1095 }
1096
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 @Override
1098 public void handleMessage(Message msg) {
1099 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001100 case MSG_ADD_VIDEO_CALLBACK: {
1101 IBinder binder = (IBinder) msg.obj;
1102 IVideoCallback callback = IVideoCallback.Stub
1103 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001104 if (callback == null) {
1105 Log.w(this, "addVideoProvider - skipped; callback is null.");
1106 break;
1107 }
1108
Tyler Gunn75958422015-04-15 14:23:42 -07001109 if (mVideoCallbacks.containsKey(binder)) {
1110 Log.i(this, "addVideoProvider - skipped; already present.");
1111 break;
1112 }
1113 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001115 }
1116 case MSG_REMOVE_VIDEO_CALLBACK: {
1117 IBinder binder = (IBinder) msg.obj;
1118 IVideoCallback callback = IVideoCallback.Stub
1119 .asInterface((IBinder) msg.obj);
1120 if (!mVideoCallbacks.containsKey(binder)) {
1121 Log.i(this, "removeVideoProvider - skipped; not present.");
1122 break;
1123 }
1124 mVideoCallbacks.remove(binder);
1125 break;
1126 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001127 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001128 {
1129 SomeArgs args = (SomeArgs) msg.obj;
1130 try {
1131 onSetCamera((String) args.arg1);
1132 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001133 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001134 } finally {
1135 args.recycle();
1136 }
1137 }
1138 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001139 case MSG_SET_PREVIEW_SURFACE:
1140 onSetPreviewSurface((Surface) msg.obj);
1141 break;
1142 case MSG_SET_DISPLAY_SURFACE:
1143 onSetDisplaySurface((Surface) msg.obj);
1144 break;
1145 case MSG_SET_DEVICE_ORIENTATION:
1146 onSetDeviceOrientation(msg.arg1);
1147 break;
1148 case MSG_SET_ZOOM:
1149 onSetZoom((Float) msg.obj);
1150 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001151 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1152 SomeArgs args = (SomeArgs) msg.obj;
1153 try {
1154 onSendSessionModifyRequest((VideoProfile) args.arg1,
1155 (VideoProfile) args.arg2);
1156 } finally {
1157 args.recycle();
1158 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001159 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001160 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1162 onSendSessionModifyResponse((VideoProfile) msg.obj);
1163 break;
1164 case MSG_REQUEST_CAMERA_CAPABILITIES:
1165 onRequestCameraCapabilities();
1166 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001167 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1168 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001169 break;
1170 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001171 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 break;
1173 default:
1174 break;
1175 }
1176 }
1177 }
1178
1179 /**
1180 * IVideoProvider stub implementation.
1181 */
1182 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001183 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001185 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1186 }
1187
1188 public void removeVideoCallback(IBinder videoCallbackBinder) {
1189 mMessageHandler.obtainMessage(
1190 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001191 }
1192
Tyler Gunn159f35c2017-03-02 09:28:37 -08001193 public void setCamera(String cameraId, String callingPackageName,
1194 int targetSdkVersion) {
1195
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001196 SomeArgs args = SomeArgs.obtain();
1197 args.arg1 = cameraId;
1198 // Propagate the calling package; originally determined in
1199 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1200 // process.
1201 args.arg2 = callingPackageName;
1202 // Pass along the uid and pid of the calling app; this gets lost when we put the
1203 // message onto the handler. These are required for Telecom to perform a permission
1204 // check to see if the calling app is able to use the camera.
1205 args.argi1 = Binder.getCallingUid();
1206 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001207 // Pass along the target SDK version of the calling InCallService. This is used to
1208 // maintain backwards compatibility of the API for older callers.
1209 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001210 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 }
1212
1213 public void setPreviewSurface(Surface surface) {
1214 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1215 }
1216
1217 public void setDisplaySurface(Surface surface) {
1218 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1219 }
1220
1221 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001222 mMessageHandler.obtainMessage(
1223 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 }
1225
1226 public void setZoom(float value) {
1227 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1228 }
1229
Tyler Gunn45382162015-05-06 08:52:27 -07001230 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1231 SomeArgs args = SomeArgs.obtain();
1232 args.arg1 = fromProfile;
1233 args.arg2 = toProfile;
1234 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001235 }
1236
1237 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1238 mMessageHandler.obtainMessage(
1239 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1240 }
1241
1242 public void requestCameraCapabilities() {
1243 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1244 }
1245
1246 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001247 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 }
1249
Yorke Lee32f24732015-05-12 16:18:03 -07001250 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001251 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1252 }
1253 }
1254
1255 public VideoProvider() {
1256 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001257 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001258 }
1259
1260 /**
1261 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1262 *
1263 * @param looper The looper.
1264 * @hide
1265 */
1266 public VideoProvider(Looper looper) {
1267 mBinder = new VideoProvider.VideoProviderBinder();
1268 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 }
1270
1271 /**
1272 * Returns binder object which can be used across IPC methods.
1273 * @hide
1274 */
1275 public final IVideoProvider getInterface() {
1276 return mBinder;
1277 }
1278
1279 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001280 * Sets the camera to be used for the outgoing video.
1281 * <p>
1282 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1283 * camera via
1284 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1285 * <p>
1286 * Sent from the {@link InCallService} via
1287 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001288 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001289 * @param cameraId The id of the camera (use ids as reported by
1290 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 */
1292 public abstract void onSetCamera(String cameraId);
1293
1294 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001295 * Sets the camera to be used for the outgoing video.
1296 * <p>
1297 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1298 * camera via
1299 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1300 * <p>
1301 * This prototype is used internally to ensure that the calling package name, UID and PID
1302 * are sent to Telecom so that can perform a camera permission check on the caller.
1303 * <p>
1304 * Sent from the {@link InCallService} via
1305 * {@link InCallService.VideoCall#setCamera(String)}.
1306 *
1307 * @param cameraId The id of the camera (use ids as reported by
1308 * {@link CameraManager#getCameraIdList()}).
1309 * @param callingPackageName The AppOpps package name of the caller.
1310 * @param callingUid The UID of the caller.
1311 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001312 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001313 * @hide
1314 */
1315 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001316 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001317
1318 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 * Sets the surface to be used for displaying a preview of what the user's camera is
1320 * currently capturing. When video transmission is enabled, this is the video signal which
1321 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001322 * <p>
1323 * Sent from the {@link InCallService} via
1324 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001326 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 */
1328 public abstract void onSetPreviewSurface(Surface surface);
1329
1330 /**
1331 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001332 * <p>
1333 * Sent from the {@link InCallService} via
1334 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001336 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 */
1338 public abstract void onSetDisplaySurface(Surface surface);
1339
1340 /**
1341 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1342 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001343 * <p>
1344 * Sent from the {@link InCallService} via
1345 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 *
1347 * @param rotation The device orientation, in degrees.
1348 */
1349 public abstract void onSetDeviceOrientation(int rotation);
1350
1351 /**
1352 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001353 * <p>
1354 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 *
1356 * @param value The camera zoom ratio.
1357 */
1358 public abstract void onSetZoom(float value);
1359
1360 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001361 * Issues a request to modify the properties of the current video session.
1362 * <p>
1363 * Example scenarios include: requesting an audio-only call to be upgraded to a
1364 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1365 * when the {@link InCallService} is no longer the foreground application.
1366 * <p>
1367 * If the {@link VideoProvider} determines a request to be invalid, it should call
1368 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1369 * invalid request back to the {@link InCallService}.
1370 * <p>
1371 * Where a request requires confirmation from the user of the peer device, the
1372 * {@link VideoProvider} must communicate the request to the peer device and handle the
1373 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1374 * is used to inform the {@link InCallService} of the result of the request.
1375 * <p>
1376 * Sent from the {@link InCallService} via
1377 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001379 * @param fromProfile The video profile prior to the request.
1380 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 */
Tyler Gunn45382162015-05-06 08:52:27 -07001382 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1383 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384
Tyler Gunnb702ef82015-05-29 11:51:53 -07001385 /**
1386 * Provides a response to a request to change the current video session properties.
1387 * <p>
1388 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1389 * video call, could decline the request and keep the call as audio-only.
1390 * In such a scenario, the {@code responseProfile} would have a video state of
1391 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1392 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1393 * <p>
1394 * Sent from the {@link InCallService} via
1395 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1396 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1397 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001399 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 */
1401 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1402
1403 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001404 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1405 * <p>
1406 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1407 * camera via
1408 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1409 * <p>
1410 * Sent from the {@link InCallService} via
1411 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001412 */
1413 public abstract void onRequestCameraCapabilities();
1414
1415 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001416 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1417 * video component of the current {@link Connection}.
1418 * <p>
1419 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1420 * via {@link VideoProvider#setCallDataUsage(long)}.
1421 * <p>
1422 * Sent from the {@link InCallService} via
1423 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001425 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426
1427 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1429 * the peer device when the video signal is paused.
1430 * <p>
1431 * Sent from the {@link InCallService} via
1432 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 *
1434 * @param uri URI of image to display.
1435 */
Yorke Lee32f24732015-05-12 16:18:03 -07001436 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001437
1438 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001439 * Used to inform listening {@link InCallService} implementations when the
1440 * {@link VideoProvider} receives a session modification request.
1441 * <p>
1442 * Received by the {@link InCallService} via
1443 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001445 * @param videoProfile The requested video profile.
1446 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001447 */
1448 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001449 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001450 for (IVideoCallback callback : mVideoCallbacks.values()) {
1451 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001452 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001453 } catch (RemoteException ignored) {
1454 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001455 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 }
1457 }
1458 }
1459
1460 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001461 * Used to inform listening {@link InCallService} implementations when the
1462 * {@link VideoProvider} receives a response to a session modification request.
1463 * <p>
1464 * Received by the {@link InCallService} via
1465 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1466 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467 *
1468 * @param status Status of the session modify request. Valid values are
1469 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1470 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001471 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1472 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1473 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1474 * @param requestedProfile The original request which was sent to the peer device.
1475 * @param responseProfile The actual profile changes agreed to by the peer device.
1476 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 */
1478 public void receiveSessionModifyResponse(int status,
1479 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001480 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001481 for (IVideoCallback callback : mVideoCallbacks.values()) {
1482 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001483 callback.receiveSessionModifyResponse(status, requestedProfile,
1484 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001485 } catch (RemoteException ignored) {
1486 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001487 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 }
1489 }
1490 }
1491
1492 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001493 * Used to inform listening {@link InCallService} implementations when the
1494 * {@link VideoProvider} reports a call session event.
1495 * <p>
1496 * Received by the {@link InCallService} via
1497 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001499 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1500 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1501 * {@link VideoProvider#SESSION_EVENT_TX_START},
1502 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1503 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001504 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1505 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001506 */
1507 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001508 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001509 for (IVideoCallback callback : mVideoCallbacks.values()) {
1510 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001511 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001512 } catch (RemoteException ignored) {
1513 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001514 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 }
1516 }
1517 }
1518
1519 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001520 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1521 * peer's video have changed.
1522 * <p>
1523 * This could occur if, for example, the peer rotates their device, changing the aspect
1524 * ratio of the video, or if the user switches between the back and front cameras.
1525 * <p>
1526 * Received by the {@link InCallService} via
1527 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 *
1529 * @param width The updated peer video width.
1530 * @param height The updated peer video height.
1531 */
1532 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001533 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001534 for (IVideoCallback callback : mVideoCallbacks.values()) {
1535 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001536 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001537 } catch (RemoteException ignored) {
1538 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001539 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 }
1541 }
1542 }
1543
1544 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001545 * Used to inform listening {@link InCallService} implementations when the data usage of the
1546 * video associated with the current {@link Connection} has changed.
1547 * <p>
1548 * This could be in response to a preview request via
1549 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001550 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1551 * 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 -07001552 * <p>
1553 * Received by the {@link InCallService} via
1554 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001555 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001556 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1557 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 */
Yorke Lee32f24732015-05-12 16:18:03 -07001559 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001560 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001561 for (IVideoCallback callback : mVideoCallbacks.values()) {
1562 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001563 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001564 } catch (RemoteException ignored) {
1565 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001566 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 }
1568 }
1569 }
1570
1571 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001572 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001573 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001574 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001575 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1576 * @hide
1577 */
1578 public void changeCallDataUsage(long dataUsage) {
1579 setCallDataUsage(dataUsage);
1580 }
1581
1582 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001583 * Used to inform listening {@link InCallService} implementations when the capabilities of
1584 * the current camera have changed.
1585 * <p>
1586 * The {@link VideoProvider} should call this in response to
1587 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1588 * changed via {@link VideoProvider#onSetCamera(String)}.
1589 * <p>
1590 * Received by the {@link InCallService} via
1591 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1592 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001593 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001594 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001595 */
Yorke Lee400470f2015-05-12 13:31:25 -07001596 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001597 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001598 for (IVideoCallback callback : mVideoCallbacks.values()) {
1599 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001600 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001601 } catch (RemoteException ignored) {
1602 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001603 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 }
1605 }
1606 }
Rekha Kumar07366812015-03-24 16:42:31 -07001607
1608 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001609 * Used to inform listening {@link InCallService} implementations when the video quality
1610 * of the call has changed.
1611 * <p>
1612 * Received by the {@link InCallService} via
1613 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001614 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001615 * @param videoQuality The updated video quality. Valid values:
1616 * {@link VideoProfile#QUALITY_HIGH},
1617 * {@link VideoProfile#QUALITY_MEDIUM},
1618 * {@link VideoProfile#QUALITY_LOW},
1619 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001620 */
1621 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001622 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001623 for (IVideoCallback callback : mVideoCallbacks.values()) {
1624 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001625 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001626 } catch (RemoteException ignored) {
1627 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001628 }
Rekha Kumar07366812015-03-24 16:42:31 -07001629 }
1630 }
1631 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001632
1633 /**
1634 * Returns a string representation of a call session event.
1635 *
1636 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1637 * @return String representation of the call session event.
1638 * @hide
1639 */
1640 public static String sessionEventToString(int event) {
1641 switch (event) {
1642 case SESSION_EVENT_CAMERA_FAILURE:
1643 return SESSION_EVENT_CAMERA_FAILURE_STR;
1644 case SESSION_EVENT_CAMERA_READY:
1645 return SESSION_EVENT_CAMERA_READY_STR;
1646 case SESSION_EVENT_RX_PAUSE:
1647 return SESSION_EVENT_RX_PAUSE_STR;
1648 case SESSION_EVENT_RX_RESUME:
1649 return SESSION_EVENT_RX_RESUME_STR;
1650 case SESSION_EVENT_TX_START:
1651 return SESSION_EVENT_TX_START_STR;
1652 case SESSION_EVENT_TX_STOP:
1653 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001654 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1655 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001656 default:
1657 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1658 }
1659 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001660 }
1661
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001662 private final Listener mConnectionDeathListener = new Listener() {
1663 @Override
1664 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001665 if (mConferenceables.remove(c)) {
1666 fireOnConferenceableConnectionsChanged();
1667 }
1668 }
1669 };
1670
1671 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1672 @Override
1673 public void onDestroyed(Conference c) {
1674 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001675 fireOnConferenceableConnectionsChanged();
1676 }
1677 }
1678 };
1679
Jay Shrauner229e3822014-08-15 09:23:07 -07001680 /**
1681 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1682 * load factor before resizing, 1 means we only expect a single thread to
1683 * access the map so make only a single shard
1684 */
1685 private final Set<Listener> mListeners = Collections.newSetFromMap(
1686 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001687 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1688 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001689 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001690
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001691 // The internal telecom call ID associated with this connection.
1692 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001693 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001694 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001695 private Uri mAddress;
1696 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001697 private String mCallerDisplayName;
1698 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001699 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001700 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001701 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001702 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001703 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001704 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001705 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001706 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001707 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001708 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001709 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001710 private Conference mConference;
1711 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001712 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001713 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714
1715 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001716 * Tracks the key set for the extras bundle provided on the last invocation of
1717 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1718 * keys which were set previously but are no longer present in the replacement Bundle.
1719 */
1720 private Set<String> mPreviousExtraKeys;
1721
1722 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723 * Create a new Connection.
1724 */
Santos Cordonf2951102014-07-20 19:06:29 -07001725 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001726
1727 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001728 * Returns the Telecom internal call ID associated with this connection. Should only be used
1729 * for debugging and tracing purposes.
1730 *
1731 * @return The Telecom call ID.
1732 * @hide
1733 */
1734 public final String getTelecomCallId() {
1735 return mTelecomCallId;
1736 }
1737
1738 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001739 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001740 */
Andrew Lee100e2932014-09-08 15:34:24 -07001741 public final Uri getAddress() {
1742 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001743 }
1744
1745 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001746 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001747 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001748 */
Andrew Lee100e2932014-09-08 15:34:24 -07001749 public final int getAddressPresentation() {
1750 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001751 }
1752
1753 /**
1754 * @return The caller display name (CNAP).
1755 */
1756 public final String getCallerDisplayName() {
1757 return mCallerDisplayName;
1758 }
1759
1760 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001761 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001762 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001763 */
1764 public final int getCallerDisplayNamePresentation() {
1765 return mCallerDisplayNamePresentation;
1766 }
1767
1768 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001769 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001770 */
1771 public final int getState() {
1772 return mState;
1773 }
1774
1775 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001776 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001777 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1778 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1779 * {@link VideoProfile#STATE_TX_ENABLED},
1780 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001781 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001782 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001783 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001784 */
1785 public final int getVideoState() {
1786 return mVideoState;
1787 }
1788
1789 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001790 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001791 * being routed by the system. This is {@code null} if this Connection
1792 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001793 * @deprecated Use {@link #getCallAudioState()} instead.
1794 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001795 */
Yorke Lee4af59352015-05-13 14:14:54 -07001796 @SystemApi
1797 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001798 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001799 if (mCallAudioState == null) {
1800 return null;
1801 }
Yorke Lee4af59352015-05-13 14:14:54 -07001802 return new AudioState(mCallAudioState);
1803 }
1804
1805 /**
1806 * @return The audio state of the connection, describing how its audio is currently
1807 * being routed by the system. This is {@code null} if this Connection
1808 * does not directly know about its audio state.
1809 */
1810 public final CallAudioState getCallAudioState() {
1811 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001812 }
1813
1814 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001815 * @return The conference that this connection is a part of. Null if it is not part of any
1816 * conference.
1817 */
1818 public final Conference getConference() {
1819 return mConference;
1820 }
1821
1822 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001823 * Returns whether this connection is requesting that the system play a ringback tone
1824 * on its behalf.
1825 */
Andrew Lee100e2932014-09-08 15:34:24 -07001826 public final boolean isRingbackRequested() {
1827 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001828 }
1829
1830 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001831 * @return True if the connection's audio mode is VOIP.
1832 */
1833 public final boolean getAudioModeIsVoip() {
1834 return mAudioModeIsVoip;
1835 }
1836
1837 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001838 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1839 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1840 * start time of the conference.
1841 *
1842 * @return The time at which the {@code Connnection} was connected.
1843 *
1844 * @hide
1845 */
1846 public final long getConnectTimeMillis() {
1847 return mConnectTimeMillis;
1848 }
1849
1850 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001851 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1852 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1853 * start time of the conference.
1854 *
1855 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1856 * changes do not impact the call duration.
1857 *
1858 * @return The time at which the {@link Connection} was connected.
1859 *
1860 * @hide
1861 */
1862 public final long getConnectElapsedTimeMillis() {
1863 return mConnectElapsedTimeMillis;
1864 }
1865
1866 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001867 * @return The status hints for this connection.
1868 */
1869 public final StatusHints getStatusHints() {
1870 return mStatusHints;
1871 }
1872
1873 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001874 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001875 * <p>
1876 * Extras should be updated using {@link #putExtras(Bundle)}.
1877 * <p>
1878 * Telecom or an {@link InCallService} can also update the extras via
1879 * {@link android.telecom.Call#putExtras(Bundle)}, and
1880 * {@link Call#removeExtras(List)}.
1881 * <p>
1882 * The connection is notified of changes to the extras made by Telecom or an
1883 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001884 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001885 * @return The extras associated with this connection.
1886 */
1887 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001888 Bundle extras = null;
1889 synchronized (mExtrasLock) {
1890 if (mExtras != null) {
1891 extras = new Bundle(mExtras);
1892 }
1893 }
1894 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001895 }
1896
1897 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001898 * Assign a listener to be notified of state changes.
1899 *
1900 * @param l A listener.
1901 * @return This Connection.
1902 *
1903 * @hide
1904 */
1905 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001906 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001907 return this;
1908 }
1909
1910 /**
1911 * Remove a previously assigned listener that was being notified of state changes.
1912 *
1913 * @param l A Listener.
1914 * @return This Connection.
1915 *
1916 * @hide
1917 */
1918 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001919 if (l != null) {
1920 mListeners.remove(l);
1921 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001922 return this;
1923 }
1924
1925 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001926 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001927 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001928 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001929 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001930 }
1931
1932 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001933 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1934 * ONLY for debugging purposes.
1935 *
1936 * @param callId The telecom call ID.
1937 * @hide
1938 */
1939 public void setTelecomCallId(String callId) {
1940 mTelecomCallId = callId;
1941 }
1942
1943 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001944 * Inform this Connection that the state of its audio output has been changed externally.
1945 *
1946 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001947 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 */
Yorke Lee4af59352015-05-13 14:14:54 -07001949 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001950 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001951 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001952 mCallAudioState = state;
1953 onAudioStateChanged(getAudioState());
1954 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001955 }
1956
1957 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001958 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001959 * @return A string representation of the value.
1960 */
1961 public static String stateToString(int state) {
1962 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001963 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001964 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001965 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001966 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001967 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001968 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001969 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001970 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001971 case STATE_PULLING_CALL:
1972 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001973 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001974 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001975 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001976 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001978 return "DISCONNECTED";
1979 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001980 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001981 return "UNKNOWN";
1982 }
1983 }
1984
1985 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001986 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001987 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001988 public final int getConnectionCapabilities() {
1989 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001990 }
1991
1992 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001993 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1994 */
1995 public final int getConnectionProperties() {
1996 return mConnectionProperties;
1997 }
1998
1999 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002000 * Returns the connection's supported audio routes.
2001 *
2002 * @hide
2003 */
2004 public final int getSupportedAudioRoutes() {
2005 return mSupportedAudioRoutes;
2006 }
2007
2008 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002009 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002010 *
Andrew Lee100e2932014-09-08 15:34:24 -07002011 * @param address The new address.
2012 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002013 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002014 */
Andrew Lee100e2932014-09-08 15:34:24 -07002015 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002016 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002017 Log.d(this, "setAddress %s", address);
2018 mAddress = address;
2019 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002020 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002021 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002022 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002023 }
2024
2025 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002026 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002027 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002028 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002029 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002030 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002031 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002032 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002033 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002034 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002035 mCallerDisplayName = callerDisplayName;
2036 mCallerDisplayNamePresentation = presentation;
2037 for (Listener l : mListeners) {
2038 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2039 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002040 }
2041
2042 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002043 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002044 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2045 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2046 * {@link VideoProfile#STATE_TX_ENABLED},
2047 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002048 *
2049 * @param videoState The new video state.
2050 */
2051 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002052 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002053 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002054 mVideoState = videoState;
2055 for (Listener l : mListeners) {
2056 l.onVideoStateChanged(this, mVideoState);
2057 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002058 }
2059
2060 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002061 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002062 * communicate).
2063 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002064 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002065 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002066 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002067 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002068 }
2069
2070 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002071 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002073 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002074 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002075 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 }
2077
2078 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002079 * Sets state to initializing (this Connection is not yet ready to be used).
2080 */
2081 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002082 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002083 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002084 }
2085
2086 /**
2087 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2088 */
2089 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002090 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002091 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002092 }
2093
2094 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002095 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002096 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002097 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002098 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002099 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002100 }
2101
2102 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002103 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2104 * device). Only applicable for {@link Connection}s with
2105 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2106 */
2107 public final void setPulling() {
2108 checkImmutable();
2109 setState(STATE_PULLING_CALL);
2110 }
2111
2112 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002113 * Sets state to be on hold.
2114 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002115 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002118 }
2119
2120 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002121 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002122 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002123 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002124 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002126 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002127 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002128 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002129 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002130 }
2131
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002132 public final VideoProvider getVideoProvider() {
2133 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002134 }
2135
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002136 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002137 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002138 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002139 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002140 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002141 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002142 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002143 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002144 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002145 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002146 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002147 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002148 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002149 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002150 }
2151
2152 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002153 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2154 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2155 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2156 * to send an {@link #onPostDialContinue(boolean)} signal.
2157 *
2158 * @param remaining The DTMF character sequence remaining to be emitted once the
2159 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2160 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002161 */
2162 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002163 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002164 for (Listener l : mListeners) {
2165 l.onPostDialWait(this, remaining);
2166 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002167 }
2168
2169 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002170 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2171 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002172 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002173 *
2174 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002175 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002176 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002177 checkImmutable();
2178 for (Listener l : mListeners) {
2179 l.onPostDialChar(this, nextChar);
2180 }
2181 }
2182
2183 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002184 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002185 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002186 *
2187 * @param ringback Whether the ringback tone is to be played.
2188 */
Andrew Lee100e2932014-09-08 15:34:24 -07002189 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002190 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002191 if (mRingbackRequested != ringback) {
2192 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002193 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002194 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002195 }
2196 }
Ihab Awadf8358972014-05-28 16:46:42 -07002197 }
2198
2199 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002200 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002201 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002202 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002203 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002204 public final void setConnectionCapabilities(int connectionCapabilities) {
2205 checkImmutable();
2206 if (mConnectionCapabilities != connectionCapabilities) {
2207 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002208 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002209 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002210 }
2211 }
Santos Cordonb6939982014-06-04 20:20:58 -07002212 }
2213
2214 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002215 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2216 *
2217 * @param connectionProperties The new connection properties.
2218 */
2219 public final void setConnectionProperties(int connectionProperties) {
2220 checkImmutable();
2221 if (mConnectionProperties != connectionProperties) {
2222 mConnectionProperties = connectionProperties;
2223 for (Listener l : mListeners) {
2224 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2225 }
2226 }
2227 }
2228
2229 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002230 * Sets the supported audio routes.
2231 *
2232 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2233 * See {@link CallAudioState}
2234 * @hide
2235 */
2236 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2237 if ((supportedAudioRoutes
2238 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2239 throw new IllegalArgumentException(
2240 "supported audio routes must include either speaker or earpiece");
2241 }
2242
2243 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2244 mSupportedAudioRoutes = supportedAudioRoutes;
2245 for (Listener l : mListeners) {
2246 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2247 }
2248 }
2249 }
2250
2251 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002252 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002253 */
Evan Charlton36a71342014-07-19 16:31:02 -07002254 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002255 for (Listener l : mListeners) {
2256 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002257 }
Santos Cordonb6939982014-06-04 20:20:58 -07002258 }
2259
2260 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002261 * Requests that the framework use VOIP audio mode for this connection.
2262 *
2263 * @param isVoip True if the audio mode is VOIP.
2264 */
2265 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002266 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002267 mAudioModeIsVoip = isVoip;
2268 for (Listener l : mListeners) {
2269 l.onAudioModeIsVoipChanged(this, isVoip);
2270 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002271 }
2272
2273 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002274 * Sets the time at which a call became active on this Connection. This is set only
2275 * when a conference call becomes active on this connection.
2276 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002277 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2278 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002279 *
2280 * @hide
2281 */
2282 public final void setConnectTimeMillis(long connectTimeMillis) {
2283 mConnectTimeMillis = connectTimeMillis;
2284 }
2285
2286 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002287 * Sets the time at which a call became active on this Connection. This is set only
2288 * when a conference call becomes active on this connection.
2289 *
2290 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2291 * {@link SystemClock#elapsedRealtime()}.
2292 *
2293 * @hide
2294 */
2295 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2296 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2297 }
2298
2299 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002300 * Sets the label and icon status to display in the in-call UI.
2301 *
2302 * @param statusHints The status label and icon to set.
2303 */
2304 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002305 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002306 mStatusHints = statusHints;
2307 for (Listener l : mListeners) {
2308 l.onStatusHintsChanged(this, statusHints);
2309 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002310 }
2311
2312 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002313 * Sets the connections with which this connection can be conferenced.
2314 *
2315 * @param conferenceableConnections The set of connections this connection can conference with.
2316 */
2317 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002318 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002319 clearConferenceableList();
2320 for (Connection c : conferenceableConnections) {
2321 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2322 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002323 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002324 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002325 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002326 }
2327 }
2328 fireOnConferenceableConnectionsChanged();
2329 }
2330
2331 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002332 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2333 * or conferences with which this connection can be conferenced.
2334 *
2335 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002336 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002337 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002338 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002339 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002340 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2341 // small amount of items here.
2342 if (!mConferenceables.contains(c)) {
2343 if (c instanceof Connection) {
2344 Connection connection = (Connection) c;
2345 connection.addConnectionListener(mConnectionDeathListener);
2346 } else if (c instanceof Conference) {
2347 Conference conference = (Conference) c;
2348 conference.addListener(mConferenceDeathListener);
2349 }
2350 mConferenceables.add(c);
2351 }
2352 }
2353 fireOnConferenceableConnectionsChanged();
2354 }
2355
2356 /**
2357 * Returns the connections or conferences with which this connection can be conferenced.
2358 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002359 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002360 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002361 }
2362
Yorke Lee53463962015-08-04 16:07:19 -07002363 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002364 * @hide
2365 */
2366 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002367 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002368 if (mConnectionService != null) {
2369 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2370 "which is already associated with another ConnectionService.");
2371 } else {
2372 mConnectionService = connectionService;
2373 }
2374 }
2375
2376 /**
2377 * @hide
2378 */
2379 public final void unsetConnectionService(ConnectionService connectionService) {
2380 if (mConnectionService != connectionService) {
2381 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2382 "that does not belong to the ConnectionService.");
2383 } else {
2384 mConnectionService = null;
2385 }
2386 }
2387
2388 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002389 * @hide
2390 */
2391 public final ConnectionService getConnectionService() {
2392 return mConnectionService;
2393 }
2394
2395 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002396 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002397 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002398 *
2399 * @param conference The conference.
2400 * @return {@code true} if the conference was successfully set.
2401 * @hide
2402 */
2403 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002404 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002405 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002406 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002407 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002408 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2409 fireConferenceChanged();
2410 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002411 return true;
2412 }
2413 return false;
2414 }
2415
2416 /**
2417 * Resets the conference that this connection is a part of.
2418 * @hide
2419 */
2420 public final void resetConference() {
2421 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002422 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 mConference = null;
2424 fireConferenceChanged();
2425 }
2426 }
2427
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002428 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002429 * Set some extras that can be associated with this {@code Connection}.
2430 * <p>
2431 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2432 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2433 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002434 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2435 * {@link #removeExtras(String...)} methods to modify the extras.
2436 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002437 * 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 -07002438 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2439 *
2440 * @param extras The extras associated with this {@code Connection}.
2441 */
2442 public final void setExtras(@Nullable Bundle extras) {
2443 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002444
2445 // Add/replace any new or changed extras values.
2446 putExtras(extras);
2447
2448 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2449 // the current one and remove any keys that went away.
2450 if (mPreviousExtraKeys != null) {
2451 List<String> toRemove = new ArrayList<String>();
2452 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002453 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002454 toRemove.add(oldKey);
2455 }
2456 }
2457 if (!toRemove.isEmpty()) {
2458 removeExtras(toRemove);
2459 }
2460 }
2461
2462 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2463 // called we can see if the caller has removed any extras values.
2464 if (mPreviousExtraKeys == null) {
2465 mPreviousExtraKeys = new ArraySet<String>();
2466 }
2467 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002468 if (extras != null) {
2469 mPreviousExtraKeys.addAll(extras.keySet());
2470 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002471 }
2472
2473 /**
2474 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2475 * added.
2476 * <p>
2477 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2478 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2479 *
2480 * @param extras The extras to add.
2481 */
2482 public final void putExtras(@NonNull Bundle extras) {
2483 checkImmutable();
2484 if (extras == null) {
2485 return;
2486 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002487 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2488 // the listeners.
2489 Bundle listenerExtras;
2490 synchronized (mExtrasLock) {
2491 if (mExtras == null) {
2492 mExtras = new Bundle();
2493 }
2494 mExtras.putAll(extras);
2495 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002496 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002497 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002498 // Create a new clone of the extras for each listener so that they don't clobber
2499 // each other
2500 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002501 }
2502 }
2503
2504 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002505 * Adds a boolean extra to this {@code Connection}.
2506 *
2507 * @param key The extra key.
2508 * @param value The value.
2509 * @hide
2510 */
2511 public final void putExtra(String key, boolean value) {
2512 Bundle newExtras = new Bundle();
2513 newExtras.putBoolean(key, value);
2514 putExtras(newExtras);
2515 }
2516
2517 /**
2518 * Adds an integer extra to this {@code Connection}.
2519 *
2520 * @param key The extra key.
2521 * @param value The value.
2522 * @hide
2523 */
2524 public final void putExtra(String key, int value) {
2525 Bundle newExtras = new Bundle();
2526 newExtras.putInt(key, value);
2527 putExtras(newExtras);
2528 }
2529
2530 /**
2531 * Adds a string extra to this {@code Connection}.
2532 *
2533 * @param key The extra key.
2534 * @param value The value.
2535 * @hide
2536 */
2537 public final void putExtra(String key, String value) {
2538 Bundle newExtras = new Bundle();
2539 newExtras.putString(key, value);
2540 putExtras(newExtras);
2541 }
2542
2543 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002544 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002545 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002546 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002547 */
2548 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002549 synchronized (mExtrasLock) {
2550 if (mExtras != null) {
2551 for (String key : keys) {
2552 mExtras.remove(key);
2553 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002554 }
2555 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002556 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002557 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002558 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002559 }
2560 }
2561
2562 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002563 * Removes extras from this {@code Connection}.
2564 *
2565 * @param keys The keys of the extras to remove.
2566 */
2567 public final void removeExtras(String ... keys) {
2568 removeExtras(Arrays.asList(keys));
2569 }
2570
2571 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002572 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2573 * be change to the {@link #getCallAudioState()}.
2574 * <p>
2575 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2576 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2577 * <p>
2578 * See also {@link InCallService#setAudioRoute(int)}.
2579 *
2580 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2581 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2582 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2583 */
2584 public final void setAudioRoute(int route) {
2585 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002586 l.onAudioRouteChanged(this, route, null);
2587 }
2588 }
2589
2590 /**
2591 *
2592 * Request audio routing to a specific bluetooth device. Calling this method may result in
2593 * the device routing audio to a different bluetooth device than the one specified if the
2594 * bluetooth stack is unable to route audio to the requested device.
2595 * A list of available devices can be obtained via
2596 * {@link CallAudioState#getSupportedBluetoothDevices()}
2597 *
2598 * <p>
2599 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2600 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2601 * <p>
2602 * See also {@link InCallService#requestBluetoothAudio(String)}
2603 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2604 * {@link BluetoothDevice#getAddress()}.
2605 */
2606 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2607 for (Listener l : mListeners) {
2608 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08002609 }
2610 }
2611
2612 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002613 * Informs listeners that a previously requested RTT session via
2614 * {@link ConnectionRequest#isRequestingRtt()} or
2615 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2616 * @hide
2617 */
Hall Liuffa4a812017-03-02 16:11:00 -08002618 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002619 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002620 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002621 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2622 }
2623
2624 /**
2625 * Informs listeners that a previously requested RTT session via
2626 * {@link ConnectionRequest#isRequestingRtt()} or
2627 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2628 * has failed.
2629 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2630 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2631 * @hide
2632 */
Hall Liuffa4a812017-03-02 16:11:00 -08002633 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002634 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002635 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2637 }
2638
2639 /**
2640 * Informs listeners that a currently active RTT session has been terminated by the remote
2641 * side of the coll.
2642 * @hide
2643 */
Hall Liuffa4a812017-03-02 16:11:00 -08002644 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002645 public final void sendRttSessionRemotelyTerminated() {
2646 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2647 }
2648
2649 /**
2650 * Informs listeners that the remote side of the call has requested an upgrade to include an
2651 * RTT session in the call.
2652 * @hide
2653 */
Hall Liuffa4a812017-03-02 16:11:00 -08002654 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002655 public final void sendRemoteRttRequest() {
2656 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2657 }
2658
2659 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002660 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002661 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002662 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002663 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2664 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002665 */
Yorke Lee4af59352015-05-13 14:14:54 -07002666 @SystemApi
2667 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002668 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002669
2670 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002671 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2672 *
2673 * @param state The new connection audio state.
2674 */
2675 public void onCallAudioStateChanged(CallAudioState state) {}
2676
2677 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002678 * Notifies this Connection of an internal state change. This method is called after the
2679 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002680 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002681 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002682 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002683 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002684
2685 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002686 * Notifies this Connection of a request to play a DTMF tone.
2687 *
2688 * @param c A DTMF character.
2689 */
Santos Cordonf2951102014-07-20 19:06:29 -07002690 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002691
2692 /**
2693 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2694 */
Santos Cordonf2951102014-07-20 19:06:29 -07002695 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002696
2697 /**
2698 * Notifies this Connection of a request to disconnect.
2699 */
Santos Cordonf2951102014-07-20 19:06:29 -07002700 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002701
2702 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002703 * Notifies this Connection of a request to disconnect a participant of the conference managed
2704 * by the connection.
2705 *
2706 * @param endpoint the {@link Uri} of the participant to disconnect.
2707 * @hide
2708 */
2709 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2710
2711 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002712 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002713 */
Santos Cordonf2951102014-07-20 19:06:29 -07002714 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002715
2716 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002717 * Notifies this Connection of a request to abort.
2718 */
Santos Cordonf2951102014-07-20 19:06:29 -07002719 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002720
2721 /**
2722 * Notifies this Connection of a request to hold.
2723 */
Santos Cordonf2951102014-07-20 19:06:29 -07002724 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002725
2726 /**
2727 * Notifies this Connection of a request to exit a hold state.
2728 */
Santos Cordonf2951102014-07-20 19:06:29 -07002729 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002730
2731 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002732 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002733 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002734 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002735 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002736 */
Santos Cordonf2951102014-07-20 19:06:29 -07002737 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002738
2739 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002740 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002741 * a request to accept.
2742 */
2743 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002744 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002745 }
2746
2747 /**
2748 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002749 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002750 */
Santos Cordonf2951102014-07-20 19:06:29 -07002751 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002752
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002753 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002754 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2755 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002756 */
2757 public void onReject(String replyMessage) {}
2758
2759 /**
Bryce Leecac50772015-11-17 15:13:29 -08002760 * Notifies the Connection of a request to silence the ringer.
2761 *
2762 * @hide
2763 */
2764 public void onSilence() {}
2765
2766 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002767 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2768 */
Santos Cordonf2951102014-07-20 19:06:29 -07002769 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002770
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002771 /**
2772 * Notifies this Connection of a request to pull an external call to the local device.
2773 * <p>
2774 * The {@link InCallService} issues a request to pull an external call to the local device via
2775 * {@link Call#pullExternalCall()}.
2776 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002777 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2778 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002779 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002780 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002781 */
2782 public void onPullExternalCall() {}
2783
2784 /**
2785 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2786 * <p>
2787 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2788 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002789 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2790 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2791 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2792 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2793 * not aware of.
2794 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002795 * See also {@link Call#sendCallEvent(String, Bundle)}.
2796 *
2797 * @param event The call event.
2798 * @param extras Extras associated with the call event.
2799 */
2800 public void onCallEvent(String event, Bundle extras) {}
2801
Tyler Gunndee56a82016-03-23 16:06:34 -07002802 /**
2803 * Notifies this {@link Connection} of a change to the extras made outside the
2804 * {@link ConnectionService}.
2805 * <p>
2806 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2807 * the {@link android.telecom.Call#putExtras(Bundle)} and
2808 * {@link Call#removeExtras(List)}.
2809 *
2810 * @param extras The new extras bundle.
2811 */
2812 public void onExtrasChanged(Bundle extras) {}
2813
Tyler Gunnf5035432017-01-09 09:43:12 -08002814 /**
2815 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2816 * displaying its incoming call user interface for the {@link Connection}.
2817 * <p>
2818 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2819 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2820 * should show its own incoming call user interface.
2821 * <p>
2822 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2823 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2824 * user interface to allow the user to choose whether to answer the new incoming call and
2825 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002826 * <p>
2827 * You should trigger the display of the incoming call user interface for your application by
2828 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2829 * For example:
2830 * <pre><code>
2831 * // Create an intent which triggers your fullscreen incoming call user interface.
2832 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2833 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2834 * intent.setClass(context, YourIncomingCallActivity.class);
2835 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2836 *
2837 * // Build the notification as an ongoing high priority item; this ensures it will show as
2838 * // a heads up notification which slides down over top of the current content.
2839 * final Notification.Builder builder = new Notification.Builder(context);
2840 * builder.setOngoing(true);
2841 * builder.setPriority(Notification.PRIORITY_HIGH);
2842 *
2843 * // Set notification content intent to take user to fullscreen UI if user taps on the
2844 * // notification body.
2845 * builder.setContentIntent(pendingIntent);
2846 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2847 * // manager deems it appropriate.
2848 * builder.setFullScreenIntent(pendingIntent, true);
2849 *
2850 * // Setup notification content.
2851 * builder.setSmallIcon( yourIconResourceId );
2852 * builder.setContentTitle("Your notification title");
2853 * builder.setContentText("Your notification content.");
2854 *
2855 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2856 *
2857 * NotificationManager notificationManager = mContext.getSystemService(
2858 * NotificationManager.class);
2859 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2860 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002861 */
2862 public void onShowIncomingCallUi() {}
2863
Hall Liub64ac4c2017-02-06 10:49:48 -08002864 /**
2865 * Notifies this {@link Connection} that the user has requested an RTT session.
2866 * The connection service should call {@link #sendRttInitiationSuccess} or
2867 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2868 * request, respectively.
2869 * @param rttTextStream The object that should be used to send text to or receive text from
2870 * the in-call app.
2871 * @hide
2872 */
Hall Liuffa4a812017-03-02 16:11:00 -08002873 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002874 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2875
2876 /**
2877 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2878 * channel. No response to Telecom is needed for this method.
2879 * @hide
2880 */
Hall Liuffa4a812017-03-02 16:11:00 -08002881 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002882 public void onStopRtt() {}
2883
2884 /**
2885 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2886 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2887 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2888 * indicated by {@code rttTextStream} being {@code null}
2889 * @hide
2890 * @param rttTextStream The object that should be used to send text to or receive text from
2891 * the in-call app.
2892 */
Hall Liuffa4a812017-03-02 16:11:00 -08002893 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002894 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2895
Hall Liuffa4a812017-03-02 16:11:00 -08002896 /**
2897 * Internal method to set {@link #PROPERTY_IS_RTT}.
2898 * @hide
2899 */
2900 void setRttProperty() {
2901 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2902 }
2903
2904 /**
2905 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2906 * @hide
2907 */
2908 void unsetRttProperty() {
2909 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2910 }
2911
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002912 static String toLogSafePhoneNumber(String number) {
2913 // For unknown number, log empty string.
2914 if (number == null) {
2915 return "";
2916 }
2917
2918 if (PII_DEBUG) {
2919 // When PII_DEBUG is true we emit PII.
2920 return number;
2921 }
2922
2923 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2924 // sanitized phone numbers.
2925 StringBuilder builder = new StringBuilder();
2926 for (int i = 0; i < number.length(); i++) {
2927 char c = number.charAt(i);
2928 if (c == '-' || c == '@' || c == '.') {
2929 builder.append(c);
2930 } else {
2931 builder.append('x');
2932 }
2933 }
2934 return builder.toString();
2935 }
2936
Ihab Awad542e0ea2014-05-16 10:22:16 -07002937 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002938 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002939 if (mState == STATE_DISCONNECTED && mState != state) {
2940 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002941 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002942 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002943 if (mState != state) {
2944 Log.d(this, "setState: %s", stateToString(state));
2945 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002946 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002947 for (Listener l : mListeners) {
2948 l.onStateChanged(this, state);
2949 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002950 }
2951 }
2952
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002953 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002954 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002955 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2956 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002957 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002958 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002959
2960 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002961 if (mImmutable) {
2962 throw new UnsupportedOperationException("Connection is immutable");
2963 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002964 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002965 }
2966
Evan Charltonbf11f982014-07-20 22:06:28 -07002967 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002968 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002969 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2970 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002971 * <p>
2972 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2973 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002974 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002975 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002976 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002977 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002978 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2979 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002980 }
2981
Evan Charltonbf11f982014-07-20 22:06:28 -07002982 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002983 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2984 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2985 * this should never be un-@hide-den.
2986 *
2987 * @hide
2988 */
2989 public void checkImmutable() {}
2990
2991 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002992 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2993 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2994 * that state. This connection should not be used for anything, and no other
2995 * {@code Connection}s should be attempted.
2996 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002997 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002998 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002999 * @return A {@code Connection} which indicates that the underlying connection should
3000 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003001 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003002 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003003 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003004 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003005
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003006 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003007 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003008 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003009 }
3010 }
3011
Santos Cordon823fd3c2014-08-07 18:35:18 -07003012 private final void fireConferenceChanged() {
3013 for (Listener l : mListeners) {
3014 l.onConferenceChanged(this, mConference);
3015 }
3016 }
3017
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003018 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003019 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003020 if (c instanceof Connection) {
3021 Connection connection = (Connection) c;
3022 connection.removeConnectionListener(mConnectionDeathListener);
3023 } else if (c instanceof Conference) {
3024 Conference conference = (Conference) c;
3025 conference.removeListener(mConferenceDeathListener);
3026 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003027 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003028 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003029 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003030
3031 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003032 * Handles a change to extras received from Telecom.
3033 *
3034 * @param extras The new extras.
3035 * @hide
3036 */
3037 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003038 Bundle b = null;
3039 synchronized (mExtrasLock) {
3040 mExtras = extras;
3041 if (mExtras != null) {
3042 b = new Bundle(mExtras);
3043 }
3044 }
3045 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003046 }
3047
3048 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003049 * Notifies listeners that the merge request failed.
3050 *
3051 * @hide
3052 */
3053 protected final void notifyConferenceMergeFailed() {
3054 for (Listener l : mListeners) {
3055 l.onConferenceMergeFailed(this);
3056 }
3057 }
3058
3059 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003060 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003061 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003062 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003063 * @hide
3064 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003065 protected final void updateConferenceParticipants(
3066 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003067 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003068 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003069 }
3070 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003071
3072 /**
3073 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003074 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003075 */
3076 protected void notifyConferenceStarted() {
3077 for (Listener l : mListeners) {
3078 l.onConferenceStarted();
3079 }
3080 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003081
3082 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003083 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3084 * be a part of a conference call.
3085 * @param isConferenceSupported {@code true} if the connection supports being part of a
3086 * conference call, {@code false} otherwise.
3087 * @hide
3088 */
3089 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3090 for (Listener l : mListeners) {
3091 l.onConferenceSupportedChanged(this, isConferenceSupported);
3092 }
3093 }
3094
3095 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303096 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3097 * changed due to an emergency call being redialed.
3098 * @param pHandle The new PhoneAccountHandle for this connection.
3099 * @hide
3100 */
3101 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3102 for (Listener l : mListeners) {
3103 l.onPhoneAccountChanged(this, pHandle);
3104 }
3105 }
3106
3107 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003108 * Sends an event associated with this {@code Connection} with associated event extras to the
3109 * {@link InCallService}.
3110 * <p>
3111 * Connection events are used to communicate point in time information from a
3112 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3113 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3114 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3115 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3116 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3117 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3118 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3119 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3120 * <p>
3121 * Events are exposed to {@link InCallService} implementations via
3122 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3123 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003124 * 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 -07003125 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3126 * some events altogether.
3127 * <p>
3128 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3129 * conflicts between {@link ConnectionService} implementations. Further, custom
3130 * {@link ConnectionService} implementations shall not re-purpose events in the
3131 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3132 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3133 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3134 * {@code com.example.extra.MY_EXTRA}).
3135 * <p>
3136 * When defining events and the associated extras, it is important to keep their behavior
3137 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3138 * events/extras should me maintained to ensure backwards compatibility with older
3139 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003140 *
3141 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003142 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003143 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003144 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003145 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003146 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003147 }
3148 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003149}