blob: 36333e448b151e78437845ddcfbd323fc85d3db6 [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 Liua549fed2018-02-09 16:40:03 -080043import java.io.FileInputStream;
44import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080045import java.io.IOException;
46import java.io.InputStreamReader;
47import java.io.OutputStreamWriter;
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 Erfanian62706c52017-12-06 16:27:53 -0800407 /**
408 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000409 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800410 */
411 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
412
Tyler Gunn96d6c402015-03-18 12:39:23 -0700413 //**********************************************************************************************
Eric Erfanian62706c52017-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 Liud4d2a8a2018-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 Liua549fed2018-02-09 16:40:03 -0800865 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800866 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-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 Liua549fed2018-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 Liua549fed2018-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 Liua549fed2018-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 Liua549fed2018-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 Liua549fed2018-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;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001703 // The PhoneAccountHandle associated with this connection.
1704 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001705 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001706 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001707 private Uri mAddress;
1708 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001709 private String mCallerDisplayName;
1710 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001711 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001712 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001713 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001714 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001715 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001716 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001717 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001718 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001719 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001720 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001721 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001722 private Conference mConference;
1723 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001724 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001725 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001726
1727 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001728 * Tracks the key set for the extras bundle provided on the last invocation of
1729 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1730 * keys which were set previously but are no longer present in the replacement Bundle.
1731 */
1732 private Set<String> mPreviousExtraKeys;
1733
1734 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001735 * Create a new Connection.
1736 */
Santos Cordonf2951102014-07-20 19:06:29 -07001737 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001738
1739 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001740 * Returns the Telecom internal call ID associated with this connection. Should only be used
1741 * for debugging and tracing purposes.
1742 *
1743 * @return The Telecom call ID.
1744 * @hide
1745 */
1746 public final String getTelecomCallId() {
1747 return mTelecomCallId;
1748 }
1749
1750 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001751 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001752 */
Andrew Lee100e2932014-09-08 15:34:24 -07001753 public final Uri getAddress() {
1754 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001755 }
1756
1757 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001758 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001759 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001760 */
Andrew Lee100e2932014-09-08 15:34:24 -07001761 public final int getAddressPresentation() {
1762 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001763 }
1764
1765 /**
1766 * @return The caller display name (CNAP).
1767 */
1768 public final String getCallerDisplayName() {
1769 return mCallerDisplayName;
1770 }
1771
1772 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001773 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001774 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001775 */
1776 public final int getCallerDisplayNamePresentation() {
1777 return mCallerDisplayNamePresentation;
1778 }
1779
1780 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001781 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001782 */
1783 public final int getState() {
1784 return mState;
1785 }
1786
1787 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001788 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001789 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1790 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1791 * {@link VideoProfile#STATE_TX_ENABLED},
1792 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001793 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001794 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001795 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001796 */
1797 public final int getVideoState() {
1798 return mVideoState;
1799 }
1800
1801 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001802 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001803 * being routed by the system. This is {@code null} if this Connection
1804 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001805 * @deprecated Use {@link #getCallAudioState()} instead.
1806 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001807 */
Yorke Lee4af59352015-05-13 14:14:54 -07001808 @SystemApi
1809 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001810 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001811 if (mCallAudioState == null) {
1812 return null;
1813 }
Yorke Lee4af59352015-05-13 14:14:54 -07001814 return new AudioState(mCallAudioState);
1815 }
1816
1817 /**
1818 * @return The audio state of the connection, describing how its audio is currently
1819 * being routed by the system. This is {@code null} if this Connection
1820 * does not directly know about its audio state.
1821 */
1822 public final CallAudioState getCallAudioState() {
1823 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001824 }
1825
1826 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001827 * @return The conference that this connection is a part of. Null if it is not part of any
1828 * conference.
1829 */
1830 public final Conference getConference() {
1831 return mConference;
1832 }
1833
1834 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001835 * Returns whether this connection is requesting that the system play a ringback tone
1836 * on its behalf.
1837 */
Andrew Lee100e2932014-09-08 15:34:24 -07001838 public final boolean isRingbackRequested() {
1839 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001840 }
1841
1842 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001843 * @return True if the connection's audio mode is VOIP.
1844 */
1845 public final boolean getAudioModeIsVoip() {
1846 return mAudioModeIsVoip;
1847 }
1848
1849 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001850 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1851 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1852 * start time of the conference.
1853 *
1854 * @return The time at which the {@code Connnection} was connected.
1855 *
1856 * @hide
1857 */
1858 public final long getConnectTimeMillis() {
1859 return mConnectTimeMillis;
1860 }
1861
1862 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001863 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1864 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1865 * start time of the conference.
1866 *
1867 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1868 * changes do not impact the call duration.
1869 *
1870 * @return The time at which the {@link Connection} was connected.
1871 *
1872 * @hide
1873 */
1874 public final long getConnectElapsedTimeMillis() {
1875 return mConnectElapsedTimeMillis;
1876 }
1877
1878 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001879 * @return The status hints for this connection.
1880 */
1881 public final StatusHints getStatusHints() {
1882 return mStatusHints;
1883 }
1884
1885 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001886 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001887 * <p>
1888 * Extras should be updated using {@link #putExtras(Bundle)}.
1889 * <p>
1890 * Telecom or an {@link InCallService} can also update the extras via
1891 * {@link android.telecom.Call#putExtras(Bundle)}, and
1892 * {@link Call#removeExtras(List)}.
1893 * <p>
1894 * The connection is notified of changes to the extras made by Telecom or an
1895 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001896 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001897 * @return The extras associated with this connection.
1898 */
1899 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001900 Bundle extras = null;
1901 synchronized (mExtrasLock) {
1902 if (mExtras != null) {
1903 extras = new Bundle(mExtras);
1904 }
1905 }
1906 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001907 }
1908
1909 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001910 * Assign a listener to be notified of state changes.
1911 *
1912 * @param l A listener.
1913 * @return This Connection.
1914 *
1915 * @hide
1916 */
1917 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001918 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001919 return this;
1920 }
1921
1922 /**
1923 * Remove a previously assigned listener that was being notified of state changes.
1924 *
1925 * @param l A Listener.
1926 * @return This Connection.
1927 *
1928 * @hide
1929 */
1930 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001931 if (l != null) {
1932 mListeners.remove(l);
1933 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001934 return this;
1935 }
1936
1937 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001938 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001939 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001940 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001941 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001942 }
1943
1944 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001945 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1946 * ONLY for debugging purposes.
1947 *
1948 * @param callId The telecom call ID.
1949 * @hide
1950 */
1951 public void setTelecomCallId(String callId) {
1952 mTelecomCallId = callId;
1953 }
1954
1955 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 * Inform this Connection that the state of its audio output has been changed externally.
1957 *
1958 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001959 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001960 */
Yorke Lee4af59352015-05-13 14:14:54 -07001961 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001962 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001963 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001964 mCallAudioState = state;
1965 onAudioStateChanged(getAudioState());
1966 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001967 }
1968
1969 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001970 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001971 * @return A string representation of the value.
1972 */
1973 public static String stateToString(int state) {
1974 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001975 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001976 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001978 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001979 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001980 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001981 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001982 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001983 case STATE_PULLING_CALL:
1984 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001985 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001986 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001987 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001988 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001989 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001990 return "DISCONNECTED";
1991 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001992 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001993 return "UNKNOWN";
1994 }
1995 }
1996
1997 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001998 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001999 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002000 public final int getConnectionCapabilities() {
2001 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002002 }
2003
2004 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002005 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2006 */
2007 public final int getConnectionProperties() {
2008 return mConnectionProperties;
2009 }
2010
2011 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002012 * Returns the connection's supported audio routes.
2013 *
2014 * @hide
2015 */
2016 public final int getSupportedAudioRoutes() {
2017 return mSupportedAudioRoutes;
2018 }
2019
2020 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002021 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002022 *
Andrew Lee100e2932014-09-08 15:34:24 -07002023 * @param address The new address.
2024 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002025 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002026 */
Andrew Lee100e2932014-09-08 15:34:24 -07002027 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002028 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002029 Log.d(this, "setAddress %s", address);
2030 mAddress = address;
2031 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002032 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002033 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002034 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002035 }
2036
2037 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002038 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002039 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002040 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002041 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002042 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002043 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002044 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002045 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002046 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002047 mCallerDisplayName = callerDisplayName;
2048 mCallerDisplayNamePresentation = presentation;
2049 for (Listener l : mListeners) {
2050 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2051 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002052 }
2053
2054 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002055 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002056 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2057 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2058 * {@link VideoProfile#STATE_TX_ENABLED},
2059 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002060 *
2061 * @param videoState The new video state.
2062 */
2063 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002064 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002065 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002066 mVideoState = videoState;
2067 for (Listener l : mListeners) {
2068 l.onVideoStateChanged(this, mVideoState);
2069 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002070 }
2071
2072 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002073 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002074 * communicate).
2075 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002076 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002077 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002078 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002079 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002080 }
2081
2082 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002083 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002085 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002086 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002087 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002088 }
2089
2090 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002091 * Sets state to initializing (this Connection is not yet ready to be used).
2092 */
2093 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002094 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002095 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002096 }
2097
2098 /**
2099 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2100 */
2101 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002102 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002103 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002104 }
2105
2106 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002107 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002108 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002109 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002110 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002111 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002112 }
2113
2114 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002115 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2116 * device). Only applicable for {@link Connection}s with
2117 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2118 */
2119 public final void setPulling() {
2120 checkImmutable();
2121 setState(STATE_PULLING_CALL);
2122 }
2123
2124 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002125 * Sets state to be on hold.
2126 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002127 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002128 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002129 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002130 }
2131
2132 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002133 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002134 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002135 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002136 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002137 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002138 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002139 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002140 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002141 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002142 }
2143
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002144 public final VideoProvider getVideoProvider() {
2145 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002146 }
2147
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002148 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002149 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002150 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002151 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002152 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002153 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002154 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002155 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002156 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002157 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002158 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002159 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002160 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002161 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002162 }
2163
2164 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002165 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2166 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2167 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2168 * to send an {@link #onPostDialContinue(boolean)} signal.
2169 *
2170 * @param remaining The DTMF character sequence remaining to be emitted once the
2171 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2172 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002173 */
2174 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002175 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002176 for (Listener l : mListeners) {
2177 l.onPostDialWait(this, remaining);
2178 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002179 }
2180
2181 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002182 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2183 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002184 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002185 *
2186 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002187 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002188 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002189 checkImmutable();
2190 for (Listener l : mListeners) {
2191 l.onPostDialChar(this, nextChar);
2192 }
2193 }
2194
2195 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002196 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002197 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002198 *
2199 * @param ringback Whether the ringback tone is to be played.
2200 */
Andrew Lee100e2932014-09-08 15:34:24 -07002201 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002202 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002203 if (mRingbackRequested != ringback) {
2204 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002205 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002206 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002207 }
2208 }
Ihab Awadf8358972014-05-28 16:46:42 -07002209 }
2210
2211 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002212 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002213 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002214 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002215 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002216 public final void setConnectionCapabilities(int connectionCapabilities) {
2217 checkImmutable();
2218 if (mConnectionCapabilities != connectionCapabilities) {
2219 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002220 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002221 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002222 }
2223 }
Santos Cordonb6939982014-06-04 20:20:58 -07002224 }
2225
2226 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002227 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2228 *
2229 * @param connectionProperties The new connection properties.
2230 */
2231 public final void setConnectionProperties(int connectionProperties) {
2232 checkImmutable();
2233 if (mConnectionProperties != connectionProperties) {
2234 mConnectionProperties = connectionProperties;
2235 for (Listener l : mListeners) {
2236 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2237 }
2238 }
2239 }
2240
2241 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002242 * Sets the supported audio routes.
2243 *
2244 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2245 * See {@link CallAudioState}
2246 * @hide
2247 */
2248 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2249 if ((supportedAudioRoutes
2250 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2251 throw new IllegalArgumentException(
2252 "supported audio routes must include either speaker or earpiece");
2253 }
2254
2255 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2256 mSupportedAudioRoutes = supportedAudioRoutes;
2257 for (Listener l : mListeners) {
2258 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2259 }
2260 }
2261 }
2262
2263 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002264 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002265 */
Evan Charlton36a71342014-07-19 16:31:02 -07002266 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002267 for (Listener l : mListeners) {
2268 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002269 }
Santos Cordonb6939982014-06-04 20:20:58 -07002270 }
2271
2272 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002273 * Requests that the framework use VOIP audio mode for this connection.
2274 *
2275 * @param isVoip True if the audio mode is VOIP.
2276 */
2277 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002278 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002279 mAudioModeIsVoip = isVoip;
2280 for (Listener l : mListeners) {
2281 l.onAudioModeIsVoipChanged(this, isVoip);
2282 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002283 }
2284
2285 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002286 * Sets the time at which a call became active on this Connection. This is set only
2287 * when a conference call becomes active on this connection.
2288 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002289 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2290 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002291 *
2292 * @hide
2293 */
2294 public final void setConnectTimeMillis(long connectTimeMillis) {
2295 mConnectTimeMillis = connectTimeMillis;
2296 }
2297
2298 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002299 * Sets the time at which a call became active on this Connection. This is set only
2300 * when a conference call becomes active on this connection.
2301 *
2302 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2303 * {@link SystemClock#elapsedRealtime()}.
2304 *
2305 * @hide
2306 */
Tyler Gunn17541392018-02-01 08:58:38 -08002307 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002308 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2309 }
2310
2311 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002312 * Sets the label and icon status to display in the in-call UI.
2313 *
2314 * @param statusHints The status label and icon to set.
2315 */
2316 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002317 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002318 mStatusHints = statusHints;
2319 for (Listener l : mListeners) {
2320 l.onStatusHintsChanged(this, statusHints);
2321 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002322 }
2323
2324 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002325 * Sets the connections with which this connection can be conferenced.
2326 *
2327 * @param conferenceableConnections The set of connections this connection can conference with.
2328 */
2329 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002330 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002331 clearConferenceableList();
2332 for (Connection c : conferenceableConnections) {
2333 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2334 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002335 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002336 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002337 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002338 }
2339 }
2340 fireOnConferenceableConnectionsChanged();
2341 }
2342
2343 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002344 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2345 * or conferences with which this connection can be conferenced.
2346 *
2347 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002348 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002349 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002350 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002351 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002352 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2353 // small amount of items here.
2354 if (!mConferenceables.contains(c)) {
2355 if (c instanceof Connection) {
2356 Connection connection = (Connection) c;
2357 connection.addConnectionListener(mConnectionDeathListener);
2358 } else if (c instanceof Conference) {
2359 Conference conference = (Conference) c;
2360 conference.addListener(mConferenceDeathListener);
2361 }
2362 mConferenceables.add(c);
2363 }
2364 }
2365 fireOnConferenceableConnectionsChanged();
2366 }
2367
2368 /**
2369 * Returns the connections or conferences with which this connection can be conferenced.
2370 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002371 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002372 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002373 }
2374
Yorke Lee53463962015-08-04 16:07:19 -07002375 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002376 * @hide
2377 */
2378 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002379 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002380 if (mConnectionService != null) {
2381 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2382 "which is already associated with another ConnectionService.");
2383 } else {
2384 mConnectionService = connectionService;
2385 }
2386 }
2387
2388 /**
2389 * @hide
2390 */
2391 public final void unsetConnectionService(ConnectionService connectionService) {
2392 if (mConnectionService != connectionService) {
2393 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2394 "that does not belong to the ConnectionService.");
2395 } else {
2396 mConnectionService = null;
2397 }
2398 }
2399
2400 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002401 * @hide
2402 */
2403 public final ConnectionService getConnectionService() {
2404 return mConnectionService;
2405 }
2406
2407 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002408 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002409 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002410 *
2411 * @param conference The conference.
2412 * @return {@code true} if the conference was successfully set.
2413 * @hide
2414 */
2415 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002416 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002417 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002418 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002419 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002420 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2421 fireConferenceChanged();
2422 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 return true;
2424 }
2425 return false;
2426 }
2427
2428 /**
2429 * Resets the conference that this connection is a part of.
2430 * @hide
2431 */
2432 public final void resetConference() {
2433 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002434 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002435 mConference = null;
2436 fireConferenceChanged();
2437 }
2438 }
2439
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002440 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002441 * Set some extras that can be associated with this {@code Connection}.
2442 * <p>
2443 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2444 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2445 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002446 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2447 * {@link #removeExtras(String...)} methods to modify the extras.
2448 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002449 * 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 -07002450 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2451 *
2452 * @param extras The extras associated with this {@code Connection}.
2453 */
2454 public final void setExtras(@Nullable Bundle extras) {
2455 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002456
2457 // Add/replace any new or changed extras values.
2458 putExtras(extras);
2459
2460 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2461 // the current one and remove any keys that went away.
2462 if (mPreviousExtraKeys != null) {
2463 List<String> toRemove = new ArrayList<String>();
2464 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002465 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002466 toRemove.add(oldKey);
2467 }
2468 }
2469 if (!toRemove.isEmpty()) {
2470 removeExtras(toRemove);
2471 }
2472 }
2473
2474 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2475 // called we can see if the caller has removed any extras values.
2476 if (mPreviousExtraKeys == null) {
2477 mPreviousExtraKeys = new ArraySet<String>();
2478 }
2479 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002480 if (extras != null) {
2481 mPreviousExtraKeys.addAll(extras.keySet());
2482 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002483 }
2484
2485 /**
2486 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2487 * added.
2488 * <p>
2489 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2490 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2491 *
2492 * @param extras The extras to add.
2493 */
2494 public final void putExtras(@NonNull Bundle extras) {
2495 checkImmutable();
2496 if (extras == null) {
2497 return;
2498 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002499 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2500 // the listeners.
2501 Bundle listenerExtras;
2502 synchronized (mExtrasLock) {
2503 if (mExtras == null) {
2504 mExtras = new Bundle();
2505 }
2506 mExtras.putAll(extras);
2507 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002508 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002509 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002510 // Create a new clone of the extras for each listener so that they don't clobber
2511 // each other
2512 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002513 }
2514 }
2515
2516 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002517 * Adds a boolean extra to this {@code Connection}.
2518 *
2519 * @param key The extra key.
2520 * @param value The value.
2521 * @hide
2522 */
2523 public final void putExtra(String key, boolean value) {
2524 Bundle newExtras = new Bundle();
2525 newExtras.putBoolean(key, value);
2526 putExtras(newExtras);
2527 }
2528
2529 /**
2530 * Adds an integer extra to this {@code Connection}.
2531 *
2532 * @param key The extra key.
2533 * @param value The value.
2534 * @hide
2535 */
2536 public final void putExtra(String key, int value) {
2537 Bundle newExtras = new Bundle();
2538 newExtras.putInt(key, value);
2539 putExtras(newExtras);
2540 }
2541
2542 /**
2543 * Adds a string extra to this {@code Connection}.
2544 *
2545 * @param key The extra key.
2546 * @param value The value.
2547 * @hide
2548 */
2549 public final void putExtra(String key, String value) {
2550 Bundle newExtras = new Bundle();
2551 newExtras.putString(key, value);
2552 putExtras(newExtras);
2553 }
2554
2555 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002556 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002557 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002558 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002559 */
2560 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002561 synchronized (mExtrasLock) {
2562 if (mExtras != null) {
2563 for (String key : keys) {
2564 mExtras.remove(key);
2565 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002566 }
2567 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002568 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002569 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002570 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002571 }
2572 }
2573
2574 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002575 * Removes extras from this {@code Connection}.
2576 *
2577 * @param keys The keys of the extras to remove.
2578 */
2579 public final void removeExtras(String ... keys) {
2580 removeExtras(Arrays.asList(keys));
2581 }
2582
2583 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002584 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2585 * be change to the {@link #getCallAudioState()}.
2586 * <p>
2587 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2588 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2589 * <p>
2590 * See also {@link InCallService#setAudioRoute(int)}.
2591 *
2592 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2593 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2594 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2595 */
2596 public final void setAudioRoute(int route) {
2597 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002598 l.onAudioRouteChanged(this, route, null);
2599 }
2600 }
2601
2602 /**
2603 *
2604 * Request audio routing to a specific bluetooth device. Calling this method may result in
2605 * the device routing audio to a different bluetooth device than the one specified if the
2606 * bluetooth stack is unable to route audio to the requested device.
2607 * A list of available devices can be obtained via
2608 * {@link CallAudioState#getSupportedBluetoothDevices()}
2609 *
2610 * <p>
2611 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2612 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2613 * <p>
2614 * See also {@link InCallService#requestBluetoothAudio(String)}
2615 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2616 * {@link BluetoothDevice#getAddress()}.
2617 */
2618 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2619 for (Listener l : mListeners) {
2620 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08002621 }
2622 }
2623
2624 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002625 * Informs listeners that a previously requested RTT session via
2626 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002627 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002628 */
2629 public final void sendRttInitiationSuccess() {
2630 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2631 }
2632
2633 /**
2634 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002635 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 * has failed.
2637 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2638 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002639 */
2640 public final void sendRttInitiationFailure(int reason) {
2641 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2642 }
2643
2644 /**
2645 * Informs listeners that a currently active RTT session has been terminated by the remote
2646 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002647 */
2648 public final void sendRttSessionRemotelyTerminated() {
2649 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2650 }
2651
2652 /**
2653 * Informs listeners that the remote side of the call has requested an upgrade to include an
2654 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002655 */
2656 public final void sendRemoteRttRequest() {
2657 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2658 }
2659
2660 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002661 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002662 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002663 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002664 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2665 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002666 */
Yorke Lee4af59352015-05-13 14:14:54 -07002667 @SystemApi
2668 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002669 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002670
2671 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002672 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2673 *
2674 * @param state The new connection audio state.
2675 */
2676 public void onCallAudioStateChanged(CallAudioState state) {}
2677
2678 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002679 * Notifies this Connection of an internal state change. This method is called after the
2680 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002681 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002682 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002683 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002684 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002685
2686 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002687 * Notifies this Connection of a request to play a DTMF tone.
2688 *
2689 * @param c A DTMF character.
2690 */
Santos Cordonf2951102014-07-20 19:06:29 -07002691 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002692
2693 /**
2694 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2695 */
Santos Cordonf2951102014-07-20 19:06:29 -07002696 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002697
2698 /**
2699 * Notifies this Connection of a request to disconnect.
2700 */
Santos Cordonf2951102014-07-20 19:06:29 -07002701 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002702
2703 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002704 * Notifies this Connection of a request to disconnect a participant of the conference managed
2705 * by the connection.
2706 *
2707 * @param endpoint the {@link Uri} of the participant to disconnect.
2708 * @hide
2709 */
2710 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2711
2712 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002713 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002714 */
Santos Cordonf2951102014-07-20 19:06:29 -07002715 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002716
2717 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002718 * Notifies this Connection of a request to abort.
2719 */
Santos Cordonf2951102014-07-20 19:06:29 -07002720 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002721
2722 /**
2723 * Notifies this Connection of a request to hold.
2724 */
Santos Cordonf2951102014-07-20 19:06:29 -07002725 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002726
2727 /**
2728 * Notifies this Connection of a request to exit a hold state.
2729 */
Santos Cordonf2951102014-07-20 19:06:29 -07002730 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002731
2732 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002733 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002734 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002735 * <p>
2736 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2737 * the default dialer's {@link InCallService}.
2738 * <p>
2739 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2740 * Telecom framework may request that the call is answered in the following circumstances:
2741 * <ul>
2742 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2743 * <li>A car mode {@link InCallService} is in use which has declared
2744 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2745 * {@link InCallService} will be able to see calls from self-managed
2746 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2747 * behalf.</li>
2748 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002749 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002750 */
Santos Cordonf2951102014-07-20 19:06:29 -07002751 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002752
2753 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002754 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002755 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002756 * <p>
2757 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2758 * the default dialer's {@link InCallService}.
2759 * <p>
2760 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2761 * Telecom framework may request that the call is answered in the following circumstances:
2762 * <ul>
2763 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2764 * <li>A car mode {@link InCallService} is in use which has declared
2765 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2766 * {@link InCallService} will be able to see calls from self-managed
2767 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2768 * behalf.</li>
2769 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002770 */
2771 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002772 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002773 }
2774
2775 /**
2776 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302777 * a request to deflect.
2778 */
2779 public void onDeflect(Uri address) {}
2780
2781 /**
2782 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002783 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002784 * <p>
2785 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2786 * the default dialer's {@link InCallService}.
2787 * <p>
2788 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2789 * Telecom framework may request that the call is rejected in the following circumstances:
2790 * <ul>
2791 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2792 * <li>A car mode {@link InCallService} is in use which has declared
2793 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2794 * {@link InCallService} will be able to see calls from self-managed
2795 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2796 * behalf.</li>
2797 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002798 */
Santos Cordonf2951102014-07-20 19:06:29 -07002799 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002800
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002801 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002802 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2803 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002804 */
2805 public void onReject(String replyMessage) {}
2806
2807 /**
Bryce Leecac50772015-11-17 15:13:29 -08002808 * Notifies the Connection of a request to silence the ringer.
2809 *
2810 * @hide
2811 */
2812 public void onSilence() {}
2813
2814 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002815 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2816 */
Santos Cordonf2951102014-07-20 19:06:29 -07002817 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002818
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002819 /**
2820 * Notifies this Connection of a request to pull an external call to the local device.
2821 * <p>
2822 * The {@link InCallService} issues a request to pull an external call to the local device via
2823 * {@link Call#pullExternalCall()}.
2824 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002825 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2826 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002827 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002828 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002829 */
2830 public void onPullExternalCall() {}
2831
2832 /**
2833 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2834 * <p>
2835 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2836 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002837 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2838 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2839 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2840 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2841 * not aware of.
2842 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002843 * See also {@link Call#sendCallEvent(String, Bundle)}.
2844 *
2845 * @param event The call event.
2846 * @param extras Extras associated with the call event.
2847 */
2848 public void onCallEvent(String event, Bundle extras) {}
2849
Tyler Gunndee56a82016-03-23 16:06:34 -07002850 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002851 * Notifies this {@link Connection} that a handover has completed.
2852 * <p>
2853 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2854 * Bundle)} on the initiating side of the handover, and
2855 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2856 */
2857 public void onHandoverComplete() {}
2858
2859 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002860 * Notifies this {@link Connection} of a change to the extras made outside the
2861 * {@link ConnectionService}.
2862 * <p>
2863 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2864 * the {@link android.telecom.Call#putExtras(Bundle)} and
2865 * {@link Call#removeExtras(List)}.
2866 *
2867 * @param extras The new extras bundle.
2868 */
2869 public void onExtrasChanged(Bundle extras) {}
2870
Tyler Gunnf5035432017-01-09 09:43:12 -08002871 /**
2872 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2873 * displaying its incoming call user interface for the {@link Connection}.
2874 * <p>
2875 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2876 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2877 * should show its own incoming call user interface.
2878 * <p>
2879 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002880 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2881 * Telecom framework will display its own incoming call user interface to allow the user to
2882 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2883 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002884 * <p>
2885 * You should trigger the display of the incoming call user interface for your application by
2886 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2887 * For example:
2888 * <pre><code>
2889 * // Create an intent which triggers your fullscreen incoming call user interface.
2890 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2891 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2892 * intent.setClass(context, YourIncomingCallActivity.class);
2893 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2894 *
2895 * // Build the notification as an ongoing high priority item; this ensures it will show as
2896 * // a heads up notification which slides down over top of the current content.
2897 * final Notification.Builder builder = new Notification.Builder(context);
2898 * builder.setOngoing(true);
2899 * builder.setPriority(Notification.PRIORITY_HIGH);
2900 *
2901 * // Set notification content intent to take user to fullscreen UI if user taps on the
2902 * // notification body.
2903 * builder.setContentIntent(pendingIntent);
2904 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2905 * // manager deems it appropriate.
2906 * builder.setFullScreenIntent(pendingIntent, true);
2907 *
2908 * // Setup notification content.
2909 * builder.setSmallIcon( yourIconResourceId );
2910 * builder.setContentTitle("Your notification title");
2911 * builder.setContentText("Your notification content.");
2912 *
2913 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2914 *
2915 * NotificationManager notificationManager = mContext.getSystemService(
2916 * NotificationManager.class);
2917 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2918 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002919 */
2920 public void onShowIncomingCallUi() {}
2921
Hall Liub64ac4c2017-02-06 10:49:48 -08002922 /**
2923 * Notifies this {@link Connection} that the user has requested an RTT session.
2924 * The connection service should call {@link #sendRttInitiationSuccess} or
2925 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2926 * request, respectively.
2927 * @param rttTextStream The object that should be used to send text to or receive text from
2928 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002929 */
2930 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2931
2932 /**
2933 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2934 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002935 */
2936 public void onStopRtt() {}
2937
2938 /**
2939 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2940 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2941 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2942 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002943 * @param rttTextStream The object that should be used to send text to or receive text from
2944 * the in-call app.
2945 */
2946 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2947
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002948 static String toLogSafePhoneNumber(String number) {
2949 // For unknown number, log empty string.
2950 if (number == null) {
2951 return "";
2952 }
2953
2954 if (PII_DEBUG) {
2955 // When PII_DEBUG is true we emit PII.
2956 return number;
2957 }
2958
2959 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2960 // sanitized phone numbers.
2961 StringBuilder builder = new StringBuilder();
2962 for (int i = 0; i < number.length(); i++) {
2963 char c = number.charAt(i);
2964 if (c == '-' || c == '@' || c == '.') {
2965 builder.append(c);
2966 } else {
2967 builder.append('x');
2968 }
2969 }
2970 return builder.toString();
2971 }
2972
Ihab Awad542e0ea2014-05-16 10:22:16 -07002973 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002974 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002975 if (mState == STATE_DISCONNECTED && mState != state) {
2976 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002977 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002978 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002979 if (mState != state) {
2980 Log.d(this, "setState: %s", stateToString(state));
2981 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002982 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002983 for (Listener l : mListeners) {
2984 l.onStateChanged(this, state);
2985 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002986 }
2987 }
2988
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002989 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002990 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002991 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2992 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002993 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002994 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002995
2996 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002997 if (mImmutable) {
2998 throw new UnsupportedOperationException("Connection is immutable");
2999 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003000 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003001 }
3002
Evan Charltonbf11f982014-07-20 22:06:28 -07003003 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003004 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003005 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3006 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003007 * <p>
3008 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3009 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003010 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003011 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003012 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003013 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003014 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3015 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003016 }
3017
Evan Charltonbf11f982014-07-20 22:06:28 -07003018 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003019 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3020 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3021 * this should never be un-@hide-den.
3022 *
3023 * @hide
3024 */
3025 public void checkImmutable() {}
3026
3027 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003028 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3029 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3030 * that state. This connection should not be used for anything, and no other
3031 * {@code Connection}s should be attempted.
3032 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003033 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003034 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003035 * @return A {@code Connection} which indicates that the underlying connection should
3036 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003037 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003038 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003039 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003040 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003041
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003042 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003043 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003044 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003045 }
3046 }
3047
Santos Cordon823fd3c2014-08-07 18:35:18 -07003048 private final void fireConferenceChanged() {
3049 for (Listener l : mListeners) {
3050 l.onConferenceChanged(this, mConference);
3051 }
3052 }
3053
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003054 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003055 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003056 if (c instanceof Connection) {
3057 Connection connection = (Connection) c;
3058 connection.removeConnectionListener(mConnectionDeathListener);
3059 } else if (c instanceof Conference) {
3060 Conference conference = (Conference) c;
3061 conference.removeListener(mConferenceDeathListener);
3062 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003063 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003064 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003065 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003066
3067 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003068 * Handles a change to extras received from Telecom.
3069 *
3070 * @param extras The new extras.
3071 * @hide
3072 */
3073 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003074 Bundle b = null;
3075 synchronized (mExtrasLock) {
3076 mExtras = extras;
3077 if (mExtras != null) {
3078 b = new Bundle(mExtras);
3079 }
3080 }
3081 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003082 }
3083
3084 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003085 * Notifies listeners that the merge request failed.
3086 *
3087 * @hide
3088 */
3089 protected final void notifyConferenceMergeFailed() {
3090 for (Listener l : mListeners) {
3091 l.onConferenceMergeFailed(this);
3092 }
3093 }
3094
3095 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003096 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003097 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003098 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003099 * @hide
3100 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003101 protected final void updateConferenceParticipants(
3102 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003103 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003104 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003105 }
3106 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003107
3108 /**
3109 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003110 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003111 */
3112 protected void notifyConferenceStarted() {
3113 for (Listener l : mListeners) {
3114 l.onConferenceStarted();
3115 }
3116 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003117
3118 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003119 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3120 * be a part of a conference call.
3121 * @param isConferenceSupported {@code true} if the connection supports being part of a
3122 * conference call, {@code false} otherwise.
3123 * @hide
3124 */
3125 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3126 for (Listener l : mListeners) {
3127 l.onConferenceSupportedChanged(this, isConferenceSupported);
3128 }
3129 }
3130
3131 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303132 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3133 * changed due to an emergency call being redialed.
3134 * @param pHandle The new PhoneAccountHandle for this connection.
3135 * @hide
3136 */
3137 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3138 for (Listener l : mListeners) {
3139 l.onPhoneAccountChanged(this, pHandle);
3140 }
3141 }
3142
3143 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003144 * Sets the {@link PhoneAccountHandle} associated with this connection.
3145 *
3146 * @hide
3147 */
3148 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3149 if (mPhoneAccountHandle != phoneAccountHandle) {
3150 mPhoneAccountHandle = phoneAccountHandle;
3151 notifyPhoneAccountChanged(phoneAccountHandle);
3152 }
3153 }
3154
3155 /**
3156 * Returns the {@link PhoneAccountHandle} associated with this connection.
3157 *
3158 * @hide
3159 */
3160 public PhoneAccountHandle getPhoneAccountHandle() {
3161 return mPhoneAccountHandle;
3162 }
3163
3164 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003165 * Sends an event associated with this {@code Connection} with associated event extras to the
3166 * {@link InCallService}.
3167 * <p>
3168 * Connection events are used to communicate point in time information from a
3169 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3170 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3171 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3172 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3173 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3174 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3175 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3176 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3177 * <p>
3178 * Events are exposed to {@link InCallService} implementations via
3179 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3180 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003181 * 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 -07003182 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3183 * some events altogether.
3184 * <p>
3185 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3186 * conflicts between {@link ConnectionService} implementations. Further, custom
3187 * {@link ConnectionService} implementations shall not re-purpose events in the
3188 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3189 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3190 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3191 * {@code com.example.extra.MY_EXTRA}).
3192 * <p>
3193 * When defining events and the associated extras, it is important to keep their behavior
3194 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3195 * events/extras should me maintained to ensure backwards compatibility with older
3196 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003197 *
3198 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003199 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003200 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003201 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003202 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003203 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003204 }
3205 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003206}