blob: 24184e033c66be6f9a14b276c04f010663403d44 [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;
Eric Erfanianaf7b8c02018-01-17 15:27:39 -080038import android.os.Parcelable;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070040import android.os.SystemClock;
Tyler Gunndee56a82016-03-23 16:06:34 -070041import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043
Hall Liu95d55872017-01-25 17:12:49 -080044import java.io.IOException;
45import java.io.InputStreamReader;
46import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070047import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070048import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070050import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070052import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053
54/**
Santos Cordon895d4b82015-06-25 16:41:48 -070055 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
56 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070057 * <p>
58 * Implementations create a custom subclass of {@code Connection} and return it to the framework
59 * as the return value of
60 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
61 * or
62 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
63 * Implementations are then responsible for updating the state of the {@code Connection}, and
64 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
65 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070066 * <p>
67 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
68 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
69 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
70 * {@code Connection} instance.
71 * <p>
72 * Basic call support requires overriding the following methods: {@link #onAnswer()},
73 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
74 * <p>
75 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
76 * {@link #onUnhold()} methods should be overridden to provide hold support for the
77 * {@code Connection}.
78 * <p>
79 * Where a {@code Connection} supports a variation of video calling (e.g. the
80 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
81 * to support answering a call as a video call.
82 * <p>
83 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
84 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
85 * support for pulling the external call.
86 * <p>
87 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
88 * overridden.
89 * <p>
90 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
91 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
92 * for example, call events from a {@link InCallService} are handled,
93 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
94 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
95 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
96 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -070097 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070098public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070099
Santos Cordon895d4b82015-06-25 16:41:48 -0700100 /**
101 * The connection is initializing. This is generally the first state for a {@code Connection}
102 * returned by a {@link ConnectionService}.
103 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 public static final int STATE_INITIALIZING = 0;
105
Santos Cordon895d4b82015-06-25 16:41:48 -0700106 /**
107 * The connection is new and not connected.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_NEW = 1;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * An incoming connection is in the ringing state. During this state, the user's ringer or
113 * vibration feature will be activated.
114 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 public static final int STATE_RINGING = 2;
116
Santos Cordon895d4b82015-06-25 16:41:48 -0700117 /**
118 * An outgoing connection is in the dialing state. In this state the other party has not yet
119 * answered the call and the user traditionally hears a ringback tone.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_DIALING = 3;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * A connection is active. Both parties are connected to the call and can actively communicate.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_ACTIVE = 4;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is on hold.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_HOLDING = 5;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection has been disconnected. This is the final state once the user has been
135 * disconnected from a call either locally, remotely or by an error in the service.
136 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 public static final int STATE_DISCONNECTED = 6;
138
Santos Cordon895d4b82015-06-25 16:41:48 -0700139 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700140 * The state of an external connection which is in the process of being pulled from a remote
141 * device to the local device.
142 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700143 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700144 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
145 */
146 public static final int STATE_PULLING_CALL = 7;
147
148 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700149 * Connection can currently be put on hold or unheld. This is distinct from
150 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
151 * it does not at the moment support the function. This can be true while the call is in the
152 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
153 * display a disabled 'hold' button.
154 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 public static final int CAPABILITY_HOLD = 0x00000001;
156
157 /** Connection supports the hold feature. */
158 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
159
160 /**
161 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
162 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
163 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
164 * capability allows a merge button to be shown while the conference is in the foreground
165 * of the in-call UI.
166 * <p>
167 * This is only intended for use by a {@link Conference}.
168 */
169 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
170
171 /**
172 * Connections within a conference can be swapped between foreground and background.
173 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
174 * <p>
175 * This is only intended for use by a {@link Conference}.
176 */
177 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
178
179 /**
180 * @hide
181 */
182 public static final int CAPABILITY_UNUSED = 0x00000010;
183
184 /** Connection supports responding via text option. */
185 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
186
187 /** Connection can be muted. */
188 public static final int CAPABILITY_MUTE = 0x00000040;
189
190 /**
191 * Connection supports conference management. This capability only applies to
192 * {@link Conference}s which can have {@link Connection}s as children.
193 */
194 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
195
196 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800198 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700210 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211
212 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800214 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
216
217 /**
218 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 */
220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
221
222 /**
223 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700226 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800227
228 /**
229 * Connection is able to be separated from its parent {@code Conference}, if any.
230 */
231 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
232
233 /**
234 * Connection is able to be individually disconnected when in a {@code Conference}.
235 */
236 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
237
238 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800240 * @hide
241 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700242 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700244 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700245 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700246 * @hide
247 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700248 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249
250 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700251 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700252 * @hide
253 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700254 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255
Tyler Gunn068085b2015-02-06 13:56:52 -0800256 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700257 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800258 * @hide
259 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700260 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800261
Tyler Gunn96d6c402015-03-18 12:39:23 -0700262 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500263 * Speed up audio setup for MT call.
264 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700265 */
266 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800267
Rekha Kumar07366812015-03-24 16:42:31 -0700268 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700269 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700270 */
271 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
272
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700273 /**
274 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700275 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700276 */
277 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
278
Tyler Gunnd4091732015-06-29 09:15:37 -0700279 /**
280 * For a conference, indicates the conference will not have child connections.
281 * <p>
282 * An example of a conference with child connections is a GSM conference call, where the radio
283 * retains connections to the individual participants of the conference. Another example is an
284 * IMS conference call where conference event package functionality is supported; in this case
285 * the conference server ensures the radio is aware of the participants in the conference, which
286 * are represented by child connections.
287 * <p>
288 * An example of a conference with no child connections is an IMS conference call with no
289 * conference event package support. Such a conference is represented by the radio as a single
290 * connection to the IMS conference server.
291 * <p>
292 * Indicating whether a conference has children or not is important to help user interfaces
293 * visually represent a conference. A conference with no children, for example, will have the
294 * conference connection shown in the list of calls on a Bluetooth device, where if the
295 * conference has children, only the children will be shown in the list of calls on a Bluetooth
296 * device.
297 * @hide
298 */
299 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
300
Bryce Lee81901682015-08-28 16:38:02 -0700301 /**
302 * Indicates that the connection itself wants to handle any sort of reply response, rather than
303 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700304 */
305 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
306
Tyler Gunnf97a0092016-01-19 15:59:34 -0800307 /**
308 * When set, prevents a video call from being downgraded to an audio-only call.
309 * <p>
310 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
311 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
312 * downgraded from a video call back to a VideoState of
313 * {@link VideoProfile#STATE_AUDIO_ONLY}.
314 * <p>
315 * Intuitively, a call which can be downgraded to audio should also have local and remote
316 * video
317 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
318 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
319 */
320 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
321
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700322 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700323 * When set for an external connection, indicates that this {@code Connection} can be pulled
324 * from a remote device to the current device.
325 * <p>
326 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
327 * is set.
328 */
329 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
330
Pooja Jaind34698d2017-12-28 14:15:31 +0530331 /** Call supports the deflect feature. */
332 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
333
Tyler Gunn720c6642016-03-22 09:02:47 -0700334 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530335 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700336 //**********************************************************************************************
337
338 /**
339 * Indicates that the current device callback number should be shown.
340 *
341 * @hide
342 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700343 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700344
345 /**
346 * Whether the call is a generic conference, where we do not know the precise state of
347 * participants in the conference (eg. on CDMA).
348 *
349 * @hide
350 */
351 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
352
353 /**
354 * Connection is using high definition audio.
355 * @hide
356 */
357 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
358
359 /**
360 * Connection is using WIFI.
361 * @hide
362 */
363 public static final int PROPERTY_WIFI = 1<<3;
364
365 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700366 * When set, indicates that the {@code Connection} does not actually exist locally for the
367 * {@link ConnectionService}.
368 * <p>
369 * Consider, for example, a scenario where a user has two devices with the same phone number.
370 * When a user places a call on one devices, the telephony stack can represent that call on the
371 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700372 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700373 * <p>
374 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
375 * external connections. Only those {@link InCallService}s which have the
376 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
377 * manifest will see external connections.
378 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700379 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700380
Brad Ebinger15847072016-05-18 11:08:36 -0700381 /**
382 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
383 */
384 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700385
Hall Liu9f332c72016-07-14 15:37:37 -0700386 /**
387 * Indicates that the connection represents a downgraded IMS conference.
388 * @hide
389 */
390 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
391
Tyler Gunnf5035432017-01-09 09:43:12 -0800392 /**
393 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
394 * {@link ConnectionService}.
395 * <p>
396 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
397 */
398 public static final int PROPERTY_SELF_MANAGED = 1<<7;
399
Hall Liu95d55872017-01-25 17:12:49 -0800400 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800401 * Set by the framework to indicate that a connection has an active RTT session associated with
402 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800403 */
404 public static final int PROPERTY_IS_RTT = 1 << 8;
405
Eric Erfanian62706c52017-12-06 16:27:53 -0800406 /**
407 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfanian62706c52017-12-06 16:27:53 -0800408 */
409 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
410
Tyler Gunn96d6c402015-03-18 12:39:23 -0700411 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800412 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700413 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800414
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700415 /**
416 * Connection extra key used to store the last forwarded number associated with the current
417 * connection. Used to communicate to the user interface that the connection was forwarded via
418 * the specified number.
419 */
420 public static final String EXTRA_LAST_FORWARDED_NUMBER =
421 "android.telecom.extra.LAST_FORWARDED_NUMBER";
422
423 /**
424 * Connection extra key used to store a child number associated with the current connection.
425 * Used to communicate to the user interface that the connection was received via
426 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
427 * address.
428 */
429 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
430
431 /**
432 * Connection extra key used to store the subject for an incoming call. The user interface can
433 * query this extra and display its contents for incoming calls. Will only be used if the
434 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
435 */
436 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
437
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800438 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700439 * Boolean connection extra key set on a {@link Connection} in
440 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
441 * current active foreground call to be dropped.
442 */
443 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
444 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
445
446 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700447 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
448 * state to indicate the name of the third-party app which is responsible for the current
449 * foreground call.
450 * <p>
451 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
452 * is able to inform the user that answering the new incoming call will cause a call owned by
453 * another app to be dropped when the incoming call is answered.
454 */
455 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
456 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
457
458 /**
Hall Liu10208662016-06-15 17:55:00 -0700459 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700460 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700461 * @hide
462 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700463 public static final String EXTRA_DISABLE_ADD_CALL =
464 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700465
466 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700467 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
468 * original Connection ID associated with the connection. Used in
469 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
470 * connection/conference added via
471 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
472 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
473 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
474 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
475 * be a way to ensure that we don't add the connection again as a duplicate.
476 * <p>
477 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
478 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
479 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
480 * in a new {@link Connection} which it adds to Telecom via
481 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
482 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
483 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
484 * ID it originally referred to the connection as. Thus Telecom needs to know that the
485 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
486 * @hide
487 */
488 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
489 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
490
491 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800492 * Connection event used to inform Telecom that it should play the on hold tone. This is used
493 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700494 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800495 * @hide
496 */
497 public static final String EVENT_ON_HOLD_TONE_START =
498 "android.telecom.event.ON_HOLD_TONE_START";
499
500 /**
501 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
502 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700503 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800504 * @hide
505 */
506 public static final String EVENT_ON_HOLD_TONE_END =
507 "android.telecom.event.ON_HOLD_TONE_END";
508
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700509 /**
510 * Connection event used to inform {@link InCallService}s when pulling of an external call has
511 * failed. The user interface should inform the user of the error.
512 * <p>
513 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
514 * API is called on a {@link Call} with the properties
515 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
516 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
517 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700518 * <p>
519 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
520 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700521 */
522 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
523
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700524 /**
525 * Connection event used to inform {@link InCallService}s when the merging of two calls has
526 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700527 * <p>
528 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
529 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700530 */
531 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
532
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700533 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700534 * Connection event used to inform {@link InCallService}s when the process of merging a
535 * Connection into a conference has begun.
536 * <p>
537 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
538 * expected to be null when this connection event is used.
539 * @hide
540 */
541 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
542
543 /**
544 * Connection event used to inform {@link InCallService}s when the process of merging a
545 * Connection into a conference has completed.
546 * <p>
547 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
548 * expected to be null when this connection event is used.
549 * @hide
550 */
551 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
552
553 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700554 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
555 * the remote party.
556 * <p>
557 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
558 * call is being held locally on the device. When a capable {@link ConnectionService} receives
559 * signalling to indicate that the remote party has put the call on hold, it can send this
560 * connection event.
561 * @hide
562 */
563 public static final String EVENT_CALL_REMOTELY_HELD =
564 "android.telecom.event.CALL_REMOTELY_HELD";
565
566 /**
567 * Connection event used to inform {@link InCallService}s when a call which was remotely held
568 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
569 * <p>
570 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
571 * call is being held locally on the device. When a capable {@link ConnectionService} receives
572 * signalling to indicate that the remote party has taken the call off hold, it can send this
573 * connection event.
574 * @hide
575 */
576 public static final String EVENT_CALL_REMOTELY_UNHELD =
577 "android.telecom.event.CALL_REMOTELY_UNHELD";
578
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700579 /**
580 * Connection event used to inform an {@link InCallService} which initiated a call handover via
581 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
582 * successfully completed.
583 * @hide
584 */
585 public static final String EVENT_HANDOVER_COMPLETE =
586 "android.telecom.event.HANDOVER_COMPLETE";
587
588 /**
589 * Connection event used to inform an {@link InCallService} which initiated a call handover via
590 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
591 * to complete.
592 * @hide
593 */
594 public static final String EVENT_HANDOVER_FAILED =
595 "android.telecom.event.HANDOVER_FAILED";
596
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 // Flag controlling whether PII is emitted into the logs
598 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
599
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800600 /**
601 * Whether the given capabilities support the specified capability.
602 *
603 * @param capabilities A capability bit field.
604 * @param capability The capability to check capabilities for.
605 * @return Whether the specified capability is supported.
606 * @hide
607 */
608 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800609 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800610 }
611
612 /**
613 * Whether the capabilities of this {@code Connection} supports the specified capability.
614 *
615 * @param capability The capability to check capabilities for.
616 * @return Whether the specified capability is supported.
617 * @hide
618 */
619 public boolean can(int capability) {
620 return can(mConnectionCapabilities, capability);
621 }
622
623 /**
624 * Removes the specified capability from the set of capabilities of this {@code Connection}.
625 *
626 * @param capability The capability to remove from the set.
627 * @hide
628 */
629 public void removeCapability(int capability) {
630 mConnectionCapabilities &= ~capability;
631 }
632
633 /**
634 * Adds the specified capability to the set of capabilities of this {@code Connection}.
635 *
636 * @param capability The capability to add to the set.
637 * @hide
638 */
639 public void addCapability(int capability) {
640 mConnectionCapabilities |= capability;
641 }
642
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700643 /**
644 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
645 *
646 * @param capabilities A capability bit field.
647 * @return A human readable string representation.
648 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700650 return capabilitiesToStringInternal(capabilities, true /* isLong */);
651 }
652
653 /**
654 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
655 * string.
656 *
657 * @param capabilities A capability bit field.
658 * @return A human readable string representation.
659 * @hide
660 */
661 public static String capabilitiesToStringShort(int capabilities) {
662 return capabilitiesToStringInternal(capabilities, false /* isLong */);
663 }
664
665 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800666 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700667 builder.append("[");
668 if (isLong) {
669 builder.append("Capabilities:");
670 }
671
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800672 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700673 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 }
675 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700676 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 }
678 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700679 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800680 }
681 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700682 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 }
684 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700685 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800686 }
687 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700688 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800689 }
690 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700691 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800692 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700693 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700694 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700695 }
696 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700697 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700699 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700700 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800701 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700702 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700703 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700704 }
705 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700706 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700707 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700708 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700709 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800710 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800711 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700712 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800713 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500714 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700715 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500716 }
Rekha Kumar07366812015-03-24 16:42:31 -0700717 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700718 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700719 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700720 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700721 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700722 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700723 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700724 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700725 }
Bryce Lee81901682015-08-28 16:38:02 -0700726 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700727 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700728 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700729 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700730 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700731 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530732 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
733 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
734 }
Bryce Lee81901682015-08-28 16:38:02 -0700735
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800736 builder.append("]");
737 return builder.toString();
738 }
739
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700740 /**
741 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
742 *
743 * @param properties A property bit field.
744 * @return A human readable string representation.
745 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700746 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700747 return propertiesToStringInternal(properties, true /* isLong */);
748 }
749
750 /**
751 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
752 *
753 * @param properties A property bit field.
754 * @return A human readable string representation.
755 * @hide
756 */
757 public static String propertiesToStringShort(int properties) {
758 return propertiesToStringInternal(properties, false /* isLong */);
759 }
760
761 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700762 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700763 builder.append("[");
764 if (isLong) {
765 builder.append("Properties:");
766 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700767
Tyler Gunnf5035432017-01-09 09:43:12 -0800768 if (can(properties, PROPERTY_SELF_MANAGED)) {
769 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
770 }
771
Hall Liu25c7c4d2016-08-30 13:41:02 -0700772 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
773 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700774 }
775
776 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700777 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700778 }
779
780 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700781 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700782 }
783
784 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700785 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700786 }
787
788 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700789 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700790 }
791
Brad Ebinger15847072016-05-18 11:08:36 -0700792 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700793 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700794 }
795
Hall Liud4d2a8a2018-01-29 17:22:02 -0800796 if (can(properties, PROPERTY_IS_RTT)) {
797 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
798 }
799
Tyler Gunn720c6642016-03-22 09:02:47 -0700800 builder.append("]");
801 return builder.toString();
802 }
803
Sailesh Nepal091768c2014-06-30 15:15:23 -0700804 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700805 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700806 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700807 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700808 public void onCallerDisplayNameChanged(
809 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700810 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700811 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700812 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800813 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700814 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700815 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700817 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800818 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819 public void onVideoProviderChanged(
820 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700821 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
822 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800823 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700824 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700825 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700826 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800827 public void onConferenceParticipantsChanged(Connection c,
828 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800829 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700830 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700831 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700832 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700833 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700834 /** @hide */
835 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800836 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800837 public void onRttInitiationSuccess(Connection c) {}
838 public void onRttInitiationFailure(Connection c, int reason) {}
839 public void onRttSessionRemotelyTerminated(Connection c) {}
840 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530841 /** @hide */
842 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700843 }
844
Tyler Gunnb702ef82015-05-29 11:51:53 -0700845 /**
Hall Liu95d55872017-01-25 17:12:49 -0800846 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800847 */
848 public static final class RttTextStream {
849 private static final int READ_BUFFER_SIZE = 1000;
850 private final InputStreamReader mPipeFromInCall;
851 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800852 private final ParcelFileDescriptor mFdFromInCall;
853 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800854 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
855
856 /**
857 * @hide
858 */
859 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800860 mFdFromInCall = fromInCall;
861 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800862 mPipeFromInCall = new InputStreamReader(
863 new ParcelFileDescriptor.AutoCloseInputStream(fromInCall));
864 mPipeToInCall = new OutputStreamWriter(
865 new ParcelFileDescriptor.AutoCloseOutputStream(toInCall));
866 }
867
868 /**
869 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
870 * RTT transmits text in real-time, this method should be called as often as text snippets
871 * are received from the remote user, even if it is only one character.
872 *
873 * This method is not thread-safe -- calling it from multiple threads simultaneously may
874 * lead to interleaved text.
875 * @param input The message to send to the in-call app.
876 */
877 public void write(String input) throws IOException {
878 mPipeToInCall.write(input);
879 mPipeToInCall.flush();
880 }
881
882
883 /**
884 * Reads a string from the in-call app, blocking if there is no data available. Returns
885 * {@code null} if the RTT conversation has been terminated and there is no further data
886 * to read.
887 *
888 * This method is not thread-safe -- calling it from multiple threads simultaneously may
889 * lead to interleaved text.
890 * @return A string containing text entered by the user, or {@code null} if the
891 * conversation has been terminated or if there was an error while reading.
892 */
Hall Liuffa4a812017-03-02 16:11:00 -0800893 public String read() throws IOException {
894 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
895 if (numRead < 0) {
896 return null;
897 }
898 return new String(mReadBuffer, 0, numRead);
899 }
900
901 /**
902 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
903 * be read.
904 * @return A string containing text entered by the user, or {@code null} if the user has
905 * not entered any new text yet.
906 */
907 public String readImmediately() throws IOException {
908 if (mPipeFromInCall.ready()) {
909 return read();
910 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800911 return null;
912 }
913 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800914
915 /** @hide */
916 public ParcelFileDescriptor getFdFromInCall() {
917 return mFdFromInCall;
918 }
919
920 /** @hide */
921 public ParcelFileDescriptor getFdToInCall() {
922 return mFdToInCall;
923 }
924 }
925
926 /**
927 * Provides constants to represent the results of responses to session modify requests sent via
928 * {@link Call#sendRttRequest()}
929 */
930 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700931 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800932 /**
933 * Session modify request was successful.
934 */
935 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
936
937 /**
938 * Session modify request failed.
939 */
940 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
941
942 /**
943 * Session modify request ignored due to invalid parameters.
944 */
945 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
946
947 /**
948 * Session modify request timed out.
949 */
950 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
951
952 /**
953 * Session modify request rejected by remote user.
954 */
955 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800956 }
957
958 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700959 * Provides a means of controlling the video session associated with a {@link Connection}.
960 * <p>
961 * Implementations create a custom subclass of {@link VideoProvider} and the
962 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
963 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
964 * should set the {@link VideoProvider}.
965 * <p>
966 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
967 * {@link InCallService} implementations to issue requests related to the video session;
968 * it provides a means for the {@link ConnectionService} to report events and information
969 * related to the video session to Telecom and the {@link InCallService} implementations.
970 * <p>
971 * {@link InCallService} implementations interact with the {@link VideoProvider} via
972 * {@link android.telecom.InCallService.VideoCall}.
973 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 /**
976 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700977 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700978 */
979 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700980
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700981 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700982 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
983 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 */
985 public static final int SESSION_EVENT_RX_RESUME = 2;
986
987 /**
988 * Video transmission has begun. This occurs after a negotiated start of video transmission
989 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700990 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 */
992 public static final int SESSION_EVENT_TX_START = 3;
993
994 /**
995 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
996 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 */
999 public static final int SESSION_EVENT_TX_STOP = 4;
1000
1001 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001002 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001003 * this as a cue to inform the user the camera is not available.
1004 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 */
1006 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1007
1008 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001009 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001010 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001011 * the camera has become available again.
1012 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001013 */
1014 public static final int SESSION_EVENT_CAMERA_READY = 6;
1015
1016 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001017 * Session event raised by Telecom when
1018 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1019 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1020 * @see #handleCallSessionEvent(int)
1021 */
1022 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1023
1024 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001025 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001026 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 */
1028 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1029
1030 /**
1031 * Session modify request failed.
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_FAIL = 2;
1035
1036 /**
1037 * Session modify request ignored due to invalid parameters.
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_INVALID = 3;
1041
Rekha Kumar07366812015-03-24 16:42:31 -07001042 /**
1043 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001044 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001045 */
1046 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1047
1048 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * Session modify request rejected by remote user.
1050 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001051 */
1052 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1053
Tyler Gunn75958422015-04-15 14:23:42 -07001054 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001055 private static final int MSG_SET_CAMERA = 2;
1056 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1057 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1058 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1059 private static final int MSG_SET_ZOOM = 6;
1060 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1061 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1062 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001063 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001064 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001065 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001066
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001067 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1068 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1069 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1070 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1071 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1072 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001073 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1074 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001075 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1076
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001077 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001078 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001079
1080 /**
1081 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001082 *
1083 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1084 * load factor before resizing, 1 means we only expect a single thread to
1085 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001086 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001087 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1088 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089
1090 /**
1091 * Default handler used to consolidate binder method calls onto a single thread.
1092 */
1093 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001094 public VideoProviderHandler() {
1095 super();
1096 }
1097
1098 public VideoProviderHandler(Looper looper) {
1099 super(looper);
1100 }
1101
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 @Override
1103 public void handleMessage(Message msg) {
1104 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001105 case MSG_ADD_VIDEO_CALLBACK: {
1106 IBinder binder = (IBinder) msg.obj;
1107 IVideoCallback callback = IVideoCallback.Stub
1108 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001109 if (callback == null) {
1110 Log.w(this, "addVideoProvider - skipped; callback is null.");
1111 break;
1112 }
1113
Tyler Gunn75958422015-04-15 14:23:42 -07001114 if (mVideoCallbacks.containsKey(binder)) {
1115 Log.i(this, "addVideoProvider - skipped; already present.");
1116 break;
1117 }
1118 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001119 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001120 }
1121 case MSG_REMOVE_VIDEO_CALLBACK: {
1122 IBinder binder = (IBinder) msg.obj;
1123 IVideoCallback callback = IVideoCallback.Stub
1124 .asInterface((IBinder) msg.obj);
1125 if (!mVideoCallbacks.containsKey(binder)) {
1126 Log.i(this, "removeVideoProvider - skipped; not present.");
1127 break;
1128 }
1129 mVideoCallbacks.remove(binder);
1130 break;
1131 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001133 {
1134 SomeArgs args = (SomeArgs) msg.obj;
1135 try {
1136 onSetCamera((String) args.arg1);
1137 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001138 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001139 } finally {
1140 args.recycle();
1141 }
1142 }
1143 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001144 case MSG_SET_PREVIEW_SURFACE:
1145 onSetPreviewSurface((Surface) msg.obj);
1146 break;
1147 case MSG_SET_DISPLAY_SURFACE:
1148 onSetDisplaySurface((Surface) msg.obj);
1149 break;
1150 case MSG_SET_DEVICE_ORIENTATION:
1151 onSetDeviceOrientation(msg.arg1);
1152 break;
1153 case MSG_SET_ZOOM:
1154 onSetZoom((Float) msg.obj);
1155 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001156 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1157 SomeArgs args = (SomeArgs) msg.obj;
1158 try {
1159 onSendSessionModifyRequest((VideoProfile) args.arg1,
1160 (VideoProfile) args.arg2);
1161 } finally {
1162 args.recycle();
1163 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001165 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001166 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1167 onSendSessionModifyResponse((VideoProfile) msg.obj);
1168 break;
1169 case MSG_REQUEST_CAMERA_CAPABILITIES:
1170 onRequestCameraCapabilities();
1171 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001172 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1173 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001174 break;
1175 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001176 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 break;
1178 default:
1179 break;
1180 }
1181 }
1182 }
1183
1184 /**
1185 * IVideoProvider stub implementation.
1186 */
1187 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001188 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001189 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001190 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1191 }
1192
1193 public void removeVideoCallback(IBinder videoCallbackBinder) {
1194 mMessageHandler.obtainMessage(
1195 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001196 }
1197
Tyler Gunn159f35c2017-03-02 09:28:37 -08001198 public void setCamera(String cameraId, String callingPackageName,
1199 int targetSdkVersion) {
1200
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001201 SomeArgs args = SomeArgs.obtain();
1202 args.arg1 = cameraId;
1203 // Propagate the calling package; originally determined in
1204 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1205 // process.
1206 args.arg2 = callingPackageName;
1207 // Pass along the uid and pid of the calling app; this gets lost when we put the
1208 // message onto the handler. These are required for Telecom to perform a permission
1209 // check to see if the calling app is able to use the camera.
1210 args.argi1 = Binder.getCallingUid();
1211 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001212 // Pass along the target SDK version of the calling InCallService. This is used to
1213 // maintain backwards compatibility of the API for older callers.
1214 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001215 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001216 }
1217
1218 public void setPreviewSurface(Surface surface) {
1219 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1220 }
1221
1222 public void setDisplaySurface(Surface surface) {
1223 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1224 }
1225
1226 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001227 mMessageHandler.obtainMessage(
1228 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001229 }
1230
1231 public void setZoom(float value) {
1232 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1233 }
1234
Tyler Gunn45382162015-05-06 08:52:27 -07001235 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1236 SomeArgs args = SomeArgs.obtain();
1237 args.arg1 = fromProfile;
1238 args.arg2 = toProfile;
1239 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 }
1241
1242 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1243 mMessageHandler.obtainMessage(
1244 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1245 }
1246
1247 public void requestCameraCapabilities() {
1248 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1249 }
1250
1251 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001252 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 }
1254
Yorke Lee32f24732015-05-12 16:18:03 -07001255 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001256 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1257 }
1258 }
1259
1260 public VideoProvider() {
1261 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001262 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001263 }
1264
1265 /**
1266 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1267 *
1268 * @param looper The looper.
1269 * @hide
1270 */
1271 public VideoProvider(Looper looper) {
1272 mBinder = new VideoProvider.VideoProviderBinder();
1273 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 }
1275
1276 /**
1277 * Returns binder object which can be used across IPC methods.
1278 * @hide
1279 */
1280 public final IVideoProvider getInterface() {
1281 return mBinder;
1282 }
1283
1284 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001285 * Sets the camera to be used for the outgoing video.
1286 * <p>
1287 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1288 * camera via
1289 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1290 * <p>
1291 * Sent from the {@link InCallService} via
1292 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001294 * @param cameraId The id of the camera (use ids as reported by
1295 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001296 */
1297 public abstract void onSetCamera(String cameraId);
1298
1299 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001300 * Sets the camera to be used for the outgoing video.
1301 * <p>
1302 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1303 * camera via
1304 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1305 * <p>
1306 * This prototype is used internally to ensure that the calling package name, UID and PID
1307 * are sent to Telecom so that can perform a camera permission check on the caller.
1308 * <p>
1309 * Sent from the {@link InCallService} via
1310 * {@link InCallService.VideoCall#setCamera(String)}.
1311 *
1312 * @param cameraId The id of the camera (use ids as reported by
1313 * {@link CameraManager#getCameraIdList()}).
1314 * @param callingPackageName The AppOpps package name of the caller.
1315 * @param callingUid The UID of the caller.
1316 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001317 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001318 * @hide
1319 */
1320 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001321 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001322
1323 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 * Sets the surface to be used for displaying a preview of what the user's camera is
1325 * currently capturing. When video transmission is enabled, this is the video signal which
1326 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001327 * <p>
1328 * Sent from the {@link InCallService} via
1329 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001331 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001332 */
1333 public abstract void onSetPreviewSurface(Surface surface);
1334
1335 /**
1336 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001337 * <p>
1338 * Sent from the {@link InCallService} via
1339 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001340 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001341 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 */
1343 public abstract void onSetDisplaySurface(Surface surface);
1344
1345 /**
1346 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1347 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * <p>
1349 * Sent from the {@link InCallService} via
1350 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001351 *
1352 * @param rotation The device orientation, in degrees.
1353 */
1354 public abstract void onSetDeviceOrientation(int rotation);
1355
1356 /**
1357 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001358 * <p>
1359 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001360 *
1361 * @param value The camera zoom ratio.
1362 */
1363 public abstract void onSetZoom(float value);
1364
1365 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001366 * Issues a request to modify the properties of the current video session.
1367 * <p>
1368 * Example scenarios include: requesting an audio-only call to be upgraded to a
1369 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1370 * when the {@link InCallService} is no longer the foreground application.
1371 * <p>
1372 * If the {@link VideoProvider} determines a request to be invalid, it should call
1373 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1374 * invalid request back to the {@link InCallService}.
1375 * <p>
1376 * Where a request requires confirmation from the user of the peer device, the
1377 * {@link VideoProvider} must communicate the request to the peer device and handle the
1378 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1379 * is used to inform the {@link InCallService} of the result of the request.
1380 * <p>
1381 * Sent from the {@link InCallService} via
1382 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001383 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001384 * @param fromProfile The video profile prior to the request.
1385 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001386 */
Tyler Gunn45382162015-05-06 08:52:27 -07001387 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1388 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389
Tyler Gunnb702ef82015-05-29 11:51:53 -07001390 /**
1391 * Provides a response to a request to change the current video session properties.
1392 * <p>
1393 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1394 * video call, could decline the request and keep the call as audio-only.
1395 * In such a scenario, the {@code responseProfile} would have a video state of
1396 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1397 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1398 * <p>
1399 * Sent from the {@link InCallService} via
1400 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1401 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1402 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001404 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 */
1406 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1407
1408 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1410 * <p>
1411 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1412 * camera via
1413 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1414 * <p>
1415 * Sent from the {@link InCallService} via
1416 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001417 */
1418 public abstract void onRequestCameraCapabilities();
1419
1420 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001421 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1422 * video component of the current {@link Connection}.
1423 * <p>
1424 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1425 * via {@link VideoProvider#setCallDataUsage(long)}.
1426 * <p>
1427 * Sent from the {@link InCallService} via
1428 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001429 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001430 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431
1432 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001433 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1434 * the peer device when the video signal is paused.
1435 * <p>
1436 * Sent from the {@link InCallService} via
1437 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 *
1439 * @param uri URI of image to display.
1440 */
Yorke Lee32f24732015-05-12 16:18:03 -07001441 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442
1443 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001444 * Used to inform listening {@link InCallService} implementations when the
1445 * {@link VideoProvider} receives a session modification request.
1446 * <p>
1447 * Received by the {@link InCallService} via
1448 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001450 * @param videoProfile The requested video profile.
1451 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452 */
1453 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001454 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001455 for (IVideoCallback callback : mVideoCallbacks.values()) {
1456 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001457 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001458 } catch (RemoteException ignored) {
1459 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001460 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001461 }
1462 }
1463 }
1464
1465 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001466 * Used to inform listening {@link InCallService} implementations when the
1467 * {@link VideoProvider} receives a response to a session modification request.
1468 * <p>
1469 * Received by the {@link InCallService} via
1470 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1471 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 *
1473 * @param status Status of the session modify request. Valid values are
1474 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1475 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001476 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1477 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1478 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1479 * @param requestedProfile The original request which was sent to the peer device.
1480 * @param responseProfile The actual profile changes agreed to by the peer device.
1481 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 */
1483 public void receiveSessionModifyResponse(int status,
1484 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001485 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001486 for (IVideoCallback callback : mVideoCallbacks.values()) {
1487 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001488 callback.receiveSessionModifyResponse(status, requestedProfile,
1489 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001490 } catch (RemoteException ignored) {
1491 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001492 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 }
1494 }
1495 }
1496
1497 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001498 * Used to inform listening {@link InCallService} implementations when the
1499 * {@link VideoProvider} reports a call session event.
1500 * <p>
1501 * Received by the {@link InCallService} via
1502 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001504 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1505 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1506 * {@link VideoProvider#SESSION_EVENT_TX_START},
1507 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1508 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001509 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1510 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511 */
1512 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001513 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001514 for (IVideoCallback callback : mVideoCallbacks.values()) {
1515 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001516 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001517 } catch (RemoteException ignored) {
1518 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001519 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001520 }
1521 }
1522 }
1523
1524 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001525 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1526 * peer's video have changed.
1527 * <p>
1528 * This could occur if, for example, the peer rotates their device, changing the aspect
1529 * ratio of the video, or if the user switches between the back and front cameras.
1530 * <p>
1531 * Received by the {@link InCallService} via
1532 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001533 *
1534 * @param width The updated peer video width.
1535 * @param height The updated peer video height.
1536 */
1537 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001538 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001539 for (IVideoCallback callback : mVideoCallbacks.values()) {
1540 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001541 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001542 } catch (RemoteException ignored) {
1543 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001544 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 }
1546 }
1547 }
1548
1549 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001550 * Used to inform listening {@link InCallService} implementations when the data usage of the
1551 * video associated with the current {@link Connection} has changed.
1552 * <p>
1553 * This could be in response to a preview request via
1554 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001555 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1556 * 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 -07001557 * <p>
1558 * Received by the {@link InCallService} via
1559 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001561 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1562 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001563 */
Yorke Lee32f24732015-05-12 16:18:03 -07001564 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001565 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001566 for (IVideoCallback callback : mVideoCallbacks.values()) {
1567 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001568 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001569 } catch (RemoteException ignored) {
1570 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001571 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001572 }
1573 }
1574 }
1575
1576 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001577 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001578 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001579 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001580 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1581 * @hide
1582 */
1583 public void changeCallDataUsage(long dataUsage) {
1584 setCallDataUsage(dataUsage);
1585 }
1586
1587 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001588 * Used to inform listening {@link InCallService} implementations when the capabilities of
1589 * the current camera have changed.
1590 * <p>
1591 * The {@link VideoProvider} should call this in response to
1592 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1593 * changed via {@link VideoProvider#onSetCamera(String)}.
1594 * <p>
1595 * Received by the {@link InCallService} via
1596 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1597 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001598 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001599 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 */
Yorke Lee400470f2015-05-12 13:31:25 -07001601 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001602 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001603 for (IVideoCallback callback : mVideoCallbacks.values()) {
1604 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001605 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001606 } catch (RemoteException ignored) {
1607 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001608 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 }
1610 }
1611 }
Rekha Kumar07366812015-03-24 16:42:31 -07001612
1613 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001614 * Used to inform listening {@link InCallService} implementations when the video quality
1615 * of the call has changed.
1616 * <p>
1617 * Received by the {@link InCallService} via
1618 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001619 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001620 * @param videoQuality The updated video quality. Valid values:
1621 * {@link VideoProfile#QUALITY_HIGH},
1622 * {@link VideoProfile#QUALITY_MEDIUM},
1623 * {@link VideoProfile#QUALITY_LOW},
1624 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001625 */
1626 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001627 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001628 for (IVideoCallback callback : mVideoCallbacks.values()) {
1629 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001630 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001631 } catch (RemoteException ignored) {
1632 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001633 }
Rekha Kumar07366812015-03-24 16:42:31 -07001634 }
1635 }
1636 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001637
1638 /**
1639 * Returns a string representation of a call session event.
1640 *
1641 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1642 * @return String representation of the call session event.
1643 * @hide
1644 */
1645 public static String sessionEventToString(int event) {
1646 switch (event) {
1647 case SESSION_EVENT_CAMERA_FAILURE:
1648 return SESSION_EVENT_CAMERA_FAILURE_STR;
1649 case SESSION_EVENT_CAMERA_READY:
1650 return SESSION_EVENT_CAMERA_READY_STR;
1651 case SESSION_EVENT_RX_PAUSE:
1652 return SESSION_EVENT_RX_PAUSE_STR;
1653 case SESSION_EVENT_RX_RESUME:
1654 return SESSION_EVENT_RX_RESUME_STR;
1655 case SESSION_EVENT_TX_START:
1656 return SESSION_EVENT_TX_START_STR;
1657 case SESSION_EVENT_TX_STOP:
1658 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001659 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1660 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001661 default:
1662 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1663 }
1664 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001665 }
1666
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001667 private final Listener mConnectionDeathListener = new Listener() {
1668 @Override
1669 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001670 if (mConferenceables.remove(c)) {
1671 fireOnConferenceableConnectionsChanged();
1672 }
1673 }
1674 };
1675
1676 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1677 @Override
1678 public void onDestroyed(Conference c) {
1679 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001680 fireOnConferenceableConnectionsChanged();
1681 }
1682 }
1683 };
1684
Jay Shrauner229e3822014-08-15 09:23:07 -07001685 /**
1686 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1687 * load factor before resizing, 1 means we only expect a single thread to
1688 * access the map so make only a single shard
1689 */
1690 private final Set<Listener> mListeners = Collections.newSetFromMap(
1691 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001692 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1693 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001694 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001695
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001696 // The internal telecom call ID associated with this connection.
1697 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001698 // The PhoneAccountHandle associated with this connection.
1699 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001701 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001702 private Uri mAddress;
1703 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001704 private String mCallerDisplayName;
1705 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001706 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001707 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001708 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001709 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001711 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001712 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001713 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001714 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001715 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001716 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001717 private Conference mConference;
1718 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001719 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001720 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001721
1722 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001723 * Tracks the key set for the extras bundle provided on the last invocation of
1724 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1725 * keys which were set previously but are no longer present in the replacement Bundle.
1726 */
1727 private Set<String> mPreviousExtraKeys;
1728
1729 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001730 * Create a new Connection.
1731 */
Santos Cordonf2951102014-07-20 19:06:29 -07001732 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001733
1734 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001735 * Returns the Telecom internal call ID associated with this connection. Should only be used
1736 * for debugging and tracing purposes.
1737 *
1738 * @return The Telecom call ID.
1739 * @hide
1740 */
1741 public final String getTelecomCallId() {
1742 return mTelecomCallId;
1743 }
1744
1745 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001746 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001747 */
Andrew Lee100e2932014-09-08 15:34:24 -07001748 public final Uri getAddress() {
1749 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001750 }
1751
1752 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001753 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001754 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001755 */
Andrew Lee100e2932014-09-08 15:34:24 -07001756 public final int getAddressPresentation() {
1757 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001758 }
1759
1760 /**
1761 * @return The caller display name (CNAP).
1762 */
1763 public final String getCallerDisplayName() {
1764 return mCallerDisplayName;
1765 }
1766
1767 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001768 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001769 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001770 */
1771 public final int getCallerDisplayNamePresentation() {
1772 return mCallerDisplayNamePresentation;
1773 }
1774
1775 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001776 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001777 */
1778 public final int getState() {
1779 return mState;
1780 }
1781
1782 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001783 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001784 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1785 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1786 * {@link VideoProfile#STATE_TX_ENABLED},
1787 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001788 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001789 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001790 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001791 */
1792 public final int getVideoState() {
1793 return mVideoState;
1794 }
1795
1796 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001797 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001798 * being routed by the system. This is {@code null} if this Connection
1799 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001800 * @deprecated Use {@link #getCallAudioState()} instead.
1801 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 */
Yorke Lee4af59352015-05-13 14:14:54 -07001803 @SystemApi
1804 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001805 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001806 if (mCallAudioState == null) {
1807 return null;
1808 }
Yorke Lee4af59352015-05-13 14:14:54 -07001809 return new AudioState(mCallAudioState);
1810 }
1811
1812 /**
1813 * @return The audio state of the connection, describing how its audio is currently
1814 * being routed by the system. This is {@code null} if this Connection
1815 * does not directly know about its audio state.
1816 */
1817 public final CallAudioState getCallAudioState() {
1818 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001819 }
1820
1821 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001822 * @return The conference that this connection is a part of. Null if it is not part of any
1823 * conference.
1824 */
1825 public final Conference getConference() {
1826 return mConference;
1827 }
1828
1829 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001830 * Returns whether this connection is requesting that the system play a ringback tone
1831 * on its behalf.
1832 */
Andrew Lee100e2932014-09-08 15:34:24 -07001833 public final boolean isRingbackRequested() {
1834 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001835 }
1836
1837 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001838 * @return True if the connection's audio mode is VOIP.
1839 */
1840 public final boolean getAudioModeIsVoip() {
1841 return mAudioModeIsVoip;
1842 }
1843
1844 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001845 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1846 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1847 * start time of the conference.
1848 *
1849 * @return The time at which the {@code Connnection} was connected.
1850 *
1851 * @hide
1852 */
1853 public final long getConnectTimeMillis() {
1854 return mConnectTimeMillis;
1855 }
1856
1857 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001858 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1859 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1860 * start time of the conference.
1861 *
1862 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1863 * changes do not impact the call duration.
1864 *
1865 * @return The time at which the {@link Connection} was connected.
1866 *
1867 * @hide
1868 */
1869 public final long getConnectElapsedTimeMillis() {
1870 return mConnectElapsedTimeMillis;
1871 }
1872
1873 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001874 * @return The status hints for this connection.
1875 */
1876 public final StatusHints getStatusHints() {
1877 return mStatusHints;
1878 }
1879
1880 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001881 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001882 * <p>
1883 * Extras should be updated using {@link #putExtras(Bundle)}.
1884 * <p>
1885 * Telecom or an {@link InCallService} can also update the extras via
1886 * {@link android.telecom.Call#putExtras(Bundle)}, and
1887 * {@link Call#removeExtras(List)}.
1888 * <p>
1889 * The connection is notified of changes to the extras made by Telecom or an
1890 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001891 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001892 * @return The extras associated with this connection.
1893 */
1894 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001895 Bundle extras = null;
1896 synchronized (mExtrasLock) {
1897 if (mExtras != null) {
1898 extras = new Bundle(mExtras);
1899 }
1900 }
1901 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001902 }
1903
1904 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001905 * Assign a listener to be notified of state changes.
1906 *
1907 * @param l A listener.
1908 * @return This Connection.
1909 *
1910 * @hide
1911 */
1912 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001913 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914 return this;
1915 }
1916
1917 /**
1918 * Remove a previously assigned listener that was being notified of state changes.
1919 *
1920 * @param l A Listener.
1921 * @return This Connection.
1922 *
1923 * @hide
1924 */
1925 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001926 if (l != null) {
1927 mListeners.remove(l);
1928 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001929 return this;
1930 }
1931
1932 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001933 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001934 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001935 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001936 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001937 }
1938
1939 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001940 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1941 * ONLY for debugging purposes.
1942 *
1943 * @param callId The telecom call ID.
1944 * @hide
1945 */
1946 public void setTelecomCallId(String callId) {
1947 mTelecomCallId = callId;
1948 }
1949
1950 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001951 * Inform this Connection that the state of its audio output has been changed externally.
1952 *
1953 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001954 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001955 */
Yorke Lee4af59352015-05-13 14:14:54 -07001956 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001957 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001958 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001959 mCallAudioState = state;
1960 onAudioStateChanged(getAudioState());
1961 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001962 }
1963
1964 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001965 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001966 * @return A string representation of the value.
1967 */
1968 public static String stateToString(int state) {
1969 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001970 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001971 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001972 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001973 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001974 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001975 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001976 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001977 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001978 case STATE_PULLING_CALL:
1979 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001980 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001981 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001982 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001983 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001984 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001985 return "DISCONNECTED";
1986 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001987 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001988 return "UNKNOWN";
1989 }
1990 }
1991
1992 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001993 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001994 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001995 public final int getConnectionCapabilities() {
1996 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001997 }
1998
1999 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002000 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2001 */
2002 public final int getConnectionProperties() {
2003 return mConnectionProperties;
2004 }
2005
2006 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002007 * Returns the connection's supported audio routes.
2008 *
2009 * @hide
2010 */
2011 public final int getSupportedAudioRoutes() {
2012 return mSupportedAudioRoutes;
2013 }
2014
2015 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002016 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002017 *
Andrew Lee100e2932014-09-08 15:34:24 -07002018 * @param address The new address.
2019 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002020 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002021 */
Andrew Lee100e2932014-09-08 15:34:24 -07002022 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002023 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002024 Log.d(this, "setAddress %s", address);
2025 mAddress = address;
2026 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002027 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002028 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002029 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002030 }
2031
2032 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002033 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002034 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002035 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002036 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002037 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002038 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002039 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002040 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002041 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002042 mCallerDisplayName = callerDisplayName;
2043 mCallerDisplayNamePresentation = presentation;
2044 for (Listener l : mListeners) {
2045 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2046 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002047 }
2048
2049 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002050 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002051 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2052 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2053 * {@link VideoProfile#STATE_TX_ENABLED},
2054 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002055 *
2056 * @param videoState The new video state.
2057 */
2058 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002059 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002060 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002061 mVideoState = videoState;
2062 for (Listener l : mListeners) {
2063 l.onVideoStateChanged(this, mVideoState);
2064 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002065 }
2066
2067 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002068 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002069 * communicate).
2070 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002071 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002072 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002073 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002074 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002075 }
2076
2077 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002078 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002079 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002080 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002081 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002082 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002083 }
2084
2085 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002086 * Sets state to initializing (this Connection is not yet ready to be used).
2087 */
2088 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002089 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002090 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002091 }
2092
2093 /**
2094 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2095 */
2096 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002098 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002099 }
2100
2101 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002102 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002103 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002104 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002105 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002106 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 }
2108
2109 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002110 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2111 * device). Only applicable for {@link Connection}s with
2112 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2113 */
2114 public final void setPulling() {
2115 checkImmutable();
2116 setState(STATE_PULLING_CALL);
2117 }
2118
2119 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002120 * Sets state to be on hold.
2121 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002122 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002123 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002124 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002125 }
2126
2127 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002128 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002129 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002132 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002133 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002134 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002135 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002136 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002137 }
2138
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002139 public final VideoProvider getVideoProvider() {
2140 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002141 }
2142
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002143 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002144 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002145 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002146 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002147 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002148 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002149 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002150 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002151 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002152 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002153 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002154 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002155 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002156 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002157 }
2158
2159 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002160 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2161 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2162 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2163 * to send an {@link #onPostDialContinue(boolean)} signal.
2164 *
2165 * @param remaining The DTMF character sequence remaining to be emitted once the
2166 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2167 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002168 */
2169 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002171 for (Listener l : mListeners) {
2172 l.onPostDialWait(this, remaining);
2173 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002174 }
2175
2176 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002177 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2178 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002179 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002180 *
2181 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002182 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002183 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002184 checkImmutable();
2185 for (Listener l : mListeners) {
2186 l.onPostDialChar(this, nextChar);
2187 }
2188 }
2189
2190 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002191 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002192 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002193 *
2194 * @param ringback Whether the ringback tone is to be played.
2195 */
Andrew Lee100e2932014-09-08 15:34:24 -07002196 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002197 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002198 if (mRingbackRequested != ringback) {
2199 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002200 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002201 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002202 }
2203 }
Ihab Awadf8358972014-05-28 16:46:42 -07002204 }
2205
2206 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002207 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002208 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002209 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002210 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002211 public final void setConnectionCapabilities(int connectionCapabilities) {
2212 checkImmutable();
2213 if (mConnectionCapabilities != connectionCapabilities) {
2214 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002215 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002216 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002217 }
2218 }
Santos Cordonb6939982014-06-04 20:20:58 -07002219 }
2220
2221 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002222 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2223 *
2224 * @param connectionProperties The new connection properties.
2225 */
2226 public final void setConnectionProperties(int connectionProperties) {
2227 checkImmutable();
2228 if (mConnectionProperties != connectionProperties) {
2229 mConnectionProperties = connectionProperties;
2230 for (Listener l : mListeners) {
2231 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2232 }
2233 }
2234 }
2235
2236 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002237 * Sets the supported audio routes.
2238 *
2239 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2240 * See {@link CallAudioState}
2241 * @hide
2242 */
2243 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2244 if ((supportedAudioRoutes
2245 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2246 throw new IllegalArgumentException(
2247 "supported audio routes must include either speaker or earpiece");
2248 }
2249
2250 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2251 mSupportedAudioRoutes = supportedAudioRoutes;
2252 for (Listener l : mListeners) {
2253 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2254 }
2255 }
2256 }
2257
2258 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002259 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002260 */
Evan Charlton36a71342014-07-19 16:31:02 -07002261 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002262 for (Listener l : mListeners) {
2263 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002264 }
Santos Cordonb6939982014-06-04 20:20:58 -07002265 }
2266
2267 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002268 * Requests that the framework use VOIP audio mode for this connection.
2269 *
2270 * @param isVoip True if the audio mode is VOIP.
2271 */
2272 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002273 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002274 mAudioModeIsVoip = isVoip;
2275 for (Listener l : mListeners) {
2276 l.onAudioModeIsVoipChanged(this, isVoip);
2277 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002278 }
2279
2280 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002281 * Sets the time at which a call became active on this Connection. This is set only
2282 * when a conference call becomes active on this connection.
2283 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002284 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2285 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002286 *
2287 * @hide
2288 */
2289 public final void setConnectTimeMillis(long connectTimeMillis) {
2290 mConnectTimeMillis = connectTimeMillis;
2291 }
2292
2293 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002294 * Sets the time at which a call became active on this Connection. This is set only
2295 * when a conference call becomes active on this connection.
2296 *
2297 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2298 * {@link SystemClock#elapsedRealtime()}.
2299 *
2300 * @hide
2301 */
2302 public final void setConnectElapsedTimeMillis(long connectElapsedTimeMillis) {
2303 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2304 }
2305
2306 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002307 * Sets the label and icon status to display in the in-call UI.
2308 *
2309 * @param statusHints The status label and icon to set.
2310 */
2311 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002312 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002313 mStatusHints = statusHints;
2314 for (Listener l : mListeners) {
2315 l.onStatusHintsChanged(this, statusHints);
2316 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002317 }
2318
2319 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002320 * Sets the connections with which this connection can be conferenced.
2321 *
2322 * @param conferenceableConnections The set of connections this connection can conference with.
2323 */
2324 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002325 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002326 clearConferenceableList();
2327 for (Connection c : conferenceableConnections) {
2328 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2329 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002330 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002331 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002332 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002333 }
2334 }
2335 fireOnConferenceableConnectionsChanged();
2336 }
2337
2338 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002339 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2340 * or conferences with which this connection can be conferenced.
2341 *
2342 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002343 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002344 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002345 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002346 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002347 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2348 // small amount of items here.
2349 if (!mConferenceables.contains(c)) {
2350 if (c instanceof Connection) {
2351 Connection connection = (Connection) c;
2352 connection.addConnectionListener(mConnectionDeathListener);
2353 } else if (c instanceof Conference) {
2354 Conference conference = (Conference) c;
2355 conference.addListener(mConferenceDeathListener);
2356 }
2357 mConferenceables.add(c);
2358 }
2359 }
2360 fireOnConferenceableConnectionsChanged();
2361 }
2362
2363 /**
2364 * Returns the connections or conferences with which this connection can be conferenced.
2365 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002366 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002367 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002368 }
2369
Yorke Lee53463962015-08-04 16:07:19 -07002370 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002371 * @hide
2372 */
2373 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002374 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002375 if (mConnectionService != null) {
2376 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2377 "which is already associated with another ConnectionService.");
2378 } else {
2379 mConnectionService = connectionService;
2380 }
2381 }
2382
2383 /**
2384 * @hide
2385 */
2386 public final void unsetConnectionService(ConnectionService connectionService) {
2387 if (mConnectionService != connectionService) {
2388 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2389 "that does not belong to the ConnectionService.");
2390 } else {
2391 mConnectionService = null;
2392 }
2393 }
2394
2395 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002396 * @hide
2397 */
2398 public final ConnectionService getConnectionService() {
2399 return mConnectionService;
2400 }
2401
2402 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002403 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002404 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002405 *
2406 * @param conference The conference.
2407 * @return {@code true} if the conference was successfully set.
2408 * @hide
2409 */
2410 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002411 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002412 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002413 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002414 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002415 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2416 fireConferenceChanged();
2417 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002418 return true;
2419 }
2420 return false;
2421 }
2422
2423 /**
2424 * Resets the conference that this connection is a part of.
2425 * @hide
2426 */
2427 public final void resetConference() {
2428 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002429 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002430 mConference = null;
2431 fireConferenceChanged();
2432 }
2433 }
2434
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002435 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002436 * Set some extras that can be associated with this {@code Connection}.
2437 * <p>
2438 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2439 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2440 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002441 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2442 * {@link #removeExtras(String...)} methods to modify the extras.
2443 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002444 * 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 -07002445 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2446 *
2447 * @param extras The extras associated with this {@code Connection}.
2448 */
2449 public final void setExtras(@Nullable Bundle extras) {
2450 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002451
2452 // Add/replace any new or changed extras values.
2453 putExtras(extras);
2454
2455 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2456 // the current one and remove any keys that went away.
2457 if (mPreviousExtraKeys != null) {
2458 List<String> toRemove = new ArrayList<String>();
2459 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002460 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002461 toRemove.add(oldKey);
2462 }
2463 }
2464 if (!toRemove.isEmpty()) {
2465 removeExtras(toRemove);
2466 }
2467 }
2468
2469 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2470 // called we can see if the caller has removed any extras values.
2471 if (mPreviousExtraKeys == null) {
2472 mPreviousExtraKeys = new ArraySet<String>();
2473 }
2474 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002475 if (extras != null) {
2476 mPreviousExtraKeys.addAll(extras.keySet());
2477 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002478 }
2479
2480 /**
2481 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2482 * added.
2483 * <p>
2484 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2485 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2486 *
2487 * @param extras The extras to add.
2488 */
2489 public final void putExtras(@NonNull Bundle extras) {
2490 checkImmutable();
2491 if (extras == null) {
2492 return;
2493 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002494 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2495 // the listeners.
2496 Bundle listenerExtras;
2497 synchronized (mExtrasLock) {
2498 if (mExtras == null) {
2499 mExtras = new Bundle();
2500 }
2501 mExtras.putAll(extras);
2502 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002503 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002504 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002505 // Create a new clone of the extras for each listener so that they don't clobber
2506 // each other
2507 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002508 }
2509 }
2510
2511 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002512 * Adds a boolean extra to this {@code Connection}.
2513 *
2514 * @param key The extra key.
2515 * @param value The value.
2516 * @hide
2517 */
2518 public final void putExtra(String key, boolean value) {
2519 Bundle newExtras = new Bundle();
2520 newExtras.putBoolean(key, value);
2521 putExtras(newExtras);
2522 }
2523
2524 /**
2525 * Adds an integer extra to this {@code Connection}.
2526 *
2527 * @param key The extra key.
2528 * @param value The value.
2529 * @hide
2530 */
2531 public final void putExtra(String key, int value) {
2532 Bundle newExtras = new Bundle();
2533 newExtras.putInt(key, value);
2534 putExtras(newExtras);
2535 }
2536
2537 /**
2538 * Adds a string extra to this {@code Connection}.
2539 *
2540 * @param key The extra key.
2541 * @param value The value.
2542 * @hide
2543 */
2544 public final void putExtra(String key, String value) {
2545 Bundle newExtras = new Bundle();
2546 newExtras.putString(key, value);
2547 putExtras(newExtras);
2548 }
2549
2550 /**
Eric Erfanianaf7b8c02018-01-17 15:27:39 -08002551 * Adds a parcelable extra to this {@code Connection}.
2552 *
2553 * @param key The extra key.
2554 * @param value The value.
2555 * @hide
2556 */
2557 public final void putExtra(@NonNull String key, @NonNull Parcelable value) {
2558 Bundle newExtras = new Bundle();
2559 newExtras.putParcelable(key, value);
2560 putExtras(newExtras);
2561 }
2562
2563 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002564 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002565 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002566 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002567 */
2568 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002569 synchronized (mExtrasLock) {
2570 if (mExtras != null) {
2571 for (String key : keys) {
2572 mExtras.remove(key);
2573 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002574 }
2575 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002576 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002577 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002578 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002579 }
2580 }
2581
2582 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002583 * Removes extras from this {@code Connection}.
2584 *
2585 * @param keys The keys of the extras to remove.
2586 */
2587 public final void removeExtras(String ... keys) {
2588 removeExtras(Arrays.asList(keys));
2589 }
2590
2591 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002592 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2593 * be change to the {@link #getCallAudioState()}.
2594 * <p>
2595 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2596 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2597 * <p>
2598 * See also {@link InCallService#setAudioRoute(int)}.
2599 *
2600 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2601 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2602 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2603 */
2604 public final void setAudioRoute(int route) {
2605 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002606 l.onAudioRouteChanged(this, route, null);
2607 }
2608 }
2609
2610 /**
2611 *
2612 * 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>
2622 * See also {@link InCallService#requestBluetoothAudio(String)}
2623 * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by
2624 * {@link BluetoothDevice#getAddress()}.
2625 */
2626 public void requestBluetoothAudio(@NonNull String bluetoothAddress) {
2627 for (Listener l : mListeners) {
2628 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH, bluetoothAddress);
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 Liu37dfdb02017-12-04 14:19:30 -08002635 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002636 */
2637 public final void sendRttInitiationSuccess() {
Hall Liuffa4a812017-03-02 16:11:00 -08002638 setRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002639 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2640 }
2641
2642 /**
2643 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002644 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002645 * has failed.
2646 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2647 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002648 */
2649 public final void sendRttInitiationFailure(int reason) {
Hall Liuffa4a812017-03-02 16:11:00 -08002650 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002651 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2652 }
2653
2654 /**
2655 * Informs listeners that a currently active RTT session has been terminated by the remote
2656 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002657 */
2658 public final void sendRttSessionRemotelyTerminated() {
Hall Liud4d2a8a2018-01-29 17:22:02 -08002659 unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08002660 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2661 }
2662
2663 /**
2664 * Informs listeners that the remote side of the call has requested an upgrade to include an
2665 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002666 */
2667 public final void sendRemoteRttRequest() {
2668 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2669 }
2670
2671 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002672 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002673 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002674 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002675 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2676 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002677 */
Yorke Lee4af59352015-05-13 14:14:54 -07002678 @SystemApi
2679 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002680 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002681
2682 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002683 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2684 *
2685 * @param state The new connection audio state.
2686 */
2687 public void onCallAudioStateChanged(CallAudioState state) {}
2688
2689 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002690 * Notifies this Connection of an internal state change. This method is called after the
2691 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002692 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002693 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002694 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002695 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002696
2697 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002698 * Notifies this Connection of a request to play a DTMF tone.
2699 *
2700 * @param c A DTMF character.
2701 */
Santos Cordonf2951102014-07-20 19:06:29 -07002702 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002703
2704 /**
2705 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2706 */
Santos Cordonf2951102014-07-20 19:06:29 -07002707 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002708
2709 /**
2710 * Notifies this Connection of a request to disconnect.
2711 */
Santos Cordonf2951102014-07-20 19:06:29 -07002712 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002713
2714 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002715 * Notifies this Connection of a request to disconnect a participant of the conference managed
2716 * by the connection.
2717 *
2718 * @param endpoint the {@link Uri} of the participant to disconnect.
2719 * @hide
2720 */
2721 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2722
2723 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002724 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002725 */
Santos Cordonf2951102014-07-20 19:06:29 -07002726 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002727
2728 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002729 * Notifies this Connection of a request to abort.
2730 */
Santos Cordonf2951102014-07-20 19:06:29 -07002731 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002732
2733 /**
2734 * Notifies this Connection of a request to hold.
2735 */
Santos Cordonf2951102014-07-20 19:06:29 -07002736 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002737
2738 /**
2739 * Notifies this Connection of a request to exit a hold state.
2740 */
Santos Cordonf2951102014-07-20 19:06:29 -07002741 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002742
2743 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002744 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002745 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07002746 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002747 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002748 */
Santos Cordonf2951102014-07-20 19:06:29 -07002749 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002750
2751 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002752 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002753 * a request to accept.
2754 */
2755 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002756 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002757 }
2758
2759 /**
2760 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302761 * a request to deflect.
2762 */
2763 public void onDeflect(Uri address) {}
2764
2765 /**
2766 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002767 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002768 */
Santos Cordonf2951102014-07-20 19:06:29 -07002769 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002770
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002771 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002772 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2773 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002774 */
2775 public void onReject(String replyMessage) {}
2776
2777 /**
Bryce Leecac50772015-11-17 15:13:29 -08002778 * Notifies the Connection of a request to silence the ringer.
2779 *
2780 * @hide
2781 */
2782 public void onSilence() {}
2783
2784 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002785 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2786 */
Santos Cordonf2951102014-07-20 19:06:29 -07002787 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002788
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002789 /**
2790 * Notifies this Connection of a request to pull an external call to the local device.
2791 * <p>
2792 * The {@link InCallService} issues a request to pull an external call to the local device via
2793 * {@link Call#pullExternalCall()}.
2794 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002795 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2796 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002797 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002798 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002799 */
2800 public void onPullExternalCall() {}
2801
2802 /**
2803 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2804 * <p>
2805 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2806 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002807 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2808 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2809 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2810 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2811 * not aware of.
2812 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002813 * See also {@link Call#sendCallEvent(String, Bundle)}.
2814 *
2815 * @param event The call event.
2816 * @param extras Extras associated with the call event.
2817 */
2818 public void onCallEvent(String event, Bundle extras) {}
2819
Tyler Gunndee56a82016-03-23 16:06:34 -07002820 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002821 * Notifies this {@link Connection} that a handover has completed.
2822 * <p>
2823 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2824 * Bundle)} on the initiating side of the handover, and
2825 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2826 */
2827 public void onHandoverComplete() {}
2828
2829 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002830 * Notifies this {@link Connection} of a change to the extras made outside the
2831 * {@link ConnectionService}.
2832 * <p>
2833 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2834 * the {@link android.telecom.Call#putExtras(Bundle)} and
2835 * {@link Call#removeExtras(List)}.
2836 *
2837 * @param extras The new extras bundle.
2838 */
2839 public void onExtrasChanged(Bundle extras) {}
2840
Tyler Gunnf5035432017-01-09 09:43:12 -08002841 /**
2842 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2843 * displaying its incoming call user interface for the {@link Connection}.
2844 * <p>
2845 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2846 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2847 * should show its own incoming call user interface.
2848 * <p>
2849 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
2850 * regular {@link ConnectionService}, the Telecom framework will display its own incoming call
2851 * user interface to allow the user to choose whether to answer the new incoming call and
2852 * disconnect other ongoing calls, or to reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002853 * <p>
2854 * You should trigger the display of the incoming call user interface for your application by
2855 * showing a {@link Notification} with a full-screen {@link Intent} specified.
2856 * For example:
2857 * <pre><code>
2858 * // Create an intent which triggers your fullscreen incoming call user interface.
2859 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2860 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2861 * intent.setClass(context, YourIncomingCallActivity.class);
2862 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2863 *
2864 * // Build the notification as an ongoing high priority item; this ensures it will show as
2865 * // a heads up notification which slides down over top of the current content.
2866 * final Notification.Builder builder = new Notification.Builder(context);
2867 * builder.setOngoing(true);
2868 * builder.setPriority(Notification.PRIORITY_HIGH);
2869 *
2870 * // Set notification content intent to take user to fullscreen UI if user taps on the
2871 * // notification body.
2872 * builder.setContentIntent(pendingIntent);
2873 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2874 * // manager deems it appropriate.
2875 * builder.setFullScreenIntent(pendingIntent, true);
2876 *
2877 * // Setup notification content.
2878 * builder.setSmallIcon( yourIconResourceId );
2879 * builder.setContentTitle("Your notification title");
2880 * builder.setContentText("Your notification content.");
2881 *
2882 * // Use builder.addAction(..) to add buttons to answer or reject the call.
2883 *
2884 * NotificationManager notificationManager = mContext.getSystemService(
2885 * NotificationManager.class);
2886 * notificationManager.notify(YOUR_TAG, YOUR_ID, builder.build());
2887 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08002888 */
2889 public void onShowIncomingCallUi() {}
2890
Hall Liub64ac4c2017-02-06 10:49:48 -08002891 /**
2892 * Notifies this {@link Connection} that the user has requested an RTT session.
2893 * The connection service should call {@link #sendRttInitiationSuccess} or
2894 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
2895 * request, respectively.
2896 * @param rttTextStream The object that should be used to send text to or receive text from
2897 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08002898 */
2899 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
2900
2901 /**
2902 * Notifies this {@link Connection} that it should terminate any existing RTT communication
2903 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08002904 */
2905 public void onStopRtt() {}
2906
2907 /**
2908 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
2909 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
2910 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
2911 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08002912 * @param rttTextStream The object that should be used to send text to or receive text from
2913 * the in-call app.
2914 */
2915 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
2916
Hall Liuffa4a812017-03-02 16:11:00 -08002917 /**
2918 * Internal method to set {@link #PROPERTY_IS_RTT}.
2919 * @hide
2920 */
2921 void setRttProperty() {
2922 setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
2923 }
2924
2925 /**
2926 * Internal method to un-set {@link #PROPERTY_IS_RTT}.
2927 * @hide
2928 */
2929 void unsetRttProperty() {
2930 setConnectionProperties(getConnectionProperties() & (~PROPERTY_IS_RTT));
2931 }
2932
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002933 static String toLogSafePhoneNumber(String number) {
2934 // For unknown number, log empty string.
2935 if (number == null) {
2936 return "";
2937 }
2938
2939 if (PII_DEBUG) {
2940 // When PII_DEBUG is true we emit PII.
2941 return number;
2942 }
2943
2944 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2945 // sanitized phone numbers.
2946 StringBuilder builder = new StringBuilder();
2947 for (int i = 0; i < number.length(); i++) {
2948 char c = number.charAt(i);
2949 if (c == '-' || c == '@' || c == '.') {
2950 builder.append(c);
2951 } else {
2952 builder.append('x');
2953 }
2954 }
2955 return builder.toString();
2956 }
2957
Ihab Awad542e0ea2014-05-16 10:22:16 -07002958 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002959 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07002960 if (mState == STATE_DISCONNECTED && mState != state) {
2961 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07002962 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07002963 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002964 if (mState != state) {
2965 Log.d(this, "setState: %s", stateToString(state));
2966 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07002967 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07002968 for (Listener l : mListeners) {
2969 l.onStateChanged(this, state);
2970 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002971 }
2972 }
2973
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002974 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08002975 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002976 public FailureSignalingConnection(DisconnectCause disconnectCause) {
2977 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08002978 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07002979 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002980
2981 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08002982 if (mImmutable) {
2983 throw new UnsupportedOperationException("Connection is immutable");
2984 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002985 }
Ihab Awad6107bab2014-08-18 09:23:25 -07002986 }
2987
Evan Charltonbf11f982014-07-20 22:06:28 -07002988 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002989 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002990 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
2991 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07002992 * <p>
2993 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
2994 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002995 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002996 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07002997 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07002998 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002999 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3000 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003001 }
3002
Evan Charltonbf11f982014-07-20 22:06:28 -07003003 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003004 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3005 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3006 * this should never be un-@hide-den.
3007 *
3008 * @hide
3009 */
3010 public void checkImmutable() {}
3011
3012 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003013 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3014 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3015 * that state. This connection should not be used for anything, and no other
3016 * {@code Connection}s should be attempted.
3017 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003018 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003019 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003020 * @return A {@code Connection} which indicates that the underlying connection should
3021 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003022 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003023 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003024 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003025 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003026
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003027 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003028 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003029 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003030 }
3031 }
3032
Santos Cordon823fd3c2014-08-07 18:35:18 -07003033 private final void fireConferenceChanged() {
3034 for (Listener l : mListeners) {
3035 l.onConferenceChanged(this, mConference);
3036 }
3037 }
3038
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003039 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003040 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003041 if (c instanceof Connection) {
3042 Connection connection = (Connection) c;
3043 connection.removeConnectionListener(mConnectionDeathListener);
3044 } else if (c instanceof Conference) {
3045 Conference conference = (Conference) c;
3046 conference.removeListener(mConferenceDeathListener);
3047 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003048 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003049 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003050 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003051
3052 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003053 * Handles a change to extras received from Telecom.
3054 *
3055 * @param extras The new extras.
3056 * @hide
3057 */
3058 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003059 Bundle b = null;
3060 synchronized (mExtrasLock) {
3061 mExtras = extras;
3062 if (mExtras != null) {
3063 b = new Bundle(mExtras);
3064 }
3065 }
3066 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003067 }
3068
3069 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003070 * Notifies listeners that the merge request failed.
3071 *
3072 * @hide
3073 */
3074 protected final void notifyConferenceMergeFailed() {
3075 for (Listener l : mListeners) {
3076 l.onConferenceMergeFailed(this);
3077 }
3078 }
3079
3080 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003081 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003082 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003083 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003084 * @hide
3085 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003086 protected final void updateConferenceParticipants(
3087 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003088 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003089 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003090 }
3091 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003092
3093 /**
3094 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003095 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003096 */
3097 protected void notifyConferenceStarted() {
3098 for (Listener l : mListeners) {
3099 l.onConferenceStarted();
3100 }
3101 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003102
3103 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003104 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3105 * be a part of a conference call.
3106 * @param isConferenceSupported {@code true} if the connection supports being part of a
3107 * conference call, {@code false} otherwise.
3108 * @hide
3109 */
3110 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3111 for (Listener l : mListeners) {
3112 l.onConferenceSupportedChanged(this, isConferenceSupported);
3113 }
3114 }
3115
3116 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303117 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3118 * changed due to an emergency call being redialed.
3119 * @param pHandle The new PhoneAccountHandle for this connection.
3120 * @hide
3121 */
3122 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3123 for (Listener l : mListeners) {
3124 l.onPhoneAccountChanged(this, pHandle);
3125 }
3126 }
3127
3128 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003129 * Sets the {@link PhoneAccountHandle} associated with this connection.
3130 *
3131 * @hide
3132 */
3133 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3134 if (mPhoneAccountHandle != phoneAccountHandle) {
3135 mPhoneAccountHandle = phoneAccountHandle;
3136 notifyPhoneAccountChanged(phoneAccountHandle);
3137 }
3138 }
3139
3140 /**
3141 * Returns the {@link PhoneAccountHandle} associated with this connection.
3142 *
3143 * @hide
3144 */
3145 public PhoneAccountHandle getPhoneAccountHandle() {
3146 return mPhoneAccountHandle;
3147 }
3148
3149 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003150 * Sends an event associated with this {@code Connection} with associated event extras to the
3151 * {@link InCallService}.
3152 * <p>
3153 * Connection events are used to communicate point in time information from a
3154 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3155 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3156 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3157 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3158 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3159 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3160 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3161 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3162 * <p>
3163 * Events are exposed to {@link InCallService} implementations via
3164 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3165 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003166 * 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 -07003167 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3168 * some events altogether.
3169 * <p>
3170 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3171 * conflicts between {@link ConnectionService} implementations. Further, custom
3172 * {@link ConnectionService} implementations shall not re-purpose events in the
3173 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3174 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3175 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3176 * {@code com.example.extra.MY_EXTRA}).
3177 * <p>
3178 * When defining events and the associated extras, it is important to keep their behavior
3179 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3180 * events/extras should me maintained to ensure backwards compatibility with older
3181 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003182 *
3183 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003184 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003185 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003186 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003187 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003188 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003189 }
3190 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003191}