blob: 25e67c8ee17bb2fa08174686529c5f9e56c0e787 [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 Liua98f58b52017-11-07 17:59:28 -080027import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070039import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Hall Liue9041242018-02-09 16:40:03 -080043import java.io.FileInputStream;
44import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080045import java.io.IOException;
46import java.io.InputStreamReader;
47import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070048import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070049import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070051import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070052import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070053import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070054
55/**
Santos Cordon895d4b82015-06-25 16:41:48 -070056 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
57 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070058 * <p>
59 * Implementations create a custom subclass of {@code Connection} and return it to the framework
60 * as the return value of
61 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
62 * or
63 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
64 * Implementations are then responsible for updating the state of the {@code Connection}, and
65 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
66 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070067 * <p>
68 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
69 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
70 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
71 * {@code Connection} instance.
72 * <p>
73 * Basic call support requires overriding the following methods: {@link #onAnswer()},
74 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
75 * <p>
76 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
77 * {@link #onUnhold()} methods should be overridden to provide hold support for the
78 * {@code Connection}.
79 * <p>
80 * Where a {@code Connection} supports a variation of video calling (e.g. the
81 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
82 * to support answering a call as a video call.
83 * <p>
84 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
85 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
86 * support for pulling the external call.
87 * <p>
88 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
89 * overridden.
90 * <p>
91 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
92 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
93 * for example, call events from a {@link InCallService} are handled,
94 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
95 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
96 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
97 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070098 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070099public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700100
Santos Cordon895d4b82015-06-25 16:41:48 -0700101 /**
102 * The connection is initializing. This is generally the first state for a {@code Connection}
103 * returned by a {@link ConnectionService}.
104 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 public static final int STATE_INITIALIZING = 0;
106
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 /**
108 * The connection is new and not connected.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_NEW = 1;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * An incoming connection is in the ringing state. During this state, the user's ringer or
114 * vibration feature will be activated.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_RINGING = 2;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * An outgoing connection is in the dialing state. In this state the other party has not yet
120 * answered the call and the user traditionally hears a ringback tone.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_DIALING = 3;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * A connection is active. Both parties are connected to the call and can actively communicate.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_ACTIVE = 4;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * A connection is on hold.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_HOLDING = 5;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
135 * A connection has been disconnected. This is the final state once the user has been
136 * disconnected from a call either locally, remotely or by an error in the service.
137 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 public static final int STATE_DISCONNECTED = 6;
139
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700141 * The state of an external connection which is in the process of being pulled from a remote
142 * device to the local device.
143 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700144 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
146 */
147 public static final int STATE_PULLING_CALL = 7;
148
149 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700150 * Connection can currently be put on hold or unheld. This is distinct from
151 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
152 * it does not at the moment support the function. This can be true while the call is in the
153 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
154 * display a disabled 'hold' button.
155 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 public static final int CAPABILITY_HOLD = 0x00000001;
157
158 /** Connection supports the hold feature. */
159 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
160
161 /**
162 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
163 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
164 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
165 * capability allows a merge button to be shown while the conference is in the foreground
166 * of the in-call UI.
167 * <p>
168 * This is only intended for use by a {@link Conference}.
169 */
170 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
171
172 /**
173 * Connections within a conference can be swapped between foreground and background.
174 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
175 * <p>
176 * This is only intended for use by a {@link Conference}.
177 */
178 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
179
180 /**
181 * @hide
182 */
183 public static final int CAPABILITY_UNUSED = 0x00000010;
184
185 /** Connection supports responding via text option. */
186 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
187
188 /** Connection can be muted. */
189 public static final int CAPABILITY_MUTE = 0x00000040;
190
191 /**
192 * Connection supports conference management. This capability only applies to
193 * {@link Conference}s which can have {@link Connection}s as children.
194 */
195 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
196
197 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700200 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700210 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212
213 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800215 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
217
218 /**
219 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 */
221 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
222
223 /**
224 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700226 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700227 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800228
229 /**
230 * Connection is able to be separated from its parent {@code Conference}, if any.
231 */
232 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
233
234 /**
235 * Connection is able to be individually disconnected when in a {@code Conference}.
236 */
237 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
238
239 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700240 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800241 * @hide
242 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * @hide
248 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250
251 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * @hide
254 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256
Tyler Gunn068085b2015-02-06 13:56:52 -0800257 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800259 * @hide
260 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700261 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800262
Tyler Gunn96d6c402015-03-18 12:39:23 -0700263 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500264 * Speed up audio setup for MT call.
265 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700266 */
267 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800268
Rekha Kumar07366812015-03-24 16:42:31 -0700269 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700270 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700271 */
272 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
273
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 /**
275 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700276 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700277 */
278 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
279
Tyler Gunnd4091732015-06-29 09:15:37 -0700280 /**
281 * For a conference, indicates the conference will not have child connections.
282 * <p>
283 * An example of a conference with child connections is a GSM conference call, where the radio
284 * retains connections to the individual participants of the conference. Another example is an
285 * IMS conference call where conference event package functionality is supported; in this case
286 * the conference server ensures the radio is aware of the participants in the conference, which
287 * are represented by child connections.
288 * <p>
289 * An example of a conference with no child connections is an IMS conference call with no
290 * conference event package support. Such a conference is represented by the radio as a single
291 * connection to the IMS conference server.
292 * <p>
293 * Indicating whether a conference has children or not is important to help user interfaces
294 * visually represent a conference. A conference with no children, for example, will have the
295 * conference connection shown in the list of calls on a Bluetooth device, where if the
296 * conference has children, only the children will be shown in the list of calls on a Bluetooth
297 * device.
298 * @hide
299 */
300 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
301
Bryce Lee81901682015-08-28 16:38:02 -0700302 /**
303 * Indicates that the connection itself wants to handle any sort of reply response, rather than
304 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700305 */
306 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
307
Tyler Gunnf97a0092016-01-19 15:59:34 -0800308 /**
309 * When set, prevents a video call from being downgraded to an audio-only call.
310 * <p>
311 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
312 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
313 * downgraded from a video call back to a VideoState of
314 * {@link VideoProfile#STATE_AUDIO_ONLY}.
315 * <p>
316 * Intuitively, a call which can be downgraded to audio should also have local and remote
317 * video
318 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
319 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
320 */
321 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
322
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700323 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700324 * When set for an external connection, indicates that this {@code Connection} can be pulled
325 * from a remote device to the current device.
326 * <p>
327 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
328 * is set.
329 */
330 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
331
Pooja Jaind34698d2017-12-28 14:15:31 +0530332 /** Call supports the deflect feature. */
333 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
334
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530336 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700337 //**********************************************************************************************
338
339 /**
340 * Indicates that the current device callback number should be shown.
341 *
342 * @hide
343 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700344 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700345
346 /**
347 * Whether the call is a generic conference, where we do not know the precise state of
348 * participants in the conference (eg. on CDMA).
349 *
350 * @hide
351 */
352 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
353
354 /**
355 * Connection is using high definition audio.
356 * @hide
357 */
358 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
359
360 /**
361 * Connection is using WIFI.
362 * @hide
363 */
364 public static final int PROPERTY_WIFI = 1<<3;
365
366 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367 * When set, indicates that the {@code Connection} does not actually exist locally for the
368 * {@link ConnectionService}.
369 * <p>
370 * Consider, for example, a scenario where a user has two devices with the same phone number.
371 * When a user places a call on one devices, the telephony stack can represent that call on the
372 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700373 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700374 * <p>
375 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
376 * external connections. Only those {@link InCallService}s which have the
377 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
378 * manifest will see external connections.
379 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700381
Brad Ebinger15847072016-05-18 11:08:36 -0700382 /**
383 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
384 */
385 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700386
Hall Liu9f332c72016-07-14 15:37:37 -0700387 /**
388 * Indicates that the connection represents a downgraded IMS conference.
389 * @hide
390 */
391 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
392
Tyler Gunnf5035432017-01-09 09:43:12 -0800393 /**
394 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
395 * {@link ConnectionService}.
396 * <p>
397 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
398 */
399 public static final int PROPERTY_SELF_MANAGED = 1<<7;
400
Hall Liu95d55872017-01-25 17:12:49 -0800401 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800402 * Set by the framework to indicate that a connection has an active RTT session associated with
403 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800404 */
405 public static final int PROPERTY_IS_RTT = 1 << 8;
406
Eric Erfanianec881872017-12-06 16:27:53 -0800407 /**
408 * Set by the framework to indicate that a connection is using assisted dialing.
409 * @hide
410 */
411 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
412
Tyler Gunn96d6c402015-03-18 12:39:23 -0700413 //**********************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800414 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700415 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800416
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700417 /**
418 * Connection extra key used to store the last forwarded number associated with the current
419 * connection. Used to communicate to the user interface that the connection was forwarded via
420 * the specified number.
421 */
422 public static final String EXTRA_LAST_FORWARDED_NUMBER =
423 "android.telecom.extra.LAST_FORWARDED_NUMBER";
424
425 /**
426 * Connection extra key used to store a child number associated with the current connection.
427 * Used to communicate to the user interface that the connection was received via
428 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
429 * address.
430 */
431 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
432
433 /**
434 * Connection extra key used to store the subject for an incoming call. The user interface can
435 * query this extra and display its contents for incoming calls. Will only be used if the
436 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
437 */
438 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
439
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800440 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700441 * Boolean connection extra key set on a {@link Connection} in
442 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
443 * current active foreground call to be dropped.
444 */
445 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
446 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
447
448 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700449 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
450 * state to indicate the name of the third-party app which is responsible for the current
451 * foreground call.
452 * <p>
453 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
454 * is able to inform the user that answering the new incoming call will cause a call owned by
455 * another app to be dropped when the incoming call is answered.
456 */
457 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
458 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
459
460 /**
Hall Liu10208662016-06-15 17:55:00 -0700461 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700462 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700463 * @hide
464 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700465 public static final String EXTRA_DISABLE_ADD_CALL =
466 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700467
468 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700469 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
470 * original Connection ID associated with the connection. Used in
471 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
472 * connection/conference added via
473 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
474 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
475 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
476 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
477 * be a way to ensure that we don't add the connection again as a duplicate.
478 * <p>
479 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
480 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
481 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
482 * in a new {@link Connection} which it adds to Telecom via
483 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
484 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
485 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
486 * ID it originally referred to the connection as. Thus Telecom needs to know that the
487 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
488 * @hide
489 */
490 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
491 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
492
493 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800494 * Connection event used to inform Telecom that it should play the on hold tone. This is used
495 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700496 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800497 * @hide
498 */
499 public static final String EVENT_ON_HOLD_TONE_START =
500 "android.telecom.event.ON_HOLD_TONE_START";
501
502 /**
503 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
504 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700505 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800506 * @hide
507 */
508 public static final String EVENT_ON_HOLD_TONE_END =
509 "android.telecom.event.ON_HOLD_TONE_END";
510
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700511 /**
512 * Connection event used to inform {@link InCallService}s when pulling of an external call has
513 * failed. The user interface should inform the user of the error.
514 * <p>
515 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
516 * API is called on a {@link Call} with the properties
517 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
518 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
519 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700520 * <p>
521 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
522 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700523 */
524 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
525
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700526 /**
527 * Connection event used to inform {@link InCallService}s when the merging of two calls has
528 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700529 * <p>
530 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
531 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700532 */
533 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
534
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700535 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700536 * Connection event used to inform {@link InCallService}s when the process of merging a
537 * Connection into a conference has begun.
538 * <p>
539 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
540 * expected to be null when this connection event is used.
541 * @hide
542 */
543 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
544
545 /**
546 * Connection event used to inform {@link InCallService}s when the process of merging a
547 * Connection into a conference has completed.
548 * <p>
549 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
550 * expected to be null when this connection event is used.
551 * @hide
552 */
553 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
554
555 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700556 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
557 * the remote party.
558 * <p>
559 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
560 * call is being held locally on the device. When a capable {@link ConnectionService} receives
561 * signalling to indicate that the remote party has put the call on hold, it can send this
562 * connection event.
563 * @hide
564 */
565 public static final String EVENT_CALL_REMOTELY_HELD =
566 "android.telecom.event.CALL_REMOTELY_HELD";
567
568 /**
569 * Connection event used to inform {@link InCallService}s when a call which was remotely held
570 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
571 * <p>
572 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
573 * call is being held locally on the device. When a capable {@link ConnectionService} receives
574 * signalling to indicate that the remote party has taken the call off hold, it can send this
575 * connection event.
576 * @hide
577 */
578 public static final String EVENT_CALL_REMOTELY_UNHELD =
579 "android.telecom.event.CALL_REMOTELY_UNHELD";
580
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700581 /**
582 * Connection event used to inform an {@link InCallService} which initiated a call handover via
583 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
584 * successfully completed.
585 * @hide
586 */
587 public static final String EVENT_HANDOVER_COMPLETE =
588 "android.telecom.event.HANDOVER_COMPLETE";
589
590 /**
591 * Connection event used to inform an {@link InCallService} which initiated a call handover via
592 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
593 * to complete.
594 * @hide
595 */
596 public static final String EVENT_HANDOVER_FAILED =
597 "android.telecom.event.HANDOVER_FAILED";
598
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 // Flag controlling whether PII is emitted into the logs
600 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
601
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800602 /**
603 * Whether the given capabilities support the specified capability.
604 *
605 * @param capabilities A capability bit field.
606 * @param capability The capability to check capabilities for.
607 * @return Whether the specified capability is supported.
608 * @hide
609 */
610 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800611 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800612 }
613
614 /**
615 * Whether the capabilities of this {@code Connection} supports the specified capability.
616 *
617 * @param capability The capability to check capabilities for.
618 * @return Whether the specified capability is supported.
619 * @hide
620 */
621 public boolean can(int capability) {
622 return can(mConnectionCapabilities, capability);
623 }
624
625 /**
626 * Removes the specified capability from the set of capabilities of this {@code Connection}.
627 *
628 * @param capability The capability to remove from the set.
629 * @hide
630 */
631 public void removeCapability(int capability) {
632 mConnectionCapabilities &= ~capability;
633 }
634
635 /**
636 * Adds the specified capability to the set of capabilities of this {@code Connection}.
637 *
638 * @param capability The capability to add to the set.
639 * @hide
640 */
641 public void addCapability(int capability) {
642 mConnectionCapabilities |= capability;
643 }
644
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700645 /**
646 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
647 *
648 * @param capabilities A capability bit field.
649 * @return A human readable string representation.
650 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800651 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700652 return capabilitiesToStringInternal(capabilities, true /* isLong */);
653 }
654
655 /**
656 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
657 * string.
658 *
659 * @param capabilities A capability bit field.
660 * @return A human readable string representation.
661 * @hide
662 */
663 public static String capabilitiesToStringShort(int capabilities) {
664 return capabilitiesToStringInternal(capabilities, false /* isLong */);
665 }
666
667 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800668 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append("[");
670 if (isLong) {
671 builder.append("Capabilities:");
672 }
673
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800676 }
677 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800679 }
680 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 }
683 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 }
686 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800688 }
689 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700690 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 }
692 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800694 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700696 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700697 }
698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700700 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700701 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800703 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700704 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700706 }
707 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700708 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700709 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700710 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800712 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800713 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700714 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800715 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500716 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500718 }
Rekha Kumar07366812015-03-24 16:42:31 -0700719 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700721 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700722 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700724 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700725 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700726 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700727 }
Bryce Lee81901682015-08-28 16:38:02 -0700728 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700729 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700730 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700731 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700732 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700733 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530734 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
735 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
736 }
Bryce Lee81901682015-08-28 16:38:02 -0700737
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 builder.append("]");
739 return builder.toString();
740 }
741
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700742 /**
743 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
744 *
745 * @param properties A property bit field.
746 * @return A human readable string representation.
747 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700748 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 return propertiesToStringInternal(properties, true /* isLong */);
750 }
751
752 /**
753 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
754 *
755 * @param properties A property bit field.
756 * @return A human readable string representation.
757 * @hide
758 */
759 public static String propertiesToStringShort(int properties) {
760 return propertiesToStringInternal(properties, false /* isLong */);
761 }
762
763 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700764 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700765 builder.append("[");
766 if (isLong) {
767 builder.append("Properties:");
768 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700769
Tyler Gunnf5035432017-01-09 09:43:12 -0800770 if (can(properties, PROPERTY_SELF_MANAGED)) {
771 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
772 }
773
Hall Liu25c7c4d2016-08-30 13:41:02 -0700774 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
775 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700776 }
777
778 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700780 }
781
782 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700784 }
785
786 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700787 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700788 }
789
790 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700791 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700792 }
793
Brad Ebinger15847072016-05-18 11:08:36 -0700794 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700795 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700796 }
797
Hall Liuee575082018-01-29 17:22:02 -0800798 if (can(properties, PROPERTY_IS_RTT)) {
799 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
800 }
801
Tyler Gunn720c6642016-03-22 09:02:47 -0700802 builder.append("]");
803 return builder.toString();
804 }
805
Sailesh Nepal091768c2014-06-30 15:15:23 -0700806 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700807 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700808 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700809 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700810 public void onCallerDisplayNameChanged(
811 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700812 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700813 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700814 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800815 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700816 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700817 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800818 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700819 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800820 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 public void onVideoProviderChanged(
822 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700823 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
824 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800825 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700826 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700827 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700828 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800829 public void onConferenceParticipantsChanged(Connection c,
830 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800831 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700832 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700833 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700834 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700835 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700836 /** @hide */
837 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800838 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800839 public void onRttInitiationSuccess(Connection c) {}
840 public void onRttInitiationFailure(Connection c, int reason) {}
841 public void onRttSessionRemotelyTerminated(Connection c) {}
842 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530843 /** @hide */
844 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700845 }
846
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 /**
Hall Liu95d55872017-01-25 17:12:49 -0800848 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800849 */
850 public static final class RttTextStream {
851 private static final int READ_BUFFER_SIZE = 1000;
852 private final InputStreamReader mPipeFromInCall;
853 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800854 private final ParcelFileDescriptor mFdFromInCall;
855 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800856 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
857
858 /**
859 * @hide
860 */
861 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800862 mFdFromInCall = fromInCall;
863 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800864 mPipeFromInCall = new InputStreamReader(
Hall Liue9041242018-02-09 16:40:03 -0800865 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800866 mPipeToInCall = new OutputStreamWriter(
Hall Liue9041242018-02-09 16:40:03 -0800867 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800868 }
869
870 /**
871 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
872 * RTT transmits text in real-time, this method should be called as often as text snippets
873 * are received from the remote user, even if it is only one character.
Hall Liue9041242018-02-09 16:40:03 -0800874 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800875 * This method is not thread-safe -- calling it from multiple threads simultaneously may
876 * lead to interleaved text.
Hall Liue9041242018-02-09 16:40:03 -0800877 *
Hall Liu95d55872017-01-25 17:12:49 -0800878 * @param input The message to send to the in-call app.
879 */
880 public void write(String input) throws IOException {
881 mPipeToInCall.write(input);
882 mPipeToInCall.flush();
883 }
884
885
886 /**
887 * Reads a string from the in-call app, blocking if there is no data available. Returns
888 * {@code null} if the RTT conversation has been terminated and there is no further data
889 * to read.
Hall Liue9041242018-02-09 16:40:03 -0800890 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800891 * This method is not thread-safe -- calling it from multiple threads simultaneously may
892 * lead to interleaved text.
Hall Liue9041242018-02-09 16:40:03 -0800893 *
Hall Liu95d55872017-01-25 17:12:49 -0800894 * @return A string containing text entered by the user, or {@code null} if the
895 * conversation has been terminated or if there was an error while reading.
896 */
Hall Liuffa4a812017-03-02 16:11:00 -0800897 public String read() throws IOException {
898 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
899 if (numRead < 0) {
900 return null;
901 }
902 return new String(mReadBuffer, 0, numRead);
903 }
904
905 /**
906 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
907 * be read.
Hall Liue9041242018-02-09 16:40:03 -0800908 *
Hall Liuffa4a812017-03-02 16:11:00 -0800909 * @return A string containing text entered by the user, or {@code null} if the user has
910 * not entered any new text yet.
911 */
912 public String readImmediately() throws IOException {
913 if (mPipeFromInCall.ready()) {
914 return read();
915 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800916 return null;
917 }
918 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800919
920 /** @hide */
921 public ParcelFileDescriptor getFdFromInCall() {
922 return mFdFromInCall;
923 }
924
925 /** @hide */
926 public ParcelFileDescriptor getFdToInCall() {
927 return mFdToInCall;
928 }
929 }
930
931 /**
932 * Provides constants to represent the results of responses to session modify requests sent via
933 * {@link Call#sendRttRequest()}
934 */
935 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700936 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800937 /**
938 * Session modify request was successful.
939 */
940 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
941
942 /**
943 * Session modify request failed.
944 */
945 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
946
947 /**
948 * Session modify request ignored due to invalid parameters.
949 */
950 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
951
952 /**
953 * Session modify request timed out.
954 */
955 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
956
957 /**
958 * Session modify request rejected by remote user.
959 */
960 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800961 }
962
963 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700964 * Provides a means of controlling the video session associated with a {@link Connection}.
965 * <p>
966 * Implementations create a custom subclass of {@link VideoProvider} and the
967 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
968 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
969 * should set the {@link VideoProvider}.
970 * <p>
971 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
972 * {@link InCallService} implementations to issue requests related to the video session;
973 * it provides a means for the {@link ConnectionService} to report events and information
974 * related to the video session to Telecom and the {@link InCallService} implementations.
975 * <p>
976 * {@link InCallService} implementations interact with the {@link VideoProvider} via
977 * {@link android.telecom.InCallService.VideoCall}.
978 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 /**
981 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700982 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 */
984 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700985
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700987 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
988 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 */
990 public static final int SESSION_EVENT_RX_RESUME = 2;
991
992 /**
993 * Video transmission has begun. This occurs after a negotiated start of video transmission
994 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700995 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700996 */
997 public static final int SESSION_EVENT_TX_START = 3;
998
999 /**
1000 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1001 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001002 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001003 */
1004 public static final int SESSION_EVENT_TX_STOP = 4;
1005
1006 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001007 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001008 * this as a cue to inform the user the camera is not available.
1009 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001010 */
1011 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1012
1013 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001014 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001015 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001016 * the camera has become available again.
1017 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001018 */
1019 public static final int SESSION_EVENT_CAMERA_READY = 6;
1020
1021 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001022 * Session event raised by Telecom when
1023 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1024 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1025 * @see #handleCallSessionEvent(int)
1026 */
1027 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1028
1029 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001030 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001031 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001032 */
1033 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1034
1035 /**
1036 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001037 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 */
1039 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1040
1041 /**
1042 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001043 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 */
1045 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1046
Rekha Kumar07366812015-03-24 16:42:31 -07001047 /**
1048 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001050 */
1051 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1052
1053 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001054 * Session modify request rejected by remote user.
1055 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001056 */
1057 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1058
Tyler Gunn75958422015-04-15 14:23:42 -07001059 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 private static final int MSG_SET_CAMERA = 2;
1061 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1062 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1063 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1064 private static final int MSG_SET_ZOOM = 6;
1065 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1066 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1067 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001068 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001070 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001071
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001072 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1073 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1074 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1075 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1076 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1077 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001078 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1079 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001080 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1081
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001082 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001084
1085 /**
1086 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001087 *
1088 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1089 * load factor before resizing, 1 means we only expect a single thread to
1090 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001091 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001092 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1093 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001094
1095 /**
1096 * Default handler used to consolidate binder method calls onto a single thread.
1097 */
1098 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001099 public VideoProviderHandler() {
1100 super();
1101 }
1102
1103 public VideoProviderHandler(Looper looper) {
1104 super(looper);
1105 }
1106
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 @Override
1108 public void handleMessage(Message msg) {
1109 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001110 case MSG_ADD_VIDEO_CALLBACK: {
1111 IBinder binder = (IBinder) msg.obj;
1112 IVideoCallback callback = IVideoCallback.Stub
1113 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001114 if (callback == null) {
1115 Log.w(this, "addVideoProvider - skipped; callback is null.");
1116 break;
1117 }
1118
Tyler Gunn75958422015-04-15 14:23:42 -07001119 if (mVideoCallbacks.containsKey(binder)) {
1120 Log.i(this, "addVideoProvider - skipped; already present.");
1121 break;
1122 }
1123 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001124 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001125 }
1126 case MSG_REMOVE_VIDEO_CALLBACK: {
1127 IBinder binder = (IBinder) msg.obj;
1128 IVideoCallback callback = IVideoCallback.Stub
1129 .asInterface((IBinder) msg.obj);
1130 if (!mVideoCallbacks.containsKey(binder)) {
1131 Log.i(this, "removeVideoProvider - skipped; not present.");
1132 break;
1133 }
1134 mVideoCallbacks.remove(binder);
1135 break;
1136 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001137 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001138 {
1139 SomeArgs args = (SomeArgs) msg.obj;
1140 try {
1141 onSetCamera((String) args.arg1);
1142 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001143 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001144 } finally {
1145 args.recycle();
1146 }
1147 }
1148 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001149 case MSG_SET_PREVIEW_SURFACE:
1150 onSetPreviewSurface((Surface) msg.obj);
1151 break;
1152 case MSG_SET_DISPLAY_SURFACE:
1153 onSetDisplaySurface((Surface) msg.obj);
1154 break;
1155 case MSG_SET_DEVICE_ORIENTATION:
1156 onSetDeviceOrientation(msg.arg1);
1157 break;
1158 case MSG_SET_ZOOM:
1159 onSetZoom((Float) msg.obj);
1160 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001161 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1162 SomeArgs args = (SomeArgs) msg.obj;
1163 try {
1164 onSendSessionModifyRequest((VideoProfile) args.arg1,
1165 (VideoProfile) args.arg2);
1166 } finally {
1167 args.recycle();
1168 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001169 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001170 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001171 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1172 onSendSessionModifyResponse((VideoProfile) msg.obj);
1173 break;
1174 case MSG_REQUEST_CAMERA_CAPABILITIES:
1175 onRequestCameraCapabilities();
1176 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001177 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1178 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 break;
1180 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001181 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001182 break;
1183 default:
1184 break;
1185 }
1186 }
1187 }
1188
1189 /**
1190 * IVideoProvider stub implementation.
1191 */
1192 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001193 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001194 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001195 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1196 }
1197
1198 public void removeVideoCallback(IBinder videoCallbackBinder) {
1199 mMessageHandler.obtainMessage(
1200 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 }
1202
Tyler Gunn159f35c2017-03-02 09:28:37 -08001203 public void setCamera(String cameraId, String callingPackageName,
1204 int targetSdkVersion) {
1205
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001206 SomeArgs args = SomeArgs.obtain();
1207 args.arg1 = cameraId;
1208 // Propagate the calling package; originally determined in
1209 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1210 // process.
1211 args.arg2 = callingPackageName;
1212 // Pass along the uid and pid of the calling app; this gets lost when we put the
1213 // message onto the handler. These are required for Telecom to perform a permission
1214 // check to see if the calling app is able to use the camera.
1215 args.argi1 = Binder.getCallingUid();
1216 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001217 // Pass along the target SDK version of the calling InCallService. This is used to
1218 // maintain backwards compatibility of the API for older callers.
1219 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001220 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001221 }
1222
1223 public void setPreviewSurface(Surface surface) {
1224 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1225 }
1226
1227 public void setDisplaySurface(Surface surface) {
1228 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1229 }
1230
1231 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001232 mMessageHandler.obtainMessage(
1233 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001234 }
1235
1236 public void setZoom(float value) {
1237 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1238 }
1239
Tyler Gunn45382162015-05-06 08:52:27 -07001240 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1241 SomeArgs args = SomeArgs.obtain();
1242 args.arg1 = fromProfile;
1243 args.arg2 = toProfile;
1244 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001245 }
1246
1247 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1248 mMessageHandler.obtainMessage(
1249 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1250 }
1251
1252 public void requestCameraCapabilities() {
1253 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1254 }
1255
1256 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001257 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 }
1259
Yorke Lee32f24732015-05-12 16:18:03 -07001260 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001261 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1262 }
1263 }
1264
1265 public VideoProvider() {
1266 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001267 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001268 }
1269
1270 /**
1271 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1272 *
1273 * @param looper The looper.
1274 * @hide
1275 */
1276 public VideoProvider(Looper looper) {
1277 mBinder = new VideoProvider.VideoProviderBinder();
1278 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 }
1280
1281 /**
1282 * Returns binder object which can be used across IPC methods.
1283 * @hide
1284 */
1285 public final IVideoProvider getInterface() {
1286 return mBinder;
1287 }
1288
1289 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001290 * 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 * Sent from the {@link InCallService} via
1297 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001298 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001299 * @param cameraId The id of the camera (use ids as reported by
1300 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 */
1302 public abstract void onSetCamera(String cameraId);
1303
1304 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001305 * Sets the camera to be used for the outgoing video.
1306 * <p>
1307 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1308 * camera via
1309 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1310 * <p>
1311 * This prototype is used internally to ensure that the calling package name, UID and PID
1312 * are sent to Telecom so that can perform a camera permission check on the caller.
1313 * <p>
1314 * Sent from the {@link InCallService} via
1315 * {@link InCallService.VideoCall#setCamera(String)}.
1316 *
1317 * @param cameraId The id of the camera (use ids as reported by
1318 * {@link CameraManager#getCameraIdList()}).
1319 * @param callingPackageName The AppOpps package name of the caller.
1320 * @param callingUid The UID of the caller.
1321 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001322 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001323 * @hide
1324 */
1325 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001326 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001327
1328 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001329 * Sets the surface to be used for displaying a preview of what the user's camera is
1330 * currently capturing. When video transmission is enabled, this is the video signal which
1331 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001332 * <p>
1333 * Sent from the {@link InCallService} via
1334 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001336 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 */
1338 public abstract void onSetPreviewSurface(Surface surface);
1339
1340 /**
1341 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001342 * <p>
1343 * Sent from the {@link InCallService} via
1344 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001345 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001346 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 */
1348 public abstract void onSetDisplaySurface(Surface surface);
1349
1350 /**
1351 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1352 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001353 * <p>
1354 * Sent from the {@link InCallService} via
1355 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 *
1357 * @param rotation The device orientation, in degrees.
1358 */
1359 public abstract void onSetDeviceOrientation(int rotation);
1360
1361 /**
1362 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001363 * <p>
1364 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 *
1366 * @param value The camera zoom ratio.
1367 */
1368 public abstract void onSetZoom(float value);
1369
1370 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001371 * Issues a request to modify the properties of the current video session.
1372 * <p>
1373 * Example scenarios include: requesting an audio-only call to be upgraded to a
1374 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1375 * when the {@link InCallService} is no longer the foreground application.
1376 * <p>
1377 * If the {@link VideoProvider} determines a request to be invalid, it should call
1378 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1379 * invalid request back to the {@link InCallService}.
1380 * <p>
1381 * Where a request requires confirmation from the user of the peer device, the
1382 * {@link VideoProvider} must communicate the request to the peer device and handle the
1383 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1384 * is used to inform the {@link InCallService} of the result of the request.
1385 * <p>
1386 * Sent from the {@link InCallService} via
1387 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001389 * @param fromProfile The video profile prior to the request.
1390 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001391 */
Tyler Gunn45382162015-05-06 08:52:27 -07001392 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1393 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394
Tyler Gunnb702ef82015-05-29 11:51:53 -07001395 /**
1396 * Provides a response to a request to change the current video session properties.
1397 * <p>
1398 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1399 * video call, could decline the request and keep the call as audio-only.
1400 * In such a scenario, the {@code responseProfile} would have a video state of
1401 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1402 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1403 * <p>
1404 * Sent from the {@link InCallService} via
1405 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1406 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1407 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001410 */
1411 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1412
1413 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001414 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1415 * <p>
1416 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1417 * camera via
1418 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1419 * <p>
1420 * Sent from the {@link InCallService} via
1421 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 */
1423 public abstract void onRequestCameraCapabilities();
1424
1425 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001426 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1427 * video component of the current {@link Connection}.
1428 * <p>
1429 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1430 * via {@link VideoProvider#setCallDataUsage(long)}.
1431 * <p>
1432 * Sent from the {@link InCallService} via
1433 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001434 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001435 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436
1437 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001438 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1439 * the peer device when the video signal is paused.
1440 * <p>
1441 * Sent from the {@link InCallService} via
1442 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001443 *
1444 * @param uri URI of image to display.
1445 */
Yorke Lee32f24732015-05-12 16:18:03 -07001446 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001447
1448 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001449 * Used to inform listening {@link InCallService} implementations when the
1450 * {@link VideoProvider} receives a session modification request.
1451 * <p>
1452 * Received by the {@link InCallService} via
1453 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001455 * @param videoProfile The requested video profile.
1456 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 */
1458 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001459 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001460 for (IVideoCallback callback : mVideoCallbacks.values()) {
1461 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001462 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001463 } catch (RemoteException ignored) {
1464 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001465 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 }
1467 }
1468 }
1469
1470 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001471 * Used to inform listening {@link InCallService} implementations when the
1472 * {@link VideoProvider} receives a response to a session modification request.
1473 * <p>
1474 * Received by the {@link InCallService} via
1475 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1476 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 *
1478 * @param status Status of the session modify request. Valid values are
1479 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1480 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001481 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1482 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1483 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1484 * @param requestedProfile The original request which was sent to the peer device.
1485 * @param responseProfile The actual profile changes agreed to by the peer device.
1486 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 */
1488 public void receiveSessionModifyResponse(int status,
1489 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001490 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001491 for (IVideoCallback callback : mVideoCallbacks.values()) {
1492 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001493 callback.receiveSessionModifyResponse(status, requestedProfile,
1494 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001495 } catch (RemoteException ignored) {
1496 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001497 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001498 }
1499 }
1500 }
1501
1502 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001503 * Used to inform listening {@link InCallService} implementations when the
1504 * {@link VideoProvider} reports a call session event.
1505 * <p>
1506 * Received by the {@link InCallService} via
1507 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001509 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1510 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1511 * {@link VideoProvider#SESSION_EVENT_TX_START},
1512 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1513 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001514 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1515 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001516 */
1517 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001518 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001519 for (IVideoCallback callback : mVideoCallbacks.values()) {
1520 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001521 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001522 } catch (RemoteException ignored) {
1523 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001524 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 }
1526 }
1527 }
1528
1529 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001530 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1531 * peer's video have changed.
1532 * <p>
1533 * This could occur if, for example, the peer rotates their device, changing the aspect
1534 * ratio of the video, or if the user switches between the back and front cameras.
1535 * <p>
1536 * Received by the {@link InCallService} via
1537 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001538 *
1539 * @param width The updated peer video width.
1540 * @param height The updated peer video height.
1541 */
1542 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001543 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001544 for (IVideoCallback callback : mVideoCallbacks.values()) {
1545 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001546 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001547 } catch (RemoteException ignored) {
1548 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001549 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 }
1551 }
1552 }
1553
1554 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001555 * Used to inform listening {@link InCallService} implementations when the data usage of the
1556 * video associated with the current {@link Connection} has changed.
1557 * <p>
1558 * This could be in response to a preview request via
1559 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001560 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1561 * 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 -07001562 * <p>
1563 * Received by the {@link InCallService} via
1564 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001565 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001566 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1567 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001568 */
Yorke Lee32f24732015-05-12 16:18:03 -07001569 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001570 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001571 for (IVideoCallback callback : mVideoCallbacks.values()) {
1572 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001573 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001574 } catch (RemoteException ignored) {
1575 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001576 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001577 }
1578 }
1579 }
1580
1581 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001582 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001583 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001584 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001585 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1586 * @hide
1587 */
1588 public void changeCallDataUsage(long dataUsage) {
1589 setCallDataUsage(dataUsage);
1590 }
1591
1592 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001593 * Used to inform listening {@link InCallService} implementations when the capabilities of
1594 * the current camera have changed.
1595 * <p>
1596 * The {@link VideoProvider} should call this in response to
1597 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1598 * changed via {@link VideoProvider#onSetCamera(String)}.
1599 * <p>
1600 * Received by the {@link InCallService} via
1601 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1602 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001603 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001605 */
Yorke Lee400470f2015-05-12 13:31:25 -07001606 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001607 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001608 for (IVideoCallback callback : mVideoCallbacks.values()) {
1609 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001610 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001611 } catch (RemoteException ignored) {
1612 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001613 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 }
1615 }
1616 }
Rekha Kumar07366812015-03-24 16:42:31 -07001617
1618 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001619 * Used to inform listening {@link InCallService} implementations when the video quality
1620 * of the call has changed.
1621 * <p>
1622 * Received by the {@link InCallService} via
1623 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001624 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001625 * @param videoQuality The updated video quality. Valid values:
1626 * {@link VideoProfile#QUALITY_HIGH},
1627 * {@link VideoProfile#QUALITY_MEDIUM},
1628 * {@link VideoProfile#QUALITY_LOW},
1629 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001630 */
1631 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001632 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001633 for (IVideoCallback callback : mVideoCallbacks.values()) {
1634 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001635 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001636 } catch (RemoteException ignored) {
1637 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001638 }
Rekha Kumar07366812015-03-24 16:42:31 -07001639 }
1640 }
1641 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001642
1643 /**
1644 * Returns a string representation of a call session event.
1645 *
1646 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1647 * @return String representation of the call session event.
1648 * @hide
1649 */
1650 public static String sessionEventToString(int event) {
1651 switch (event) {
1652 case SESSION_EVENT_CAMERA_FAILURE:
1653 return SESSION_EVENT_CAMERA_FAILURE_STR;
1654 case SESSION_EVENT_CAMERA_READY:
1655 return SESSION_EVENT_CAMERA_READY_STR;
1656 case SESSION_EVENT_RX_PAUSE:
1657 return SESSION_EVENT_RX_PAUSE_STR;
1658 case SESSION_EVENT_RX_RESUME:
1659 return SESSION_EVENT_RX_RESUME_STR;
1660 case SESSION_EVENT_TX_START:
1661 return SESSION_EVENT_TX_START_STR;
1662 case SESSION_EVENT_TX_STOP:
1663 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001664 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1665 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001666 default:
1667 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1668 }
1669 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001670 }
1671
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001672 private final Listener mConnectionDeathListener = new Listener() {
1673 @Override
1674 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001675 if (mConferenceables.remove(c)) {
1676 fireOnConferenceableConnectionsChanged();
1677 }
1678 }
1679 };
1680
1681 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1682 @Override
1683 public void onDestroyed(Conference c) {
1684 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001685 fireOnConferenceableConnectionsChanged();
1686 }
1687 }
1688 };
1689
Jay Shrauner229e3822014-08-15 09:23:07 -07001690 /**
1691 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1692 * load factor before resizing, 1 means we only expect a single thread to
1693 * access the map so make only a single shard
1694 */
1695 private final Set<Listener> mListeners = Collections.newSetFromMap(
1696 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001697 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1698 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001699 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001700
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001701 // The internal telecom call ID associated with this connection.
1702 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001703 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001704 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001705 private Uri mAddress;
1706 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001707 private String mCallerDisplayName;
1708 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001709 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001710 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001711 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001712 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001713 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001714 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001715 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001716 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001717 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001718 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001719 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001720 private Conference mConference;
1721 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001722 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001723 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001724
1725 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001726 * Tracks the key set for the extras bundle provided on the last invocation of
1727 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1728 * keys which were set previously but are no longer present in the replacement Bundle.
1729 */
1730 private Set<String> mPreviousExtraKeys;
1731
1732 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001733 * Create a new Connection.
1734 */
Santos Cordonf2951102014-07-20 19:06:29 -07001735 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001736
1737 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001738 * Returns the Telecom internal call ID associated with this connection. Should only be used
1739 * for debugging and tracing purposes.
1740 *
1741 * @return The Telecom call ID.
1742 * @hide
1743 */
1744 public final String getTelecomCallId() {
1745 return mTelecomCallId;
1746 }
1747
1748 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001749 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001750 */
Andrew Lee100e2932014-09-08 15:34:24 -07001751 public final Uri getAddress() {
1752 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001753 }
1754
1755 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001756 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001757 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001758 */
Andrew Lee100e2932014-09-08 15:34:24 -07001759 public final int getAddressPresentation() {
1760 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001761 }
1762
1763 /**
1764 * @return The caller display name (CNAP).
1765 */
1766 public final String getCallerDisplayName() {
1767 return mCallerDisplayName;
1768 }
1769
1770 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001771 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001772 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001773 */
1774 public final int getCallerDisplayNamePresentation() {
1775 return mCallerDisplayNamePresentation;
1776 }
1777
1778 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001779 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001780 */
1781 public final int getState() {
1782 return mState;
1783 }
1784
1785 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001786 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001787 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1788 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1789 * {@link VideoProfile#STATE_TX_ENABLED},
1790 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001791 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001792 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001793 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001794 */
1795 public final int getVideoState() {
1796 return mVideoState;
1797 }
1798
1799 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001800 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001801 * being routed by the system. This is {@code null} if this Connection
1802 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001803 * @deprecated Use {@link #getCallAudioState()} instead.
1804 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805 */
Yorke Lee4af59352015-05-13 14:14:54 -07001806 @SystemApi
1807 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001808 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001809 if (mCallAudioState == null) {
1810 return null;
1811 }
Yorke Lee4af59352015-05-13 14:14:54 -07001812 return new AudioState(mCallAudioState);
1813 }
1814
1815 /**
1816 * @return The audio state of the connection, describing how its audio is currently
1817 * being routed by the system. This is {@code null} if this Connection
1818 * does not directly know about its audio state.
1819 */
1820 public final CallAudioState getCallAudioState() {
1821 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001822 }
1823
1824 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001825 * @return The conference that this connection is a part of. Null if it is not part of any
1826 * conference.
1827 */
1828 public final Conference getConference() {
1829 return mConference;
1830 }
1831
1832 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001833 * Returns whether this connection is requesting that the system play a ringback tone
1834 * on its behalf.
1835 */
Andrew Lee100e2932014-09-08 15:34:24 -07001836 public final boolean isRingbackRequested() {
1837 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001838 }
1839
1840 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001841 * @return True if the connection's audio mode is VOIP.
1842 */
1843 public final boolean getAudioModeIsVoip() {
1844 return mAudioModeIsVoip;
1845 }
1846
1847 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001848 * Retrieves the connection start time of the {@code Connnection}, 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 * @return The time at which the {@code Connnection} was connected.
1853 *
1854 * @hide
1855 */
1856 public final long getConnectTimeMillis() {
1857 return mConnectTimeMillis;
1858 }
1859
1860 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001861 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1862 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1863 * start time of the conference.
1864 *
1865 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1866 * changes do not impact the call duration.
1867 *
1868 * @return The time at which the {@link Connection} was connected.
1869 *
1870 * @hide
1871 */
1872 public final long getConnectElapsedTimeMillis() {
1873 return mConnectElapsedTimeMillis;
1874 }
1875
1876 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001877 * @return The status hints for this connection.
1878 */
1879 public final StatusHints getStatusHints() {
1880 return mStatusHints;
1881 }
1882
1883 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001884 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001885 * <p>
1886 * Extras should be updated using {@link #putExtras(Bundle)}.
1887 * <p>
1888 * Telecom or an {@link InCallService} can also update the extras via
1889 * {@link android.telecom.Call#putExtras(Bundle)}, and
1890 * {@link Call#removeExtras(List)}.
1891 * <p>
1892 * The connection is notified of changes to the extras made by Telecom or an
1893 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001894 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001895 * @return The extras associated with this connection.
1896 */
1897 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001898 Bundle extras = null;
1899 synchronized (mExtrasLock) {
1900 if (mExtras != null) {
1901 extras = new Bundle(mExtras);
1902 }
1903 }
1904 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001905 }
1906
1907 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001908 * Assign a listener to be notified of state changes.
1909 *
1910 * @param l A listener.
1911 * @return This Connection.
1912 *
1913 * @hide
1914 */
1915 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001916 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001917 return this;
1918 }
1919
1920 /**
1921 * Remove a previously assigned listener that was being notified of state changes.
1922 *
1923 * @param l A Listener.
1924 * @return This Connection.
1925 *
1926 * @hide
1927 */
1928 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001929 if (l != null) {
1930 mListeners.remove(l);
1931 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001932 return this;
1933 }
1934
1935 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001936 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001937 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001938 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001939 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001940 }
1941
1942 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001943 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1944 * ONLY for debugging purposes.
1945 *
1946 * @param callId The telecom call ID.
1947 * @hide
1948 */
1949 public void setTelecomCallId(String callId) {
1950 mTelecomCallId = callId;
1951 }
1952
1953 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001954 * Inform this Connection that the state of its audio output has been changed externally.
1955 *
1956 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001957 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001958 */
Yorke Lee4af59352015-05-13 14:14:54 -07001959 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001960 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001961 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001962 mCallAudioState = state;
1963 onAudioStateChanged(getAudioState());
1964 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001965 }
1966
1967 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001968 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001969 * @return A string representation of the value.
1970 */
1971 public static String stateToString(int state) {
1972 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001973 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001974 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001975 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001976 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001978 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001979 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001980 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001981 case STATE_PULLING_CALL:
1982 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001983 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001984 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001985 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001986 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001987 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001988 return "DISCONNECTED";
1989 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001990 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001991 return "UNKNOWN";
1992 }
1993 }
1994
1995 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001996 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001997 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001998 public final int getConnectionCapabilities() {
1999 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002000 }
2001
2002 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002003 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2004 */
2005 public final int getConnectionProperties() {
2006 return mConnectionProperties;
2007 }
2008
2009 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002010 * Returns the connection's supported audio routes.
2011 *
2012 * @hide
2013 */
2014 public final int getSupportedAudioRoutes() {
2015 return mSupportedAudioRoutes;
2016 }
2017
2018 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002019 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002020 *
Andrew Lee100e2932014-09-08 15:34:24 -07002021 * @param address The new address.
2022 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002023 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002024 */
Andrew Lee100e2932014-09-08 15:34:24 -07002025 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002026 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002027 Log.d(this, "setAddress %s", address);
2028 mAddress = address;
2029 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002030 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002031 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002032 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002033 }
2034
2035 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002036 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002037 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002038 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002039 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002040 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002041 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002042 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002043 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002044 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002045 mCallerDisplayName = callerDisplayName;
2046 mCallerDisplayNamePresentation = presentation;
2047 for (Listener l : mListeners) {
2048 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2049 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002050 }
2051
2052 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002053 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002054 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2055 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2056 * {@link VideoProfile#STATE_TX_ENABLED},
2057 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002058 *
2059 * @param videoState The new video state.
2060 */
2061 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002062 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002063 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002064 mVideoState = videoState;
2065 for (Listener l : mListeners) {
2066 l.onVideoStateChanged(this, mVideoState);
2067 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002068 }
2069
2070 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002071 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002072 * communicate).
2073 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002074 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002075 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002076 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002077 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002078 }
2079
2080 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002081 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002082 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002083 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002084 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002085 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002086 }
2087
2088 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002089 * Sets state to initializing (this Connection is not yet ready to be used).
2090 */
2091 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002092 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002093 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002094 }
2095
2096 /**
2097 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2098 */
2099 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002101 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002102 }
2103
2104 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002105 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002106 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002107 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002108 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002109 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002110 }
2111
2112 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002113 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2114 * device). Only applicable for {@link Connection}s with
2115 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2116 */
2117 public final void setPulling() {
2118 checkImmutable();
2119 setState(STATE_PULLING_CALL);
2120 }
2121
2122 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002123 * Sets state to be on hold.
2124 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002125 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002126 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002127 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002128 }
2129
2130 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002131 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002132 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002134 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002135 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002136 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002137 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002138 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002139 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002140 }
2141
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002142 public final VideoProvider getVideoProvider() {
2143 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002144 }
2145
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002146 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002147 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002148 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002149 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002150 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002151 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002152 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002153 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002154 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002155 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002156 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002157 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002158 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002159 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002160 }
2161
2162 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002163 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2164 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2165 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2166 * to send an {@link #onPostDialContinue(boolean)} signal.
2167 *
2168 * @param remaining The DTMF character sequence remaining to be emitted once the
2169 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2170 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002171 */
2172 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002173 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002174 for (Listener l : mListeners) {
2175 l.onPostDialWait(this, remaining);
2176 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002177 }
2178
2179 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002180 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2181 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002182 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002183 *
2184 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002185 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002186 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002187 checkImmutable();
2188 for (Listener l : mListeners) {
2189 l.onPostDialChar(this, nextChar);
2190 }
2191 }
2192
2193 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002194 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002195 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002196 *
2197 * @param ringback Whether the ringback tone is to be played.
2198 */
Andrew Lee100e2932014-09-08 15:34:24 -07002199 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002200 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002201 if (mRingbackRequested != ringback) {
2202 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002203 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002204 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002205 }
2206 }
Ihab Awadf8358972014-05-28 16:46:42 -07002207 }
2208
2209 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002210 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002211 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002212 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002213 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002214 public final void setConnectionCapabilities(int connectionCapabilities) {
2215 checkImmutable();
2216 if (mConnectionCapabilities != connectionCapabilities) {
2217 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002218 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002219 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002220 }
2221 }
Santos Cordonb6939982014-06-04 20:20:58 -07002222 }
2223
2224 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002225 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2226 *
2227 * @param connectionProperties The new connection properties.
2228 */
2229 public final void setConnectionProperties(int connectionProperties) {
2230 checkImmutable();
2231 if (mConnectionProperties != connectionProperties) {
2232 mConnectionProperties = connectionProperties;
2233 for (Listener l : mListeners) {
2234 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2235 }
2236 }
2237 }
2238
2239 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002240 * Sets the supported audio routes.
2241 *
2242 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2243 * See {@link CallAudioState}
2244 * @hide
2245 */
2246 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2247 if ((supportedAudioRoutes
2248 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2249 throw new IllegalArgumentException(
2250 "supported audio routes must include either speaker or earpiece");
2251 }
2252
2253 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2254 mSupportedAudioRoutes = supportedAudioRoutes;
2255 for (Listener l : mListeners) {
2256 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2257 }
2258 }
2259 }
2260
2261 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002262 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002263 */
Evan Charlton36a71342014-07-19 16:31:02 -07002264 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002265 for (Listener l : mListeners) {
2266 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002267 }
Santos Cordonb6939982014-06-04 20:20:58 -07002268 }
2269
2270 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002271 * Requests that the framework use VOIP audio mode for this connection.
2272 *
2273 * @param isVoip True if the audio mode is VOIP.
2274 */
2275 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002276 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002277 mAudioModeIsVoip = isVoip;
2278 for (Listener l : mListeners) {
2279 l.onAudioModeIsVoipChanged(this, isVoip);
2280 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002281 }
2282
2283 /**
Roshan Piuse927ec02015-07-15 15:47:21 -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 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002287 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2288 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002289 *
2290 * @hide
2291 */
2292 public final void setConnectTimeMillis(long connectTimeMillis) {
2293 mConnectTimeMillis = connectTimeMillis;
2294 }
2295
2296 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002297 * Sets the time at which a call became active on this Connection. This is set only
2298 * when a conference call becomes active on this connection.
2299 *
2300 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2301 * {@link SystemClock#elapsedRealtime()}.
2302 *
2303 * @hide
2304 */
Tyler Gunn17541392018-02-01 08:58:38 -08002305 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002306 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2307 }
2308
2309 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002310 * Sets the label and icon status to display in the in-call UI.
2311 *
2312 * @param statusHints The status label and icon to set.
2313 */
2314 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002315 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002316 mStatusHints = statusHints;
2317 for (Listener l : mListeners) {
2318 l.onStatusHintsChanged(this, statusHints);
2319 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002320 }
2321
2322 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002323 * Sets the connections with which this connection can be conferenced.
2324 *
2325 * @param conferenceableConnections The set of connections this connection can conference with.
2326 */
2327 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002328 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002329 clearConferenceableList();
2330 for (Connection c : conferenceableConnections) {
2331 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2332 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002333 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002334 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002335 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002336 }
2337 }
2338 fireOnConferenceableConnectionsChanged();
2339 }
2340
2341 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002342 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2343 * or conferences with which this connection can be conferenced.
2344 *
2345 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002346 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002347 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002348 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002349 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002350 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2351 // small amount of items here.
2352 if (!mConferenceables.contains(c)) {
2353 if (c instanceof Connection) {
2354 Connection connection = (Connection) c;
2355 connection.addConnectionListener(mConnectionDeathListener);
2356 } else if (c instanceof Conference) {
2357 Conference conference = (Conference) c;
2358 conference.addListener(mConferenceDeathListener);
2359 }
2360 mConferenceables.add(c);
2361 }
2362 }
2363 fireOnConferenceableConnectionsChanged();
2364 }
2365
2366 /**
2367 * Returns the connections or conferences with which this connection can be conferenced.
2368 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002369 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002370 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002371 }
2372
Yorke Lee53463962015-08-04 16:07:19 -07002373 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002374 * @hide
2375 */
2376 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002377 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002378 if (mConnectionService != null) {
2379 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2380 "which is already associated with another ConnectionService.");
2381 } else {
2382 mConnectionService = connectionService;
2383 }
2384 }
2385
2386 /**
2387 * @hide
2388 */
2389 public final void unsetConnectionService(ConnectionService connectionService) {
2390 if (mConnectionService != connectionService) {
2391 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2392 "that does not belong to the ConnectionService.");
2393 } else {
2394 mConnectionService = null;
2395 }
2396 }
2397
2398 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002399 * @hide
2400 */
2401 public final ConnectionService getConnectionService() {
2402 return mConnectionService;
2403 }
2404
2405 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002406 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002407 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002408 *
2409 * @param conference The conference.
2410 * @return {@code true} if the conference was successfully set.
2411 * @hide
2412 */
2413 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002414 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002415 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002416 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002417 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002418 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2419 fireConferenceChanged();
2420 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002421 return true;
2422 }
2423 return false;
2424 }
2425
2426 /**
2427 * Resets the conference that this connection is a part of.
2428 * @hide
2429 */
2430 public final void resetConference() {
2431 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002432 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002433 mConference = null;
2434 fireConferenceChanged();
2435 }
2436 }
2437
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002438 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002439 * Set some extras that can be associated with this {@code Connection}.
2440 * <p>
2441 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2442 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2443 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002444 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2445 * {@link #removeExtras(String...)} methods to modify the extras.
2446 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002447 * 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 -07002448 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2449 *
2450 * @param extras The extras associated with this {@code Connection}.
2451 */
2452 public final void setExtras(@Nullable Bundle extras) {
2453 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002454
2455 // Add/replace any new or changed extras values.
2456 putExtras(extras);
2457
2458 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2459 // the current one and remove any keys that went away.
2460 if (mPreviousExtraKeys != null) {
2461 List<String> toRemove = new ArrayList<String>();
2462 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002463 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002464 toRemove.add(oldKey);
2465 }
2466 }
2467 if (!toRemove.isEmpty()) {
2468 removeExtras(toRemove);
2469 }
2470 }
2471
2472 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2473 // called we can see if the caller has removed any extras values.
2474 if (mPreviousExtraKeys == null) {
2475 mPreviousExtraKeys = new ArraySet<String>();
2476 }
2477 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002478 if (extras != null) {
2479 mPreviousExtraKeys.addAll(extras.keySet());
2480 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002481 }
2482
2483 /**
2484 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2485 * added.
2486 * <p>
2487 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2488 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2489 *
2490 * @param extras The extras to add.
2491 */
2492 public final void putExtras(@NonNull Bundle extras) {
2493 checkImmutable();
2494 if (extras == null) {
2495 return;
2496 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002497 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2498 // the listeners.
2499 Bundle listenerExtras;
2500 synchronized (mExtrasLock) {
2501 if (mExtras == null) {
2502 mExtras = new Bundle();
2503 }
2504 mExtras.putAll(extras);
2505 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002506 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002507 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002508 // Create a new clone of the extras for each listener so that they don't clobber
2509 // each other
2510 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002511 }
2512 }
2513
2514 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002515 * Adds a boolean 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, boolean value) {
2522 Bundle newExtras = new Bundle();
2523 newExtras.putBoolean(key, value);
2524 putExtras(newExtras);
2525 }
2526
2527 /**
2528 * Adds an integer 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, int value) {
2535 Bundle newExtras = new Bundle();
2536 newExtras.putInt(key, value);
2537 putExtras(newExtras);
2538 }
2539
2540 /**
2541 * Adds a string 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(String key, String value) {
2548 Bundle newExtras = new Bundle();
2549 newExtras.putString(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 Liua98f58b52017-11-07 17:59:28 -08002596 l.onAudioRouteChanged(this, route, null);
2597 }
2598 }
2599
2600 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002601 * Request audio routing to a specific bluetooth device. Calling this method may result in
2602 * the device routing audio to a different bluetooth device than the one specified if the
2603 * bluetooth stack is unable to route audio to the requested device.
2604 * A list of available devices can be obtained via
2605 * {@link CallAudioState#getSupportedBluetoothDevices()}
2606 *
2607 * <p>
2608 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2609 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2610 * <p>
Hall Liu15392832018-04-02 13:52:57 -07002611 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2612 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002613 */
Hall Liu15392832018-04-02 13:52:57 -07002614 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002615 for (Listener l : mListeners) {
Hall Liu15392832018-04-02 13:52:57 -07002616 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2617 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002618 }
2619 }
2620
2621 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002622 * Informs listeners that a previously requested RTT session via
2623 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu13ee5762017-12-04 14:19:30 -08002624 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002625 */
2626 public final void sendRttInitiationSuccess() {
2627 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2628 }
2629
2630 /**
2631 * Informs listeners that a previously requested RTT session via
Hall Liu13ee5762017-12-04 14:19:30 -08002632 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002633 * has failed.
2634 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2635 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 */
2637 public final void sendRttInitiationFailure(int reason) {
2638 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2639 }
2640
2641 /**
2642 * Informs listeners that a currently active RTT session has been terminated by the remote
2643 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002644 */
2645 public final void sendRttSessionRemotelyTerminated() {
2646 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2647 }
2648
2649 /**
2650 * Informs listeners that the remote side of the call has requested an upgrade to include an
2651 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002652 */
2653 public final void sendRemoteRttRequest() {
2654 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2655 }
2656
2657 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002658 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002659 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002660 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002661 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2662 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002663 */
Yorke Lee4af59352015-05-13 14:14:54 -07002664 @SystemApi
2665 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002666 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002667
2668 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002669 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2670 *
2671 * @param state The new connection audio state.
2672 */
2673 public void onCallAudioStateChanged(CallAudioState state) {}
2674
2675 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002676 * Notifies this Connection of an internal state change. This method is called after the
2677 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002678 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002679 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002680 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002681 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002682
2683 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002684 * Notifies this Connection of a request to play a DTMF tone.
2685 *
2686 * @param c A DTMF character.
2687 */
Santos Cordonf2951102014-07-20 19:06:29 -07002688 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002689
2690 /**
2691 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2692 */
Santos Cordonf2951102014-07-20 19:06:29 -07002693 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002694
2695 /**
2696 * Notifies this Connection of a request to disconnect.
2697 */
Santos Cordonf2951102014-07-20 19:06:29 -07002698 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002699
2700 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002701 * Notifies this Connection of a request to disconnect a participant of the conference managed
2702 * by the connection.
2703 *
2704 * @param endpoint the {@link Uri} of the participant to disconnect.
2705 * @hide
2706 */
2707 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2708
2709 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002710 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002711 */
Santos Cordonf2951102014-07-20 19:06:29 -07002712 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002713
2714 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002715 * Notifies this Connection of a request to abort.
2716 */
Santos Cordonf2951102014-07-20 19:06:29 -07002717 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002718
2719 /**
2720 * Notifies this Connection of a request to hold.
2721 */
Santos Cordonf2951102014-07-20 19:06:29 -07002722 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002723
2724 /**
2725 * Notifies this Connection of a request to exit a hold state.
2726 */
Santos Cordonf2951102014-07-20 19:06:29 -07002727 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002728
2729 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002730 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002731 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002732 * <p>
2733 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2734 * the default dialer's {@link InCallService}.
2735 * <p>
2736 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2737 * Telecom framework may request that the call is answered in the following circumstances:
2738 * <ul>
2739 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2740 * <li>A car mode {@link InCallService} is in use which has declared
2741 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2742 * {@link InCallService} will be able to see calls from self-managed
2743 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2744 * behalf.</li>
2745 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002746 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002747 */
Santos Cordonf2951102014-07-20 19:06:29 -07002748 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002749
2750 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002751 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002752 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002753 * <p>
2754 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2755 * the default dialer's {@link InCallService}.
2756 * <p>
2757 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2758 * Telecom framework may request that the call is answered in the following circumstances:
2759 * <ul>
2760 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2761 * <li>A car mode {@link InCallService} is in use which has declared
2762 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2763 * {@link InCallService} will be able to see calls from self-managed
2764 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2765 * behalf.</li>
2766 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002767 */
2768 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002769 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002770 }
2771
2772 /**
2773 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302774 * a request to deflect.
2775 */
2776 public void onDeflect(Uri address) {}
2777
2778 /**
2779 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002780 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002781 * <p>
2782 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2783 * the default dialer's {@link InCallService}.
2784 * <p>
2785 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2786 * Telecom framework may request that the call is rejected in the following circumstances:
2787 * <ul>
2788 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2789 * <li>A car mode {@link InCallService} is in use which has declared
2790 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2791 * {@link InCallService} will be able to see calls from self-managed
2792 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2793 * behalf.</li>
2794 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002795 */
Santos Cordonf2951102014-07-20 19:06:29 -07002796 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002797
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002798 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002799 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2800 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002801 */
2802 public void onReject(String replyMessage) {}
2803
2804 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002805 * Notifies this Connection of a request to silence the ringer.
2806 * <p>
2807 * The ringer may be silenced by any of the following methods:
2808 * <ul>
2809 * <li>{@link TelecomManager#silenceRinger()}</li>
2810 * <li>The user presses the volume-down button while a call is ringing.</li>
2811 * </ul>
2812 * <p>
2813 * Self-managed {@link ConnectionService} implementations should override this method in their
2814 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2815 * your app set the ringtone as part of the incoming call {@link Notification} (see
2816 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2817 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2818 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2819 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002820 */
2821 public void onSilence() {}
2822
2823 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002824 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2825 */
Santos Cordonf2951102014-07-20 19:06:29 -07002826 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002827
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002828 /**
2829 * Notifies this Connection of a request to pull an external call to the local device.
2830 * <p>
2831 * The {@link InCallService} issues a request to pull an external call to the local device via
2832 * {@link Call#pullExternalCall()}.
2833 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002834 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2835 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002836 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002837 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002838 */
2839 public void onPullExternalCall() {}
2840
2841 /**
2842 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2843 * <p>
2844 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2845 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002846 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2847 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2848 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2849 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2850 * not aware of.
2851 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002852 * See also {@link Call#sendCallEvent(String, Bundle)}.
2853 *
2854 * @param event The call event.
2855 * @param extras Extras associated with the call event.
2856 */
2857 public void onCallEvent(String event, Bundle extras) {}
2858
Tyler Gunndee56a82016-03-23 16:06:34 -07002859 /**
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002860 * Notifies this {@link Connection} that a handover has completed.
2861 * <p>
2862 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2863 * Bundle)} on the initiating side of the handover, and on the receiving side with
2864 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2865 */
2866 public void onHandoverComplete() {}
2867
2868 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002869 * Notifies this {@link Connection} of a change to the extras made outside the
2870 * {@link ConnectionService}.
2871 * <p>
2872 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2873 * the {@link android.telecom.Call#putExtras(Bundle)} and
2874 * {@link Call#removeExtras(List)}.
2875 *
2876 * @param extras The new extras bundle.
2877 */
2878 public void onExtrasChanged(Bundle extras) {}
2879
Tyler Gunnf5035432017-01-09 09:43:12 -08002880 /**
2881 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2882 * displaying its incoming call user interface for the {@link Connection}.
2883 * <p>
2884 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2885 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2886 * should show its own incoming call user interface.
2887 * <p>
2888 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002889 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2890 * Telecom framework will display its own incoming call user interface to allow the user to
2891 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2892 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002893 * <p>
2894 * You should trigger the display of the incoming call user interface for your application by
2895 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002896 *
2897 * In your application code, you should create a {@link android.app.NotificationChannel} for
2898 * incoming call notifications from your app:
2899 * <pre><code>
2900 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2901 * NotificationManager.IMPORTANCE_MAX);
2902 * // other channel setup stuff goes here.
2903 *
2904 * // We'll use the default system ringtone for our incoming call notification channel. You can
2905 * // use your own audio resource here.
2906 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2907 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2908 * // Setting the AudioAttributes is important as it identifies the purpose of your
2909 * // notification sound.
2910 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2911 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2912 * .build());
2913 *
2914 * NotificationManager mgr = getSystemService(NotificationManager.class);
2915 * mgr.createNotificationChannel(channel);
2916 * </code></pre>
2917 * When it comes time to post a notification for your incoming call, ensure it uses your
2918 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002919 * <pre><code>
2920 * // Create an intent which triggers your fullscreen incoming call user interface.
2921 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2922 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2923 * intent.setClass(context, YourIncomingCallActivity.class);
2924 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2925 *
2926 * // Build the notification as an ongoing high priority item; this ensures it will show as
2927 * // a heads up notification which slides down over top of the current content.
2928 * final Notification.Builder builder = new Notification.Builder(context);
2929 * builder.setOngoing(true);
2930 * builder.setPriority(Notification.PRIORITY_HIGH);
2931 *
2932 * // Set notification content intent to take user to fullscreen UI if user taps on the
2933 * // notification body.
2934 * builder.setContentIntent(pendingIntent);
2935 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2936 * // manager deems it appropriate.
2937 * builder.setFullScreenIntent(pendingIntent, true);
2938 *
2939 * // Setup notification content.
2940 * builder.setSmallIcon( yourIconResourceId );
2941 * builder.setContentTitle("Your notification title");
2942 * builder.setContentText("Your notification content.");
2943 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002944 * // Set notification as insistent to cause your ringtone to loop.
2945 * Notification notification = builder.build();
2946 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002947 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002948 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002949 * NotificationManager notificationManager = mContext.getSystemService(
2950 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07002951 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08002952 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002953 */
2954 public void onShowIncomingCallUi() {}
2955
Hall Liub64ac4c2017-02-06 10:49:48 -08002956 /**
2957 * Notifies this {@link Connection} that the user has requested an RTT session.
2958 * The connection service should call {@link #sendRttInitiationSuccess} or
2959 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2960 * request, respectively.
2961 * @param rttTextStream The object that should be used to send text to or receive text from
2962 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002963 */
2964 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2965
2966 /**
2967 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2968 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002969 */
2970 public void onStopRtt() {}
2971
2972 /**
2973 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2974 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2975 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2976 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002977 * @param rttTextStream The object that should be used to send text to or receive text from
2978 * the in-call app.
2979 */
2980 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2981
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002982 static String toLogSafePhoneNumber(String number) {
2983 // For unknown number, log empty string.
2984 if (number == null) {
2985 return "";
2986 }
2987
2988 if (PII_DEBUG) {
2989 // When PII_DEBUG is true we emit PII.
2990 return number;
2991 }
2992
2993 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2994 // sanitized phone numbers.
2995 StringBuilder builder = new StringBuilder();
2996 for (int i = 0; i < number.length(); i++) {
2997 char c = number.charAt(i);
2998 if (c == '-' || c == '@' || c == '.') {
2999 builder.append(c);
3000 } else {
3001 builder.append('x');
3002 }
3003 }
3004 return builder.toString();
3005 }
3006
Ihab Awad542e0ea2014-05-16 10:22:16 -07003007 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003008 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003009 if (mState == STATE_DISCONNECTED && mState != state) {
3010 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003011 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003012 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003013 if (mState != state) {
3014 Log.d(this, "setState: %s", stateToString(state));
3015 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003016 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003017 for (Listener l : mListeners) {
3018 l.onStateChanged(this, state);
3019 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003020 }
3021 }
3022
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003023 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003024 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003025 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3026 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003027 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003028 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003029
3030 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003031 if (mImmutable) {
3032 throw new UnsupportedOperationException("Connection is immutable");
3033 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003034 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003035 }
3036
Evan Charltonbf11f982014-07-20 22:06:28 -07003037 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003038 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003039 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3040 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003041 * <p>
3042 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3043 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003044 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003045 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003046 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003047 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003048 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3049 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003050 }
3051
Evan Charltonbf11f982014-07-20 22:06:28 -07003052 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003053 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3054 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3055 * this should never be un-@hide-den.
3056 *
3057 * @hide
3058 */
3059 public void checkImmutable() {}
3060
3061 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003062 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3063 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3064 * that state. This connection should not be used for anything, and no other
3065 * {@code Connection}s should be attempted.
3066 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003067 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003068 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003069 * @return A {@code Connection} which indicates that the underlying connection should
3070 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003071 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003072 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003073 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003074 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003075
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003076 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003077 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003078 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003079 }
3080 }
3081
Santos Cordon823fd3c2014-08-07 18:35:18 -07003082 private final void fireConferenceChanged() {
3083 for (Listener l : mListeners) {
3084 l.onConferenceChanged(this, mConference);
3085 }
3086 }
3087
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003088 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003089 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003090 if (c instanceof Connection) {
3091 Connection connection = (Connection) c;
3092 connection.removeConnectionListener(mConnectionDeathListener);
3093 } else if (c instanceof Conference) {
3094 Conference conference = (Conference) c;
3095 conference.removeListener(mConferenceDeathListener);
3096 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003097 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003098 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003099 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003100
3101 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003102 * Handles a change to extras received from Telecom.
3103 *
3104 * @param extras The new extras.
3105 * @hide
3106 */
3107 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003108 Bundle b = null;
3109 synchronized (mExtrasLock) {
3110 mExtras = extras;
3111 if (mExtras != null) {
3112 b = new Bundle(mExtras);
3113 }
3114 }
3115 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003116 }
3117
3118 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003119 * Notifies listeners that the merge request failed.
3120 *
3121 * @hide
3122 */
3123 protected final void notifyConferenceMergeFailed() {
3124 for (Listener l : mListeners) {
3125 l.onConferenceMergeFailed(this);
3126 }
3127 }
3128
3129 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003130 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003131 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003132 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003133 * @hide
3134 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003135 protected final void updateConferenceParticipants(
3136 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003137 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003138 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003139 }
3140 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003141
3142 /**
3143 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003144 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003145 */
3146 protected void notifyConferenceStarted() {
3147 for (Listener l : mListeners) {
3148 l.onConferenceStarted();
3149 }
3150 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003151
3152 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003153 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3154 * be a part of a conference call.
3155 * @param isConferenceSupported {@code true} if the connection supports being part of a
3156 * conference call, {@code false} otherwise.
3157 * @hide
3158 */
3159 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3160 for (Listener l : mListeners) {
3161 l.onConferenceSupportedChanged(this, isConferenceSupported);
3162 }
3163 }
3164
3165 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303166 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3167 * changed due to an emergency call being redialed.
3168 * @param pHandle The new PhoneAccountHandle for this connection.
3169 * @hide
3170 */
3171 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3172 for (Listener l : mListeners) {
3173 l.onPhoneAccountChanged(this, pHandle);
3174 }
3175 }
3176
3177 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003178 * Sends an event associated with this {@code Connection} with associated event extras to the
3179 * {@link InCallService}.
3180 * <p>
3181 * Connection events are used to communicate point in time information from a
3182 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3183 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3184 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3185 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3186 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3187 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3188 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3189 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3190 * <p>
3191 * Events are exposed to {@link InCallService} implementations via
3192 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3193 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003194 * 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 -07003195 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3196 * some events altogether.
3197 * <p>
3198 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3199 * conflicts between {@link ConnectionService} implementations. Further, custom
3200 * {@link ConnectionService} implementations shall not re-purpose events in the
3201 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3202 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3203 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3204 * {@code com.example.extra.MY_EXTRA}).
3205 * <p>
3206 * When defining events and the associated extras, it is important to keep their behavior
3207 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3208 * events/extras should me maintained to ensure backwards compatibility with older
3209 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003210 *
3211 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003212 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003213 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003214 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003215 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003216 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003217 }
3218 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003219}