blob: a570176e04a41726fb9b21aacb353118dd64bd4c [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080026import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080027import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070029import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080031import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070032import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.os.Handler;
34import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070035import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080037import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070039import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070040import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
Hall Liue9041242018-02-09 16:40:03 -080043import java.io.FileInputStream;
44import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080045import java.io.IOException;
46import java.io.InputStreamReader;
47import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070048import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070049import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070051import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070052import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070053import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070054
55/**
Santos Cordon895d4b82015-06-25 16:41:48 -070056 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
57 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070058 * <p>
59 * Implementations create a custom subclass of {@code Connection} and return it to the framework
60 * as the return value of
61 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
62 * or
63 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
64 * Implementations are then responsible for updating the state of the {@code Connection}, and
65 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
66 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070067 * <p>
68 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
69 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
70 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
71 * {@code Connection} instance.
72 * <p>
73 * Basic call support requires overriding the following methods: {@link #onAnswer()},
74 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
75 * <p>
76 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
77 * {@link #onUnhold()} methods should be overridden to provide hold support for the
78 * {@code Connection}.
79 * <p>
80 * Where a {@code Connection} supports a variation of video calling (e.g. the
81 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
82 * to support answering a call as a video call.
83 * <p>
84 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
85 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
86 * support for pulling the external call.
87 * <p>
88 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
89 * overridden.
90 * <p>
91 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
92 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
93 * for example, call events from a {@link InCallService} are handled,
94 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
95 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
96 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
97 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070098 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070099public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700100
Santos Cordon895d4b82015-06-25 16:41:48 -0700101 /**
102 * The connection is initializing. This is generally the first state for a {@code Connection}
103 * returned by a {@link ConnectionService}.
104 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 public static final int STATE_INITIALIZING = 0;
106
Santos Cordon895d4b82015-06-25 16:41:48 -0700107 /**
108 * The connection is new and not connected.
109 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 public static final int STATE_NEW = 1;
111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * An incoming connection is in the ringing state. During this state, the user's ringer or
114 * vibration feature will be activated.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_RINGING = 2;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * An outgoing connection is in the dialing state. In this state the other party has not yet
120 * answered the call and the user traditionally hears a ringback tone.
121 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 public static final int STATE_DIALING = 3;
123
Santos Cordon895d4b82015-06-25 16:41:48 -0700124 /**
125 * A connection is active. Both parties are connected to the call and can actively communicate.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_ACTIVE = 4;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * A connection is on hold.
131 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 public static final int STATE_HOLDING = 5;
133
Santos Cordon895d4b82015-06-25 16:41:48 -0700134 /**
135 * A connection has been disconnected. This is the final state once the user has been
136 * disconnected from a call either locally, remotely or by an error in the service.
137 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 public static final int STATE_DISCONNECTED = 6;
139
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700141 * The state of an external connection which is in the process of being pulled from a remote
142 * device to the local device.
143 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700144 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
146 */
147 public static final int STATE_PULLING_CALL = 7;
148
149 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700150 * Connection can currently be put on hold or unheld. This is distinct from
151 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
152 * it does not at the moment support the function. This can be true while the call is in the
153 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
154 * display a disabled 'hold' button.
155 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 public static final int CAPABILITY_HOLD = 0x00000001;
157
158 /** Connection supports the hold feature. */
159 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
160
161 /**
162 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
163 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
164 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
165 * capability allows a merge button to be shown while the conference is in the foreground
166 * of the in-call UI.
167 * <p>
168 * This is only intended for use by a {@link Conference}.
169 */
170 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
171
172 /**
173 * Connections within a conference can be swapped between foreground and background.
174 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
175 * <p>
176 * This is only intended for use by a {@link Conference}.
177 */
178 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
179
180 /**
181 * @hide
182 */
183 public static final int CAPABILITY_UNUSED = 0x00000010;
184
185 /** Connection supports responding via text option. */
186 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
187
188 /** Connection can be muted. */
189 public static final int CAPABILITY_MUTE = 0x00000040;
190
191 /**
192 * Connection supports conference management. This capability only applies to
193 * {@link Conference}s which can have {@link Connection}s as children.
194 */
195 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
196
197 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700198 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800199 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700200 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201
202 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700205 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206
207 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700210 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212
213 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800215 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700216 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
217
218 /**
219 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 */
221 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
222
223 /**
224 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700225 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700226 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700227 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800228
229 /**
230 * Connection is able to be separated from its parent {@code Conference}, if any.
231 */
232 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
233
234 /**
235 * Connection is able to be individually disconnected when in a {@code Conference}.
236 */
237 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
238
239 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700240 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800241 * @hide
242 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700247 * @hide
248 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250
251 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * @hide
254 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256
Tyler Gunn068085b2015-02-06 13:56:52 -0800257 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800259 * @hide
260 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700261 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800262
Tyler Gunn96d6c402015-03-18 12:39:23 -0700263 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500264 * Speed up audio setup for MT call.
265 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700266 */
267 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800268
Rekha Kumar07366812015-03-24 16:42:31 -0700269 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700270 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700271 */
272 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
273
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 /**
275 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700276 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700277 */
278 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
279
Tyler Gunnd4091732015-06-29 09:15:37 -0700280 /**
281 * For a conference, indicates the conference will not have child connections.
282 * <p>
283 * An example of a conference with child connections is a GSM conference call, where the radio
284 * retains connections to the individual participants of the conference. Another example is an
285 * IMS conference call where conference event package functionality is supported; in this case
286 * the conference server ensures the radio is aware of the participants in the conference, which
287 * are represented by child connections.
288 * <p>
289 * An example of a conference with no child connections is an IMS conference call with no
290 * conference event package support. Such a conference is represented by the radio as a single
291 * connection to the IMS conference server.
292 * <p>
293 * Indicating whether a conference has children or not is important to help user interfaces
294 * visually represent a conference. A conference with no children, for example, will have the
295 * conference connection shown in the list of calls on a Bluetooth device, where if the
296 * conference has children, only the children will be shown in the list of calls on a Bluetooth
297 * device.
298 * @hide
299 */
300 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
301
Bryce Lee81901682015-08-28 16:38:02 -0700302 /**
303 * Indicates that the connection itself wants to handle any sort of reply response, rather than
304 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700305 */
306 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
307
Tyler Gunnf97a0092016-01-19 15:59:34 -0800308 /**
309 * When set, prevents a video call from being downgraded to an audio-only call.
310 * <p>
311 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
312 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
313 * downgraded from a video call back to a VideoState of
314 * {@link VideoProfile#STATE_AUDIO_ONLY}.
315 * <p>
316 * Intuitively, a call which can be downgraded to audio should also have local and remote
317 * video
318 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
319 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
320 */
321 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
322
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700323 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700324 * When set for an external connection, indicates that this {@code Connection} can be pulled
325 * from a remote device to the current device.
326 * <p>
327 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
328 * is set.
329 */
330 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
331
Pooja Jaind34698d2017-12-28 14:15:31 +0530332 /** Call supports the deflect feature. */
333 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
334
Tyler Gunn720c6642016-03-22 09:02:47 -0700335 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530336 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700337 //**********************************************************************************************
338
339 /**
340 * Indicates that the current device callback number should be shown.
341 *
342 * @hide
343 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700344 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700345
346 /**
347 * Whether the call is a generic conference, where we do not know the precise state of
348 * participants in the conference (eg. on CDMA).
349 *
350 * @hide
351 */
352 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
353
354 /**
355 * Connection is using high definition audio.
356 * @hide
357 */
358 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
359
360 /**
361 * Connection is using WIFI.
362 * @hide
363 */
364 public static final int PROPERTY_WIFI = 1<<3;
365
366 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700367 * When set, indicates that the {@code Connection} does not actually exist locally for the
368 * {@link ConnectionService}.
369 * <p>
370 * Consider, for example, a scenario where a user has two devices with the same phone number.
371 * When a user places a call on one devices, the telephony stack can represent that call on the
372 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700373 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700374 * <p>
375 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
376 * external connections. Only those {@link InCallService}s which have the
377 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
378 * manifest will see external connections.
379 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700381
Brad Ebinger15847072016-05-18 11:08:36 -0700382 /**
383 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
384 */
385 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700386
Hall Liu9f332c72016-07-14 15:37:37 -0700387 /**
388 * Indicates that the connection represents a downgraded IMS conference.
389 * @hide
390 */
391 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
392
Tyler Gunnf5035432017-01-09 09:43:12 -0800393 /**
394 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
395 * {@link ConnectionService}.
396 * <p>
397 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
398 */
399 public static final int PROPERTY_SELF_MANAGED = 1<<7;
400
Hall Liu95d55872017-01-25 17:12:49 -0800401 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800402 * Set by the framework to indicate that a connection has an active RTT session associated with
403 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800404 */
405 public static final int PROPERTY_IS_RTT = 1 << 8;
406
Eric Erfanianec881872017-12-06 16:27:53 -0800407 /**
408 * Set by the framework to indicate that a connection is using assisted dialing.
409 * @hide
410 */
411 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
412
Tyler Gunn96d6c402015-03-18 12:39:23 -0700413 //**********************************************************************************************
Eric Erfanianec881872017-12-06 16:27:53 -0800414 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700415 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800416
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700417 /**
418 * Connection extra key used to store the last forwarded number associated with the current
419 * connection. Used to communicate to the user interface that the connection was forwarded via
420 * the specified number.
421 */
422 public static final String EXTRA_LAST_FORWARDED_NUMBER =
423 "android.telecom.extra.LAST_FORWARDED_NUMBER";
424
425 /**
426 * Connection extra key used to store a child number associated with the current connection.
427 * Used to communicate to the user interface that the connection was received via
428 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
429 * address.
430 */
431 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
432
433 /**
434 * Connection extra key used to store the subject for an incoming call. The user interface can
435 * query this extra and display its contents for incoming calls. Will only be used if the
436 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
437 */
438 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
439
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800440 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700441 * Boolean connection extra key set on a {@link Connection} in
442 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
443 * current active foreground call to be dropped.
444 */
445 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
446 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
447
448 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700449 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
450 * state to indicate the name of the third-party app which is responsible for the current
451 * foreground call.
452 * <p>
453 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
454 * is able to inform the user that answering the new incoming call will cause a call owned by
455 * another app to be dropped when the incoming call is answered.
456 */
457 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
458 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
459
460 /**
Hall Liu10208662016-06-15 17:55:00 -0700461 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700462 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700463 * @hide
464 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700465 public static final String EXTRA_DISABLE_ADD_CALL =
466 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700467
468 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700469 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
470 * original Connection ID associated with the connection. Used in
471 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
472 * connection/conference added via
473 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
474 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
475 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
476 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
477 * be a way to ensure that we don't add the connection again as a duplicate.
478 * <p>
479 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
480 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
481 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
482 * in a new {@link Connection} which it adds to Telecom via
483 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
484 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
485 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
486 * ID it originally referred to the connection as. Thus Telecom needs to know that the
487 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
488 * @hide
489 */
490 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
491 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
492
493 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800494 * Connection event used to inform Telecom that it should play the on hold tone. This is used
495 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700496 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800497 * @hide
498 */
499 public static final String EVENT_ON_HOLD_TONE_START =
500 "android.telecom.event.ON_HOLD_TONE_START";
501
502 /**
503 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
504 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700505 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800506 * @hide
507 */
508 public static final String EVENT_ON_HOLD_TONE_END =
509 "android.telecom.event.ON_HOLD_TONE_END";
510
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700511 /**
512 * Connection event used to inform {@link InCallService}s when pulling of an external call has
513 * failed. The user interface should inform the user of the error.
514 * <p>
515 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
516 * API is called on a {@link Call} with the properties
517 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
518 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
519 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700520 * <p>
521 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
522 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700523 */
524 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
525
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700526 /**
527 * Connection event used to inform {@link InCallService}s when the merging of two calls has
528 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700529 * <p>
530 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
531 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700532 */
533 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
534
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700535 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700536 * Connection event used to inform {@link InCallService}s when the process of merging a
537 * Connection into a conference has begun.
538 * <p>
539 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
540 * expected to be null when this connection event is used.
541 * @hide
542 */
543 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
544
545 /**
546 * Connection event used to inform {@link InCallService}s when the process of merging a
547 * Connection into a conference has completed.
548 * <p>
549 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
550 * expected to be null when this connection event is used.
551 * @hide
552 */
553 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
554
555 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700556 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
557 * the remote party.
558 * <p>
559 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
560 * call is being held locally on the device. When a capable {@link ConnectionService} receives
561 * signalling to indicate that the remote party has put the call on hold, it can send this
562 * connection event.
563 * @hide
564 */
565 public static final String EVENT_CALL_REMOTELY_HELD =
566 "android.telecom.event.CALL_REMOTELY_HELD";
567
568 /**
569 * Connection event used to inform {@link InCallService}s when a call which was remotely held
570 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
571 * <p>
572 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
573 * call is being held locally on the device. When a capable {@link ConnectionService} receives
574 * signalling to indicate that the remote party has taken the call off hold, it can send this
575 * connection event.
576 * @hide
577 */
578 public static final String EVENT_CALL_REMOTELY_UNHELD =
579 "android.telecom.event.CALL_REMOTELY_UNHELD";
580
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700581 /**
582 * Connection event used to inform an {@link InCallService} which initiated a call handover via
583 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
584 * successfully completed.
585 * @hide
586 */
587 public static final String EVENT_HANDOVER_COMPLETE =
588 "android.telecom.event.HANDOVER_COMPLETE";
589
590 /**
591 * Connection event used to inform an {@link InCallService} which initiated a call handover via
592 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
593 * to complete.
594 * @hide
595 */
596 public static final String EVENT_HANDOVER_FAILED =
597 "android.telecom.event.HANDOVER_FAILED";
598
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 // Flag controlling whether PII is emitted into the logs
600 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
601
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800602 /**
603 * Whether the given capabilities support the specified capability.
604 *
605 * @param capabilities A capability bit field.
606 * @param capability The capability to check capabilities for.
607 * @return Whether the specified capability is supported.
608 * @hide
609 */
610 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800611 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800612 }
613
614 /**
615 * Whether the capabilities of this {@code Connection} supports the specified capability.
616 *
617 * @param capability The capability to check capabilities for.
618 * @return Whether the specified capability is supported.
619 * @hide
620 */
621 public boolean can(int capability) {
622 return can(mConnectionCapabilities, capability);
623 }
624
625 /**
626 * Removes the specified capability from the set of capabilities of this {@code Connection}.
627 *
628 * @param capability The capability to remove from the set.
629 * @hide
630 */
631 public void removeCapability(int capability) {
632 mConnectionCapabilities &= ~capability;
633 }
634
635 /**
636 * Adds the specified capability to the set of capabilities of this {@code Connection}.
637 *
638 * @param capability The capability to add to the set.
639 * @hide
640 */
641 public void addCapability(int capability) {
642 mConnectionCapabilities |= capability;
643 }
644
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700645 /**
646 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
647 *
648 * @param capabilities A capability bit field.
649 * @return A human readable string representation.
650 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800651 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700652 return capabilitiesToStringInternal(capabilities, true /* isLong */);
653 }
654
655 /**
656 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
657 * string.
658 *
659 * @param capabilities A capability bit field.
660 * @return A human readable string representation.
661 * @hide
662 */
663 public static String capabilitiesToStringShort(int capabilities) {
664 return capabilitiesToStringInternal(capabilities, false /* isLong */);
665 }
666
667 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800668 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700669 builder.append("[");
670 if (isLong) {
671 builder.append("Capabilities:");
672 }
673
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800676 }
677 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800679 }
680 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 }
683 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 }
686 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800688 }
689 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700690 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 }
692 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800694 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700696 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700697 }
698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700700 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700701 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800703 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700704 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700706 }
707 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700708 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700709 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700710 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800712 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800713 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700714 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800715 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500716 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500718 }
Rekha Kumar07366812015-03-24 16:42:31 -0700719 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700721 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700722 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700724 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700725 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700726 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700727 }
Bryce Lee81901682015-08-28 16:38:02 -0700728 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700729 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700730 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700731 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700732 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700733 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530734 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
735 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
736 }
Bryce Lee81901682015-08-28 16:38:02 -0700737
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800738 builder.append("]");
739 return builder.toString();
740 }
741
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700742 /**
743 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
744 *
745 * @param properties A property bit field.
746 * @return A human readable string representation.
747 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700748 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 return propertiesToStringInternal(properties, true /* isLong */);
750 }
751
752 /**
753 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
754 *
755 * @param properties A property bit field.
756 * @return A human readable string representation.
757 * @hide
758 */
759 public static String propertiesToStringShort(int properties) {
760 return propertiesToStringInternal(properties, false /* isLong */);
761 }
762
763 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700764 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700765 builder.append("[");
766 if (isLong) {
767 builder.append("Properties:");
768 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700769
Tyler Gunnf5035432017-01-09 09:43:12 -0800770 if (can(properties, PROPERTY_SELF_MANAGED)) {
771 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
772 }
773
Hall Liu25c7c4d2016-08-30 13:41:02 -0700774 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
775 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700776 }
777
778 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700780 }
781
782 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700783 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700784 }
785
786 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700787 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700788 }
789
790 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700791 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700792 }
793
Brad Ebinger15847072016-05-18 11:08:36 -0700794 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700795 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700796 }
797
Hall Liuee575082018-01-29 17:22:02 -0800798 if (can(properties, PROPERTY_IS_RTT)) {
799 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
800 }
801
Tyler Gunn720c6642016-03-22 09:02:47 -0700802 builder.append("]");
803 return builder.toString();
804 }
805
Sailesh Nepal091768c2014-06-30 15:15:23 -0700806 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700807 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700808 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700809 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700810 public void onCallerDisplayNameChanged(
811 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700812 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700813 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700814 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800815 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700816 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700817 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800818 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700819 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800820 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 public void onVideoProviderChanged(
822 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700823 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
824 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800825 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700826 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700827 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700828 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800829 public void onConferenceParticipantsChanged(Connection c,
830 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800831 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700832 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700833 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700834 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700835 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700836 /** @hide */
837 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800838 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800839 public void onRttInitiationSuccess(Connection c) {}
840 public void onRttInitiationFailure(Connection c, int reason) {}
841 public void onRttSessionRemotelyTerminated(Connection c) {}
842 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530843 /** @hide */
844 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800845 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700846 }
847
Tyler Gunnb702ef82015-05-29 11:51:53 -0700848 /**
Hall Liu95d55872017-01-25 17:12:49 -0800849 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800850 */
851 public static final class RttTextStream {
852 private static final int READ_BUFFER_SIZE = 1000;
853 private final InputStreamReader mPipeFromInCall;
854 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800855 private final ParcelFileDescriptor mFdFromInCall;
856 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800857 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
858
859 /**
860 * @hide
861 */
862 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800863 mFdFromInCall = fromInCall;
864 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800865 mPipeFromInCall = new InputStreamReader(
Hall Liue9041242018-02-09 16:40:03 -0800866 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800867 mPipeToInCall = new OutputStreamWriter(
Hall Liue9041242018-02-09 16:40:03 -0800868 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800869 }
870
871 /**
872 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
873 * RTT transmits text in real-time, this method should be called as often as text snippets
874 * are received from the remote user, even if it is only one character.
Hall Liue9041242018-02-09 16:40:03 -0800875 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800876 * This method is not thread-safe -- calling it from multiple threads simultaneously may
877 * lead to interleaved text.
Hall Liue9041242018-02-09 16:40:03 -0800878 *
Hall Liu95d55872017-01-25 17:12:49 -0800879 * @param input The message to send to the in-call app.
880 */
881 public void write(String input) throws IOException {
882 mPipeToInCall.write(input);
883 mPipeToInCall.flush();
884 }
885
886
887 /**
888 * Reads a string from the in-call app, blocking if there is no data available. Returns
889 * {@code null} if the RTT conversation has been terminated and there is no further data
890 * to read.
Hall Liue9041242018-02-09 16:40:03 -0800891 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800892 * This method is not thread-safe -- calling it from multiple threads simultaneously may
893 * lead to interleaved text.
Hall Liue9041242018-02-09 16:40:03 -0800894 *
Hall Liu95d55872017-01-25 17:12:49 -0800895 * @return A string containing text entered by the user, or {@code null} if the
896 * conversation has been terminated or if there was an error while reading.
897 */
Hall Liuffa4a812017-03-02 16:11:00 -0800898 public String read() throws IOException {
899 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
900 if (numRead < 0) {
901 return null;
902 }
903 return new String(mReadBuffer, 0, numRead);
904 }
905
906 /**
907 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
908 * be read.
Hall Liue9041242018-02-09 16:40:03 -0800909 *
Hall Liuffa4a812017-03-02 16:11:00 -0800910 * @return A string containing text entered by the user, or {@code null} if the user has
911 * not entered any new text yet.
912 */
913 public String readImmediately() throws IOException {
914 if (mPipeFromInCall.ready()) {
915 return read();
916 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800917 return null;
918 }
919 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800920
921 /** @hide */
922 public ParcelFileDescriptor getFdFromInCall() {
923 return mFdFromInCall;
924 }
925
926 /** @hide */
927 public ParcelFileDescriptor getFdToInCall() {
928 return mFdToInCall;
929 }
930 }
931
932 /**
933 * Provides constants to represent the results of responses to session modify requests sent via
934 * {@link Call#sendRttRequest()}
935 */
936 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700937 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800938 /**
939 * Session modify request was successful.
940 */
941 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
942
943 /**
944 * Session modify request failed.
945 */
946 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
947
948 /**
949 * Session modify request ignored due to invalid parameters.
950 */
951 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
952
953 /**
954 * Session modify request timed out.
955 */
956 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
957
958 /**
959 * Session modify request rejected by remote user.
960 */
961 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800962 }
963
964 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700965 * Provides a means of controlling the video session associated with a {@link Connection}.
966 * <p>
967 * Implementations create a custom subclass of {@link VideoProvider} and the
968 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
969 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
970 * should set the {@link VideoProvider}.
971 * <p>
972 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
973 * {@link InCallService} implementations to issue requests related to the video session;
974 * it provides a means for the {@link ConnectionService} to report events and information
975 * related to the video session to Telecom and the {@link InCallService} implementations.
976 * <p>
977 * {@link InCallService} implementations interact with the {@link VideoProvider} via
978 * {@link android.telecom.InCallService.VideoCall}.
979 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700981 /**
982 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700983 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 */
985 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700986
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700988 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
989 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 */
991 public static final int SESSION_EVENT_RX_RESUME = 2;
992
993 /**
994 * Video transmission has begun. This occurs after a negotiated start of video transmission
995 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700996 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700997 */
998 public static final int SESSION_EVENT_TX_START = 3;
999
1000 /**
1001 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1002 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001003 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 */
1005 public static final int SESSION_EVENT_TX_STOP = 4;
1006
1007 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001008 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001009 * this as a cue to inform the user the camera is not available.
1010 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 */
1012 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1013
1014 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001016 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001017 * the camera has become available again.
1018 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 */
1020 public static final int SESSION_EVENT_CAMERA_READY = 6;
1021
1022 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001023 * Session event raised by Telecom when
1024 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1025 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1026 * @see #handleCallSessionEvent(int)
1027 */
1028 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1029
1030 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001032 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001033 */
1034 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1035
1036 /**
1037 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001038 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 */
1040 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1041
1042 /**
1043 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001044 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001045 */
1046 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1047
Rekha Kumar07366812015-03-24 16:42:31 -07001048 /**
1049 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001051 */
1052 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1053
1054 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001055 * Session modify request rejected by remote user.
1056 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001057 */
1058 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1059
Tyler Gunn75958422015-04-15 14:23:42 -07001060 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061 private static final int MSG_SET_CAMERA = 2;
1062 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1063 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1064 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1065 private static final int MSG_SET_ZOOM = 6;
1066 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1067 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1068 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001069 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001070 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001071 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001073 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1074 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1075 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1076 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1077 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1078 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001079 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1080 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001081 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1082
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001083 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001084 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001085
1086 /**
1087 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001088 *
1089 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1090 * load factor before resizing, 1 means we only expect a single thread to
1091 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001092 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001093 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1094 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001095
1096 /**
1097 * Default handler used to consolidate binder method calls onto a single thread.
1098 */
1099 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001100 public VideoProviderHandler() {
1101 super();
1102 }
1103
1104 public VideoProviderHandler(Looper looper) {
1105 super(looper);
1106 }
1107
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 @Override
1109 public void handleMessage(Message msg) {
1110 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001111 case MSG_ADD_VIDEO_CALLBACK: {
1112 IBinder binder = (IBinder) msg.obj;
1113 IVideoCallback callback = IVideoCallback.Stub
1114 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001115 if (callback == null) {
1116 Log.w(this, "addVideoProvider - skipped; callback is null.");
1117 break;
1118 }
1119
Tyler Gunn75958422015-04-15 14:23:42 -07001120 if (mVideoCallbacks.containsKey(binder)) {
1121 Log.i(this, "addVideoProvider - skipped; already present.");
1122 break;
1123 }
1124 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001126 }
1127 case MSG_REMOVE_VIDEO_CALLBACK: {
1128 IBinder binder = (IBinder) msg.obj;
1129 IVideoCallback callback = IVideoCallback.Stub
1130 .asInterface((IBinder) msg.obj);
1131 if (!mVideoCallbacks.containsKey(binder)) {
1132 Log.i(this, "removeVideoProvider - skipped; not present.");
1133 break;
1134 }
1135 mVideoCallbacks.remove(binder);
1136 break;
1137 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001138 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001139 {
1140 SomeArgs args = (SomeArgs) msg.obj;
1141 try {
1142 onSetCamera((String) args.arg1);
1143 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001144 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001145 } finally {
1146 args.recycle();
1147 }
1148 }
1149 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001150 case MSG_SET_PREVIEW_SURFACE:
1151 onSetPreviewSurface((Surface) msg.obj);
1152 break;
1153 case MSG_SET_DISPLAY_SURFACE:
1154 onSetDisplaySurface((Surface) msg.obj);
1155 break;
1156 case MSG_SET_DEVICE_ORIENTATION:
1157 onSetDeviceOrientation(msg.arg1);
1158 break;
1159 case MSG_SET_ZOOM:
1160 onSetZoom((Float) msg.obj);
1161 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001162 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1163 SomeArgs args = (SomeArgs) msg.obj;
1164 try {
1165 onSendSessionModifyRequest((VideoProfile) args.arg1,
1166 (VideoProfile) args.arg2);
1167 } finally {
1168 args.recycle();
1169 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001171 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1173 onSendSessionModifyResponse((VideoProfile) msg.obj);
1174 break;
1175 case MSG_REQUEST_CAMERA_CAPABILITIES:
1176 onRequestCameraCapabilities();
1177 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001178 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1179 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 break;
1181 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001182 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001183 break;
1184 default:
1185 break;
1186 }
1187 }
1188 }
1189
1190 /**
1191 * IVideoProvider stub implementation.
1192 */
1193 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001194 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001195 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001196 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1197 }
1198
1199 public void removeVideoCallback(IBinder videoCallbackBinder) {
1200 mMessageHandler.obtainMessage(
1201 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 }
1203
Tyler Gunn159f35c2017-03-02 09:28:37 -08001204 public void setCamera(String cameraId, String callingPackageName,
1205 int targetSdkVersion) {
1206
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001207 SomeArgs args = SomeArgs.obtain();
1208 args.arg1 = cameraId;
1209 // Propagate the calling package; originally determined in
1210 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1211 // process.
1212 args.arg2 = callingPackageName;
1213 // Pass along the uid and pid of the calling app; this gets lost when we put the
1214 // message onto the handler. These are required for Telecom to perform a permission
1215 // check to see if the calling app is able to use the camera.
1216 args.argi1 = Binder.getCallingUid();
1217 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001218 // Pass along the target SDK version of the calling InCallService. This is used to
1219 // maintain backwards compatibility of the API for older callers.
1220 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001221 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001222 }
1223
1224 public void setPreviewSurface(Surface surface) {
1225 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1226 }
1227
1228 public void setDisplaySurface(Surface surface) {
1229 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1230 }
1231
1232 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001233 mMessageHandler.obtainMessage(
1234 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001235 }
1236
1237 public void setZoom(float value) {
1238 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1239 }
1240
Tyler Gunn45382162015-05-06 08:52:27 -07001241 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1242 SomeArgs args = SomeArgs.obtain();
1243 args.arg1 = fromProfile;
1244 args.arg2 = toProfile;
1245 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001246 }
1247
1248 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1249 mMessageHandler.obtainMessage(
1250 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1251 }
1252
1253 public void requestCameraCapabilities() {
1254 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1255 }
1256
1257 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001258 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001259 }
1260
Yorke Lee32f24732015-05-12 16:18:03 -07001261 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001262 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1263 }
1264 }
1265
1266 public VideoProvider() {
1267 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001268 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001269 }
1270
1271 /**
1272 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1273 *
1274 * @param looper The looper.
1275 * @hide
1276 */
1277 public VideoProvider(Looper looper) {
1278 mBinder = new VideoProvider.VideoProviderBinder();
1279 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001280 }
1281
1282 /**
1283 * Returns binder object which can be used across IPC methods.
1284 * @hide
1285 */
1286 public final IVideoProvider getInterface() {
1287 return mBinder;
1288 }
1289
1290 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001291 * Sets the camera to be used for the outgoing video.
1292 * <p>
1293 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1294 * camera via
1295 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1296 * <p>
1297 * Sent from the {@link InCallService} via
1298 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001300 * @param cameraId The id of the camera (use ids as reported by
1301 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 */
1303 public abstract void onSetCamera(String cameraId);
1304
1305 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001306 * Sets the camera to be used for the outgoing video.
1307 * <p>
1308 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1309 * camera via
1310 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1311 * <p>
1312 * This prototype is used internally to ensure that the calling package name, UID and PID
1313 * are sent to Telecom so that can perform a camera permission check on the caller.
1314 * <p>
1315 * Sent from the {@link InCallService} via
1316 * {@link InCallService.VideoCall#setCamera(String)}.
1317 *
1318 * @param cameraId The id of the camera (use ids as reported by
1319 * {@link CameraManager#getCameraIdList()}).
1320 * @param callingPackageName The AppOpps package name of the caller.
1321 * @param callingUid The UID of the caller.
1322 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001323 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001324 * @hide
1325 */
1326 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001327 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001328
1329 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 * Sets the surface to be used for displaying a preview of what the user's camera is
1331 * currently capturing. When video transmission is enabled, this is the video signal which
1332 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001333 * <p>
1334 * Sent from the {@link InCallService} via
1335 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001337 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 */
1339 public abstract void onSetPreviewSurface(Surface surface);
1340
1341 /**
1342 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001343 * <p>
1344 * Sent from the {@link InCallService} via
1345 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001347 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001348 */
1349 public abstract void onSetDisplaySurface(Surface surface);
1350
1351 /**
1352 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1353 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001354 * <p>
1355 * Sent from the {@link InCallService} via
1356 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001357 *
1358 * @param rotation The device orientation, in degrees.
1359 */
1360 public abstract void onSetDeviceOrientation(int rotation);
1361
1362 /**
1363 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001364 * <p>
1365 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001366 *
1367 * @param value The camera zoom ratio.
1368 */
1369 public abstract void onSetZoom(float value);
1370
1371 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001372 * Issues a request to modify the properties of the current video session.
1373 * <p>
1374 * Example scenarios include: requesting an audio-only call to be upgraded to a
1375 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1376 * when the {@link InCallService} is no longer the foreground application.
1377 * <p>
1378 * If the {@link VideoProvider} determines a request to be invalid, it should call
1379 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1380 * invalid request back to the {@link InCallService}.
1381 * <p>
1382 * Where a request requires confirmation from the user of the peer device, the
1383 * {@link VideoProvider} must communicate the request to the peer device and handle the
1384 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1385 * is used to inform the {@link InCallService} of the result of the request.
1386 * <p>
1387 * Sent from the {@link InCallService} via
1388 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001390 * @param fromProfile The video profile prior to the request.
1391 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 */
Tyler Gunn45382162015-05-06 08:52:27 -07001393 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1394 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395
Tyler Gunnb702ef82015-05-29 11:51:53 -07001396 /**
1397 * Provides a response to a request to change the current video session properties.
1398 * <p>
1399 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1400 * video call, could decline the request and keep the call as audio-only.
1401 * In such a scenario, the {@code responseProfile} would have a video state of
1402 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1403 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1404 * <p>
1405 * Sent from the {@link InCallService} via
1406 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1407 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1408 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001410 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 */
1412 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1413
1414 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001415 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1416 * <p>
1417 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1418 * camera via
1419 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1420 * <p>
1421 * Sent from the {@link InCallService} via
1422 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001423 */
1424 public abstract void onRequestCameraCapabilities();
1425
1426 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001427 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1428 * video component of the current {@link Connection}.
1429 * <p>
1430 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1431 * via {@link VideoProvider#setCallDataUsage(long)}.
1432 * <p>
1433 * Sent from the {@link InCallService} via
1434 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001435 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001436 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001437
1438 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001439 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1440 * the peer device when the video signal is paused.
1441 * <p>
1442 * Sent from the {@link InCallService} via
1443 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 *
1445 * @param uri URI of image to display.
1446 */
Yorke Lee32f24732015-05-12 16:18:03 -07001447 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448
1449 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001450 * Used to inform listening {@link InCallService} implementations when the
1451 * {@link VideoProvider} receives a session modification request.
1452 * <p>
1453 * Received by the {@link InCallService} via
1454 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001455 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001456 * @param videoProfile The requested video profile.
1457 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 */
1459 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001460 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001461 for (IVideoCallback callback : mVideoCallbacks.values()) {
1462 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001463 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001464 } catch (RemoteException ignored) {
1465 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001466 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467 }
1468 }
1469 }
1470
1471 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001472 * Used to inform listening {@link InCallService} implementations when the
1473 * {@link VideoProvider} receives a response to a session modification request.
1474 * <p>
1475 * Received by the {@link InCallService} via
1476 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1477 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001478 *
1479 * @param status Status of the session modify request. Valid values are
1480 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1481 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001482 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1483 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1484 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1485 * @param requestedProfile The original request which was sent to the peer device.
1486 * @param responseProfile The actual profile changes agreed to by the peer device.
1487 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 */
1489 public void receiveSessionModifyResponse(int status,
1490 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001491 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001492 for (IVideoCallback callback : mVideoCallbacks.values()) {
1493 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001494 callback.receiveSessionModifyResponse(status, requestedProfile,
1495 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001496 } catch (RemoteException ignored) {
1497 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001498 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001499 }
1500 }
1501 }
1502
1503 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001504 * Used to inform listening {@link InCallService} implementations when the
1505 * {@link VideoProvider} reports a call session event.
1506 * <p>
1507 * Received by the {@link InCallService} via
1508 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001510 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1511 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1512 * {@link VideoProvider#SESSION_EVENT_TX_START},
1513 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1514 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001515 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1516 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001517 */
1518 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001519 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001520 for (IVideoCallback callback : mVideoCallbacks.values()) {
1521 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001522 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001523 } catch (RemoteException ignored) {
1524 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001525 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001526 }
1527 }
1528 }
1529
1530 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001531 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1532 * peer's video have changed.
1533 * <p>
1534 * This could occur if, for example, the peer rotates their device, changing the aspect
1535 * ratio of the video, or if the user switches between the back and front cameras.
1536 * <p>
1537 * Received by the {@link InCallService} via
1538 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001539 *
1540 * @param width The updated peer video width.
1541 * @param height The updated peer video height.
1542 */
1543 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001544 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001545 for (IVideoCallback callback : mVideoCallbacks.values()) {
1546 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001547 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001548 } catch (RemoteException ignored) {
1549 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001550 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 }
1552 }
1553 }
1554
1555 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001556 * Used to inform listening {@link InCallService} implementations when the data usage of the
1557 * video associated with the current {@link Connection} has changed.
1558 * <p>
1559 * This could be in response to a preview request via
1560 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001561 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1562 * 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 -07001563 * <p>
1564 * Received by the {@link InCallService} via
1565 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001567 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1568 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 */
Yorke Lee32f24732015-05-12 16:18:03 -07001570 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001571 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001572 for (IVideoCallback callback : mVideoCallbacks.values()) {
1573 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001574 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001575 } catch (RemoteException ignored) {
1576 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001577 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001578 }
1579 }
1580 }
1581
1582 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001583 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001584 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001585 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001586 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1587 * @hide
1588 */
1589 public void changeCallDataUsage(long dataUsage) {
1590 setCallDataUsage(dataUsage);
1591 }
1592
1593 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001594 * Used to inform listening {@link InCallService} implementations when the capabilities of
1595 * the current camera have changed.
1596 * <p>
1597 * The {@link VideoProvider} should call this in response to
1598 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1599 * changed via {@link VideoProvider#onSetCamera(String)}.
1600 * <p>
1601 * Received by the {@link InCallService} via
1602 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1603 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001604 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001605 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001606 */
Yorke Lee400470f2015-05-12 13:31:25 -07001607 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001608 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001609 for (IVideoCallback callback : mVideoCallbacks.values()) {
1610 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001611 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001612 } catch (RemoteException ignored) {
1613 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001614 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 }
1616 }
1617 }
Rekha Kumar07366812015-03-24 16:42:31 -07001618
1619 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001620 * Used to inform listening {@link InCallService} implementations when the video quality
1621 * of the call has changed.
1622 * <p>
1623 * Received by the {@link InCallService} via
1624 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001625 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001626 * @param videoQuality The updated video quality. Valid values:
1627 * {@link VideoProfile#QUALITY_HIGH},
1628 * {@link VideoProfile#QUALITY_MEDIUM},
1629 * {@link VideoProfile#QUALITY_LOW},
1630 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001631 */
1632 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001633 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001634 for (IVideoCallback callback : mVideoCallbacks.values()) {
1635 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001636 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001637 } catch (RemoteException ignored) {
1638 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001639 }
Rekha Kumar07366812015-03-24 16:42:31 -07001640 }
1641 }
1642 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001643
1644 /**
1645 * Returns a string representation of a call session event.
1646 *
1647 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1648 * @return String representation of the call session event.
1649 * @hide
1650 */
1651 public static String sessionEventToString(int event) {
1652 switch (event) {
1653 case SESSION_EVENT_CAMERA_FAILURE:
1654 return SESSION_EVENT_CAMERA_FAILURE_STR;
1655 case SESSION_EVENT_CAMERA_READY:
1656 return SESSION_EVENT_CAMERA_READY_STR;
1657 case SESSION_EVENT_RX_PAUSE:
1658 return SESSION_EVENT_RX_PAUSE_STR;
1659 case SESSION_EVENT_RX_RESUME:
1660 return SESSION_EVENT_RX_RESUME_STR;
1661 case SESSION_EVENT_TX_START:
1662 return SESSION_EVENT_TX_START_STR;
1663 case SESSION_EVENT_TX_STOP:
1664 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001665 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1666 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001667 default:
1668 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1669 }
1670 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001671 }
1672
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001673 private final Listener mConnectionDeathListener = new Listener() {
1674 @Override
1675 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001676 if (mConferenceables.remove(c)) {
1677 fireOnConferenceableConnectionsChanged();
1678 }
1679 }
1680 };
1681
1682 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1683 @Override
1684 public void onDestroyed(Conference c) {
1685 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001686 fireOnConferenceableConnectionsChanged();
1687 }
1688 }
1689 };
1690
Jay Shrauner229e3822014-08-15 09:23:07 -07001691 /**
1692 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1693 * load factor before resizing, 1 means we only expect a single thread to
1694 * access the map so make only a single shard
1695 */
1696 private final Set<Listener> mListeners = Collections.newSetFromMap(
1697 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001698 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1699 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001700 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001701
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001702 // The internal telecom call ID associated with this connection.
1703 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001704 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001705 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001706 private Uri mAddress;
1707 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001708 private String mCallerDisplayName;
1709 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001710 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001711 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001712 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001713 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001714 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001715 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001716 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001717 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001718 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001719 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001720 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001721 private Conference mConference;
1722 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001723 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001724 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001725
1726 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001727 * Tracks the key set for the extras bundle provided on the last invocation of
1728 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1729 * keys which were set previously but are no longer present in the replacement Bundle.
1730 */
1731 private Set<String> mPreviousExtraKeys;
1732
1733 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001734 * Create a new Connection.
1735 */
Santos Cordonf2951102014-07-20 19:06:29 -07001736 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001737
1738 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001739 * Returns the Telecom internal call ID associated with this connection. Should only be used
1740 * for debugging and tracing purposes.
1741 *
1742 * @return The Telecom call ID.
1743 * @hide
1744 */
1745 public final String getTelecomCallId() {
1746 return mTelecomCallId;
1747 }
1748
1749 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001750 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001751 */
Andrew Lee100e2932014-09-08 15:34:24 -07001752 public final Uri getAddress() {
1753 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001754 }
1755
1756 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001757 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001758 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001759 */
Andrew Lee100e2932014-09-08 15:34:24 -07001760 public final int getAddressPresentation() {
1761 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001762 }
1763
1764 /**
1765 * @return The caller display name (CNAP).
1766 */
1767 public final String getCallerDisplayName() {
1768 return mCallerDisplayName;
1769 }
1770
1771 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001772 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001773 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001774 */
1775 public final int getCallerDisplayNamePresentation() {
1776 return mCallerDisplayNamePresentation;
1777 }
1778
1779 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001780 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001781 */
1782 public final int getState() {
1783 return mState;
1784 }
1785
1786 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001787 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001788 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1789 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1790 * {@link VideoProfile#STATE_TX_ENABLED},
1791 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001792 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001793 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001794 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001795 */
1796 public final int getVideoState() {
1797 return mVideoState;
1798 }
1799
1800 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001801 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 * being routed by the system. This is {@code null} if this Connection
1803 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001804 * @deprecated Use {@link #getCallAudioState()} instead.
1805 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001806 */
Yorke Lee4af59352015-05-13 14:14:54 -07001807 @SystemApi
1808 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001809 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001810 if (mCallAudioState == null) {
1811 return null;
1812 }
Yorke Lee4af59352015-05-13 14:14:54 -07001813 return new AudioState(mCallAudioState);
1814 }
1815
1816 /**
1817 * @return The audio state of the connection, describing how its audio is currently
1818 * being routed by the system. This is {@code null} if this Connection
1819 * does not directly know about its audio state.
1820 */
1821 public final CallAudioState getCallAudioState() {
1822 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823 }
1824
1825 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001826 * @return The conference that this connection is a part of. Null if it is not part of any
1827 * conference.
1828 */
1829 public final Conference getConference() {
1830 return mConference;
1831 }
1832
1833 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001834 * Returns whether this connection is requesting that the system play a ringback tone
1835 * on its behalf.
1836 */
Andrew Lee100e2932014-09-08 15:34:24 -07001837 public final boolean isRingbackRequested() {
1838 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001839 }
1840
1841 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001842 * @return True if the connection's audio mode is VOIP.
1843 */
1844 public final boolean getAudioModeIsVoip() {
1845 return mAudioModeIsVoip;
1846 }
1847
1848 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001849 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1850 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1851 * start time of the conference.
1852 *
1853 * @return The time at which the {@code Connnection} was connected.
1854 *
1855 * @hide
1856 */
1857 public final long getConnectTimeMillis() {
1858 return mConnectTimeMillis;
1859 }
1860
1861 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001862 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1863 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1864 * start time of the conference.
1865 *
1866 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1867 * changes do not impact the call duration.
1868 *
1869 * @return The time at which the {@link Connection} was connected.
1870 *
1871 * @hide
1872 */
1873 public final long getConnectElapsedTimeMillis() {
1874 return mConnectElapsedTimeMillis;
1875 }
1876
1877 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001878 * @return The status hints for this connection.
1879 */
1880 public final StatusHints getStatusHints() {
1881 return mStatusHints;
1882 }
1883
1884 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001885 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001886 * <p>
1887 * Extras should be updated using {@link #putExtras(Bundle)}.
1888 * <p>
1889 * Telecom or an {@link InCallService} can also update the extras via
1890 * {@link android.telecom.Call#putExtras(Bundle)}, and
1891 * {@link Call#removeExtras(List)}.
1892 * <p>
1893 * The connection is notified of changes to the extras made by Telecom or an
1894 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001895 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001896 * @return The extras associated with this connection.
1897 */
1898 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001899 Bundle extras = null;
1900 synchronized (mExtrasLock) {
1901 if (mExtras != null) {
1902 extras = new Bundle(mExtras);
1903 }
1904 }
1905 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001906 }
1907
1908 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001909 * Assign a listener to be notified of state changes.
1910 *
1911 * @param l A listener.
1912 * @return This Connection.
1913 *
1914 * @hide
1915 */
1916 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001917 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001918 return this;
1919 }
1920
1921 /**
1922 * Remove a previously assigned listener that was being notified of state changes.
1923 *
1924 * @param l A Listener.
1925 * @return This Connection.
1926 *
1927 * @hide
1928 */
1929 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001930 if (l != null) {
1931 mListeners.remove(l);
1932 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001933 return this;
1934 }
1935
1936 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001937 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001938 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001939 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001940 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001941 }
1942
1943 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001944 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1945 * ONLY for debugging purposes.
1946 *
1947 * @param callId The telecom call ID.
1948 * @hide
1949 */
1950 public void setTelecomCallId(String callId) {
1951 mTelecomCallId = callId;
1952 }
1953
1954 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001955 * Inform this Connection that the state of its audio output has been changed externally.
1956 *
1957 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001958 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001959 */
Yorke Lee4af59352015-05-13 14:14:54 -07001960 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001961 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001962 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001963 mCallAudioState = state;
1964 onAudioStateChanged(getAudioState());
1965 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966 }
1967
1968 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001969 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001970 * @return A string representation of the value.
1971 */
1972 public static String stateToString(int state) {
1973 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001974 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001975 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001976 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001977 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001978 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001979 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001980 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001981 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001982 case STATE_PULLING_CALL:
1983 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001984 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001985 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001986 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001987 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001988 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001989 return "DISCONNECTED";
1990 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001991 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001992 return "UNKNOWN";
1993 }
1994 }
1995
1996 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001997 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001998 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001999 public final int getConnectionCapabilities() {
2000 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002001 }
2002
2003 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002004 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2005 */
2006 public final int getConnectionProperties() {
2007 return mConnectionProperties;
2008 }
2009
2010 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002011 * Returns the connection's supported audio routes.
2012 *
2013 * @hide
2014 */
2015 public final int getSupportedAudioRoutes() {
2016 return mSupportedAudioRoutes;
2017 }
2018
2019 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002020 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002021 *
Andrew Lee100e2932014-09-08 15:34:24 -07002022 * @param address The new address.
2023 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002024 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002025 */
Andrew Lee100e2932014-09-08 15:34:24 -07002026 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002027 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002028 Log.d(this, "setAddress %s", address);
2029 mAddress = address;
2030 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002031 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002032 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002033 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002034 }
2035
2036 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002037 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002038 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002039 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002040 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002041 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002042 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002043 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002044 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002045 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002046 mCallerDisplayName = callerDisplayName;
2047 mCallerDisplayNamePresentation = presentation;
2048 for (Listener l : mListeners) {
2049 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2050 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002051 }
2052
2053 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002054 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002055 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2056 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2057 * {@link VideoProfile#STATE_TX_ENABLED},
2058 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002059 *
2060 * @param videoState The new video state.
2061 */
2062 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002063 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002064 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002065 mVideoState = videoState;
2066 for (Listener l : mListeners) {
2067 l.onVideoStateChanged(this, mVideoState);
2068 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002069 }
2070
2071 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002072 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002073 * communicate).
2074 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002075 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002076 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002077 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002078 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002079 }
2080
2081 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002082 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002083 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002084 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002085 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002086 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 }
2088
2089 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002090 * Sets state to initializing (this Connection is not yet ready to be used).
2091 */
2092 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002093 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002094 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002095 }
2096
2097 /**
2098 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2099 */
2100 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002101 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002102 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002103 }
2104
2105 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002106 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002108 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002109 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002110 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111 }
2112
2113 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002114 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2115 * device). Only applicable for {@link Connection}s with
2116 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2117 */
2118 public final void setPulling() {
2119 checkImmutable();
2120 setState(STATE_PULLING_CALL);
2121 }
2122
2123 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002124 * Sets state to be on hold.
2125 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002126 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002127 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002128 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002129 }
2130
2131 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002132 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002133 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002134 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002135 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002136 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002137 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002138 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002139 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002140 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002141 }
2142
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002143 public final VideoProvider getVideoProvider() {
2144 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002145 }
2146
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002147 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002148 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002149 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002150 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002151 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002152 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002153 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002154 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002155 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002156 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002157 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002158 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002159 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002160 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002161 }
2162
2163 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002164 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2165 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2166 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2167 * to send an {@link #onPostDialContinue(boolean)} signal.
2168 *
2169 * @param remaining The DTMF character sequence remaining to be emitted once the
2170 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2171 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002172 */
2173 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002174 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002175 for (Listener l : mListeners) {
2176 l.onPostDialWait(this, remaining);
2177 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002178 }
2179
2180 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002181 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2182 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002183 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002184 *
2185 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002186 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002187 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002188 checkImmutable();
2189 for (Listener l : mListeners) {
2190 l.onPostDialChar(this, nextChar);
2191 }
2192 }
2193
2194 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002195 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002196 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002197 *
2198 * @param ringback Whether the ringback tone is to be played.
2199 */
Andrew Lee100e2932014-09-08 15:34:24 -07002200 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002201 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002202 if (mRingbackRequested != ringback) {
2203 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002204 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002205 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002206 }
2207 }
Ihab Awadf8358972014-05-28 16:46:42 -07002208 }
2209
2210 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002211 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002212 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002214 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002215 public final void setConnectionCapabilities(int connectionCapabilities) {
2216 checkImmutable();
2217 if (mConnectionCapabilities != connectionCapabilities) {
2218 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002219 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002220 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002221 }
2222 }
Santos Cordonb6939982014-06-04 20:20:58 -07002223 }
2224
2225 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002226 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2227 *
2228 * @param connectionProperties The new connection properties.
2229 */
2230 public final void setConnectionProperties(int connectionProperties) {
2231 checkImmutable();
2232 if (mConnectionProperties != connectionProperties) {
2233 mConnectionProperties = connectionProperties;
2234 for (Listener l : mListeners) {
2235 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2236 }
2237 }
2238 }
2239
2240 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002241 * Sets the supported audio routes.
2242 *
2243 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2244 * See {@link CallAudioState}
2245 * @hide
2246 */
2247 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2248 if ((supportedAudioRoutes
2249 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2250 throw new IllegalArgumentException(
2251 "supported audio routes must include either speaker or earpiece");
2252 }
2253
2254 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2255 mSupportedAudioRoutes = supportedAudioRoutes;
2256 for (Listener l : mListeners) {
2257 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2258 }
2259 }
2260 }
2261
2262 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002263 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002264 */
Evan Charlton36a71342014-07-19 16:31:02 -07002265 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002266 for (Listener l : mListeners) {
2267 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002268 }
Santos Cordonb6939982014-06-04 20:20:58 -07002269 }
2270
2271 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002272 * Requests that the framework use VOIP audio mode for this connection.
2273 *
2274 * @param isVoip True if the audio mode is VOIP.
2275 */
2276 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002277 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002278 mAudioModeIsVoip = isVoip;
2279 for (Listener l : mListeners) {
2280 l.onAudioModeIsVoipChanged(this, isVoip);
2281 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002282 }
2283
2284 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002285 * Sets the time at which a call became active on this Connection. This is set only
2286 * when a conference call becomes active on this connection.
2287 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002288 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2289 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002290 *
2291 * @hide
2292 */
2293 public final void setConnectTimeMillis(long connectTimeMillis) {
2294 mConnectTimeMillis = connectTimeMillis;
2295 }
2296
2297 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002298 * Sets the time at which a call became active on this Connection. This is set only
2299 * when a conference call becomes active on this connection.
2300 *
2301 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2302 * {@link SystemClock#elapsedRealtime()}.
2303 *
2304 * @hide
2305 */
Tyler Gunn17541392018-02-01 08:58:38 -08002306 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002307 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2308 }
2309
2310 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002311 * Sets the label and icon status to display in the in-call UI.
2312 *
2313 * @param statusHints The status label and icon to set.
2314 */
2315 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002316 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002317 mStatusHints = statusHints;
2318 for (Listener l : mListeners) {
2319 l.onStatusHintsChanged(this, statusHints);
2320 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002321 }
2322
2323 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002324 * Sets the connections with which this connection can be conferenced.
2325 *
2326 * @param conferenceableConnections The set of connections this connection can conference with.
2327 */
2328 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002329 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002330 clearConferenceableList();
2331 for (Connection c : conferenceableConnections) {
2332 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2333 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002334 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002335 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002336 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002337 }
2338 }
2339 fireOnConferenceableConnectionsChanged();
2340 }
2341
2342 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002343 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2344 * or conferences with which this connection can be conferenced.
2345 *
2346 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002347 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002348 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002349 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002350 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002351 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2352 // small amount of items here.
2353 if (!mConferenceables.contains(c)) {
2354 if (c instanceof Connection) {
2355 Connection connection = (Connection) c;
2356 connection.addConnectionListener(mConnectionDeathListener);
2357 } else if (c instanceof Conference) {
2358 Conference conference = (Conference) c;
2359 conference.addListener(mConferenceDeathListener);
2360 }
2361 mConferenceables.add(c);
2362 }
2363 }
2364 fireOnConferenceableConnectionsChanged();
2365 }
2366
2367 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002368 * @hide
2369 * Resets the cdma connection time.
2370 */
2371 public final void resetConnectionTime() {
2372 for (Listener l : mListeners) {
2373 l.onConnectionTimeReset(this);
2374 }
2375 }
2376
2377 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002378 * Returns the connections or conferences with which this connection can be conferenced.
2379 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002380 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002381 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002382 }
2383
Yorke Lee53463962015-08-04 16:07:19 -07002384 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002385 * @hide
2386 */
2387 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002388 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002389 if (mConnectionService != null) {
2390 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2391 "which is already associated with another ConnectionService.");
2392 } else {
2393 mConnectionService = connectionService;
2394 }
2395 }
2396
2397 /**
2398 * @hide
2399 */
2400 public final void unsetConnectionService(ConnectionService connectionService) {
2401 if (mConnectionService != connectionService) {
2402 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2403 "that does not belong to the ConnectionService.");
2404 } else {
2405 mConnectionService = null;
2406 }
2407 }
2408
2409 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002410 * @hide
2411 */
2412 public final ConnectionService getConnectionService() {
2413 return mConnectionService;
2414 }
2415
2416 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002417 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002418 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002419 *
2420 * @param conference The conference.
2421 * @return {@code true} if the conference was successfully set.
2422 * @hide
2423 */
2424 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002425 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002426 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002427 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002428 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002429 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2430 fireConferenceChanged();
2431 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002432 return true;
2433 }
2434 return false;
2435 }
2436
2437 /**
2438 * Resets the conference that this connection is a part of.
2439 * @hide
2440 */
2441 public final void resetConference() {
2442 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002443 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002444 mConference = null;
2445 fireConferenceChanged();
2446 }
2447 }
2448
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002449 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002450 * Set some extras that can be associated with this {@code Connection}.
2451 * <p>
2452 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2453 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2454 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002455 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2456 * {@link #removeExtras(String...)} methods to modify the extras.
2457 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002458 * 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 -07002459 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2460 *
2461 * @param extras The extras associated with this {@code Connection}.
2462 */
2463 public final void setExtras(@Nullable Bundle extras) {
2464 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002465
2466 // Add/replace any new or changed extras values.
2467 putExtras(extras);
2468
2469 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2470 // the current one and remove any keys that went away.
2471 if (mPreviousExtraKeys != null) {
2472 List<String> toRemove = new ArrayList<String>();
2473 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002474 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002475 toRemove.add(oldKey);
2476 }
2477 }
2478 if (!toRemove.isEmpty()) {
2479 removeExtras(toRemove);
2480 }
2481 }
2482
2483 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2484 // called we can see if the caller has removed any extras values.
2485 if (mPreviousExtraKeys == null) {
2486 mPreviousExtraKeys = new ArraySet<String>();
2487 }
2488 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002489 if (extras != null) {
2490 mPreviousExtraKeys.addAll(extras.keySet());
2491 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002492 }
2493
2494 /**
2495 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2496 * added.
2497 * <p>
2498 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2499 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2500 *
2501 * @param extras The extras to add.
2502 */
2503 public final void putExtras(@NonNull Bundle extras) {
2504 checkImmutable();
2505 if (extras == null) {
2506 return;
2507 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002508 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2509 // the listeners.
2510 Bundle listenerExtras;
2511 synchronized (mExtrasLock) {
2512 if (mExtras == null) {
2513 mExtras = new Bundle();
2514 }
2515 mExtras.putAll(extras);
2516 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002517 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002518 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002519 // Create a new clone of the extras for each listener so that they don't clobber
2520 // each other
2521 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002522 }
2523 }
2524
2525 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002526 * Adds a boolean extra to this {@code Connection}.
2527 *
2528 * @param key The extra key.
2529 * @param value The value.
2530 * @hide
2531 */
2532 public final void putExtra(String key, boolean value) {
2533 Bundle newExtras = new Bundle();
2534 newExtras.putBoolean(key, value);
2535 putExtras(newExtras);
2536 }
2537
2538 /**
2539 * Adds an integer extra to this {@code Connection}.
2540 *
2541 * @param key The extra key.
2542 * @param value The value.
2543 * @hide
2544 */
2545 public final void putExtra(String key, int value) {
2546 Bundle newExtras = new Bundle();
2547 newExtras.putInt(key, value);
2548 putExtras(newExtras);
2549 }
2550
2551 /**
2552 * Adds a string extra to this {@code Connection}.
2553 *
2554 * @param key The extra key.
2555 * @param value The value.
2556 * @hide
2557 */
2558 public final void putExtra(String key, String value) {
2559 Bundle newExtras = new Bundle();
2560 newExtras.putString(key, value);
2561 putExtras(newExtras);
2562 }
2563
2564 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002565 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002566 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002567 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002568 */
2569 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002570 synchronized (mExtrasLock) {
2571 if (mExtras != null) {
2572 for (String key : keys) {
2573 mExtras.remove(key);
2574 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002575 }
2576 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002577 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002578 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002579 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002580 }
2581 }
2582
2583 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002584 * Removes extras from this {@code Connection}.
2585 *
2586 * @param keys The keys of the extras to remove.
2587 */
2588 public final void removeExtras(String ... keys) {
2589 removeExtras(Arrays.asList(keys));
2590 }
2591
2592 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002593 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2594 * be change to the {@link #getCallAudioState()}.
2595 * <p>
2596 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2597 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2598 * <p>
2599 * See also {@link InCallService#setAudioRoute(int)}.
2600 *
2601 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2602 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2603 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2604 */
2605 public final void setAudioRoute(int route) {
2606 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002607 l.onAudioRouteChanged(this, route, null);
2608 }
2609 }
2610
2611 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002612 * Request audio routing to a specific bluetooth device. Calling this method may result in
2613 * the device routing audio to a different bluetooth device than the one specified if the
2614 * bluetooth stack is unable to route audio to the requested device.
2615 * A list of available devices can be obtained via
2616 * {@link CallAudioState#getSupportedBluetoothDevices()}
2617 *
2618 * <p>
2619 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2620 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2621 * <p>
Hall Liu15392832018-04-02 13:52:57 -07002622 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2623 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002624 */
Hall Liu15392832018-04-02 13:52:57 -07002625 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002626 for (Listener l : mListeners) {
Hall Liu15392832018-04-02 13:52:57 -07002627 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2628 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002629 }
2630 }
2631
2632 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002633 * Informs listeners that a previously requested RTT session via
2634 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu13ee5762017-12-04 14:19:30 -08002635 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 */
2637 public final void sendRttInitiationSuccess() {
2638 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2639 }
2640
2641 /**
2642 * Informs listeners that a previously requested RTT session via
Hall Liu13ee5762017-12-04 14:19:30 -08002643 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002644 * has failed.
2645 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2646 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002647 */
2648 public final void sendRttInitiationFailure(int reason) {
2649 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2650 }
2651
2652 /**
2653 * Informs listeners that a currently active RTT session has been terminated by the remote
2654 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002655 */
2656 public final void sendRttSessionRemotelyTerminated() {
2657 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2658 }
2659
2660 /**
2661 * Informs listeners that the remote side of the call has requested an upgrade to include an
2662 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002663 */
2664 public final void sendRemoteRttRequest() {
2665 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2666 }
2667
2668 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002669 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002670 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002671 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002672 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2673 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002674 */
Yorke Lee4af59352015-05-13 14:14:54 -07002675 @SystemApi
2676 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002677 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002678
2679 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002680 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2681 *
2682 * @param state The new connection audio state.
2683 */
2684 public void onCallAudioStateChanged(CallAudioState state) {}
2685
2686 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002687 * Notifies this Connection of an internal state change. This method is called after the
2688 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002689 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002690 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002691 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002692 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002693
2694 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002695 * Notifies this Connection of a request to play a DTMF tone.
2696 *
2697 * @param c A DTMF character.
2698 */
Santos Cordonf2951102014-07-20 19:06:29 -07002699 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002700
2701 /**
2702 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2703 */
Santos Cordonf2951102014-07-20 19:06:29 -07002704 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002705
2706 /**
2707 * Notifies this Connection of a request to disconnect.
2708 */
Santos Cordonf2951102014-07-20 19:06:29 -07002709 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002710
2711 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002712 * Notifies this Connection of a request to disconnect a participant of the conference managed
2713 * by the connection.
2714 *
2715 * @param endpoint the {@link Uri} of the participant to disconnect.
2716 * @hide
2717 */
2718 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2719
2720 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002721 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002722 */
Santos Cordonf2951102014-07-20 19:06:29 -07002723 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002724
2725 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002726 * Notifies this Connection of a request to abort.
2727 */
Santos Cordonf2951102014-07-20 19:06:29 -07002728 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002729
2730 /**
2731 * Notifies this Connection of a request to hold.
2732 */
Santos Cordonf2951102014-07-20 19:06:29 -07002733 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002734
2735 /**
2736 * Notifies this Connection of a request to exit a hold state.
2737 */
Santos Cordonf2951102014-07-20 19:06:29 -07002738 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002739
2740 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002741 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002742 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002743 * <p>
2744 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2745 * the default dialer's {@link InCallService}.
2746 * <p>
2747 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2748 * Telecom framework may request that the call is answered in the following circumstances:
2749 * <ul>
2750 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2751 * <li>A car mode {@link InCallService} is in use which has declared
2752 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2753 * {@link InCallService} will be able to see calls from self-managed
2754 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2755 * behalf.</li>
2756 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002757 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002758 */
Santos Cordonf2951102014-07-20 19:06:29 -07002759 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002760
2761 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002762 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002763 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002764 * <p>
2765 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2766 * the default dialer's {@link InCallService}.
2767 * <p>
2768 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2769 * Telecom framework may request that the call is answered in the following circumstances:
2770 * <ul>
2771 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2772 * <li>A car mode {@link InCallService} is in use which has declared
2773 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2774 * {@link InCallService} will be able to see calls from self-managed
2775 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2776 * behalf.</li>
2777 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002778 */
2779 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002780 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002781 }
2782
2783 /**
2784 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302785 * a request to deflect.
2786 */
2787 public void onDeflect(Uri address) {}
2788
2789 /**
2790 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002791 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002792 * <p>
2793 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2794 * the default dialer's {@link InCallService}.
2795 * <p>
2796 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2797 * Telecom framework may request that the call is rejected in the following circumstances:
2798 * <ul>
2799 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2800 * <li>A car mode {@link InCallService} is in use which has declared
2801 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2802 * {@link InCallService} will be able to see calls from self-managed
2803 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2804 * behalf.</li>
2805 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002806 */
Santos Cordonf2951102014-07-20 19:06:29 -07002807 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002808
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002809 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002810 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2811 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002812 */
2813 public void onReject(String replyMessage) {}
2814
2815 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002816 * Notifies this Connection of a request to silence the ringer.
2817 * <p>
2818 * The ringer may be silenced by any of the following methods:
2819 * <ul>
2820 * <li>{@link TelecomManager#silenceRinger()}</li>
2821 * <li>The user presses the volume-down button while a call is ringing.</li>
2822 * </ul>
2823 * <p>
2824 * Self-managed {@link ConnectionService} implementations should override this method in their
2825 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2826 * your app set the ringtone as part of the incoming call {@link Notification} (see
2827 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2828 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2829 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2830 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002831 */
2832 public void onSilence() {}
2833
2834 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002835 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2836 */
Santos Cordonf2951102014-07-20 19:06:29 -07002837 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002838
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002839 /**
2840 * Notifies this Connection of a request to pull an external call to the local device.
2841 * <p>
2842 * The {@link InCallService} issues a request to pull an external call to the local device via
2843 * {@link Call#pullExternalCall()}.
2844 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002845 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2846 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002847 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002848 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002849 */
2850 public void onPullExternalCall() {}
2851
2852 /**
2853 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2854 * <p>
2855 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2856 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002857 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2858 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2859 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2860 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2861 * not aware of.
2862 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002863 * See also {@link Call#sendCallEvent(String, Bundle)}.
2864 *
2865 * @param event The call event.
2866 * @param extras Extras associated with the call event.
2867 */
2868 public void onCallEvent(String event, Bundle extras) {}
2869
Tyler Gunndee56a82016-03-23 16:06:34 -07002870 /**
Tyler Gunn858bfaf2018-01-22 15:17:54 -08002871 * Notifies this {@link Connection} that a handover has completed.
2872 * <p>
2873 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2874 * Bundle)} on the initiating side of the handover, and on the receiving side with
2875 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2876 */
2877 public void onHandoverComplete() {}
2878
2879 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002880 * Notifies this {@link Connection} of a change to the extras made outside the
2881 * {@link ConnectionService}.
2882 * <p>
2883 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2884 * the {@link android.telecom.Call#putExtras(Bundle)} and
2885 * {@link Call#removeExtras(List)}.
2886 *
2887 * @param extras The new extras bundle.
2888 */
2889 public void onExtrasChanged(Bundle extras) {}
2890
Tyler Gunnf5035432017-01-09 09:43:12 -08002891 /**
2892 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2893 * displaying its incoming call user interface for the {@link Connection}.
2894 * <p>
2895 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2896 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2897 * should show its own incoming call user interface.
2898 * <p>
2899 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002900 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2901 * Telecom framework will display its own incoming call user interface to allow the user to
2902 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2903 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002904 * <p>
2905 * You should trigger the display of the incoming call user interface for your application by
2906 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002907 *
2908 * In your application code, you should create a {@link android.app.NotificationChannel} for
2909 * incoming call notifications from your app:
2910 * <pre><code>
2911 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2912 * NotificationManager.IMPORTANCE_MAX);
2913 * // other channel setup stuff goes here.
2914 *
2915 * // We'll use the default system ringtone for our incoming call notification channel. You can
2916 * // use your own audio resource here.
2917 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2918 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2919 * // Setting the AudioAttributes is important as it identifies the purpose of your
2920 * // notification sound.
2921 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2922 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2923 * .build());
2924 *
2925 * NotificationManager mgr = getSystemService(NotificationManager.class);
2926 * mgr.createNotificationChannel(channel);
2927 * </code></pre>
2928 * When it comes time to post a notification for your incoming call, ensure it uses your
2929 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002930 * <pre><code>
2931 * // Create an intent which triggers your fullscreen incoming call user interface.
2932 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2933 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2934 * intent.setClass(context, YourIncomingCallActivity.class);
2935 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2936 *
2937 * // Build the notification as an ongoing high priority item; this ensures it will show as
2938 * // a heads up notification which slides down over top of the current content.
2939 * final Notification.Builder builder = new Notification.Builder(context);
2940 * builder.setOngoing(true);
2941 * builder.setPriority(Notification.PRIORITY_HIGH);
2942 *
2943 * // Set notification content intent to take user to fullscreen UI if user taps on the
2944 * // notification body.
2945 * builder.setContentIntent(pendingIntent);
2946 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2947 * // manager deems it appropriate.
2948 * builder.setFullScreenIntent(pendingIntent, true);
2949 *
2950 * // Setup notification content.
2951 * builder.setSmallIcon( yourIconResourceId );
2952 * builder.setContentTitle("Your notification title");
2953 * builder.setContentText("Your notification content.");
2954 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002955 * // Set notification as insistent to cause your ringtone to loop.
2956 * Notification notification = builder.build();
2957 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08002958 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002959 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002960 * NotificationManager notificationManager = mContext.getSystemService(
2961 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07002962 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08002963 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002964 */
2965 public void onShowIncomingCallUi() {}
2966
Hall Liub64ac4c2017-02-06 10:49:48 -08002967 /**
2968 * Notifies this {@link Connection} that the user has requested an RTT session.
2969 * The connection service should call {@link #sendRttInitiationSuccess} or
2970 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2971 * request, respectively.
2972 * @param rttTextStream The object that should be used to send text to or receive text from
2973 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002974 */
2975 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2976
2977 /**
2978 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2979 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002980 */
2981 public void onStopRtt() {}
2982
2983 /**
2984 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2985 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2986 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2987 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002988 * @param rttTextStream The object that should be used to send text to or receive text from
2989 * the in-call app.
2990 */
2991 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2992
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002993 static String toLogSafePhoneNumber(String number) {
2994 // For unknown number, log empty string.
2995 if (number == null) {
2996 return "";
2997 }
2998
2999 if (PII_DEBUG) {
3000 // When PII_DEBUG is true we emit PII.
3001 return number;
3002 }
3003
3004 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3005 // sanitized phone numbers.
3006 StringBuilder builder = new StringBuilder();
3007 for (int i = 0; i < number.length(); i++) {
3008 char c = number.charAt(i);
3009 if (c == '-' || c == '@' || c == '.') {
3010 builder.append(c);
3011 } else {
3012 builder.append('x');
3013 }
3014 }
3015 return builder.toString();
3016 }
3017
Ihab Awad542e0ea2014-05-16 10:22:16 -07003018 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003019 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003020 if (mState == STATE_DISCONNECTED && mState != state) {
3021 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003022 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003023 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003024 if (mState != state) {
3025 Log.d(this, "setState: %s", stateToString(state));
3026 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003027 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003028 for (Listener l : mListeners) {
3029 l.onStateChanged(this, state);
3030 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003031 }
3032 }
3033
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003034 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003035 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003036 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3037 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003038 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003039 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003040
3041 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003042 if (mImmutable) {
3043 throw new UnsupportedOperationException("Connection is immutable");
3044 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003045 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003046 }
3047
Evan Charltonbf11f982014-07-20 22:06:28 -07003048 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003049 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003050 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3051 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003052 * <p>
3053 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3054 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003055 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003056 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003057 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003058 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003059 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3060 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003061 }
3062
Evan Charltonbf11f982014-07-20 22:06:28 -07003063 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003064 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3065 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3066 * this should never be un-@hide-den.
3067 *
3068 * @hide
3069 */
3070 public void checkImmutable() {}
3071
3072 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003073 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3074 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3075 * that state. This connection should not be used for anything, and no other
3076 * {@code Connection}s should be attempted.
3077 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003078 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003079 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003080 * @return A {@code Connection} which indicates that the underlying connection should
3081 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003082 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003083 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003084 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003085 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003086
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003087 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003088 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003089 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003090 }
3091 }
3092
Santos Cordon823fd3c2014-08-07 18:35:18 -07003093 private final void fireConferenceChanged() {
3094 for (Listener l : mListeners) {
3095 l.onConferenceChanged(this, mConference);
3096 }
3097 }
3098
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003099 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003100 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003101 if (c instanceof Connection) {
3102 Connection connection = (Connection) c;
3103 connection.removeConnectionListener(mConnectionDeathListener);
3104 } else if (c instanceof Conference) {
3105 Conference conference = (Conference) c;
3106 conference.removeListener(mConferenceDeathListener);
3107 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003108 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003109 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003110 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003111
3112 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003113 * Handles a change to extras received from Telecom.
3114 *
3115 * @param extras The new extras.
3116 * @hide
3117 */
3118 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003119 Bundle b = null;
3120 synchronized (mExtrasLock) {
3121 mExtras = extras;
3122 if (mExtras != null) {
3123 b = new Bundle(mExtras);
3124 }
3125 }
3126 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003127 }
3128
3129 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003130 * Notifies listeners that the merge request failed.
3131 *
3132 * @hide
3133 */
3134 protected final void notifyConferenceMergeFailed() {
3135 for (Listener l : mListeners) {
3136 l.onConferenceMergeFailed(this);
3137 }
3138 }
3139
3140 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003141 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003142 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003143 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003144 * @hide
3145 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003146 protected final void updateConferenceParticipants(
3147 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003148 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003149 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003150 }
3151 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003152
3153 /**
3154 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003155 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003156 */
3157 protected void notifyConferenceStarted() {
3158 for (Listener l : mListeners) {
3159 l.onConferenceStarted();
3160 }
3161 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003162
3163 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003164 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3165 * be a part of a conference call.
3166 * @param isConferenceSupported {@code true} if the connection supports being part of a
3167 * conference call, {@code false} otherwise.
3168 * @hide
3169 */
3170 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3171 for (Listener l : mListeners) {
3172 l.onConferenceSupportedChanged(this, isConferenceSupported);
3173 }
3174 }
3175
3176 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303177 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3178 * changed due to an emergency call being redialed.
3179 * @param pHandle The new PhoneAccountHandle for this connection.
3180 * @hide
3181 */
3182 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3183 for (Listener l : mListeners) {
3184 l.onPhoneAccountChanged(this, pHandle);
3185 }
3186 }
3187
3188 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003189 * Sends an event associated with this {@code Connection} with associated event extras to the
3190 * {@link InCallService}.
3191 * <p>
3192 * Connection events are used to communicate point in time information from a
3193 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3194 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3195 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3196 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3197 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3198 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3199 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3200 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3201 * <p>
3202 * Events are exposed to {@link InCallService} implementations via
3203 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3204 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003205 * 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 -07003206 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3207 * some events altogether.
3208 * <p>
3209 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3210 * conflicts between {@link ConnectionService} implementations. Further, custom
3211 * {@link ConnectionService} implementations shall not re-purpose events in the
3212 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3213 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3214 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3215 * {@code com.example.extra.MY_EXTRA}).
3216 * <p>
3217 * When defining events and the associated extras, it is important to keep their behavior
3218 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3219 * events/extras should me maintained to ensure backwards compatibility with older
3220 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003221 *
3222 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003223 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003224 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003225 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003226 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003227 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003228 }
3229 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003230}