blob: ee1ca5f120e807e2935650d4d6b7cedba1726441 [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 Gunn5bd90852018-09-21 09:37:07 -0700416 /**
417 * Set by the framework to indicate that the network has identified a Connection as an emergency
418 * call.
419 * @hide
420 */
421 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
422
Tyler Gunn96d6c402015-03-18 12:39:23 -0700423 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800424 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700425 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800426
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700427 /**
428 * Connection extra key used to store the last forwarded number associated with the current
429 * connection. Used to communicate to the user interface that the connection was forwarded via
430 * the specified number.
431 */
432 public static final String EXTRA_LAST_FORWARDED_NUMBER =
433 "android.telecom.extra.LAST_FORWARDED_NUMBER";
434
435 /**
436 * Connection extra key used to store a child number associated with the current connection.
437 * Used to communicate to the user interface that the connection was received via
438 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
439 * address.
440 */
441 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
442
443 /**
444 * Connection extra key used to store the subject for an incoming call. The user interface can
445 * query this extra and display its contents for incoming calls. Will only be used if the
446 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
447 */
448 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
449
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800450 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700451 * Boolean connection extra key set on a {@link Connection} in
452 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
453 * current active foreground call to be dropped.
454 */
455 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
456 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
457
458 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700459 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
460 * state to indicate the name of the third-party app which is responsible for the current
461 * foreground call.
462 * <p>
463 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
464 * is able to inform the user that answering the new incoming call will cause a call owned by
465 * another app to be dropped when the incoming call is answered.
466 */
467 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
468 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
469
470 /**
Hall Liu10208662016-06-15 17:55:00 -0700471 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700472 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700473 * @hide
474 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700475 public static final String EXTRA_DISABLE_ADD_CALL =
476 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700477
478 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700479 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
480 * original Connection ID associated with the connection. Used in
481 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
482 * connection/conference added via
483 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
484 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
485 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
486 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
487 * be a way to ensure that we don't add the connection again as a duplicate.
488 * <p>
489 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
490 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
491 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
492 * in a new {@link Connection} which it adds to Telecom via
493 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
494 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
495 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
496 * ID it originally referred to the connection as. Thus Telecom needs to know that the
497 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
498 * @hide
499 */
500 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
501 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
502
503 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800504 * Connection event used to inform Telecom that it should play the on hold tone. This is used
505 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700506 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800507 * @hide
508 */
509 public static final String EVENT_ON_HOLD_TONE_START =
510 "android.telecom.event.ON_HOLD_TONE_START";
511
512 /**
513 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
514 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700515 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800516 * @hide
517 */
518 public static final String EVENT_ON_HOLD_TONE_END =
519 "android.telecom.event.ON_HOLD_TONE_END";
520
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700521 /**
522 * Connection event used to inform {@link InCallService}s when pulling of an external call has
523 * failed. The user interface should inform the user of the error.
524 * <p>
525 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
526 * API is called on a {@link Call} with the properties
527 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
528 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
529 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700530 * <p>
531 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
532 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700533 */
534 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
535
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700536 /**
537 * Connection event used to inform {@link InCallService}s when the merging of two calls has
538 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700539 * <p>
540 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
541 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700542 */
543 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
544
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700545 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700546 * Connection event used to inform {@link InCallService}s when the process of merging a
547 * Connection into a conference has begun.
548 * <p>
549 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
550 * expected to be null when this connection event is used.
551 * @hide
552 */
553 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
554
555 /**
556 * Connection event used to inform {@link InCallService}s when the process of merging a
557 * Connection into a conference has completed.
558 * <p>
559 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
560 * expected to be null when this connection event is used.
561 * @hide
562 */
563 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
564
565 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700566 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
567 * the remote party.
568 * <p>
569 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
570 * call is being held locally on the device. When a capable {@link ConnectionService} receives
571 * signalling to indicate that the remote party has put the call on hold, it can send this
572 * connection event.
573 * @hide
574 */
575 public static final String EVENT_CALL_REMOTELY_HELD =
576 "android.telecom.event.CALL_REMOTELY_HELD";
577
578 /**
579 * Connection event used to inform {@link InCallService}s when a call which was remotely held
580 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
581 * <p>
582 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
583 * call is being held locally on the device. When a capable {@link ConnectionService} receives
584 * signalling to indicate that the remote party has taken the call off hold, it can send this
585 * connection event.
586 * @hide
587 */
588 public static final String EVENT_CALL_REMOTELY_UNHELD =
589 "android.telecom.event.CALL_REMOTELY_UNHELD";
590
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700591 /**
592 * Connection event used to inform an {@link InCallService} which initiated a call handover via
593 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
594 * successfully completed.
595 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700596 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
597 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700598 */
599 public static final String EVENT_HANDOVER_COMPLETE =
600 "android.telecom.event.HANDOVER_COMPLETE";
601
602 /**
603 * Connection event used to inform an {@link InCallService} which initiated a call handover via
604 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
605 * to complete.
606 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700607 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
608 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700609 */
610 public static final String EVENT_HANDOVER_FAILED =
611 "android.telecom.event.HANDOVER_FAILED";
612
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 // Flag controlling whether PII is emitted into the logs
614 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
615
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800616 /**
617 * Whether the given capabilities support the specified capability.
618 *
619 * @param capabilities A capability bit field.
620 * @param capability The capability to check capabilities for.
621 * @return Whether the specified capability is supported.
622 * @hide
623 */
624 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800625 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 }
627
628 /**
629 * Whether the capabilities of this {@code Connection} supports the specified capability.
630 *
631 * @param capability The capability to check capabilities for.
632 * @return Whether the specified capability is supported.
633 * @hide
634 */
635 public boolean can(int capability) {
636 return can(mConnectionCapabilities, capability);
637 }
638
639 /**
640 * Removes the specified capability from the set of capabilities of this {@code Connection}.
641 *
642 * @param capability The capability to remove from the set.
643 * @hide
644 */
645 public void removeCapability(int capability) {
646 mConnectionCapabilities &= ~capability;
647 }
648
649 /**
650 * Adds the specified capability to the set of capabilities of this {@code Connection}.
651 *
652 * @param capability The capability to add to the set.
653 * @hide
654 */
655 public void addCapability(int capability) {
656 mConnectionCapabilities |= capability;
657 }
658
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700659 /**
660 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
661 *
662 * @param capabilities A capability bit field.
663 * @return A human readable string representation.
664 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800665 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700666 return capabilitiesToStringInternal(capabilities, true /* isLong */);
667 }
668
669 /**
670 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
671 * string.
672 *
673 * @param capabilities A capability bit field.
674 * @return A human readable string representation.
675 * @hide
676 */
677 public static String capabilitiesToStringShort(int capabilities) {
678 return capabilitiesToStringInternal(capabilities, false /* isLong */);
679 }
680
681 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700683 builder.append("[");
684 if (isLong) {
685 builder.append("Capabilities:");
686 }
687
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800688 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700689 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800690 }
691 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700692 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800693 }
694 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700695 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800696 }
697 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700698 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800699 }
700 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700701 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800702 }
703 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700704 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800705 }
706 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700707 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700709 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700710 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700711 }
712 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700713 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700714 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700715 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700716 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800717 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700718 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700720 }
721 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700722 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700723 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700724 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800727 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800729 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500730 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500732 }
Rekha Kumar07366812015-03-24 16:42:31 -0700733 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700735 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700736 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700738 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700739 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700741 }
Bryce Lee81901682015-08-28 16:38:02 -0700742 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700744 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700745 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700747 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530748 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
749 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
750 }
Bryce Lee81901682015-08-28 16:38:02 -0700751
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800752 builder.append("]");
753 return builder.toString();
754 }
755
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700756 /**
757 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
758 *
759 * @param properties A property bit field.
760 * @return A human readable string representation.
761 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700762 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700763 return propertiesToStringInternal(properties, true /* isLong */);
764 }
765
766 /**
767 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
768 *
769 * @param properties A property bit field.
770 * @return A human readable string representation.
771 * @hide
772 */
773 public static String propertiesToStringShort(int properties) {
774 return propertiesToStringInternal(properties, false /* isLong */);
775 }
776
777 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700778 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700779 builder.append("[");
780 if (isLong) {
781 builder.append("Properties:");
782 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700783
Tyler Gunnf5035432017-01-09 09:43:12 -0800784 if (can(properties, PROPERTY_SELF_MANAGED)) {
785 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
786 }
787
Hall Liu25c7c4d2016-08-30 13:41:02 -0700788 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
789 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700790 }
791
792 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700793 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700794 }
795
796 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700797 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700798 }
799
800 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700801 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700802 }
803
804 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700805 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700806 }
807
Brad Ebinger15847072016-05-18 11:08:36 -0700808 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700809 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700810 }
811
Hall Liud4d2a8a2018-01-29 17:22:02 -0800812 if (can(properties, PROPERTY_IS_RTT)) {
813 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
814 }
815
Tyler Gunn5bd90852018-09-21 09:37:07 -0700816 if (can(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
817 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
818 }
819
Tyler Gunn720c6642016-03-22 09:02:47 -0700820 builder.append("]");
821 return builder.toString();
822 }
823
Sailesh Nepal091768c2014-06-30 15:15:23 -0700824 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700825 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700826 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700827 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700828 public void onCallerDisplayNameChanged(
829 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700830 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700831 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700832 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800833 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700834 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700835 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800836 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700837 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800838 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 public void onVideoProviderChanged(
840 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700841 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
842 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800843 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700844 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700845 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700846 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800847 public void onConferenceParticipantsChanged(Connection c,
848 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800849 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700850 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700851 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700852 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700853 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700854 /** @hide */
855 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800856 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800857 public void onRttInitiationSuccess(Connection c) {}
858 public void onRttInitiationFailure(Connection c, int reason) {}
859 public void onRttSessionRemotelyTerminated(Connection c) {}
860 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530861 /** @hide */
862 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800863 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700864 }
865
Tyler Gunnb702ef82015-05-29 11:51:53 -0700866 /**
Hall Liu95d55872017-01-25 17:12:49 -0800867 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800868 */
869 public static final class RttTextStream {
870 private static final int READ_BUFFER_SIZE = 1000;
871 private final InputStreamReader mPipeFromInCall;
872 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800873 private final ParcelFileDescriptor mFdFromInCall;
874 private final ParcelFileDescriptor mFdToInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800875 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
876
877 /**
878 * @hide
879 */
880 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800881 mFdFromInCall = fromInCall;
882 mFdToInCall = toInCall;
Hall Liu95d55872017-01-25 17:12:49 -0800883 mPipeFromInCall = new InputStreamReader(
Hall Liua549fed2018-02-09 16:40:03 -0800884 new FileInputStream(fromInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800885 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800886 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800887 }
888
889 /**
890 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
891 * RTT transmits text in real-time, this method should be called as often as text snippets
892 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800893 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800894 * This method is not thread-safe -- calling it from multiple threads simultaneously may
895 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800896 *
Hall Liu95d55872017-01-25 17:12:49 -0800897 * @param input The message to send to the in-call app.
898 */
899 public void write(String input) throws IOException {
900 mPipeToInCall.write(input);
901 mPipeToInCall.flush();
902 }
903
904
905 /**
906 * Reads a string from the in-call app, blocking if there is no data available. Returns
907 * {@code null} if the RTT conversation has been terminated and there is no further data
908 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800909 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800910 * This method is not thread-safe -- calling it from multiple threads simultaneously may
911 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800912 *
Hall Liu95d55872017-01-25 17:12:49 -0800913 * @return A string containing text entered by the user, or {@code null} if the
914 * conversation has been terminated or if there was an error while reading.
915 */
Hall Liuffa4a812017-03-02 16:11:00 -0800916 public String read() throws IOException {
917 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
918 if (numRead < 0) {
919 return null;
920 }
921 return new String(mReadBuffer, 0, numRead);
922 }
923
924 /**
925 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
926 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800927 *
Hall Liuffa4a812017-03-02 16:11:00 -0800928 * @return A string containing text entered by the user, or {@code null} if the user has
929 * not entered any new text yet.
930 */
931 public String readImmediately() throws IOException {
932 if (mPipeFromInCall.ready()) {
933 return read();
934 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800935 return null;
936 }
937 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800938
939 /** @hide */
940 public ParcelFileDescriptor getFdFromInCall() {
941 return mFdFromInCall;
942 }
943
944 /** @hide */
945 public ParcelFileDescriptor getFdToInCall() {
946 return mFdToInCall;
947 }
948 }
949
950 /**
951 * Provides constants to represent the results of responses to session modify requests sent via
952 * {@link Call#sendRttRequest()}
953 */
954 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700955 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800956 /**
957 * Session modify request was successful.
958 */
959 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
960
961 /**
962 * Session modify request failed.
963 */
964 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
965
966 /**
967 * Session modify request ignored due to invalid parameters.
968 */
969 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
970
971 /**
972 * Session modify request timed out.
973 */
974 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
975
976 /**
977 * Session modify request rejected by remote user.
978 */
979 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800980 }
981
982 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700983 * Provides a means of controlling the video session associated with a {@link Connection}.
984 * <p>
985 * Implementations create a custom subclass of {@link VideoProvider} and the
986 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
987 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
988 * should set the {@link VideoProvider}.
989 * <p>
990 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
991 * {@link InCallService} implementations to issue requests related to the video session;
992 * it provides a means for the {@link ConnectionService} to report events and information
993 * related to the video session to Telecom and the {@link InCallService} implementations.
994 * <p>
995 * {@link InCallService} implementations interact with the {@link VideoProvider} via
996 * {@link android.telecom.InCallService.VideoCall}.
997 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700999 /**
1000 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001001 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 */
1003 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001004
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001006 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1007 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008 */
1009 public static final int SESSION_EVENT_RX_RESUME = 2;
1010
1011 /**
1012 * Video transmission has begun. This occurs after a negotiated start of video transmission
1013 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001014 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 */
1016 public static final int SESSION_EVENT_TX_START = 3;
1017
1018 /**
1019 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1020 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001021 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 */
1023 public static final int SESSION_EVENT_TX_STOP = 4;
1024
1025 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001026 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001027 * this as a cue to inform the user the camera is not available.
1028 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 */
1030 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1031
1032 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001033 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001034 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * the camera has become available again.
1036 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001037 */
1038 public static final int SESSION_EVENT_CAMERA_READY = 6;
1039
1040 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001041 * Session event raised by Telecom when
1042 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1043 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1044 * @see #handleCallSessionEvent(int)
1045 */
1046 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1047
1048 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001050 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 */
1052 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1053
1054 /**
1055 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001056 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001057 */
1058 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1059
1060 /**
1061 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001062 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 */
1064 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1065
Rekha Kumar07366812015-03-24 16:42:31 -07001066 /**
1067 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001068 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001069 */
1070 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1071
1072 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001073 * Session modify request rejected by remote user.
1074 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001075 */
1076 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1077
Tyler Gunn75958422015-04-15 14:23:42 -07001078 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001079 private static final int MSG_SET_CAMERA = 2;
1080 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1081 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1082 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1083 private static final int MSG_SET_ZOOM = 6;
1084 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1085 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1086 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001087 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001089 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001090
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001091 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1092 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1093 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1094 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1095 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1096 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001097 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1098 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001099 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1100
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001101 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001103
1104 /**
1105 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001106 *
1107 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1108 * load factor before resizing, 1 means we only expect a single thread to
1109 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001110 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001111 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1112 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113
1114 /**
1115 * Default handler used to consolidate binder method calls onto a single thread.
1116 */
1117 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001118 public VideoProviderHandler() {
1119 super();
1120 }
1121
1122 public VideoProviderHandler(Looper looper) {
1123 super(looper);
1124 }
1125
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 @Override
1127 public void handleMessage(Message msg) {
1128 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001129 case MSG_ADD_VIDEO_CALLBACK: {
1130 IBinder binder = (IBinder) msg.obj;
1131 IVideoCallback callback = IVideoCallback.Stub
1132 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001133 if (callback == null) {
1134 Log.w(this, "addVideoProvider - skipped; callback is null.");
1135 break;
1136 }
1137
Tyler Gunn75958422015-04-15 14:23:42 -07001138 if (mVideoCallbacks.containsKey(binder)) {
1139 Log.i(this, "addVideoProvider - skipped; already present.");
1140 break;
1141 }
1142 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001144 }
1145 case MSG_REMOVE_VIDEO_CALLBACK: {
1146 IBinder binder = (IBinder) msg.obj;
1147 IVideoCallback callback = IVideoCallback.Stub
1148 .asInterface((IBinder) msg.obj);
1149 if (!mVideoCallbacks.containsKey(binder)) {
1150 Log.i(this, "removeVideoProvider - skipped; not present.");
1151 break;
1152 }
1153 mVideoCallbacks.remove(binder);
1154 break;
1155 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001156 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001157 {
1158 SomeArgs args = (SomeArgs) msg.obj;
1159 try {
1160 onSetCamera((String) args.arg1);
1161 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001162 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001163 } finally {
1164 args.recycle();
1165 }
1166 }
1167 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001168 case MSG_SET_PREVIEW_SURFACE:
1169 onSetPreviewSurface((Surface) msg.obj);
1170 break;
1171 case MSG_SET_DISPLAY_SURFACE:
1172 onSetDisplaySurface((Surface) msg.obj);
1173 break;
1174 case MSG_SET_DEVICE_ORIENTATION:
1175 onSetDeviceOrientation(msg.arg1);
1176 break;
1177 case MSG_SET_ZOOM:
1178 onSetZoom((Float) msg.obj);
1179 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001180 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1181 SomeArgs args = (SomeArgs) msg.obj;
1182 try {
1183 onSendSessionModifyRequest((VideoProfile) args.arg1,
1184 (VideoProfile) args.arg2);
1185 } finally {
1186 args.recycle();
1187 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001188 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001189 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001190 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1191 onSendSessionModifyResponse((VideoProfile) msg.obj);
1192 break;
1193 case MSG_REQUEST_CAMERA_CAPABILITIES:
1194 onRequestCameraCapabilities();
1195 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001196 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1197 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001198 break;
1199 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001200 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 break;
1202 default:
1203 break;
1204 }
1205 }
1206 }
1207
1208 /**
1209 * IVideoProvider stub implementation.
1210 */
1211 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001212 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001214 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1215 }
1216
1217 public void removeVideoCallback(IBinder videoCallbackBinder) {
1218 mMessageHandler.obtainMessage(
1219 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001220 }
1221
Tyler Gunn159f35c2017-03-02 09:28:37 -08001222 public void setCamera(String cameraId, String callingPackageName,
1223 int targetSdkVersion) {
1224
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001225 SomeArgs args = SomeArgs.obtain();
1226 args.arg1 = cameraId;
1227 // Propagate the calling package; originally determined in
1228 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1229 // process.
1230 args.arg2 = callingPackageName;
1231 // Pass along the uid and pid of the calling app; this gets lost when we put the
1232 // message onto the handler. These are required for Telecom to perform a permission
1233 // check to see if the calling app is able to use the camera.
1234 args.argi1 = Binder.getCallingUid();
1235 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001236 // Pass along the target SDK version of the calling InCallService. This is used to
1237 // maintain backwards compatibility of the API for older callers.
1238 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001239 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 }
1241
1242 public void setPreviewSurface(Surface surface) {
1243 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1244 }
1245
1246 public void setDisplaySurface(Surface surface) {
1247 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1248 }
1249
1250 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001251 mMessageHandler.obtainMessage(
1252 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 }
1254
1255 public void setZoom(float value) {
1256 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1257 }
1258
Tyler Gunn45382162015-05-06 08:52:27 -07001259 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1260 SomeArgs args = SomeArgs.obtain();
1261 args.arg1 = fromProfile;
1262 args.arg2 = toProfile;
1263 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 }
1265
1266 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1267 mMessageHandler.obtainMessage(
1268 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1269 }
1270
1271 public void requestCameraCapabilities() {
1272 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1273 }
1274
1275 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001276 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 }
1278
Yorke Lee32f24732015-05-12 16:18:03 -07001279 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001280 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1281 }
1282 }
1283
1284 public VideoProvider() {
1285 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001286 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001287 }
1288
1289 /**
1290 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1291 *
1292 * @param looper The looper.
1293 * @hide
1294 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001295 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001296 public VideoProvider(Looper looper) {
1297 mBinder = new VideoProvider.VideoProviderBinder();
1298 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 }
1300
1301 /**
1302 * Returns binder object which can be used across IPC methods.
1303 * @hide
1304 */
1305 public final IVideoProvider getInterface() {
1306 return mBinder;
1307 }
1308
1309 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001310 * 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 * Sent from the {@link InCallService} via
1317 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001319 * @param cameraId The id of the camera (use ids as reported by
1320 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 */
1322 public abstract void onSetCamera(String cameraId);
1323
1324 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001325 * Sets the camera to be used for the outgoing video.
1326 * <p>
1327 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1328 * camera via
1329 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1330 * <p>
1331 * This prototype is used internally to ensure that the calling package name, UID and PID
1332 * are sent to Telecom so that can perform a camera permission check on the caller.
1333 * <p>
1334 * Sent from the {@link InCallService} via
1335 * {@link InCallService.VideoCall#setCamera(String)}.
1336 *
1337 * @param cameraId The id of the camera (use ids as reported by
1338 * {@link CameraManager#getCameraIdList()}).
1339 * @param callingPackageName The AppOpps package name of the caller.
1340 * @param callingUid The UID of the caller.
1341 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001342 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001343 * @hide
1344 */
1345 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001346 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001347
1348 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 * Sets the surface to be used for displaying a preview of what the user's camera is
1350 * currently capturing. When video transmission is enabled, this is the video signal which
1351 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001352 * <p>
1353 * Sent from the {@link InCallService} via
1354 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001356 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001357 */
1358 public abstract void onSetPreviewSurface(Surface surface);
1359
1360 /**
1361 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001362 * <p>
1363 * Sent from the {@link InCallService} via
1364 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001366 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 */
1368 public abstract void onSetDisplaySurface(Surface surface);
1369
1370 /**
1371 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1372 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001373 * <p>
1374 * Sent from the {@link InCallService} via
1375 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 *
1377 * @param rotation The device orientation, in degrees.
1378 */
1379 public abstract void onSetDeviceOrientation(int rotation);
1380
1381 /**
1382 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001383 * <p>
1384 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001385 *
1386 * @param value The camera zoom ratio.
1387 */
1388 public abstract void onSetZoom(float value);
1389
1390 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001391 * Issues a request to modify the properties of the current video session.
1392 * <p>
1393 * Example scenarios include: requesting an audio-only call to be upgraded to a
1394 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1395 * when the {@link InCallService} is no longer the foreground application.
1396 * <p>
1397 * If the {@link VideoProvider} determines a request to be invalid, it should call
1398 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1399 * invalid request back to the {@link InCallService}.
1400 * <p>
1401 * Where a request requires confirmation from the user of the peer device, the
1402 * {@link VideoProvider} must communicate the request to the peer device and handle the
1403 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1404 * is used to inform the {@link InCallService} of the result of the request.
1405 * <p>
1406 * Sent from the {@link InCallService} via
1407 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 * @param fromProfile The video profile prior to the request.
1410 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 */
Tyler Gunn45382162015-05-06 08:52:27 -07001412 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1413 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414
Tyler Gunnb702ef82015-05-29 11:51:53 -07001415 /**
1416 * Provides a response to a request to change the current video session properties.
1417 * <p>
1418 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1419 * video call, could decline the request and keep the call as audio-only.
1420 * In such a scenario, the {@code responseProfile} would have a video state of
1421 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1422 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1423 * <p>
1424 * Sent from the {@link InCallService} via
1425 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1426 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1427 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001428 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001429 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430 */
1431 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1432
1433 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001434 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1435 * <p>
1436 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1437 * camera via
1438 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1439 * <p>
1440 * Sent from the {@link InCallService} via
1441 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 */
1443 public abstract void onRequestCameraCapabilities();
1444
1445 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001446 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1447 * video component of the current {@link Connection}.
1448 * <p>
1449 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1450 * via {@link VideoProvider#setCallDataUsage(long)}.
1451 * <p>
1452 * Sent from the {@link InCallService} via
1453 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001454 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001455 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456
1457 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001458 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1459 * the peer device when the video signal is paused.
1460 * <p>
1461 * Sent from the {@link InCallService} via
1462 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001463 *
1464 * @param uri URI of image to display.
1465 */
Yorke Lee32f24732015-05-12 16:18:03 -07001466 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467
1468 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001469 * Used to inform listening {@link InCallService} implementations when the
1470 * {@link VideoProvider} receives a session modification request.
1471 * <p>
1472 * Received by the {@link InCallService} via
1473 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001474 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001475 * @param videoProfile The requested video profile.
1476 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 */
1478 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001479 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001480 for (IVideoCallback callback : mVideoCallbacks.values()) {
1481 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001482 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001483 } catch (RemoteException ignored) {
1484 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001485 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001486 }
1487 }
1488 }
1489
1490 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001491 * Used to inform listening {@link InCallService} implementations when the
1492 * {@link VideoProvider} receives a response to a session modification request.
1493 * <p>
1494 * Received by the {@link InCallService} via
1495 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1496 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001497 *
1498 * @param status Status of the session modify request. Valid values are
1499 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1500 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001501 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1502 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1503 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1504 * @param requestedProfile The original request which was sent to the peer device.
1505 * @param responseProfile The actual profile changes agreed to by the peer device.
1506 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001507 */
1508 public void receiveSessionModifyResponse(int status,
1509 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001510 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001511 for (IVideoCallback callback : mVideoCallbacks.values()) {
1512 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001513 callback.receiveSessionModifyResponse(status, requestedProfile,
1514 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001515 } catch (RemoteException ignored) {
1516 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001517 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001518 }
1519 }
1520 }
1521
1522 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001523 * Used to inform listening {@link InCallService} implementations when the
1524 * {@link VideoProvider} reports a call session event.
1525 * <p>
1526 * Received by the {@link InCallService} via
1527 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001529 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1530 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1531 * {@link VideoProvider#SESSION_EVENT_TX_START},
1532 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1533 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001534 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1535 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001536 */
1537 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001538 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001539 for (IVideoCallback callback : mVideoCallbacks.values()) {
1540 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001541 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001542 } catch (RemoteException ignored) {
1543 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001544 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 }
1546 }
1547 }
1548
1549 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001550 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1551 * peer's video have changed.
1552 * <p>
1553 * This could occur if, for example, the peer rotates their device, changing the aspect
1554 * ratio of the video, or if the user switches between the back and front cameras.
1555 * <p>
1556 * Received by the {@link InCallService} via
1557 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 *
1559 * @param width The updated peer video width.
1560 * @param height The updated peer video height.
1561 */
1562 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001563 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001564 for (IVideoCallback callback : mVideoCallbacks.values()) {
1565 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001566 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001567 } catch (RemoteException ignored) {
1568 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001569 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 }
1571 }
1572 }
1573
1574 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001575 * Used to inform listening {@link InCallService} implementations when the data usage of the
1576 * video associated with the current {@link Connection} has changed.
1577 * <p>
1578 * This could be in response to a preview request via
1579 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001580 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1581 * 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 -07001582 * <p>
1583 * Received by the {@link InCallService} via
1584 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001585 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001586 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1587 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 */
Yorke Lee32f24732015-05-12 16:18:03 -07001589 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001590 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001591 for (IVideoCallback callback : mVideoCallbacks.values()) {
1592 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001593 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001594 } catch (RemoteException ignored) {
1595 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001596 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 }
1598 }
1599 }
1600
1601 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001602 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001604 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001605 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1606 * @hide
1607 */
1608 public void changeCallDataUsage(long dataUsage) {
1609 setCallDataUsage(dataUsage);
1610 }
1611
1612 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001613 * Used to inform listening {@link InCallService} implementations when the capabilities of
1614 * the current camera have changed.
1615 * <p>
1616 * The {@link VideoProvider} should call this in response to
1617 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1618 * changed via {@link VideoProvider#onSetCamera(String)}.
1619 * <p>
1620 * Received by the {@link InCallService} via
1621 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1622 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001623 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001624 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001625 */
Yorke Lee400470f2015-05-12 13:31:25 -07001626 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001627 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001628 for (IVideoCallback callback : mVideoCallbacks.values()) {
1629 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001630 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001631 } catch (RemoteException ignored) {
1632 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001633 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001634 }
1635 }
1636 }
Rekha Kumar07366812015-03-24 16:42:31 -07001637
1638 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001639 * Used to inform listening {@link InCallService} implementations when the video quality
1640 * of the call has changed.
1641 * <p>
1642 * Received by the {@link InCallService} via
1643 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001644 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001645 * @param videoQuality The updated video quality. Valid values:
1646 * {@link VideoProfile#QUALITY_HIGH},
1647 * {@link VideoProfile#QUALITY_MEDIUM},
1648 * {@link VideoProfile#QUALITY_LOW},
1649 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001650 */
1651 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001652 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001653 for (IVideoCallback callback : mVideoCallbacks.values()) {
1654 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001655 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001656 } catch (RemoteException ignored) {
1657 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001658 }
Rekha Kumar07366812015-03-24 16:42:31 -07001659 }
1660 }
1661 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001662
1663 /**
1664 * Returns a string representation of a call session event.
1665 *
1666 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1667 * @return String representation of the call session event.
1668 * @hide
1669 */
1670 public static String sessionEventToString(int event) {
1671 switch (event) {
1672 case SESSION_EVENT_CAMERA_FAILURE:
1673 return SESSION_EVENT_CAMERA_FAILURE_STR;
1674 case SESSION_EVENT_CAMERA_READY:
1675 return SESSION_EVENT_CAMERA_READY_STR;
1676 case SESSION_EVENT_RX_PAUSE:
1677 return SESSION_EVENT_RX_PAUSE_STR;
1678 case SESSION_EVENT_RX_RESUME:
1679 return SESSION_EVENT_RX_RESUME_STR;
1680 case SESSION_EVENT_TX_START:
1681 return SESSION_EVENT_TX_START_STR;
1682 case SESSION_EVENT_TX_STOP:
1683 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001684 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1685 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001686 default:
1687 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1688 }
1689 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 }
1691
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001692 private final Listener mConnectionDeathListener = new Listener() {
1693 @Override
1694 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001695 if (mConferenceables.remove(c)) {
1696 fireOnConferenceableConnectionsChanged();
1697 }
1698 }
1699 };
1700
1701 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1702 @Override
1703 public void onDestroyed(Conference c) {
1704 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001705 fireOnConferenceableConnectionsChanged();
1706 }
1707 }
1708 };
1709
Jay Shrauner229e3822014-08-15 09:23:07 -07001710 /**
1711 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1712 * load factor before resizing, 1 means we only expect a single thread to
1713 * access the map so make only a single shard
1714 */
1715 private final Set<Listener> mListeners = Collections.newSetFromMap(
1716 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001717 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1718 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001719 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001720
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001721 // The internal telecom call ID associated with this connection.
1722 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001723 // The PhoneAccountHandle associated with this connection.
1724 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001725 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001726 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001727 private Uri mAddress;
1728 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001729 private String mCallerDisplayName;
1730 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001731 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001732 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001733 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001734 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001735 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001736 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001737 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001738 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001739 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001740 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001741 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001742 private Conference mConference;
1743 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001744 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001745 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001746
1747 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001748 * Tracks the key set for the extras bundle provided on the last invocation of
1749 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1750 * keys which were set previously but are no longer present in the replacement Bundle.
1751 */
1752 private Set<String> mPreviousExtraKeys;
1753
1754 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001755 * Create a new Connection.
1756 */
Santos Cordonf2951102014-07-20 19:06:29 -07001757 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001758
1759 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001760 * Returns the Telecom internal call ID associated with this connection. Should only be used
1761 * for debugging and tracing purposes.
1762 *
1763 * @return The Telecom call ID.
1764 * @hide
1765 */
1766 public final String getTelecomCallId() {
1767 return mTelecomCallId;
1768 }
1769
1770 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001771 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001772 */
Andrew Lee100e2932014-09-08 15:34:24 -07001773 public final Uri getAddress() {
1774 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001775 }
1776
1777 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001778 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001779 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001780 */
Andrew Lee100e2932014-09-08 15:34:24 -07001781 public final int getAddressPresentation() {
1782 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001783 }
1784
1785 /**
1786 * @return The caller display name (CNAP).
1787 */
1788 public final String getCallerDisplayName() {
1789 return mCallerDisplayName;
1790 }
1791
1792 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001793 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001794 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001795 */
1796 public final int getCallerDisplayNamePresentation() {
1797 return mCallerDisplayNamePresentation;
1798 }
1799
1800 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001801 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 */
1803 public final int getState() {
1804 return mState;
1805 }
1806
1807 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001808 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001809 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1810 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1811 * {@link VideoProfile#STATE_TX_ENABLED},
1812 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001813 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001814 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001815 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001816 */
1817 public final int getVideoState() {
1818 return mVideoState;
1819 }
1820
1821 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001822 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823 * being routed by the system. This is {@code null} if this Connection
1824 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001825 * @deprecated Use {@link #getCallAudioState()} instead.
1826 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001827 */
Yorke Lee4af59352015-05-13 14:14:54 -07001828 @SystemApi
1829 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001830 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001831 if (mCallAudioState == null) {
1832 return null;
1833 }
Yorke Lee4af59352015-05-13 14:14:54 -07001834 return new AudioState(mCallAudioState);
1835 }
1836
1837 /**
1838 * @return The audio state of the connection, describing how its audio is currently
1839 * being routed by the system. This is {@code null} if this Connection
1840 * does not directly know about its audio state.
1841 */
1842 public final CallAudioState getCallAudioState() {
1843 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001844 }
1845
1846 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001847 * @return The conference that this connection is a part of. Null if it is not part of any
1848 * conference.
1849 */
1850 public final Conference getConference() {
1851 return mConference;
1852 }
1853
1854 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001855 * Returns whether this connection is requesting that the system play a ringback tone
1856 * on its behalf.
1857 */
Andrew Lee100e2932014-09-08 15:34:24 -07001858 public final boolean isRingbackRequested() {
1859 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001860 }
1861
1862 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001863 * @return True if the connection's audio mode is VOIP.
1864 */
1865 public final boolean getAudioModeIsVoip() {
1866 return mAudioModeIsVoip;
1867 }
1868
1869 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001870 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1871 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1872 * start time of the conference.
1873 *
1874 * @return The time at which the {@code Connnection} was connected.
1875 *
1876 * @hide
1877 */
1878 public final long getConnectTimeMillis() {
1879 return mConnectTimeMillis;
1880 }
1881
1882 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001883 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1884 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1885 * start time of the conference.
1886 *
1887 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1888 * changes do not impact the call duration.
1889 *
1890 * @return The time at which the {@link Connection} was connected.
1891 *
1892 * @hide
1893 */
1894 public final long getConnectElapsedTimeMillis() {
1895 return mConnectElapsedTimeMillis;
1896 }
1897
1898 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001899 * Returns RIL voice radio technology used for current connection.
1900 *
1901 * @return the RIL voice radio technology used for current connection,
1902 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1903 *
1904 * @hide
1905 */
1906 public final @ServiceState.RilRadioTechnology int getCallRadioTech() {
1907 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1908 Bundle extras = getExtras();
1909 if (extras != null) {
1910 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1911 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1912 }
1913 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1914 }
1915
1916 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001917 * @return The status hints for this connection.
1918 */
1919 public final StatusHints getStatusHints() {
1920 return mStatusHints;
1921 }
1922
1923 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001924 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001925 * <p>
1926 * Extras should be updated using {@link #putExtras(Bundle)}.
1927 * <p>
1928 * Telecom or an {@link InCallService} can also update the extras via
1929 * {@link android.telecom.Call#putExtras(Bundle)}, and
1930 * {@link Call#removeExtras(List)}.
1931 * <p>
1932 * The connection is notified of changes to the extras made by Telecom or an
1933 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001934 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001935 * @return The extras associated with this connection.
1936 */
1937 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001938 Bundle extras = null;
1939 synchronized (mExtrasLock) {
1940 if (mExtras != null) {
1941 extras = new Bundle(mExtras);
1942 }
1943 }
1944 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001945 }
1946
1947 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001948 * Assign a listener to be notified of state changes.
1949 *
1950 * @param l A listener.
1951 * @return This Connection.
1952 *
1953 * @hide
1954 */
1955 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001956 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001957 return this;
1958 }
1959
1960 /**
1961 * Remove a previously assigned listener that was being notified of state changes.
1962 *
1963 * @param l A Listener.
1964 * @return This Connection.
1965 *
1966 * @hide
1967 */
1968 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001969 if (l != null) {
1970 mListeners.remove(l);
1971 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001972 return this;
1973 }
1974
1975 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001976 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001977 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001978 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001979 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001980 }
1981
1982 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001983 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1984 * ONLY for debugging purposes.
1985 *
1986 * @param callId The telecom call ID.
1987 * @hide
1988 */
1989 public void setTelecomCallId(String callId) {
1990 mTelecomCallId = callId;
1991 }
1992
1993 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001994 * Inform this Connection that the state of its audio output has been changed externally.
1995 *
1996 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001997 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001998 */
Yorke Lee4af59352015-05-13 14:14:54 -07001999 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002000 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002001 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002002 mCallAudioState = state;
2003 onAudioStateChanged(getAudioState());
2004 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002005 }
2006
2007 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002008 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002009 * @return A string representation of the value.
2010 */
2011 public static String stateToString(int state) {
2012 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002013 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002014 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002015 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002016 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002017 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002018 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002019 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002020 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002021 case STATE_PULLING_CALL:
2022 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002023 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002024 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002025 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002026 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002027 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002028 return "DISCONNECTED";
2029 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002030 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002031 return "UNKNOWN";
2032 }
2033 }
2034
2035 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002036 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002037 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002038 public final int getConnectionCapabilities() {
2039 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002040 }
2041
2042 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002043 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2044 */
2045 public final int getConnectionProperties() {
2046 return mConnectionProperties;
2047 }
2048
2049 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002050 * Returns the connection's supported audio routes.
2051 *
2052 * @hide
2053 */
2054 public final int getSupportedAudioRoutes() {
2055 return mSupportedAudioRoutes;
2056 }
2057
2058 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002059 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002060 *
Andrew Lee100e2932014-09-08 15:34:24 -07002061 * @param address The new address.
2062 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002063 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002064 */
Andrew Lee100e2932014-09-08 15:34:24 -07002065 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002066 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002067 Log.d(this, "setAddress %s", address);
2068 mAddress = address;
2069 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002070 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002071 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002072 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002073 }
2074
2075 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002076 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002077 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002078 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002079 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002080 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002081 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002082 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002083 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002084 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002085 mCallerDisplayName = callerDisplayName;
2086 mCallerDisplayNamePresentation = presentation;
2087 for (Listener l : mListeners) {
2088 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2089 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002090 }
2091
2092 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002093 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002094 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2095 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2096 * {@link VideoProfile#STATE_TX_ENABLED},
2097 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002098 *
2099 * @param videoState The new video state.
2100 */
2101 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002102 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002103 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002104 mVideoState = videoState;
2105 for (Listener l : mListeners) {
2106 l.onVideoStateChanged(this, mVideoState);
2107 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002108 }
2109
2110 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002111 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002112 * communicate).
2113 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002114 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002115 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002116 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002117 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002118 }
2119
2120 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002121 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002122 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002123 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002124 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002125 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 }
2127
2128 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002129 * Sets state to initializing (this Connection is not yet ready to be used).
2130 */
2131 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002132 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002133 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002134 }
2135
2136 /**
2137 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2138 */
2139 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002141 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002142 }
2143
2144 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002145 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002146 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002147 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002148 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002149 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002150 }
2151
2152 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002153 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2154 * device). Only applicable for {@link Connection}s with
2155 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2156 */
2157 public final void setPulling() {
2158 checkImmutable();
2159 setState(STATE_PULLING_CALL);
2160 }
2161
2162 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002163 * Sets state to be on hold.
2164 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002165 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002166 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002167 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002168 }
2169
2170 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002171 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002172 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002173 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002174 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002175 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002176 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002177 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002178 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002179 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002180 }
2181
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002182 public final VideoProvider getVideoProvider() {
2183 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002184 }
2185
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002186 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002187 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002188 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002189 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002190 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002191 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002192 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002193 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002194 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002195 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002196 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002197 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002198 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002199 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002200 }
2201
2202 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002203 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2204 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2205 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2206 * to send an {@link #onPostDialContinue(boolean)} signal.
2207 *
2208 * @param remaining The DTMF character sequence remaining to be emitted once the
2209 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2210 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002211 */
2212 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002213 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002214 for (Listener l : mListeners) {
2215 l.onPostDialWait(this, remaining);
2216 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002217 }
2218
2219 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002220 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2221 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002222 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002223 *
2224 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002225 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002226 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002227 checkImmutable();
2228 for (Listener l : mListeners) {
2229 l.onPostDialChar(this, nextChar);
2230 }
2231 }
2232
2233 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002234 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002235 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002236 *
2237 * @param ringback Whether the ringback tone is to be played.
2238 */
Andrew Lee100e2932014-09-08 15:34:24 -07002239 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002240 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002241 if (mRingbackRequested != ringback) {
2242 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002243 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002244 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002245 }
2246 }
Ihab Awadf8358972014-05-28 16:46:42 -07002247 }
2248
2249 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002250 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002251 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002252 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002253 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002254 public final void setConnectionCapabilities(int connectionCapabilities) {
2255 checkImmutable();
2256 if (mConnectionCapabilities != connectionCapabilities) {
2257 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002258 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002259 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002260 }
2261 }
Santos Cordonb6939982014-06-04 20:20:58 -07002262 }
2263
2264 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002265 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2266 *
2267 * @param connectionProperties The new connection properties.
2268 */
2269 public final void setConnectionProperties(int connectionProperties) {
2270 checkImmutable();
2271 if (mConnectionProperties != connectionProperties) {
2272 mConnectionProperties = connectionProperties;
2273 for (Listener l : mListeners) {
2274 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2275 }
2276 }
2277 }
2278
2279 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002280 * Sets the supported audio routes.
2281 *
2282 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2283 * See {@link CallAudioState}
2284 * @hide
2285 */
2286 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2287 if ((supportedAudioRoutes
2288 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2289 throw new IllegalArgumentException(
2290 "supported audio routes must include either speaker or earpiece");
2291 }
2292
2293 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2294 mSupportedAudioRoutes = supportedAudioRoutes;
2295 for (Listener l : mListeners) {
2296 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2297 }
2298 }
2299 }
2300
2301 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002302 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002303 */
Evan Charlton36a71342014-07-19 16:31:02 -07002304 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002305 for (Listener l : mListeners) {
2306 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002307 }
Santos Cordonb6939982014-06-04 20:20:58 -07002308 }
2309
2310 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002311 * Requests that the framework use VOIP audio mode for this connection.
2312 *
2313 * @param isVoip True if the audio mode is VOIP.
2314 */
2315 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002316 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002317 mAudioModeIsVoip = isVoip;
2318 for (Listener l : mListeners) {
2319 l.onAudioModeIsVoipChanged(this, isVoip);
2320 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002321 }
2322
2323 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002324 * Sets the time at which a call became active on this Connection. This is set only
2325 * when a conference call becomes active on this connection.
2326 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002327 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2328 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002329 *
2330 * @hide
2331 */
2332 public final void setConnectTimeMillis(long connectTimeMillis) {
2333 mConnectTimeMillis = connectTimeMillis;
2334 }
2335
2336 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002337 * Sets the time at which a call became active on this Connection. This is set only
2338 * when a conference call becomes active on this connection.
2339 *
2340 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2341 * {@link SystemClock#elapsedRealtime()}.
2342 *
2343 * @hide
2344 */
Tyler Gunn17541392018-02-01 08:58:38 -08002345 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002346 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2347 }
2348
2349 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002350 * Sets RIL voice radio technology used for current connection.
2351 *
2352 * @param vrat the RIL Voice Radio Technology used for current connection,
2353 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2354 *
2355 * @hide
2356 */
2357 public final void setCallRadioTech(@ServiceState.RilRadioTechnology int vrat) {
2358 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
2359 ServiceState.rilRadioTechnologyToNetworkType(vrat));
2360 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2361 // This action only covers non-IMS CS conference calls.
2362 // For IMS PS call conference call, it can be updated via its host connection
2363 // {@link #Listener.onExtrasChanged} event.
2364 if (getConference() != null) {
2365 getConference().setCallRadioTech(vrat);
2366 }
2367 }
2368
2369 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002370 * Sets the label and icon status to display in the in-call UI.
2371 *
2372 * @param statusHints The status label and icon to set.
2373 */
2374 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002375 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002376 mStatusHints = statusHints;
2377 for (Listener l : mListeners) {
2378 l.onStatusHintsChanged(this, statusHints);
2379 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002380 }
2381
2382 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002383 * Sets the connections with which this connection can be conferenced.
2384 *
2385 * @param conferenceableConnections The set of connections this connection can conference with.
2386 */
2387 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002388 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002389 clearConferenceableList();
2390 for (Connection c : conferenceableConnections) {
2391 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2392 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002393 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002394 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002395 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002396 }
2397 }
2398 fireOnConferenceableConnectionsChanged();
2399 }
2400
2401 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002402 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2403 * or conferences with which this connection can be conferenced.
2404 *
2405 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002406 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002407 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002408 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002409 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002410 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2411 // small amount of items here.
2412 if (!mConferenceables.contains(c)) {
2413 if (c instanceof Connection) {
2414 Connection connection = (Connection) c;
2415 connection.addConnectionListener(mConnectionDeathListener);
2416 } else if (c instanceof Conference) {
2417 Conference conference = (Conference) c;
2418 conference.addListener(mConferenceDeathListener);
2419 }
2420 mConferenceables.add(c);
2421 }
2422 }
2423 fireOnConferenceableConnectionsChanged();
2424 }
2425
2426 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002427 * @hide
2428 * Resets the cdma connection time.
2429 */
2430 public final void resetConnectionTime() {
2431 for (Listener l : mListeners) {
2432 l.onConnectionTimeReset(this);
2433 }
2434 }
2435
2436 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002437 * Returns the connections or conferences with which this connection can be conferenced.
2438 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002439 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002440 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002441 }
2442
Yorke Lee53463962015-08-04 16:07:19 -07002443 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002444 * @hide
2445 */
2446 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002447 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002448 if (mConnectionService != null) {
2449 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2450 "which is already associated with another ConnectionService.");
2451 } else {
2452 mConnectionService = connectionService;
2453 }
2454 }
2455
2456 /**
2457 * @hide
2458 */
2459 public final void unsetConnectionService(ConnectionService connectionService) {
2460 if (mConnectionService != connectionService) {
2461 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2462 "that does not belong to the ConnectionService.");
2463 } else {
2464 mConnectionService = null;
2465 }
2466 }
2467
2468 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002469 * @hide
2470 */
2471 public final ConnectionService getConnectionService() {
2472 return mConnectionService;
2473 }
2474
2475 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002476 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002477 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002478 *
2479 * @param conference The conference.
2480 * @return {@code true} if the conference was successfully set.
2481 * @hide
2482 */
2483 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002484 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002485 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002486 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002487 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002488 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2489 fireConferenceChanged();
2490 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002491 return true;
2492 }
2493 return false;
2494 }
2495
2496 /**
2497 * Resets the conference that this connection is a part of.
2498 * @hide
2499 */
2500 public final void resetConference() {
2501 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002502 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002503 mConference = null;
2504 fireConferenceChanged();
2505 }
2506 }
2507
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002508 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002509 * Set some extras that can be associated with this {@code Connection}.
2510 * <p>
2511 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2512 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2513 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002514 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2515 * {@link #removeExtras(String...)} methods to modify the extras.
2516 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002517 * 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 -07002518 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2519 *
2520 * @param extras The extras associated with this {@code Connection}.
2521 */
2522 public final void setExtras(@Nullable Bundle extras) {
2523 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002524
2525 // Add/replace any new or changed extras values.
2526 putExtras(extras);
2527
2528 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2529 // the current one and remove any keys that went away.
2530 if (mPreviousExtraKeys != null) {
2531 List<String> toRemove = new ArrayList<String>();
2532 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002533 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002534 toRemove.add(oldKey);
2535 }
2536 }
2537 if (!toRemove.isEmpty()) {
2538 removeExtras(toRemove);
2539 }
2540 }
2541
2542 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2543 // called we can see if the caller has removed any extras values.
2544 if (mPreviousExtraKeys == null) {
2545 mPreviousExtraKeys = new ArraySet<String>();
2546 }
2547 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002548 if (extras != null) {
2549 mPreviousExtraKeys.addAll(extras.keySet());
2550 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002551 }
2552
2553 /**
2554 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2555 * added.
2556 * <p>
2557 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2558 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2559 *
2560 * @param extras The extras to add.
2561 */
2562 public final void putExtras(@NonNull Bundle extras) {
2563 checkImmutable();
2564 if (extras == null) {
2565 return;
2566 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002567 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2568 // the listeners.
2569 Bundle listenerExtras;
2570 synchronized (mExtrasLock) {
2571 if (mExtras == null) {
2572 mExtras = new Bundle();
2573 }
2574 mExtras.putAll(extras);
2575 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002576 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002577 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002578 // Create a new clone of the extras for each listener so that they don't clobber
2579 // each other
2580 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002581 }
2582 }
2583
2584 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002585 * Adds a boolean extra to this {@code Connection}.
2586 *
2587 * @param key The extra key.
2588 * @param value The value.
2589 * @hide
2590 */
2591 public final void putExtra(String key, boolean value) {
2592 Bundle newExtras = new Bundle();
2593 newExtras.putBoolean(key, value);
2594 putExtras(newExtras);
2595 }
2596
2597 /**
2598 * Adds an integer extra to this {@code Connection}.
2599 *
2600 * @param key The extra key.
2601 * @param value The value.
2602 * @hide
2603 */
2604 public final void putExtra(String key, int value) {
2605 Bundle newExtras = new Bundle();
2606 newExtras.putInt(key, value);
2607 putExtras(newExtras);
2608 }
2609
2610 /**
2611 * Adds a string extra to this {@code Connection}.
2612 *
2613 * @param key The extra key.
2614 * @param value The value.
2615 * @hide
2616 */
2617 public final void putExtra(String key, String value) {
2618 Bundle newExtras = new Bundle();
2619 newExtras.putString(key, value);
2620 putExtras(newExtras);
2621 }
2622
2623 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002624 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002625 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002626 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002627 */
2628 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002629 synchronized (mExtrasLock) {
2630 if (mExtras != null) {
2631 for (String key : keys) {
2632 mExtras.remove(key);
2633 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002634 }
2635 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002636 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002637 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002638 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002639 }
2640 }
2641
2642 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002643 * Removes extras from this {@code Connection}.
2644 *
2645 * @param keys The keys of the extras to remove.
2646 */
2647 public final void removeExtras(String ... keys) {
2648 removeExtras(Arrays.asList(keys));
2649 }
2650
2651 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002652 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2653 * be change to the {@link #getCallAudioState()}.
2654 * <p>
2655 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2656 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2657 * <p>
2658 * See also {@link InCallService#setAudioRoute(int)}.
2659 *
2660 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2661 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2662 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2663 */
2664 public final void setAudioRoute(int route) {
2665 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002666 l.onAudioRouteChanged(this, route, null);
2667 }
2668 }
2669
2670 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002671 * Request audio routing to a specific bluetooth device. Calling this method may result in
2672 * the device routing audio to a different bluetooth device than the one specified if the
2673 * bluetooth stack is unable to route audio to the requested device.
2674 * A list of available devices can be obtained via
2675 * {@link CallAudioState#getSupportedBluetoothDevices()}
2676 *
2677 * <p>
2678 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2679 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2680 * <p>
Hall Liu15392832018-04-02 13:52:57 -07002681 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2682 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002683 */
Hall Liu15392832018-04-02 13:52:57 -07002684 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002685 for (Listener l : mListeners) {
Hall Liu15392832018-04-02 13:52:57 -07002686 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2687 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002688 }
2689 }
2690
2691 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002692 * Informs listeners that a previously requested RTT session via
2693 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002694 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002695 */
2696 public final void sendRttInitiationSuccess() {
2697 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2698 }
2699
2700 /**
2701 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002702 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002703 * has failed.
2704 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2705 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002706 */
2707 public final void sendRttInitiationFailure(int reason) {
2708 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2709 }
2710
2711 /**
2712 * Informs listeners that a currently active RTT session has been terminated by the remote
2713 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002714 */
2715 public final void sendRttSessionRemotelyTerminated() {
2716 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2717 }
2718
2719 /**
2720 * Informs listeners that the remote side of the call has requested an upgrade to include an
2721 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002722 */
2723 public final void sendRemoteRttRequest() {
2724 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2725 }
2726
2727 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002728 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002729 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002730 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002731 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2732 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002733 */
Yorke Lee4af59352015-05-13 14:14:54 -07002734 @SystemApi
2735 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002736 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002737
2738 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002739 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2740 *
2741 * @param state The new connection audio state.
2742 */
2743 public void onCallAudioStateChanged(CallAudioState state) {}
2744
2745 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002746 * Notifies this Connection of an internal state change. This method is called after the
2747 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002748 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002749 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002750 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002751 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002752
2753 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002754 * Notifies this Connection of a request to play a DTMF tone.
2755 *
2756 * @param c A DTMF character.
2757 */
Santos Cordonf2951102014-07-20 19:06:29 -07002758 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002759
2760 /**
2761 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2762 */
Santos Cordonf2951102014-07-20 19:06:29 -07002763 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002764
2765 /**
2766 * Notifies this Connection of a request to disconnect.
2767 */
Santos Cordonf2951102014-07-20 19:06:29 -07002768 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002769
2770 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002771 * Notifies this Connection of a request to disconnect a participant of the conference managed
2772 * by the connection.
2773 *
2774 * @param endpoint the {@link Uri} of the participant to disconnect.
2775 * @hide
2776 */
2777 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2778
2779 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002780 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002781 */
Santos Cordonf2951102014-07-20 19:06:29 -07002782 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002783
2784 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002785 * Notifies this Connection of a request to abort.
2786 */
Santos Cordonf2951102014-07-20 19:06:29 -07002787 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002788
2789 /**
2790 * Notifies this Connection of a request to hold.
2791 */
Santos Cordonf2951102014-07-20 19:06:29 -07002792 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002793
2794 /**
2795 * Notifies this Connection of a request to exit a hold state.
2796 */
Santos Cordonf2951102014-07-20 19:06:29 -07002797 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002798
2799 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002800 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002801 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002802 * <p>
2803 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2804 * the default dialer's {@link InCallService}.
2805 * <p>
2806 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2807 * Telecom framework may request that the call is answered in the following circumstances:
2808 * <ul>
2809 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2810 * <li>A car mode {@link InCallService} is in use which has declared
2811 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2812 * {@link InCallService} will be able to see calls from self-managed
2813 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2814 * behalf.</li>
2815 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002816 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002817 */
Santos Cordonf2951102014-07-20 19:06:29 -07002818 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002819
2820 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002821 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002822 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002823 * <p>
2824 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2825 * the default dialer's {@link InCallService}.
2826 * <p>
2827 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2828 * Telecom framework may request that the call is answered in the following circumstances:
2829 * <ul>
2830 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2831 * <li>A car mode {@link InCallService} is in use which has declared
2832 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2833 * {@link InCallService} will be able to see calls from self-managed
2834 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2835 * behalf.</li>
2836 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002837 */
2838 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002839 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002840 }
2841
2842 /**
2843 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302844 * a request to deflect.
2845 */
2846 public void onDeflect(Uri address) {}
2847
2848 /**
2849 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002850 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002851 * <p>
2852 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2853 * the default dialer's {@link InCallService}.
2854 * <p>
2855 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2856 * Telecom framework may request that the call is rejected in the following circumstances:
2857 * <ul>
2858 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2859 * <li>A car mode {@link InCallService} is in use which has declared
2860 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2861 * {@link InCallService} will be able to see calls from self-managed
2862 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2863 * behalf.</li>
2864 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002865 */
Santos Cordonf2951102014-07-20 19:06:29 -07002866 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002867
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002868 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002869 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2870 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002871 */
2872 public void onReject(String replyMessage) {}
2873
2874 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002875 * Notifies this Connection of a request to silence the ringer.
2876 * <p>
2877 * The ringer may be silenced by any of the following methods:
2878 * <ul>
2879 * <li>{@link TelecomManager#silenceRinger()}</li>
2880 * <li>The user presses the volume-down button while a call is ringing.</li>
2881 * </ul>
2882 * <p>
2883 * Self-managed {@link ConnectionService} implementations should override this method in their
2884 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2885 * your app set the ringtone as part of the incoming call {@link Notification} (see
2886 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2887 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2888 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2889 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002890 */
2891 public void onSilence() {}
2892
2893 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002894 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2895 */
Santos Cordonf2951102014-07-20 19:06:29 -07002896 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002897
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002898 /**
2899 * Notifies this Connection of a request to pull an external call to the local device.
2900 * <p>
2901 * The {@link InCallService} issues a request to pull an external call to the local device via
2902 * {@link Call#pullExternalCall()}.
2903 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002904 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2905 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002906 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002907 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002908 */
2909 public void onPullExternalCall() {}
2910
2911 /**
2912 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2913 * <p>
2914 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2915 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002916 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2917 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2918 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2919 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2920 * not aware of.
2921 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002922 * See also {@link Call#sendCallEvent(String, Bundle)}.
2923 *
2924 * @param event The call event.
2925 * @param extras Extras associated with the call event.
2926 */
2927 public void onCallEvent(String event, Bundle extras) {}
2928
Tyler Gunndee56a82016-03-23 16:06:34 -07002929 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002930 * Notifies this {@link Connection} that a handover has completed.
2931 * <p>
2932 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2933 * Bundle)} on the initiating side of the handover, and
2934 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2935 */
2936 public void onHandoverComplete() {}
2937
2938 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002939 * Notifies this {@link Connection} of a change to the extras made outside the
2940 * {@link ConnectionService}.
2941 * <p>
2942 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2943 * the {@link android.telecom.Call#putExtras(Bundle)} and
2944 * {@link Call#removeExtras(List)}.
2945 *
2946 * @param extras The new extras bundle.
2947 */
2948 public void onExtrasChanged(Bundle extras) {}
2949
Tyler Gunnf5035432017-01-09 09:43:12 -08002950 /**
2951 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2952 * displaying its incoming call user interface for the {@link Connection}.
2953 * <p>
2954 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2955 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2956 * should show its own incoming call user interface.
2957 * <p>
2958 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002959 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2960 * Telecom framework will display its own incoming call user interface to allow the user to
2961 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2962 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002963 * <p>
2964 * You should trigger the display of the incoming call user interface for your application by
2965 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002966 *
2967 * In your application code, you should create a {@link android.app.NotificationChannel} for
2968 * incoming call notifications from your app:
2969 * <pre><code>
2970 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2971 * NotificationManager.IMPORTANCE_MAX);
2972 * // other channel setup stuff goes here.
2973 *
2974 * // We'll use the default system ringtone for our incoming call notification channel. You can
2975 * // use your own audio resource here.
2976 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2977 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2978 * // Setting the AudioAttributes is important as it identifies the purpose of your
2979 * // notification sound.
2980 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2981 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2982 * .build());
2983 *
2984 * NotificationManager mgr = getSystemService(NotificationManager.class);
2985 * mgr.createNotificationChannel(channel);
2986 * </code></pre>
2987 * When it comes time to post a notification for your incoming call, ensure it uses your
2988 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002989 * <pre><code>
2990 * // Create an intent which triggers your fullscreen incoming call user interface.
2991 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
2992 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
2993 * intent.setClass(context, YourIncomingCallActivity.class);
2994 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
2995 *
2996 * // Build the notification as an ongoing high priority item; this ensures it will show as
2997 * // a heads up notification which slides down over top of the current content.
2998 * final Notification.Builder builder = new Notification.Builder(context);
2999 * builder.setOngoing(true);
3000 * builder.setPriority(Notification.PRIORITY_HIGH);
3001 *
3002 * // Set notification content intent to take user to fullscreen UI if user taps on the
3003 * // notification body.
3004 * builder.setContentIntent(pendingIntent);
3005 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3006 * // manager deems it appropriate.
3007 * builder.setFullScreenIntent(pendingIntent, true);
3008 *
3009 * // Setup notification content.
3010 * builder.setSmallIcon( yourIconResourceId );
3011 * builder.setContentTitle("Your notification title");
3012 * builder.setContentText("Your notification content.");
3013 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003014 * // Set notification as insistent to cause your ringtone to loop.
3015 * Notification notification = builder.build();
3016 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003017 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003018 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003019 * NotificationManager notificationManager = mContext.getSystemService(
3020 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003021 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003022 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003023 */
3024 public void onShowIncomingCallUi() {}
3025
Hall Liub64ac4c2017-02-06 10:49:48 -08003026 /**
3027 * Notifies this {@link Connection} that the user has requested an RTT session.
3028 * The connection service should call {@link #sendRttInitiationSuccess} or
3029 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3030 * request, respectively.
3031 * @param rttTextStream The object that should be used to send text to or receive text from
3032 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003033 */
3034 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3035
3036 /**
3037 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3038 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003039 */
3040 public void onStopRtt() {}
3041
3042 /**
3043 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3044 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3045 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3046 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003047 * @param rttTextStream The object that should be used to send text to or receive text from
3048 * the in-call app.
3049 */
3050 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3051
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003052 static String toLogSafePhoneNumber(String number) {
3053 // For unknown number, log empty string.
3054 if (number == null) {
3055 return "";
3056 }
3057
3058 if (PII_DEBUG) {
3059 // When PII_DEBUG is true we emit PII.
3060 return number;
3061 }
3062
3063 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3064 // sanitized phone numbers.
3065 StringBuilder builder = new StringBuilder();
3066 for (int i = 0; i < number.length(); i++) {
3067 char c = number.charAt(i);
3068 if (c == '-' || c == '@' || c == '.') {
3069 builder.append(c);
3070 } else {
3071 builder.append('x');
3072 }
3073 }
3074 return builder.toString();
3075 }
3076
Ihab Awad542e0ea2014-05-16 10:22:16 -07003077 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003078 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003079 if (mState == STATE_DISCONNECTED && mState != state) {
3080 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003081 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003082 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003083 if (mState != state) {
3084 Log.d(this, "setState: %s", stateToString(state));
3085 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003086 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003087 for (Listener l : mListeners) {
3088 l.onStateChanged(this, state);
3089 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003090 }
3091 }
3092
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003093 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003094 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003095 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3096 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003097 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003098 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003099
3100 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003101 if (mImmutable) {
3102 throw new UnsupportedOperationException("Connection is immutable");
3103 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003104 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003105 }
3106
Evan Charltonbf11f982014-07-20 22:06:28 -07003107 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003108 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003109 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3110 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003111 * <p>
3112 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3113 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003114 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003115 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003116 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003117 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003118 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3119 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003120 }
3121
Evan Charltonbf11f982014-07-20 22:06:28 -07003122 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003123 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3124 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3125 * this should never be un-@hide-den.
3126 *
3127 * @hide
3128 */
3129 public void checkImmutable() {}
3130
3131 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003132 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3133 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3134 * that state. This connection should not be used for anything, and no other
3135 * {@code Connection}s should be attempted.
3136 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003137 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003138 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003139 * @return A {@code Connection} which indicates that the underlying connection should
3140 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003142 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003143 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003144 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003145
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003146 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003147 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003148 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003149 }
3150 }
3151
Santos Cordon823fd3c2014-08-07 18:35:18 -07003152 private final void fireConferenceChanged() {
3153 for (Listener l : mListeners) {
3154 l.onConferenceChanged(this, mConference);
3155 }
3156 }
3157
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003158 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003159 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003160 if (c instanceof Connection) {
3161 Connection connection = (Connection) c;
3162 connection.removeConnectionListener(mConnectionDeathListener);
3163 } else if (c instanceof Conference) {
3164 Conference conference = (Conference) c;
3165 conference.removeListener(mConferenceDeathListener);
3166 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003167 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003168 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003169 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003170
3171 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003172 * Handles a change to extras received from Telecom.
3173 *
3174 * @param extras The new extras.
3175 * @hide
3176 */
3177 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003178 Bundle b = null;
3179 synchronized (mExtrasLock) {
3180 mExtras = extras;
3181 if (mExtras != null) {
3182 b = new Bundle(mExtras);
3183 }
3184 }
3185 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003186 }
3187
3188 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003189 * Notifies listeners that the merge request failed.
3190 *
3191 * @hide
3192 */
3193 protected final void notifyConferenceMergeFailed() {
3194 for (Listener l : mListeners) {
3195 l.onConferenceMergeFailed(this);
3196 }
3197 }
3198
3199 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003200 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003201 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003202 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003203 * @hide
3204 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003205 protected final void updateConferenceParticipants(
3206 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003207 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003208 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003209 }
3210 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003211
3212 /**
3213 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003214 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003215 */
3216 protected void notifyConferenceStarted() {
3217 for (Listener l : mListeners) {
3218 l.onConferenceStarted();
3219 }
3220 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003221
3222 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003223 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3224 * be a part of a conference call.
3225 * @param isConferenceSupported {@code true} if the connection supports being part of a
3226 * conference call, {@code false} otherwise.
3227 * @hide
3228 */
3229 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3230 for (Listener l : mListeners) {
3231 l.onConferenceSupportedChanged(this, isConferenceSupported);
3232 }
3233 }
3234
3235 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303236 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3237 * changed due to an emergency call being redialed.
3238 * @param pHandle The new PhoneAccountHandle for this connection.
3239 * @hide
3240 */
3241 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3242 for (Listener l : mListeners) {
3243 l.onPhoneAccountChanged(this, pHandle);
3244 }
3245 }
3246
3247 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003248 * Sets the {@link PhoneAccountHandle} associated with this connection.
3249 *
3250 * @hide
3251 */
3252 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3253 if (mPhoneAccountHandle != phoneAccountHandle) {
3254 mPhoneAccountHandle = phoneAccountHandle;
3255 notifyPhoneAccountChanged(phoneAccountHandle);
3256 }
3257 }
3258
3259 /**
3260 * Returns the {@link PhoneAccountHandle} associated with this connection.
3261 *
3262 * @hide
3263 */
3264 public PhoneAccountHandle getPhoneAccountHandle() {
3265 return mPhoneAccountHandle;
3266 }
3267
3268 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003269 * Sends an event associated with this {@code Connection} with associated event extras to the
3270 * {@link InCallService}.
3271 * <p>
3272 * Connection events are used to communicate point in time information from a
3273 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3274 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3275 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3276 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3277 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3278 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3279 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3280 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3281 * <p>
3282 * Events are exposed to {@link InCallService} implementations via
3283 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3284 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003285 * 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 -07003286 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3287 * some events altogether.
3288 * <p>
3289 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3290 * conflicts between {@link ConnectionService} implementations. Further, custom
3291 * {@link ConnectionService} implementations shall not re-purpose events in the
3292 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3293 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3294 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3295 * {@code com.example.extra.MY_EXTRA}).
3296 * <p>
3297 * When defining events and the associated extras, it is important to keep their behavior
3298 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3299 * events/extras should me maintained to ensure backwards compatibility with older
3300 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003301 *
3302 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003303 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003304 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003305 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003306 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003307 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003308 }
3309 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003310}