blob: 84256037b3793fa5371aab0e91f5b5cb77e54aab [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;
Hall Liu730a2592018-06-25 19:48:33 -070051import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070052import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070053import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070055import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070056import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070057import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070058
59/**
Santos Cordon895d4b82015-06-25 16:41:48 -070060 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
61 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070062 * <p>
63 * Implementations create a custom subclass of {@code Connection} and return it to the framework
64 * as the return value of
65 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
66 * or
67 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
68 * Implementations are then responsible for updating the state of the {@code Connection}, and
69 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
70 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070071 * <p>
72 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
73 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
74 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
75 * {@code Connection} instance.
76 * <p>
77 * Basic call support requires overriding the following methods: {@link #onAnswer()},
78 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
79 * <p>
80 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
81 * {@link #onUnhold()} methods should be overridden to provide hold support for the
82 * {@code Connection}.
83 * <p>
84 * Where a {@code Connection} supports a variation of video calling (e.g. the
85 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
86 * to support answering a call as a video call.
87 * <p>
88 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
89 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
90 * support for pulling the external call.
91 * <p>
92 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
93 * overridden.
94 * <p>
95 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
96 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
97 * for example, call events from a {@link InCallService} are handled,
98 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
99 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
100 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
101 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700102 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700103public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700104
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 /**
106 * The connection is initializing. This is generally the first state for a {@code Connection}
107 * returned by a {@link ConnectionService}.
108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public static final int STATE_INITIALIZING = 0;
110
Santos Cordon895d4b82015-06-25 16:41:48 -0700111 /**
112 * The connection is new and not connected.
113 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 public static final int STATE_NEW = 1;
115
Santos Cordon895d4b82015-06-25 16:41:48 -0700116 /**
117 * An incoming connection is in the ringing state. During this state, the user's ringer or
118 * vibration feature will be activated.
119 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700120 public static final int STATE_RINGING = 2;
121
Santos Cordon895d4b82015-06-25 16:41:48 -0700122 /**
123 * An outgoing connection is in the dialing state. In this state the other party has not yet
124 * answered the call and the user traditionally hears a ringback tone.
125 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700126 public static final int STATE_DIALING = 3;
127
Santos Cordon895d4b82015-06-25 16:41:48 -0700128 /**
129 * A connection is active. Both parties are connected to the call and can actively communicate.
130 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700131 public static final int STATE_ACTIVE = 4;
132
Santos Cordon895d4b82015-06-25 16:41:48 -0700133 /**
134 * A connection is on hold.
135 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700136 public static final int STATE_HOLDING = 5;
137
Santos Cordon895d4b82015-06-25 16:41:48 -0700138 /**
139 * A connection has been disconnected. This is the final state once the user has been
140 * disconnected from a call either locally, remotely or by an error in the service.
141 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 public static final int STATE_DISCONNECTED = 6;
143
Santos Cordon895d4b82015-06-25 16:41:48 -0700144 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700145 * The state of an external connection which is in the process of being pulled from a remote
146 * device to the local device.
147 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700148 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700149 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
150 */
151 public static final int STATE_PULLING_CALL = 7;
152
153 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 * Connection can currently be put on hold or unheld. This is distinct from
155 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
156 * it does not at the moment support the function. This can be true while the call is in the
157 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
158 * display a disabled 'hold' button.
159 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800160 public static final int CAPABILITY_HOLD = 0x00000001;
161
162 /** Connection supports the hold feature. */
163 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
164
165 /**
166 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
167 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
168 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
169 * capability allows a merge button to be shown while the conference is in the foreground
170 * of the in-call UI.
171 * <p>
172 * This is only intended for use by a {@link Conference}.
173 */
174 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
175
176 /**
177 * Connections within a conference can be swapped between foreground and background.
178 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
179 * <p>
180 * This is only intended for use by a {@link Conference}.
181 */
182 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
183
184 /**
185 * @hide
186 */
187 public static final int CAPABILITY_UNUSED = 0x00000010;
188
189 /** Connection supports responding via text option. */
190 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
191
192 /** Connection can be muted. */
193 public static final int CAPABILITY_MUTE = 0x00000040;
194
195 /**
196 * Connection supports conference management. This capability only applies to
197 * {@link Conference}s which can have {@link Connection}s as children.
198 */
199 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
200
201 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800203 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700204 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205
206 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700207 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800208 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700209 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210
211 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700212 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800213 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700214 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700215 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800216
217 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700218 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800219 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700220 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
221
222 /**
223 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700224 */
225 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
226
227 /**
228 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700229 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700230 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700231 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800232
233 /**
234 * Connection is able to be separated from its parent {@code Conference}, if any.
235 */
236 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
237
238 /**
239 * Connection is able to be individually disconnected when in a {@code Conference}.
240 */
241 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
242
243 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700244 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245 * @hide
246 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700247 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700249 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700250 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 * @hide
252 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700253 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254
255 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700256 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257 * @hide
258 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700259 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260
Tyler Gunn068085b2015-02-06 13:56:52 -0800261 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700262 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800263 * @hide
264 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700265 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800266
Tyler Gunn96d6c402015-03-18 12:39:23 -0700267 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500268 * Speed up audio setup for MT call.
269 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700270 */
271 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800272
Rekha Kumar07366812015-03-24 16:42:31 -0700273 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700274 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800275 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
276 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
277 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700278 */
279 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
280
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700281 /**
282 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700283 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700284 */
285 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
286
Tyler Gunnd4091732015-06-29 09:15:37 -0700287 /**
288 * For a conference, indicates the conference will not have child connections.
289 * <p>
290 * An example of a conference with child connections is a GSM conference call, where the radio
291 * retains connections to the individual participants of the conference. Another example is an
292 * IMS conference call where conference event package functionality is supported; in this case
293 * the conference server ensures the radio is aware of the participants in the conference, which
294 * are represented by child connections.
295 * <p>
296 * An example of a conference with no child connections is an IMS conference call with no
297 * conference event package support. Such a conference is represented by the radio as a single
298 * connection to the IMS conference server.
299 * <p>
300 * Indicating whether a conference has children or not is important to help user interfaces
301 * visually represent a conference. A conference with no children, for example, will have the
302 * conference connection shown in the list of calls on a Bluetooth device, where if the
303 * conference has children, only the children will be shown in the list of calls on a Bluetooth
304 * device.
305 * @hide
306 */
307 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
308
Bryce Lee81901682015-08-28 16:38:02 -0700309 /**
310 * Indicates that the connection itself wants to handle any sort of reply response, rather than
311 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700312 */
313 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
314
Tyler Gunnf97a0092016-01-19 15:59:34 -0800315 /**
316 * When set, prevents a video call from being downgraded to an audio-only call.
317 * <p>
318 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
319 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
320 * downgraded from a video call back to a VideoState of
321 * {@link VideoProfile#STATE_AUDIO_ONLY}.
322 * <p>
323 * Intuitively, a call which can be downgraded to audio should also have local and remote
324 * video
325 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
326 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
327 */
328 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
329
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700330 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700331 * When set for an external connection, indicates that this {@code Connection} can be pulled
332 * from a remote device to the current device.
333 * <p>
334 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
335 * is set.
336 */
337 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
338
Pooja Jaind34698d2017-12-28 14:15:31 +0530339 /** Call supports the deflect feature. */
340 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
341
Tyler Gunn720c6642016-03-22 09:02:47 -0700342 //**********************************************************************************************
Pooja Jaind34698d2017-12-28 14:15:31 +0530343 // Next CAPABILITY value: 0x04000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700344 //**********************************************************************************************
345
346 /**
347 * Indicates that the current device callback number should be shown.
348 *
349 * @hide
350 */
Hall Liu25c7c4d2016-08-30 13:41:02 -0700351 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700352
353 /**
354 * Whether the call is a generic conference, where we do not know the precise state of
355 * participants in the conference (eg. on CDMA).
356 *
357 * @hide
358 */
359 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
360
361 /**
362 * Connection is using high definition audio.
363 * @hide
364 */
365 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
366
367 /**
368 * Connection is using WIFI.
369 * @hide
370 */
371 public static final int PROPERTY_WIFI = 1<<3;
372
373 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700374 * When set, indicates that the {@code Connection} does not actually exist locally for the
375 * {@link ConnectionService}.
376 * <p>
377 * Consider, for example, a scenario where a user has two devices with the same phone number.
378 * When a user places a call on one devices, the telephony stack can represent that call on the
379 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700381 * <p>
382 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
383 * external connections. Only those {@link InCallService}s which have the
384 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
385 * manifest will see external connections.
386 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700387 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700388
Brad Ebinger15847072016-05-18 11:08:36 -0700389 /**
390 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
391 */
392 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700393
Hall Liu9f332c72016-07-14 15:37:37 -0700394 /**
395 * Indicates that the connection represents a downgraded IMS conference.
396 * @hide
397 */
398 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
399
Tyler Gunnf5035432017-01-09 09:43:12 -0800400 /**
401 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
402 * {@link ConnectionService}.
403 * <p>
404 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
405 */
406 public static final int PROPERTY_SELF_MANAGED = 1<<7;
407
Hall Liu95d55872017-01-25 17:12:49 -0800408 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800409 * Set by the framework to indicate that a connection has an active RTT session associated with
410 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800411 */
412 public static final int PROPERTY_IS_RTT = 1 << 8;
413
Eric Erfanian62706c52017-12-06 16:27:53 -0800414 /**
415 * Set by the framework to indicate that a connection is using assisted dialing.
Eric Erfaniandd2db2f2018-02-21 19:27:53 +0000416 * @hide
Eric Erfanian62706c52017-12-06 16:27:53 -0800417 */
418 public static final int PROPERTY_ASSISTED_DIALING_USED = 1 << 9;
419
Tyler Gunn5bd90852018-09-21 09:37:07 -0700420 /**
421 * Set by the framework to indicate that the network has identified a Connection as an emergency
422 * call.
423 * @hide
424 */
425 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
426
Tyler Gunn96d6c402015-03-18 12:39:23 -0700427 //**********************************************************************************************
Eric Erfanian62706c52017-12-06 16:27:53 -0800428 // Next PROPERTY value: 1<<10
Tyler Gunn96d6c402015-03-18 12:39:23 -0700429 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800430
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700431 /**
432 * Connection extra key used to store the last forwarded number associated with the current
433 * connection. Used to communicate to the user interface that the connection was forwarded via
434 * the specified number.
435 */
436 public static final String EXTRA_LAST_FORWARDED_NUMBER =
437 "android.telecom.extra.LAST_FORWARDED_NUMBER";
438
439 /**
440 * Connection extra key used to store a child number associated with the current connection.
441 * Used to communicate to the user interface that the connection was received via
442 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
443 * address.
444 */
445 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
446
447 /**
448 * Connection extra key used to store the subject for an incoming call. The user interface can
449 * query this extra and display its contents for incoming calls. Will only be used if the
450 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
451 */
452 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
453
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800454 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700455 * Boolean connection extra key set on a {@link Connection} in
456 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
457 * current active foreground call to be dropped.
458 */
459 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
460 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
461
462 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700463 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
464 * state to indicate the name of the third-party app which is responsible for the current
465 * foreground call.
466 * <p>
467 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
468 * is able to inform the user that answering the new incoming call will cause a call owned by
469 * another app to be dropped when the incoming call is answered.
470 */
471 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
472 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
473
474 /**
Hall Liu10208662016-06-15 17:55:00 -0700475 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700476 * additional call is disallowed.
Hall Liu10208662016-06-15 17:55:00 -0700477 * @hide
478 */
Hall Liuee6e86b2016-07-06 16:32:43 -0700479 public static final String EXTRA_DISABLE_ADD_CALL =
480 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700481
482 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700483 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
484 * original Connection ID associated with the connection. Used in
485 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
486 * connection/conference added via
487 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
488 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
489 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
490 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
491 * be a way to ensure that we don't add the connection again as a duplicate.
492 * <p>
493 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
494 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
495 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
496 * in a new {@link Connection} which it adds to Telecom via
497 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
498 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
499 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
500 * ID it originally referred to the connection as. Thus Telecom needs to know that the
501 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
502 * @hide
503 */
504 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
505 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
506
507 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800508 * Connection event used to inform Telecom that it should play the on hold tone. This is used
509 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700510 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800511 * @hide
512 */
513 public static final String EVENT_ON_HOLD_TONE_START =
514 "android.telecom.event.ON_HOLD_TONE_START";
515
516 /**
517 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
518 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700519 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800520 * @hide
521 */
522 public static final String EVENT_ON_HOLD_TONE_END =
523 "android.telecom.event.ON_HOLD_TONE_END";
524
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700525 /**
526 * Connection event used to inform {@link InCallService}s when pulling of an external call has
527 * failed. The user interface should inform the user of the error.
528 * <p>
529 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
530 * API is called on a {@link Call} with the properties
531 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
532 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
533 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700534 * <p>
535 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
536 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700537 */
538 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
539
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700540 /**
541 * Connection event used to inform {@link InCallService}s when the merging of two calls has
542 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700543 * <p>
544 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
545 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700546 */
547 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
548
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700549 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700550 * Connection event used to inform {@link InCallService}s when the process of merging a
551 * Connection into a conference has begun.
552 * <p>
553 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
554 * expected to be null when this connection event is used.
555 * @hide
556 */
557 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
558
559 /**
560 * Connection event used to inform {@link InCallService}s when the process of merging a
561 * Connection into a conference has completed.
562 * <p>
563 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
564 * expected to be null when this connection event is used.
565 * @hide
566 */
567 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
568
569 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700570 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
571 * the remote party.
572 * <p>
573 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
574 * call is being held locally on the device. When a capable {@link ConnectionService} receives
575 * signalling to indicate that the remote party has put the call on hold, it can send this
576 * connection event.
577 * @hide
578 */
579 public static final String EVENT_CALL_REMOTELY_HELD =
580 "android.telecom.event.CALL_REMOTELY_HELD";
581
582 /**
583 * Connection event used to inform {@link InCallService}s when a call which was remotely held
584 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
585 * <p>
586 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
587 * call is being held locally on the device. When a capable {@link ConnectionService} receives
588 * signalling to indicate that the remote party has taken the call off hold, it can send this
589 * connection event.
590 * @hide
591 */
592 public static final String EVENT_CALL_REMOTELY_UNHELD =
593 "android.telecom.event.CALL_REMOTELY_UNHELD";
594
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700595 /**
596 * Connection event used to inform an {@link InCallService} which initiated a call handover via
597 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
598 * successfully completed.
599 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700600 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
601 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700602 */
603 public static final String EVENT_HANDOVER_COMPLETE =
604 "android.telecom.event.HANDOVER_COMPLETE";
605
606 /**
607 * Connection event used to inform an {@link InCallService} which initiated a call handover via
608 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
609 * to complete.
610 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700611 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
612 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700613 */
614 public static final String EVENT_HANDOVER_FAILED =
615 "android.telecom.event.HANDOVER_FAILED";
616
shilub7ec9a02018-11-09 15:52:04 -0800617 /**
618 * Connection extra key used to store SIP invite fields for an incoming call for IMS calls
619 */
620 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
621
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700622 // Flag controlling whether PII is emitted into the logs
623 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
624
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800625 /**
626 * Whether the given capabilities support the specified capability.
627 *
628 * @param capabilities A capability bit field.
629 * @param capability The capability to check capabilities for.
630 * @return Whether the specified capability is supported.
631 * @hide
632 */
633 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800634 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800635 }
636
637 /**
638 * Whether the capabilities of this {@code Connection} supports the specified capability.
639 *
640 * @param capability The capability to check capabilities for.
641 * @return Whether the specified capability is supported.
642 * @hide
643 */
644 public boolean can(int capability) {
645 return can(mConnectionCapabilities, capability);
646 }
647
648 /**
649 * Removes the specified capability from the set of capabilities of this {@code Connection}.
650 *
651 * @param capability The capability to remove from the set.
652 * @hide
653 */
654 public void removeCapability(int capability) {
655 mConnectionCapabilities &= ~capability;
656 }
657
658 /**
659 * Adds the specified capability to the set of capabilities of this {@code Connection}.
660 *
661 * @param capability The capability to add to the set.
662 * @hide
663 */
664 public void addCapability(int capability) {
665 mConnectionCapabilities |= capability;
666 }
667
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700668 /**
669 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
670 *
671 * @param capabilities A capability bit field.
672 * @return A human readable string representation.
673 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800674 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700675 return capabilitiesToStringInternal(capabilities, true /* isLong */);
676 }
677
678 /**
679 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
680 * string.
681 *
682 * @param capabilities A capability bit field.
683 * @return A human readable string representation.
684 * @hide
685 */
686 public static String capabilitiesToStringShort(int capabilities) {
687 return capabilitiesToStringInternal(capabilities, false /* isLong */);
688 }
689
690 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800691 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700692 builder.append("[");
693 if (isLong) {
694 builder.append("Capabilities:");
695 }
696
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800697 if (can(capabilities, CAPABILITY_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700698 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800699 }
700 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700701 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800702 }
703 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700704 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800705 }
706 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700707 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 }
709 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700710 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800711 }
712 if (can(capabilities, CAPABILITY_MUTE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700713 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800714 }
715 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700716 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800717 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700718 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700719 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700720 }
721 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700722 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700723 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700724 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700725 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800726 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700727 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700728 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700729 }
730 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700731 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700732 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700733 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700734 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800736 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700737 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800738 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500739 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700740 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500741 }
Rekha Kumar07366812015-03-24 16:42:31 -0700742 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700743 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700744 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700745 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700746 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700747 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700748 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700749 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700750 }
Bryce Lee81901682015-08-28 16:38:02 -0700751 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700752 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700753 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700754 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700755 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700756 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530757 if (can(capabilities, CAPABILITY_SUPPORT_DEFLECT)) {
758 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
759 }
Bryce Lee81901682015-08-28 16:38:02 -0700760
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800761 builder.append("]");
762 return builder.toString();
763 }
764
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700765 /**
766 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
767 *
768 * @param properties A property bit field.
769 * @return A human readable string representation.
770 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700771 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -0700772 return propertiesToStringInternal(properties, true /* isLong */);
773 }
774
775 /**
776 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
777 *
778 * @param properties A property bit field.
779 * @return A human readable string representation.
780 * @hide
781 */
782 public static String propertiesToStringShort(int properties) {
783 return propertiesToStringInternal(properties, false /* isLong */);
784 }
785
786 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -0700787 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700788 builder.append("[");
789 if (isLong) {
790 builder.append("Properties:");
791 }
Tyler Gunn720c6642016-03-22 09:02:47 -0700792
Tyler Gunnf5035432017-01-09 09:43:12 -0800793 if (can(properties, PROPERTY_SELF_MANAGED)) {
794 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
795 }
796
Hall Liu25c7c4d2016-08-30 13:41:02 -0700797 if (can(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
798 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -0700799 }
800
801 if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700802 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -0700803 }
804
805 if (can(properties, PROPERTY_WIFI)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700806 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -0700807 }
808
809 if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700810 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -0700811 }
812
813 if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700814 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -0700815 }
816
Brad Ebinger15847072016-05-18 11:08:36 -0700817 if (can(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
Santos Cordon1a749302016-07-26 16:08:53 -0700818 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -0700819 }
820
Hall Liud4d2a8a2018-01-29 17:22:02 -0800821 if (can(properties, PROPERTY_IS_RTT)) {
822 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
823 }
824
Tyler Gunn5bd90852018-09-21 09:37:07 -0700825 if (can(properties, PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)) {
826 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
827 }
828
Tyler Gunn720c6642016-03-22 09:02:47 -0700829 builder.append("]");
830 return builder.toString();
831 }
832
Sailesh Nepal091768c2014-06-30 15:15:23 -0700833 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700834 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700835 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700836 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700837 public void onCallerDisplayNameChanged(
838 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700839 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700840 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700841 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800842 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700843 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700844 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800845 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -0700846 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800847 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 public void onVideoProviderChanged(
849 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700850 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
851 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800852 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700853 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700854 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700855 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800856 public void onConferenceParticipantsChanged(Connection c,
857 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800858 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700859 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700860 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -0700861 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700862 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Tyler Gunn7d633d32016-06-24 07:30:10 -0700863 /** @hide */
864 public void onConferenceSupportedChanged(Connection c, boolean isConferenceSupported) {}
Hall Liua98f58b52017-11-07 17:59:28 -0800865 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800866 public void onRttInitiationSuccess(Connection c) {}
867 public void onRttInitiationFailure(Connection c, int reason) {}
868 public void onRttSessionRemotelyTerminated(Connection c) {}
869 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530870 /** @hide */
871 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +0800872 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700873 }
874
Tyler Gunnb702ef82015-05-29 11:51:53 -0700875 /**
Hall Liu95d55872017-01-25 17:12:49 -0800876 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -0800877 */
878 public static final class RttTextStream {
879 private static final int READ_BUFFER_SIZE = 1000;
880 private final InputStreamReader mPipeFromInCall;
881 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -0800882 private final ParcelFileDescriptor mFdFromInCall;
883 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700884
885 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -0800886 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
887
888 /**
889 * @hide
890 */
891 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -0800892 mFdFromInCall = fromInCall;
893 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -0700894 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -0700895
896 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -0800897 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -0700898 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -0800899 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -0800900 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -0800901 }
902
903 /**
904 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
905 * RTT transmits text in real-time, this method should be called as often as text snippets
906 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -0800907 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800908 * This method is not thread-safe -- calling it from multiple threads simultaneously may
909 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800910 *
Hall Liu95d55872017-01-25 17:12:49 -0800911 * @param input The message to send to the in-call app.
912 */
913 public void write(String input) throws IOException {
914 mPipeToInCall.write(input);
915 mPipeToInCall.flush();
916 }
917
918
919 /**
920 * Reads a string from the in-call app, blocking if there is no data available. Returns
921 * {@code null} if the RTT conversation has been terminated and there is no further data
922 * to read.
Hall Liua549fed2018-02-09 16:40:03 -0800923 * <p>
Hall Liu95d55872017-01-25 17:12:49 -0800924 * This method is not thread-safe -- calling it from multiple threads simultaneously may
925 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -0800926 *
Hall Liu95d55872017-01-25 17:12:49 -0800927 * @return A string containing text entered by the user, or {@code null} if the
928 * conversation has been terminated or if there was an error while reading.
929 */
Hall Liuffa4a812017-03-02 16:11:00 -0800930 public String read() throws IOException {
931 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
932 if (numRead < 0) {
933 return null;
934 }
935 return new String(mReadBuffer, 0, numRead);
936 }
937
938 /**
939 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
940 * be read.
Hall Liua549fed2018-02-09 16:40:03 -0800941 *
Hall Liuffa4a812017-03-02 16:11:00 -0800942 * @return A string containing text entered by the user, or {@code null} if the user has
943 * not entered any new text yet.
944 */
945 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -0700946 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -0800947 return read();
948 } else {
Hall Liu95d55872017-01-25 17:12:49 -0800949 return null;
950 }
951 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800952
953 /** @hide */
954 public ParcelFileDescriptor getFdFromInCall() {
955 return mFdFromInCall;
956 }
957
958 /** @hide */
959 public ParcelFileDescriptor getFdToInCall() {
960 return mFdToInCall;
961 }
962 }
963
964 /**
965 * Provides constants to represent the results of responses to session modify requests sent via
966 * {@link Call#sendRttRequest()}
967 */
968 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -0700969 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800970 /**
971 * Session modify request was successful.
972 */
973 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
974
975 /**
976 * Session modify request failed.
977 */
978 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
979
980 /**
981 * Session modify request ignored due to invalid parameters.
982 */
983 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
984
985 /**
986 * Session modify request timed out.
987 */
988 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
989
990 /**
991 * Session modify request rejected by remote user.
992 */
993 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -0800994 }
995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Provides a means of controlling the video session associated with a {@link Connection}.
998 * <p>
999 * Implementations create a custom subclass of {@link VideoProvider} and the
1000 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1001 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1002 * should set the {@link VideoProvider}.
1003 * <p>
1004 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1005 * {@link InCallService} implementations to issue requests related to the video session;
1006 * it provides a means for the {@link ConnectionService} to report events and information
1007 * related to the video session to Telecom and the {@link InCallService} implementations.
1008 * <p>
1009 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1010 * {@link android.telecom.InCallService.VideoCall}.
1011 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001012 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001013 /**
1014 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001015 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 */
1017 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001018
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001020 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1021 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001022 */
1023 public static final int SESSION_EVENT_RX_RESUME = 2;
1024
1025 /**
1026 * Video transmission has begun. This occurs after a negotiated start of video transmission
1027 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001028 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001029 */
1030 public static final int SESSION_EVENT_TX_START = 3;
1031
1032 /**
1033 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1034 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001035 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 */
1037 public static final int SESSION_EVENT_TX_STOP = 4;
1038
1039 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001040 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001041 * this as a cue to inform the user the camera is not available.
1042 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 */
1044 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1045
1046 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001047 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001048 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001049 * the camera has become available again.
1050 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001051 */
1052 public static final int SESSION_EVENT_CAMERA_READY = 6;
1053
1054 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001055 * Session event raised by Telecom when
1056 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1057 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1058 * @see #handleCallSessionEvent(int)
1059 */
1060 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1061
1062 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001063 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001064 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001065 */
1066 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1067
1068 /**
1069 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001070 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001071 */
1072 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1073
1074 /**
1075 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001076 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 */
1078 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1079
Rekha Kumar07366812015-03-24 16:42:31 -07001080 /**
1081 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001082 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001083 */
1084 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1085
1086 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001087 * Session modify request rejected by remote user.
1088 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001089 */
1090 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1091
Tyler Gunn75958422015-04-15 14:23:42 -07001092 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001093 private static final int MSG_SET_CAMERA = 2;
1094 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1095 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1096 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1097 private static final int MSG_SET_ZOOM = 6;
1098 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1099 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1100 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001103 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001104
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001105 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1106 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1107 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1108 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1109 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1110 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001111 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1112 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001113 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1114
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001115 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001117
1118 /**
1119 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001120 *
1121 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1122 * load factor before resizing, 1 means we only expect a single thread to
1123 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001124 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001125 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1126 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001127
1128 /**
1129 * Default handler used to consolidate binder method calls onto a single thread.
1130 */
1131 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001132 public VideoProviderHandler() {
1133 super();
1134 }
1135
1136 public VideoProviderHandler(Looper looper) {
1137 super(looper);
1138 }
1139
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 @Override
1141 public void handleMessage(Message msg) {
1142 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001143 case MSG_ADD_VIDEO_CALLBACK: {
1144 IBinder binder = (IBinder) msg.obj;
1145 IVideoCallback callback = IVideoCallback.Stub
1146 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001147 if (callback == null) {
1148 Log.w(this, "addVideoProvider - skipped; callback is null.");
1149 break;
1150 }
1151
Tyler Gunn75958422015-04-15 14:23:42 -07001152 if (mVideoCallbacks.containsKey(binder)) {
1153 Log.i(this, "addVideoProvider - skipped; already present.");
1154 break;
1155 }
1156 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001157 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001158 }
1159 case MSG_REMOVE_VIDEO_CALLBACK: {
1160 IBinder binder = (IBinder) msg.obj;
1161 IVideoCallback callback = IVideoCallback.Stub
1162 .asInterface((IBinder) msg.obj);
1163 if (!mVideoCallbacks.containsKey(binder)) {
1164 Log.i(this, "removeVideoProvider - skipped; not present.");
1165 break;
1166 }
1167 mVideoCallbacks.remove(binder);
1168 break;
1169 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001171 {
1172 SomeArgs args = (SomeArgs) msg.obj;
1173 try {
1174 onSetCamera((String) args.arg1);
1175 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001176 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001177 } finally {
1178 args.recycle();
1179 }
1180 }
1181 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001182 case MSG_SET_PREVIEW_SURFACE:
1183 onSetPreviewSurface((Surface) msg.obj);
1184 break;
1185 case MSG_SET_DISPLAY_SURFACE:
1186 onSetDisplaySurface((Surface) msg.obj);
1187 break;
1188 case MSG_SET_DEVICE_ORIENTATION:
1189 onSetDeviceOrientation(msg.arg1);
1190 break;
1191 case MSG_SET_ZOOM:
1192 onSetZoom((Float) msg.obj);
1193 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001194 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1195 SomeArgs args = (SomeArgs) msg.obj;
1196 try {
1197 onSendSessionModifyRequest((VideoProfile) args.arg1,
1198 (VideoProfile) args.arg2);
1199 } finally {
1200 args.recycle();
1201 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001203 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001204 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1205 onSendSessionModifyResponse((VideoProfile) msg.obj);
1206 break;
1207 case MSG_REQUEST_CAMERA_CAPABILITIES:
1208 onRequestCameraCapabilities();
1209 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001210 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1211 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001212 break;
1213 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001214 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001215 break;
1216 default:
1217 break;
1218 }
1219 }
1220 }
1221
1222 /**
1223 * IVideoProvider stub implementation.
1224 */
1225 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001226 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001227 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001228 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1229 }
1230
1231 public void removeVideoCallback(IBinder videoCallbackBinder) {
1232 mMessageHandler.obtainMessage(
1233 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001234 }
1235
Tyler Gunn159f35c2017-03-02 09:28:37 -08001236 public void setCamera(String cameraId, String callingPackageName,
1237 int targetSdkVersion) {
1238
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001239 SomeArgs args = SomeArgs.obtain();
1240 args.arg1 = cameraId;
1241 // Propagate the calling package; originally determined in
1242 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1243 // process.
1244 args.arg2 = callingPackageName;
1245 // Pass along the uid and pid of the calling app; this gets lost when we put the
1246 // message onto the handler. These are required for Telecom to perform a permission
1247 // check to see if the calling app is able to use the camera.
1248 args.argi1 = Binder.getCallingUid();
1249 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001250 // Pass along the target SDK version of the calling InCallService. This is used to
1251 // maintain backwards compatibility of the API for older callers.
1252 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001253 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001254 }
1255
1256 public void setPreviewSurface(Surface surface) {
1257 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1258 }
1259
1260 public void setDisplaySurface(Surface surface) {
1261 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1262 }
1263
1264 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001265 mMessageHandler.obtainMessage(
1266 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 }
1268
1269 public void setZoom(float value) {
1270 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1271 }
1272
Tyler Gunn45382162015-05-06 08:52:27 -07001273 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1274 SomeArgs args = SomeArgs.obtain();
1275 args.arg1 = fromProfile;
1276 args.arg2 = toProfile;
1277 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 }
1279
1280 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1281 mMessageHandler.obtainMessage(
1282 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1283 }
1284
1285 public void requestCameraCapabilities() {
1286 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1287 }
1288
1289 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001290 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 }
1292
Yorke Lee32f24732015-05-12 16:18:03 -07001293 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1295 }
1296 }
1297
1298 public VideoProvider() {
1299 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001300 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001301 }
1302
1303 /**
1304 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1305 *
1306 * @param looper The looper.
1307 * @hide
1308 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001309 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001310 public VideoProvider(Looper looper) {
1311 mBinder = new VideoProvider.VideoProviderBinder();
1312 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 }
1314
1315 /**
1316 * Returns binder object which can be used across IPC methods.
1317 * @hide
1318 */
1319 public final IVideoProvider getInterface() {
1320 return mBinder;
1321 }
1322
1323 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001324 * Sets the camera to be used for the outgoing video.
1325 * <p>
1326 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1327 * camera via
1328 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1329 * <p>
1330 * Sent from the {@link InCallService} via
1331 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001332 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001333 * @param cameraId The id of the camera (use ids as reported by
1334 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 */
1336 public abstract void onSetCamera(String cameraId);
1337
1338 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001339 * Sets the camera to be used for the outgoing video.
1340 * <p>
1341 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1342 * camera via
1343 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1344 * <p>
1345 * This prototype is used internally to ensure that the calling package name, UID and PID
1346 * are sent to Telecom so that can perform a camera permission check on the caller.
1347 * <p>
1348 * Sent from the {@link InCallService} via
1349 * {@link InCallService.VideoCall#setCamera(String)}.
1350 *
1351 * @param cameraId The id of the camera (use ids as reported by
1352 * {@link CameraManager#getCameraIdList()}).
1353 * @param callingPackageName The AppOpps package name of the caller.
1354 * @param callingUid The UID of the caller.
1355 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001356 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001357 * @hide
1358 */
1359 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001360 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001361
1362 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001363 * Sets the surface to be used for displaying a preview of what the user's camera is
1364 * currently capturing. When video transmission is enabled, this is the video signal which
1365 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001366 * <p>
1367 * Sent from the {@link InCallService} via
1368 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001369 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001370 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 */
1372 public abstract void onSetPreviewSurface(Surface surface);
1373
1374 /**
1375 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001376 * <p>
1377 * Sent from the {@link InCallService} via
1378 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001380 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 */
1382 public abstract void onSetDisplaySurface(Surface surface);
1383
1384 /**
1385 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1386 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001387 * <p>
1388 * Sent from the {@link InCallService} via
1389 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 *
1391 * @param rotation The device orientation, in degrees.
1392 */
1393 public abstract void onSetDeviceOrientation(int rotation);
1394
1395 /**
1396 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * <p>
1398 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399 *
1400 * @param value The camera zoom ratio.
1401 */
1402 public abstract void onSetZoom(float value);
1403
1404 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001405 * Issues a request to modify the properties of the current video session.
1406 * <p>
1407 * Example scenarios include: requesting an audio-only call to be upgraded to a
1408 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1409 * when the {@link InCallService} is no longer the foreground application.
1410 * <p>
1411 * If the {@link VideoProvider} determines a request to be invalid, it should call
1412 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1413 * invalid request back to the {@link InCallService}.
1414 * <p>
1415 * Where a request requires confirmation from the user of the peer device, the
1416 * {@link VideoProvider} must communicate the request to the peer device and handle the
1417 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1418 * is used to inform the {@link InCallService} of the result of the request.
1419 * <p>
1420 * Sent from the {@link InCallService} via
1421 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001422 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001423 * @param fromProfile The video profile prior to the request.
1424 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001425 */
Tyler Gunn45382162015-05-06 08:52:27 -07001426 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1427 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001428
Tyler Gunnb702ef82015-05-29 11:51:53 -07001429 /**
1430 * Provides a response to a request to change the current video session properties.
1431 * <p>
1432 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1433 * video call, could decline the request and keep the call as audio-only.
1434 * In such a scenario, the {@code responseProfile} would have a video state of
1435 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1436 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1437 * <p>
1438 * Sent from the {@link InCallService} via
1439 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1440 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1441 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001443 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 */
1445 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1446
1447 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001448 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1449 * <p>
1450 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1451 * camera via
1452 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1453 * <p>
1454 * Sent from the {@link InCallService} via
1455 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 */
1457 public abstract void onRequestCameraCapabilities();
1458
1459 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001460 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1461 * video component of the current {@link Connection}.
1462 * <p>
1463 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1464 * via {@link VideoProvider#setCallDataUsage(long)}.
1465 * <p>
1466 * Sent from the {@link InCallService} via
1467 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001469 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470
1471 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001472 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1473 * the peer device when the video signal is paused.
1474 * <p>
1475 * Sent from the {@link InCallService} via
1476 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 *
1478 * @param uri URI of image to display.
1479 */
Yorke Lee32f24732015-05-12 16:18:03 -07001480 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481
1482 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001483 * Used to inform listening {@link InCallService} implementations when the
1484 * {@link VideoProvider} receives a session modification request.
1485 * <p>
1486 * Received by the {@link InCallService} via
1487 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001489 * @param videoProfile The requested video profile.
1490 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491 */
1492 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001493 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001494 for (IVideoCallback callback : mVideoCallbacks.values()) {
1495 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001496 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001497 } catch (RemoteException ignored) {
1498 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001499 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 }
1501 }
1502 }
1503
1504 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001505 * Used to inform listening {@link InCallService} implementations when the
1506 * {@link VideoProvider} receives a response to a session modification request.
1507 * <p>
1508 * Received by the {@link InCallService} via
1509 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1510 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511 *
1512 * @param status Status of the session modify request. Valid values are
1513 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1514 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001515 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1516 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1517 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1518 * @param requestedProfile The original request which was sent to the peer device.
1519 * @param responseProfile The actual profile changes agreed to by the peer device.
1520 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 */
1522 public void receiveSessionModifyResponse(int status,
1523 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001524 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001525 for (IVideoCallback callback : mVideoCallbacks.values()) {
1526 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001527 callback.receiveSessionModifyResponse(status, requestedProfile,
1528 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001529 } catch (RemoteException ignored) {
1530 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001531 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 }
1533 }
1534 }
1535
1536 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001537 * Used to inform listening {@link InCallService} implementations when the
1538 * {@link VideoProvider} reports a call session event.
1539 * <p>
1540 * Received by the {@link InCallService} via
1541 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001543 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1544 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1545 * {@link VideoProvider#SESSION_EVENT_TX_START},
1546 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1547 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001548 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1549 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 */
1551 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001552 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001553 for (IVideoCallback callback : mVideoCallbacks.values()) {
1554 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001555 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001556 } catch (RemoteException ignored) {
1557 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001558 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001559 }
1560 }
1561 }
1562
1563 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001564 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1565 * peer's video have changed.
1566 * <p>
1567 * This could occur if, for example, the peer rotates their device, changing the aspect
1568 * ratio of the video, or if the user switches between the back and front cameras.
1569 * <p>
1570 * Received by the {@link InCallService} via
1571 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001572 *
1573 * @param width The updated peer video width.
1574 * @param height The updated peer video height.
1575 */
1576 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001577 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001578 for (IVideoCallback callback : mVideoCallbacks.values()) {
1579 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001580 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001581 } catch (RemoteException ignored) {
1582 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001583 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001584 }
1585 }
1586 }
1587
1588 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001589 * Used to inform listening {@link InCallService} implementations when the data usage of the
1590 * video associated with the current {@link Connection} has changed.
1591 * <p>
1592 * This could be in response to a preview request via
1593 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001594 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1595 * 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 -07001596 * <p>
1597 * Received by the {@link InCallService} via
1598 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001600 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1601 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 */
Yorke Lee32f24732015-05-12 16:18:03 -07001603 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001604 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001605 for (IVideoCallback callback : mVideoCallbacks.values()) {
1606 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001607 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001608 } catch (RemoteException ignored) {
1609 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001610 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001611 }
1612 }
1613 }
1614
1615 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001616 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001617 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001618 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001619 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1620 * @hide
1621 */
1622 public void changeCallDataUsage(long dataUsage) {
1623 setCallDataUsage(dataUsage);
1624 }
1625
1626 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001627 * Used to inform listening {@link InCallService} implementations when the capabilities of
1628 * the current camera have changed.
1629 * <p>
1630 * The {@link VideoProvider} should call this in response to
1631 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1632 * changed via {@link VideoProvider#onSetCamera(String)}.
1633 * <p>
1634 * Received by the {@link InCallService} via
1635 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1636 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001637 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001638 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001639 */
Yorke Lee400470f2015-05-12 13:31:25 -07001640 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001641 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001642 for (IVideoCallback callback : mVideoCallbacks.values()) {
1643 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001644 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001645 } catch (RemoteException ignored) {
1646 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001647 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 }
1649 }
1650 }
Rekha Kumar07366812015-03-24 16:42:31 -07001651
1652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001653 * Used to inform listening {@link InCallService} implementations when the video quality
1654 * of the call has changed.
1655 * <p>
1656 * Received by the {@link InCallService} via
1657 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001658 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * @param videoQuality The updated video quality. Valid values:
1660 * {@link VideoProfile#QUALITY_HIGH},
1661 * {@link VideoProfile#QUALITY_MEDIUM},
1662 * {@link VideoProfile#QUALITY_LOW},
1663 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001664 */
1665 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001666 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001667 for (IVideoCallback callback : mVideoCallbacks.values()) {
1668 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001669 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001670 } catch (RemoteException ignored) {
1671 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001672 }
Rekha Kumar07366812015-03-24 16:42:31 -07001673 }
1674 }
1675 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001676
1677 /**
1678 * Returns a string representation of a call session event.
1679 *
1680 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1681 * @return String representation of the call session event.
1682 * @hide
1683 */
1684 public static String sessionEventToString(int event) {
1685 switch (event) {
1686 case SESSION_EVENT_CAMERA_FAILURE:
1687 return SESSION_EVENT_CAMERA_FAILURE_STR;
1688 case SESSION_EVENT_CAMERA_READY:
1689 return SESSION_EVENT_CAMERA_READY_STR;
1690 case SESSION_EVENT_RX_PAUSE:
1691 return SESSION_EVENT_RX_PAUSE_STR;
1692 case SESSION_EVENT_RX_RESUME:
1693 return SESSION_EVENT_RX_RESUME_STR;
1694 case SESSION_EVENT_TX_START:
1695 return SESSION_EVENT_TX_START_STR;
1696 case SESSION_EVENT_TX_STOP:
1697 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001698 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1699 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001700 default:
1701 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1702 }
1703 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001704 }
1705
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001706 private final Listener mConnectionDeathListener = new Listener() {
1707 @Override
1708 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001709 if (mConferenceables.remove(c)) {
1710 fireOnConferenceableConnectionsChanged();
1711 }
1712 }
1713 };
1714
1715 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1716 @Override
1717 public void onDestroyed(Conference c) {
1718 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001719 fireOnConferenceableConnectionsChanged();
1720 }
1721 }
1722 };
1723
Jay Shrauner229e3822014-08-15 09:23:07 -07001724 /**
1725 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1726 * load factor before resizing, 1 means we only expect a single thread to
1727 * access the map so make only a single shard
1728 */
1729 private final Set<Listener> mListeners = Collections.newSetFromMap(
1730 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001731 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1732 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001733 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001734
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001735 // The internal telecom call ID associated with this connection.
1736 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001737 // The PhoneAccountHandle associated with this connection.
1738 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001739 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001740 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001741 private Uri mAddress;
1742 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001743 private String mCallerDisplayName;
1744 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001745 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001746 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07001747 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001748 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001749 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001750 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001751 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001752 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001753 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001754 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001755 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001756 private Conference mConference;
1757 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001758 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001759 private final Object mExtrasLock = new Object();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001760
1761 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001762 * Tracks the key set for the extras bundle provided on the last invocation of
1763 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
1764 * keys which were set previously but are no longer present in the replacement Bundle.
1765 */
1766 private Set<String> mPreviousExtraKeys;
1767
1768 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001769 * Create a new Connection.
1770 */
Santos Cordonf2951102014-07-20 19:06:29 -07001771 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001772
1773 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001774 * Returns the Telecom internal call ID associated with this connection. Should only be used
1775 * for debugging and tracing purposes.
1776 *
1777 * @return The Telecom call ID.
1778 * @hide
1779 */
1780 public final String getTelecomCallId() {
1781 return mTelecomCallId;
1782 }
1783
1784 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001785 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001786 */
Andrew Lee100e2932014-09-08 15:34:24 -07001787 public final Uri getAddress() {
1788 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001789 }
1790
1791 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001792 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001793 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001794 */
Andrew Lee100e2932014-09-08 15:34:24 -07001795 public final int getAddressPresentation() {
1796 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001797 }
1798
1799 /**
1800 * @return The caller display name (CNAP).
1801 */
1802 public final String getCallerDisplayName() {
1803 return mCallerDisplayName;
1804 }
1805
1806 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001807 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001808 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001809 */
1810 public final int getCallerDisplayNamePresentation() {
1811 return mCallerDisplayNamePresentation;
1812 }
1813
1814 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001816 */
1817 public final int getState() {
1818 return mState;
1819 }
1820
1821 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001822 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001823 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1824 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1825 * {@link VideoProfile#STATE_TX_ENABLED},
1826 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001827 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001828 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001829 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001830 */
1831 public final int getVideoState() {
1832 return mVideoState;
1833 }
1834
1835 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001836 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001837 * being routed by the system. This is {@code null} if this Connection
1838 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001839 * @deprecated Use {@link #getCallAudioState()} instead.
1840 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001841 */
Yorke Lee4af59352015-05-13 14:14:54 -07001842 @SystemApi
1843 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001844 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001845 if (mCallAudioState == null) {
1846 return null;
1847 }
Yorke Lee4af59352015-05-13 14:14:54 -07001848 return new AudioState(mCallAudioState);
1849 }
1850
1851 /**
1852 * @return The audio state of the connection, describing how its audio is currently
1853 * being routed by the system. This is {@code null} if this Connection
1854 * does not directly know about its audio state.
1855 */
1856 public final CallAudioState getCallAudioState() {
1857 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001858 }
1859
1860 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001861 * @return The conference that this connection is a part of. Null if it is not part of any
1862 * conference.
1863 */
1864 public final Conference getConference() {
1865 return mConference;
1866 }
1867
1868 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001869 * Returns whether this connection is requesting that the system play a ringback tone
1870 * on its behalf.
1871 */
Andrew Lee100e2932014-09-08 15:34:24 -07001872 public final boolean isRingbackRequested() {
1873 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001874 }
1875
1876 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001877 * @return True if the connection's audio mode is VOIP.
1878 */
1879 public final boolean getAudioModeIsVoip() {
1880 return mAudioModeIsVoip;
1881 }
1882
1883 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001884 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1885 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1886 * start time of the conference.
1887 *
1888 * @return The time at which the {@code Connnection} was connected.
1889 *
1890 * @hide
1891 */
1892 public final long getConnectTimeMillis() {
1893 return mConnectTimeMillis;
1894 }
1895
1896 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001897 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
1898 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1899 * start time of the conference.
1900 *
1901 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
1902 * changes do not impact the call duration.
1903 *
1904 * @return The time at which the {@link Connection} was connected.
1905 *
1906 * @hide
1907 */
1908 public final long getConnectElapsedTimeMillis() {
1909 return mConnectElapsedTimeMillis;
1910 }
1911
1912 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08001913 * Returns RIL voice radio technology used for current connection.
1914 *
1915 * @return the RIL voice radio technology used for current connection,
1916 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
1917 *
1918 * @hide
1919 */
1920 public final @ServiceState.RilRadioTechnology int getCallRadioTech() {
1921 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
1922 Bundle extras = getExtras();
1923 if (extras != null) {
1924 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
1925 TelephonyManager.NETWORK_TYPE_UNKNOWN);
1926 }
1927 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
1928 }
1929
1930 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001931 * @return The status hints for this connection.
1932 */
1933 public final StatusHints getStatusHints() {
1934 return mStatusHints;
1935 }
1936
1937 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001938 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00001939 * <p>
1940 * Extras should be updated using {@link #putExtras(Bundle)}.
1941 * <p>
1942 * Telecom or an {@link InCallService} can also update the extras via
1943 * {@link android.telecom.Call#putExtras(Bundle)}, and
1944 * {@link Call#removeExtras(List)}.
1945 * <p>
1946 * The connection is notified of changes to the extras made by Telecom or an
1947 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001948 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07001949 * @return The extras associated with this connection.
1950 */
1951 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001952 Bundle extras = null;
1953 synchronized (mExtrasLock) {
1954 if (mExtras != null) {
1955 extras = new Bundle(mExtras);
1956 }
1957 }
1958 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001959 }
1960
1961 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001962 * Assign a listener to be notified of state changes.
1963 *
1964 * @param l A listener.
1965 * @return This Connection.
1966 *
1967 * @hide
1968 */
1969 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001970 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001971 return this;
1972 }
1973
1974 /**
1975 * Remove a previously assigned listener that was being notified of state changes.
1976 *
1977 * @param l A Listener.
1978 * @return This Connection.
1979 *
1980 * @hide
1981 */
1982 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001983 if (l != null) {
1984 mListeners.remove(l);
1985 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001986 return this;
1987 }
1988
1989 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001990 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001991 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001992 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001993 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001994 }
1995
1996 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001997 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1998 * ONLY for debugging purposes.
1999 *
2000 * @param callId The telecom call ID.
2001 * @hide
2002 */
2003 public void setTelecomCallId(String callId) {
2004 mTelecomCallId = callId;
2005 }
2006
2007 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002008 * Inform this Connection that the state of its audio output has been changed externally.
2009 *
2010 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002011 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002012 */
Yorke Lee4af59352015-05-13 14:14:54 -07002013 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002014 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002015 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002016 mCallAudioState = state;
2017 onAudioStateChanged(getAudioState());
2018 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002019 }
2020
2021 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002022 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002023 * @return A string representation of the value.
2024 */
2025 public static String stateToString(int state) {
2026 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002027 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002028 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002029 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002030 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002031 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002032 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002033 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002034 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002035 case STATE_PULLING_CALL:
2036 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002037 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002038 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002039 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002040 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002041 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002042 return "DISCONNECTED";
2043 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002044 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002045 return "UNKNOWN";
2046 }
2047 }
2048
2049 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002050 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002051 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002052 public final int getConnectionCapabilities() {
2053 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002054 }
2055
2056 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002057 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2058 */
2059 public final int getConnectionProperties() {
2060 return mConnectionProperties;
2061 }
2062
2063 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002064 * Returns the connection's supported audio routes.
2065 *
2066 * @hide
2067 */
2068 public final int getSupportedAudioRoutes() {
2069 return mSupportedAudioRoutes;
2070 }
2071
2072 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002073 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002074 *
Andrew Lee100e2932014-09-08 15:34:24 -07002075 * @param address The new address.
2076 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002077 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002078 */
Andrew Lee100e2932014-09-08 15:34:24 -07002079 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002080 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002081 Log.d(this, "setAddress %s", address);
2082 mAddress = address;
2083 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002084 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002085 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002086 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 }
2088
2089 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002090 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002091 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002092 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002093 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002094 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002095 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002096 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002098 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002099 mCallerDisplayName = callerDisplayName;
2100 mCallerDisplayNamePresentation = presentation;
2101 for (Listener l : mListeners) {
2102 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2103 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002104 }
2105
2106 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002107 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002108 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2109 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2110 * {@link VideoProfile#STATE_TX_ENABLED},
2111 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002112 *
2113 * @param videoState The new video state.
2114 */
2115 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002116 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002117 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002118 mVideoState = videoState;
2119 for (Listener l : mListeners) {
2120 l.onVideoStateChanged(this, mVideoState);
2121 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002122 }
2123
2124 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 * communicate).
2127 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002128 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002129 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002130 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002131 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002132 }
2133
2134 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002135 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002136 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002137 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002138 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002139 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002140 }
2141
2142 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002143 * Sets state to initializing (this Connection is not yet ready to be used).
2144 */
2145 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002146 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002147 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002148 }
2149
2150 /**
2151 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2152 */
2153 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002154 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002155 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002156 }
2157
2158 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002159 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002160 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002161 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002162 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002163 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 }
2165
2166 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002167 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2168 * device). Only applicable for {@link Connection}s with
2169 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2170 */
2171 public final void setPulling() {
2172 checkImmutable();
2173 setState(STATE_PULLING_CALL);
2174 }
2175
2176 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002177 * Sets state to be on hold.
2178 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002179 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002180 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002181 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002182 }
2183
2184 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002185 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002186 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002187 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002188 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002189 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002190 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002191 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002192 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002193 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002194 }
2195
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002196 public final VideoProvider getVideoProvider() {
2197 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002198 }
2199
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002200 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002201 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002202 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002203 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002204 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002205 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002206 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002207 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002208 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002209 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002210 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002211 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002212 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002213 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002214 }
2215
2216 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002217 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2218 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2219 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2220 * to send an {@link #onPostDialContinue(boolean)} signal.
2221 *
2222 * @param remaining The DTMF character sequence remaining to be emitted once the
2223 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2224 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002225 */
2226 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002227 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002228 for (Listener l : mListeners) {
2229 l.onPostDialWait(this, remaining);
2230 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002231 }
2232
2233 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002234 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2235 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002236 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002237 *
2238 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002239 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002240 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002241 checkImmutable();
2242 for (Listener l : mListeners) {
2243 l.onPostDialChar(this, nextChar);
2244 }
2245 }
2246
2247 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002248 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002249 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002250 *
2251 * @param ringback Whether the ringback tone is to be played.
2252 */
Andrew Lee100e2932014-09-08 15:34:24 -07002253 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002254 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002255 if (mRingbackRequested != ringback) {
2256 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002257 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002258 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002259 }
2260 }
Ihab Awadf8358972014-05-28 16:46:42 -07002261 }
2262
2263 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002264 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002265 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002266 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002267 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002268 public final void setConnectionCapabilities(int connectionCapabilities) {
2269 checkImmutable();
2270 if (mConnectionCapabilities != connectionCapabilities) {
2271 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002272 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002273 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002274 }
2275 }
Santos Cordonb6939982014-06-04 20:20:58 -07002276 }
2277
2278 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002279 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2280 *
2281 * @param connectionProperties The new connection properties.
2282 */
2283 public final void setConnectionProperties(int connectionProperties) {
2284 checkImmutable();
2285 if (mConnectionProperties != connectionProperties) {
2286 mConnectionProperties = connectionProperties;
2287 for (Listener l : mListeners) {
2288 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2289 }
2290 }
2291 }
2292
2293 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002294 * Sets the supported audio routes.
2295 *
2296 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2297 * See {@link CallAudioState}
2298 * @hide
2299 */
2300 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2301 if ((supportedAudioRoutes
2302 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2303 throw new IllegalArgumentException(
2304 "supported audio routes must include either speaker or earpiece");
2305 }
2306
2307 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2308 mSupportedAudioRoutes = supportedAudioRoutes;
2309 for (Listener l : mListeners) {
2310 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2311 }
2312 }
2313 }
2314
2315 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002316 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002317 */
Evan Charlton36a71342014-07-19 16:31:02 -07002318 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002319 for (Listener l : mListeners) {
2320 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002321 }
Santos Cordonb6939982014-06-04 20:20:58 -07002322 }
2323
2324 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002325 * Requests that the framework use VOIP audio mode for this connection.
2326 *
2327 * @param isVoip True if the audio mode is VOIP.
2328 */
2329 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002330 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002331 mAudioModeIsVoip = isVoip;
2332 for (Listener l : mListeners) {
2333 l.onAudioModeIsVoipChanged(this, isVoip);
2334 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002335 }
2336
2337 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002338 * Sets the time at which a call became active on this Connection. This is set only
2339 * when a conference call becomes active on this connection.
2340 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002341 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2342 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002343 *
2344 * @hide
2345 */
2346 public final void setConnectTimeMillis(long connectTimeMillis) {
2347 mConnectTimeMillis = connectTimeMillis;
2348 }
2349
2350 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002351 * Sets the time at which a call became active on this Connection. This is set only
2352 * when a conference call becomes active on this connection.
2353 *
2354 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2355 * {@link SystemClock#elapsedRealtime()}.
2356 *
2357 * @hide
2358 */
Tyler Gunn17541392018-02-01 08:58:38 -08002359 public final void setConnectionStartElapsedRealTime(long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002360 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2361 }
2362
2363 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +08002364 * Sets RIL voice radio technology used for current connection.
2365 *
2366 * @param vrat the RIL Voice Radio Technology used for current connection,
2367 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
2368 *
2369 * @hide
2370 */
2371 public final void setCallRadioTech(@ServiceState.RilRadioTechnology int vrat) {
2372 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
2373 ServiceState.rilRadioTechnologyToNetworkType(vrat));
2374 // Propagates the call radio technology to its parent {@link android.telecom.Conference}
2375 // This action only covers non-IMS CS conference calls.
2376 // For IMS PS call conference call, it can be updated via its host connection
2377 // {@link #Listener.onExtrasChanged} event.
2378 if (getConference() != null) {
2379 getConference().setCallRadioTech(vrat);
2380 }
2381 }
2382
2383 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002384 * Sets the label and icon status to display in the in-call UI.
2385 *
2386 * @param statusHints The status label and icon to set.
2387 */
2388 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002389 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002390 mStatusHints = statusHints;
2391 for (Listener l : mListeners) {
2392 l.onStatusHintsChanged(this, statusHints);
2393 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002394 }
2395
2396 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002397 * Sets the connections with which this connection can be conferenced.
2398 *
2399 * @param conferenceableConnections The set of connections this connection can conference with.
2400 */
2401 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002402 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002403 clearConferenceableList();
2404 for (Connection c : conferenceableConnections) {
2405 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2406 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002407 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002408 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002409 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002410 }
2411 }
2412 fireOnConferenceableConnectionsChanged();
2413 }
2414
2415 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002416 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2417 * or conferences with which this connection can be conferenced.
2418 *
2419 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002420 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002421 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002422 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002423 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002424 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2425 // small amount of items here.
2426 if (!mConferenceables.contains(c)) {
2427 if (c instanceof Connection) {
2428 Connection connection = (Connection) c;
2429 connection.addConnectionListener(mConnectionDeathListener);
2430 } else if (c instanceof Conference) {
2431 Conference conference = (Conference) c;
2432 conference.addListener(mConferenceDeathListener);
2433 }
2434 mConferenceables.add(c);
2435 }
2436 }
2437 fireOnConferenceableConnectionsChanged();
2438 }
2439
2440 /**
Mengjun Leng25707742017-07-04 11:10:37 +08002441 * @hide
2442 * Resets the cdma connection time.
2443 */
2444 public final void resetConnectionTime() {
2445 for (Listener l : mListeners) {
2446 l.onConnectionTimeReset(this);
2447 }
2448 }
2449
2450 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002451 * Returns the connections or conferences with which this connection can be conferenced.
2452 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002453 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002454 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002455 }
2456
Yorke Lee53463962015-08-04 16:07:19 -07002457 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002458 * @hide
2459 */
2460 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002461 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002462 if (mConnectionService != null) {
2463 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2464 "which is already associated with another ConnectionService.");
2465 } else {
2466 mConnectionService = connectionService;
2467 }
2468 }
2469
2470 /**
2471 * @hide
2472 */
2473 public final void unsetConnectionService(ConnectionService connectionService) {
2474 if (mConnectionService != connectionService) {
2475 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2476 "that does not belong to the ConnectionService.");
2477 } else {
2478 mConnectionService = null;
2479 }
2480 }
2481
2482 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07002483 * @hide
2484 */
2485 public final ConnectionService getConnectionService() {
2486 return mConnectionService;
2487 }
2488
2489 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002490 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002491 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002492 *
2493 * @param conference The conference.
2494 * @return {@code true} if the conference was successfully set.
2495 * @hide
2496 */
2497 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002498 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002499 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002500 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002501 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002502 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2503 fireConferenceChanged();
2504 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002505 return true;
2506 }
2507 return false;
2508 }
2509
2510 /**
2511 * Resets the conference that this connection is a part of.
2512 * @hide
2513 */
2514 public final void resetConference() {
2515 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002516 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002517 mConference = null;
2518 fireConferenceChanged();
2519 }
2520 }
2521
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002522 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002523 * Set some extras that can be associated with this {@code Connection}.
2524 * <p>
2525 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2526 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2527 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002528 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2529 * {@link #removeExtras(String...)} methods to modify the extras.
2530 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002531 * 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 -07002532 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2533 *
2534 * @param extras The extras associated with this {@code Connection}.
2535 */
2536 public final void setExtras(@Nullable Bundle extras) {
2537 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002538
2539 // Add/replace any new or changed extras values.
2540 putExtras(extras);
2541
2542 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2543 // the current one and remove any keys that went away.
2544 if (mPreviousExtraKeys != null) {
2545 List<String> toRemove = new ArrayList<String>();
2546 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002547 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002548 toRemove.add(oldKey);
2549 }
2550 }
2551 if (!toRemove.isEmpty()) {
2552 removeExtras(toRemove);
2553 }
2554 }
2555
2556 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2557 // called we can see if the caller has removed any extras values.
2558 if (mPreviousExtraKeys == null) {
2559 mPreviousExtraKeys = new ArraySet<String>();
2560 }
2561 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002562 if (extras != null) {
2563 mPreviousExtraKeys.addAll(extras.keySet());
2564 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002565 }
2566
2567 /**
2568 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2569 * added.
2570 * <p>
2571 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2572 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2573 *
2574 * @param extras The extras to add.
2575 */
2576 public final void putExtras(@NonNull Bundle extras) {
2577 checkImmutable();
2578 if (extras == null) {
2579 return;
2580 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002581 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2582 // the listeners.
2583 Bundle listenerExtras;
2584 synchronized (mExtrasLock) {
2585 if (mExtras == null) {
2586 mExtras = new Bundle();
2587 }
2588 mExtras.putAll(extras);
2589 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002590 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002591 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002592 // Create a new clone of the extras for each listener so that they don't clobber
2593 // each other
2594 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002595 }
2596 }
2597
2598 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002599 * Adds a boolean extra to this {@code Connection}.
2600 *
2601 * @param key The extra key.
2602 * @param value The value.
2603 * @hide
2604 */
2605 public final void putExtra(String key, boolean value) {
2606 Bundle newExtras = new Bundle();
2607 newExtras.putBoolean(key, value);
2608 putExtras(newExtras);
2609 }
2610
2611 /**
2612 * Adds an integer extra to this {@code Connection}.
2613 *
2614 * @param key The extra key.
2615 * @param value The value.
2616 * @hide
2617 */
2618 public final void putExtra(String key, int value) {
2619 Bundle newExtras = new Bundle();
2620 newExtras.putInt(key, value);
2621 putExtras(newExtras);
2622 }
2623
2624 /**
2625 * Adds a string extra to this {@code Connection}.
2626 *
2627 * @param key The extra key.
2628 * @param value The value.
2629 * @hide
2630 */
2631 public final void putExtra(String key, String value) {
2632 Bundle newExtras = new Bundle();
2633 newExtras.putString(key, value);
2634 putExtras(newExtras);
2635 }
2636
2637 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002638 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002639 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002640 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002641 */
2642 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002643 synchronized (mExtrasLock) {
2644 if (mExtras != null) {
2645 for (String key : keys) {
2646 mExtras.remove(key);
2647 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002648 }
2649 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002650 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002651 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002652 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002653 }
2654 }
2655
2656 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002657 * Removes extras from this {@code Connection}.
2658 *
2659 * @param keys The keys of the extras to remove.
2660 */
2661 public final void removeExtras(String ... keys) {
2662 removeExtras(Arrays.asList(keys));
2663 }
2664
2665 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002666 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2667 * be change to the {@link #getCallAudioState()}.
2668 * <p>
2669 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2670 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2671 * <p>
2672 * See also {@link InCallService#setAudioRoute(int)}.
2673 *
2674 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2675 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2676 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2677 */
2678 public final void setAudioRoute(int route) {
2679 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002680 l.onAudioRouteChanged(this, route, null);
2681 }
2682 }
2683
2684 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002685 * Request audio routing to a specific bluetooth device. Calling this method may result in
2686 * the device routing audio to a different bluetooth device than the one specified if the
2687 * bluetooth stack is unable to route audio to the requested device.
2688 * A list of available devices can be obtained via
2689 * {@link CallAudioState#getSupportedBluetoothDevices()}
2690 *
2691 * <p>
2692 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2693 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2694 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002695 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2696 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002697 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002698 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002699 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002700 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2701 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002702 }
2703 }
2704
2705 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002706 * Informs listeners that a previously requested RTT session via
2707 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002708 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002709 */
2710 public final void sendRttInitiationSuccess() {
2711 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2712 }
2713
2714 /**
2715 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002716 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002717 * has failed.
2718 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2719 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002720 */
2721 public final void sendRttInitiationFailure(int reason) {
2722 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2723 }
2724
2725 /**
2726 * Informs listeners that a currently active RTT session has been terminated by the remote
2727 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002728 */
2729 public final void sendRttSessionRemotelyTerminated() {
2730 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2731 }
2732
2733 /**
2734 * Informs listeners that the remote side of the call has requested an upgrade to include an
2735 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002736 */
2737 public final void sendRemoteRttRequest() {
2738 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2739 }
2740
2741 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002742 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002743 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002744 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002745 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2746 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002747 */
Yorke Lee4af59352015-05-13 14:14:54 -07002748 @SystemApi
2749 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002750 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002751
2752 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002753 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2754 *
2755 * @param state The new connection audio state.
2756 */
2757 public void onCallAudioStateChanged(CallAudioState state) {}
2758
2759 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002760 * Notifies this Connection of an internal state change. This method is called after the
2761 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002762 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002763 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002764 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002765 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002766
2767 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002768 * Notifies this Connection of a request to play a DTMF tone.
2769 *
2770 * @param c A DTMF character.
2771 */
Santos Cordonf2951102014-07-20 19:06:29 -07002772 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002773
2774 /**
2775 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2776 */
Santos Cordonf2951102014-07-20 19:06:29 -07002777 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002778
2779 /**
2780 * Notifies this Connection of a request to disconnect.
2781 */
Santos Cordonf2951102014-07-20 19:06:29 -07002782 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002783
2784 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08002785 * Notifies this Connection of a request to disconnect a participant of the conference managed
2786 * by the connection.
2787 *
2788 * @param endpoint the {@link Uri} of the participant to disconnect.
2789 * @hide
2790 */
2791 public void onDisconnectConferenceParticipant(Uri endpoint) {}
2792
2793 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002794 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07002795 */
Santos Cordonf2951102014-07-20 19:06:29 -07002796 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07002797
2798 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002799 * Notifies this Connection of a request to abort.
2800 */
Santos Cordonf2951102014-07-20 19:06:29 -07002801 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002802
2803 /**
2804 * Notifies this Connection of a request to hold.
2805 */
Santos Cordonf2951102014-07-20 19:06:29 -07002806 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002807
2808 /**
2809 * Notifies this Connection of a request to exit a hold state.
2810 */
Santos Cordonf2951102014-07-20 19:06:29 -07002811 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002812
2813 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002814 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002815 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002816 * <p>
2817 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2818 * the default dialer's {@link InCallService}.
2819 * <p>
2820 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2821 * Telecom framework may request that the call is answered in the following circumstances:
2822 * <ul>
2823 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2824 * <li>A car mode {@link InCallService} is in use which has declared
2825 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2826 * {@link InCallService} will be able to see calls from self-managed
2827 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2828 * behalf.</li>
2829 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002830 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002831 */
Santos Cordonf2951102014-07-20 19:06:29 -07002832 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002833
2834 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002835 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07002836 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002837 * <p>
2838 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
2839 * the default dialer's {@link InCallService}.
2840 * <p>
2841 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2842 * Telecom framework may request that the call is answered in the following circumstances:
2843 * <ul>
2844 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
2845 * <li>A car mode {@link InCallService} is in use which has declared
2846 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2847 * {@link InCallService} will be able to see calls from self-managed
2848 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2849 * behalf.</li>
2850 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07002851 */
2852 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07002853 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07002854 }
2855
2856 /**
2857 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05302858 * a request to deflect.
2859 */
2860 public void onDeflect(Uri address) {}
2861
2862 /**
2863 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00002864 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002865 * <p>
2866 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
2867 * the default dialer's {@link InCallService}.
2868 * <p>
2869 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
2870 * Telecom framework may request that the call is rejected in the following circumstances:
2871 * <ul>
2872 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
2873 * <li>A car mode {@link InCallService} is in use which has declared
2874 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
2875 * {@link InCallService} will be able to see calls from self-managed
2876 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
2877 * behalf.</li>
2878 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07002879 */
Santos Cordonf2951102014-07-20 19:06:29 -07002880 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002881
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002882 /**
Hall Liu712acbe2016-03-14 16:38:56 -07002883 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2884 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07002885 */
2886 public void onReject(String replyMessage) {}
2887
2888 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07002889 * Notifies this Connection of a request to silence the ringer.
2890 * <p>
2891 * The ringer may be silenced by any of the following methods:
2892 * <ul>
2893 * <li>{@link TelecomManager#silenceRinger()}</li>
2894 * <li>The user presses the volume-down button while a call is ringing.</li>
2895 * </ul>
2896 * <p>
2897 * Self-managed {@link ConnectionService} implementations should override this method in their
2898 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
2899 * your app set the ringtone as part of the incoming call {@link Notification} (see
2900 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
2901 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
2902 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
2903 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08002904 */
2905 public void onSilence() {}
2906
2907 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002908 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
2909 */
Santos Cordonf2951102014-07-20 19:06:29 -07002910 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002911
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002912 /**
2913 * Notifies this Connection of a request to pull an external call to the local device.
2914 * <p>
2915 * The {@link InCallService} issues a request to pull an external call to the local device via
2916 * {@link Call#pullExternalCall()}.
2917 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002918 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2919 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002920 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07002921 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002922 */
2923 public void onPullExternalCall() {}
2924
2925 /**
2926 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2927 * <p>
2928 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2929 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002930 * Where possible, the Connection should make an attempt to handle {@link Call} events which
2931 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
2932 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
2933 * possible that a {@link InCallService} has defined its own Call events which a Connection is
2934 * not aware of.
2935 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002936 * See also {@link Call#sendCallEvent(String, Bundle)}.
2937 *
2938 * @param event The call event.
2939 * @param extras Extras associated with the call event.
2940 */
2941 public void onCallEvent(String event, Bundle extras) {}
2942
Tyler Gunndee56a82016-03-23 16:06:34 -07002943 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002944 * Notifies this {@link Connection} that a handover has completed.
2945 * <p>
2946 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
2947 * Bundle)} on the initiating side of the handover, and
2948 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
2949 */
2950 public void onHandoverComplete() {}
2951
2952 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002953 * Notifies this {@link Connection} of a change to the extras made outside the
2954 * {@link ConnectionService}.
2955 * <p>
2956 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2957 * the {@link android.telecom.Call#putExtras(Bundle)} and
2958 * {@link Call#removeExtras(List)}.
2959 *
2960 * @param extras The new extras bundle.
2961 */
2962 public void onExtrasChanged(Bundle extras) {}
2963
Tyler Gunnf5035432017-01-09 09:43:12 -08002964 /**
2965 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
2966 * displaying its incoming call user interface for the {@link Connection}.
2967 * <p>
2968 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
2969 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
2970 * should show its own incoming call user interface.
2971 * <p>
2972 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08002973 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
2974 * Telecom framework will display its own incoming call user interface to allow the user to
2975 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
2976 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08002977 * <p>
2978 * You should trigger the display of the incoming call user interface for your application by
2979 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07002980 *
2981 * In your application code, you should create a {@link android.app.NotificationChannel} for
2982 * incoming call notifications from your app:
2983 * <pre><code>
2984 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
2985 * NotificationManager.IMPORTANCE_MAX);
2986 * // other channel setup stuff goes here.
2987 *
2988 * // We'll use the default system ringtone for our incoming call notification channel. You can
2989 * // use your own audio resource here.
2990 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
2991 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
2992 * // Setting the AudioAttributes is important as it identifies the purpose of your
2993 * // notification sound.
2994 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
2995 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
2996 * .build());
2997 *
2998 * NotificationManager mgr = getSystemService(NotificationManager.class);
2999 * mgr.createNotificationChannel(channel);
3000 * </code></pre>
3001 * When it comes time to post a notification for your incoming call, ensure it uses your
3002 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003003 * <pre><code>
3004 * // Create an intent which triggers your fullscreen incoming call user interface.
3005 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3006 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3007 * intent.setClass(context, YourIncomingCallActivity.class);
3008 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3009 *
3010 * // Build the notification as an ongoing high priority item; this ensures it will show as
3011 * // a heads up notification which slides down over top of the current content.
3012 * final Notification.Builder builder = new Notification.Builder(context);
3013 * builder.setOngoing(true);
3014 * builder.setPriority(Notification.PRIORITY_HIGH);
3015 *
3016 * // Set notification content intent to take user to fullscreen UI if user taps on the
3017 * // notification body.
3018 * builder.setContentIntent(pendingIntent);
3019 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3020 * // manager deems it appropriate.
3021 * builder.setFullScreenIntent(pendingIntent, true);
3022 *
3023 * // Setup notification content.
3024 * builder.setSmallIcon( yourIconResourceId );
3025 * builder.setContentTitle("Your notification title");
3026 * builder.setContentText("Your notification content.");
3027 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003028 * // Set notification as insistent to cause your ringtone to loop.
3029 * Notification notification = builder.build();
3030 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003031 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003032 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003033 * NotificationManager notificationManager = mContext.getSystemService(
3034 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003035 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003036 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003037 */
3038 public void onShowIncomingCallUi() {}
3039
Hall Liub64ac4c2017-02-06 10:49:48 -08003040 /**
3041 * Notifies this {@link Connection} that the user has requested an RTT session.
3042 * The connection service should call {@link #sendRttInitiationSuccess} or
3043 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3044 * request, respectively.
3045 * @param rttTextStream The object that should be used to send text to or receive text from
3046 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003047 */
3048 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3049
3050 /**
3051 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3052 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003053 */
3054 public void onStopRtt() {}
3055
3056 /**
3057 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3058 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3059 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3060 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003061 * @param rttTextStream The object that should be used to send text to or receive text from
3062 * the in-call app.
3063 */
3064 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3065
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003066 static String toLogSafePhoneNumber(String number) {
3067 // For unknown number, log empty string.
3068 if (number == null) {
3069 return "";
3070 }
3071
3072 if (PII_DEBUG) {
3073 // When PII_DEBUG is true we emit PII.
3074 return number;
3075 }
3076
3077 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3078 // sanitized phone numbers.
3079 StringBuilder builder = new StringBuilder();
3080 for (int i = 0; i < number.length(); i++) {
3081 char c = number.charAt(i);
3082 if (c == '-' || c == '@' || c == '.') {
3083 builder.append(c);
3084 } else {
3085 builder.append('x');
3086 }
3087 }
3088 return builder.toString();
3089 }
3090
Ihab Awad542e0ea2014-05-16 10:22:16 -07003091 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003092 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003093 if (mState == STATE_DISCONNECTED && mState != state) {
3094 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003095 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003096 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003097 if (mState != state) {
3098 Log.d(this, "setState: %s", stateToString(state));
3099 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003100 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003101 for (Listener l : mListeners) {
3102 l.onStateChanged(this, state);
3103 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003104 }
3105 }
3106
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003107 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003108 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003109 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3110 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08003111 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003112 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003113
3114 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003115 if (mImmutable) {
3116 throw new UnsupportedOperationException("Connection is immutable");
3117 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003118 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003119 }
3120
Evan Charltonbf11f982014-07-20 22:06:28 -07003121 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003122 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003123 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3124 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003125 * <p>
3126 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3127 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003128 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003129 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003130 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003131 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003132 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3133 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003134 }
3135
Evan Charltonbf11f982014-07-20 22:06:28 -07003136 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003137 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3138 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3139 * this should never be un-@hide-den.
3140 *
3141 * @hide
3142 */
3143 public void checkImmutable() {}
3144
3145 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003146 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3147 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3148 * that state. This connection should not be used for anything, and no other
3149 * {@code Connection}s should be attempted.
3150 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003151 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003152 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003153 * @return A {@code Connection} which indicates that the underlying connection should
3154 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003155 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003156 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003157 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003158 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003159
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003160 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003161 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003162 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003163 }
3164 }
3165
Santos Cordon823fd3c2014-08-07 18:35:18 -07003166 private final void fireConferenceChanged() {
3167 for (Listener l : mListeners) {
3168 l.onConferenceChanged(this, mConference);
3169 }
3170 }
3171
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003172 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003173 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003174 if (c instanceof Connection) {
3175 Connection connection = (Connection) c;
3176 connection.removeConnectionListener(mConnectionDeathListener);
3177 } else if (c instanceof Conference) {
3178 Conference conference = (Conference) c;
3179 conference.removeListener(mConferenceDeathListener);
3180 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003181 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003182 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003183 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003184
3185 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003186 * Handles a change to extras received from Telecom.
3187 *
3188 * @param extras The new extras.
3189 * @hide
3190 */
3191 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003192 Bundle b = null;
3193 synchronized (mExtrasLock) {
3194 mExtras = extras;
3195 if (mExtras != null) {
3196 b = new Bundle(mExtras);
3197 }
3198 }
3199 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003200 }
3201
3202 /**
Anthony Lee17455a32015-04-24 15:25:29 -07003203 * Notifies listeners that the merge request failed.
3204 *
3205 * @hide
3206 */
3207 protected final void notifyConferenceMergeFailed() {
3208 for (Listener l : mListeners) {
3209 l.onConferenceMergeFailed(this);
3210 }
3211 }
3212
3213 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08003214 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003215 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08003216 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003217 * @hide
3218 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08003219 protected final void updateConferenceParticipants(
3220 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003221 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08003222 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003223 }
3224 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003225
3226 /**
3227 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07003228 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08003229 */
3230 protected void notifyConferenceStarted() {
3231 for (Listener l : mListeners) {
3232 l.onConferenceStarted();
3233 }
3234 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003235
3236 /**
Tyler Gunn7d633d32016-06-24 07:30:10 -07003237 * Notifies listeners when a change has occurred to the Connection which impacts its ability to
3238 * be a part of a conference call.
3239 * @param isConferenceSupported {@code true} if the connection supports being part of a
3240 * conference call, {@code false} otherwise.
3241 * @hide
3242 */
3243 protected void notifyConferenceSupportedChanged(boolean isConferenceSupported) {
3244 for (Listener l : mListeners) {
3245 l.onConferenceSupportedChanged(this, isConferenceSupported);
3246 }
3247 }
3248
3249 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303250 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3251 * changed due to an emergency call being redialed.
3252 * @param pHandle The new PhoneAccountHandle for this connection.
3253 * @hide
3254 */
3255 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3256 for (Listener l : mListeners) {
3257 l.onPhoneAccountChanged(this, pHandle);
3258 }
3259 }
3260
3261 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003262 * Sets the {@link PhoneAccountHandle} associated with this connection.
3263 *
3264 * @hide
3265 */
3266 public void setPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) {
3267 if (mPhoneAccountHandle != phoneAccountHandle) {
3268 mPhoneAccountHandle = phoneAccountHandle;
3269 notifyPhoneAccountChanged(phoneAccountHandle);
3270 }
3271 }
3272
3273 /**
3274 * Returns the {@link PhoneAccountHandle} associated with this connection.
3275 *
3276 * @hide
3277 */
3278 public PhoneAccountHandle getPhoneAccountHandle() {
3279 return mPhoneAccountHandle;
3280 }
3281
3282 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003283 * Sends an event associated with this {@code Connection} with associated event extras to the
3284 * {@link InCallService}.
3285 * <p>
3286 * Connection events are used to communicate point in time information from a
3287 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3288 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3289 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3290 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3291 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3292 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3293 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3294 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3295 * <p>
3296 * Events are exposed to {@link InCallService} implementations via
3297 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3298 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003299 * 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 -07003300 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3301 * some events altogether.
3302 * <p>
3303 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3304 * conflicts between {@link ConnectionService} implementations. Further, custom
3305 * {@link ConnectionService} implementations shall not re-purpose events in the
3306 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3307 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3308 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3309 * {@code com.example.extra.MY_EXTRA}).
3310 * <p>
3311 * When defining events and the associated extras, it is important to keep their behavior
3312 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3313 * events/extras should me maintained to ensure backwards compatibility with older
3314 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003315 *
3316 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003317 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003318 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003319 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003320 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003321 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003322 }
3323 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003324}