blob: 75224434bc1c5293b03117f83850d98eb43c65cf [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.app.Notification;
Hall Liua98f58b2017-11-07 17:59:28 -080027import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Eric Erfanianaf7b8c02018-01-17 15:27:39 -080038import android.os.Parcelable;
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 */
401 public static final int PROPERTY_IS_RTT = 1 << 8;
402
Eric Erfanian62706c52017-12-06 16:27:53 -0800403 /**
404 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfanian62706c52017-12-06 16:27:53 -0800405 */
406 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
407
Tyler Gunn96d6c402015-03-18 12:39:23 -0700408 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800409 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700410 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800411
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700412 /**
413 * Connection extra key used to store the last forwarded number associated with the current
414 * connection. Used to communicate to the user interface that the connection was forwarded via
415 * the specified number.
416 */
417 public static final String EXTRA_LAST_FORWARDED_NUMBER =
418 "android.telecom.extra.LAST_FORWARDED_NUMBER";
419
420 /**
421 * Connection extra key used to store a child number associated with the current connection.
422 * Used to communicate to the user interface that the connection was received via
423 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
424 * address.
425 */
426 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
427
428 /**
429 * Connection extra key used to store the subject for an incoming call. The user interface can
430 * query this extra and display its contents for incoming calls. Will only be used if the
431 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
432 */
433 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
434
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800435 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700436 * Boolean connection extra key set on a {@link Connection} in
437 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
438 * current active foreground call to be dropped.
439 */
440 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
441 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
442
443 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700444 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
445 * state to indicate the name of the third-party app which is responsible for the current
446 * foreground call.
447 * <p>
448 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
449 * is able to inform the user that answering the new incoming call will cause a call owned by
450 * another app to be dropped when the incoming call is answered.
451 */
452 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
453 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
454
455 /**
Hall Liu10208662016-06-15 17:55:00 -0700456 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700457 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700458 * @hide
459 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700460 public static final String EXTRA_DISABLE_ADD_CALL =
461 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700462
463 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700464 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
465 * original Connection ID associated with the connection. Used in
466 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
467 * connection/conference added via
468 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
469 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
470 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
471 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
472 * be a way to ensure that we don't add the connection again as a duplicate.
473 * <p>
474 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
475 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
476 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
477 * in a new {@link Connection} which it adds to Telecom via
478 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
479 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
480 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
481 * ID it originally referred to the connection as. Thus Telecom needs to know that the
482 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
483 * @hide
484 */
485 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
486 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
487
488 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800489 * Connection event used to inform Telecom that it should play the on hold tone. This is used
490 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700491 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800492 * @hide
493 */
494 public static final String EVENT_ON_HOLD_TONE_START =
495 "android.telecom.event.ON_HOLD_TONE_START";
496
497 /**
498 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
499 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700500 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800501 * @hide
502 */
503 public static final String EVENT_ON_HOLD_TONE_END =
504 "android.telecom.event.ON_HOLD_TONE_END";
505
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700506 /**
507 * Connection event used to inform {@link InCallService}s when pulling of an external call has
508 * failed. The user interface should inform the user of the error.
509 * <p>
510 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
511 * API is called on a {@link Call} with the properties
512 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
513 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
514 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700515 * <p>
516 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
517 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700518 */
519 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
520
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700521 /**
522 * Connection event used to inform {@link InCallService}s when the merging of two calls has
523 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700524 * <p>
525 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
526 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700527 */
528 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
529
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700530 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700531 * Connection event used to inform {@link InCallService}s when the process of merging a
532 * Connection into a conference has begun.
533 * <p>
534 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
535 * expected to be null when this connection event is used.
536 * @hide
537 */
538 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
539
540 /**
541 * Connection event used to inform {@link InCallService}s when the process of merging a
542 * Connection into a conference has completed.
543 * <p>
544 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
545 * expected to be null when this connection event is used.
546 * @hide
547 */
548 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
549
550 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700551 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
552 * the remote party.
553 * <p>
554 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
555 * call is being held locally on the device. When a capable {@link ConnectionService} receives
556 * signalling to indicate that the remote party has put the call on hold, it can send this
557 * connection event.
558 * @hide
559 */
560 public static final String EVENT_CALL_REMOTELY_HELD =
561 "android.telecom.event.CALL_REMOTELY_HELD";
562
563 /**
564 * Connection event used to inform {@link InCallService}s when a call which was remotely held
565 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
566 * <p>
567 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
568 * call is being held locally on the device. When a capable {@link ConnectionService} receives
569 * signalling to indicate that the remote party has taken the call off hold, it can send this
570 * connection event.
571 * @hide
572 */
573 public static final String EVENT_CALL_REMOTELY_UNHELD =
574 "android.telecom.event.CALL_REMOTELY_UNHELD";
575
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700576 /**
577 * Connection event used to inform an {@link InCallService} which initiated a call handover via
578 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
579 * successfully completed.
580 * @hide
581 */
582 public static final String EVENT_HANDOVER_COMPLETE =
583 "android.telecom.event.HANDOVER_COMPLETE";
584
585 /**
586 * Connection event used to inform an {@link InCallService} which initiated a call handover via
587 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
588 * to complete.
589 * @hide
590 */
591 public static final String EVENT_HANDOVER_FAILED =
592 "android.telecom.event.HANDOVER_FAILED";
593
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700594 // Flag controlling whether PII is emitted into the logs
595 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
596
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800597 /**
598 * Whether the given capabilities support the specified capability.
599 *
600 * @param capabilities A capability bit field.
601 * @param capability The capability to check capabilities for.
602 * @return Whether the specified capability is supported.
603 * @hide
604 */
605 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800606 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800607 }
608
609 /**
610 * Whether the capabilities of this {@code Connection} supports the specified capability.
611 *
612 * @param capability The capability to check capabilities for.
613 * @return Whether the specified capability is supported.
614 * @hide
615 */
616 public boolean can(int capability) {
617 return can(mConnectionCapabilities, capability);
618 }
619
620 /**
621 * Removes the specified capability from the set of capabilities of this {@code Connection}.
622 *
623 * @param capability The capability to remove from the set.
624 * @hide
625 */
626 public void removeCapability(int capability) {
627 mConnectionCapabilities &= ~capability;
628 }
629
630 /**
631 * Adds the specified capability to the set of capabilities of this {@code Connection}.
632 *
633 * @param capability The capability to add to the set.
634 * @hide
635 */
636 public void addCapability(int capability) {
637 mConnectionCapabilities |= capability;
638 }
639
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700640 /**
641 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
642 *
643 * @param capabilities A capability bit field.
644 * @return A human readable string representation.
645 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700647 return capabilitiesToStringInternal(capabilities, true /* isLong */);
648 }
649
650 /**
651 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
652 * string.
653 *
654 * @param capabilities A capability bit field.
655 * @return A human readable string representation.
656 * @hide
657 */
658 public static String capabilitiesToStringShort(int capabilities) {
659 return capabilitiesToStringInternal(capabilities, false /* isLong */);
660 }
661
662 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800663 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700664 builder.append("[");
665 if (isLong) {
666 builder.append("Capabilities:");
667 }
668
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800669 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700670 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800671 }
672 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700673 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 }
675 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
684 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800686 }
687 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700690 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700692 }
693 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800698 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700701 }
702 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700704 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700705 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800707 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800708 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800710 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500711 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500713 }
Rekha Kumar07366812015-03-24 16:42:31 -0700714 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700716 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700717 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700719 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700720 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700722 }
Bryce Lee81901682015-08-28 16:38:02 -0700723 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700725 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700726 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700728 }
Bryce Lee81901682015-08-28 16:38:02 -0700729
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800730 builder.append("]");
731 return builder.toString();
732 }
733
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700734 /**
735 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
736 *
737 * @param properties A property bit field.
738 * @return A human readable string representation.
739 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700740 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700741 return propertiesToStringInternal(properties, true /* isLong */);
742 }
743
744 /**
745 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
746 *
747 * @param properties A property bit field.
748 * @return A human readable string representation.
749 * @hide
750 */
751 public static String propertiesToStringShort(int properties) {
752 return propertiesToStringInternal(properties, false /* isLong */);
753 }
754
755 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700756 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700757 builder.append("[");
758 if (isLong) {
759 builder.append("Properties:");
760 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700761
Tyler Gunnf5035432017-01-09 09:43:12 -0800762 if (can(properties, PROPERTY_SELF_MANAGED)) {
763 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
764 }
765
Hall Liu25c7c4d2016-08-30 13:41:02 -0700766 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
767 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700768 }
769
770 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700771 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700772 }
773
774 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700775 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700776 }
777
778 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700780 }
781
782 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700784 }
785
Brad Ebinger15847072016-05-18 11:08:36 -0700786 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700787 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700788 }
789
Tyler Gunn720c6642016-03-22 09:02:47 -0700790 builder.append("]");
791 return builder.toString();
792 }
793
Sailesh Nepal091768c2014-06-30 15:15:23 -0700794 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700795 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700796 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700797 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700798 public void onCallerDisplayNameChanged(
799 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700800 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700801 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700802 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800803 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700804 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700805 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700807 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800808 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700809 public void onVideoProviderChanged(
810 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700811 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
812 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800813 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700814 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700815 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700816 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800817 public void onConferenceParticipantsChanged(Connection c,
818 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800819 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700820 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700821 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700822 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700823 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700824 /** @hide */
825 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b2017-11-07 17:59:28 -0800826 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800827 public void onRttInitiationSuccess(Connection c) {}
828 public void onRttInitiationFailure(Connection c, int reason) {}
829 public void onRttSessionRemotelyTerminated(Connection c) {}
830 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530831 /** @hide */
832 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700833 }
834
Tyler Gunnb702ef82015-05-29 11:51:53 -0700835 /**
Hall Liu95d55872017-01-25 17:12:49 -0800836 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800837 */
838 public static final class RttTextStream {
839 private static final int READ_BUFFER_SIZE = 1000;
840 private final InputStreamReader mPipeFromInCall;
841 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800842 private final ParcelFileDescriptor mFdFromInCall;
843 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800844 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
845
846 /**
847 * @hide
848 */
849 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800850 mFdFromInCall = fromInCall;
851 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800852 mPipeFromInCall = new InputStreamReader(
853 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
854 mPipeToInCall = new OutputStreamWriter(
855 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
856 }
857
858 /**
859 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
860 * RTT transmits text in real-time, this method should be called as often as text snippets
861 * are received from the remote user, even if it is only one character.
862 *
863 * This method is not thread-safe -- calling it from multiple threads simultaneously may
864 * lead to interleaved text.
865 * @param input The message to send to the in-call app.
866 */
867 public void write(String input) throws IOException {
868 mPipeToInCall.write(input);
869 mPipeToInCall.flush();
870 }
871
872
873 /**
874 * Reads a string from the in-call app, blocking if there is no data available. Returns
875 * {@code null} if the RTT conversation has been terminated and there is no further data
876 * to read.
877 *
878 * This method is not thread-safe -- calling it from multiple threads simultaneously may
879 * lead to interleaved text.
880 * @return A string containing text entered by the user, or {@code null} if the
881 * conversation has been terminated or if there was an error while reading.
882 */
Hall Liuffa4a812017-03-02 16:11:00 -0800883 public String read() throws IOException {
884 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
885 if (numRead < 0) {
886 return null;
887 }
888 return new String(mReadBuffer, 0, numRead);
889 }
890
891 /**
892 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
893 * be read.
894 * @return A string containing text entered by the user, or {@code null} if the user has
895 * not entered any new text yet.
896 */
897 public String readImmediately() throws IOException {
898 if (mPipeFromInCall.ready()) {
899 return read();
900 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800901 return null;
902 }
903 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800904
905 /** @hide */
906 public ParcelFileDescriptor getFdFromInCall() {
907 return mFdFromInCall;
908 }
909
910 /** @hide */
911 public ParcelFileDescriptor getFdToInCall() {
912 return mFdToInCall;
913 }
914 }
915
916 /**
917 * Provides constants to represent the results of responses to session modify requests sent via
918 * {@link Call#sendRttRequest()}
919 */
920 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700921 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800922 /**
923 * Session modify request was successful.
924 */
925 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
926
927 /**
928 * Session modify request failed.
929 */
930 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
931
932 /**
933 * Session modify request ignored due to invalid parameters.
934 */
935 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
936
937 /**
938 * Session modify request timed out.
939 */
940 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
941
942 /**
943 * Session modify request rejected by remote user.
944 */
945 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800946 }
947
948 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 * Provides a means of controlling the video session associated with a {@link Connection}.
950 * <p>
951 * Implementations create a custom subclass of {@link VideoProvider} and the
952 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
953 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
954 * should set the {@link VideoProvider}.
955 * <p>
956 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
957 * {@link InCallService} implementations to issue requests related to the video session;
958 * it provides a means for the {@link ConnectionService} to report events and information
959 * related to the video session to Telecom and the {@link InCallService} implementations.
960 * <p>
961 * {@link InCallService} implementations interact with the {@link VideoProvider} via
962 * {@link android.telecom.InCallService.VideoCall}.
963 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 /**
966 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700967 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700968 */
969 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700970
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700972 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
973 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 */
975 public static final int SESSION_EVENT_RX_RESUME = 2;
976
977 /**
978 * Video transmission has begun. This occurs after a negotiated start of video transmission
979 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700980 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700981 */
982 public static final int SESSION_EVENT_TX_START = 3;
983
984 /**
985 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
986 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700988 */
989 public static final int SESSION_EVENT_TX_STOP = 4;
990
991 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800992 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -0700993 * this as a cue to inform the user the camera is not available.
994 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995 */
996 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
997
998 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001000 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001001 * the camera has become available again.
1002 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001003 */
1004 public static final int SESSION_EVENT_CAMERA_READY = 6;
1005
1006 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001007 * Session event raised by Telecom when
1008 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1009 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1010 * @see #handleCallSessionEvent(int)
1011 */
1012 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1013
1014 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001016 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 */
1018 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1019
1020 /**
1021 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001022 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001023 */
1024 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1025
1026 /**
1027 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001028 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 */
1030 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1031
Rekha Kumar07366812015-03-24 16:42:31 -07001032 /**
1033 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001034 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001035 */
1036 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1037
1038 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001039 * Session modify request rejected by remote user.
1040 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001041 */
1042 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1043
Tyler Gunn75958422015-04-15 14:23:42 -07001044 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001045 private static final int MSG_SET_CAMERA = 2;
1046 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1047 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1048 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1049 private static final int MSG_SET_ZOOM = 6;
1050 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1051 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1052 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001053 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001055 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001057 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1058 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1059 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1060 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1061 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1062 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001063 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1064 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001065 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1066
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001067 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001069
1070 /**
1071 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001072 *
1073 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1074 * load factor before resizing, 1 means we only expect a single thread to
1075 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001076 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001077 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1078 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001079
1080 /**
1081 * Default handler used to consolidate binder method calls onto a single thread.
1082 */
1083 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001084 public VideoProviderHandler() {
1085 super();
1086 }
1087
1088 public VideoProviderHandler(Looper looper) {
1089 super(looper);
1090 }
1091
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001092 @Override
1093 public void handleMessage(Message msg) {
1094 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001095 case MSG_ADD_VIDEO_CALLBACK: {
1096 IBinder binder = (IBinder) msg.obj;
1097 IVideoCallback callback = IVideoCallback.Stub
1098 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001099 if (callback == null) {
1100 Log.w(this, "addVideoProvider - skipped; callback is null.");
1101 break;
1102 }
1103
Tyler Gunn75958422015-04-15 14:23:42 -07001104 if (mVideoCallbacks.containsKey(binder)) {
1105 Log.i(this, "addVideoProvider - skipped; already present.");
1106 break;
1107 }
1108 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001110 }
1111 case MSG_REMOVE_VIDEO_CALLBACK: {
1112 IBinder binder = (IBinder) msg.obj;
1113 IVideoCallback callback = IVideoCallback.Stub
1114 .asInterface((IBinder) msg.obj);
1115 if (!mVideoCallbacks.containsKey(binder)) {
1116 Log.i(this, "removeVideoProvider - skipped; not present.");
1117 break;
1118 }
1119 mVideoCallbacks.remove(binder);
1120 break;
1121 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001122 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001123 {
1124 SomeArgs args = (SomeArgs) msg.obj;
1125 try {
1126 onSetCamera((String) args.arg1);
1127 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001128 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001129 } finally {
1130 args.recycle();
1131 }
1132 }
1133 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 case MSG_SET_PREVIEW_SURFACE:
1135 onSetPreviewSurface((Surface) msg.obj);
1136 break;
1137 case MSG_SET_DISPLAY_SURFACE:
1138 onSetDisplaySurface((Surface) msg.obj);
1139 break;
1140 case MSG_SET_DEVICE_ORIENTATION:
1141 onSetDeviceOrientation(msg.arg1);
1142 break;
1143 case MSG_SET_ZOOM:
1144 onSetZoom((Float) msg.obj);
1145 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001146 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1147 SomeArgs args = (SomeArgs) msg.obj;
1148 try {
1149 onSendSessionModifyRequest((VideoProfile) args.arg1,
1150 (VideoProfile) args.arg2);
1151 } finally {
1152 args.recycle();
1153 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001154 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001155 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001156 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1157 onSendSessionModifyResponse((VideoProfile) msg.obj);
1158 break;
1159 case MSG_REQUEST_CAMERA_CAPABILITIES:
1160 onRequestCameraCapabilities();
1161 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001162 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1163 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 break;
1165 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001166 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167 break;
1168 default:
1169 break;
1170 }
1171 }
1172 }
1173
1174 /**
1175 * IVideoProvider stub implementation.
1176 */
1177 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001178 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001180 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1181 }
1182
1183 public void removeVideoCallback(IBinder videoCallbackBinder) {
1184 mMessageHandler.obtainMessage(
1185 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001186 }
1187
Tyler Gunn159f35c2017-03-02 09:28:37 -08001188 public void setCamera(String cameraId, String callingPackageName,
1189 int targetSdkVersion) {
1190
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001191 SomeArgs args = SomeArgs.obtain();
1192 args.arg1 = cameraId;
1193 // Propagate the calling package; originally determined in
1194 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1195 // process.
1196 args.arg2 = callingPackageName;
1197 // Pass along the uid and pid of the calling app; this gets lost when we put the
1198 // message onto the handler. These are required for Telecom to perform a permission
1199 // check to see if the calling app is able to use the camera.
1200 args.argi1 = Binder.getCallingUid();
1201 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001202 // Pass along the target SDK version of the calling InCallService. This is used to
1203 // maintain backwards compatibility of the API for older callers.
1204 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001205 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001206 }
1207
1208 public void setPreviewSurface(Surface surface) {
1209 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1210 }
1211
1212 public void setDisplaySurface(Surface surface) {
1213 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1214 }
1215
1216 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001217 mMessageHandler.obtainMessage(
1218 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001219 }
1220
1221 public void setZoom(float value) {
1222 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1223 }
1224
Tyler Gunn45382162015-05-06 08:52:27 -07001225 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1226 SomeArgs args = SomeArgs.obtain();
1227 args.arg1 = fromProfile;
1228 args.arg2 = toProfile;
1229 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001230 }
1231
1232 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1233 mMessageHandler.obtainMessage(
1234 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1235 }
1236
1237 public void requestCameraCapabilities() {
1238 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1239 }
1240
1241 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001242 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001243 }
1244
Yorke Lee32f24732015-05-12 16:18:03 -07001245 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1247 }
1248 }
1249
1250 public VideoProvider() {
1251 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001252 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001253 }
1254
1255 /**
1256 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1257 *
1258 * @param looper The looper.
1259 * @hide
1260 */
1261 public VideoProvider(Looper looper) {
1262 mBinder = new VideoProvider.VideoProviderBinder();
1263 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 }
1265
1266 /**
1267 * Returns binder object which can be used across IPC methods.
1268 * @hide
1269 */
1270 public final IVideoProvider getInterface() {
1271 return mBinder;
1272 }
1273
1274 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001275 * Sets the camera to be used for the outgoing video.
1276 * <p>
1277 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1278 * camera via
1279 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1280 * <p>
1281 * Sent from the {@link InCallService} via
1282 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001283 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001284 * @param cameraId The id of the camera (use ids as reported by
1285 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001286 */
1287 public abstract void onSetCamera(String cameraId);
1288
1289 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001290 * Sets the camera to be used for the outgoing video.
1291 * <p>
1292 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1293 * camera via
1294 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1295 * <p>
1296 * This prototype is used internally to ensure that the calling package name, UID and PID
1297 * are sent to Telecom so that can perform a camera permission check on the caller.
1298 * <p>
1299 * Sent from the {@link InCallService} via
1300 * {@link InCallService.VideoCall#setCamera(String)}.
1301 *
1302 * @param cameraId The id of the camera (use ids as reported by
1303 * {@link CameraManager#getCameraIdList()}).
1304 * @param callingPackageName The AppOpps package name of the caller.
1305 * @param callingUid The UID of the caller.
1306 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001307 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001308 * @hide
1309 */
1310 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001311 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001312
1313 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 * Sets the surface to be used for displaying a preview of what the user's camera is
1315 * currently capturing. When video transmission is enabled, this is the video signal which
1316 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001317 * <p>
1318 * Sent from the {@link InCallService} via
1319 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001320 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001321 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001322 */
1323 public abstract void onSetPreviewSurface(Surface surface);
1324
1325 /**
1326 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001327 * <p>
1328 * Sent from the {@link InCallService} via
1329 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001331 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001332 */
1333 public abstract void onSetDisplaySurface(Surface surface);
1334
1335 /**
1336 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1337 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001338 * <p>
1339 * Sent from the {@link InCallService} via
1340 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001341 *
1342 * @param rotation The device orientation, in degrees.
1343 */
1344 public abstract void onSetDeviceOrientation(int rotation);
1345
1346 /**
1347 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * <p>
1349 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 *
1351 * @param value The camera zoom ratio.
1352 */
1353 public abstract void onSetZoom(float value);
1354
1355 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001356 * Issues a request to modify the properties of the current video session.
1357 * <p>
1358 * Example scenarios include: requesting an audio-only call to be upgraded to a
1359 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1360 * when the {@link InCallService} is no longer the foreground application.
1361 * <p>
1362 * If the {@link VideoProvider} determines a request to be invalid, it should call
1363 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1364 * invalid request back to the {@link InCallService}.
1365 * <p>
1366 * Where a request requires confirmation from the user of the peer device, the
1367 * {@link VideoProvider} must communicate the request to the peer device and handle the
1368 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1369 * is used to inform the {@link InCallService} of the result of the request.
1370 * <p>
1371 * Sent from the {@link InCallService} via
1372 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 * @param fromProfile The video profile prior to the request.
1375 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 */
Tyler Gunn45382162015-05-06 08:52:27 -07001377 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1378 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379
Tyler Gunnb702ef82015-05-29 11:51:53 -07001380 /**
1381 * Provides a response to a request to change the current video session properties.
1382 * <p>
1383 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1384 * video call, could decline the request and keep the call as audio-only.
1385 * In such a scenario, the {@code responseProfile} would have a video state of
1386 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1387 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1388 * <p>
1389 * Sent from the {@link InCallService} via
1390 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1391 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1392 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001394 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 */
1396 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1397
1398 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001399 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1400 * <p>
1401 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1402 * camera via
1403 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1404 * <p>
1405 * Sent from the {@link InCallService} via
1406 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001407 */
1408 public abstract void onRequestCameraCapabilities();
1409
1410 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001411 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1412 * video component of the current {@link Connection}.
1413 * <p>
1414 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1415 * via {@link VideoProvider#setCallDataUsage(long)}.
1416 * <p>
1417 * Sent from the {@link InCallService} via
1418 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001420 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001421
1422 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001423 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1424 * the peer device when the video signal is paused.
1425 * <p>
1426 * Sent from the {@link InCallService} via
1427 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001428 *
1429 * @param uri URI of image to display.
1430 */
Yorke Lee32f24732015-05-12 16:18:03 -07001431 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432
1433 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001434 * Used to inform listening {@link InCallService} implementations when the
1435 * {@link VideoProvider} receives a session modification request.
1436 * <p>
1437 * Received by the {@link InCallService} via
1438 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001439 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001440 * @param videoProfile The requested video profile.
1441 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 */
1443 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001444 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001445 for (IVideoCallback callback : mVideoCallbacks.values()) {
1446 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001447 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001448 } catch (RemoteException ignored) {
1449 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001450 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001451 }
1452 }
1453 }
1454
1455 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001456 * Used to inform listening {@link InCallService} implementations when the
1457 * {@link VideoProvider} receives a response to a session modification request.
1458 * <p>
1459 * Received by the {@link InCallService} via
1460 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1461 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 *
1463 * @param status Status of the session modify request. Valid values are
1464 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1465 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001466 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1467 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1468 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1469 * @param requestedProfile The original request which was sent to the peer device.
1470 * @param responseProfile The actual profile changes agreed to by the peer device.
1471 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 */
1473 public void receiveSessionModifyResponse(int status,
1474 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001475 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001476 for (IVideoCallback callback : mVideoCallbacks.values()) {
1477 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001478 callback.receiveSessionModifyResponse(status, requestedProfile,
1479 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001480 } catch (RemoteException ignored) {
1481 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001482 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 }
1484 }
1485 }
1486
1487 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001488 * Used to inform listening {@link InCallService} implementations when the
1489 * {@link VideoProvider} reports a call session event.
1490 * <p>
1491 * Received by the {@link InCallService} via
1492 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001494 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1495 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1496 * {@link VideoProvider#SESSION_EVENT_TX_START},
1497 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1498 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001499 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1500 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001501 */
1502 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001503 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001504 for (IVideoCallback callback : mVideoCallbacks.values()) {
1505 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001506 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001507 } catch (RemoteException ignored) {
1508 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001509 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001510 }
1511 }
1512 }
1513
1514 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001515 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1516 * peer's video have changed.
1517 * <p>
1518 * This could occur if, for example, the peer rotates their device, changing the aspect
1519 * ratio of the video, or if the user switches between the back and front cameras.
1520 * <p>
1521 * Received by the {@link InCallService} via
1522 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001523 *
1524 * @param width The updated peer video width.
1525 * @param height The updated peer video height.
1526 */
1527 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001528 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001529 for (IVideoCallback callback : mVideoCallbacks.values()) {
1530 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001531 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001532 } catch (RemoteException ignored) {
1533 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001534 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001535 }
1536 }
1537 }
1538
1539 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001540 * Used to inform listening {@link InCallService} implementations when the data usage of the
1541 * video associated with the current {@link Connection} has changed.
1542 * <p>
1543 * This could be in response to a preview request via
1544 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001545 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1546 * 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 -07001547 * <p>
1548 * Received by the {@link InCallService} via
1549 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001551 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1552 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553 */
Yorke Lee32f24732015-05-12 16:18:03 -07001554 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001555 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001556 for (IVideoCallback callback : mVideoCallbacks.values()) {
1557 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001558 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001559 } catch (RemoteException ignored) {
1560 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001561 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 }
1563 }
1564 }
1565
1566 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001567 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001569 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001570 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1571 * @hide
1572 */
1573 public void changeCallDataUsage(long dataUsage) {
1574 setCallDataUsage(dataUsage);
1575 }
1576
1577 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001578 * Used to inform listening {@link InCallService} implementations when the capabilities of
1579 * the current camera have changed.
1580 * <p>
1581 * The {@link VideoProvider} should call this in response to
1582 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1583 * changed via {@link VideoProvider#onSetCamera(String)}.
1584 * <p>
1585 * Received by the {@link InCallService} via
1586 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1587 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001588 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001589 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001590 */
Yorke Lee400470f2015-05-12 13:31:25 -07001591 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001592 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001593 for (IVideoCallback callback : mVideoCallbacks.values()) {
1594 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001595 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001596 } catch (RemoteException ignored) {
1597 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001598 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 }
1600 }
1601 }
Rekha Kumar07366812015-03-24 16:42:31 -07001602
1603 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * Used to inform listening {@link InCallService} implementations when the video quality
1605 * of the call has changed.
1606 * <p>
1607 * Received by the {@link InCallService} via
1608 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001609 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001610 * @param videoQuality The updated video quality. Valid values:
1611 * {@link VideoProfile#QUALITY_HIGH},
1612 * {@link VideoProfile#QUALITY_MEDIUM},
1613 * {@link VideoProfile#QUALITY_LOW},
1614 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001615 */
1616 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001617 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001618 for (IVideoCallback callback : mVideoCallbacks.values()) {
1619 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001620 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001621 } catch (RemoteException ignored) {
1622 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001623 }
Rekha Kumar07366812015-03-24 16:42:31 -07001624 }
1625 }
1626 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001627
1628 /**
1629 * Returns a string representation of a call session event.
1630 *
1631 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1632 * @return String representation of the call session event.
1633 * @hide
1634 */
1635 public static String sessionEventToString(int event) {
1636 switch (event) {
1637 case SESSION_EVENT_CAMERA_FAILURE:
1638 return SESSION_EVENT_CAMERA_FAILURE_STR;
1639 case SESSION_EVENT_CAMERA_READY:
1640 return SESSION_EVENT_CAMERA_READY_STR;
1641 case SESSION_EVENT_RX_PAUSE:
1642 return SESSION_EVENT_RX_PAUSE_STR;
1643 case SESSION_EVENT_RX_RESUME:
1644 return SESSION_EVENT_RX_RESUME_STR;
1645 case SESSION_EVENT_TX_START:
1646 return SESSION_EVENT_TX_START_STR;
1647 case SESSION_EVENT_TX_STOP:
1648 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001649 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1650 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001651 default:
1652 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1653 }
1654 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001655 }
1656
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001657 private final Listener mConnectionDeathListener = new Listener() {
1658 @Override
1659 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001660 if (mConferenceables.remove(c)) {
1661 fireOnConferenceableConnectionsChanged();
1662 }
1663 }
1664 };
1665
1666 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1667 @Override
1668 public void onDestroyed(Conference c) {
1669 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001670 fireOnConferenceableConnectionsChanged();
1671 }
1672 }
1673 };
1674
Jay Shrauner229e3822014-08-15 09:23:07 -07001675 /**
1676 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1677 * load factor before resizing, 1 means we only expect a single thread to
1678 * access the map so make only a single shard
1679 */
1680 private final Set<Listener> mListeners = Collections.newSetFromMap(
1681 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001682 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1683 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001684 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001685
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001686 // The internal telecom call ID associated with this connection.
1687 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001688 // The PhoneAccountHandle associated with this connection.
1689 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001690 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001691 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001692 private Uri mAddress;
1693 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001694 private String mCallerDisplayName;
1695 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001696 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001697 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001698 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001699 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001701 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001702 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001703 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001704 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001705 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001706 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001707 private Conference mConference;
1708 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001709 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001710 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001711
1712 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001713 * Tracks the key set for the extras bundle provided on the last invocation of
1714 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1715 * keys which were set previously but are no longer present in the replacement Bundle.
1716 */
1717 private Set<String> mPreviousExtraKeys;
1718
1719 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001720 * Create a new Connection.
1721 */
Santos Cordonf2951102014-07-20 19:06:29 -07001722 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723
1724 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001725 * Returns the Telecom internal call ID associated with this connection. Should only be used
1726 * for debugging and tracing purposes.
1727 *
1728 * @return The Telecom call ID.
1729 * @hide
1730 */
1731 public final String getTelecomCallId() {
1732 return mTelecomCallId;
1733 }
1734
1735 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001736 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001737 */
Andrew Lee100e2932014-09-08 15:34:24 -07001738 public final Uri getAddress() {
1739 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001740 }
1741
1742 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001743 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001744 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001745 */
Andrew Lee100e2932014-09-08 15:34:24 -07001746 public final int getAddressPresentation() {
1747 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001748 }
1749
1750 /**
1751 * @return The caller display name (CNAP).
1752 */
1753 public final String getCallerDisplayName() {
1754 return mCallerDisplayName;
1755 }
1756
1757 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001758 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001759 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001760 */
1761 public final int getCallerDisplayNamePresentation() {
1762 return mCallerDisplayNamePresentation;
1763 }
1764
1765 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001766 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001767 */
1768 public final int getState() {
1769 return mState;
1770 }
1771
1772 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001773 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001774 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1775 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1776 * {@link VideoProfile#STATE_TX_ENABLED},
1777 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001778 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001779 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001780 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001781 */
1782 public final int getVideoState() {
1783 return mVideoState;
1784 }
1785
1786 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001787 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001788 * being routed by the system. This is {@code null} if this Connection
1789 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001790 * @deprecated Use {@link #getCallAudioState()} instead.
1791 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001792 */
Yorke Lee4af59352015-05-13 14:14:54 -07001793 @SystemApi
1794 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001795 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001796 if (mCallAudioState == null) {
1797 return null;
1798 }
Yorke Lee4af59352015-05-13 14:14:54 -07001799 return new AudioState(mCallAudioState);
1800 }
1801
1802 /**
1803 * @return The audio state of the connection, describing how its audio is currently
1804 * being routed by the system. This is {@code null} if this Connection
1805 * does not directly know about its audio state.
1806 */
1807 public final CallAudioState getCallAudioState() {
1808 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001809 }
1810
1811 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001812 * @return The conference that this connection is a part of. Null if it is not part of any
1813 * conference.
1814 */
1815 public final Conference getConference() {
1816 return mConference;
1817 }
1818
1819 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001820 * Returns whether this connection is requesting that the system play a ringback tone
1821 * on its behalf.
1822 */
Andrew Lee100e2932014-09-08 15:34:24 -07001823 public final boolean isRingbackRequested() {
1824 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001825 }
1826
1827 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001828 * @return True if the connection's audio mode is VOIP.
1829 */
1830 public final boolean getAudioModeIsVoip() {
1831 return mAudioModeIsVoip;
1832 }
1833
1834 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001835 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1836 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1837 * start time of the conference.
1838 *
1839 * @return The time at which the {@code Connnection} was connected.
1840 *
1841 * @hide
1842 */
1843 public final long getConnectTimeMillis() {
1844 return mConnectTimeMillis;
1845 }
1846
1847 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001848 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1849 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1850 * start time of the conference.
1851 *
1852 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1853 * changes do not impact the call duration.
1854 *
1855 * @return The time at which the {@link Connection} was connected.
1856 *
1857 * @hide
1858 */
1859 public final long getConnectElapsedTimeMillis() {
1860 return mConnectElapsedTimeMillis;
1861 }
1862
1863 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001864 * @return The status hints for this connection.
1865 */
1866 public final StatusHints getStatusHints() {
1867 return mStatusHints;
1868 }
1869
1870 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001871 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001872 * <p>
1873 * Extras should be updated using {@link #putExtras(Bundle)}.
1874 * <p>
1875 * Telecom or an {@link InCallService} can also update the extras via
1876 * {@link android.telecom.Call#putExtras(Bundle)}, and
1877 * {@link Call#removeExtras(List)}.
1878 * <p>
1879 * The connection is notified of changes to the extras made by Telecom or an
1880 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001881 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001882 * @return The extras associated with this connection.
1883 */
1884 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001885 Bundle extras = null;
1886 synchronized (mExtrasLock) {
1887 if (mExtras != null) {
1888 extras = new Bundle(mExtras);
1889 }
1890 }
1891 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001892 }
1893
1894 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001895 * Assign a listener to be notified of state changes.
1896 *
1897 * @param l A listener.
1898 * @return This Connection.
1899 *
1900 * @hide
1901 */
1902 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001903 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001904 return this;
1905 }
1906
1907 /**
1908 * Remove a previously assigned listener that was being notified of state changes.
1909 *
1910 * @param l A Listener.
1911 * @return This Connection.
1912 *
1913 * @hide
1914 */
1915 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001916 if (l != null) {
1917 mListeners.remove(l);
1918 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001919 return this;
1920 }
1921
1922 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001923 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001924 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001925 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001926 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001927 }
1928
1929 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001930 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1931 * ONLY for debugging purposes.
1932 *
1933 * @param callId The telecom call ID.
1934 * @hide
1935 */
1936 public void setTelecomCallId(String callId) {
1937 mTelecomCallId = callId;
1938 }
1939
1940 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001941 * Inform this Connection that the state of its audio output has been changed externally.
1942 *
1943 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001944 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001945 */
Yorke Lee4af59352015-05-13 14:14:54 -07001946 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001947 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001948 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001949 mCallAudioState = state;
1950 onAudioStateChanged(getAudioState());
1951 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001952 }
1953
1954 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001955 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 * @return A string representation of the value.
1957 */
1958 public static String stateToString(int state) {
1959 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001960 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001961 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001962 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001963 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001964 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001965 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001967 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001968 case STATE_PULLING_CALL:
1969 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001970 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001971 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001972 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001973 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001974 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001975 return "DISCONNECTED";
1976 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001977 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001978 return "UNKNOWN";
1979 }
1980 }
1981
1982 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001983 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001984 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001985 public final int getConnectionCapabilities() {
1986 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001987 }
1988
1989 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07001990 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
1991 */
1992 public final int getConnectionProperties() {
1993 return mConnectionProperties;
1994 }
1995
1996 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001997 * Returns the connection's supported audio routes.
1998 *
1999 * @hide
2000 */
2001 public final int getSupportedAudioRoutes() {
2002 return mSupportedAudioRoutes;
2003 }
2004
2005 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002006 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002007 *
Andrew Lee100e2932014-09-08 15:34:24 -07002008 * @param address The new address.
2009 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002010 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002011 */
Andrew Lee100e2932014-09-08 15:34:24 -07002012 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002013 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002014 Log.d(this, "setAddress %s", address);
2015 mAddress = address;
2016 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002017 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002018 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002019 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002020 }
2021
2022 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002023 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002024 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002025 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002026 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002027 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002028 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002029 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002030 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002031 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002032 mCallerDisplayName = callerDisplayName;
2033 mCallerDisplayNamePresentation = presentation;
2034 for (Listener l : mListeners) {
2035 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2036 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002037 }
2038
2039 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002040 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002041 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2042 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2043 * {@link VideoProfile#STATE_TX_ENABLED},
2044 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002045 *
2046 * @param videoState The new video state.
2047 */
2048 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002049 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002050 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002051 mVideoState = videoState;
2052 for (Listener l : mListeners) {
2053 l.onVideoStateChanged(this, mVideoState);
2054 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002055 }
2056
2057 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002058 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002059 * communicate).
2060 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002061 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002062 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002063 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002064 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065 }
2066
2067 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002068 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002069 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002070 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002071 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002072 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002073 }
2074
2075 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002076 * Sets state to initializing (this Connection is not yet ready to be used).
2077 */
2078 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002079 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002080 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002081 }
2082
2083 /**
2084 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2085 */
2086 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002087 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002088 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002089 }
2090
2091 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002092 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002093 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002094 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002095 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002096 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002097 }
2098
2099 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002100 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2101 * device). Only applicable for {@link Connection}s with
2102 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2103 */
2104 public final void setPulling() {
2105 checkImmutable();
2106 setState(STATE_PULLING_CALL);
2107 }
2108
2109 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002110 * Sets state to be on hold.
2111 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002112 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002113 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002114 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002115 }
2116
2117 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002119 * @param videoProvider The video provider.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002121 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002122 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002123 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002124 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002125 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002126 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002127 }
2128
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002129 public final VideoProvider getVideoProvider() {
2130 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002131 }
2132
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07002133 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002134 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002136 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002137 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002138 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002139 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002141 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002142 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002143 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002144 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002145 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002146 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002147 }
2148
2149 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002150 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2151 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2152 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2153 * to send an {@link #onPostDialContinue(boolean)} signal.
2154 *
2155 * @param remaining The DTMF character sequence remaining to be emitted once the
2156 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2157 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002158 */
2159 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002160 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002161 for (Listener l : mListeners) {
2162 l.onPostDialWait(this, remaining);
2163 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002164 }
2165
2166 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002167 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2168 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002169 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002170 *
2171 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002172 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002173 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002174 checkImmutable();
2175 for (Listener l : mListeners) {
2176 l.onPostDialChar(this, nextChar);
2177 }
2178 }
2179
2180 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002181 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002182 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002183 *
2184 * @param ringback Whether the ringback tone is to be played.
2185 */
Andrew Lee100e2932014-09-08 15:34:24 -07002186 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002187 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002188 if (mRingbackRequested != ringback) {
2189 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002190 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002191 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002192 }
2193 }
Ihab Awadf8358972014-05-28 16:46:42 -07002194 }
2195
2196 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002197 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002198 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002199 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002200 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201 public final void setConnectionCapabilities(int connectionCapabilities) {
2202 checkImmutable();
2203 if (mConnectionCapabilities != connectionCapabilities) {
2204 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002205 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002206 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002207 }
2208 }
Santos Cordonb6939982014-06-04 20:20:58 -07002209 }
2210
2211 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002212 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2213 *
2214 * @param connectionProperties The new connection properties.
2215 */
2216 public final void setConnectionProperties(int connectionProperties) {
2217 checkImmutable();
2218 if (mConnectionProperties != connectionProperties) {
2219 mConnectionProperties = connectionProperties;
2220 for (Listener l : mListeners) {
2221 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2222 }
2223 }
2224 }
2225
2226 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002227 * Sets the supported audio routes.
2228 *
2229 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2230 * See {@link CallAudioState}
2231 * @hide
2232 */
2233 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2234 if ((supportedAudioRoutes
2235 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2236 throw new IllegalArgumentException(
2237 "supported audio routes must include either speaker or earpiece");
2238 }
2239
2240 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2241 mSupportedAudioRoutes = supportedAudioRoutes;
2242 for (Listener l : mListeners) {
2243 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2244 }
2245 }
2246 }
2247
2248 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002249 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002250 */
Evan Charlton36a71342014-07-19 16:31:02 -07002251 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002252 for (Listener l : mListeners) {
2253 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002254 }
Santos Cordonb6939982014-06-04 20:20:58 -07002255 }
2256
2257 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002258 * Requests that the framework use VOIP audio mode for this connection.
2259 *
2260 * @param isVoip True if the audio mode is VOIP.
2261 */
2262 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002263 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002264 mAudioModeIsVoip = isVoip;
2265 for (Listener l : mListeners) {
2266 l.onAudioModeIsVoipChanged(this, isVoip);
2267 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002268 }
2269
2270 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002271 * Sets the time at which a call became active on this Connection. This is set only
2272 * when a conference call becomes active on this connection.
2273 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002274 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2275 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002276 *
2277 * @hide
2278 */
2279 public final void setConnectTimeMillis(long connectTimeMillis) {
2280 mConnectTimeMillis = connectTimeMillis;
2281 }
2282
2283 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002284 * Sets the time at which a call became active on this Connection. This is set only
2285 * when a conference call becomes active on this connection.
2286 *
2287 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2288 * {@link SystemClock#elapsedRealtime()}.
2289 *
2290 * @hide
2291 */
2292 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2293 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2294 }
2295
2296 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002297 * Sets the label and icon status to display in the in-call UI.
2298 *
2299 * @param statusHints The status label and icon to set.
2300 */
2301 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002302 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002303 mStatusHints = statusHints;
2304 for (Listener l : mListeners) {
2305 l.onStatusHintsChanged(this, statusHints);
2306 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002307 }
2308
2309 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002310 * Sets the connections with which this connection can be conferenced.
2311 *
2312 * @param conferenceableConnections The set of connections this connection can conference with.
2313 */
2314 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002315 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002316 clearConferenceableList();
2317 for (Connection c : conferenceableConnections) {
2318 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2319 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002320 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002321 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002322 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002323 }
2324 }
2325 fireOnConferenceableConnectionsChanged();
2326 }
2327
2328 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002329 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2330 * or conferences with which this connection can be conferenced.
2331 *
2332 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002333 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002334 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002335 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002336 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002337 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2338 // small amount of items here.
2339 if (!mConferenceables.contains(c)) {
2340 if (c instanceof Connection) {
2341 Connection connection = (Connection) c;
2342 connection.addConnectionListener(mConnectionDeathListener);
2343 } else if (c instanceof Conference) {
2344 Conference conference = (Conference) c;
2345 conference.addListener(mConferenceDeathListener);
2346 }
2347 mConferenceables.add(c);
2348 }
2349 }
2350 fireOnConferenceableConnectionsChanged();
2351 }
2352
2353 /**
2354 * Returns the connections or conferences with which this connection can be conferenced.
2355 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002356 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002357 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002358 }
2359
Yorke Lee53463962015-08-04 16:07:19 -07002360 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002361 * @hide
2362 */
2363 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002364 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002365 if (mConnectionService != null) {
2366 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2367 "which is already associated with another ConnectionService.");
2368 } else {
2369 mConnectionService = connectionService;
2370 }
2371 }
2372
2373 /**
2374 * @hide
2375 */
2376 public final void unsetConnectionService(ConnectionService connectionService) {
2377 if (mConnectionService != connectionService) {
2378 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2379 "that does not belong to the ConnectionService.");
2380 } else {
2381 mConnectionService = null;
2382 }
2383 }
2384
2385 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002386 * @hide
2387 */
2388 public final ConnectionService getConnectionService() {
2389 return mConnectionService;
2390 }
2391
2392 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002393 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002394 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002395 *
2396 * @param conference The conference.
2397 * @return {@code true} if the conference was successfully set.
2398 * @hide
2399 */
2400 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002401 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002402 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002403 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002404 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002405 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2406 fireConferenceChanged();
2407 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002408 return true;
2409 }
2410 return false;
2411 }
2412
2413 /**
2414 * Resets the conference that this connection is a part of.
2415 * @hide
2416 */
2417 public final void resetConference() {
2418 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002419 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002420 mConference = null;
2421 fireConferenceChanged();
2422 }
2423 }
2424
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002425 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002426 * Set some extras that can be associated with this {@code Connection}.
2427 * <p>
2428 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2429 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2430 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002431 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2432 * {@link #removeExtras(String...)} methods to modify the extras.
2433 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002434 * 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 -07002435 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2436 *
2437 * @param extras The extras associated with this {@code Connection}.
2438 */
2439 public final void setExtras(@Nullable Bundle extras) {
2440 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002441
2442 // Add/replace any new or changed extras values.
2443 putExtras(extras);
2444
2445 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2446 // the current one and remove any keys that went away.
2447 if (mPreviousExtraKeys != null) {
2448 List<String> toRemove = new ArrayList<String>();
2449 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002450 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002451 toRemove.add(oldKey);
2452 }
2453 }
2454 if (!toRemove.isEmpty()) {
2455 removeExtras(toRemove);
2456 }
2457 }
2458
2459 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2460 // called we can see if the caller has removed any extras values.
2461 if (mPreviousExtraKeys == null) {
2462 mPreviousExtraKeys = new ArraySet<String>();
2463 }
2464 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002465 if (extras != null) {
2466 mPreviousExtraKeys.addAll(extras.keySet());
2467 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002468 }
2469
2470 /**
2471 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2472 * added.
2473 * <p>
2474 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2475 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2476 *
2477 * @param extras The extras to add.
2478 */
2479 public final void putExtras(@NonNull Bundle extras) {
2480 checkImmutable();
2481 if (extras == null) {
2482 return;
2483 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002484 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2485 // the listeners.
2486 Bundle listenerExtras;
2487 synchronized (mExtrasLock) {
2488 if (mExtras == null) {
2489 mExtras = new Bundle();
2490 }
2491 mExtras.putAll(extras);
2492 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002493 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002494 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002495 // Create a new clone of the extras for each listener so that they don't clobber
2496 // each other
2497 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002498 }
2499 }
2500
2501 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002502 * Adds a boolean extra to this {@code Connection}.
2503 *
2504 * @param key The extra key.
2505 * @param value The value.
2506 * @hide
2507 */
2508 public final void putExtra(String key, boolean value) {
2509 Bundle newExtras = new Bundle();
2510 newExtras.putBoolean(key, value);
2511 putExtras(newExtras);
2512 }
2513
2514 /**
2515 * Adds an integer extra to this {@code Connection}.
2516 *
2517 * @param key The extra key.
2518 * @param value The value.
2519 * @hide
2520 */
2521 public final void putExtra(String key, int value) {
2522 Bundle newExtras = new Bundle();
2523 newExtras.putInt(key, value);
2524 putExtras(newExtras);
2525 }
2526
2527 /**
2528 * Adds a string extra to this {@code Connection}.
2529 *
2530 * @param key The extra key.
2531 * @param value The value.
2532 * @hide
2533 */
2534 public final void putExtra(String key, String value) {
2535 Bundle newExtras = new Bundle();
2536 newExtras.putString(key, value);
2537 putExtras(newExtras);
2538 }
2539
2540 /**
Eric Erfanianaf7b8c02018-01-17 15:27:39 -08002541 * Adds a parcelable extra to this {@code Connection}.
2542 *
2543 * @param key The extra key.
2544 * @param value The value.
2545 * @hide
2546 */
2547 public final void putExtra(@NonNull String key, @NonNull Parcelable value) {
2548 Bundle newExtras = new Bundle();
2549 newExtras.putParcelable(key, value);
2550 putExtras(newExtras);
2551 }
2552
2553 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002554 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002555 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002556 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002557 */
2558 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002559 synchronized (mExtrasLock) {
2560 if (mExtras != null) {
2561 for (String key : keys) {
2562 mExtras.remove(key);
2563 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002564 }
2565 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002566 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002567 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002568 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002569 }
2570 }
2571
2572 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002573 * Removes extras from this {@code Connection}.
2574 *
2575 * @param keys The keys of the extras to remove.
2576 */
2577 public final void removeExtras(String ... keys) {
2578 removeExtras(Arrays.asList(keys));
2579 }
2580
2581 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002582 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2583 * be change to the {@link #getCallAudioState()}.
2584 * <p>
2585 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2586 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2587 * <p>
2588 * See also {@link InCallService#setAudioRoute(int)}.
2589 *
2590 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2591 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2592 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2593 */
2594 public final void setAudioRoute(int route) {
2595 for (Listener l : mListeners) {
Hall Liua98f58b2017-11-07 17:59:28 -08002596 l.onAudioRouteChanged(this, route, null);
2597 }
2598 }
2599
2600 /**
2601 *
2602 * Request audio routing to a specific bluetooth device. Calling this method may result in
2603 * the device routing audio to a different bluetooth device than the one specified if the
2604 * bluetooth stack is unable to route audio to the requested device.
2605 * A list of available devices can be obtained via
2606 * {@link CallAudioState#getSupportedBluetoothDevices()}
2607 *
2608 * <p>
2609 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2610 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2611 * <p>
2612 * See also {@link InCallService#requestBluetoothAudio(String)}
2613 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2614 * {@link BluetoothDevice#getAddress()}.
2615 */
2616 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2617 for (Listener l : mListeners) {
2618 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08002619 }
2620 }
2621
2622 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002623 * Informs listeners that a previously requested RTT session via
2624 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002625 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002626 */
2627 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002628 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002629 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2630 }
2631
2632 /**
2633 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002634 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002635 * has failed.
2636 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2637 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002638 */
2639 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002640 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002641 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2642 }
2643
2644 /**
2645 * Informs listeners that a currently active RTT session has been terminated by the remote
2646 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002647 */
2648 public final void sendRttSessionRemotelyTerminated() {
2649 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2650 }
2651
2652 /**
2653 * Informs listeners that the remote side of the call has requested an upgrade to include an
2654 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002655 */
2656 public final void sendRemoteRttRequest() {
2657 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2658 }
2659
2660 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002661 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002662 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002663 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002664 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2665 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002666 */
Yorke Lee4af59352015-05-13 14:14:54 -07002667 @SystemApi
2668 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002669 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002670
2671 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002672 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2673 *
2674 * @param state The new connection audio state.
2675 */
2676 public void onCallAudioStateChanged(CallAudioState state) {}
2677
2678 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002679 * Notifies this Connection of an internal state change. This method is called after the
2680 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002681 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002682 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002683 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002684 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002685
2686 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002687 * Notifies this Connection of a request to play a DTMF tone.
2688 *
2689 * @param c A DTMF character.
2690 */
Santos Cordonf2951102014-07-20 19:06:29 -07002691 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002692
2693 /**
2694 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2695 */
Santos Cordonf2951102014-07-20 19:06:29 -07002696 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002697
2698 /**
2699 * Notifies this Connection of a request to disconnect.
2700 */
Santos Cordonf2951102014-07-20 19:06:29 -07002701 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002702
2703 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002704 * Notifies this Connection of a request to disconnect a participant of the conference managed
2705 * by the connection.
2706 *
2707 * @param endpoint the {@link Uri} of the participant to disconnect.
2708 * @hide
2709 */
2710 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2711
2712 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002713 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002714 */
Santos Cordonf2951102014-07-20 19:06:29 -07002715 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002716
2717 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002718 * Notifies this Connection of a request to abort.
2719 */
Santos Cordonf2951102014-07-20 19:06:29 -07002720 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002721
2722 /**
2723 * Notifies this Connection of a request to hold.
2724 */
Santos Cordonf2951102014-07-20 19:06:29 -07002725 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002726
2727 /**
2728 * Notifies this Connection of a request to exit a hold state.
2729 */
Santos Cordonf2951102014-07-20 19:06:29 -07002730 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002731
2732 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002733 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002734 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002735 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002736 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002737 */
Santos Cordonf2951102014-07-20 19:06:29 -07002738 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002739
2740 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002741 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002742 * a request to accept.
2743 */
2744 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002745 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002746 }
2747
2748 /**
2749 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002750 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002751 */
Santos Cordonf2951102014-07-20 19:06:29 -07002752 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002753
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002754 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002755 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2756 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002757 */
2758 public void onReject(String replyMessage) {}
2759
2760 /**
Bryce Leecac50772015-11-17 15:13:29 -08002761 * Notifies the Connection of a request to silence the ringer.
2762 *
2763 * @hide
2764 */
2765 public void onSilence() {}
2766
2767 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002768 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2769 */
Santos Cordonf2951102014-07-20 19:06:29 -07002770 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002771
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002772 /**
2773 * Notifies this Connection of a request to pull an external call to the local device.
2774 * <p>
2775 * The {@link InCallService} issues a request to pull an external call to the local device via
2776 * {@link Call#pullExternalCall()}.
2777 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002778 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2779 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002780 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002781 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002782 */
2783 public void onPullExternalCall() {}
2784
2785 /**
2786 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2787 * <p>
2788 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2789 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002790 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2791 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2792 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2793 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2794 * not aware of.
2795 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002796 * See also {@link Call#sendCallEvent(String, Bundle)}.
2797 *
2798 * @param event The call event.
2799 * @param extras Extras associated with the call event.
2800 */
2801 public void onCallEvent(String event, Bundle extras) {}
2802
Tyler Gunndee56a82016-03-23 16:06:34 -07002803 /**
2804 * Notifies this {@link Connection} of a change to the extras made outside the
2805 * {@link ConnectionService}.
2806 * <p>
2807 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2808 * the {@link android.telecom.Call#putExtras(Bundle)} and
2809 * {@link Call#removeExtras(List)}.
2810 *
2811 * @param extras The new extras bundle.
2812 */
2813 public void onExtrasChanged(Bundle extras) {}
2814
Tyler Gunnf5035432017-01-09 09:43:12 -08002815 /**
2816 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2817 * displaying its incoming call user interface for the {@link Connection}.
2818 * <p>
2819 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2820 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2821 * should show its own incoming call user interface.
2822 * <p>
2823 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2824 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2825 * user interface to allow the user to choose whether to answer the new incoming call and
2826 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002827 * <p>
2828 * You should trigger the display of the incoming call user interface for your application by
2829 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2830 * For example:
2831 * <pre><code>
2832 * // Create an intent which triggers your fullscreen incoming call user interface.
2833 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2834 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2835 * intent.setClass(context, YourIncomingCallActivity.class);
2836 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2837 *
2838 * // Build the notification as an ongoing high priority item; this ensures it will show as
2839 * // a heads up notification which slides down over top of the current content.
2840 * final Notification.Builder builder = new Notification.Builder(context);
2841 * builder.setOngoing(true);
2842 * builder.setPriority(Notification.PRIORITY_HIGH);
2843 *
2844 * // Set notification content intent to take user to fullscreen UI if user taps on the
2845 * // notification body.
2846 * builder.setContentIntent(pendingIntent);
2847 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2848 * // manager deems it appropriate.
2849 * builder.setFullScreenIntent(pendingIntent, true);
2850 *
2851 * // Setup notification content.
2852 * builder.setSmallIcon( yourIconResourceId );
2853 * builder.setContentTitle("Your notification title");
2854 * builder.setContentText("Your notification content.");
2855 *
2856 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2857 *
2858 * NotificationManager notificationManager = mContext.getSystemService(
2859 * NotificationManager.class);
2860 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2861 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002862 */
2863 public void onShowIncomingCallUi() {}
2864
Hall Liub64ac4c2017-02-06 10:49:48 -08002865 /**
2866 * Notifies this {@link Connection} that the user has requested an RTT session.
2867 * The connection service should call {@link #sendRttInitiationSuccess} or
2868 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2869 * request, respectively.
2870 * @param rttTextStream The object that should be used to send text to or receive text from
2871 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002872 */
2873 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2874
2875 /**
2876 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2877 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002878 */
2879 public void onStopRtt() {}
2880
2881 /**
2882 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2883 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2884 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2885 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002886 * @param rttTextStream The object that should be used to send text to or receive text from
2887 * the in-call app.
2888 */
2889 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2890
Hall Liuffa4a812017-03-02 16:11:00 -08002891 /**
2892 * Internal method to set {@link #PROPERTY_IS_RTT}.
2893 * @hide
2894 */
2895 void setRttProperty() {
2896 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2897 }
2898
2899 /**
2900 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2901 * @hide
2902 */
2903 void unsetRttProperty() {
2904 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2905 }
2906
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002907 static String toLogSafePhoneNumber(String number) {
2908 // For unknown number, log empty string.
2909 if (number == null) {
2910 return "";
2911 }
2912
2913 if (PII_DEBUG) {
2914 // When PII_DEBUG is true we emit PII.
2915 return number;
2916 }
2917
2918 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2919 // sanitized phone numbers.
2920 StringBuilder builder = new StringBuilder();
2921 for (int i = 0; i < number.length(); i++) {
2922 char c = number.charAt(i);
2923 if (c == '-' || c == '@' || c == '.') {
2924 builder.append(c);
2925 } else {
2926 builder.append('x');
2927 }
2928 }
2929 return builder.toString();
2930 }
2931
Ihab Awad542e0ea2014-05-16 10:22:16 -07002932 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002933 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002934 if (mState == STATE_DISCONNECTED && mState != state) {
2935 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002936 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002937 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002938 if (mState != state) {
2939 Log.d(this, "setState: %s", stateToString(state));
2940 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002941 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002942 for (Listener l : mListeners) {
2943 l.onStateChanged(this, state);
2944 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002945 }
2946 }
2947
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002948 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002949 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002950 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2951 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002952 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002953 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002954
2955 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002956 if (mImmutable) {
2957 throw new UnsupportedOperationException("Connection is immutable");
2958 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002959 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002960 }
2961
Evan Charltonbf11f982014-07-20 22:06:28 -07002962 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002963 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002964 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2965 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002966 * <p>
2967 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2968 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002969 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002970 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002971 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002972 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002973 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2974 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002975 }
2976
Evan Charltonbf11f982014-07-20 22:06:28 -07002977 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002978 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2979 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2980 * this should never be un-@hide-den.
2981 *
2982 * @hide
2983 */
2984 public void checkImmutable() {}
2985
2986 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002987 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2988 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2989 * that state. This connection should not be used for anything, and no other
2990 * {@code Connection}s should be attempted.
2991 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002992 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002993 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002994 * @return A {@code Connection} which indicates that the underlying connection should
2995 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002996 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002997 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002998 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002999 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003000
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003001 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003002 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003003 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003004 }
3005 }
3006
Santos Cordon823fd3c2014-08-07 18:35:18 -07003007 private final void fireConferenceChanged() {
3008 for (Listener l : mListeners) {
3009 l.onConferenceChanged(this, mConference);
3010 }
3011 }
3012
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003013 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003014 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003015 if (c instanceof Connection) {
3016 Connection connection = (Connection) c;
3017 connection.removeConnectionListener(mConnectionDeathListener);
3018 } else if (c instanceof Conference) {
3019 Conference conference = (Conference) c;
3020 conference.removeListener(mConferenceDeathListener);
3021 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003022 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003023 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003024 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003025
3026 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003027 * Handles a change to extras received from Telecom.
3028 *
3029 * @param extras The new extras.
3030 * @hide
3031 */
3032 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003033 Bundle b = null;
3034 synchronized (mExtrasLock) {
3035 mExtras = extras;
3036 if (mExtras != null) {
3037 b = new Bundle(mExtras);
3038 }
3039 }
3040 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003041 }
3042
3043 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003044 * Notifies listeners that the merge request failed.
3045 *
3046 * @hide
3047 */
3048 protected final void notifyConferenceMergeFailed() {
3049 for (Listener l : mListeners) {
3050 l.onConferenceMergeFailed(this);
3051 }
3052 }
3053
3054 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003055 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003056 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003057 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003058 * @hide
3059 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003060 protected final void updateConferenceParticipants(
3061 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003062 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003063 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003064 }
3065 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003066
3067 /**
3068 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003069 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003070 */
3071 protected void notifyConferenceStarted() {
3072 for (Listener l : mListeners) {
3073 l.onConferenceStarted();
3074 }
3075 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003076
3077 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003078 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3079 * be a part of a conference call.
3080 * @param isConferenceSupported {@code true} if the connection supports being part of a
3081 * conference call, {@code false} otherwise.
3082 * @hide
3083 */
3084 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3085 for (Listener l : mListeners) {
3086 l.onConferenceSupportedChanged(this, isConferenceSupported);
3087 }
3088 }
3089
3090 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303091 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3092 * changed due to an emergency call being redialed.
3093 * @param pHandle The new PhoneAccountHandle for this connection.
3094 * @hide
3095 */
3096 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3097 for (Listener l : mListeners) {
3098 l.onPhoneAccountChanged(this, pHandle);
3099 }
3100 }
3101
3102 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003103 * Sets the {@link PhoneAccountHandle} associated with this connection.
3104 *
3105 * @hide
3106 */
3107 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3108 if (mPhoneAccountHandle != phoneAccountHandle) {
3109 mPhoneAccountHandle = phoneAccountHandle;
3110 notifyPhoneAccountChanged(phoneAccountHandle);
3111 }
3112 }
3113
3114 /**
3115 * Returns the {@link PhoneAccountHandle} associated with this connection.
3116 *
3117 * @hide
3118 */
3119 public PhoneAccountHandle getPhoneAccountHandle() {
3120 return mPhoneAccountHandle;
3121 }
3122
3123 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003124 * Sends an event associated with this {@code Connection} with associated event extras to the
3125 * {@link InCallService}.
3126 * <p>
3127 * Connection events are used to communicate point in time information from a
3128 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3129 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3130 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3131 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3132 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3133 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3134 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3135 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3136 * <p>
3137 * Events are exposed to {@link InCallService} implementations via
3138 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3139 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003140 * 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 -07003141 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3142 * some events altogether.
3143 * <p>
3144 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3145 * conflicts between {@link ConnectionService} implementations. Further, custom
3146 * {@link ConnectionService} implementations shall not re-purpose events in the
3147 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3148 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3149 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3150 * {@code com.example.extra.MY_EXTRA}).
3151 * <p>
3152 * When defining events and the associated extras, it is important to keep their behavior
3153 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3154 * events/extras should me maintained to ensure backwards compatibility with older
3155 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003156 *
3157 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003158 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003159 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003160 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003161 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003162 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003163 }
3164 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003165}