blob: ffb5e93f457c074177b8daff305bcb285d077ff9 [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
Tyler Gunn96d6c402015-03-18 12:39:23 -0700405 //**********************************************************************************************
Hall Liu95d55872017-01-25 17:12:49 -0800406 // Next PROPERTY value: 1<<9
Tyler Gunn96d6c402015-03-18 12:39:23 -0700407 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800408
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700409 /**
410 * Connection extra key used to store the last forwarded number associated with the current
411 * connection. Used to communicate to the user interface that the connection was forwarded via
412 * the specified number.
413 */
414 public static final String EXTRA_LAST_FORWARDED_NUMBER =
415 "android.telecom.extra.LAST_FORWARDED_NUMBER";
416
417 /**
418 * Connection extra key used to store a child number associated with the current connection.
419 * Used to communicate to the user interface that the connection was received via
420 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
421 * address.
422 */
423 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
424
425 /**
426 * Connection extra key used to store the subject for an incoming call. The user interface can
427 * query this extra and display its contents for incoming calls. Will only be used if the
428 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
429 */
430 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
431
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800432 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700433 * Boolean connection extra key set on a {@link Connection} in
434 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
435 * current active foreground call to be dropped.
436 */
437 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
438 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
439
440 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700441 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
442 * state to indicate the name of the third-party app which is responsible for the current
443 * foreground call.
444 * <p>
445 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
446 * is able to inform the user that answering the new incoming call will cause a call owned by
447 * another app to be dropped when the incoming call is answered.
448 */
449 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
450 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
451
452 /**
Hall Liu10208662016-06-15 17:55:00 -0700453 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700454 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700455 * @hide
456 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700457 public static final String EXTRA_DISABLE_ADD_CALL =
458 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700459
460 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700461 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
462 * original Connection ID associated with the connection. Used in
463 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
464 * connection/conference added via
465 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
466 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
467 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
468 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
469 * be a way to ensure that we don't add the connection again as a duplicate.
470 * <p>
471 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
472 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
473 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
474 * in a new {@link Connection} which it adds to Telecom via
475 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
476 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
477 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
478 * ID it originally referred to the connection as. Thus Telecom needs to know that the
479 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
480 * @hide
481 */
482 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
483 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
484
485 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800486 * Connection event used to inform Telecom that it should play the on hold tone. This is used
487 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700488 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800489 * @hide
490 */
491 public static final String EVENT_ON_HOLD_TONE_START =
492 "android.telecom.event.ON_HOLD_TONE_START";
493
494 /**
495 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
496 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700497 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800498 * @hide
499 */
500 public static final String EVENT_ON_HOLD_TONE_END =
501 "android.telecom.event.ON_HOLD_TONE_END";
502
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700503 /**
504 * Connection event used to inform {@link InCallService}s when pulling of an external call has
505 * failed. The user interface should inform the user of the error.
506 * <p>
507 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
508 * API is called on a {@link Call} with the properties
509 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
510 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
511 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700512 * <p>
513 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
514 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700515 */
516 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
517
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700518 /**
519 * Connection event used to inform {@link InCallService}s when the merging of two calls has
520 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700521 * <p>
522 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
523 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700524 */
525 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
526
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700527 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700528 * Connection event used to inform {@link InCallService}s when the process of merging a
529 * Connection into a conference has begun.
530 * <p>
531 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
532 * expected to be null when this connection event is used.
533 * @hide
534 */
535 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
536
537 /**
538 * Connection event used to inform {@link InCallService}s when the process of merging a
539 * Connection into a conference has completed.
540 * <p>
541 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
542 * expected to be null when this connection event is used.
543 * @hide
544 */
545 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
546
547 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700548 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
549 * the remote party.
550 * <p>
551 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
552 * call is being held locally on the device. When a capable {@link ConnectionService} receives
553 * signalling to indicate that the remote party has put the call on hold, it can send this
554 * connection event.
555 * @hide
556 */
557 public static final String EVENT_CALL_REMOTELY_HELD =
558 "android.telecom.event.CALL_REMOTELY_HELD";
559
560 /**
561 * Connection event used to inform {@link InCallService}s when a call which was remotely held
562 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
563 * <p>
564 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
565 * call is being held locally on the device. When a capable {@link ConnectionService} receives
566 * signalling to indicate that the remote party has taken the call off hold, it can send this
567 * connection event.
568 * @hide
569 */
570 public static final String EVENT_CALL_REMOTELY_UNHELD =
571 "android.telecom.event.CALL_REMOTELY_UNHELD";
572
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700573 /**
574 * Connection event used to inform an {@link InCallService} which initiated a call handover via
575 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
576 * successfully completed.
577 * @hide
578 */
579 public static final String EVENT_HANDOVER_COMPLETE =
580 "android.telecom.event.HANDOVER_COMPLETE";
581
582 /**
583 * Connection event used to inform an {@link InCallService} which initiated a call handover via
584 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
585 * to complete.
586 * @hide
587 */
588 public static final String EVENT_HANDOVER_FAILED =
589 "android.telecom.event.HANDOVER_FAILED";
590
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700591 // Flag controlling whether PII is emitted into the logs
592 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
593
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800594 /**
595 * Whether the given capabilities support the specified capability.
596 *
597 * @param capabilities A capability bit field.
598 * @param capability The capability to check capabilities for.
599 * @return Whether the specified capability is supported.
600 * @hide
601 */
602 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800603 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800604 }
605
606 /**
607 * Whether the capabilities of this {@code Connection} supports the specified capability.
608 *
609 * @param capability The capability to check capabilities for.
610 * @return Whether the specified capability is supported.
611 * @hide
612 */
613 public boolean can(int capability) {
614 return can(mConnectionCapabilities, capability);
615 }
616
617 /**
618 * Removes the specified capability from the set of capabilities of this {@code Connection}.
619 *
620 * @param capability The capability to remove from the set.
621 * @hide
622 */
623 public void removeCapability(int capability) {
624 mConnectionCapabilities &= ~capability;
625 }
626
627 /**
628 * Adds the specified capability to the set of capabilities of this {@code Connection}.
629 *
630 * @param capability The capability to add to the set.
631 * @hide
632 */
633 public void addCapability(int capability) {
634 mConnectionCapabilities |= capability;
635 }
636
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700637 /**
638 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
639 *
640 * @param capabilities A capability bit field.
641 * @return A human readable string representation.
642 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800643 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700644 return capabilitiesToStringInternal(capabilities, true /* isLong */);
645 }
646
647 /**
648 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
649 * string.
650 *
651 * @param capabilities A capability bit field.
652 * @return A human readable string representation.
653 * @hide
654 */
655 public static String capabilitiesToStringShort(int capabilities) {
656 return capabilitiesToStringInternal(capabilities, false /* isLong */);
657 }
658
659 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800660 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700661 builder.append("[");
662 if (isLong) {
663 builder.append("Capabilities:");
664 }
665
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800666 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800668 }
669 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700670 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800671 }
672 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700673 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 }
675 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
684 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800686 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700687 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700689 }
690 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700692 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700693 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800695 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 }
699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700701 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700702 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800704 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800705 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800707 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500708 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500710 }
Rekha Kumar07366812015-03-24 16:42:31 -0700711 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700713 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700714 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700716 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700717 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700719 }
Bryce Lee81901682015-08-28 16:38:02 -0700720 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700722 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700723 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700725 }
Bryce Lee81901682015-08-28 16:38:02 -0700726
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800727 builder.append("]");
728 return builder.toString();
729 }
730
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700731 /**
732 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
733 *
734 * @param properties A property bit field.
735 * @return A human readable string representation.
736 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700737 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700738 return propertiesToStringInternal(properties, true /* isLong */);
739 }
740
741 /**
742 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
743 *
744 * @param properties A property bit field.
745 * @return A human readable string representation.
746 * @hide
747 */
748 public static String propertiesToStringShort(int properties) {
749 return propertiesToStringInternal(properties, false /* isLong */);
750 }
751
752 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700753 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700754 builder.append("[");
755 if (isLong) {
756 builder.append("Properties:");
757 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700758
Tyler Gunnf5035432017-01-09 09:43:12 -0800759 if (can(properties, PROPERTY_SELF_MANAGED)) {
760 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
761 }
762
Hall Liu25c7c4d2016-08-30 13:41:02 -0700763 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
764 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700765 }
766
767 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700768 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700769 }
770
771 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700772 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700773 }
774
775 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700776 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700777 }
778
779 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700780 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700781 }
782
Brad Ebinger15847072016-05-18 11:08:36 -0700783 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700784 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700785 }
786
Tyler Gunn720c6642016-03-22 09:02:47 -0700787 builder.append("]");
788 return builder.toString();
789 }
790
Sailesh Nepal091768c2014-06-30 15:15:23 -0700791 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700792 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700793 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700794 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700795 public void onCallerDisplayNameChanged(
796 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700797 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700798 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700799 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800800 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700801 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700802 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800803 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700804 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800805 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 public void onVideoProviderChanged(
807 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700808 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
809 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800810 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700811 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700812 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700813 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800814 public void onConferenceParticipantsChanged(Connection c,
815 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800816 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700817 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700818 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700819 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700820 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700821 /** @hide */
822 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800823 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800824 public void onRttInitiationSuccess(Connection c) {}
825 public void onRttInitiationFailure(Connection c, int reason) {}
826 public void onRttSessionRemotelyTerminated(Connection c) {}
827 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530828 /** @hide */
829 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700830 }
831
Tyler Gunnb702ef82015-05-29 11:51:53 -0700832 /**
Hall Liu95d55872017-01-25 17:12:49 -0800833 * Provides methods to read and write RTT data to/from the in-call app.
834 * @hide
835 */
Hall Liuffa4a812017-03-02 16:11:00 -0800836 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800837 public static final class RttTextStream {
838 private static final int READ_BUFFER_SIZE = 1000;
839 private final InputStreamReader mPipeFromInCall;
840 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800841 private final ParcelFileDescriptor mFdFromInCall;
842 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800843 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
844
845 /**
846 * @hide
847 */
848 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800849 mFdFromInCall = fromInCall;
850 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800851 mPipeFromInCall = new InputStreamReader(
852 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
853 mPipeToInCall = new OutputStreamWriter(
854 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
855 }
856
857 /**
858 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
859 * RTT transmits text in real-time, this method should be called as often as text snippets
860 * are received from the remote user, even if it is only one character.
861 *
862 * This method is not thread-safe -- calling it from multiple threads simultaneously may
863 * lead to interleaved text.
864 * @param input The message to send to the in-call app.
865 */
866 public void write(String input) throws IOException {
867 mPipeToInCall.write(input);
868 mPipeToInCall.flush();
869 }
870
871
872 /**
873 * Reads a string from the in-call app, blocking if there is no data available. Returns
874 * {@code null} if the RTT conversation has been terminated and there is no further data
875 * to read.
876 *
877 * This method is not thread-safe -- calling it from multiple threads simultaneously may
878 * lead to interleaved text.
879 * @return A string containing text entered by the user, or {@code null} if the
880 * conversation has been terminated or if there was an error while reading.
881 */
Hall Liuffa4a812017-03-02 16:11:00 -0800882 public String read() throws IOException {
883 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
884 if (numRead < 0) {
885 return null;
886 }
887 return new String(mReadBuffer, 0, numRead);
888 }
889
890 /**
891 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
892 * be read.
893 * @return A string containing text entered by the user, or {@code null} if the user has
894 * not entered any new text yet.
895 */
896 public String readImmediately() throws IOException {
897 if (mPipeFromInCall.ready()) {
898 return read();
899 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800900 return null;
901 }
902 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800903
904 /** @hide */
905 public ParcelFileDescriptor getFdFromInCall() {
906 return mFdFromInCall;
907 }
908
909 /** @hide */
910 public ParcelFileDescriptor getFdToInCall() {
911 return mFdToInCall;
912 }
913 }
914
915 /**
916 * Provides constants to represent the results of responses to session modify requests sent via
917 * {@link Call#sendRttRequest()}
918 */
919 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700920 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800921 /**
922 * Session modify request was successful.
923 */
924 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
925
926 /**
927 * Session modify request failed.
928 */
929 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
930
931 /**
932 * Session modify request ignored due to invalid parameters.
933 */
934 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
935
936 /**
937 * Session modify request timed out.
938 */
939 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
940
941 /**
942 * Session modify request rejected by remote user.
943 */
944 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800945 }
946
947 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * Provides a means of controlling the video session associated with a {@link Connection}.
949 * <p>
950 * Implementations create a custom subclass of {@link VideoProvider} and the
951 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
952 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
953 * should set the {@link VideoProvider}.
954 * <p>
955 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
956 * {@link InCallService} implementations to issue requests related to the video session;
957 * it provides a means for the {@link ConnectionService} to report events and information
958 * related to the video session to Telecom and the {@link InCallService} implementations.
959 * <p>
960 * {@link InCallService} implementations interact with the {@link VideoProvider} via
961 * {@link android.telecom.InCallService.VideoCall}.
962 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 /**
965 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700966 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 */
968 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700969
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700971 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
972 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700973 */
974 public static final int SESSION_EVENT_RX_RESUME = 2;
975
976 /**
977 * Video transmission has begun. This occurs after a negotiated start of video transmission
978 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700979 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 */
981 public static final int SESSION_EVENT_TX_START = 3;
982
983 /**
984 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
985 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 */
988 public static final int SESSION_EVENT_TX_STOP = 4;
989
990 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800991 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700992 * this as a cue to inform the user the camera is not available.
993 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700994 */
995 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
996
997 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700998 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800999 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001000 * the camera has become available again.
1001 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 */
1003 public static final int SESSION_EVENT_CAMERA_READY = 6;
1004
1005 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001006 * Session event raised by Telecom when
1007 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1008 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1009 * @see #handleCallSessionEvent(int)
1010 */
1011 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1012
1013 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 */
1017 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1018
1019 /**
1020 * Session modify request failed.
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_FAIL = 2;
1024
1025 /**
1026 * Session modify request ignored due to invalid parameters.
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_INVALID = 3;
1030
Rekha Kumar07366812015-03-24 16:42:31 -07001031 /**
1032 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001034 */
1035 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1036
1037 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001038 * Session modify request rejected by remote user.
1039 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001040 */
1041 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1042
Tyler Gunn75958422015-04-15 14:23:42 -07001043 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 private static final int MSG_SET_CAMERA = 2;
1045 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1046 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1047 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1048 private static final int MSG_SET_ZOOM = 6;
1049 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1050 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1051 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001052 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001053 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001054 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001055
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001056 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1057 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1058 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1059 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1060 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1061 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001062 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1063 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001064 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1065
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001066 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001067 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001068
1069 /**
1070 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001071 *
1072 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1073 * load factor before resizing, 1 means we only expect a single thread to
1074 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001075 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001076 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1077 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078
1079 /**
1080 * Default handler used to consolidate binder method calls onto a single thread.
1081 */
1082 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001083 public VideoProviderHandler() {
1084 super();
1085 }
1086
1087 public VideoProviderHandler(Looper looper) {
1088 super(looper);
1089 }
1090
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001091 @Override
1092 public void handleMessage(Message msg) {
1093 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001094 case MSG_ADD_VIDEO_CALLBACK: {
1095 IBinder binder = (IBinder) msg.obj;
1096 IVideoCallback callback = IVideoCallback.Stub
1097 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001098 if (callback == null) {
1099 Log.w(this, "addVideoProvider - skipped; callback is null.");
1100 break;
1101 }
1102
Tyler Gunn75958422015-04-15 14:23:42 -07001103 if (mVideoCallbacks.containsKey(binder)) {
1104 Log.i(this, "addVideoProvider - skipped; already present.");
1105 break;
1106 }
1107 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001109 }
1110 case MSG_REMOVE_VIDEO_CALLBACK: {
1111 IBinder binder = (IBinder) msg.obj;
1112 IVideoCallback callback = IVideoCallback.Stub
1113 .asInterface((IBinder) msg.obj);
1114 if (!mVideoCallbacks.containsKey(binder)) {
1115 Log.i(this, "removeVideoProvider - skipped; not present.");
1116 break;
1117 }
1118 mVideoCallbacks.remove(binder);
1119 break;
1120 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001122 {
1123 SomeArgs args = (SomeArgs) msg.obj;
1124 try {
1125 onSetCamera((String) args.arg1);
1126 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001127 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001128 } finally {
1129 args.recycle();
1130 }
1131 }
1132 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 case MSG_SET_PREVIEW_SURFACE:
1134 onSetPreviewSurface((Surface) msg.obj);
1135 break;
1136 case MSG_SET_DISPLAY_SURFACE:
1137 onSetDisplaySurface((Surface) msg.obj);
1138 break;
1139 case MSG_SET_DEVICE_ORIENTATION:
1140 onSetDeviceOrientation(msg.arg1);
1141 break;
1142 case MSG_SET_ZOOM:
1143 onSetZoom((Float) msg.obj);
1144 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001145 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1146 SomeArgs args = (SomeArgs) msg.obj;
1147 try {
1148 onSendSessionModifyRequest((VideoProfile) args.arg1,
1149 (VideoProfile) args.arg2);
1150 } finally {
1151 args.recycle();
1152 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001154 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001155 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1156 onSendSessionModifyResponse((VideoProfile) msg.obj);
1157 break;
1158 case MSG_REQUEST_CAMERA_CAPABILITIES:
1159 onRequestCameraCapabilities();
1160 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001161 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1162 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 break;
1164 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001165 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 break;
1167 default:
1168 break;
1169 }
1170 }
1171 }
1172
1173 /**
1174 * IVideoProvider stub implementation.
1175 */
1176 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001177 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001178 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001179 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1180 }
1181
1182 public void removeVideoCallback(IBinder videoCallbackBinder) {
1183 mMessageHandler.obtainMessage(
1184 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001185 }
1186
Tyler Gunn159f35c2017-03-02 09:28:37 -08001187 public void setCamera(String cameraId, String callingPackageName,
1188 int targetSdkVersion) {
1189
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001190 SomeArgs args = SomeArgs.obtain();
1191 args.arg1 = cameraId;
1192 // Propagate the calling package; originally determined in
1193 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1194 // process.
1195 args.arg2 = callingPackageName;
1196 // Pass along the uid and pid of the calling app; this gets lost when we put the
1197 // message onto the handler. These are required for Telecom to perform a permission
1198 // check to see if the calling app is able to use the camera.
1199 args.argi1 = Binder.getCallingUid();
1200 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001201 // Pass along the target SDK version of the calling InCallService. This is used to
1202 // maintain backwards compatibility of the API for older callers.
1203 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001204 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001205 }
1206
1207 public void setPreviewSurface(Surface surface) {
1208 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1209 }
1210
1211 public void setDisplaySurface(Surface surface) {
1212 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1213 }
1214
1215 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001216 mMessageHandler.obtainMessage(
1217 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001218 }
1219
1220 public void setZoom(float value) {
1221 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1222 }
1223
Tyler Gunn45382162015-05-06 08:52:27 -07001224 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1225 SomeArgs args = SomeArgs.obtain();
1226 args.arg1 = fromProfile;
1227 args.arg2 = toProfile;
1228 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001229 }
1230
1231 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1232 mMessageHandler.obtainMessage(
1233 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1234 }
1235
1236 public void requestCameraCapabilities() {
1237 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1238 }
1239
1240 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001241 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001242 }
1243
Yorke Lee32f24732015-05-12 16:18:03 -07001244 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001245 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1246 }
1247 }
1248
1249 public VideoProvider() {
1250 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001251 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001252 }
1253
1254 /**
1255 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1256 *
1257 * @param looper The looper.
1258 * @hide
1259 */
1260 public VideoProvider(Looper looper) {
1261 mBinder = new VideoProvider.VideoProviderBinder();
1262 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001263 }
1264
1265 /**
1266 * Returns binder object which can be used across IPC methods.
1267 * @hide
1268 */
1269 public final IVideoProvider getInterface() {
1270 return mBinder;
1271 }
1272
1273 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001274 * Sets the camera to be used for the outgoing video.
1275 * <p>
1276 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1277 * camera via
1278 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1279 * <p>
1280 * Sent from the {@link InCallService} via
1281 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001282 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001283 * @param cameraId The id of the camera (use ids as reported by
1284 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001285 */
1286 public abstract void onSetCamera(String cameraId);
1287
1288 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001289 * Sets the camera to be used for the outgoing video.
1290 * <p>
1291 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1292 * camera via
1293 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1294 * <p>
1295 * This prototype is used internally to ensure that the calling package name, UID and PID
1296 * are sent to Telecom so that can perform a camera permission check on the caller.
1297 * <p>
1298 * Sent from the {@link InCallService} via
1299 * {@link InCallService.VideoCall#setCamera(String)}.
1300 *
1301 * @param cameraId The id of the camera (use ids as reported by
1302 * {@link CameraManager#getCameraIdList()}).
1303 * @param callingPackageName The AppOpps package name of the caller.
1304 * @param callingUid The UID of the caller.
1305 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001306 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001307 * @hide
1308 */
1309 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001310 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001311
1312 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 * Sets the surface to be used for displaying a preview of what the user's camera is
1314 * currently capturing. When video transmission is enabled, this is the video signal which
1315 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001316 * <p>
1317 * Sent from the {@link InCallService} via
1318 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001320 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 */
1322 public abstract void onSetPreviewSurface(Surface surface);
1323
1324 /**
1325 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001326 * <p>
1327 * Sent from the {@link InCallService} via
1328 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001329 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001330 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 */
1332 public abstract void onSetDisplaySurface(Surface surface);
1333
1334 /**
1335 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1336 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001337 * <p>
1338 * Sent from the {@link InCallService} via
1339 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001340 *
1341 * @param rotation The device orientation, in degrees.
1342 */
1343 public abstract void onSetDeviceOrientation(int rotation);
1344
1345 /**
1346 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001347 * <p>
1348 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 *
1350 * @param value The camera zoom ratio.
1351 */
1352 public abstract void onSetZoom(float value);
1353
1354 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001355 * Issues a request to modify the properties of the current video session.
1356 * <p>
1357 * Example scenarios include: requesting an audio-only call to be upgraded to a
1358 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1359 * when the {@link InCallService} is no longer the foreground application.
1360 * <p>
1361 * If the {@link VideoProvider} determines a request to be invalid, it should call
1362 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1363 * invalid request back to the {@link InCallService}.
1364 * <p>
1365 * Where a request requires confirmation from the user of the peer device, the
1366 * {@link VideoProvider} must communicate the request to the peer device and handle the
1367 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1368 * is used to inform the {@link InCallService} of the result of the request.
1369 * <p>
1370 * Sent from the {@link InCallService} via
1371 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001373 * @param fromProfile The video profile prior to the request.
1374 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001375 */
Tyler Gunn45382162015-05-06 08:52:27 -07001376 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1377 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378
Tyler Gunnb702ef82015-05-29 11:51:53 -07001379 /**
1380 * Provides a response to a request to change the current video session properties.
1381 * <p>
1382 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1383 * video call, could decline the request and keep the call as audio-only.
1384 * In such a scenario, the {@code responseProfile} would have a video state of
1385 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1386 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1387 * <p>
1388 * Sent from the {@link InCallService} via
1389 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1390 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1391 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001393 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 */
1395 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1396
1397 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001398 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1399 * <p>
1400 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1401 * camera via
1402 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1403 * <p>
1404 * Sent from the {@link InCallService} via
1405 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 */
1407 public abstract void onRequestCameraCapabilities();
1408
1409 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001410 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1411 * video component of the current {@link Connection}.
1412 * <p>
1413 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1414 * via {@link VideoProvider#setCallDataUsage(long)}.
1415 * <p>
1416 * Sent from the {@link InCallService} via
1417 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001419 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420
1421 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001422 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1423 * the peer device when the video signal is paused.
1424 * <p>
1425 * Sent from the {@link InCallService} via
1426 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 *
1428 * @param uri URI of image to display.
1429 */
Yorke Lee32f24732015-05-12 16:18:03 -07001430 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431
1432 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001433 * Used to inform listening {@link InCallService} implementations when the
1434 * {@link VideoProvider} receives a session modification request.
1435 * <p>
1436 * Received by the {@link InCallService} via
1437 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001439 * @param videoProfile The requested video profile.
1440 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 */
1442 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001443 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001444 for (IVideoCallback callback : mVideoCallbacks.values()) {
1445 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001446 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001447 } catch (RemoteException ignored) {
1448 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001449 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 }
1451 }
1452 }
1453
1454 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001455 * Used to inform listening {@link InCallService} implementations when the
1456 * {@link VideoProvider} receives a response to a session modification request.
1457 * <p>
1458 * Received by the {@link InCallService} via
1459 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1460 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 *
1462 * @param status Status of the session modify request. Valid values are
1463 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1464 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001465 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1466 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1467 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1468 * @param requestedProfile The original request which was sent to the peer device.
1469 * @param responseProfile The actual profile changes agreed to by the peer device.
1470 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 */
1472 public void receiveSessionModifyResponse(int status,
1473 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001474 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001475 for (IVideoCallback callback : mVideoCallbacks.values()) {
1476 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001477 callback.receiveSessionModifyResponse(status, requestedProfile,
1478 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001479 } catch (RemoteException ignored) {
1480 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001481 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 }
1483 }
1484 }
1485
1486 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001487 * Used to inform listening {@link InCallService} implementations when the
1488 * {@link VideoProvider} reports a call session event.
1489 * <p>
1490 * Received by the {@link InCallService} via
1491 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001493 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1494 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1495 * {@link VideoProvider#SESSION_EVENT_TX_START},
1496 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1497 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001498 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1499 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 */
1501 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001502 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001503 for (IVideoCallback callback : mVideoCallbacks.values()) {
1504 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001505 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001506 } catch (RemoteException ignored) {
1507 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001508 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 }
1510 }
1511 }
1512
1513 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001514 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1515 * peer's video have changed.
1516 * <p>
1517 * This could occur if, for example, the peer rotates their device, changing the aspect
1518 * ratio of the video, or if the user switches between the back and front cameras.
1519 * <p>
1520 * Received by the {@link InCallService} via
1521 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 *
1523 * @param width The updated peer video width.
1524 * @param height The updated peer video height.
1525 */
1526 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001527 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001528 for (IVideoCallback callback : mVideoCallbacks.values()) {
1529 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001530 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001531 } catch (RemoteException ignored) {
1532 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001533 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001534 }
1535 }
1536 }
1537
1538 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001539 * Used to inform listening {@link InCallService} implementations when the data usage of the
1540 * video associated with the current {@link Connection} has changed.
1541 * <p>
1542 * This could be in response to a preview request via
1543 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001544 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1545 * 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 -07001546 * <p>
1547 * Received by the {@link InCallService} via
1548 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001549 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001550 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1551 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001552 */
Yorke Lee32f24732015-05-12 16:18:03 -07001553 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001554 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001555 for (IVideoCallback callback : mVideoCallbacks.values()) {
1556 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001557 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001558 } catch (RemoteException ignored) {
1559 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001560 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001561 }
1562 }
1563 }
1564
1565 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001566 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001568 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001569 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1570 * @hide
1571 */
1572 public void changeCallDataUsage(long dataUsage) {
1573 setCallDataUsage(dataUsage);
1574 }
1575
1576 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001577 * Used to inform listening {@link InCallService} implementations when the capabilities of
1578 * the current camera have changed.
1579 * <p>
1580 * The {@link VideoProvider} should call this in response to
1581 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1582 * changed via {@link VideoProvider#onSetCamera(String)}.
1583 * <p>
1584 * Received by the {@link InCallService} via
1585 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1586 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001587 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001588 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 */
Yorke Lee400470f2015-05-12 13:31:25 -07001590 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001591 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001592 for (IVideoCallback callback : mVideoCallbacks.values()) {
1593 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001594 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001595 } catch (RemoteException ignored) {
1596 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001597 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001598 }
1599 }
1600 }
Rekha Kumar07366812015-03-24 16:42:31 -07001601
1602 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001603 * Used to inform listening {@link InCallService} implementations when the video quality
1604 * of the call has changed.
1605 * <p>
1606 * Received by the {@link InCallService} via
1607 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001608 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001609 * @param videoQuality The updated video quality. Valid values:
1610 * {@link VideoProfile#QUALITY_HIGH},
1611 * {@link VideoProfile#QUALITY_MEDIUM},
1612 * {@link VideoProfile#QUALITY_LOW},
1613 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001614 */
1615 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001616 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001617 for (IVideoCallback callback : mVideoCallbacks.values()) {
1618 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001619 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001620 } catch (RemoteException ignored) {
1621 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001622 }
Rekha Kumar07366812015-03-24 16:42:31 -07001623 }
1624 }
1625 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001626
1627 /**
1628 * Returns a string representation of a call session event.
1629 *
1630 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1631 * @return String representation of the call session event.
1632 * @hide
1633 */
1634 public static String sessionEventToString(int event) {
1635 switch (event) {
1636 case SESSION_EVENT_CAMERA_FAILURE:
1637 return SESSION_EVENT_CAMERA_FAILURE_STR;
1638 case SESSION_EVENT_CAMERA_READY:
1639 return SESSION_EVENT_CAMERA_READY_STR;
1640 case SESSION_EVENT_RX_PAUSE:
1641 return SESSION_EVENT_RX_PAUSE_STR;
1642 case SESSION_EVENT_RX_RESUME:
1643 return SESSION_EVENT_RX_RESUME_STR;
1644 case SESSION_EVENT_TX_START:
1645 return SESSION_EVENT_TX_START_STR;
1646 case SESSION_EVENT_TX_STOP:
1647 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001648 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1649 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001650 default:
1651 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1652 }
1653 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001654 }
1655
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001656 private final Listener mConnectionDeathListener = new Listener() {
1657 @Override
1658 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001659 if (mConferenceables.remove(c)) {
1660 fireOnConferenceableConnectionsChanged();
1661 }
1662 }
1663 };
1664
1665 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1666 @Override
1667 public void onDestroyed(Conference c) {
1668 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001669 fireOnConferenceableConnectionsChanged();
1670 }
1671 }
1672 };
1673
Jay Shrauner229e3822014-08-15 09:23:07 -07001674 /**
1675 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1676 * load factor before resizing, 1 means we only expect a single thread to
1677 * access the map so make only a single shard
1678 */
1679 private final Set<Listener> mListeners = Collections.newSetFromMap(
1680 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001681 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1682 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001683 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001684
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001685 // The internal telecom call ID associated with this connection.
1686 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001688 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001689 private Uri mAddress;
1690 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001691 private String mCallerDisplayName;
1692 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001693 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001694 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001695 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001696 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001697 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001698 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001699 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001700 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001701 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001702 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001703 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001704 private Conference mConference;
1705 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001706 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001707 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001708
1709 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001710 * Tracks the key set for the extras bundle provided on the last invocation of
1711 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1712 * keys which were set previously but are no longer present in the replacement Bundle.
1713 */
1714 private Set<String> mPreviousExtraKeys;
1715
1716 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001717 * Create a new Connection.
1718 */
Santos Cordonf2951102014-07-20 19:06:29 -07001719 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001720
1721 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001722 * Returns the Telecom internal call ID associated with this connection. Should only be used
1723 * for debugging and tracing purposes.
1724 *
1725 * @return The Telecom call ID.
1726 * @hide
1727 */
1728 public final String getTelecomCallId() {
1729 return mTelecomCallId;
1730 }
1731
1732 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001733 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001734 */
Andrew Lee100e2932014-09-08 15:34:24 -07001735 public final Uri getAddress() {
1736 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001737 }
1738
1739 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001740 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001741 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001742 */
Andrew Lee100e2932014-09-08 15:34:24 -07001743 public final int getAddressPresentation() {
1744 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001745 }
1746
1747 /**
1748 * @return The caller display name (CNAP).
1749 */
1750 public final String getCallerDisplayName() {
1751 return mCallerDisplayName;
1752 }
1753
1754 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001755 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001756 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001757 */
1758 public final int getCallerDisplayNamePresentation() {
1759 return mCallerDisplayNamePresentation;
1760 }
1761
1762 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001763 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001764 */
1765 public final int getState() {
1766 return mState;
1767 }
1768
1769 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001770 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001771 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1772 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1773 * {@link VideoProfile#STATE_TX_ENABLED},
1774 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001775 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001776 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001777 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001778 */
1779 public final int getVideoState() {
1780 return mVideoState;
1781 }
1782
1783 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001784 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001785 * being routed by the system. This is {@code null} if this Connection
1786 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001787 * @deprecated Use {@link #getCallAudioState()} instead.
1788 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001789 */
Yorke Lee4af59352015-05-13 14:14:54 -07001790 @SystemApi
1791 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001792 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001793 if (mCallAudioState == null) {
1794 return null;
1795 }
Yorke Lee4af59352015-05-13 14:14:54 -07001796 return new AudioState(mCallAudioState);
1797 }
1798
1799 /**
1800 * @return The audio state of the connection, describing how its audio is currently
1801 * being routed by the system. This is {@code null} if this Connection
1802 * does not directly know about its audio state.
1803 */
1804 public final CallAudioState getCallAudioState() {
1805 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001806 }
1807
1808 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001809 * @return The conference that this connection is a part of. Null if it is not part of any
1810 * conference.
1811 */
1812 public final Conference getConference() {
1813 return mConference;
1814 }
1815
1816 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001817 * Returns whether this connection is requesting that the system play a ringback tone
1818 * on its behalf.
1819 */
Andrew Lee100e2932014-09-08 15:34:24 -07001820 public final boolean isRingbackRequested() {
1821 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001822 }
1823
1824 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001825 * @return True if the connection's audio mode is VOIP.
1826 */
1827 public final boolean getAudioModeIsVoip() {
1828 return mAudioModeIsVoip;
1829 }
1830
1831 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001832 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1833 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1834 * start time of the conference.
1835 *
1836 * @return The time at which the {@code Connnection} was connected.
1837 *
1838 * @hide
1839 */
1840 public final long getConnectTimeMillis() {
1841 return mConnectTimeMillis;
1842 }
1843
1844 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001845 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1846 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1847 * start time of the conference.
1848 *
1849 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1850 * changes do not impact the call duration.
1851 *
1852 * @return The time at which the {@link Connection} was connected.
1853 *
1854 * @hide
1855 */
1856 public final long getConnectElapsedTimeMillis() {
1857 return mConnectElapsedTimeMillis;
1858 }
1859
1860 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001861 * @return The status hints for this connection.
1862 */
1863 public final StatusHints getStatusHints() {
1864 return mStatusHints;
1865 }
1866
1867 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001868 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001869 * <p>
1870 * Extras should be updated using {@link #putExtras(Bundle)}.
1871 * <p>
1872 * Telecom or an {@link InCallService} can also update the extras via
1873 * {@link android.telecom.Call#putExtras(Bundle)}, and
1874 * {@link Call#removeExtras(List)}.
1875 * <p>
1876 * The connection is notified of changes to the extras made by Telecom or an
1877 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001878 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001879 * @return The extras associated with this connection.
1880 */
1881 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001882 Bundle extras = null;
1883 synchronized (mExtrasLock) {
1884 if (mExtras != null) {
1885 extras = new Bundle(mExtras);
1886 }
1887 }
1888 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001889 }
1890
1891 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001892 * Assign a listener to be notified of state changes.
1893 *
1894 * @param l A listener.
1895 * @return This Connection.
1896 *
1897 * @hide
1898 */
1899 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001900 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001901 return this;
1902 }
1903
1904 /**
1905 * Remove a previously assigned listener that was being notified of state changes.
1906 *
1907 * @param l A Listener.
1908 * @return This Connection.
1909 *
1910 * @hide
1911 */
1912 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001913 if (l != null) {
1914 mListeners.remove(l);
1915 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001916 return this;
1917 }
1918
1919 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001920 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001921 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001922 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001923 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001924 }
1925
1926 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001927 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1928 * ONLY for debugging purposes.
1929 *
1930 * @param callId The telecom call ID.
1931 * @hide
1932 */
1933 public void setTelecomCallId(String callId) {
1934 mTelecomCallId = callId;
1935 }
1936
1937 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001938 * Inform this Connection that the state of its audio output has been changed externally.
1939 *
1940 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001941 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001942 */
Yorke Lee4af59352015-05-13 14:14:54 -07001943 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001944 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001945 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001946 mCallAudioState = state;
1947 onAudioStateChanged(getAudioState());
1948 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001949 }
1950
1951 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001952 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001953 * @return A string representation of the value.
1954 */
1955 public static String stateToString(int state) {
1956 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001957 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001958 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001959 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001960 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001961 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001962 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001963 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001964 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001965 case STATE_PULLING_CALL:
1966 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001967 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001968 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001969 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001970 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001971 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001972 return "DISCONNECTED";
1973 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001974 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001975 return "UNKNOWN";
1976 }
1977 }
1978
1979 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001980 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001981 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001982 public final int getConnectionCapabilities() {
1983 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001984 }
1985
1986 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001987 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1988 */
1989 public final int getConnectionProperties() {
1990 return mConnectionProperties;
1991 }
1992
1993 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001994 * Returns the connection's supported audio routes.
1995 *
1996 * @hide
1997 */
1998 public final int getSupportedAudioRoutes() {
1999 return mSupportedAudioRoutes;
2000 }
2001
2002 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002003 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 *
Andrew Lee100e2932014-09-08 15:34:24 -07002005 * @param address The new address.
2006 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002007 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002008 */
Andrew Lee100e2932014-09-08 15:34:24 -07002009 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002010 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002011 Log.d(this, "setAddress %s", address);
2012 mAddress = address;
2013 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002014 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002015 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002016 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002017 }
2018
2019 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002020 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002021 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002022 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002023 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002024 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002025 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002026 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002027 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002028 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002029 mCallerDisplayName = callerDisplayName;
2030 mCallerDisplayNamePresentation = presentation;
2031 for (Listener l : mListeners) {
2032 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2033 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002034 }
2035
2036 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002037 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002038 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2039 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2040 * {@link VideoProfile#STATE_TX_ENABLED},
2041 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002042 *
2043 * @param videoState The new video state.
2044 */
2045 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002046 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002047 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002048 mVideoState = videoState;
2049 for (Listener l : mListeners) {
2050 l.onVideoStateChanged(this, mVideoState);
2051 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002052 }
2053
2054 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002055 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002056 * communicate).
2057 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002058 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002059 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002060 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002061 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002062 }
2063
2064 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002065 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002066 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002067 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002068 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002069 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002070 }
2071
2072 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002073 * Sets state to initializing (this Connection is not yet ready to be used).
2074 */
2075 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002076 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002077 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002078 }
2079
2080 /**
2081 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2082 */
2083 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002084 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002085 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002086 }
2087
2088 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002090 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002091 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002092 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002093 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 }
2095
2096 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002097 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2098 * device). Only applicable for {@link Connection}s with
2099 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2100 */
2101 public final void setPulling() {
2102 checkImmutable();
2103 setState(STATE_PULLING_CALL);
2104 }
2105
2106 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 * Sets state to be on hold.
2108 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002109 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002110 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002111 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002112 }
2113
2114 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002115 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002116 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002117 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002118 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002119 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002120 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002121 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002122 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002123 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002124 }
2125
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002126 public final VideoProvider getVideoProvider() {
2127 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002128 }
2129
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002130 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002131 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002132 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002133 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002134 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002136 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002137 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002138 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002139 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002140 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002141 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002142 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002143 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002144 }
2145
2146 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002147 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2148 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2149 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2150 * to send an {@link #onPostDialContinue(boolean)} signal.
2151 *
2152 * @param remaining The DTMF character sequence remaining to be emitted once the
2153 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2154 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002155 */
2156 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002157 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002158 for (Listener l : mListeners) {
2159 l.onPostDialWait(this, remaining);
2160 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002161 }
2162
2163 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002164 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2165 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002166 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002167 *
2168 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002169 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002170 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002171 checkImmutable();
2172 for (Listener l : mListeners) {
2173 l.onPostDialChar(this, nextChar);
2174 }
2175 }
2176
2177 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002178 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002179 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002180 *
2181 * @param ringback Whether the ringback tone is to be played.
2182 */
Andrew Lee100e2932014-09-08 15:34:24 -07002183 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002184 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002185 if (mRingbackRequested != ringback) {
2186 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002187 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002188 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002189 }
2190 }
Ihab Awadf8358972014-05-28 16:46:42 -07002191 }
2192
2193 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002194 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002195 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002196 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002197 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002198 public final void setConnectionCapabilities(int connectionCapabilities) {
2199 checkImmutable();
2200 if (mConnectionCapabilities != connectionCapabilities) {
2201 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002202 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002203 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002204 }
2205 }
Santos Cordonb6939982014-06-04 20:20:58 -07002206 }
2207
2208 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002209 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2210 *
2211 * @param connectionProperties The new connection properties.
2212 */
2213 public final void setConnectionProperties(int connectionProperties) {
2214 checkImmutable();
2215 if (mConnectionProperties != connectionProperties) {
2216 mConnectionProperties = connectionProperties;
2217 for (Listener l : mListeners) {
2218 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2219 }
2220 }
2221 }
2222
2223 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002224 * Sets the supported audio routes.
2225 *
2226 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2227 * See {@link CallAudioState}
2228 * @hide
2229 */
2230 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2231 if ((supportedAudioRoutes
2232 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2233 throw new IllegalArgumentException(
2234 "supported audio routes must include either speaker or earpiece");
2235 }
2236
2237 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2238 mSupportedAudioRoutes = supportedAudioRoutes;
2239 for (Listener l : mListeners) {
2240 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2241 }
2242 }
2243 }
2244
2245 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002246 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002247 */
Evan Charlton36a71342014-07-19 16:31:02 -07002248 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002249 for (Listener l : mListeners) {
2250 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002251 }
Santos Cordonb6939982014-06-04 20:20:58 -07002252 }
2253
2254 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002255 * Requests that the framework use VOIP audio mode for this connection.
2256 *
2257 * @param isVoip True if the audio mode is VOIP.
2258 */
2259 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002260 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002261 mAudioModeIsVoip = isVoip;
2262 for (Listener l : mListeners) {
2263 l.onAudioModeIsVoipChanged(this, isVoip);
2264 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002265 }
2266
2267 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002268 * Sets the time at which a call became active on this Connection. This is set only
2269 * when a conference call becomes active on this connection.
2270 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002271 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2272 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002273 *
2274 * @hide
2275 */
2276 public final void setConnectTimeMillis(long connectTimeMillis) {
2277 mConnectTimeMillis = connectTimeMillis;
2278 }
2279
2280 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002281 * Sets the time at which a call became active on this Connection. This is set only
2282 * when a conference call becomes active on this connection.
2283 *
2284 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2285 * {@link SystemClock#elapsedRealtime()}.
2286 *
2287 * @hide
2288 */
2289 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2290 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2291 }
2292
2293 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002294 * Sets the label and icon status to display in the in-call UI.
2295 *
2296 * @param statusHints The status label and icon to set.
2297 */
2298 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002299 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002300 mStatusHints = statusHints;
2301 for (Listener l : mListeners) {
2302 l.onStatusHintsChanged(this, statusHints);
2303 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002304 }
2305
2306 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002307 * Sets the connections with which this connection can be conferenced.
2308 *
2309 * @param conferenceableConnections The set of connections this connection can conference with.
2310 */
2311 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002312 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002313 clearConferenceableList();
2314 for (Connection c : conferenceableConnections) {
2315 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2316 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002317 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002318 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002319 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002320 }
2321 }
2322 fireOnConferenceableConnectionsChanged();
2323 }
2324
2325 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002326 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2327 * or conferences with which this connection can be conferenced.
2328 *
2329 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002330 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002331 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002332 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002333 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002334 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2335 // small amount of items here.
2336 if (!mConferenceables.contains(c)) {
2337 if (c instanceof Connection) {
2338 Connection connection = (Connection) c;
2339 connection.addConnectionListener(mConnectionDeathListener);
2340 } else if (c instanceof Conference) {
2341 Conference conference = (Conference) c;
2342 conference.addListener(mConferenceDeathListener);
2343 }
2344 mConferenceables.add(c);
2345 }
2346 }
2347 fireOnConferenceableConnectionsChanged();
2348 }
2349
2350 /**
2351 * Returns the connections or conferences with which this connection can be conferenced.
2352 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002353 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002354 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002355 }
2356
Yorke Lee53463962015-08-04 16:07:19 -07002357 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002358 * @hide
2359 */
2360 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002361 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002362 if (mConnectionService != null) {
2363 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2364 "which is already associated with another ConnectionService.");
2365 } else {
2366 mConnectionService = connectionService;
2367 }
2368 }
2369
2370 /**
2371 * @hide
2372 */
2373 public final void unsetConnectionService(ConnectionService connectionService) {
2374 if (mConnectionService != connectionService) {
2375 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2376 "that does not belong to the ConnectionService.");
2377 } else {
2378 mConnectionService = null;
2379 }
2380 }
2381
2382 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002383 * @hide
2384 */
2385 public final ConnectionService getConnectionService() {
2386 return mConnectionService;
2387 }
2388
2389 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002390 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002391 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002392 *
2393 * @param conference The conference.
2394 * @return {@code true} if the conference was successfully set.
2395 * @hide
2396 */
2397 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002398 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002399 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002400 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002401 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002402 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2403 fireConferenceChanged();
2404 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002405 return true;
2406 }
2407 return false;
2408 }
2409
2410 /**
2411 * Resets the conference that this connection is a part of.
2412 * @hide
2413 */
2414 public final void resetConference() {
2415 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002416 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002417 mConference = null;
2418 fireConferenceChanged();
2419 }
2420 }
2421
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002422 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002423 * Set some extras that can be associated with this {@code Connection}.
2424 * <p>
2425 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2426 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2427 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002428 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2429 * {@link #removeExtras(String...)} methods to modify the extras.
2430 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002431 * 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 -07002432 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2433 *
2434 * @param extras The extras associated with this {@code Connection}.
2435 */
2436 public final void setExtras(@Nullable Bundle extras) {
2437 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002438
2439 // Add/replace any new or changed extras values.
2440 putExtras(extras);
2441
2442 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2443 // the current one and remove any keys that went away.
2444 if (mPreviousExtraKeys != null) {
2445 List<String> toRemove = new ArrayList<String>();
2446 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002447 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002448 toRemove.add(oldKey);
2449 }
2450 }
2451 if (!toRemove.isEmpty()) {
2452 removeExtras(toRemove);
2453 }
2454 }
2455
2456 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2457 // called we can see if the caller has removed any extras values.
2458 if (mPreviousExtraKeys == null) {
2459 mPreviousExtraKeys = new ArraySet<String>();
2460 }
2461 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002462 if (extras != null) {
2463 mPreviousExtraKeys.addAll(extras.keySet());
2464 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002465 }
2466
2467 /**
2468 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2469 * added.
2470 * <p>
2471 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2472 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2473 *
2474 * @param extras The extras to add.
2475 */
2476 public final void putExtras(@NonNull Bundle extras) {
2477 checkImmutable();
2478 if (extras == null) {
2479 return;
2480 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002481 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2482 // the listeners.
2483 Bundle listenerExtras;
2484 synchronized (mExtrasLock) {
2485 if (mExtras == null) {
2486 mExtras = new Bundle();
2487 }
2488 mExtras.putAll(extras);
2489 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002490 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002491 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002492 // Create a new clone of the extras for each listener so that they don't clobber
2493 // each other
2494 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002495 }
2496 }
2497
2498 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002499 * Adds a boolean extra to this {@code Connection}.
2500 *
2501 * @param key The extra key.
2502 * @param value The value.
2503 * @hide
2504 */
2505 public final void putExtra(String key, boolean value) {
2506 Bundle newExtras = new Bundle();
2507 newExtras.putBoolean(key, value);
2508 putExtras(newExtras);
2509 }
2510
2511 /**
2512 * Adds an integer extra to this {@code Connection}.
2513 *
2514 * @param key The extra key.
2515 * @param value The value.
2516 * @hide
2517 */
2518 public final void putExtra(String key, int value) {
2519 Bundle newExtras = new Bundle();
2520 newExtras.putInt(key, value);
2521 putExtras(newExtras);
2522 }
2523
2524 /**
2525 * Adds a string extra to this {@code Connection}.
2526 *
2527 * @param key The extra key.
2528 * @param value The value.
2529 * @hide
2530 */
2531 public final void putExtra(String key, String value) {
2532 Bundle newExtras = new Bundle();
2533 newExtras.putString(key, value);
2534 putExtras(newExtras);
2535 }
2536
2537 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002538 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002539 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002540 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002541 */
2542 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002543 synchronized (mExtrasLock) {
2544 if (mExtras != null) {
2545 for (String key : keys) {
2546 mExtras.remove(key);
2547 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002548 }
2549 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002550 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002551 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002552 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002553 }
2554 }
2555
2556 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002557 * Removes extras from this {@code Connection}.
2558 *
2559 * @param keys The keys of the extras to remove.
2560 */
2561 public final void removeExtras(String ... keys) {
2562 removeExtras(Arrays.asList(keys));
2563 }
2564
2565 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002566 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2567 * be change to the {@link #getCallAudioState()}.
2568 * <p>
2569 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2570 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2571 * <p>
2572 * See also {@link InCallService#setAudioRoute(int)}.
2573 *
2574 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2575 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2576 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2577 */
2578 public final void setAudioRoute(int route) {
2579 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002580 l.onAudioRouteChanged(this, route, null);
2581 }
2582 }
2583
2584 /**
2585 *
2586 * Request audio routing to a specific bluetooth device. Calling this method may result in
2587 * the device routing audio to a different bluetooth device than the one specified if the
2588 * bluetooth stack is unable to route audio to the requested device.
2589 * A list of available devices can be obtained via
2590 * {@link CallAudioState#getSupportedBluetoothDevices()}
2591 *
2592 * <p>
2593 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2594 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2595 * <p>
2596 * See also {@link InCallService#requestBluetoothAudio(String)}
2597 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2598 * {@link BluetoothDevice#getAddress()}.
2599 */
2600 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2601 for (Listener l : mListeners) {
2602 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08002603 }
2604 }
2605
2606 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002607 * Informs listeners that a previously requested RTT session via
2608 * {@link ConnectionRequest#isRequestingRtt()} or
2609 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)} has succeeded.
2610 * @hide
2611 */
Hall Liuffa4a812017-03-02 16:11:00 -08002612 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002613 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002614 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002615 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2616 }
2617
2618 /**
2619 * Informs listeners that a previously requested RTT session via
2620 * {@link ConnectionRequest#isRequestingRtt()} or
2621 * {@link #onStartRtt(ParcelFileDescriptor, ParcelFileDescriptor)}
2622 * has failed.
2623 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2624 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
2625 * @hide
2626 */
Hall Liuffa4a812017-03-02 16:11:00 -08002627 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002628 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002629 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002630 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2631 }
2632
2633 /**
2634 * Informs listeners that a currently active RTT session has been terminated by the remote
2635 * side of the coll.
2636 * @hide
2637 */
Hall Liuffa4a812017-03-02 16:11:00 -08002638 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002639 public final void sendRttSessionRemotelyTerminated() {
2640 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2641 }
2642
2643 /**
2644 * Informs listeners that the remote side of the call has requested an upgrade to include an
2645 * RTT session in the call.
2646 * @hide
2647 */
Hall Liuffa4a812017-03-02 16:11:00 -08002648 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002649 public final void sendRemoteRttRequest() {
2650 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2651 }
2652
2653 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002654 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002655 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002656 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002657 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2658 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002659 */
Yorke Lee4af59352015-05-13 14:14:54 -07002660 @SystemApi
2661 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002662 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002663
2664 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002665 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2666 *
2667 * @param state The new connection audio state.
2668 */
2669 public void onCallAudioStateChanged(CallAudioState state) {}
2670
2671 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002672 * Notifies this Connection of an internal state change. This method is called after the
2673 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002674 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002675 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002676 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002677 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002678
2679 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002680 * Notifies this Connection of a request to play a DTMF tone.
2681 *
2682 * @param c A DTMF character.
2683 */
Santos Cordonf2951102014-07-20 19:06:29 -07002684 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002685
2686 /**
2687 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2688 */
Santos Cordonf2951102014-07-20 19:06:29 -07002689 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002690
2691 /**
2692 * Notifies this Connection of a request to disconnect.
2693 */
Santos Cordonf2951102014-07-20 19:06:29 -07002694 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002695
2696 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002697 * Notifies this Connection of a request to disconnect a participant of the conference managed
2698 * by the connection.
2699 *
2700 * @param endpoint the {@link Uri} of the participant to disconnect.
2701 * @hide
2702 */
2703 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2704
2705 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002706 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002707 */
Santos Cordonf2951102014-07-20 19:06:29 -07002708 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002709
2710 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002711 * Notifies this Connection of a request to abort.
2712 */
Santos Cordonf2951102014-07-20 19:06:29 -07002713 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002714
2715 /**
2716 * Notifies this Connection of a request to hold.
2717 */
Santos Cordonf2951102014-07-20 19:06:29 -07002718 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002719
2720 /**
2721 * Notifies this Connection of a request to exit a hold state.
2722 */
Santos Cordonf2951102014-07-20 19:06:29 -07002723 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002724
2725 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002726 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002727 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002728 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002729 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002730 */
Santos Cordonf2951102014-07-20 19:06:29 -07002731 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002732
2733 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002734 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002735 * a request to accept.
2736 */
2737 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002738 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002739 }
2740
2741 /**
2742 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002743 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002744 */
Santos Cordonf2951102014-07-20 19:06:29 -07002745 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002746
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002747 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002748 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2749 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002750 */
2751 public void onReject(String replyMessage) {}
2752
2753 /**
Bryce Leecac50772015-11-17 15:13:29 -08002754 * Notifies the Connection of a request to silence the ringer.
2755 *
2756 * @hide
2757 */
2758 public void onSilence() {}
2759
2760 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002761 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2762 */
Santos Cordonf2951102014-07-20 19:06:29 -07002763 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002764
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002765 /**
2766 * Notifies this Connection of a request to pull an external call to the local device.
2767 * <p>
2768 * The {@link InCallService} issues a request to pull an external call to the local device via
2769 * {@link Call#pullExternalCall()}.
2770 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002771 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2772 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002773 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002774 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002775 */
2776 public void onPullExternalCall() {}
2777
2778 /**
2779 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2780 * <p>
2781 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2782 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002783 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2784 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2785 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2786 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2787 * not aware of.
2788 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002789 * See also {@link Call#sendCallEvent(String, Bundle)}.
2790 *
2791 * @param event The call event.
2792 * @param extras Extras associated with the call event.
2793 */
2794 public void onCallEvent(String event, Bundle extras) {}
2795
Tyler Gunndee56a82016-03-23 16:06:34 -07002796 /**
2797 * Notifies this {@link Connection} of a change to the extras made outside the
2798 * {@link ConnectionService}.
2799 * <p>
2800 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2801 * the {@link android.telecom.Call#putExtras(Bundle)} and
2802 * {@link Call#removeExtras(List)}.
2803 *
2804 * @param extras The new extras bundle.
2805 */
2806 public void onExtrasChanged(Bundle extras) {}
2807
Tyler Gunnf5035432017-01-09 09:43:12 -08002808 /**
2809 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2810 * displaying its incoming call user interface for the {@link Connection}.
2811 * <p>
2812 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2813 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2814 * should show its own incoming call user interface.
2815 * <p>
2816 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2817 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2818 * user interface to allow the user to choose whether to answer the new incoming call and
2819 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002820 * <p>
2821 * You should trigger the display of the incoming call user interface for your application by
2822 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2823 * For example:
2824 * <pre><code>
2825 * // Create an intent which triggers your fullscreen incoming call user interface.
2826 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2827 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2828 * intent.setClass(context, YourIncomingCallActivity.class);
2829 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2830 *
2831 * // Build the notification as an ongoing high priority item; this ensures it will show as
2832 * // a heads up notification which slides down over top of the current content.
2833 * final Notification.Builder builder = new Notification.Builder(context);
2834 * builder.setOngoing(true);
2835 * builder.setPriority(Notification.PRIORITY_HIGH);
2836 *
2837 * // Set notification content intent to take user to fullscreen UI if user taps on the
2838 * // notification body.
2839 * builder.setContentIntent(pendingIntent);
2840 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2841 * // manager deems it appropriate.
2842 * builder.setFullScreenIntent(pendingIntent, true);
2843 *
2844 * // Setup notification content.
2845 * builder.setSmallIcon( yourIconResourceId );
2846 * builder.setContentTitle("Your notification title");
2847 * builder.setContentText("Your notification content.");
2848 *
2849 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2850 *
2851 * NotificationManager notificationManager = mContext.getSystemService(
2852 * NotificationManager.class);
2853 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2854 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002855 */
2856 public void onShowIncomingCallUi() {}
2857
Hall Liub64ac4c2017-02-06 10:49:48 -08002858 /**
2859 * Notifies this {@link Connection} that the user has requested an RTT session.
2860 * The connection service should call {@link #sendRttInitiationSuccess} or
2861 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2862 * request, respectively.
2863 * @param rttTextStream The object that should be used to send text to or receive text from
2864 * the in-call app.
2865 * @hide
2866 */
Hall Liuffa4a812017-03-02 16:11:00 -08002867 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002868 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2869
2870 /**
2871 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2872 * channel. No response to Telecom is needed for this method.
2873 * @hide
2874 */
Hall Liuffa4a812017-03-02 16:11:00 -08002875 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002876 public void onStopRtt() {}
2877
2878 /**
2879 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2880 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2881 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2882 * indicated by {@code rttTextStream} being {@code null}
2883 * @hide
2884 * @param rttTextStream The object that should be used to send text to or receive text from
2885 * the in-call app.
2886 */
Hall Liuffa4a812017-03-02 16:11:00 -08002887 @TestApi
Hall Liub64ac4c2017-02-06 10:49:48 -08002888 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2889
Hall Liuffa4a812017-03-02 16:11:00 -08002890 /**
2891 * Internal method to set {@link #PROPERTY_IS_RTT}.
2892 * @hide
2893 */
2894 void setRttProperty() {
2895 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2896 }
2897
2898 /**
2899 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2900 * @hide
2901 */
2902 void unsetRttProperty() {
2903 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2904 }
2905
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002906 static String toLogSafePhoneNumber(String number) {
2907 // For unknown number, log empty string.
2908 if (number == null) {
2909 return "";
2910 }
2911
2912 if (PII_DEBUG) {
2913 // When PII_DEBUG is true we emit PII.
2914 return number;
2915 }
2916
2917 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2918 // sanitized phone numbers.
2919 StringBuilder builder = new StringBuilder();
2920 for (int i = 0; i < number.length(); i++) {
2921 char c = number.charAt(i);
2922 if (c == '-' || c == '@' || c == '.') {
2923 builder.append(c);
2924 } else {
2925 builder.append('x');
2926 }
2927 }
2928 return builder.toString();
2929 }
2930
Ihab Awad542e0ea2014-05-16 10:22:16 -07002931 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002932 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002933 if (mState == STATE_DISCONNECTED && mState != state) {
2934 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002935 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002936 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002937 if (mState != state) {
2938 Log.d(this, "setState: %s", stateToString(state));
2939 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002940 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002941 for (Listener l : mListeners) {
2942 l.onStateChanged(this, state);
2943 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002944 }
2945 }
2946
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002947 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002948 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002949 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2950 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002951 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002952 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002953
2954 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002955 if (mImmutable) {
2956 throw new UnsupportedOperationException("Connection is immutable");
2957 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002958 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002959 }
2960
Evan Charltonbf11f982014-07-20 22:06:28 -07002961 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002962 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002963 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2964 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002965 * <p>
2966 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2967 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002968 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002969 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002970 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002971 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002972 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2973 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002974 }
2975
Evan Charltonbf11f982014-07-20 22:06:28 -07002976 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002977 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2978 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2979 * this should never be un-@hide-den.
2980 *
2981 * @hide
2982 */
2983 public void checkImmutable() {}
2984
2985 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002986 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2987 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2988 * that state. This connection should not be used for anything, and no other
2989 * {@code Connection}s should be attempted.
2990 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002991 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002992 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002993 * @return A {@code Connection} which indicates that the underlying connection should
2994 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002995 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002996 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002997 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002998 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002999
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003000 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003001 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003002 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003003 }
3004 }
3005
Santos Cordon823fd3c2014-08-07 18:35:18 -07003006 private final void fireConferenceChanged() {
3007 for (Listener l : mListeners) {
3008 l.onConferenceChanged(this, mConference);
3009 }
3010 }
3011
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003012 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003013 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003014 if (c instanceof Connection) {
3015 Connection connection = (Connection) c;
3016 connection.removeConnectionListener(mConnectionDeathListener);
3017 } else if (c instanceof Conference) {
3018 Conference conference = (Conference) c;
3019 conference.removeListener(mConferenceDeathListener);
3020 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003021 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003022 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003023 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003024
3025 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003026 * Handles a change to extras received from Telecom.
3027 *
3028 * @param extras The new extras.
3029 * @hide
3030 */
3031 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003032 Bundle b = null;
3033 synchronized (mExtrasLock) {
3034 mExtras = extras;
3035 if (mExtras != null) {
3036 b = new Bundle(mExtras);
3037 }
3038 }
3039 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003040 }
3041
3042 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003043 * Notifies listeners that the merge request failed.
3044 *
3045 * @hide
3046 */
3047 protected final void notifyConferenceMergeFailed() {
3048 for (Listener l : mListeners) {
3049 l.onConferenceMergeFailed(this);
3050 }
3051 }
3052
3053 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003054 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003055 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003056 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003057 * @hide
3058 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003059 protected final void updateConferenceParticipants(
3060 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003061 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003062 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003063 }
3064 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003065
3066 /**
3067 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003068 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003069 */
3070 protected void notifyConferenceStarted() {
3071 for (Listener l : mListeners) {
3072 l.onConferenceStarted();
3073 }
3074 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003075
3076 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003077 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3078 * be a part of a conference call.
3079 * @param isConferenceSupported {@code true} if the connection supports being part of a
3080 * conference call, {@code false} otherwise.
3081 * @hide
3082 */
3083 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3084 for (Listener l : mListeners) {
3085 l.onConferenceSupportedChanged(this, isConferenceSupported);
3086 }
3087 }
3088
3089 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303090 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3091 * changed due to an emergency call being redialed.
3092 * @param pHandle The new PhoneAccountHandle for this connection.
3093 * @hide
3094 */
3095 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3096 for (Listener l : mListeners) {
3097 l.onPhoneAccountChanged(this, pHandle);
3098 }
3099 }
3100
3101 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003102 * Sends an event associated with this {@code Connection} with associated event extras to the
3103 * {@link InCallService}.
3104 * <p>
3105 * Connection events are used to communicate point in time information from a
3106 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3107 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3108 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3109 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3110 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3111 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3112 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3113 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3114 * <p>
3115 * Events are exposed to {@link InCallService} implementations via
3116 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3117 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003118 * 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 -07003119 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3120 * some events altogether.
3121 * <p>
3122 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3123 * conflicts between {@link ConnectionService} implementations. Further, custom
3124 * {@link ConnectionService} implementations shall not re-purpose events in the
3125 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3126 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3127 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3128 * {@code com.example.extra.MY_EXTRA}).
3129 * <p>
3130 * When defining events and the associated extras, it is important to keep their behavior
3131 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3132 * events/extras should me maintained to ensure backwards compatibility with older
3133 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003134 *
3135 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003136 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003137 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003138 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003139 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003140 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003141 }
3142 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003143}