blob: 330db28b18ddb89080feb8584adddc4be6fecfb8 [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;
Mathew Inwood42346d12018-08-01 11:33:05 +010026import android.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080027import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080028import android.bluetooth.BluetoothDevice;
Tyler Gunn159f35c2017-03-02 09:28:37 -080029import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070030import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070031import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080032import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070033import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034import android.os.Handler;
35import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070036import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070037import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080038import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070040import android.os.SystemClock;
Wei Huang7f7f72e2018-05-30 19:21:36 +080041import android.telephony.ServiceState;
42import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070043import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070044import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070045
Hall Liua549fed2018-02-09 16:40:03 -080046import java.io.FileInputStream;
47import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080048import java.io.IOException;
49import java.io.InputStreamReader;
50import java.io.OutputStreamWriter;
Santos Cordonb6939982014-06-04 20:20:58 -070051import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070052import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070053import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070054import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070055import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070056import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070057
58/**
Santos Cordon895d4b82015-06-25 16:41:48 -070059 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
60 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070061 * <p>
62 * Implementations create a custom subclass of {@code Connection} and return it to the framework
63 * as the return value of
64 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
65 * or
66 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
67 * Implementations are then responsible for updating the state of the {@code Connection}, and
68 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
69 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070070 * <p>
71 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
72 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
73 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
74 * {@code Connection} instance.
75 * <p>
76 * Basic call support requires overriding the following methods: {@link #onAnswer()},
77 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
78 * <p>
79 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
80 * {@link #onUnhold()} methods should be overridden to provide hold support for the
81 * {@code Connection}.
82 * <p>
83 * Where a {@code Connection} supports a variation of video calling (e.g. the
84 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
85 * to support answering a call as a video call.
86 * <p>
87 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
88 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
89 * support for pulling the external call.
90 * <p>
91 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
92 * overridden.
93 * <p>
94 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
95 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
96 * for example, call events from a {@link InCallService} are handled,
97 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
98 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
99 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
100 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700101 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700102public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103
Santos Cordon895d4b82015-06-25 16:41:48 -0700104 /**
105 * The connection is initializing. This is generally the first state for a {@code Connection}
106 * returned by a {@link ConnectionService}.
107 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700108 public static final int STATE_INITIALIZING = 0;
109
Santos Cordon895d4b82015-06-25 16:41:48 -0700110 /**
111 * The connection is new and not connected.
112 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700113 public static final int STATE_NEW = 1;
114
Santos Cordon895d4b82015-06-25 16:41:48 -0700115 /**
116 * An incoming connection is in the ringing state. During this state, the user's ringer or
117 * vibration feature will be activated.
118 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700119 public static final int STATE_RINGING = 2;
120
Santos Cordon895d4b82015-06-25 16:41:48 -0700121 /**
122 * An outgoing connection is in the dialing state. In this state the other party has not yet
123 * answered the call and the user traditionally hears a ringback tone.
124 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700125 public static final int STATE_DIALING = 3;
126
Santos Cordon895d4b82015-06-25 16:41:48 -0700127 /**
128 * A connection is active. Both parties are connected to the call and can actively communicate.
129 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700130 public static final int STATE_ACTIVE = 4;
131
Santos Cordon895d4b82015-06-25 16:41:48 -0700132 /**
133 * A connection is on hold.
134 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700135 public static final int STATE_HOLDING = 5;
136
Santos Cordon895d4b82015-06-25 16:41:48 -0700137 /**
138 * A connection has been disconnected. This is the final state once the user has been
139 * disconnected from a call either locally, remotely or by an error in the service.
140 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 public static final int STATE_DISCONNECTED = 6;
142
Santos Cordon895d4b82015-06-25 16:41:48 -0700143 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700144 * The state of an external connection which is in the process of being pulled from a remote
145 * device to the local device.
146 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700147 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700148 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
149 */
150 public static final int STATE_PULLING_CALL = 7;
151
152 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700153 * Connection can currently be put on hold or unheld. This is distinct from
154 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
155 * it does not at the moment support the function. This can be true while the call is in the
156 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
157 * display a disabled 'hold' button.
158 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159 public static final int CAPABILITY_HOLD = 0x00000001;
160
161 /** Connection supports the hold feature. */
162 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
163
164 /**
165 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
166 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
167 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
168 * capability allows a merge button to be shown while the conference is in the foreground
169 * of the in-call UI.
170 * <p>
171 * This is only intended for use by a {@link Conference}.
172 */
173 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
174
175 /**
176 * Connections within a conference can be swapped between foreground and background.
177 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
178 * <p>
179 * This is only intended for use by a {@link Conference}.
180 */
181 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
182
183 /**
184 * @hide
185 */
186 public static final int CAPABILITY_UNUSED = 0x00000010;
187
188 /** Connection supports responding via text option. */
189 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
190
191 /** Connection can be muted. */
192 public static final int CAPABILITY_MUTE = 0x00000040;
193
194 /**
195 * Connection supports conference management. This capability only applies to
196 * {@link Conference}s which can have {@link Connection}s as children.
197 */
198 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
199
200 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700203 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204
205 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209
210 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700211 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700213 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700214 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800215
216 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700217 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800218 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700219 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
220
221 /**
222 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700223 */
224 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
225
226 /**
227 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700228 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700229 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700230 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800231
232 /**
233 * Connection is able to be separated from its parent {@code Conference}, if any.
234 */
235 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
236
237 /**
238 * Connection is able to be individually disconnected when in a {@code Conference}.
239 */
240 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
241
242 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700243 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244 * @hide
245 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700246 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700249 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700250 * @hide
251 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700252 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253
254 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700255 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256 * @hide
257 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700258 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700259
Tyler Gunn068085b2015-02-06 13:56:52 -0800260 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700261 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800262 * @hide
263 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700264 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800265
Tyler Gunn96d6c402015-03-18 12:39:23 -0700266 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500267 * Speed up audio setup for MT call.
268 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700269 */
270 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800271
Rekha Kumar07366812015-03-24 16:42:31 -0700272 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700273 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700274 */
275 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
276
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700277 /**
278 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700279 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700280 */
281 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
282
Tyler Gunnd4091732015-06-29 09:15:37 -0700283 /**
284 * For a conference, indicates the conference will not have child connections.
285 * <p>
286 * An example of a conference with child connections is a GSM conference call, where the radio
287 * retains connections to the individual participants of the conference. Another example is an
288 * IMS conference call where conference event package functionality is supported; in this case
289 * the conference server ensures the radio is aware of the participants in the conference, which
290 * are represented by child connections.
291 * <p>
292 * An example of a conference with no child connections is an IMS conference call with no
293 * conference event package support. Such a conference is represented by the radio as a single
294 * connection to the IMS conference server.
295 * <p>
296 * Indicating whether a conference has children or not is important to help user interfaces
297 * visually represent a conference. A conference with no children, for example, will have the
298 * conference connection shown in the list of calls on a Bluetooth device, where if the
299 * conference has children, only the children will be shown in the list of calls on a Bluetooth
300 * device.
301 * @hide
302 */
303 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
304
Bryce Lee81901682015-08-28 16:38:02 -0700305 /**
306 * Indicates that the connection itself wants to handle any sort of reply response, rather than
307 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700308 */
309 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
310
Tyler Gunnf97a0092016-01-19 15:59:34 -0800311 /**
312 * When set, prevents a video call from being downgraded to an audio-only call.
313 * <p>
314 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
315 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
316 * downgraded from a video call back to a VideoState of
317 * {@link VideoProfile#STATE_AUDIO_ONLY}.
318 * <p>
319 * Intuitively, a call which can be downgraded to audio should also have local and remote
320 * video
321 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
322 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
323 */
324 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
325
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700326 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700327 * When set for an external connection, indicates that this {@code Connection} can be pulled
328 * from a remote device to the current device.
329 * <p>
330 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
331 * is set.
332 */
333 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
334
Pooja Jaind34698d2017-12-28 14:15:31 +0530335 /** Call supports the deflect feature. */
336 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
337
Tyler Gunn720c6642016-03-22 09:02:47 -0700338 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530339 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700340 //**********************************************************************************************
341
342 /**
343 * Indicates that the current device callback number should be shown.
344 *
345 * @hide
346 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700347 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700348
349 /**
350 * Whether the call is a generic conference, where we do not know the precise state of
351 * participants in the conference (eg. on CDMA).
352 *
353 * @hide
354 */
355 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
356
357 /**
358 * Connection is using high definition audio.
359 * @hide
360 */
361 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
362
363 /**
364 * Connection is using WIFI.
365 * @hide
366 */
367 public static final int PROPERTY_WIFI = 1<<3;
368
369 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700370 * When set, indicates that the {@code Connection} does not actually exist locally for the
371 * {@link ConnectionService}.
372 * <p>
373 * Consider, for example, a scenario where a user has two devices with the same phone number.
374 * When a user places a call on one devices, the telephony stack can represent that call on the
375 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700376 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700377 * <p>
378 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
379 * external connections. Only those {@link InCallService}s which have the
380 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
381 * manifest will see external connections.
382 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700383 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700384
Brad Ebinger15847072016-05-18 11:08:36 -0700385 /**
386 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
387 */
388 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700389
Hall Liu9f332c72016-07-14 15:37:37 -0700390 /**
391 * Indicates that the connection represents a downgraded IMS conference.
392 * @hide
393 */
394 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
395
Tyler Gunnf5035432017-01-09 09:43:12 -0800396 /**
397 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
398 * {@link ConnectionService}.
399 * <p>
400 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
401 */
402 public static final int PROPERTY_SELF_MANAGED = 1<<7;
403
Hall Liu95d55872017-01-25 17:12:49 -0800404 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800405 * Set by the framework to indicate that a connection has an active RTT session associated with
406 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800407 */
408 public static final int PROPERTY_IS_RTT = 1 << 8;
409
Eric Erfanian62706c52017-12-06 16:27:53 -0800410 /**
411 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000412 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800413 */
414 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
415
Tyler Gunn96d6c402015-03-18 12:39:23 -0700416 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800417 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700418 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800419
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700420 /**
421 * Connection extra key used to store the last forwarded number associated with the current
422 * connection. Used to communicate to the user interface that the connection was forwarded via
423 * the specified number.
424 */
425 public static final String EXTRA_LAST_FORWARDED_NUMBER =
426 "android.telecom.extra.LAST_FORWARDED_NUMBER";
427
428 /**
429 * Connection extra key used to store a child number associated with the current connection.
430 * Used to communicate to the user interface that the connection was received via
431 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
432 * address.
433 */
434 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
435
436 /**
437 * Connection extra key used to store the subject for an incoming call. The user interface can
438 * query this extra and display its contents for incoming calls. Will only be used if the
439 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
440 */
441 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
442
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800443 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700444 * Boolean connection extra key set on a {@link Connection} in
445 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
446 * current active foreground call to be dropped.
447 */
448 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
449 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
450
451 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700452 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
453 * state to indicate the name of the third-party app which is responsible for the current
454 * foreground call.
455 * <p>
456 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
457 * is able to inform the user that answering the new incoming call will cause a call owned by
458 * another app to be dropped when the incoming call is answered.
459 */
460 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
461 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
462
463 /**
Hall Liu10208662016-06-15 17:55:00 -0700464 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700465 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700466 * @hide
467 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700468 public static final String EXTRA_DISABLE_ADD_CALL =
469 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700470
471 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700472 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
473 * original Connection ID associated with the connection. Used in
474 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
475 * connection/conference added via
476 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
477 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
478 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
479 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
480 * be a way to ensure that we don't add the connection again as a duplicate.
481 * <p>
482 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
483 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
484 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
485 * in a new {@link Connection} which it adds to Telecom via
486 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
487 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
488 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
489 * ID it originally referred to the connection as. Thus Telecom needs to know that the
490 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
491 * @hide
492 */
493 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
494 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
495
496 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800497 * Connection event used to inform Telecom that it should play the on hold tone. This is used
498 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700499 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800500 * @hide
501 */
502 public static final String EVENT_ON_HOLD_TONE_START =
503 "android.telecom.event.ON_HOLD_TONE_START";
504
505 /**
506 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
507 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700508 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800509 * @hide
510 */
511 public static final String EVENT_ON_HOLD_TONE_END =
512 "android.telecom.event.ON_HOLD_TONE_END";
513
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700514 /**
515 * Connection event used to inform {@link InCallService}s when pulling of an external call has
516 * failed. The user interface should inform the user of the error.
517 * <p>
518 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
519 * API is called on a {@link Call} with the properties
520 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
521 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
522 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700523 * <p>
524 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
525 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700526 */
527 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
528
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700529 /**
530 * Connection event used to inform {@link InCallService}s when the merging of two calls has
531 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700532 * <p>
533 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
534 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700535 */
536 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
537
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700538 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700539 * Connection event used to inform {@link InCallService}s when the process of merging a
540 * Connection into a conference has begun.
541 * <p>
542 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
543 * expected to be null when this connection event is used.
544 * @hide
545 */
546 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
547
548 /**
549 * Connection event used to inform {@link InCallService}s when the process of merging a
550 * Connection into a conference has completed.
551 * <p>
552 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
553 * expected to be null when this connection event is used.
554 * @hide
555 */
556 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
557
558 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700559 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
560 * the remote party.
561 * <p>
562 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
563 * call is being held locally on the device. When a capable {@link ConnectionService} receives
564 * signalling to indicate that the remote party has put the call on hold, it can send this
565 * connection event.
566 * @hide
567 */
568 public static final String EVENT_CALL_REMOTELY_HELD =
569 "android.telecom.event.CALL_REMOTELY_HELD";
570
571 /**
572 * Connection event used to inform {@link InCallService}s when a call which was remotely held
573 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
574 * <p>
575 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
576 * call is being held locally on the device. When a capable {@link ConnectionService} receives
577 * signalling to indicate that the remote party has taken the call off hold, it can send this
578 * connection event.
579 * @hide
580 */
581 public static final String EVENT_CALL_REMOTELY_UNHELD =
582 "android.telecom.event.CALL_REMOTELY_UNHELD";
583
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700584 /**
585 * Connection event used to inform an {@link InCallService} which initiated a call handover via
586 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
587 * successfully completed.
588 * @hide
589 */
590 public static final String EVENT_HANDOVER_COMPLETE =
591 "android.telecom.event.HANDOVER_COMPLETE";
592
593 /**
594 * Connection event used to inform an {@link InCallService} which initiated a call handover via
595 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
596 * to complete.
597 * @hide
598 */
599 public static final String EVENT_HANDOVER_FAILED =
600 "android.telecom.event.HANDOVER_FAILED";
601
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700602 // Flag controlling whether PII is emitted into the logs
603 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
604
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800605 /**
606 * Whether the given capabilities support the specified capability.
607 *
608 * @param capabilities A capability bit field.
609 * @param capability The capability to check capabilities for.
610 * @return Whether the specified capability is supported.
611 * @hide
612 */
613 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800614 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800615 }
616
617 /**
618 * Whether the capabilities of this {@code Connection} supports the specified capability.
619 *
620 * @param capability The capability to check capabilities for.
621 * @return Whether the specified capability is supported.
622 * @hide
623 */
624 public boolean can(int capability) {
625 return can(mConnectionCapabilities, capability);
626 }
627
628 /**
629 * Removes the specified capability from the set of capabilities of this {@code Connection}.
630 *
631 * @param capability The capability to remove from the set.
632 * @hide
633 */
634 public void removeCapability(int capability) {
635 mConnectionCapabilities &= ~capability;
636 }
637
638 /**
639 * Adds the specified capability to the set of capabilities of this {@code Connection}.
640 *
641 * @param capability The capability to add to the set.
642 * @hide
643 */
644 public void addCapability(int capability) {
645 mConnectionCapabilities |= capability;
646 }
647
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700648 /**
649 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
650 *
651 * @param capabilities A capability bit field.
652 * @return A human readable string representation.
653 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800654 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700655 return capabilitiesToStringInternal(capabilities, true /* isLong */);
656 }
657
658 /**
659 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
660 * string.
661 *
662 * @param capabilities A capability bit field.
663 * @return A human readable string representation.
664 * @hide
665 */
666 public static String capabilitiesToStringShort(int capabilities) {
667 return capabilitiesToStringInternal(capabilities, false /* isLong */);
668 }
669
670 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800671 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700672 builder.append("[");
673 if (isLong) {
674 builder.append("Capabilities:");
675 }
676
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700678 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800679 }
680 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700681 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 }
683 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700684 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800685 }
686 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700687 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800688 }
689 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700690 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 }
692 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700693 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800694 }
695 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700696 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800697 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700698 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700699 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700700 }
701 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700702 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700703 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700704 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700705 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800706 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700707 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700708 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700709 }
710 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700711 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700712 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700713 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700714 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800715 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800716 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700717 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800718 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500719 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700720 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500721 }
Rekha Kumar07366812015-03-24 16:42:31 -0700722 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700723 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700724 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700725 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700726 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700727 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700728 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700729 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700730 }
Bryce Lee81901682015-08-28 16:38:02 -0700731 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700732 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700733 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700734 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700735 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700736 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530737 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
738 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
739 }
Bryce Lee81901682015-08-28 16:38:02 -0700740
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 builder.append("]");
742 return builder.toString();
743 }
744
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700745 /**
746 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
747 *
748 * @param properties A property bit field.
749 * @return A human readable string representation.
750 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700751 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700752 return propertiesToStringInternal(properties, true /* isLong */);
753 }
754
755 /**
756 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
757 *
758 * @param properties A property bit field.
759 * @return A human readable string representation.
760 * @hide
761 */
762 public static String propertiesToStringShort(int properties) {
763 return propertiesToStringInternal(properties, false /* isLong */);
764 }
765
766 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700767 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700768 builder.append("[");
769 if (isLong) {
770 builder.append("Properties:");
771 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700772
Tyler Gunnf5035432017-01-09 09:43:12 -0800773 if (can(properties, PROPERTY_SELF_MANAGED)) {
774 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
775 }
776
Hall Liu25c7c4d2016-08-30 13:41:02 -0700777 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
778 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700779 }
780
781 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700782 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700783 }
784
785 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700786 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700787 }
788
789 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700790 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700791 }
792
793 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700794 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700795 }
796
Brad Ebinger15847072016-05-18 11:08:36 -0700797 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700798 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700799 }
800
Hall Liud4d2a8a2018-01-29 17:22:02 -0800801 if (can(properties, PROPERTY_IS_RTT)) {
802 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
803 }
804
Tyler Gunn720c6642016-03-22 09:02:47 -0700805 builder.append("]");
806 return builder.toString();
807 }
808
Sailesh Nepal091768c2014-06-30 15:15:23 -0700809 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700810 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700811 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700812 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700813 public void onCallerDisplayNameChanged(
814 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700815 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700816 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700817 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800818 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700819 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700820 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800821 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700822 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800823 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700824 public void onVideoProviderChanged(
825 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700826 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
827 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800828 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700829 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700830 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700831 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800832 public void onConferenceParticipantsChanged(Connection c,
833 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800834 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700835 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700836 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700837 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700838 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700839 /** @hide */
840 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800841 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800842 public void onRttInitiationSuccess(Connection c) {}
843 public void onRttInitiationFailure(Connection c, int reason) {}
844 public void onRttSessionRemotelyTerminated(Connection c) {}
845 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530846 /** @hide */
847 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800848 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700849 }
850
Tyler Gunnb702ef82015-05-29 11:51:53 -0700851 /**
Hall Liu95d55872017-01-25 17:12:49 -0800852 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800853 */
854 public static final class RttTextStream {
855 private static final int READ_BUFFER_SIZE = 1000;
856 private final InputStreamReader mPipeFromInCall;
857 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800858 private final ParcelFileDescriptor mFdFromInCall;
859 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800860 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
861
862 /**
863 * @hide
864 */
865 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800866 mFdFromInCall = fromInCall;
867 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800868 mPipeFromInCall = new InputStreamReader(
Hall Liua549fed2018-02-09 16:40:03 -0800869 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800870 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800871 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800872 }
873
874 /**
875 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
876 * RTT transmits text in real-time, this method should be called as often as text snippets
877 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800878 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800879 * This method is not thread-safe -- calling it from multiple threads simultaneously may
880 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800881 *
Hall Liu95d55872017-01-25 17:12:49 -0800882 * @param input The message to send to the in-call app.
883 */
884 public void write(String input) throws IOException {
885 mPipeToInCall.write(input);
886 mPipeToInCall.flush();
887 }
888
889
890 /**
891 * Reads a string from the in-call app, blocking if there is no data available. Returns
892 * {@code null} if the RTT conversation has been terminated and there is no further data
893 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800894 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800895 * This method is not thread-safe -- calling it from multiple threads simultaneously may
896 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800897 *
Hall Liu95d55872017-01-25 17:12:49 -0800898 * @return A string containing text entered by the user, or {@code null} if the
899 * conversation has been terminated or if there was an error while reading.
900 */
Hall Liuffa4a812017-03-02 16:11:00 -0800901 public String read() throws IOException {
902 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
903 if (numRead < 0) {
904 return null;
905 }
906 return new String(mReadBuffer, 0, numRead);
907 }
908
909 /**
910 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
911 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800912 *
Hall Liuffa4a812017-03-02 16:11:00 -0800913 * @return A string containing text entered by the user, or {@code null} if the user has
914 * not entered any new text yet.
915 */
916 public String readImmediately() throws IOException {
917 if (mPipeFromInCall.ready()) {
918 return read();
919 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800920 return null;
921 }
922 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800923
924 /** @hide */
925 public ParcelFileDescriptor getFdFromInCall() {
926 return mFdFromInCall;
927 }
928
929 /** @hide */
930 public ParcelFileDescriptor getFdToInCall() {
931 return mFdToInCall;
932 }
933 }
934
935 /**
936 * Provides constants to represent the results of responses to session modify requests sent via
937 * {@link Call#sendRttRequest()}
938 */
939 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700940 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800941 /**
942 * Session modify request was successful.
943 */
944 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
945
946 /**
947 * Session modify request failed.
948 */
949 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
950
951 /**
952 * Session modify request ignored due to invalid parameters.
953 */
954 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
955
956 /**
957 * Session modify request timed out.
958 */
959 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
960
961 /**
962 * Session modify request rejected by remote user.
963 */
964 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800965 }
966
967 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700968 * Provides a means of controlling the video session associated with a {@link Connection}.
969 * <p>
970 * Implementations create a custom subclass of {@link VideoProvider} and the
971 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
972 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
973 * should set the {@link VideoProvider}.
974 * <p>
975 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
976 * {@link InCallService} implementations to issue requests related to the video session;
977 * it provides a means for the {@link ConnectionService} to report events and information
978 * related to the video session to Telecom and the {@link InCallService} implementations.
979 * <p>
980 * {@link InCallService} implementations interact with the {@link VideoProvider} via
981 * {@link android.telecom.InCallService.VideoCall}.
982 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700983 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700984 /**
985 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700986 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 */
988 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700989
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700991 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
992 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 */
994 public static final int SESSION_EVENT_RX_RESUME = 2;
995
996 /**
997 * Video transmission has begun. This occurs after a negotiated start of video transmission
998 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700999 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000 */
1001 public static final int SESSION_EVENT_TX_START = 3;
1002
1003 /**
1004 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1005 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 */
1008 public static final int SESSION_EVENT_TX_STOP = 4;
1009
1010 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001011 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001012 * this as a cue to inform the user the camera is not available.
1013 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 */
1015 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1016
1017 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001018 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001019 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * the camera has become available again.
1021 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 */
1023 public static final int SESSION_EVENT_CAMERA_READY = 6;
1024
1025 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001026 * Session event raised by Telecom when
1027 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1028 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1029 * @see #handleCallSessionEvent(int)
1030 */
1031 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1032
1033 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 */
1037 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1038
1039 /**
1040 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001041 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001042 */
1043 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1044
1045 /**
1046 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001047 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 */
1049 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1050
Rekha Kumar07366812015-03-24 16:42:31 -07001051 /**
1052 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001053 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001054 */
1055 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1056
1057 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001058 * Session modify request rejected by remote user.
1059 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001060 */
1061 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1062
Tyler Gunn75958422015-04-15 14:23:42 -07001063 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001064 private static final int MSG_SET_CAMERA = 2;
1065 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1066 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1067 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1068 private static final int MSG_SET_ZOOM = 6;
1069 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1070 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1071 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001072 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001074 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001076 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1077 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1078 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1079 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1080 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1081 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001082 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1083 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001084 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1085
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001086 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001087 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001088
1089 /**
1090 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001091 *
1092 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1093 * load factor before resizing, 1 means we only expect a single thread to
1094 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001095 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001096 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1097 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098
1099 /**
1100 * Default handler used to consolidate binder method calls onto a single thread.
1101 */
1102 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001103 public VideoProviderHandler() {
1104 super();
1105 }
1106
1107 public VideoProviderHandler(Looper looper) {
1108 super(looper);
1109 }
1110
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 @Override
1112 public void handleMessage(Message msg) {
1113 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001114 case MSG_ADD_VIDEO_CALLBACK: {
1115 IBinder binder = (IBinder) msg.obj;
1116 IVideoCallback callback = IVideoCallback.Stub
1117 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001118 if (callback == null) {
1119 Log.w(this, "addVideoProvider - skipped; callback is null.");
1120 break;
1121 }
1122
Tyler Gunn75958422015-04-15 14:23:42 -07001123 if (mVideoCallbacks.containsKey(binder)) {
1124 Log.i(this, "addVideoProvider - skipped; already present.");
1125 break;
1126 }
1127 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001129 }
1130 case MSG_REMOVE_VIDEO_CALLBACK: {
1131 IBinder binder = (IBinder) msg.obj;
1132 IVideoCallback callback = IVideoCallback.Stub
1133 .asInterface((IBinder) msg.obj);
1134 if (!mVideoCallbacks.containsKey(binder)) {
1135 Log.i(this, "removeVideoProvider - skipped; not present.");
1136 break;
1137 }
1138 mVideoCallbacks.remove(binder);
1139 break;
1140 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001141 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001142 {
1143 SomeArgs args = (SomeArgs) msg.obj;
1144 try {
1145 onSetCamera((String) args.arg1);
1146 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001147 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001148 } finally {
1149 args.recycle();
1150 }
1151 }
1152 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001153 case MSG_SET_PREVIEW_SURFACE:
1154 onSetPreviewSurface((Surface) msg.obj);
1155 break;
1156 case MSG_SET_DISPLAY_SURFACE:
1157 onSetDisplaySurface((Surface) msg.obj);
1158 break;
1159 case MSG_SET_DEVICE_ORIENTATION:
1160 onSetDeviceOrientation(msg.arg1);
1161 break;
1162 case MSG_SET_ZOOM:
1163 onSetZoom((Float) msg.obj);
1164 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001165 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1166 SomeArgs args = (SomeArgs) msg.obj;
1167 try {
1168 onSendSessionModifyRequest((VideoProfile) args.arg1,
1169 (VideoProfile) args.arg2);
1170 } finally {
1171 args.recycle();
1172 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001173 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001174 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1176 onSendSessionModifyResponse((VideoProfile) msg.obj);
1177 break;
1178 case MSG_REQUEST_CAMERA_CAPABILITIES:
1179 onRequestCameraCapabilities();
1180 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001181 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1182 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001183 break;
1184 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001185 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001186 break;
1187 default:
1188 break;
1189 }
1190 }
1191 }
1192
1193 /**
1194 * IVideoProvider stub implementation.
1195 */
1196 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001197 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001198 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001199 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1200 }
1201
1202 public void removeVideoCallback(IBinder videoCallbackBinder) {
1203 mMessageHandler.obtainMessage(
1204 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001205 }
1206
Tyler Gunn159f35c2017-03-02 09:28:37 -08001207 public void setCamera(String cameraId, String callingPackageName,
1208 int targetSdkVersion) {
1209
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001210 SomeArgs args = SomeArgs.obtain();
1211 args.arg1 = cameraId;
1212 // Propagate the calling package; originally determined in
1213 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1214 // process.
1215 args.arg2 = callingPackageName;
1216 // Pass along the uid and pid of the calling app; this gets lost when we put the
1217 // message onto the handler. These are required for Telecom to perform a permission
1218 // check to see if the calling app is able to use the camera.
1219 args.argi1 = Binder.getCallingUid();
1220 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001221 // Pass along the target SDK version of the calling InCallService. This is used to
1222 // maintain backwards compatibility of the API for older callers.
1223 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001224 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001225 }
1226
1227 public void setPreviewSurface(Surface surface) {
1228 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1229 }
1230
1231 public void setDisplaySurface(Surface surface) {
1232 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1233 }
1234
1235 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001236 mMessageHandler.obtainMessage(
1237 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001238 }
1239
1240 public void setZoom(float value) {
1241 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1242 }
1243
Tyler Gunn45382162015-05-06 08:52:27 -07001244 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1245 SomeArgs args = SomeArgs.obtain();
1246 args.arg1 = fromProfile;
1247 args.arg2 = toProfile;
1248 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001249 }
1250
1251 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1252 mMessageHandler.obtainMessage(
1253 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1254 }
1255
1256 public void requestCameraCapabilities() {
1257 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1258 }
1259
1260 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001262 }
1263
Yorke Lee32f24732015-05-12 16:18:03 -07001264 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001265 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1266 }
1267 }
1268
1269 public VideoProvider() {
1270 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001271 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001272 }
1273
1274 /**
1275 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1276 *
1277 * @param looper The looper.
1278 * @hide
1279 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001280 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001281 public VideoProvider(Looper looper) {
1282 mBinder = new VideoProvider.VideoProviderBinder();
1283 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 }
1285
1286 /**
1287 * Returns binder object which can be used across IPC methods.
1288 * @hide
1289 */
1290 public final IVideoProvider getInterface() {
1291 return mBinder;
1292 }
1293
1294 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001295 * Sets the camera to be used for the outgoing video.
1296 * <p>
1297 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1298 * camera via
1299 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1300 * <p>
1301 * Sent from the {@link InCallService} via
1302 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001304 * @param cameraId The id of the camera (use ids as reported by
1305 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001306 */
1307 public abstract void onSetCamera(String cameraId);
1308
1309 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001310 * Sets the camera to be used for the outgoing video.
1311 * <p>
1312 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1313 * camera via
1314 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1315 * <p>
1316 * This prototype is used internally to ensure that the calling package name, UID and PID
1317 * are sent to Telecom so that can perform a camera permission check on the caller.
1318 * <p>
1319 * Sent from the {@link InCallService} via
1320 * {@link InCallService.VideoCall#setCamera(String)}.
1321 *
1322 * @param cameraId The id of the camera (use ids as reported by
1323 * {@link CameraManager#getCameraIdList()}).
1324 * @param callingPackageName The AppOpps package name of the caller.
1325 * @param callingUid The UID of the caller.
1326 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001327 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001328 * @hide
1329 */
1330 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001331 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001332
1333 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 * Sets the surface to be used for displaying a preview of what the user's camera is
1335 * currently capturing. When video transmission is enabled, this is the video signal which
1336 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001337 * <p>
1338 * Sent from the {@link InCallService} via
1339 * {@link InCallService.VideoCall#setPreviewSurface(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 onSetPreviewSurface(Surface surface);
1344
1345 /**
1346 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001347 * <p>
1348 * Sent from the {@link InCallService} via
1349 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001351 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001352 */
1353 public abstract void onSetDisplaySurface(Surface surface);
1354
1355 /**
1356 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1357 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001358 * <p>
1359 * Sent from the {@link InCallService} via
1360 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001361 *
1362 * @param rotation The device orientation, in degrees.
1363 */
1364 public abstract void onSetDeviceOrientation(int rotation);
1365
1366 /**
1367 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001368 * <p>
1369 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001370 *
1371 * @param value The camera zoom ratio.
1372 */
1373 public abstract void onSetZoom(float value);
1374
1375 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001376 * Issues a request to modify the properties of the current video session.
1377 * <p>
1378 * Example scenarios include: requesting an audio-only call to be upgraded to a
1379 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1380 * when the {@link InCallService} is no longer the foreground application.
1381 * <p>
1382 * If the {@link VideoProvider} determines a request to be invalid, it should call
1383 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1384 * invalid request back to the {@link InCallService}.
1385 * <p>
1386 * Where a request requires confirmation from the user of the peer device, the
1387 * {@link VideoProvider} must communicate the request to the peer device and handle the
1388 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1389 * is used to inform the {@link InCallService} of the result of the request.
1390 * <p>
1391 * Sent from the {@link InCallService} via
1392 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001394 * @param fromProfile The video profile prior to the request.
1395 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 */
Tyler Gunn45382162015-05-06 08:52:27 -07001397 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1398 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399
Tyler Gunnb702ef82015-05-29 11:51:53 -07001400 /**
1401 * Provides a response to a request to change the current video session properties.
1402 * <p>
1403 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1404 * video call, could decline the request and keep the call as audio-only.
1405 * In such a scenario, the {@code responseProfile} would have a video state of
1406 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1407 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1408 * <p>
1409 * Sent from the {@link InCallService} via
1410 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1411 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1412 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001413 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001414 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001415 */
1416 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1417
1418 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001419 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1420 * <p>
1421 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1422 * camera via
1423 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1424 * <p>
1425 * Sent from the {@link InCallService} via
1426 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 */
1428 public abstract void onRequestCameraCapabilities();
1429
1430 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001431 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1432 * video component of the current {@link Connection}.
1433 * <p>
1434 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1435 * via {@link VideoProvider#setCallDataUsage(long)}.
1436 * <p>
1437 * Sent from the {@link InCallService} via
1438 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001439 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001440 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441
1442 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001443 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1444 * the peer device when the video signal is paused.
1445 * <p>
1446 * Sent from the {@link InCallService} via
1447 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448 *
1449 * @param uri URI of image to display.
1450 */
Yorke Lee32f24732015-05-12 16:18:03 -07001451 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452
1453 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001454 * Used to inform listening {@link InCallService} implementations when the
1455 * {@link VideoProvider} receives a session modification request.
1456 * <p>
1457 * Received by the {@link InCallService} via
1458 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 * @param videoProfile The requested video profile.
1461 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001462 */
1463 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001464 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001465 for (IVideoCallback callback : mVideoCallbacks.values()) {
1466 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001467 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001468 } catch (RemoteException ignored) {
1469 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001470 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 }
1472 }
1473 }
1474
1475 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001476 * Used to inform listening {@link InCallService} implementations when the
1477 * {@link VideoProvider} receives a response to a session modification request.
1478 * <p>
1479 * Received by the {@link InCallService} via
1480 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1481 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482 *
1483 * @param status Status of the session modify request. Valid values are
1484 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1485 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001486 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1487 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1488 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1489 * @param requestedProfile The original request which was sent to the peer device.
1490 * @param responseProfile The actual profile changes agreed to by the peer device.
1491 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001492 */
1493 public void receiveSessionModifyResponse(int status,
1494 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001495 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001496 for (IVideoCallback callback : mVideoCallbacks.values()) {
1497 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001498 callback.receiveSessionModifyResponse(status, requestedProfile,
1499 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001500 } catch (RemoteException ignored) {
1501 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001502 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 }
1504 }
1505 }
1506
1507 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001508 * Used to inform listening {@link InCallService} implementations when the
1509 * {@link VideoProvider} reports a call session event.
1510 * <p>
1511 * Received by the {@link InCallService} via
1512 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001513 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001514 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1515 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1516 * {@link VideoProvider#SESSION_EVENT_TX_START},
1517 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1518 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001519 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1520 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 */
1522 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001523 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001524 for (IVideoCallback callback : mVideoCallbacks.values()) {
1525 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001526 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001527 } catch (RemoteException ignored) {
1528 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001529 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001530 }
1531 }
1532 }
1533
1534 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001535 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1536 * peer's video have changed.
1537 * <p>
1538 * This could occur if, for example, the peer rotates their device, changing the aspect
1539 * ratio of the video, or if the user switches between the back and front cameras.
1540 * <p>
1541 * Received by the {@link InCallService} via
1542 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001543 *
1544 * @param width The updated peer video width.
1545 * @param height The updated peer video height.
1546 */
1547 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001548 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001549 for (IVideoCallback callback : mVideoCallbacks.values()) {
1550 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001551 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001552 } catch (RemoteException ignored) {
1553 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001554 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001555 }
1556 }
1557 }
1558
1559 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001560 * Used to inform listening {@link InCallService} implementations when the data usage of the
1561 * video associated with the current {@link Connection} has changed.
1562 * <p>
1563 * This could be in response to a preview request via
1564 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001565 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1566 * 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 -07001567 * <p>
1568 * Received by the {@link InCallService} via
1569 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001571 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1572 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001573 */
Yorke Lee32f24732015-05-12 16:18:03 -07001574 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001575 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001576 for (IVideoCallback callback : mVideoCallbacks.values()) {
1577 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001578 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001579 } catch (RemoteException ignored) {
1580 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001581 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 }
1583 }
1584 }
1585
1586 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001587 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001589 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001590 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1591 * @hide
1592 */
1593 public void changeCallDataUsage(long dataUsage) {
1594 setCallDataUsage(dataUsage);
1595 }
1596
1597 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001598 * Used to inform listening {@link InCallService} implementations when the capabilities of
1599 * the current camera have changed.
1600 * <p>
1601 * The {@link VideoProvider} should call this in response to
1602 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1603 * changed via {@link VideoProvider#onSetCamera(String)}.
1604 * <p>
1605 * Received by the {@link InCallService} via
1606 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1607 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001608 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001609 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001610 */
Yorke Lee400470f2015-05-12 13:31:25 -07001611 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001612 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001613 for (IVideoCallback callback : mVideoCallbacks.values()) {
1614 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001615 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001616 } catch (RemoteException ignored) {
1617 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001618 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001619 }
1620 }
1621 }
Rekha Kumar07366812015-03-24 16:42:31 -07001622
1623 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001624 * Used to inform listening {@link InCallService} implementations when the video quality
1625 * of the call has changed.
1626 * <p>
1627 * Received by the {@link InCallService} via
1628 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001629 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001630 * @param videoQuality The updated video quality. Valid values:
1631 * {@link VideoProfile#QUALITY_HIGH},
1632 * {@link VideoProfile#QUALITY_MEDIUM},
1633 * {@link VideoProfile#QUALITY_LOW},
1634 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001635 */
1636 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001637 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001638 for (IVideoCallback callback : mVideoCallbacks.values()) {
1639 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001640 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001641 } catch (RemoteException ignored) {
1642 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001643 }
Rekha Kumar07366812015-03-24 16:42:31 -07001644 }
1645 }
1646 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001647
1648 /**
1649 * Returns a string representation of a call session event.
1650 *
1651 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1652 * @return String representation of the call session event.
1653 * @hide
1654 */
1655 public static String sessionEventToString(int event) {
1656 switch (event) {
1657 case SESSION_EVENT_CAMERA_FAILURE:
1658 return SESSION_EVENT_CAMERA_FAILURE_STR;
1659 case SESSION_EVENT_CAMERA_READY:
1660 return SESSION_EVENT_CAMERA_READY_STR;
1661 case SESSION_EVENT_RX_PAUSE:
1662 return SESSION_EVENT_RX_PAUSE_STR;
1663 case SESSION_EVENT_RX_RESUME:
1664 return SESSION_EVENT_RX_RESUME_STR;
1665 case SESSION_EVENT_TX_START:
1666 return SESSION_EVENT_TX_START_STR;
1667 case SESSION_EVENT_TX_STOP:
1668 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001669 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1670 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001671 default:
1672 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1673 }
1674 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001675 }
1676
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001677 private final Listener mConnectionDeathListener = new Listener() {
1678 @Override
1679 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001680 if (mConferenceables.remove(c)) {
1681 fireOnConferenceableConnectionsChanged();
1682 }
1683 }
1684 };
1685
1686 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1687 @Override
1688 public void onDestroyed(Conference c) {
1689 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001690 fireOnConferenceableConnectionsChanged();
1691 }
1692 }
1693 };
1694
Jay Shrauner229e3822014-08-15 09:23:07 -07001695 /**
1696 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1697 * load factor before resizing, 1 means we only expect a single thread to
1698 * access the map so make only a single shard
1699 */
1700 private final Set<Listener> mListeners = Collections.newSetFromMap(
1701 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001702 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1703 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001704 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001705
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001706 // The internal telecom call ID associated with this connection.
1707 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001708 // The PhoneAccountHandle associated with this connection.
1709 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001711 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001712 private Uri mAddress;
1713 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001714 private String mCallerDisplayName;
1715 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001716 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001718 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001719 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001720 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001721 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001722 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001723 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001724 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001725 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001726 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001727 private Conference mConference;
1728 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001729 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001730 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001731
1732 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001733 * Tracks the key set for the extras bundle provided on the last invocation of
1734 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1735 * keys which were set previously but are no longer present in the replacement Bundle.
1736 */
1737 private Set<String> mPreviousExtraKeys;
1738
1739 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001740 * Create a new Connection.
1741 */
Santos Cordonf2951102014-07-20 19:06:29 -07001742 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001743
1744 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001745 * Returns the Telecom internal call ID associated with this connection. Should only be used
1746 * for debugging and tracing purposes.
1747 *
1748 * @return The Telecom call ID.
1749 * @hide
1750 */
1751 public final String getTelecomCallId() {
1752 return mTelecomCallId;
1753 }
1754
1755 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001756 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001757 */
Andrew Lee100e2932014-09-08 15:34:24 -07001758 public final Uri getAddress() {
1759 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001760 }
1761
1762 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001763 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001764 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001765 */
Andrew Lee100e2932014-09-08 15:34:24 -07001766 public final int getAddressPresentation() {
1767 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001768 }
1769
1770 /**
1771 * @return The caller display name (CNAP).
1772 */
1773 public final String getCallerDisplayName() {
1774 return mCallerDisplayName;
1775 }
1776
1777 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001778 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001779 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001780 */
1781 public final int getCallerDisplayNamePresentation() {
1782 return mCallerDisplayNamePresentation;
1783 }
1784
1785 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001787 */
1788 public final int getState() {
1789 return mState;
1790 }
1791
1792 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001793 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001794 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1795 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1796 * {@link VideoProfile#STATE_TX_ENABLED},
1797 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001798 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001799 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001800 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001801 */
1802 public final int getVideoState() {
1803 return mVideoState;
1804 }
1805
1806 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001807 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001808 * being routed by the system. This is {@code null} if this Connection
1809 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001810 * @deprecated Use {@link #getCallAudioState()} instead.
1811 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001812 */
Yorke Lee4af59352015-05-13 14:14:54 -07001813 @SystemApi
1814 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001816 if (mCallAudioState == null) {
1817 return null;
1818 }
Yorke Lee4af59352015-05-13 14:14:54 -07001819 return new AudioState(mCallAudioState);
1820 }
1821
1822 /**
1823 * @return The audio state of the connection, describing how its audio is currently
1824 * being routed by the system. This is {@code null} if this Connection
1825 * does not directly know about its audio state.
1826 */
1827 public final CallAudioState getCallAudioState() {
1828 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001829 }
1830
1831 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001832 * @return The conference that this connection is a part of. Null if it is not part of any
1833 * conference.
1834 */
1835 public final Conference getConference() {
1836 return mConference;
1837 }
1838
1839 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001840 * Returns whether this connection is requesting that the system play a ringback tone
1841 * on its behalf.
1842 */
Andrew Lee100e2932014-09-08 15:34:24 -07001843 public final boolean isRingbackRequested() {
1844 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001845 }
1846
1847 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001848 * @return True if the connection's audio mode is VOIP.
1849 */
1850 public final boolean getAudioModeIsVoip() {
1851 return mAudioModeIsVoip;
1852 }
1853
1854 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001855 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1856 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1857 * start time of the conference.
1858 *
1859 * @return The time at which the {@code Connnection} was connected.
1860 *
1861 * @hide
1862 */
1863 public final long getConnectTimeMillis() {
1864 return mConnectTimeMillis;
1865 }
1866
1867 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001868 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1869 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1870 * start time of the conference.
1871 *
1872 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1873 * changes do not impact the call duration.
1874 *
1875 * @return The time at which the {@link Connection} was connected.
1876 *
1877 * @hide
1878 */
1879 public final long getConnectElapsedTimeMillis() {
1880 return mConnectElapsedTimeMillis;
1881 }
1882
1883 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001884 * Returns RIL voice radio technology used for current connection.
1885 *
1886 * @return the RIL voice radio technology used for current connection,
1887 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1888 *
1889 * @hide
1890 */
1891 public final @ServiceState.RilRadioTechnology int getCallRadioTech() {
1892 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1893 Bundle extras = getExtras();
1894 if (extras != null) {
1895 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1896 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1897 }
1898 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1899 }
1900
1901 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001902 * @return The status hints for this connection.
1903 */
1904 public final StatusHints getStatusHints() {
1905 return mStatusHints;
1906 }
1907
1908 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001909 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001910 * <p>
1911 * Extras should be updated using {@link #putExtras(Bundle)}.
1912 * <p>
1913 * Telecom or an {@link InCallService} can also update the extras via
1914 * {@link android.telecom.Call#putExtras(Bundle)}, and
1915 * {@link Call#removeExtras(List)}.
1916 * <p>
1917 * The connection is notified of changes to the extras made by Telecom or an
1918 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001919 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001920 * @return The extras associated with this connection.
1921 */
1922 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001923 Bundle extras = null;
1924 synchronized (mExtrasLock) {
1925 if (mExtras != null) {
1926 extras = new Bundle(mExtras);
1927 }
1928 }
1929 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001930 }
1931
1932 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001933 * Assign a listener to be notified of state changes.
1934 *
1935 * @param l A listener.
1936 * @return This Connection.
1937 *
1938 * @hide
1939 */
1940 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001941 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001942 return this;
1943 }
1944
1945 /**
1946 * Remove a previously assigned listener that was being notified of state changes.
1947 *
1948 * @param l A Listener.
1949 * @return This Connection.
1950 *
1951 * @hide
1952 */
1953 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001954 if (l != null) {
1955 mListeners.remove(l);
1956 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001957 return this;
1958 }
1959
1960 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001961 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001962 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001963 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001964 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001965 }
1966
1967 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001968 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1969 * ONLY for debugging purposes.
1970 *
1971 * @param callId The telecom call ID.
1972 * @hide
1973 */
1974 public void setTelecomCallId(String callId) {
1975 mTelecomCallId = callId;
1976 }
1977
1978 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001979 * Inform this Connection that the state of its audio output has been changed externally.
1980 *
1981 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001982 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001983 */
Yorke Lee4af59352015-05-13 14:14:54 -07001984 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001985 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001986 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001987 mCallAudioState = state;
1988 onAudioStateChanged(getAudioState());
1989 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001990 }
1991
1992 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001993 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001994 * @return A string representation of the value.
1995 */
1996 public static String stateToString(int state) {
1997 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001998 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001999 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002000 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002001 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002002 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002003 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002004 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002005 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002006 case STATE_PULLING_CALL:
2007 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002008 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002009 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002010 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002011 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002012 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002013 return "DISCONNECTED";
2014 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002015 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002016 return "UNKNOWN";
2017 }
2018 }
2019
2020 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002021 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002022 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002023 public final int getConnectionCapabilities() {
2024 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002025 }
2026
2027 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002028 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2029 */
2030 public final int getConnectionProperties() {
2031 return mConnectionProperties;
2032 }
2033
2034 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002035 * Returns the connection's supported audio routes.
2036 *
2037 * @hide
2038 */
2039 public final int getSupportedAudioRoutes() {
2040 return mSupportedAudioRoutes;
2041 }
2042
2043 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002044 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002045 *
Andrew Lee100e2932014-09-08 15:34:24 -07002046 * @param address The new address.
2047 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002048 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002049 */
Andrew Lee100e2932014-09-08 15:34:24 -07002050 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002051 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002052 Log.d(this, "setAddress %s", address);
2053 mAddress = address;
2054 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002055 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002056 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002057 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002058 }
2059
2060 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002061 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002062 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002063 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002064 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002065 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002066 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002067 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002068 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002069 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002070 mCallerDisplayName = callerDisplayName;
2071 mCallerDisplayNamePresentation = presentation;
2072 for (Listener l : mListeners) {
2073 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2074 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002075 }
2076
2077 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002078 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002079 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2080 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2081 * {@link VideoProfile#STATE_TX_ENABLED},
2082 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002083 *
2084 * @param videoState The new video state.
2085 */
2086 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002087 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002088 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002089 mVideoState = videoState;
2090 for (Listener l : mListeners) {
2091 l.onVideoStateChanged(this, mVideoState);
2092 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002093 }
2094
2095 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002096 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002097 * communicate).
2098 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002099 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002100 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002101 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002102 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002103 }
2104
2105 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002106 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002108 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002109 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002110 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111 }
2112
2113 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002114 * Sets state to initializing (this Connection is not yet ready to be used).
2115 */
2116 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002117 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002118 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002119 }
2120
2121 /**
2122 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2123 */
2124 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002126 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002127 }
2128
2129 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002130 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002131 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002132 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002133 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002134 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 }
2136
2137 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002138 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2139 * device). Only applicable for {@link Connection}s with
2140 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2141 */
2142 public final void setPulling() {
2143 checkImmutable();
2144 setState(STATE_PULLING_CALL);
2145 }
2146
2147 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002148 * Sets state to be on hold.
2149 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002150 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002151 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002152 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002153 }
2154
2155 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002156 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002157 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002158 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002159 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002160 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002161 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002162 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002163 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002164 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002165 }
2166
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002167 public final VideoProvider getVideoProvider() {
2168 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002169 }
2170
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002171 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002172 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002173 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002174 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002175 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002177 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002178 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002179 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002180 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002181 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002182 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002183 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002184 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002185 }
2186
2187 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002188 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2189 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2190 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2191 * to send an {@link #onPostDialContinue(boolean)} signal.
2192 *
2193 * @param remaining The DTMF character sequence remaining to be emitted once the
2194 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2195 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002196 */
2197 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002198 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002199 for (Listener l : mListeners) {
2200 l.onPostDialWait(this, remaining);
2201 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002202 }
2203
2204 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002205 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2206 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002207 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002208 *
2209 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002210 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002211 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002212 checkImmutable();
2213 for (Listener l : mListeners) {
2214 l.onPostDialChar(this, nextChar);
2215 }
2216 }
2217
2218 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002219 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002220 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002221 *
2222 * @param ringback Whether the ringback tone is to be played.
2223 */
Andrew Lee100e2932014-09-08 15:34:24 -07002224 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002225 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002226 if (mRingbackRequested != ringback) {
2227 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002228 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002229 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002230 }
2231 }
Ihab Awadf8358972014-05-28 16:46:42 -07002232 }
2233
2234 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002235 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002236 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002237 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002238 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002239 public final void setConnectionCapabilities(int connectionCapabilities) {
2240 checkImmutable();
2241 if (mConnectionCapabilities != connectionCapabilities) {
2242 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002243 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002244 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002245 }
2246 }
Santos Cordonb6939982014-06-04 20:20:58 -07002247 }
2248
2249 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002250 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2251 *
2252 * @param connectionProperties The new connection properties.
2253 */
2254 public final void setConnectionProperties(int connectionProperties) {
2255 checkImmutable();
2256 if (mConnectionProperties != connectionProperties) {
2257 mConnectionProperties = connectionProperties;
2258 for (Listener l : mListeners) {
2259 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2260 }
2261 }
2262 }
2263
2264 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002265 * Sets the supported audio routes.
2266 *
2267 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2268 * See {@link CallAudioState}
2269 * @hide
2270 */
2271 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2272 if ((supportedAudioRoutes
2273 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2274 throw new IllegalArgumentException(
2275 "supported audio routes must include either speaker or earpiece");
2276 }
2277
2278 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2279 mSupportedAudioRoutes = supportedAudioRoutes;
2280 for (Listener l : mListeners) {
2281 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2282 }
2283 }
2284 }
2285
2286 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002287 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002288 */
Evan Charlton36a71342014-07-19 16:31:02 -07002289 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002290 for (Listener l : mListeners) {
2291 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002292 }
Santos Cordonb6939982014-06-04 20:20:58 -07002293 }
2294
2295 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002296 * Requests that the framework use VOIP audio mode for this connection.
2297 *
2298 * @param isVoip True if the audio mode is VOIP.
2299 */
2300 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002301 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002302 mAudioModeIsVoip = isVoip;
2303 for (Listener l : mListeners) {
2304 l.onAudioModeIsVoipChanged(this, isVoip);
2305 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002306 }
2307
2308 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002309 * Sets the time at which a call became active on this Connection. This is set only
2310 * when a conference call becomes active on this connection.
2311 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002312 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2313 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002314 *
2315 * @hide
2316 */
2317 public final void setConnectTimeMillis(long connectTimeMillis) {
2318 mConnectTimeMillis = connectTimeMillis;
2319 }
2320
2321 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002322 * Sets the time at which a call became active on this Connection. This is set only
2323 * when a conference call becomes active on this connection.
2324 *
2325 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2326 * {@link SystemClock#elapsedRealtime()}.
2327 *
2328 * @hide
2329 */
Tyler Gunn17541392018-02-01 08:58:38 -08002330 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002331 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2332 }
2333
2334 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002335 * Sets RIL voice radio technology used for current connection.
2336 *
2337 * @param vrat the RIL Voice Radio Technology used for current connection,
2338 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2339 *
2340 * @hide
2341 */
2342 public final void setCallRadioTech(@ServiceState.RilRadioTechnology int vrat) {
2343 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
2344 ServiceState.rilRadioTechnologyToNetworkType(vrat));
2345 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2346 // This action only covers non-IMS CS conference calls.
2347 // For IMS PS call conference call, it can be updated via its host connection
2348 // {@link #Listener.onExtrasChanged} event.
2349 if (getConference() != null) {
2350 getConference().setCallRadioTech(vrat);
2351 }
2352 }
2353
2354 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002355 * Sets the label and icon status to display in the in-call UI.
2356 *
2357 * @param statusHints The status label and icon to set.
2358 */
2359 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002360 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002361 mStatusHints = statusHints;
2362 for (Listener l : mListeners) {
2363 l.onStatusHintsChanged(this, statusHints);
2364 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002365 }
2366
2367 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002368 * Sets the connections with which this connection can be conferenced.
2369 *
2370 * @param conferenceableConnections The set of connections this connection can conference with.
2371 */
2372 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002373 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002374 clearConferenceableList();
2375 for (Connection c : conferenceableConnections) {
2376 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2377 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002378 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002379 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002380 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002381 }
2382 }
2383 fireOnConferenceableConnectionsChanged();
2384 }
2385
2386 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002387 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2388 * or conferences with which this connection can be conferenced.
2389 *
2390 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002391 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002392 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002393 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002394 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002395 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2396 // small amount of items here.
2397 if (!mConferenceables.contains(c)) {
2398 if (c instanceof Connection) {
2399 Connection connection = (Connection) c;
2400 connection.addConnectionListener(mConnectionDeathListener);
2401 } else if (c instanceof Conference) {
2402 Conference conference = (Conference) c;
2403 conference.addListener(mConferenceDeathListener);
2404 }
2405 mConferenceables.add(c);
2406 }
2407 }
2408 fireOnConferenceableConnectionsChanged();
2409 }
2410
2411 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002412 * @hide
2413 * Resets the cdma connection time.
2414 */
2415 public final void resetConnectionTime() {
2416 for (Listener l : mListeners) {
2417 l.onConnectionTimeReset(this);
2418 }
2419 }
2420
2421 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002422 * Returns the connections or conferences with which this connection can be conferenced.
2423 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002424 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002425 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002426 }
2427
Yorke Lee53463962015-08-04 16:07:19 -07002428 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002429 * @hide
2430 */
2431 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002432 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002433 if (mConnectionService != null) {
2434 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2435 "which is already associated with another ConnectionService.");
2436 } else {
2437 mConnectionService = connectionService;
2438 }
2439 }
2440
2441 /**
2442 * @hide
2443 */
2444 public final void unsetConnectionService(ConnectionService connectionService) {
2445 if (mConnectionService != connectionService) {
2446 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2447 "that does not belong to the ConnectionService.");
2448 } else {
2449 mConnectionService = null;
2450 }
2451 }
2452
2453 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002454 * @hide
2455 */
2456 public final ConnectionService getConnectionService() {
2457 return mConnectionService;
2458 }
2459
2460 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002461 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002462 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002463 *
2464 * @param conference The conference.
2465 * @return {@code true} if the conference was successfully set.
2466 * @hide
2467 */
2468 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002469 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002470 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002471 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002472 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002473 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2474 fireConferenceChanged();
2475 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002476 return true;
2477 }
2478 return false;
2479 }
2480
2481 /**
2482 * Resets the conference that this connection is a part of.
2483 * @hide
2484 */
2485 public final void resetConference() {
2486 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002487 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002488 mConference = null;
2489 fireConferenceChanged();
2490 }
2491 }
2492
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002493 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002494 * Set some extras that can be associated with this {@code Connection}.
2495 * <p>
2496 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2497 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2498 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002499 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2500 * {@link #removeExtras(String...)} methods to modify the extras.
2501 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002502 * 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 -07002503 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2504 *
2505 * @param extras The extras associated with this {@code Connection}.
2506 */
2507 public final void setExtras(@Nullable Bundle extras) {
2508 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002509
2510 // Add/replace any new or changed extras values.
2511 putExtras(extras);
2512
2513 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2514 // the current one and remove any keys that went away.
2515 if (mPreviousExtraKeys != null) {
2516 List<String> toRemove = new ArrayList<String>();
2517 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002518 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002519 toRemove.add(oldKey);
2520 }
2521 }
2522 if (!toRemove.isEmpty()) {
2523 removeExtras(toRemove);
2524 }
2525 }
2526
2527 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2528 // called we can see if the caller has removed any extras values.
2529 if (mPreviousExtraKeys == null) {
2530 mPreviousExtraKeys = new ArraySet<String>();
2531 }
2532 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002533 if (extras != null) {
2534 mPreviousExtraKeys.addAll(extras.keySet());
2535 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002536 }
2537
2538 /**
2539 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2540 * added.
2541 * <p>
2542 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2543 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2544 *
2545 * @param extras The extras to add.
2546 */
2547 public final void putExtras(@NonNull Bundle extras) {
2548 checkImmutable();
2549 if (extras == null) {
2550 return;
2551 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002552 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2553 // the listeners.
2554 Bundle listenerExtras;
2555 synchronized (mExtrasLock) {
2556 if (mExtras == null) {
2557 mExtras = new Bundle();
2558 }
2559 mExtras.putAll(extras);
2560 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002561 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002562 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002563 // Create a new clone of the extras for each listener so that they don't clobber
2564 // each other
2565 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002566 }
2567 }
2568
2569 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002570 * Adds a boolean extra to this {@code Connection}.
2571 *
2572 * @param key The extra key.
2573 * @param value The value.
2574 * @hide
2575 */
2576 public final void putExtra(String key, boolean value) {
2577 Bundle newExtras = new Bundle();
2578 newExtras.putBoolean(key, value);
2579 putExtras(newExtras);
2580 }
2581
2582 /**
2583 * Adds an integer extra to this {@code Connection}.
2584 *
2585 * @param key The extra key.
2586 * @param value The value.
2587 * @hide
2588 */
2589 public final void putExtra(String key, int value) {
2590 Bundle newExtras = new Bundle();
2591 newExtras.putInt(key, value);
2592 putExtras(newExtras);
2593 }
2594
2595 /**
2596 * Adds a string extra to this {@code Connection}.
2597 *
2598 * @param key The extra key.
2599 * @param value The value.
2600 * @hide
2601 */
2602 public final void putExtra(String key, String value) {
2603 Bundle newExtras = new Bundle();
2604 newExtras.putString(key, value);
2605 putExtras(newExtras);
2606 }
2607
2608 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002609 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002610 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002611 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002612 */
2613 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002614 synchronized (mExtrasLock) {
2615 if (mExtras != null) {
2616 for (String key : keys) {
2617 mExtras.remove(key);
2618 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002619 }
2620 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002621 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002622 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002623 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002624 }
2625 }
2626
2627 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002628 * Removes extras from this {@code Connection}.
2629 *
2630 * @param keys The keys of the extras to remove.
2631 */
2632 public final void removeExtras(String ... keys) {
2633 removeExtras(Arrays.asList(keys));
2634 }
2635
2636 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002637 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2638 * be change to the {@link #getCallAudioState()}.
2639 * <p>
2640 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2641 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2642 * <p>
2643 * See also {@link InCallService#setAudioRoute(int)}.
2644 *
2645 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2646 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2647 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2648 */
2649 public final void setAudioRoute(int route) {
2650 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002651 l.onAudioRouteChanged(this, route, null);
2652 }
2653 }
2654
2655 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002656 * Request audio routing to a specific bluetooth device. Calling this method may result in
2657 * the device routing audio to a different bluetooth device than the one specified if the
2658 * bluetooth stack is unable to route audio to the requested device.
2659 * A list of available devices can be obtained via
2660 * {@link CallAudioState#getSupportedBluetoothDevices()}
2661 *
2662 * <p>
2663 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2664 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2665 * <p>
Hall Liu15392832018-04-02 13:52:57 -07002666 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2667 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002668 */
Hall Liu15392832018-04-02 13:52:57 -07002669 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002670 for (Listener l : mListeners) {
Hall Liu15392832018-04-02 13:52:57 -07002671 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2672 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002673 }
2674 }
2675
2676 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002677 * Informs listeners that a previously requested RTT session via
2678 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002679 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002680 */
2681 public final void sendRttInitiationSuccess() {
2682 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2683 }
2684
2685 /**
2686 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002687 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002688 * has failed.
2689 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2690 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002691 */
2692 public final void sendRttInitiationFailure(int reason) {
2693 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2694 }
2695
2696 /**
2697 * Informs listeners that a currently active RTT session has been terminated by the remote
2698 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002699 */
2700 public final void sendRttSessionRemotelyTerminated() {
2701 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2702 }
2703
2704 /**
2705 * Informs listeners that the remote side of the call has requested an upgrade to include an
2706 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002707 */
2708 public final void sendRemoteRttRequest() {
2709 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2710 }
2711
2712 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002713 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002714 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002715 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002716 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2717 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002718 */
Yorke Lee4af59352015-05-13 14:14:54 -07002719 @SystemApi
2720 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002721 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002722
2723 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002724 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2725 *
2726 * @param state The new connection audio state.
2727 */
2728 public void onCallAudioStateChanged(CallAudioState state) {}
2729
2730 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002731 * Notifies this Connection of an internal state change. This method is called after the
2732 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002733 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002734 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002735 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002736 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002737
2738 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002739 * Notifies this Connection of a request to play a DTMF tone.
2740 *
2741 * @param c A DTMF character.
2742 */
Santos Cordonf2951102014-07-20 19:06:29 -07002743 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002744
2745 /**
2746 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2747 */
Santos Cordonf2951102014-07-20 19:06:29 -07002748 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002749
2750 /**
2751 * Notifies this Connection of a request to disconnect.
2752 */
Santos Cordonf2951102014-07-20 19:06:29 -07002753 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002754
2755 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002756 * Notifies this Connection of a request to disconnect a participant of the conference managed
2757 * by the connection.
2758 *
2759 * @param endpoint the {@link Uri} of the participant to disconnect.
2760 * @hide
2761 */
2762 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2763
2764 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002765 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002766 */
Santos Cordonf2951102014-07-20 19:06:29 -07002767 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002768
2769 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002770 * Notifies this Connection of a request to abort.
2771 */
Santos Cordonf2951102014-07-20 19:06:29 -07002772 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002773
2774 /**
2775 * Notifies this Connection of a request to hold.
2776 */
Santos Cordonf2951102014-07-20 19:06:29 -07002777 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002778
2779 /**
2780 * Notifies this Connection of a request to exit a hold state.
2781 */
Santos Cordonf2951102014-07-20 19:06:29 -07002782 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002783
2784 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002785 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002786 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002787 * <p>
2788 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2789 * the default dialer's {@link InCallService}.
2790 * <p>
2791 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2792 * Telecom framework may request that the call is answered in the following circumstances:
2793 * <ul>
2794 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2795 * <li>A car mode {@link InCallService} is in use which has declared
2796 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2797 * {@link InCallService} will be able to see calls from self-managed
2798 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2799 * behalf.</li>
2800 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002801 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002802 */
Santos Cordonf2951102014-07-20 19:06:29 -07002803 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002804
2805 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002806 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002807 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002808 * <p>
2809 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2810 * the default dialer's {@link InCallService}.
2811 * <p>
2812 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2813 * Telecom framework may request that the call is answered in the following circumstances:
2814 * <ul>
2815 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2816 * <li>A car mode {@link InCallService} is in use which has declared
2817 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2818 * {@link InCallService} will be able to see calls from self-managed
2819 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2820 * behalf.</li>
2821 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002822 */
2823 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002824 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002825 }
2826
2827 /**
2828 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302829 * a request to deflect.
2830 */
2831 public void onDeflect(Uri address) {}
2832
2833 /**
2834 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002835 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002836 * <p>
2837 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2838 * the default dialer's {@link InCallService}.
2839 * <p>
2840 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2841 * Telecom framework may request that the call is rejected in the following circumstances:
2842 * <ul>
2843 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2844 * <li>A car mode {@link InCallService} is in use which has declared
2845 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2846 * {@link InCallService} will be able to see calls from self-managed
2847 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2848 * behalf.</li>
2849 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002850 */
Santos Cordonf2951102014-07-20 19:06:29 -07002851 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002852
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002853 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002854 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2855 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002856 */
2857 public void onReject(String replyMessage) {}
2858
2859 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002860 * Notifies this Connection of a request to silence the ringer.
2861 * <p>
2862 * The ringer may be silenced by any of the following methods:
2863 * <ul>
2864 * <li>{@link TelecomManager#silenceRinger()}</li>
2865 * <li>The user presses the volume-down button while a call is ringing.</li>
2866 * </ul>
2867 * <p>
2868 * Self-managed {@link ConnectionService} implementations should override this method in their
2869 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2870 * your app set the ringtone as part of the incoming call {@link Notification} (see
2871 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2872 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2873 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2874 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002875 */
2876 public void onSilence() {}
2877
2878 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002879 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2880 */
Santos Cordonf2951102014-07-20 19:06:29 -07002881 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002882
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002883 /**
2884 * Notifies this Connection of a request to pull an external call to the local device.
2885 * <p>
2886 * The {@link InCallService} issues a request to pull an external call to the local device via
2887 * {@link Call#pullExternalCall()}.
2888 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002889 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2890 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002891 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002892 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002893 */
2894 public void onPullExternalCall() {}
2895
2896 /**
2897 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2898 * <p>
2899 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2900 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002901 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2902 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2903 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2904 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2905 * not aware of.
2906 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002907 * See also {@link Call#sendCallEvent(String, Bundle)}.
2908 *
2909 * @param event The call event.
2910 * @param extras Extras associated with the call event.
2911 */
2912 public void onCallEvent(String event, Bundle extras) {}
2913
Tyler Gunndee56a82016-03-23 16:06:34 -07002914 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002915 * Notifies this {@link Connection} that a handover has completed.
2916 * <p>
2917 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2918 * Bundle)} on the initiating side of the handover, and
2919 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2920 */
2921 public void onHandoverComplete() {}
2922
2923 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002924 * Notifies this {@link Connection} of a change to the extras made outside the
2925 * {@link ConnectionService}.
2926 * <p>
2927 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2928 * the {@link android.telecom.Call#putExtras(Bundle)} and
2929 * {@link Call#removeExtras(List)}.
2930 *
2931 * @param extras The new extras bundle.
2932 */
2933 public void onExtrasChanged(Bundle extras) {}
2934
Tyler Gunnf5035432017-01-09 09:43:12 -08002935 /**
2936 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2937 * displaying its incoming call user interface for the {@link Connection}.
2938 * <p>
2939 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2940 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2941 * should show its own incoming call user interface.
2942 * <p>
2943 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002944 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2945 * Telecom framework will display its own incoming call user interface to allow the user to
2946 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2947 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002948 * <p>
2949 * You should trigger the display of the incoming call user interface for your application by
2950 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002951 *
2952 * In your application code, you should create a {@link android.app.NotificationChannel} for
2953 * incoming call notifications from your app:
2954 * <pre><code>
2955 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2956 * NotificationManager.IMPORTANCE_MAX);
2957 * // other channel setup stuff goes here.
2958 *
2959 * // We'll use the default system ringtone for our incoming call notification channel. You can
2960 * // use your own audio resource here.
2961 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2962 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2963 * // Setting the AudioAttributes is important as it identifies the purpose of your
2964 * // notification sound.
2965 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2966 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2967 * .build());
2968 *
2969 * NotificationManager mgr = getSystemService(NotificationManager.class);
2970 * mgr.createNotificationChannel(channel);
2971 * </code></pre>
2972 * When it comes time to post a notification for your incoming call, ensure it uses your
2973 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002974 * <pre><code>
2975 * // Create an intent which triggers your fullscreen incoming call user interface.
2976 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2977 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2978 * intent.setClass(context, YourIncomingCallActivity.class);
2979 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2980 *
2981 * // Build the notification as an ongoing high priority item; this ensures it will show as
2982 * // a heads up notification which slides down over top of the current content.
2983 * final Notification.Builder builder = new Notification.Builder(context);
2984 * builder.setOngoing(true);
2985 * builder.setPriority(Notification.PRIORITY_HIGH);
2986 *
2987 * // Set notification content intent to take user to fullscreen UI if user taps on the
2988 * // notification body.
2989 * builder.setContentIntent(pendingIntent);
2990 * // Set full screen intent to trigger display of the fullscreen UI when the notification
2991 * // manager deems it appropriate.
2992 * builder.setFullScreenIntent(pendingIntent, true);
2993 *
2994 * // Setup notification content.
2995 * builder.setSmallIcon( yourIconResourceId );
2996 * builder.setContentTitle("Your notification title");
2997 * builder.setContentText("Your notification content.");
2998 *
Tyler Gunn06f06162018-06-18 11:24:15 -07002999 * // Set notification as insistent to cause your ringtone to loop.
3000 * Notification notification = builder.build();
3001 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003002 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003003 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003004 * NotificationManager notificationManager = mContext.getSystemService(
3005 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003006 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003007 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003008 */
3009 public void onShowIncomingCallUi() {}
3010
Hall Liub64ac4c2017-02-06 10:49:48 -08003011 /**
3012 * Notifies this {@link Connection} that the user has requested an RTT session.
3013 * The connection service should call {@link #sendRttInitiationSuccess} or
3014 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3015 * request, respectively.
3016 * @param rttTextStream The object that should be used to send text to or receive text from
3017 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003018 */
3019 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3020
3021 /**
3022 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3023 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003024 */
3025 public void onStopRtt() {}
3026
3027 /**
3028 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3029 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3030 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3031 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003032 * @param rttTextStream The object that should be used to send text to or receive text from
3033 * the in-call app.
3034 */
3035 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3036
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003037 static String toLogSafePhoneNumber(String number) {
3038 // For unknown number, log empty string.
3039 if (number == null) {
3040 return "";
3041 }
3042
3043 if (PII_DEBUG) {
3044 // When PII_DEBUG is true we emit PII.
3045 return number;
3046 }
3047
3048 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3049 // sanitized phone numbers.
3050 StringBuilder builder = new StringBuilder();
3051 for (int i = 0; i < number.length(); i++) {
3052 char c = number.charAt(i);
3053 if (c == '-' || c == '@' || c == '.') {
3054 builder.append(c);
3055 } else {
3056 builder.append('x');
3057 }
3058 }
3059 return builder.toString();
3060 }
3061
Ihab Awad542e0ea2014-05-16 10:22:16 -07003062 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003063 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003064 if (mState == STATE_DISCONNECTED && mState != state) {
3065 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003066 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003067 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003068 if (mState != state) {
3069 Log.d(this, "setState: %s", stateToString(state));
3070 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003071 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003072 for (Listener l : mListeners) {
3073 l.onStateChanged(this, state);
3074 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003075 }
3076 }
3077
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003078 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003079 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003080 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3081 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003082 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003083 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003084
3085 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003086 if (mImmutable) {
3087 throw new UnsupportedOperationException("Connection is immutable");
3088 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003089 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003090 }
3091
Evan Charltonbf11f982014-07-20 22:06:28 -07003092 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003093 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003094 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3095 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003096 * <p>
3097 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3098 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003099 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003100 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003101 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003102 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003103 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3104 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003105 }
3106
Evan Charltonbf11f982014-07-20 22:06:28 -07003107 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003108 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3109 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3110 * this should never be un-@hide-den.
3111 *
3112 * @hide
3113 */
3114 public void checkImmutable() {}
3115
3116 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003117 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3118 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3119 * that state. This connection should not be used for anything, and no other
3120 * {@code Connection}s should be attempted.
3121 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003122 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003123 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003124 * @return A {@code Connection} which indicates that the underlying connection should
3125 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003127 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003128 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003129 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003130
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003131 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003132 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003133 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003134 }
3135 }
3136
Santos Cordon823fd3c2014-08-07 18:35:18 -07003137 private final void fireConferenceChanged() {
3138 for (Listener l : mListeners) {
3139 l.onConferenceChanged(this, mConference);
3140 }
3141 }
3142
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003143 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003144 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003145 if (c instanceof Connection) {
3146 Connection connection = (Connection) c;
3147 connection.removeConnectionListener(mConnectionDeathListener);
3148 } else if (c instanceof Conference) {
3149 Conference conference = (Conference) c;
3150 conference.removeListener(mConferenceDeathListener);
3151 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003152 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003153 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003154 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003155
3156 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003157 * Handles a change to extras received from Telecom.
3158 *
3159 * @param extras The new extras.
3160 * @hide
3161 */
3162 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003163 Bundle b = null;
3164 synchronized (mExtrasLock) {
3165 mExtras = extras;
3166 if (mExtras != null) {
3167 b = new Bundle(mExtras);
3168 }
3169 }
3170 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003171 }
3172
3173 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003174 * Notifies listeners that the merge request failed.
3175 *
3176 * @hide
3177 */
3178 protected final void notifyConferenceMergeFailed() {
3179 for (Listener l : mListeners) {
3180 l.onConferenceMergeFailed(this);
3181 }
3182 }
3183
3184 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003185 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003186 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003187 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003188 * @hide
3189 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003190 protected final void updateConferenceParticipants(
3191 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003192 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003193 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003194 }
3195 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003196
3197 /**
3198 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003199 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003200 */
3201 protected void notifyConferenceStarted() {
3202 for (Listener l : mListeners) {
3203 l.onConferenceStarted();
3204 }
3205 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003206
3207 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003208 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3209 * be a part of a conference call.
3210 * @param isConferenceSupported {@code true} if the connection supports being part of a
3211 * conference call, {@code false} otherwise.
3212 * @hide
3213 */
3214 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3215 for (Listener l : mListeners) {
3216 l.onConferenceSupportedChanged(this, isConferenceSupported);
3217 }
3218 }
3219
3220 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303221 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3222 * changed due to an emergency call being redialed.
3223 * @param pHandle The new PhoneAccountHandle for this connection.
3224 * @hide
3225 */
3226 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3227 for (Listener l : mListeners) {
3228 l.onPhoneAccountChanged(this, pHandle);
3229 }
3230 }
3231
3232 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003233 * Sets the {@link PhoneAccountHandle} associated with this connection.
3234 *
3235 * @hide
3236 */
3237 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3238 if (mPhoneAccountHandle != phoneAccountHandle) {
3239 mPhoneAccountHandle = phoneAccountHandle;
3240 notifyPhoneAccountChanged(phoneAccountHandle);
3241 }
3242 }
3243
3244 /**
3245 * Returns the {@link PhoneAccountHandle} associated with this connection.
3246 *
3247 * @hide
3248 */
3249 public PhoneAccountHandle getPhoneAccountHandle() {
3250 return mPhoneAccountHandle;
3251 }
3252
3253 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003254 * Sends an event associated with this {@code Connection} with associated event extras to the
3255 * {@link InCallService}.
3256 * <p>
3257 * Connection events are used to communicate point in time information from a
3258 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3259 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3260 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3261 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3262 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3263 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3264 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3265 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3266 * <p>
3267 * Events are exposed to {@link InCallService} implementations via
3268 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3269 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003270 * 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 -07003271 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3272 * some events altogether.
3273 * <p>
3274 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3275 * conflicts between {@link ConnectionService} implementations. Further, custom
3276 * {@link ConnectionService} implementations shall not re-purpose events in the
3277 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3278 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3279 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3280 * {@code com.example.extra.MY_EXTRA}).
3281 * <p>
3282 * When defining events and the associated extras, it is important to keep their behavior
3283 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3284 * events/extras should me maintained to ensure backwards compatibility with older
3285 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003286 *
3287 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003288 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003289 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003290 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003291 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003292 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003293 }
3294 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003295}